SixLabors / ImageSharp

:camera: A modern, cross-platform, 2D Graphics library for .NET
https://sixlabors.com/products/imagesharp/
Other
7.39k stars 851 forks source link

Simplify Color Space Conversion APIs #2739

Closed JimBobSquarePants closed 3 months ago

JimBobSquarePants commented 4 months ago

Prerequisites

Description

Note: I don't expect anyone to thoroughly review every file. It's far too big.

See https://github.com/SixLabors/ImageSharp/discussions/2531 for the original details. I've improved on the original design there by reducing the generic parameters required and removing the requirement for marker interfaces.

Replaces ColorSpaceConverter with ColorProfileConverter. The new generic API brings several advantages.

There's potential here now also for reusing the API to allow for converting between ICC profiles. We can use the information to create dynamically calculated working space inputs.

The new API is faster than the old implementation and alternative libraries.

BenchmarkDotNet v0.13.10, Windows 11 (10.0.22631.3593/23H2/2023Update/SunValley3)
11th Gen Intel Core i7-11370H 3.30GHz, 1 CPU, 8 logical and 4 physical cores
.NET SDK 8.0.300-preview.24203.14
  [Host]     : .NET 8.0.4 (8.0.424.16909), X64 RyuJIT AVX2
  DefaultJob : .NET 8.0.4 (8.0.424.16909), X64 RyuJIT AVX2

CieXyz => CieLab

Method Mean Error StdDev Ratio RatioSD
'Colourful Convert' 50.85 ns 0.720 ns 0.638 ns 1.00 0.00
'ImageSharp Convert Old' 64.99 ns 0.875 ns 0.819 ns 1.28 0.02
'ImageSharp Convert' 43.62 ns 0.864 ns 1.061 ns 0.86 0.02

CieXyz => HunterLab

Method Mean Error StdDev Ratio RatioSD
'Colourful Convert' 25.30 ns 0.517 ns 1.335 ns 1.00 0.00
'ImageSharp Convert' 13.51 ns 0.244 ns 0.217 ns 0.57 0.03

CieXyz => Lms

Method Mean Error StdDev Median Ratio RatioSD
'Colourful Convert' 28.653 ns 0.6023 ns 1.6487 ns 27.979 ns 1.00 0.00
'ImageSharp Convert' 8.215 ns 0.1884 ns 0.2821 ns 8.123 ns 0.29 0.02

Rgb Chromatic Adaption

Method Mean Error StdDev Ratio RatioSD
'Colourful Adapt' 347.4 ns 6.95 ns 12.70 ns 1.00 0.00
'ImageSharp Adapt' 261.8 ns 3.35 ns 2.97 ns 0.77 0.03
JimBobSquarePants commented 3 months ago

I think I'm gonna merge this tomorrow.