-
Notifications
You must be signed in to change notification settings - Fork 71
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
Addresses #214 by allowing up to 255 samples per pixel and allowing B… #216
Conversation
…lowing BlackIsZero and WhiteIsZero to have up to 64 bits per sample. Also includes decode_geotiff_images unit test.
#215 removed the same limit this does, but it would still be great to merge the test. Would you mind rebasing? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#215 removed the same limit this does, but it would still be great to merge the test. Would you mind rebasing?
Been following #214 and am interested in this patch to enable reading multi-band GeoTIFFs at https://github.com/weiji14/cog3pio. Is it ok if I open another PR for this?
@@ -336,7 +336,7 @@ impl Image { | |||
)), | |||
}, | |||
PhotometricInterpretation::BlackIsZero | PhotometricInterpretation::WhiteIsZero | |||
if self.bits_per_sample.len() == 1 => | |||
if self.bits_per_sample.len() <= 64 => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a bit more complicated because other places in the code assume that ColorType::Gray
means only a single band
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typically for multi-band GeoTIFFs, each band would be ColorType::Gray
(grayscale). Are you saying that we need to check the ColorType
for each band?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I refreshed my memory of this code. The main place that assumes that ColorType::Gray
means the image has only a single band is actually in the image crate. Other users may be making a similar assumption, particularly because Decoder
doesn't actually expose a way to query the number of bands.
We never actually marked ColorType
non_exhaustive so it would require a major version bump, but I think it might make sense to add a ColorType::Multiband(bit_depth, bands)
variant or something along those lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh ok, you mean adding ColorType::Multiband
to the enum at
Lines 22 to 43 in 895c70a
pub enum ColorType { | |
/// Pixel is grayscale | |
Gray(u8), | |
/// Pixel contains R, G and B channels | |
RGB(u8), | |
/// Pixel is an index into a color palette | |
Palette(u8), | |
/// Pixel is grayscale with an alpha channel | |
GrayA(u8), | |
/// Pixel is RGB with an alpha channel | |
RGBA(u8), | |
/// Pixel is CMYK | |
CMYK(u8), | |
/// Pixel is YCbCr | |
YCbCr(u8), | |
} |
I'll see if I can squeeze out some time this week to implement this. It sounds like we just need to add the ColorType::Multiband
variant, and modify the self.samples >= 1
branch somewhere here (under the TODO), while keeping the self.sample == 1
branch intact:
image-tiff/src/decoder/image.rs
Lines 350 to 361 in 895c70a
PhotometricInterpretation::BlackIsZero | PhotometricInterpretation::WhiteIsZero | |
if self.samples == 1 => | |
{ | |
Ok(ColorType::Gray(self.bits_per_sample)) | |
} | |
// TODO: this is bad we should not fail at this point | |
_ => Err(TiffError::UnsupportedError( | |
TiffUnsupportedError::InterpretationWithBits( | |
self.photometric_interpretation, | |
vec![self.bits_per_sample; self.samples as usize], | |
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, the code was a lot more straightforward than I expected. Opened a PR at #224 to work on this.
…lackIsZero and WhiteIsZero to have up to 64 bits per sample. Also includes decode_geotiff_images unit test.