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 support for decoding 6, 12, 30, 42 bits per pixel tiff's #1647
Conversation
@@ -274,6 +278,7 @@ public void Process(TiffEncoderCore encoder) | |||
Value = (ushort)encoder.PhotometricInterpretation | |||
}; | |||
|
|||
this.collector.AddOrReplace(planarConfig); |
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.
note that I have explicitly added the chunky planar configuration, otherwise it could have accidentally be possible that it would be set to planar, if the decoded images was planar.
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 don't really understand this change. Could you please explain to me what the issue is with pulling the value from the decoder if present?
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 are two possible values of the PlanarConfiguration
:
- Chunky: The data is stored as RGBRGBRGB. This is the default mode.
- Planar: This is more uncommon. The data is stored as:
RRR
GGG
BBB
The Tiff Encoder does always encodes the data as Chunky
, but does not make this explicitly by storing a value for the PlanarConfiguration
. The value is omitted and because decoders will assume Chunky
this will work.
Now in the case of when we decode an actual 'Planar' Tiff and the reencode this TIFF again, the PlanarConfiguration
would carry over to the encoded image, because its present in the EXIF profile. This would change the interpretation of the data and make the encoded image invalid. Therefore i thought it would be a good idea to make it explicit and always set it to Chunky
.
Codecov Report
@@ Coverage Diff @@
## master #1647 +/- ##
==========================================
+ Coverage 84.15% 84.20% +0.05%
==========================================
Files 812 813 +1
Lines 35634 35710 +76
Branches 4147 4154 +7
==========================================
+ Hits 29987 30070 +83
+ Misses 4831 4824 -7
Partials 816 816
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
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.
SamplesPerPixel
tag can have arbitrary value and can have different bits per component for each component corresponding to a pixel.
We don't need to support different different bits per component other than 565 (and 555), but we can support the same arbitrary bit values: {2,2,2}, {3,3,3}...
@@ -179,7 +180,18 @@ private static void ParseColorType(this TiffDecoderCore options, ExifProfile exi | |||
|
|||
if (options.PlanarConfiguration == TiffPlanarConfiguration.Chunky) | |||
{ | |||
options.ColorType = options.BitsPerSample == TiffBitsPerSample.Bit24 ? TiffColorType.Rgb888 : TiffColorType.Rgb; |
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.
@brianpopow TiffColorType.Rgb
- it seems that we have stopped supporting custom RGB (not in this PR, but even earlier).
The patch is workaround support for Test images: |
yeah you are right, we can do it this way, but I think this should be another PR. Feel free to open another PR with it. edit: @IldarKhayrutdinov good spot, that we can actually use the magick decoder for 2 and 4 bit! |
yeah, this PR nothing breaks, it should be another PR |
Co-authored-by: Günther Foidl <gue@korporal.at>
@IldarKhayrutdinov So what does this mean in regards to this PR? |
Now that I thought about it again, I think Ildar meant we can use |
@JimBobSquarePants In principle, this is not a bug, but we must support it, since it is worth a little effort for us. |
@brianpopow By the way, |
@IldarKhayrutdinov thanks for the clarification. |
case TiffColorType.Rgb222: | ||
DebugGuard.IsTrue( | ||
bitsPerSample.Length == 3 | ||
&& bitsPerSample[0] == 2 |
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.
You can use the indexer check skipping trick discussed the other day here I reckon.
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.
Very cool! Love how well structured this all is. 👍
Prerequisites
Description
This PR adds support for decoding:
/cc @IldarKhayrutdinov