diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/BlackIsZero16TiffColor{TPixel}.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/BlackIsZero16TiffColor{TPixel}.cs
index a31ff7a9f..1cddc9b63 100644
--- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/BlackIsZero16TiffColor{TPixel}.cs
+++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/BlackIsZero16TiffColor{TPixel}.cs
@@ -16,11 +16,18 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation
{
private readonly bool isBigEndian;
+ private readonly Configuration configuration;
+
///
/// Initializes a new instance of the class.
///
+ /// The configuration.
/// if set to true decodes the pixel data as big endian, otherwise as little endian.
- public BlackIsZero16TiffColor(bool isBigEndian) => this.isBigEndian = isBigEndian;
+ public BlackIsZero16TiffColor(Configuration configuration, bool isBigEndian)
+ {
+ this.configuration = configuration;
+ this.isBigEndian = isBigEndian;
+ }
///
public override void Decode(ReadOnlySpan data, Buffer2D pixels, int left, int top, int width, int height)
@@ -47,13 +54,14 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation
}
else
{
- for (int x = 0; x < pixelRow.Length; x++)
- {
- ushort intensity = TiffUtils.ConvertToShortLittleEndian(data.Slice(offset, 2));
- offset += 2;
+ int byteCount = pixelRow.Length * 2;
+ PixelOperations.Instance.FromL16Bytes(
+ this.configuration,
+ data.Slice(offset, byteCount),
+ pixelRow,
+ pixelRow.Length);
- pixelRow[x] = TiffUtils.ColorFromL16(l16, intensity, color);
- }
+ offset += byteCount;
}
}
}
diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/BlackIsZero8TiffColor{TPixel}.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/BlackIsZero8TiffColor{TPixel}.cs
index ea2608f6f..f62cf2952 100644
--- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/BlackIsZero8TiffColor{TPixel}.cs
+++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/BlackIsZero8TiffColor{TPixel}.cs
@@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0.
using System;
-using SixLabors.ImageSharp.Formats.Tiff.Utils;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
@@ -14,22 +13,26 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation
internal class BlackIsZero8TiffColor : TiffBaseColorDecoder
where TPixel : unmanaged, IPixel
{
+ private readonly Configuration configuration;
+
+ public BlackIsZero8TiffColor(Configuration configuration) => this.configuration = configuration;
+
///
public override void Decode(ReadOnlySpan data, Buffer2D pixels, int left, int top, int width, int height)
{
- var color = default(TPixel);
-
int offset = 0;
- var l8 = default(L8);
for (int y = top; y < top + height; y++)
{
Span pixelRow = pixels.GetRowSpan(y).Slice(left, width);
- for (int x = 0; x < pixelRow.Length; x++)
- {
- byte intensity = data[offset++];
- pixelRow[x] = TiffUtils.ColorFromL8(l8, intensity, color);
- }
+ int byteCount = pixelRow.Length;
+ PixelOperations.Instance.FromL8Bytes(
+ this.configuration,
+ data.Slice(offset, byteCount),
+ pixelRow,
+ pixelRow.Length);
+
+ offset += byteCount;
}
}
}
diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/Rgb161616TiffColor{TPixel}.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/Rgb161616TiffColor{TPixel}.cs
index 4b34d5a0d..e0d558a14 100644
--- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/Rgb161616TiffColor{TPixel}.cs
+++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/Rgb161616TiffColor{TPixel}.cs
@@ -16,11 +16,18 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation
{
private readonly bool isBigEndian;
+ private readonly Configuration configuration;
+
///
/// Initializes a new instance of the class.
///
+ /// The configuration.
/// if set to true decodes the pixel data as big endian, otherwise as little endian.
- public Rgb161616TiffColor(bool isBigEndian) => this.isBigEndian = isBigEndian;
+ public Rgb161616TiffColor(Configuration configuration, bool isBigEndian)
+ {
+ this.configuration = configuration;
+ this.isBigEndian = isBigEndian;
+ }
///
public override void Decode(ReadOnlySpan data, Buffer2D pixels, int left, int top, int width, int height)
@@ -53,17 +60,14 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation
}
else
{
- for (int x = 0; x < pixelRow.Length; x++)
- {
- ulong r = TiffUtils.ConvertToShortLittleEndian(data.Slice(offset, 2));
- offset += 2;
- ulong g = TiffUtils.ConvertToShortLittleEndian(data.Slice(offset, 2));
- offset += 2;
- ulong b = TiffUtils.ConvertToShortLittleEndian(data.Slice(offset, 2));
- offset += 2;
+ int byteCount = pixelRow.Length * 6;
+ PixelOperations.Instance.FromRgb48Bytes(
+ this.configuration,
+ data.Slice(offset, byteCount),
+ pixelRow,
+ pixelRow.Length);
- pixelRow[x] = TiffUtils.ColorFromRgba64(rgba, r, g, b, color);
- }
+ offset += byteCount;
}
}
}
diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/Rgb888TiffColor{TPixel}.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/Rgb888TiffColor{TPixel}.cs
index 536dece8e..2a86eb2ee 100644
--- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/Rgb888TiffColor{TPixel}.cs
+++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/Rgb888TiffColor{TPixel}.cs
@@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0.
using System;
-
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
@@ -14,29 +13,26 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation
internal class Rgb888TiffColor : TiffBaseColorDecoder
where TPixel : unmanaged, IPixel
{
+ private readonly Configuration configuration;
+
+ public Rgb888TiffColor(Configuration configuration) => this.configuration = configuration;
+
///
public override void Decode(ReadOnlySpan data, Buffer2D pixels, int left, int top, int width, int height)
{
- var color = default(TPixel);
-
int offset = 0;
- var rgba = default(Rgba32);
for (int y = top; y < top + height; y++)
{
Span pixelRow = pixels.GetRowSpan(y).Slice(left, width);
-
- for (int x = 0; x < pixelRow.Length; x++)
- {
- byte r = data[offset++];
- byte g = data[offset++];
- byte b = data[offset++];
-
- rgba.PackedValue = (uint)(r | (g << 8) | (b << 16) | (0xff << 24));
- color.FromRgba32(rgba);
-
- pixelRow[x] = color;
- }
+ int byteCount = pixelRow.Length * 3;
+ PixelOperations.Instance.FromRgb24Bytes(
+ this.configuration,
+ data.Slice(offset, byteCount),
+ pixelRow,
+ pixelRow.Length);
+
+ offset += byteCount;
}
}
}
diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/TiffColorDecoderFactory{TPixel}.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/TiffColorDecoderFactory{TPixel}.cs
index 0c93998c4..97d3d8665 100644
--- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/TiffColorDecoderFactory{TPixel}.cs
+++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/TiffColorDecoderFactory{TPixel}.cs
@@ -8,7 +8,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation
internal static class TiffColorDecoderFactory
where TPixel : unmanaged, IPixel
{
- public static TiffBaseColorDecoder Create(TiffColorType colorType, TiffBitsPerSample bitsPerSample, ushort[] colorMap, ByteOrder byteOrder)
+ public static TiffBaseColorDecoder Create(Configuration configuration, TiffColorType colorType, TiffBitsPerSample bitsPerSample, ushort[] colorMap, ByteOrder byteOrder)
{
switch (colorType)
{
@@ -55,12 +55,12 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation
case TiffColorType.BlackIsZero8:
DebugGuard.IsTrue(bitsPerSample.Channels == 1 && bitsPerSample.Channel0 == 8, "bitsPerSample");
DebugGuard.IsTrue(colorMap == null, "colorMap");
- return new BlackIsZero8TiffColor();
+ return new BlackIsZero8TiffColor(configuration);
case TiffColorType.BlackIsZero16:
DebugGuard.IsTrue(bitsPerSample.Channels == 1 && bitsPerSample.Channel0 == 16, "bitsPerSample");
DebugGuard.IsTrue(colorMap == null, "colorMap");
- return new BlackIsZero16TiffColor(byteOrder == ByteOrder.BigEndian);
+ return new BlackIsZero16TiffColor(configuration, byteOrder == ByteOrder.BigEndian);
case TiffColorType.Rgb:
DebugGuard.IsTrue(colorMap == null, "colorMap");
@@ -94,7 +94,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation
&& bitsPerSample.Channel0 == 8,
"bitsPerSample");
DebugGuard.IsTrue(colorMap == null, "colorMap");
- return new Rgb888TiffColor();
+ return new Rgb888TiffColor(configuration);
case TiffColorType.Rgb101010:
DebugGuard.IsTrue(
@@ -134,7 +134,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation
&& bitsPerSample.Channel0 == 16,
"bitsPerSample");
DebugGuard.IsTrue(colorMap == null, "colorMap");
- return new Rgb161616TiffColor(isBigEndian: byteOrder == ByteOrder.BigEndian);
+ return new Rgb161616TiffColor(configuration, isBigEndian: byteOrder == ByteOrder.BigEndian);
case TiffColorType.PaletteColor:
DebugGuard.NotNull(colorMap, "colorMap");
diff --git a/src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs b/src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs
index 9fb8c6ceb..8477ba2d2 100644
--- a/src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs
+++ b/src/ImageSharp/Formats/Tiff/TiffDecoderCore.cs
@@ -330,7 +330,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff
this.FaxCompressionOptions,
this.FillOrder);
- TiffBaseColorDecoder colorDecoder = TiffColorDecoderFactory.Create(this.ColorType, this.BitsPerSample, this.ColorMap, this.byteOrder);
+ TiffBaseColorDecoder colorDecoder = TiffColorDecoderFactory.Create(this.Configuration, this.ColorType, this.BitsPerSample, this.ColorMap, this.byteOrder);
for (int stripIndex = 0; stripIndex < stripOffsets.Length; stripIndex++)
{
diff --git a/tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/BlackIsZeroTiffColorTests.cs b/tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/BlackIsZeroTiffColorTests.cs
index 769ab850e..38611c6f3 100644
--- a/tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/BlackIsZeroTiffColorTests.cs
+++ b/tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/BlackIsZeroTiffColorTests.cs
@@ -188,7 +188,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation
{
AssertDecode(expectedResult, pixels =>
{
- new BlackIsZero8TiffColor().Decode(inputData, pixels, left, top, width, height);
+ new BlackIsZero8TiffColor(Configuration.Default).Decode(inputData, pixels, left, top, width, height);
});
}
}
diff --git a/tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/RgbTiffColorTests.cs b/tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/RgbTiffColorTests.cs
index 9adf59e48..f9f633106 100644
--- a/tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/RgbTiffColorTests.cs
+++ b/tests/ImageSharp.Tests/Formats/Tiff/PhotometricInterpretation/RgbTiffColorTests.cs
@@ -179,7 +179,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Tiff.PhotometricInterpretation
{
AssertDecode(expectedResult, pixels =>
{
- new Rgb888TiffColor().Decode(inputData, pixels, left, top, width, height);
+ new Rgb888TiffColor(Configuration.Default).Decode(inputData, pixels, left, top, width, height);
});
}
}