Skip to content

Conversation

@brianpopow
Copy link
Collaborator

@brianpopow brianpopow commented Aug 2, 2021

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

This PR changes the tiff decoder, so it will respect the byte order for 16 bit gray tiff images and 16 bit rgb planar images.

@brianpopow brianpopow added this to the 1.1.0 milestone Aug 2, 2021
@codecov
Copy link

codecov bot commented Aug 2, 2021

Codecov Report

Merging #1720 (f868b7a) into master (0701021) will increase coverage by 0.05%.
The diff coverage is 99.19%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1720      +/-   ##
==========================================
+ Coverage   84.34%   84.40%   +0.05%     
==========================================
  Files         818      822       +4     
  Lines       35968    36056      +88     
  Branches     4190     4203      +13     
==========================================
+ Hits        30339    30434      +95     
+ Misses       4808     4802       -6     
+ Partials      821      820       -1     
Flag Coverage Δ
unittests 84.40% <99.19%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...cInterpretation/TiffColorDecoderFactory{TPixel}.cs 75.00% <75.00%> (+5.00%) ⬆️
...icInterpretation/BlackIsZero16TiffColor{TPixel}.cs 100.00% <100.00%> (ø)
...ricInterpretation/BlackIsZero8TiffColor{TPixel}.cs 100.00% <100.00%> (ø)
...tricInterpretation/BlackIsZeroTiffColor{TPixel}.cs 100.00% <100.00%> (ø)
...tometricInterpretation/PaletteTiffColor{TPixel}.cs 100.00% <100.00%> (ø)
...metricInterpretation/Rgb161616TiffColor{TPixel}.cs 100.00% <100.00%> (ø)
...tricInterpretation/Rgb16PlanarTiffColor{TPixel}.cs 100.00% <100.00%> (ø)
...otometricInterpretation/Rgb888TiffColor{TPixel}.cs 100.00% <100.00%> (ø)
...metricInterpretation/RgbPlanarTiffColor{TPixel}.cs 100.00% <100.00%> (ø)
.../PhotometricInterpretation/RgbTiffColor{TPixel}.cs 100.00% <100.00%> (ø)
... and 12 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0701021...f868b7a. Read the comment docs.

{
for (int x = left; x < left + width; x++)
{
ushort intensity = TiffUtils.ConvertToShort(data.Slice(offset, 2), this.isBigEndian);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job!
If there is insufficient performance, you can make separate loops for isBigEndian and !isBigEndian

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea, changed with 6b538f8

@brianpopow brianpopow changed the title Respect byte order with 16 bit gray tiff images Respect byte order with 16 bit tiff images Aug 2, 2021

l16.PackedValue = intensity;
color.FromL16(l16);
pixels[x, y] = TiffUtils.ColorFromL16(l16, intensity, color);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we using the [x, y] indexer like this elsewhere? We should process per row span to avoid the additional per-pixel multiplication.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah your right. There was other places used the indexer which i have changed, too. See 0ae95f1

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weird, now a test fails only on netcore2.1: TiffDecoder_CanDecode_48Bit

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it only fails for netcore2.1 and only in Release mode, not in Debug mode.
output looks like this:
output

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its again the bug with the defaults i reported recently: netcore2.1 default bug

I will try to work around it, but there are several places were defaults are used in the TiffColorDecoders

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed the default usages introduced with this PR with values defined in TiffUtils now to workaround the issue with netcore2.1

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Man, that bug is annoying!

Span<TPixel> pixelRow = pixels.GetRowSpan(y);
if (this.isBigEndian)
{
for (int x = left; x < left + width; x++)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can go one better for performance now you have the span and avoid the bounds checks..

Span<TPixel> pixelRow = pixels.GetRowSpan(y).Slice(left, left + width);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im sorry, but I dont understand. Can you explain further? How would the loop change then?

Copy link
Member

@JimBobSquarePants JimBobSquarePants Aug 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually sorry, I misread.

The span declaration would be:

Span<TPixel> pixelRow = pixels.GetRowSpan(y).Slice(left, width);

Then the inner loop would become:

for (x = 0; x < pixelRow.Length; x++)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah ok, makes sense now, changed with f1834c7

Copy link
Member

@JimBobSquarePants JimBobSquarePants left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

@brianpopow brianpopow merged commit c084b5f into master Aug 3, 2021
@brianpopow brianpopow deleted the bp/tiff16bitgray branch August 3, 2021 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants