/// <inheritdoc /> public ValueTask InvokeAsync(TiffImageDecoderContext context, ITiffImageDecoderPipelineNode next) { if (context is null) { throw new ArgumentNullException(nameof(context)); } if (next is null) { throw new ArgumentNullException(nameof(next)); } int skippedRowOffset = context.SourceImageSize.Width * context.SourceReadOffset.Y; int planarByteCount = context.SourceImageSize.Width * context.SourceImageSize.Height; ReadOnlySpan <byte> sourceSpan = context.UncompressedData.Span; ReadOnlySpan <byte> sourceC = sourceSpan.Slice(0, planarByteCount); ReadOnlySpan <byte> sourceM = sourceSpan.Slice(planarByteCount, planarByteCount); ReadOnlySpan <byte> sourceY = sourceSpan.Slice(2 * planarByteCount, planarByteCount); ReadOnlySpan <byte> sourceK = sourceSpan.Slice(3 * planarByteCount, planarByteCount); using TiffPixelBufferWriter <TiffCmyk32> writer = context.GetWriter <TiffCmyk32>(); int rows = context.ReadSize.Height; int cols = context.ReadSize.Width; for (int row = 0; row < rows; row++) { using TiffPixelSpanHandle <TiffCmyk32> pixelSpanHandle = writer.GetRowSpan(row); Span <TiffCmyk32> rowDestinationSpan = pixelSpanHandle.GetSpan(); int rowOffset = skippedRowOffset + row * context.SourceImageSize.Width + context.SourceReadOffset.X; for (int col = 0; col < cols; col++) { int componentOffset = rowOffset + col; rowDestinationSpan[col] = new TiffCmyk32(sourceC[componentOffset], sourceM[componentOffset], sourceY[componentOffset], sourceK[componentOffset]); } } return(next.RunAsync(context)); }
public void TestCmyk32() { Assert.Equal(4, Unsafe.SizeOf <TiffCmyk32>()); var defaultPixel = default(TiffCmyk32); Assert.Equal(0, defaultPixel.C); Assert.Equal(0, defaultPixel.M); Assert.Equal(0, defaultPixel.Y); Assert.Equal(0, defaultPixel.K); var pixel1 = new TiffCmyk32(0x12, 0x34, 0x56, 0x78); Assert.Equal(0x12, pixel1.C); Assert.Equal(0x34, pixel1.M); Assert.Equal(0x56, pixel1.Y); Assert.Equal(0x78, pixel1.K); Assert.False(pixel1.Equals(defaultPixel)); Assert.False(defaultPixel.Equals(pixel1)); Assert.False(pixel1 == defaultPixel); Assert.False(defaultPixel == pixel1); Assert.True(pixel1 != defaultPixel); Assert.True(defaultPixel != pixel1); Assert.False(pixel1.GetHashCode() == defaultPixel.GetHashCode()); var pixel2 = new TiffCmyk32(0x12, 0x34, 0x56, 0x78); Assert.True(pixel1.Equals(pixel2)); Assert.True(pixel2.Equals(pixel1)); Assert.True(pixel1 == pixel2); Assert.True(pixel2 == pixel1); Assert.False(pixel1 != pixel2); Assert.False(pixel2 != pixel1); Assert.True(pixel1.GetHashCode() == pixel2.GetHashCode()); }