Browse Source

Migrate new Tiff WebPDecoder

pull/2180/head
James Jackson-South 4 years ago
parent
commit
a42101e743
  1. 10
      src/ImageSharp/Formats/Tiff/Compression/Decompressors/WebpTiffCompression.cs
  2. 2
      src/ImageSharp/Formats/Tiff/Compression/TiffDecompressorsFactory.cs
  3. 14
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Internal.cs

10
src/ImageSharp/Formats/Tiff/Compression/Decompressors/WebpTiffCompression.cs

@ -16,22 +16,24 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Compression.Decompressors
/// </summary>
internal class WebpTiffCompression : TiffBaseDecompressor
{
private readonly DecoderOptions options;
/// <summary>
/// Initializes a new instance of the <see cref="WebpTiffCompression"/> class.
/// </summary>
/// <param name="options">The general decoder options.</param>
/// <param name="memoryAllocator">The memory allocator.</param>
/// <param name="width">The width of the image.</param>
/// <param name="bitsPerPixel">The bits per pixel.</param>
/// <param name="predictor">The predictor.</param>
public WebpTiffCompression(MemoryAllocator memoryAllocator, int width, int bitsPerPixel, TiffPredictor predictor = TiffPredictor.None)
public WebpTiffCompression(DecoderOptions options, MemoryAllocator memoryAllocator, int width, int bitsPerPixel, TiffPredictor predictor = TiffPredictor.None)
: base(memoryAllocator, width, bitsPerPixel, predictor)
{
}
=> this.options = options;
/// <inheritdoc/>
protected override void Decompress(BufferedReadStream stream, int byteCount, int stripHeight, Span<byte> buffer)
{
using var image = Image.Load<Rgb24>(stream, new WebpDecoder());
using Image<Rgb24> image = new WebpDecoder().Decode<Rgb24>(this.options, stream, default);
CopyImageBytesToBuffer(buffer, image.Frames.RootFrame.PixelBuffer);
}

2
src/ImageSharp/Formats/Tiff/Compression/TiffDecompressorsFactory.cs

@ -62,7 +62,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Compression
case TiffDecoderCompressionType.Webp:
DebugGuard.IsTrue(predictor == TiffPredictor.None, "Predictor should only be used with lzw or deflate compression");
return new WebpTiffCompression(allocator, width, bitsPerPixel);
return new WebpTiffCompression(options, allocator, width, bitsPerPixel);
default:
throw TiffThrowHelper.NotSupportedDecompressor(nameof(method));

14
tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Internal.cs

@ -1,22 +1,10 @@
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.
// Licensed under the Six Labors Split License.
using System;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder;
using SixLabors.ImageSharp.IO;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils;
using SixLabors.ImageSharp.Tests.TestUtilities;
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
using SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs;
using Xunit;
using Xunit.Abstractions;
// ReSharper disable InconsistentNaming
namespace SixLabors.ImageSharp.Tests.Formats.Jpg

Loading…
Cancel
Save