diff options
author | gennyble <gen@nyble.dev> | 2024-06-10 17:17:55 -0500 |
---|---|---|
committer | gennyble <gen@nyble.dev> | 2024-06-10 17:17:55 -0500 |
commit | 36ccf4d4bf57f12dae13543b37453dc6433018e5 (patch) | |
tree | 8df59be62bd36b1cc5ed75f6a1ba150ada4aa5f2 /src | |
parent | a57cb34b513876313c755be2bbebb63138b4932b (diff) | |
download | colorsquash-36ccf4d4bf57f12dae13543b37453dc6433018e5.tar.gz colorsquash-36ccf4d4bf57f12dae13543b37453dc6433018e5.zip |
Use leftover bits in HighestBits selector
Diffstat (limited to 'src')
-rw-r--r-- | src/selection.rs | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/selection.rs b/src/selection.rs index 84d5ea3..aee3b2f 100644 --- a/src/selection.rs +++ b/src/selection.rs @@ -337,17 +337,28 @@ pub struct HighestBits {} impl Selector for HighestBits { fn select(&mut self, max_colors: usize, image: ImageData) -> Vec<RGB8> { - let max_bits = max_colors.next_power_of_two().ilog2() / 3; - let shift = 8 - max_bits; + let bits = max_colors.next_power_of_two().ilog2(); + let leftover = bits % 3; + let shift = 8 - (bits / 3); + + //TODO: gen- we're taking red/green here because, as i remember, they + // are the colours to which we are most sensetive? but it would be cool + // if this was selectable + let (rshift, gshift, bshift) = match leftover { + 0 => (shift, shift, shift), + 1 => (shift, shift - 1, shift), + 2 => (shift - 1, shift - 1, shift), + _ => unreachable!(), + }; image .0 .iter() .map(|color| { RGB8::new( - color.r >> shift << shift, - color.g >> shift << shift, - color.b >> shift << shift, + color.r >> rshift << rshift, + color.g >> gshift << gshift, + color.b >> bshift << bshift, ) }) .collect::<HashSet<_>>() |