Skip to content
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 Tiff images with associated alpha data #2062

Merged
merged 8 commits into from
Mar 15, 2022

Conversation

brianpopow
Copy link
Collaborator

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 adds support for decoding Tiff images with associated alpha data: The alpha data is pre-multiplied.

@JimBobSquarePants
Copy link
Member

@brianpopow Do you want this in 2.1? I can hold a release 'til we get it done.

@JimBobSquarePants
Copy link
Member

@brianpopow I updated your PR to use the built in operations. I had to tweak the tolerance slightly but the output is mostly the same (better alpha blending of edge pixels with Numerics).

image

I'm curious as to why there is such a significant difference from the reference as I cannot see an obvious issue.

@JimBobSquarePants JimBobSquarePants added this to the 2.1.0 milestone Mar 15, 2022
@JimBobSquarePants
Copy link
Member

JimBobSquarePants commented Mar 15, 2022

@brianpopow I might have found quite a serious issue with the Tiff decoder I hadn't spotted before. We use FromVector4 all through the decoder codebase when we should be using FromScaledVector4. There's some cases in the Bmp decoder also.

I'm going to update and fix in this PR.

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.

LGTM 👍

@brianpopow
Copy link
Collaborator Author

@brianpopow Do you want this in 2.1? I can hold a release 'til we get it done.

I dont think this should block 2.1 for this and it can be added for future.

@brianpopow I might have found quite a serious issue with the Tiff decoder I hadn't spotted before. We use FromVector4 all > through the decoder codebase when we should be using FromScaledVector4. There's some cases in the Bmp decoder also.
I'm going to update and fix in this PR.

Good spot 👍

Can't we use PixelOperations.Instance.FromVector4Destructive passing PixelConversionModifiers.Premultiply here? This allows us to use Avx2 unpremultiplication.

That was also my first thought, but I was getting different results then the reference decoder, so I was leaving it to the manual calculation.

Can't we use PixelOperations.Instance.FromVector4Destructive passing PixelConversionModifiers.Premultiply here? This allows us to use Avx2 unpremultiplication.

Let me double check that, but last time I checked any difference to the reference decoder was always off by exact 1, which I blamed on floating point inaccuracies.

@JimBobSquarePants
Copy link
Member

The hardware accelerated code should be super accurate. (More so than software) and is well tested so I think the reference decoder might have an issue. That and the same method used for the other color type works just fine. (I wonder if we can compare also with System Drawing?)

I’m happy for this to go in as-is unless you can find something significant.

@JimBobSquarePants
Copy link
Member

@brianpopow I just did a comparison using the System.Drawing reference decoder and the tests pass with the original comparison tolerance of .0.001F. This is definitely good to go.

@JimBobSquarePants JimBobSquarePants merged commit aac0783 into main Mar 15, 2022
@JimBobSquarePants JimBobSquarePants deleted the bp/extrasamples2 branch March 15, 2022 11:05
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.

2 participants