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

[WIP] Preserving isTrans data #764

Merged
merged 12 commits into from
Nov 23, 2018
Merged

Conversation

devedse
Copy link
Contributor

@devedse devedse commented Oct 30, 2018

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 matches 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

Currently still WIP but I wanted to contribute something to the project 😄. So I'm working on fixing my own issue:
#763

@CLAassistant
Copy link

CLAassistant commented Oct 30, 2018

CLA assistant check
All committers have signed the CLA.

@devedse
Copy link
Contributor Author

devedse commented Oct 30, 2018

I'm not sure if we want to implement it this way or have a look at the already existing Palette code which should be extended to always write alpha if the hasAlpha flag is true. But please let me know :)

@JimBobSquarePants
Copy link
Member

Hey @devedse this all looks great! Thanks for making the effort to fix this for us.

I'll pull it down for a final review but from looking on GitHub I can't see anything amiss.

In the interim could you please sign the CLA? Cheers! 👍

@devedse
Copy link
Contributor Author

devedse commented Oct 31, 2018

I think the bitconversion could use some improvements. But its not really my speciality.
Ill look at signing the ca

@devedse
Copy link
Contributor Author

devedse commented Nov 1, 2018

Signed 😄

Copy link
Member

@antonfirsov antonfirsov left a comment

Choose a reason for hiding this comment

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

@JimBobSquarePants @devedse I have a poor understanding of PNG, so I need some explanation to understand everything, and have some ideas for defining proper test coverage:

When a color is defined as transparent, and we decode it to Rgba32 or similar, do we set the alpha to 255 when we encounter that color? (This would make the most sense to me!)
What is then happening in the encoder? Are we converting all colors set to (*,*,*,255) to the transparent color again?

src/ImageSharp/Formats/Png/PngMetaData.cs Outdated Show resolved Hide resolved
src/ImageSharp/Formats/Png/PngMetaData.cs Outdated Show resolved Hide resolved
src/ImageSharp/Formats/Png/PngMetaData.cs Outdated Show resolved Hide resolved
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.

Looking good with just a couple of changes.

Anton made some valid suggestion regarding using our new gray types and better variable naming. We should also check the bit depth as well as whether the property is not null.

src/ImageSharp/Formats/Png/PngEncoderCore.cs Outdated Show resolved Hide resolved
src/ImageSharp/MetaData/ImageMetaData.cs Outdated Show resolved Hide resolved
@JimBobSquarePants
Copy link
Member

JimBobSquarePants commented Nov 1, 2018

@antonfirsov To answer your questions regarding the tRNS chunk.

When decoding either grayscale, 24bit, or 48bit color types, if the chunk is encountered we decode to Rgba32 and Rgba64 pixel formats (we don't have a GrayAlpha pixel format) and set the alpha component to fully opaque for any pixel that does not match the value contained within the chunk.

When encoding we use the Rgb24, Rgb48, Gray8, or Gray16 pixel format layouts and assign a color that should be regarded as transparent to the chunk.

Does that make sense?

@codecov
Copy link

codecov bot commented Nov 2, 2018

Codecov Report

Merging #764 into master will increase coverage by 0.05%.
The diff coverage is 95.37%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #764      +/-   ##
==========================================
+ Coverage   88.51%   88.56%   +0.05%     
==========================================
  Files        1005     1005              
  Lines       42769    42846      +77     
  Branches     3149     3159      +10     
==========================================
+ Hits        37855    37948      +93     
+ Misses       4222     4203      -19     
- Partials      692      695       +3
Impacted Files Coverage Δ
...eSharp.Tests/Formats/Png/PngDecoderTests.Chunks.cs 100% <ø> (ø) ⬆️
tests/ImageSharp.Tests/TestImages.cs 100% <ø> (ø) ⬆️
src/ImageSharp/Formats/Png/PngMetaData.cs 100% <100%> (ø) ⬆️
.../ImageSharp.Tests/Formats/Png/PngChunkTypeTests.cs 100% <100%> (ø) ⬆️
src/ImageSharp/Formats/Png/PngDecoderCore.cs 82.53% <100%> (ø) ⬆️
src/ImageSharp/Formats/Png/PngScanlineProcessor.cs 63.28% <75%> (+3.84%) ⬆️
src/ImageSharp/Formats/Png/PngEncoderCore.cs 93.51% <90%> (-0.33%) ⬇️
...ts/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs 99.47% <97.36%> (-0.53%) ⬇️
...ions/Generated/Rgba32.PixelOperations.Generated.cs 100% <0%> (+9.57%) ⬆️

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 b9d570f...6849617. Read the comment docs.

@devedse
Copy link
Contributor Author

devedse commented Nov 2, 2018

I've implemented almost all findings, please redo code review :)

@antonfirsov
Copy link
Member

antonfirsov commented Nov 2, 2018

and set the alpha component to fully opaque for any pixel that does not match the value contained within the chunk

But what happens when we encounter pixels matching the value? Do we decode fully transparent pixels in those cases?
Do we alter transparent pixels to chunk-defined pixels when encoding?

Copy link
Member

@antonfirsov antonfirsov left a comment

Choose a reason for hiding this comment

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

We should cover all 4 trancparency cases with tests for both decoder and encoder. Not yet sure whether we can base them on current tests or we should invent something new. (I'm still unsure whether I understand decoding/re-encoding of transparent pixels correctly.)

@JimBobSquarePants
Copy link
Member

@antonfirsov

But what happens when we encounter pixels matching the value? Do we decode fully transparent pixels in those cases?

We set the alpha component to 0 leaving the other component data intact.

Do we alter transparent pixels to chunk-defined pixels when encoding?

No the tRNS chunk is simply a marker. Pixels are encoded as normal. Delete the tRNS chunk and you have an opaque image.

@devedse

We have some test images already that might cover your needs but there's an official suite here.

http://www.schaik.com/pngsuite/

@devedse
Copy link
Contributor Author

devedse commented Nov 4, 2018

@devedse

We have some test images already that might cover your needs but there's an official suite here.

http://www.schaik.com/pngsuite/

What do you mean by this? For writing test cases?

@antonfirsov
Copy link
Member

@devedse input images for decoder tests.

@JimBobSquarePants
Copy link
Member

@devedse I've updated the code to check for the correct bit depth and also reduce allocations.

Once we add the tests images from the collection I linked this is good to go.

@JimBobSquarePants
Copy link
Member

Tests added and correct behaviour confirmed. I think this is good to go now.

@JimBobSquarePants JimBobSquarePants dismissed antonfirsov’s stale review November 23, 2018 15:45

Code and tests are now up to spec.

@JimBobSquarePants JimBobSquarePants merged commit 0483efa into SixLabors:master Nov 23, 2018
antonfirsov pushed a commit to antonfirsov/ImageSharp that referenced this pull request Nov 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants