Browse Source

Use distinct read-only spans

pull/3153/head
winscripter 1 month ago
parent
commit
f71bab20a6
  1. 26
      src/ImageSharp/Formats/Jxl/IO/FrameHeader/JxlColorTransformHelpers.cs

26
src/ImageSharp/Formats/Jxl/IO/FrameHeader/JxlColorTransformHelpers.cs

@ -8,32 +8,24 @@ namespace SixLabors.ImageSharp.Formats.Jxl.IO.FrameHeader;
/// </summary> /// </summary>
internal static class JxlColorTransformHelpers internal static class JxlColorTransformHelpers
{ {
private static readonly int[][] JpegOrders = private static ReadOnlySpan<int> Grayscale => [0, 0, 0];
[
[0, 0, 0], // Grayscale private static ReadOnlySpan<int> YCbCr => [1, 0, 2];
[1, 0, 2], // Y'Cb'Cr
[0, 1, 2], // None private static ReadOnlySpan<int> None => [0, 1, 2];
[0, 1, 2] // Anything else
];
public static ReadOnlySpan<int> GetJpegOrder(JxlColorTransform transform, bool isGraysacle) public static ReadOnlySpan<int> GetJpegOrder(JxlColorTransform transform, bool isGraysacle)
{ {
if (isGraysacle) if (isGraysacle)
{ {
return JpegOrders[0]; return Grayscale;
} }
if (transform == JxlColorTransform.YCbCr) if (transform == JxlColorTransform.YCbCr)
{ {
return JpegOrders[1]; return YCbCr;
}
else if (transform == JxlColorTransform.None)
{
return JpegOrders[2];
}
else
{
return JpegOrders[3];
} }
return None;
} }
} }

Loading…
Cancel
Save