mirror of https://github.com/SixLabors/ImageSharp
6 changed files with 72 additions and 3 deletions
@ -0,0 +1,58 @@ |
|||||
|
// Copyright (c) Six Labors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
|
||||
|
using System; |
||||
|
using System.Buffers.Binary; |
||||
|
using SixLabors.ImageSharp.Memory; |
||||
|
using SixLabors.ImageSharp.PixelFormats; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Implements the 'RGB' photometric interpretation with 16 bits for each channel.
|
||||
|
/// </summary>
|
||||
|
internal class Rgb161616TiffColor<TPixel> : TiffBaseColorDecoder<TPixel> |
||||
|
where TPixel : unmanaged, IPixel<TPixel> |
||||
|
{ |
||||
|
private readonly bool isBigEndian; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="Rgb161616TiffColor{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 Rgb161616TiffColor(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 rgba = default(Rgba64); |
||||
|
for (int y = top; y < top + height; y++) |
||||
|
{ |
||||
|
Span<TPixel> pixelRow = pixels.GetRowSpan(y); |
||||
|
|
||||
|
for (int x = left; x < left + width; x++) |
||||
|
{ |
||||
|
ulong r = this.ConvertToShort(data.Slice(offset, 2)); |
||||
|
offset += 2; |
||||
|
ulong g = this.ConvertToShort(data.Slice(offset, 2)); |
||||
|
offset += 2; |
||||
|
ulong b = this.ConvertToShort(data.Slice(offset, 2)); |
||||
|
offset += 2; |
||||
|
|
||||
|
rgba.PackedValue = r | (g << 16) | (b << 32) | (0xfffful << 48); |
||||
|
color.FromRgba64(rgba); |
||||
|
|
||||
|
pixelRow[x] = color; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private ushort ConvertToShort(ReadOnlySpan<byte> buffer) => this.isBigEndian |
||||
|
? BinaryPrimitives.ReadUInt16BigEndian(buffer) |
||||
|
: BinaryPrimitives.ReadUInt16LittleEndian(buffer); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,3 @@ |
|||||
|
version https://git-lfs.github.com/spec/v1 |
||||
|
oid sha256:c734dd489c65fb77bd7a35cd663aa16ce986df2c2ab8c7ca43d8b65db9d47c03 |
||||
|
size 6666162 |
||||
Loading…
Reference in new issue