mirror of https://github.com/SixLabors/ImageSharp
9 changed files with 91 additions and 7 deletions
@ -0,0 +1,48 @@ |
|||||
|
// 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 16-bit grayscale images.
|
||||
|
/// </summary>
|
||||
|
internal class BlackIsZero16TiffColor<TPixel> : TiffBaseColorDecoder<TPixel> |
||||
|
where TPixel : unmanaged, IPixel<TPixel> |
||||
|
{ |
||||
|
private readonly bool isBigEndian; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="BlackIsZero16TiffColor{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 BlackIsZero16TiffColor(bool isBigEndian) => this.isBigEndian = isBigEndian; |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
public override void Decode(ReadOnlySpan<byte> data, Buffer2D<TPixel> pixels, int left, int top, int width, int height) |
||||
|
{ |
||||
|
var color = default(TPixel); |
||||
|
|
||||
|
int offset = 0; |
||||
|
|
||||
|
var l16 = default(L16); |
||||
|
for (int y = top; y < top + height; y++) |
||||
|
{ |
||||
|
for (int x = left; x < left + width; x++) |
||||
|
{ |
||||
|
ushort intensity = TiffUtils.ConvertToShort(data.Slice(offset, 2), this.isBigEndian); |
||||
|
offset += 2; |
||||
|
|
||||
|
l16.PackedValue = intensity; |
||||
|
color.FromL16(l16); |
||||
|
|
||||
|
pixels[x, y] = color; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
// Copyright (c) Six Labors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
|
||||
|
using System; |
||||
|
using System.Buffers.Binary; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Formats.Tiff.Utils |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Helper methods for TIFF decoding.
|
||||
|
/// </summary>
|
||||
|
internal static class TiffUtils |
||||
|
{ |
||||
|
public static ushort ConvertToShort(ReadOnlySpan<byte> buffer, bool isBigEndian) => isBigEndian |
||||
|
? BinaryPrimitives.ReadUInt16BigEndian(buffer) |
||||
|
: BinaryPrimitives.ReadUInt16LittleEndian(buffer); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,3 @@ |
|||||
|
version https://git-lfs.github.com/spec/v1 |
||||
|
oid sha256:c3806304a5453a6ec8a6795bc77b967b9aa8593288af36bbf9802f22ee27869e |
||||
|
size 6588 |
||||
Loading…
Reference in new issue