mirror of https://github.com/SixLabors/ImageSharp
Browse Source
These should be correct. I couldn't figure out how to test the values though as I can't remember what format each component array is in. Pretty sure in CMYK it's actually Ycc + inverted K.pull/322/head
3 changed files with 93 additions and 1 deletions
@ -0,0 +1,46 @@ |
|||||
|
using System; |
||||
|
using System.Numerics; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder |
||||
|
{ |
||||
|
internal abstract partial class JpegColorConverter |
||||
|
{ |
||||
|
private class FromCmyk : JpegColorConverter |
||||
|
{ |
||||
|
public FromCmyk() |
||||
|
: base(JpegColorSpace.Cmyk) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public override void ConvertToRGBA(ComponentValues values, Span<Vector4> result) |
||||
|
{ |
||||
|
// TODO: We can optimize a lot here with Vector<float> and SRCS.Unsafe()!
|
||||
|
ReadOnlySpan<float> cVals = values.Component0; |
||||
|
ReadOnlySpan<float> mVals = values.Component1; |
||||
|
ReadOnlySpan<float> yVals = values.Component2; |
||||
|
ReadOnlySpan<float> kVals = values.Component3; |
||||
|
|
||||
|
var v = new Vector4(0, 0, 0, 1F); |
||||
|
|
||||
|
var scale = new Vector4(1 / 255F, 1 / 255F, 1 / 255F, 1F); |
||||
|
|
||||
|
for (int i = 0; i < result.Length; i++) |
||||
|
{ |
||||
|
float c = cVals[i]; |
||||
|
float m = mVals[i]; |
||||
|
float y = yVals[i]; |
||||
|
float k = kVals[i] / 255F; |
||||
|
|
||||
|
v.X = c * k; |
||||
|
v.Y = m * k; |
||||
|
v.Z = y * k; |
||||
|
v.W = 1F; |
||||
|
|
||||
|
v *= scale; |
||||
|
|
||||
|
result[i] = v; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,46 @@ |
|||||
|
using System; |
||||
|
using System.Numerics; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Formats.Jpeg.Common.Decoder |
||||
|
{ |
||||
|
internal abstract partial class JpegColorConverter |
||||
|
{ |
||||
|
private class FromYccK : JpegColorConverter |
||||
|
{ |
||||
|
public FromYccK() |
||||
|
: base(JpegColorSpace.Ycck) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public override void ConvertToRGBA(ComponentValues values, Span<Vector4> result) |
||||
|
{ |
||||
|
// TODO: We can optimize a lot here with Vector<float> and SRCS.Unsafe()!
|
||||
|
ReadOnlySpan<float> yVals = values.Component0; |
||||
|
ReadOnlySpan<float> cbVals = values.Component1; |
||||
|
ReadOnlySpan<float> crVals = values.Component2; |
||||
|
ReadOnlySpan<float> kVals = values.Component3; |
||||
|
|
||||
|
var v = new Vector4(0, 0, 0, 1F); |
||||
|
|
||||
|
var scale = new Vector4(1 / 255F, 1 / 255F, 1 / 255F, 1F); |
||||
|
|
||||
|
for (int i = 0; i < result.Length; i++) |
||||
|
{ |
||||
|
float y = yVals[i]; |
||||
|
float cb = cbVals[i] - 128F; |
||||
|
float cr = crVals[i] - 128F; |
||||
|
float k = kVals[i] / 255F; |
||||
|
|
||||
|
v.X = (255F - MathF.Round(y + (1.402F * cr), MidpointRounding.AwayFromZero)) * k; |
||||
|
v.Y = (255F - MathF.Round(y - (0.344136F * cb) - (0.714136F * cr), MidpointRounding.AwayFromZero)) * k; |
||||
|
v.Z = (255F - MathF.Round(y + (1.772F * cb), MidpointRounding.AwayFromZero)) * k; |
||||
|
v.W = 1F; |
||||
|
|
||||
|
v *= scale; |
||||
|
|
||||
|
result[i] = v; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue