mirror of https://github.com/SixLabors/ImageSharp
committed by
GitHub
32 changed files with 900 additions and 39 deletions
@ -0,0 +1,65 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System; |
|||
using SixLabors.ImageSharp.Formats.Tiff.Utils; |
|||
using SixLabors.ImageSharp.Memory; |
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation |
|||
{ |
|||
/// <summary>
|
|||
/// Implements the 'BlackIsZero' photometric interpretation for 24-bit grayscale images.
|
|||
/// </summary>
|
|||
internal class BlackIsZero24TiffColor<TPixel> : TiffBaseColorDecoder<TPixel> |
|||
where TPixel : unmanaged, IPixel<TPixel> |
|||
{ |
|||
private readonly bool isBigEndian; |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="BlackIsZero24TiffColor{TPixel}" /> class.
|
|||
/// </summary>
|
|||
/// <param name="isBigEndian">if set to <c>true</c> decodes the pixel data as big endian, otherwise as little endian.</param>
|
|||
public BlackIsZero24TiffColor(bool isBigEndian) => this.isBigEndian = isBigEndian; |
|||
|
|||
/// <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
|
|||
var color = default(TPixel); |
|||
color.FromVector4(TiffUtils.Vector4Default); |
|||
byte[] buffer = new byte[4]; |
|||
int bufferStartIdx = this.isBigEndian ? 1 : 0; |
|||
|
|||
Span<byte> bufferSpan = buffer.AsSpan(bufferStartIdx); |
|||
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++) |
|||
{ |
|||
data.Slice(offset, 3).CopyTo(bufferSpan); |
|||
ulong intensity = TiffUtils.ConvertToUIntBigEndian(buffer); |
|||
offset += 3; |
|||
|
|||
pixelRow[x] = TiffUtils.ColorScaleTo24Bit(intensity, color); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
for (int x = 0; x < pixelRow.Length; x++) |
|||
{ |
|||
data.Slice(offset, 3).CopyTo(bufferSpan); |
|||
ulong intensity = TiffUtils.ConvertToUIntLittleEndian(buffer); |
|||
offset += 3; |
|||
|
|||
pixelRow[x] = TiffUtils.ColorScaleTo24Bit(intensity, color); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,61 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System; |
|||
using System.Numerics; |
|||
using SixLabors.ImageSharp.Formats.Tiff.Utils; |
|||
using SixLabors.ImageSharp.Memory; |
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation |
|||
{ |
|||
/// <summary>
|
|||
/// Implements the 'BlackIsZero' photometric interpretation for 32-bit grayscale images.
|
|||
/// </summary>
|
|||
internal class BlackIsZero32TiffColor<TPixel> : TiffBaseColorDecoder<TPixel> |
|||
where TPixel : unmanaged, IPixel<TPixel> |
|||
{ |
|||
private readonly bool isBigEndian; |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="BlackIsZero32TiffColor{TPixel}" /> class.
|
|||
/// </summary>
|
|||
/// <param name="isBigEndian">if set to <c>true</c> decodes the pixel data as big endian, otherwise as little endian.</param>
|
|||
public BlackIsZero32TiffColor(bool isBigEndian) => this.isBigEndian = isBigEndian; |
|||
|
|||
/// <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
|
|||
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 intensity = TiffUtils.ConvertToUIntBigEndian(data.Slice(offset, 4)); |
|||
offset += 4; |
|||
|
|||
pixelRow[x] = TiffUtils.ColorScaleTo32Bit(intensity, color); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
for (int x = 0; x < pixelRow.Length; x++) |
|||
{ |
|||
ulong intensity = TiffUtils.ConvertToUIntLittleEndian(data.Slice(offset, 4)); |
|||
offset += 4; |
|||
|
|||
pixelRow[x] = TiffUtils.ColorScaleTo32Bit(intensity, color); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,82 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System; |
|||
using SixLabors.ImageSharp.Formats.Tiff.Utils; |
|||
using SixLabors.ImageSharp.Memory; |
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation |
|||
{ |
|||
/// <summary>
|
|||
/// Implements the 'RGB' photometric interpretation with 24 bits for each channel.
|
|||
/// </summary>
|
|||
internal class Rgb242424TiffColor<TPixel> : TiffBaseColorDecoder<TPixel> |
|||
where TPixel : unmanaged, IPixel<TPixel> |
|||
{ |
|||
private readonly bool isBigEndian; |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="Rgb242424TiffColor{TPixel}" /> class.
|
|||
/// </summary>
|
|||
/// <param name="isBigEndian">if set to <c>true</c> decodes the pixel data as big endian, otherwise as little endian.</param>
|
|||
public Rgb242424TiffColor(bool isBigEndian) => this.isBigEndian = isBigEndian; |
|||
|
|||
/// <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
|
|||
var color = default(TPixel); |
|||
color.FromVector4(TiffUtils.Vector4Default); |
|||
int offset = 0; |
|||
byte[] buffer = new byte[4]; |
|||
int bufferStartIdx = this.isBigEndian ? 1 : 0; |
|||
|
|||
Span<byte> bufferSpan = buffer.AsSpan(bufferStartIdx); |
|||
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++) |
|||
{ |
|||
data.Slice(offset, 3).CopyTo(bufferSpan); |
|||
ulong r = TiffUtils.ConvertToUIntBigEndian(buffer); |
|||
offset += 3; |
|||
|
|||
data.Slice(offset, 3).CopyTo(bufferSpan); |
|||
ulong g = TiffUtils.ConvertToUIntBigEndian(buffer); |
|||
offset += 3; |
|||
|
|||
data.Slice(offset, 3).CopyTo(bufferSpan); |
|||
ulong b = TiffUtils.ConvertToUIntBigEndian(buffer); |
|||
offset += 3; |
|||
|
|||
pixelRow[x] = TiffUtils.ColorScaleTo24Bit(r, g, b, color); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
for (int x = 0; x < pixelRow.Length; x++) |
|||
{ |
|||
data.Slice(offset, 3).CopyTo(bufferSpan); |
|||
ulong r = TiffUtils.ConvertToUIntLittleEndian(buffer); |
|||
offset += 3; |
|||
|
|||
data.Slice(offset, 3).CopyTo(bufferSpan); |
|||
ulong g = TiffUtils.ConvertToUIntLittleEndian(buffer); |
|||
offset += 3; |
|||
|
|||
data.Slice(offset, 3).CopyTo(bufferSpan); |
|||
ulong b = TiffUtils.ConvertToUIntLittleEndian(buffer); |
|||
offset += 3; |
|||
|
|||
pixelRow[x] = TiffUtils.ColorScaleTo24Bit(r, g, b, color); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,80 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System; |
|||
using System.Buffers; |
|||
using SixLabors.ImageSharp.Formats.Tiff.Utils; |
|||
using SixLabors.ImageSharp.Memory; |
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation |
|||
{ |
|||
/// <summary>
|
|||
/// Implements the 'RGB' photometric interpretation with 'Planar' layout for each color channel with 24 bit.
|
|||
/// </summary>
|
|||
internal class Rgb24PlanarTiffColor<TPixel> : TiffBasePlanarColorDecoder<TPixel> |
|||
where TPixel : unmanaged, IPixel<TPixel> |
|||
{ |
|||
private readonly bool isBigEndian; |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="Rgb24PlanarTiffColor{TPixel}" /> class.
|
|||
/// </summary>
|
|||
/// <param name="isBigEndian">if set to <c>true</c> decodes the pixel data as big endian, otherwise as little endian.</param>
|
|||
public Rgb24PlanarTiffColor(bool isBigEndian) => this.isBigEndian = isBigEndian; |
|||
|
|||
/// <inheritdoc/>
|
|||
public override void Decode(IMemoryOwner<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
|
|||
var color = default(TPixel); |
|||
color.FromVector4(TiffUtils.Vector4Default); |
|||
byte[] buffer = new byte[4]; |
|||
int bufferStartIdx = this.isBigEndian ? 1 : 0; |
|||
|
|||
Span<byte> redData = data[0].GetSpan(); |
|||
Span<byte> greenData = data[1].GetSpan(); |
|||
Span<byte> blueData = data[2].GetSpan(); |
|||
Span<byte> bufferSpan = buffer.AsSpan(bufferStartIdx); |
|||
|
|||
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++) |
|||
{ |
|||
redData.Slice(offset, 3).CopyTo(bufferSpan); |
|||
ulong r = TiffUtils.ConvertToUIntBigEndian(buffer); |
|||
greenData.Slice(offset, 3).CopyTo(bufferSpan); |
|||
ulong g = TiffUtils.ConvertToUIntBigEndian(buffer); |
|||
blueData.Slice(offset, 3).CopyTo(bufferSpan); |
|||
ulong b = TiffUtils.ConvertToUIntBigEndian(buffer); |
|||
|
|||
offset += 3; |
|||
|
|||
pixelRow[x] = TiffUtils.ColorScaleTo24Bit(r, g, b, color); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
for (int x = 0; x < pixelRow.Length; x++) |
|||
{ |
|||
redData.Slice(offset, 3).CopyTo(bufferSpan); |
|||
ulong r = TiffUtils.ConvertToUIntLittleEndian(buffer); |
|||
greenData.Slice(offset, 3).CopyTo(bufferSpan); |
|||
ulong g = TiffUtils.ConvertToUIntLittleEndian(buffer); |
|||
blueData.Slice(offset, 3).CopyTo(bufferSpan); |
|||
ulong b = TiffUtils.ConvertToUIntLittleEndian(buffer); |
|||
|
|||
offset += 3; |
|||
|
|||
pixelRow[x] = TiffUtils.ColorScaleTo24Bit(r, g, b, color); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,73 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System; |
|||
using SixLabors.ImageSharp.Formats.Tiff.Utils; |
|||
using SixLabors.ImageSharp.Memory; |
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation |
|||
{ |
|||
/// <summary>
|
|||
/// Implements the 'RGB' photometric interpretation with 32 bits for each channel.
|
|||
/// </summary>
|
|||
internal class Rgb323232TiffColor<TPixel> : TiffBaseColorDecoder<TPixel> |
|||
where TPixel : unmanaged, IPixel<TPixel> |
|||
{ |
|||
private readonly bool isBigEndian; |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="Rgb323232TiffColor{TPixel}" /> class.
|
|||
/// </summary>
|
|||
/// <param name="isBigEndian">if set to <c>true</c> decodes the pixel data as big endian, otherwise as little endian.</param>
|
|||
public Rgb323232TiffColor(bool isBigEndian) => this.isBigEndian = isBigEndian; |
|||
|
|||
/// <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
|
|||
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.ConvertToUIntBigEndian(data.Slice(offset, 4)); |
|||
offset += 4; |
|||
|
|||
ulong g = TiffUtils.ConvertToUIntBigEndian(data.Slice(offset, 4)); |
|||
offset += 4; |
|||
|
|||
ulong b = TiffUtils.ConvertToUIntBigEndian(data.Slice(offset, 4)); |
|||
offset += 4; |
|||
|
|||
pixelRow[x] = TiffUtils.ColorScaleTo32Bit(r, g, b, color); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
for (int x = 0; x < pixelRow.Length; x++) |
|||
{ |
|||
ulong r = TiffUtils.ConvertToUIntLittleEndian(data.Slice(offset, 4)); |
|||
offset += 4; |
|||
|
|||
ulong g = TiffUtils.ConvertToUIntLittleEndian(data.Slice(offset, 4)); |
|||
offset += 4; |
|||
|
|||
ulong b = TiffUtils.ConvertToUIntLittleEndian(data.Slice(offset, 4)); |
|||
offset += 4; |
|||
|
|||
pixelRow[x] = TiffUtils.ColorScaleTo32Bit(r, g, b, color); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,71 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System; |
|||
using System.Buffers; |
|||
using SixLabors.ImageSharp.Formats.Tiff.Utils; |
|||
using SixLabors.ImageSharp.Memory; |
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation |
|||
{ |
|||
/// <summary>
|
|||
/// Implements the 'RGB' photometric interpretation with 'Planar' layout for each color channel with 32 bit.
|
|||
/// </summary>
|
|||
internal class Rgb32PlanarTiffColor<TPixel> : TiffBasePlanarColorDecoder<TPixel> |
|||
where TPixel : unmanaged, IPixel<TPixel> |
|||
{ |
|||
private readonly bool isBigEndian; |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="Rgb32PlanarTiffColor{TPixel}" /> class.
|
|||
/// </summary>
|
|||
/// <param name="isBigEndian">if set to <c>true</c> decodes the pixel data as big endian, otherwise as little endian.</param>
|
|||
public Rgb32PlanarTiffColor(bool isBigEndian) => this.isBigEndian = isBigEndian; |
|||
|
|||
/// <inheritdoc/>
|
|||
public override void Decode(IMemoryOwner<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
|
|||
var color = default(TPixel); |
|||
color.FromVector4(TiffUtils.Vector4Default); |
|||
|
|||
Span<byte> redData = data[0].GetSpan(); |
|||
Span<byte> greenData = data[1].GetSpan(); |
|||
Span<byte> blueData = data[2].GetSpan(); |
|||
|
|||
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.ConvertToUIntBigEndian(redData.Slice(offset, 4)); |
|||
ulong g = TiffUtils.ConvertToUIntBigEndian(greenData.Slice(offset, 4)); |
|||
ulong b = TiffUtils.ConvertToUIntBigEndian(blueData.Slice(offset, 4)); |
|||
|
|||
offset += 4; |
|||
|
|||
pixelRow[x] = TiffUtils.ColorScaleTo32Bit(r, g, b, color); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
for (int x = 0; x < pixelRow.Length; x++) |
|||
{ |
|||
ulong r = TiffUtils.ConvertToUIntLittleEndian(redData.Slice(offset, 4)); |
|||
ulong g = TiffUtils.ConvertToUIntLittleEndian(greenData.Slice(offset, 4)); |
|||
ulong b = TiffUtils.ConvertToUIntLittleEndian(blueData.Slice(offset, 4)); |
|||
|
|||
offset += 4; |
|||
|
|||
pixelRow[x] = TiffUtils.ColorScaleTo32Bit(r, g, b, color); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,65 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System; |
|||
using SixLabors.ImageSharp.Formats.Tiff.Utils; |
|||
using SixLabors.ImageSharp.Memory; |
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation |
|||
{ |
|||
/// <summary>
|
|||
/// Implements the 'WhiteIsZero' photometric interpretation for 24-bit grayscale images.
|
|||
/// </summary>
|
|||
internal class WhiteIsZero24TiffColor<TPixel> : TiffBaseColorDecoder<TPixel> |
|||
where TPixel : unmanaged, IPixel<TPixel> |
|||
{ |
|||
private readonly bool isBigEndian; |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="WhiteIsZero24TiffColor{TPixel}" /> class.
|
|||
/// </summary>
|
|||
/// <param name="isBigEndian">if set to <c>true</c> decodes the pixel data as big endian, otherwise as little endian.</param>
|
|||
public WhiteIsZero24TiffColor(bool isBigEndian) => this.isBigEndian = isBigEndian; |
|||
|
|||
/// <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
|
|||
var color = default(TPixel); |
|||
color.FromVector4(TiffUtils.Vector4Default); |
|||
byte[] buffer = new byte[4]; |
|||
int bufferStartIdx = this.isBigEndian ? 1 : 0; |
|||
|
|||
Span<byte> bufferSpan = buffer.AsSpan(bufferStartIdx); |
|||
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++) |
|||
{ |
|||
data.Slice(offset, 3).CopyTo(bufferSpan); |
|||
ulong intensity = TiffUtils.ConvertToUIntBigEndian(buffer); |
|||
offset += 3; |
|||
|
|||
pixelRow[x] = TiffUtils.ColorScaleTo24Bit(intensity, color); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
for (int x = 0; x < pixelRow.Length; x++) |
|||
{ |
|||
data.Slice(offset, 3).CopyTo(bufferSpan); |
|||
ulong intensity = TiffUtils.ConvertToUIntLittleEndian(buffer); |
|||
offset += 3; |
|||
|
|||
pixelRow[x] = TiffUtils.ColorScaleTo24Bit(intensity, color); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,60 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
|
|||
using System; |
|||
using SixLabors.ImageSharp.Formats.Tiff.Utils; |
|||
using SixLabors.ImageSharp.Memory; |
|||
using SixLabors.ImageSharp.PixelFormats; |
|||
|
|||
namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation |
|||
{ |
|||
/// <summary>
|
|||
/// Implements the 'WhiteIsZero' photometric interpretation for 32-bit grayscale images.
|
|||
/// </summary>
|
|||
internal class WhiteIsZero32TiffColor<TPixel> : TiffBaseColorDecoder<TPixel> |
|||
where TPixel : unmanaged, IPixel<TPixel> |
|||
{ |
|||
private readonly bool isBigEndian; |
|||
|
|||
/// <summary>
|
|||
/// Initializes a new instance of the <see cref="WhiteIsZero32TiffColor{TPixel}" /> class.
|
|||
/// </summary>
|
|||
/// <param name="isBigEndian">if set to <c>true</c> decodes the pixel data as big endian, otherwise as little endian.</param>
|
|||
public WhiteIsZero32TiffColor(bool isBigEndian) => this.isBigEndian = isBigEndian; |
|||
|
|||
/// <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
|
|||
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 intensity = TiffUtils.ConvertToUIntBigEndian(data.Slice(offset, 4)); |
|||
offset += 4; |
|||
|
|||
pixelRow[x] = TiffUtils.ColorScaleTo32Bit(intensity, color); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
for (int x = 0; x < pixelRow.Length; x++) |
|||
{ |
|||
ulong intensity = TiffUtils.ConvertToUIntLittleEndian(data.Slice(offset, 4)); |
|||
offset += 4; |
|||
|
|||
pixelRow[x] = TiffUtils.ColorScaleTo32Bit(intensity, color); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,3 @@ |
|||
version https://git-lfs.github.com/spec/v1 |
|||
oid sha256:6b5a96942ee27a2b25d3cbb8bdd05239be71f84acc4d63c95380841a8a67befd |
|||
size 9770 |
|||
@ -0,0 +1,3 @@ |
|||
version https://git-lfs.github.com/spec/v1 |
|||
oid sha256:fe2d4e0d99bdfade966e27bd9583bce39bebb90efa8e7f768ce3cec69aa306e2 |
|||
size 9770 |
|||
@ -0,0 +1,3 @@ |
|||
version https://git-lfs.github.com/spec/v1 |
|||
oid sha256:6677c372a449fe0324b148385cf0ebaaf33ab4563484ae89831dfeacd80d7c93 |
|||
size 12885 |
|||
@ -0,0 +1,3 @@ |
|||
version https://git-lfs.github.com/spec/v1 |
|||
oid sha256:e37a4455e6b61e32720af99127b82aacdc907be91b8ed1d8e1a1f06d6a853211 |
|||
size 12885 |
|||
@ -0,0 +1,3 @@ |
|||
version https://git-lfs.github.com/spec/v1 |
|||
oid sha256:514417ead3d6c5c6ca33374ef0bb6ecbe5f875a266519d4cbaa4a6b91033d243 |
|||
size 12778 |
|||
@ -0,0 +1,3 @@ |
|||
version https://git-lfs.github.com/spec/v1 |
|||
oid sha256:64c948aa03bc4a24cd1d68bb18b5031c119936154a90f1cb1d9aaabd854c5d9b |
|||
size 12778 |
|||
@ -0,0 +1,3 @@ |
|||
version https://git-lfs.github.com/spec/v1 |
|||
oid sha256:c6368a704b0a629239024f6fbfb30723fa317593ef36ddba05d76302530bd974 |
|||
size 28568 |
|||
@ -0,0 +1,3 @@ |
|||
version https://git-lfs.github.com/spec/v1 |
|||
oid sha256:bbb2b4ca6d7eeee4737c6963c99ef68fb6971cf6ccee463427a8246574bc6440 |
|||
size 28632 |
|||
@ -0,0 +1,3 @@ |
|||
version https://git-lfs.github.com/spec/v1 |
|||
oid sha256:d7b9da8ec44da84fc89aed1ad221a5eb130a1f233a1ff8a4a15b41898a0e364f |
|||
size 38027 |
|||
@ -0,0 +1,3 @@ |
|||
version https://git-lfs.github.com/spec/v1 |
|||
oid sha256:0876580f9c5d8e13656210582137104daba137c99d55eafb5ebbfa418efa6525 |
|||
size 38027 |
|||
@ -0,0 +1,3 @@ |
|||
version https://git-lfs.github.com/spec/v1 |
|||
oid sha256:752452ac51ad1e836fb81267ab708ff81cf81a4c7e00daeed703f67782b563ec |
|||
size 28586 |
|||
@ -0,0 +1,3 @@ |
|||
version https://git-lfs.github.com/spec/v1 |
|||
oid sha256:72f27af4fe177ebe47bef2af64723497d5a5f44808424bedfc2012fe4e3fc34e |
|||
size 28586 |
|||
@ -0,0 +1,3 @@ |
|||
version https://git-lfs.github.com/spec/v1 |
|||
oid sha256:a718ae37d6d7a5bb5702cc75350f6feec3e9cdcd7e22aaa4753c7fe9c2db9aae |
|||
size 38035 |
|||
@ -0,0 +1,3 @@ |
|||
version https://git-lfs.github.com/spec/v1 |
|||
oid sha256:2241683d74e9a52c5077870731e7bd5a7e7558c2a04fd0edf57da3a583044442 |
|||
size 38035 |
|||
Loading…
Reference in new issue