Browse Source

Fix todo's

pull/1781/head
James Jackson-South 5 years ago
parent
commit
743cd629c0
  1. 38
      src/ImageSharp/Formats/Png/PngEncoderCore.cs

38
src/ImageSharp/Formats/Png/PngEncoderCore.cs

@ -268,35 +268,27 @@ namespace SixLabors.ImageSharp.Formats.Png
if (this.use16Bit) if (this.use16Bit)
{ {
// 16 bit grayscale + alpha // 16 bit grayscale + alpha
// TODO: Should we consider in the future a GrayAlpha32 type. using IMemoryOwner<La32> laBuffer = this.memoryAllocator.Allocate<La32>(rowSpan.Length);
using (IMemoryOwner<Rgba64> rgbaBuffer = this.memoryAllocator.Allocate<Rgba64>(rowSpan.Length)) Span<La32> laSpan = laBuffer.GetSpan();
{ ref La32 laRef = ref MemoryMarshal.GetReference(laSpan);
Span<Rgba64> rgbaSpan = rgbaBuffer.GetSpan(); PixelOperations<TPixel>.Instance.ToLa32(this.configuration, rowSpan, laSpan);
ref Rgba64 rgbaRef = ref MemoryMarshal.GetReference(rgbaSpan);
PixelOperations<TPixel>.Instance.ToRgba64(this.configuration, rowSpan, rgbaSpan);
// Can't map directly to byte array as it's big endian. // Can't map directly to byte array as it's big endian.
for (int x = 0, o = 0; x < rgbaSpan.Length; x++, o += 4) for (int x = 0, o = 0; x < laSpan.Length; x++, o += 4)
{ {
Rgba64 rgba = Unsafe.Add(ref rgbaRef, x); La32 la = Unsafe.Add(ref laRef, x);
ushort luminance = ColorNumerics.Get16BitBT709Luminance(rgba.R, rgba.G, rgba.B); BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o, 2), la.L);
BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o, 2), luminance); BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o + 2, 2), la.A);
BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o + 2, 2), rgba.A);
}
} }
} }
else else
{ {
// 8 bit grayscale + alpha // 8 bit grayscale + alpha
// TODO: Should we consider in the future a GrayAlpha16 type. PixelOperations<TPixel>.Instance.ToLa16Bytes(
Rgba32 rgba = default; this.configuration,
for (int x = 0, o = 0; x < rowSpan.Length; x++, o += 2) rowSpan,
{ rawScanlineSpan,
Unsafe.Add(ref rowSpanRef, x).ToRgba32(ref rgba); rowSpan.Length);
Unsafe.Add(ref rawScanlineSpanRef, o) =
ColorNumerics.Get8BitBT709Luminance(rgba.R, rgba.G, rgba.B);
Unsafe.Add(ref rawScanlineSpanRef, o + 1) = rgba.A;
}
} }
} }
} }

Loading…
Cancel
Save