Skip to content

Conversation

@antonfirsov
Copy link
Member

@antonfirsov antonfirsov commented May 11, 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

  • Next step in Epic: introduce pixel-agnostic API across the whole library #907
  • Adding a general Color struct with a hidden internal hi-res representation, that is convertible to all pixel types
    • Add implicit conversion methods to/from RGB(A)-like pixel types.
    • Add all color constants to this type. (Like Color.Black or Color.WebSafePalette)
  • Make all remaining processors and processing extensions in the ImageSharp package pixel-agnostic. Color parameters (including palette) are using the new Color type now.
  • Refactor quantization:
    • Use Color on all public API-s (Consequence: PaletteQuantizer<TPixel> has been dropped.)
    • Use ReadOnlyMemory<T> on public API-s instead of T[]
    • QuantizedFrame<T>.GetPixelSpan() returns ReadOnlySpan<T>. Populating the span is an implementation detail. Introduce IQuantizedFrame<T> to maintain clean abstractions here.
  • Miscellaneous chore work:
    • Rename ColorBuilder<T>.FromRGBA() to FromRgba
    • Move processing extension classes to a (non-namespace-providing) subfolder

Consequence on our terminlogy

Color ≠ Pixel any longer. Color is a general term, pixel is a representation drawable on an Image<TPixel>.

@codecov
Copy link

codecov bot commented May 11, 2019

Codecov Report

Merging #908 into master will decrease coverage by 0.42%.
The diff coverage is 98.02%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #908      +/-   ##
==========================================
- Coverage    89.6%   89.17%   -0.43%     
==========================================
  Files        1060     1079      +19     
  Lines       46542    47573    +1031     
  Branches     3268     3270       +2     
==========================================
+ Hits        41703    42425     +722     
- Misses       4128     4396     +268     
- Partials      711      752      +41
Impacted Files Coverage Δ
...harp/Processing/Extensions/ProcessingExtensions.cs 92.85% <ø> (ø)
...harp/Processing/Extensions/RotateFlipExtensions.cs 100% <ø> (ø)
...Sharp/Processing/Extensions/TransformExtensions.cs 100% <ø> (ø)
...Processing/Extensions/GaussianSharpenExtensions.cs 100% <ø> (ø)
...sing/Extensions/HistogramEqualizationExtensions.cs 50% <ø> (ø)
...ImageSharp/Processing/Extensions/FlipExtensions.cs 100% <ø> (ø)
...harp/Processing/Extensions/BlackWhiteExtensions.cs 100% <ø> (ø)
...eSharp/Processing/Extensions/ContrastExtensions.cs 100% <ø> (ø)
...ageSharp/Processing/Extensions/ResizeExtensions.cs 100% <ø> (ø)
...mageSharp/Processing/Extensions/SepiaExtensions.cs 100% <ø> (ø)
... and 158 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 25b3f75...d0466c4. Read the comment docs.

@codecov
Copy link

codecov bot commented May 11, 2019

Codecov Report

Merging #908 into master will decrease coverage by 0.32%.
The diff coverage is 98.2%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #908      +/-   ##
==========================================
- Coverage   89.61%   89.29%   -0.33%     
==========================================
  Files        1060     1079      +19     
  Lines       46586    47631    +1045     
  Branches     3272     3273       +1     
==========================================
+ Hits        41750    42530     +780     
- Misses       4125     4387     +262     
- Partials      711      714       +3
Impacted Files Coverage Δ
...harp/Processing/Extensions/ProcessingExtensions.cs 92.85% <ø> (ø)
...harp/Processing/Extensions/RotateFlipExtensions.cs 100% <ø> (ø)
...Sharp/Processing/Extensions/TransformExtensions.cs 100% <ø> (ø)
...Processing/Extensions/GaussianSharpenExtensions.cs 100% <ø> (ø)
...sing/Extensions/HistogramEqualizationExtensions.cs 50% <ø> (ø)
...ImageSharp/Processing/Extensions/FlipExtensions.cs 100% <ø> (ø)
...harp/Processing/Extensions/BlackWhiteExtensions.cs 100% <ø> (ø)
...eSharp/Processing/Extensions/ContrastExtensions.cs 100% <ø> (ø)
...ageSharp/Processing/Extensions/ResizeExtensions.cs 100% <ø> (ø)
...mageSharp/Processing/Extensions/SepiaExtensions.cs 100% <ø> (ø)
... and 144 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 2461da8...5931537. Read the comment docs.

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.

I absolutely love the direction this has gone. I think it's a quantum leap in usability. 👍

I think we can tighten up some of the code reuse though taking advantage of implicit casting. I'm happy to make those changes.

using (IFrameQuantizer<TPixel> palleteFrameQuantizer = palleteQuantizer.CreateFrameQuantizer(image.GetConfiguration()))
using (QuantizedFrame<TPixel> paletteQuantized = palleteFrameQuantizer.QuantizeFrame(frame))
using (IFrameQuantizer<TPixel> palleteFrameQuantizer =
new PaletteFrameQuantizer<TPixel>(this.quantizer.Diffuser, quantized.Palette))
Copy link
Member

Choose a reason for hiding this comment

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

This is all so much nicer! 😍

/// <param name="indexedPixels">The span of indexed pixels.</param>
/// <param name="stream">The stream to write to.</param>
public void Encode(Span<byte> indexedPixels, Stream stream)
public void Encode(ReadOnlySpan<byte> indexedPixels, Stream stream)
Copy link
Member

Choose a reason for hiding this comment

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

Good!

/// </summary>
/// <param name="source">The <see cref="Rgba64"/>.</param>
/// <returns>The <see cref="Color"/>.</returns>
public static implicit operator Color(Rgba64 source) => new Color(source);
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't these implicit operators be on the Pixel type instead of Color? there are alot more Pixel types after all.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point! I think I will change this.

# Conflicts:
#	src/ImageSharp/Processing/Processors/Quantization/QuantizedFrame{TPixel}.cs
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