#718 #730: Add Gray8 and Gray16 Pixel Formats and clean up IPixel#729
#718 #730: Add Gray8 and Gray16 Pixel Formats and clean up IPixel#729JimBobSquarePants merged 34 commits intoSixLabors:masterfrom
Conversation
AND add unit tests AND fix Gray16 implementation (constructor takes ushort, not byte) AND fix Gray8 and Gray16 Pack (do not scale by sum)
JimBobSquarePants
left a comment
There was a problem hiding this comment.
I've started a review but I can see quite a lot of places where the maths are incorrect. It's probably quicker for me to push the changes to the code myself so am gonna jump in. Hope you don't mind!
|
|
||
| /// <inheritdoc/> | ||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| public void ToGray8(ref Gray8 dest) => dest.PackFromScaledVector4(this.ToScaledVector4()); |
There was a problem hiding this comment.
This can be optimized.
src/ImageSharp/PixelFormats/Gray8.cs
Outdated
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| public void PackFromRgba32(Rgba32 source) | ||
| { | ||
| this.PackedValue = Pack(source.R, source.G, source.B); |
There was a problem hiding this comment.
This and others is incorrect. Will lead to a packed value of 255.
src/ImageSharp/PixelFormats/Gray8.cs
Outdated
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| public void ToRgb48(ref Rgb48 dest) | ||
| { | ||
| ushort gray = (ushort)(this.PackedValue * 255); |
src/ImageSharp/PixelFormats/Gray8.cs
Outdated
| /// <param name="b">Blue value of the color to pack.</param> | ||
| /// <returns>The <see cref="byte"/> containing the packed value.</returns> | ||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| private static byte Pack(float r, float g, float b) |
There was a problem hiding this comment.
This only works with Vector4 but is being used for Rgba32 etc.
|
I'm gonna do #730 at the same time otherwise we're writing code we'll immediately delete. |
|
@jongleur1983 Ok. So I've fixed up all the pixels formats and commented out all the old tests. I need to do two things now to complete this PR:
|
|
Got four tests failing due to https://ci.appveyor.com/project/six-labors/imagesharp/builds/19386791/job/x9ru3njufhn9ec6j/tests |
|
Yeah hex is better for this purpose |
Codecov Report
@@ Coverage Diff @@
## master #729 +/- ##
==========================================
- Coverage 89.3% 88.34% -0.96%
==========================================
Files 973 982 +9
Lines 42976 41592 -1384
Branches 3047 3126 +79
==========================================
- Hits 38381 36746 -1635
- Misses 3913 4129 +216
- Partials 682 717 +35
Continue to review full report at Codecov.
|
|
Much happier with this now. The structure has much greater conformity and all IPixel operations are covered in both singular and bulk forms. Gotta fix up the |
|
Ok, actually this might be good, I haven't noticed the new optimized bulk implementations! So never mind my comment regarding |
|
@antonfirsov Yeah, all the |
|
@JimBobSquarePants in this benchmark I emulated a scenario which is similar to the It turns out, that even in these cases the retval version is significantly slower. Also benchmarked The question is when? We have two options:
|
|
@antonfirsov Those results are extraordinary, I'm very surprised! Let's do it here now. A new PR will be another very large one again probably too large to digest. We know where we are here and can review knowing exactly what we are looking at having recently worked on the files. ScaledVector4 will have to be updated also. |
|
One possible explanation is that JIT is not capable for Return value optimization in most cases.
Edit: |
|
I was tempted to do it all here but for sanities sake lets do |
|
@JimBobSquarePants my feeling is that it would be much simpler to merge this as is, right after #742 and carry out all my proposed API changes together in a new PR. |
|
@antonfirsov works for me! 👍 |
# Conflicts: # src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs # tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs
1 similar comment
|
@JimBobSquarePants any idea how to ping the CLA assistant? Pressing "Recheck PR-s" on it's UI did not help. |
|
OK, it seem there are still issues with service availability, let's check again after a few hours. |
|
@antonfirsov Github's having all sorts of issues just now. |
SixLabors#718 SixLabors#730: Add Gray8 and Gray16 Pixel Formats and clean up IPixel

Prerequisites
Description
Implements Pixel formats Gray8 and Gray16.
Where I knew how to do it I provided optimized conversion methods, where not I used the "fallback" strategy to convert from and to Vector4, as it's done for many other implementations as well.
Unit tests are based on some of the other Pixel formats tests. Not sure this is seen as sufficient though, please tell me if not.
I guess I have to squash commits again, but for review the individual commits may help so I'm happy to do so after a first review.