|
1 | 1 | // Copyright (c) Six Labors. |
2 | 2 | // Licensed under the Six Labors Split License. |
| 3 | + |
3 | 4 | #nullable disable |
4 | 5 |
|
5 | 6 | using System.Buffers; |
@@ -48,31 +49,53 @@ public override void Decode(ReadOnlySpan<byte> data, Buffer2D<TPixel> pixels, in |
48 | 49 |
|
49 | 50 | using IMemoryOwner<Vector4> vectors = hasAssociatedAlpha ? this.memoryAllocator.Allocate<Vector4>(width) : null; |
50 | 51 | Span<Vector4> vectorsSpan = hasAssociatedAlpha ? vectors.GetSpan() : []; |
51 | | - for (int y = top; y < top + height; y++) |
52 | | - { |
53 | | - Span<TPixel> pixelRow = pixels.DangerousGetRowSpan(y).Slice(left, width); |
54 | 52 |
|
55 | | - if (this.isBigEndian) |
| 53 | + if (this.isBigEndian) |
| 54 | + { |
| 55 | + if (hasAssociatedAlpha) |
56 | 56 | { |
57 | | - for (int x = 0; x < pixelRow.Length; x++) |
| 57 | + for (int y = top; y < top + height; y++) |
58 | 58 | { |
59 | | - ushort r = TiffUtilities.ConvertToUShortBigEndian(data.Slice(offset, 2)); |
60 | | - offset += 2; |
61 | | - ushort g = TiffUtilities.ConvertToUShortBigEndian(data.Slice(offset, 2)); |
62 | | - offset += 2; |
63 | | - ushort b = TiffUtilities.ConvertToUShortBigEndian(data.Slice(offset, 2)); |
64 | | - offset += 2; |
65 | | - ushort a = TiffUtilities.ConvertToUShortBigEndian(data.Slice(offset, 2)); |
66 | | - offset += 2; |
67 | | - |
68 | | - pixelRow[x] = hasAssociatedAlpha |
69 | | - ? TiffUtilities.ColorFromRgba64Premultiplied<TPixel>(r, g, b, a) |
70 | | - : TPixel.FromRgba64(new Rgba64(r, g, b, a)); |
| 59 | + Span<TPixel> pixelRow = pixels.DangerousGetRowSpan(y).Slice(left, width); |
| 60 | + |
| 61 | + for (int x = 0; x < pixelRow.Length; x++) |
| 62 | + { |
| 63 | + ushort r = TiffUtilities.ConvertToUShortBigEndian(data.Slice(offset, 2)); |
| 64 | + ushort g = TiffUtilities.ConvertToUShortBigEndian(data.Slice(offset + 2, 2)); |
| 65 | + ushort b = TiffUtilities.ConvertToUShortBigEndian(data.Slice(offset + 4, 2)); |
| 66 | + ushort a = TiffUtilities.ConvertToUShortBigEndian(data.Slice(offset + 6, 2)); |
| 67 | + offset += 8; |
| 68 | + |
| 69 | + pixelRow[x] = TiffUtilities.ColorFromRgba64Premultiplied<TPixel>(r, g, b, a); |
| 70 | + } |
71 | 71 | } |
72 | 72 | } |
73 | 73 | else |
74 | 74 | { |
| 75 | + for (int y = top; y < top + height; y++) |
| 76 | + { |
| 77 | + Span<TPixel> pixelRow = pixels.DangerousGetRowSpan(y).Slice(left, width); |
| 78 | + |
| 79 | + for (int x = 0; x < pixelRow.Length; x++) |
| 80 | + { |
| 81 | + ushort r = TiffUtilities.ConvertToUShortBigEndian(data.Slice(offset, 2)); |
| 82 | + ushort g = TiffUtilities.ConvertToUShortBigEndian(data.Slice(offset + 2, 2)); |
| 83 | + ushort b = TiffUtilities.ConvertToUShortBigEndian(data.Slice(offset + 4, 2)); |
| 84 | + ushort a = TiffUtilities.ConvertToUShortBigEndian(data.Slice(offset + 6, 2)); |
| 85 | + offset += 8; |
| 86 | + |
| 87 | + pixelRow[x] = TPixel.FromRgba64(new Rgba64(r, g, b, a)); |
| 88 | + } |
| 89 | + } |
| 90 | + } |
| 91 | + } |
| 92 | + else |
| 93 | + { |
| 94 | + for (int y = top; y < top + height; y++) |
| 95 | + { |
| 96 | + Span<TPixel> pixelRow = pixels.DangerousGetRowSpan(y).Slice(left, width); |
75 | 97 | int byteCount = pixelRow.Length * 8; |
| 98 | + |
76 | 99 | PixelOperations<TPixel>.Instance.FromRgba64Bytes( |
77 | 100 | this.configuration, |
78 | 101 | data.Slice(offset, byteCount), |
|
0 commit comments