Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dithering for From<RGBf> for RGBu8/RGBu16 #4

Open
virtualritz opened this issue Nov 22, 2020 · 0 comments
Open

Add dithering for From<RGBf> for RGBu8/RGBu16 #4

virtualritz opened this issue Nov 22, 2020 · 0 comments

Comments

@virtualritz
Copy link

I.e. what good old RiQuantize does. I think it's safe to assume a dither amplitude of 0.5.
This should be built-in. I do not see anyone wanting to see banding when they do a conversion to one of those two types.

Only challenge I see is a nice API for seeding the RNG so results are deterministic on re-runs.

Rust version of RiQuantize:

    use num_traits::float::Float;
    use core::ops::Mul;
    use oorandom;

    pub fn quantize<T>(value: T, one: T, min: T, max: T, dither_amplitude: T, rng: &mut oorandom::Rand32) -> T
    where
        T: Float + Mul<f32, Output = T>
    {
        use clamped::Clamp;
        (one * value + dither_amplitude * rng.rand_float())
            .round()
            .clamped(min, max)
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant