mirror of https://github.com/SixLabors/ImageSharp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
2.0 KiB
58 lines
2.0 KiB
// Copyright (c) Six Labors.
|
|
// Licensed under the Apache License, Version 2.0.
|
|
|
|
using System;
|
|
using System.Buffers.Binary;
|
|
using System.Numerics;
|
|
using System.Runtime.CompilerServices;
|
|
using SixLabors.ImageSharp.PixelFormats;
|
|
|
|
namespace SixLabors.ImageSharp.Formats.Tiff.Utils
|
|
{
|
|
/// <summary>
|
|
/// Helper methods for TIFF decoding.
|
|
/// </summary>
|
|
internal static class TiffUtils
|
|
{
|
|
public static Vector4 Vector4Default { get; } = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
|
|
|
|
public static Rgba64 Rgba64Default { get; } = new Rgba64(0, 0, 0, 0);
|
|
|
|
public static L16 L16Default { get; } = new L16(0);
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static ushort ConvertToShortBigEndian(ReadOnlySpan<byte> buffer) =>
|
|
BinaryPrimitives.ReadUInt16BigEndian(buffer);
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static ushort ConvertToShortLittleEndian(ReadOnlySpan<byte> buffer) =>
|
|
BinaryPrimitives.ReadUInt16LittleEndian(buffer);
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static TPixel ColorFromL8<TPixel>(L8 l8, byte intensity, TPixel color)
|
|
where TPixel : unmanaged, IPixel<TPixel>
|
|
{
|
|
l8.PackedValue = intensity;
|
|
color.FromL8(l8);
|
|
return color;
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static TPixel ColorFromL16<TPixel>(L16 l16, ushort intensity, TPixel color)
|
|
where TPixel : unmanaged, IPixel<TPixel>
|
|
{
|
|
l16.PackedValue = intensity;
|
|
color.FromL16(l16);
|
|
return color;
|
|
}
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
public static TPixel ColorFromRgba64<TPixel>(Rgba64 rgba, ulong r, ulong g, ulong b, TPixel color)
|
|
where TPixel : unmanaged, IPixel<TPixel>
|
|
{
|
|
rgba.PackedValue = r | (g << 16) | (b << 32) | (0xfffful << 48);
|
|
color.FromRgba64(rgba);
|
|
return color;
|
|
}
|
|
}
|
|
}
|
|
|