Function image::codecs::dxt::encode_dxt_colors

source ·
fn encode_dxt_colors(source: &[u8], dest: &mut [u8], is_dxt1: bool)
👎Deprecated: DXT support will be removed or reworked in a future version. Prefer the squish crate instead. See https://github.com/image-rs/image/issues/1623
Expand description

Tries to perform the color encoding part of dxt compression the approach taken is simple, it picks unique combinations of the colors present in the block, and attempts to encode the block with each, picking the encoding that yields the least squared error out of all of them.

This could probably be faster but is already reasonably fast and a good reference impl to optimize others against.

Another way to perform this analysis would be to perform a singular value decomposition of the different colors, and then pick 2 points on this line as the base colors. But this is still rather unwieldy math and has issues with the 3-linear-colors-and-0 case, it’s also worse at conserving the original colors.

source: should be RGBAx16 or RGBx16 bytes of data, dest 8 bytes of resulting encoded color data