|
|
|
@ -13,8 +13,6 @@ namespace SixLabors.ImageSharp.Formats.Exr.Compression.Decompressors; |
|
|
|
/// </summary>
|
|
|
|
internal class B44ExrCompression : ExrBaseDecompressor |
|
|
|
{ |
|
|
|
private readonly int width; |
|
|
|
|
|
|
|
private readonly uint rowsPerBlock; |
|
|
|
|
|
|
|
private readonly int channelCount; |
|
|
|
@ -35,9 +33,8 @@ internal class B44ExrCompression : ExrBaseDecompressor |
|
|
|
/// <param name="width">The width of a pixel row in pixels.</param>
|
|
|
|
/// <param name="channelCount">The number of channels of the image.</param>
|
|
|
|
public B44ExrCompression(MemoryAllocator allocator, uint bytesPerBlock, uint bytesPerRow, uint rowsPerBlock, int width, int channelCount) |
|
|
|
: base(allocator, bytesPerBlock, bytesPerRow) |
|
|
|
: base(allocator, bytesPerBlock, bytesPerRow, width) |
|
|
|
{ |
|
|
|
this.width = width; |
|
|
|
this.rowsPerBlock = rowsPerBlock; |
|
|
|
this.channelCount = channelCount; |
|
|
|
this.tmpBuffer = allocator.Allocate<ushort>((int)(width * rowsPerBlock * channelCount)); |
|
|
|
@ -54,17 +51,17 @@ internal class B44ExrCompression : ExrBaseDecompressor |
|
|
|
{ |
|
|
|
for (int y = 0; y < this.rowsPerBlock; y += 4) |
|
|
|
{ |
|
|
|
Span<ushort> row0 = decompressed.Slice(outputOffset, this.width); |
|
|
|
outputOffset += this.width; |
|
|
|
Span<ushort> row1 = decompressed.Slice(outputOffset, this.width); |
|
|
|
outputOffset += this.width; |
|
|
|
Span<ushort> row2 = decompressed.Slice(outputOffset, this.width); |
|
|
|
outputOffset += this.width; |
|
|
|
Span<ushort> row3 = decompressed.Slice(outputOffset, this.width); |
|
|
|
outputOffset += this.width; |
|
|
|
Span<ushort> row0 = decompressed.Slice(outputOffset, this.Width); |
|
|
|
outputOffset += this.Width; |
|
|
|
Span<ushort> row1 = decompressed.Slice(outputOffset, this.Width); |
|
|
|
outputOffset += this.Width; |
|
|
|
Span<ushort> row2 = decompressed.Slice(outputOffset, this.Width); |
|
|
|
outputOffset += this.Width; |
|
|
|
Span<ushort> row3 = decompressed.Slice(outputOffset, this.Width); |
|
|
|
outputOffset += this.Width; |
|
|
|
|
|
|
|
int rowOffset = 0; |
|
|
|
for (int x = 0; x < this.width && bytesLeft > 0; x += 4) |
|
|
|
for (int x = 0; x < this.Width && bytesLeft > 0; x += 4) |
|
|
|
{ |
|
|
|
int bytesRead = stream.Read(this.scratch, 0, 3); |
|
|
|
if (bytesRead == 0) |
|
|
|
@ -90,7 +87,7 @@ internal class B44ExrCompression : ExrBaseDecompressor |
|
|
|
bytesLeft -= 14; |
|
|
|
} |
|
|
|
|
|
|
|
int n = x + 3 < this.width ? 4 : this.width - x; |
|
|
|
int n = x + 3 < this.Width ? 4 : this.Width - x; |
|
|
|
if (y + 3 < this.rowsPerBlock) |
|
|
|
{ |
|
|
|
this.s.AsSpan(0, n).CopyTo(row0[rowOffset..]); |
|
|
|
@ -125,16 +122,16 @@ internal class B44ExrCompression : ExrBaseDecompressor |
|
|
|
// Rearrange the decompressed data such that the data for each scan line form a contiguous block.
|
|
|
|
int offsetDecompressed = 0; |
|
|
|
int offsetOutput = 0; |
|
|
|
int blockSize = (int)(this.width * this.rowsPerBlock); |
|
|
|
int blockSize = (int)(this.Width * this.rowsPerBlock); |
|
|
|
for (int y = 0; y < this.rowsPerBlock; y++) |
|
|
|
{ |
|
|
|
for (int i = 0; i < this.channelCount; i++) |
|
|
|
{ |
|
|
|
decompressed.Slice(offsetDecompressed + (i * blockSize), this.width).CopyTo(outputBuffer[offsetOutput..]); |
|
|
|
offsetOutput += this.width; |
|
|
|
decompressed.Slice(offsetDecompressed + (i * blockSize), this.Width).CopyTo(outputBuffer[offsetOutput..]); |
|
|
|
offsetOutput += this.Width; |
|
|
|
} |
|
|
|
|
|
|
|
offsetDecompressed += this.width; |
|
|
|
offsetDecompressed += this.Width; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|