private static void UndoGray16Bit(Span <byte> pixelBytes, int width, bool isBigEndian) { int rowBytesCount = width * 2; int height = pixelBytes.Length / rowBytesCount; if (isBigEndian) { for (int y = 0; y < height; y++) { int offset = 0; Span <byte> rowBytes = pixelBytes.Slice(y * rowBytesCount, rowBytesCount); ushort pixelValue = TiffUtils.ConvertToUShortBigEndian(rowBytes.Slice(offset, 2)); offset += 2; for (int x = 1; x < width; x++) { Span <byte> rowSpan = rowBytes.Slice(offset, 2); ushort diff = TiffUtils.ConvertToUShortBigEndian(rowSpan); pixelValue += diff; BinaryPrimitives.WriteUInt16BigEndian(rowSpan, pixelValue); offset += 2; } } } else { for (int y = 0; y < height; y++) { int offset = 0; Span <byte> rowBytes = pixelBytes.Slice(y * rowBytesCount, rowBytesCount); ushort pixelValue = TiffUtils.ConvertToUShortLittleEndian(rowBytes.Slice(offset, 2)); offset += 2; for (int x = 1; x < width; x++) { Span <byte> rowSpan = rowBytes.Slice(offset, 2); ushort diff = TiffUtils.ConvertToUShortLittleEndian(rowSpan); pixelValue += diff; BinaryPrimitives.WriteUInt16LittleEndian(rowSpan, pixelValue); offset += 2; } } } }
/// <inheritdoc/> public override void Decode(ReadOnlySpan <byte> data, Buffer2D <TPixel> pixels, int left, int top, int width, int height) { // Note: due to an issue with netcore 2.1 and default values and unpredictable behavior with those, // we define our own defaults as a workaround. See: https://github.com/dotnet/runtime/issues/55623 Rgba64 rgba = TiffUtils.Rgba64Default; var color = default(TPixel); color.FromVector4(TiffUtils.Vector4Default); int offset = 0; for (int y = top; y < top + height; y++) { Span <TPixel> pixelRow = pixels.GetRowSpan(y).Slice(left, width); if (this.isBigEndian) { for (int x = 0; x < pixelRow.Length; x++) { ulong r = TiffUtils.ConvertToUShortBigEndian(data.Slice(offset, 2)); offset += 2; ulong g = TiffUtils.ConvertToUShortBigEndian(data.Slice(offset, 2)); offset += 2; ulong b = TiffUtils.ConvertToUShortBigEndian(data.Slice(offset, 2)); offset += 2; pixelRow[x] = TiffUtils.ColorFromRgba64(rgba, r, g, b, color); } } else { int byteCount = pixelRow.Length * 6; PixelOperations <TPixel> .Instance.FromRgb48Bytes( this.configuration, data.Slice(offset, byteCount), pixelRow, pixelRow.Length); offset += byteCount; } } }