feat: support palette (ColorMap) image decoding
Read the ColorMap tag (320) for RGBPalette images and return raw palette indices as the decoded data with ColorType::Palette(n). Changes: - Read and validate ColorMap tag during IFD parsing (3 * 2^bps entries) - Return ColorType::Palette from colortype() for RGBPalette images - Accept Palette in expand_chunk validation (standard + sub-byte depths) - Expose color_map() method on Decoder for palette lookup - Add tests for 1-bit, 4-bit, 8-bit palette images with checksums - Add test verifying ColorMap accessibility and structure The decoder returns raw palette indices; consumers apply the lookup using the color map returned by Decoder::color_map().
This commit is contained in:
1 parent
c6f6ff4c95
commit
3b11e2f577
3 files changed
+90
-8
No files matched your search
@@ -941,6 +941,16 @@ impl<R: Read + Seek> Decoder<R> {
|
||||
self.image.colortype()
|
||||
}
|
||||
|
||||
/// Returns the color map (palette) for the current image, if it uses
|
||||
/// `PhotometricInterpretation::RGBPalette`.
|
||||
///
|
||||
/// The returned slice contains `3 * 2^BitsPerSample` entries as u16 values,
|
||||
/// laid out as: all red values, then all green values, then all blue values.
|
||||
/// Each value is in the range `0..=65535` regardless of the actual bit depth.
|
||||
pub fn color_map(&self) -> Option<&[u16]> {
|
||||
self.image.color_map.as_deref()
|
||||
}
|
||||
|
||||
/// The offset of the directory representing the current image.
|
||||
pub fn ifd_pointer(&mut self) -> Option<IfdPointer> {
|
||||
self.current_ifd_pointer
|
||||
|
||||
Reference in new issue
Block a user