mirror of https://github.com/SixLabors/ImageSharp
17 changed files with 206 additions and 49 deletions
@ -0,0 +1,8 @@ |
|||||
|
// Copyright (c) Six Labors.
|
||||
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Formats.Exr.Compression.Compressors; |
||||
|
|
||||
|
internal class NoCompressor |
||||
|
{ |
||||
|
} |
||||
@ -0,0 +1,47 @@ |
|||||
|
// Copyright (c) Six Labors.
|
||||
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
|
using SixLabors.ImageSharp.Compression.Zlib; |
||||
|
using SixLabors.ImageSharp.Formats.Exr.Constants; |
||||
|
using SixLabors.ImageSharp.Memory; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Formats.Exr.Compression.Compressors; |
||||
|
|
||||
|
internal class ZipCompressor : ExrBaseCompressor |
||||
|
{ |
||||
|
private readonly DeflateCompressionLevel compressionLevel; |
||||
|
|
||||
|
private readonly MemoryStream memoryStream = new(); |
||||
|
|
||||
|
public ZipCompressor(Stream output, MemoryAllocator allocator, uint bytesPerBlock, DeflateCompressionLevel compressionLevel) |
||||
|
: base(output, allocator, bytesPerBlock) |
||||
|
=> this.compressionLevel = compressionLevel; |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
public override ExrCompression Method => ExrCompression.Zip; |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
public override void Initialize(int rowsPerStrip) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
public override void CompressStrip(Span<byte> rows, int height) |
||||
|
{ |
||||
|
this.memoryStream.Seek(0, SeekOrigin.Begin); |
||||
|
using (ZlibDeflateStream stream = new(this.Allocator, this.memoryStream, this.compressionLevel)) |
||||
|
{ |
||||
|
stream.Write(rows); |
||||
|
stream.Flush(); |
||||
|
} |
||||
|
|
||||
|
int size = (int)this.memoryStream.Position; |
||||
|
byte[] buffer = this.memoryStream.GetBuffer(); |
||||
|
this.Output.Write(buffer, 0, size); |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
protected override void Dispose(bool disposing) |
||||
|
{ |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,26 @@ |
|||||
|
// Copyright (c) Six Labors.
|
||||
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
|
using SixLabors.ImageSharp.Compression.Zlib; |
||||
|
using SixLabors.ImageSharp.Formats.Exr.Compression.Compressors; |
||||
|
using SixLabors.ImageSharp.Formats.Exr.Constants; |
||||
|
using SixLabors.ImageSharp.Memory; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Formats.Exr.Compression; |
||||
|
|
||||
|
internal static class ExrCompressorFactory |
||||
|
{ |
||||
|
public static ExrBaseCompressor Create( |
||||
|
ExrCompression method, |
||||
|
Stream output, |
||||
|
MemoryAllocator allocator, |
||||
|
int width, |
||||
|
DeflateCompressionLevel compressionLevel) |
||||
|
{ |
||||
|
switch (method) |
||||
|
{ |
||||
|
default: |
||||
|
throw ExrThrowHelper.NotSupportedCompressor(method.ToString()); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,9 +1,12 @@ |
|||||
// Copyright (c) Six Labors.
|
// Copyright (c) Six Labors.
|
||||
// Licensed under the Six Labors Split License.
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Formats.Exr.Compression; |
namespace SixLabors.ImageSharp.Formats.Exr.Constants; |
||||
|
|
||||
internal enum ExrCompressionType |
/// <summary>
|
||||
|
/// Enumeration representing the compression formats defined by the EXR file-format.
|
||||
|
/// </summary>
|
||||
|
public enum ExrCompression |
||||
{ |
{ |
||||
/// <summary>
|
/// <summary>
|
||||
/// Pixel data is not compressed.
|
/// Pixel data is not compressed.
|
||||
@ -0,0 +1,43 @@ |
|||||
|
// Copyright (c) Six Labors.
|
||||
|
// Licensed under the Six Labors Split License.
|
||||
|
|
||||
|
using SixLabors.ImageSharp.Formats.Exr.Constants; |
||||
|
using SixLabors.ImageSharp.Memory; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Formats.Exr.Compression; |
||||
|
|
||||
|
internal abstract class ExrBaseCompressor : ExrBaseCompression |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="ExrBaseCompressor"/> class.
|
||||
|
/// </summary>
|
||||
|
/// <param name="output">The output stream to write the compressed image to.</param>
|
||||
|
/// <param name="allocator">The memory allocator.</param>
|
||||
|
/// <param name="bytesPerBlock">Bytes per block.</param>
|
||||
|
protected ExrBaseCompressor(Stream output, MemoryAllocator allocator, uint bytesPerBlock) |
||||
|
: base(allocator, bytesPerBlock) |
||||
|
=> this.Output = output; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the compression method to use.
|
||||
|
/// </summary>
|
||||
|
public abstract ExrCompression Method { get; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Gets the output stream to write the compressed image to.
|
||||
|
/// </summary>
|
||||
|
public Stream Output { get; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Does any initialization required for the compression.
|
||||
|
/// </summary>
|
||||
|
/// <param name="rowsPerStrip">The number of rows per strip.</param>
|
||||
|
public abstract void Initialize(int rowsPerStrip); |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Compresses a strip of the image.
|
||||
|
/// </summary>
|
||||
|
/// <param name="rows">Image rows to compress.</param>
|
||||
|
/// <param name="height">Image height.</param>
|
||||
|
public abstract void CompressStrip(Span<byte> rows, int height); |
||||
|
} |
||||
Loading…
Reference in new issue