Skip to content

Conversation

@brianpopow
Copy link
Collaborator

@brianpopow brianpopow commented May 15, 2019

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

The title already says it: When its an Gray8 image, color quantization is actually not needed.

@codecov
Copy link

codecov bot commented May 16, 2019

Codecov Report

Merging #909 into master will increase coverage by <.01%.
The diff coverage is 93.22%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #909      +/-   ##
==========================================
+ Coverage   89.24%   89.25%   +<.01%     
==========================================
  Files        1083     1083              
  Lines       47394    47442      +48     
  Branches     3293     3299       +6     
==========================================
+ Hits        42299    42345      +46     
  Misses       4393     4393              
- Partials      702      704       +2
Impacted Files Coverage Δ
tests/ImageSharp.Tests/Drawing/DrawImageTests.cs 98.97% <100%> (ø) ⬆️
src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs 95.33% <100%> (+0.8%) ⬆️
...ts/ImageSharp.Tests/Formats/Bmp/BmpEncoderTests.cs 94.94% <86.66%> (-3.69%) ⬇️
...geSharp/PixelFormats/PixelImplementations/Gray8.cs 79.59% <0%> (-2.05%) ⬇️
.../Processing/Processors/Quantization/WuQuantizer.cs 100% <0%> (+15%) ⬆️

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 ef736e0...bb8911d. Read the comment docs.

@brianpopow
Copy link
Collaborator Author

I would like to add two additional test cases to test the quantization of a 32 bit color image to a 8 bit color image see:#10. This may require again comparing with a tolerance, because quantization could produce different results on .net462 vs netcoreapp2.1, but i think thats still better than not testing it.

Or is it maybe enough that the quantization processors already are tested?

@JimBobSquarePants
Copy link
Member

@brianpopow I've merged those images for you 👍

@brianpopow brianpopow changed the title WIP: Not using quantization for Grey8 images when encoding 8Bit Bitmaps Not using quantization for Grey8 images when encoding 8Bit Bitmaps May 18, 2019
@antonfirsov
Copy link
Member

antonfirsov commented May 18, 2019

@brianpopow 0.6686% difference is being reported on 32bit .NET 4.7.2. Can you reproduce this locally by enforcing 32 bit execution?

@brianpopow
Copy link
Collaborator Author

@antonfirsov yes this time i can actually reproduce it locally. I will try to see if i can find out why this is happening.

@brianpopow
Copy link
Collaborator Author

brianpopow commented May 18, 2019

@antonfirsov it is, what you already said previously, the quantization produces slightly different results on net472 than on netcore. It looks to me as if the quantized colors are in many case (not all) identical in net472 and netcore, but they appear in a slightly different position in the palette. For example:

net472 : idx: 112, R: 237, G: 144, B: 144
netcore: idx: 112, R: 128, G: 55, B: 128
---------------------------------------------
net472 : idx: 113, R: 128, G: 55, B: 128
netcore: idx: 113, R: 237, G: 144, B: 144
---------------------------------------------
net472 : idx: 115, R: 10, G: 99, B: 99
netcore: idx: 115, R: 221, G: 99, B: 99
---------------------------------------------
net472 : idx: 116, R: 221, G: 99, B: 99
netcore: idx: 116, R: 10, G: 99, B: 99
---------------------------------------------

Here is a zip file containing the quantized palette of net472 and netcore21. Also a comparison of which pixels differ.
[quantize_issue_net472.zip] https://github.com/SixLabors/ImageSharp/files/3194282/quantize_issue_net472.zip)

I will increase the tolerance of the bitmap color encoding test further.
I will remove the tests, i dont think its useful with such a high tolerance.

@JimBobSquarePants
Copy link
Member

There’s a lot of floating point calculation going on in Wu which will be causing the issue. If the output looks ok I’m good with dropping the tests.

@antonfirsov
Copy link
Member

antonfirsov commented May 19, 2019

My tecnhique is to check TestEnvironment.Is64BitProcess at the beginning of the test. This way we can keep the coverage for conforming platforms.

@brianpopow
Copy link
Collaborator Author

@antonfirsov ok that makes sense, i will do that.

for (int y = image.Height - 1; y >= 0; y--)
{
Span<TPixel> inputPixelRow = image.GetPixelRowSpan(y);
PixelOperations<TPixel>.Instance.ToGray8Bytes(
Copy link
Member

Choose a reason for hiding this comment

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

Can't we replace this with inputPixelRow.AsBytes().CopyTo(outputPixelRow) here? Seems more explanatory about our intention.

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 can not find AsBytes(), is that an extension method im missing?

Copy link
Member

Choose a reason for hiding this comment

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

Apologies, it's MemoryMarshal.AsBytes(spanOfThings) 😄

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 that, please check it again.

Copy link
Member

Choose a reason for hiding this comment

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

Looks very good, thanks!

@brianpopow
Copy link
Collaborator Author

@antonfirsov i was unsure about DrawImageTests.cs while resolving the merge conflict: should this tests be removed or should we keep it?

@antonfirsov
Copy link
Member

DrawImageTests should be kept in it's original form, strange you had a conflict here. Can you easily revert all changes on that class? Or just replace the code in your file with the code on current master?

@brianpopow
Copy link
Collaborator Author

after i integrated the master branch the DrawImageTests.cs was named: DrawImageTest.cs (without an s), so the tests failed because the reference images could not be found. I just changed that to fix the failing tests.
I will take the code from master

@antonfirsov
Copy link
Member

All good now! Thanks a lot for taking the time, and sorry for the conflicts!

@antonfirsov antonfirsov merged commit 2b5a575 into SixLabors:master May 19, 2019
antonfirsov added a commit to antonfirsov/ImageSharp that referenced this pull request Nov 11, 2019
…izeOnGray8

Not using quantization for Grey8 images when encoding 8Bit Bitmaps
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.

3 participants