Browse Source

Fix failing tests

pull/2511/head
James Jackson-South 3 years ago
parent
commit
3bc12e43ca
  1. 2
      src/ImageSharp/Formats/Png/PngDecoderCore.cs
  2. 67
      src/ImageSharp/Formats/Png/PngScanlineProcessor.cs

2
src/ImageSharp/Formats/Png/PngDecoderCore.cs

@ -935,7 +935,6 @@ internal sealed class PngDecoderCore : IImageDecoderInternals
case PngColorType.RgbWithAlpha: case PngColorType.RgbWithAlpha:
PngScanlineProcessor.ProcessRgbaScanline( PngScanlineProcessor.ProcessRgbaScanline(
this.configuration,
this.header.BitDepth, this.header.BitDepth,
in frameControl, in frameControl,
scanlineSpan, scanlineSpan,
@ -1035,7 +1034,6 @@ internal sealed class PngDecoderCore : IImageDecoderInternals
case PngColorType.RgbWithAlpha: case PngColorType.RgbWithAlpha:
PngScanlineProcessor.ProcessInterlacedRgbaScanline( PngScanlineProcessor.ProcessInterlacedRgbaScanline(
this.configuration,
this.header.BitDepth, this.header.BitDepth,
in frameControl, in frameControl,
scanlineSpan, scanlineSpan,

67
src/ImageSharp/Formats/Png/PngScanlineProcessor.cs

@ -41,7 +41,7 @@ internal static class PngScanlineProcessor
Color? transparentColor) Color? transparentColor)
where TPixel : unmanaged, IPixel<TPixel> where TPixel : unmanaged, IPixel<TPixel>
{ {
uint offset = pixelOffset + (uint)frameControl.XOffset; uint offset = pixelOffset + frameControl.XOffset;
TPixel pixel = default; TPixel pixel = default;
ref byte scanlineSpanRef = ref MemoryMarshal.GetReference(scanlineSpan); ref byte scanlineSpanRef = ref MemoryMarshal.GetReference(scanlineSpan);
ref TPixel rowSpanRef = ref MemoryMarshal.GetReference(rowSpan); ref TPixel rowSpanRef = ref MemoryMarshal.GetReference(rowSpan);
@ -132,7 +132,7 @@ internal static class PngScanlineProcessor
uint bytesPerSample) uint bytesPerSample)
where TPixel : unmanaged, IPixel<TPixel> where TPixel : unmanaged, IPixel<TPixel>
{ {
uint offset = pixelOffset + (uint)frameControl.XOffset; uint offset = pixelOffset + frameControl.XOffset;
TPixel pixel = default; TPixel pixel = default;
ref byte scanlineSpanRef = ref MemoryMarshal.GetReference(scanlineSpan); ref byte scanlineSpanRef = ref MemoryMarshal.GetReference(scanlineSpan);
ref TPixel rowSpanRef = ref MemoryMarshal.GetReference(rowSpan); ref TPixel rowSpanRef = ref MemoryMarshal.GetReference(rowSpan);
@ -242,7 +242,7 @@ internal static class PngScanlineProcessor
Color? transparentColor) Color? transparentColor)
where TPixel : unmanaged, IPixel<TPixel> where TPixel : unmanaged, IPixel<TPixel>
{ {
uint offset = pixelOffset + (uint)frameControl.XOffset; uint offset = pixelOffset + frameControl.XOffset;
TPixel pixel = default; TPixel pixel = default;
ref byte scanlineSpanRef = ref MemoryMarshal.GetReference(scanlineSpan); ref byte scanlineSpanRef = ref MemoryMarshal.GetReference(scanlineSpan);
@ -266,20 +266,18 @@ internal static class PngScanlineProcessor
} }
else else
{ {
// Rgb24 rgb = default; // TODO: Investigate reintroducing bulk operations optimization here.
// int o = 0; Rgb24 rgb = default;
// for (nuint x = offset; x < frameControl.XLimit; x += increment, o += bytesPerPixel) int o = 0;
// { for (nuint x = offset; x < frameControl.XMax; x += increment, o += bytesPerPixel)
// rgb.R = Unsafe.Add(ref scanlineSpanRef, (uint)o); {
// rgb.G = Unsafe.Add(ref scanlineSpanRef, (uint)(o + bytesPerSample)); rgb.R = Unsafe.Add(ref scanlineSpanRef, (uint)o);
// rgb.B = Unsafe.Add(ref scanlineSpanRef, (uint)(o + (2 * bytesPerSample))); rgb.G = Unsafe.Add(ref scanlineSpanRef, (uint)(o + bytesPerSample));
rgb.B = Unsafe.Add(ref scanlineSpanRef, (uint)(o + (2 * bytesPerSample)));
// pixel.FromRgb24(rgb);
// Unsafe.Add(ref rowSpanRef, x) = pixel; pixel.FromRgb24(rgb);
// } Unsafe.Add(ref rowSpanRef, x) = pixel;
}
// PixelOperations<TPixel>.Instance.FromRgb24Bytes(configuration, scanlineSpan, rowSpan, header.Width);
PixelOperations<TPixel>.Instance.FromRgb24Bytes(configuration, scanlineSpan, rowSpan[(int)offset..], (int)frameControl.XMax);
} }
return; return;
@ -325,7 +323,6 @@ internal static class PngScanlineProcessor
} }
public static void ProcessRgbaScanline<TPixel>( public static void ProcessRgbaScanline<TPixel>(
Configuration configuration,
int bitDepth, int bitDepth,
in FrameControl frameControl, in FrameControl frameControl,
ReadOnlySpan<byte> scanlineSpan, ReadOnlySpan<byte> scanlineSpan,
@ -334,7 +331,6 @@ internal static class PngScanlineProcessor
int bytesPerSample) int bytesPerSample)
where TPixel : unmanaged, IPixel<TPixel> => where TPixel : unmanaged, IPixel<TPixel> =>
ProcessInterlacedRgbaScanline( ProcessInterlacedRgbaScanline(
configuration,
bitDepth, bitDepth,
frameControl, frameControl,
scanlineSpan, scanlineSpan,
@ -345,7 +341,6 @@ internal static class PngScanlineProcessor
bytesPerSample); bytesPerSample);
public static void ProcessInterlacedRgbaScanline<TPixel>( public static void ProcessInterlacedRgbaScanline<TPixel>(
Configuration configuration,
int bitDepth, int bitDepth,
in FrameControl frameControl, in FrameControl frameControl,
ReadOnlySpan<byte> scanlineSpan, ReadOnlySpan<byte> scanlineSpan,
@ -356,7 +351,7 @@ internal static class PngScanlineProcessor
int bytesPerSample) int bytesPerSample)
where TPixel : unmanaged, IPixel<TPixel> where TPixel : unmanaged, IPixel<TPixel>
{ {
uint offset = pixelOffset + (uint)frameControl.XOffset; uint offset = pixelOffset + frameControl.XOffset;
TPixel pixel = default; TPixel pixel = default;
ref TPixel rowSpanRef = ref MemoryMarshal.GetReference(rowSpan); ref TPixel rowSpanRef = ref MemoryMarshal.GetReference(rowSpan);
@ -377,22 +372,20 @@ internal static class PngScanlineProcessor
} }
else else
{ {
// ref byte scanlineSpanRef = ref MemoryMarshal.GetReference(scanlineSpan); // TODO: Investigate reintroducing bulk operations optimization here.
// Rgba32 rgba = default; ref byte scanlineSpanRef = ref MemoryMarshal.GetReference(scanlineSpan);
// int o = 0; Rgba32 rgba = default;
// for (nuint x = offset; x < frameControl.XLimit; x += increment, o += bytesPerPixel) int o = 0;
// { for (nuint x = offset; x < frameControl.XMax; x += increment, o += bytesPerPixel)
// rgba.R = Unsafe.Add(ref scanlineSpanRef, (uint)o); {
// rgba.G = Unsafe.Add(ref scanlineSpanRef, (uint)(o + bytesPerSample)); rgba.R = Unsafe.Add(ref scanlineSpanRef, (uint)o);
// rgba.B = Unsafe.Add(ref scanlineSpanRef, (uint)(o + (2 * bytesPerSample))); rgba.G = Unsafe.Add(ref scanlineSpanRef, (uint)(o + bytesPerSample));
// rgba.A = Unsafe.Add(ref scanlineSpanRef, (uint)(o + (3 * bytesPerSample))); rgba.B = Unsafe.Add(ref scanlineSpanRef, (uint)(o + (2 * bytesPerSample)));
rgba.A = Unsafe.Add(ref scanlineSpanRef, (uint)(o + (3 * bytesPerSample)));
// pixel.FromRgba32(rgba);
// Unsafe.Add(ref rowSpanRef, x) = pixel; pixel.FromRgba32(rgba);
// } Unsafe.Add(ref rowSpanRef, x) = pixel;
}
// PixelOperations<TPixel>.Instance.FromRgba32Bytes(configuration, scanlineSpan, rowSpan, header.Width);
PixelOperations<TPixel>.Instance.FromRgba32Bytes(configuration, scanlineSpan, rowSpan[(int)offset..], (int)frameControl.XMax);
} }
} }
} }

Loading…
Cancel
Save