@@ -13,10 +13,6 @@ namespace SixLabors.ImageSharp.Formats.Exr.Compression.Decompressors;
1313/// </summary>
1414internal class B44ExrCompression : ExrBaseDecompressor
1515{
16- private readonly int width ;
17-
18- private readonly uint rowsPerBlock ;
19-
2016 private readonly int channelCount ;
2117
2218 private readonly byte [ ] scratch = new byte [ 14 ] ;
@@ -31,14 +27,12 @@ internal class B44ExrCompression : ExrBaseDecompressor
3127 /// <param name="allocator">The memory allocator.</param>
3228 /// <param name="bytesPerBlock">The bytes per pixel row block.</param>
3329 /// <param name="bytesPerRow">The bytes per row.</param>
34- /// <param name="rowsPerBlock">The rows per block.</param>
30+ /// <param name="rowsPerBlock">The pixel rows per block.</param>
3531 /// <param name="width">The width of a pixel row in pixels.</param>
3632 /// <param name="channelCount">The number of channels of the image.</param>
3733 public B44ExrCompression ( MemoryAllocator allocator , uint bytesPerBlock , uint bytesPerRow , uint rowsPerBlock , int width , int channelCount )
38- : base ( allocator , bytesPerBlock , bytesPerRow )
34+ : base ( allocator , bytesPerBlock , bytesPerRow , rowsPerBlock , width )
3935 {
40- this . width = width ;
41- this . rowsPerBlock = rowsPerBlock ;
4236 this . channelCount = channelCount ;
4337 this . tmpBuffer = allocator . Allocate < ushort > ( ( int ) ( width * rowsPerBlock * channelCount ) ) ;
4438 }
@@ -52,26 +46,27 @@ public override void Decompress(BufferedReadStream stream, uint compressedBytes,
5246 int bytesLeft = ( int ) compressedBytes ;
5347 for ( int i = 0 ; i < this . channelCount && bytesLeft > 0 ; i ++ )
5448 {
55- for ( int y = 0 ; y < this . rowsPerBlock ; y += 4 )
49+ for ( int y = 0 ; y < this . RowsPerBlock ; y += 4 )
5650 {
57- Span < ushort > row0 = decompressed . Slice ( outputOffset , this . width ) ;
58- outputOffset += this . width ;
59- Span < ushort > row1 = decompressed . Slice ( outputOffset , this . width ) ;
60- outputOffset += this . width ;
61- Span < ushort > row2 = decompressed . Slice ( outputOffset , this . width ) ;
62- outputOffset += this . width ;
63- Span < ushort > row3 = decompressed . Slice ( outputOffset , this . width ) ;
64- outputOffset += this . width ;
51+ Span < ushort > row0 = decompressed . Slice ( outputOffset , this . Width ) ;
52+ outputOffset += this . Width ;
53+ Span < ushort > row1 = decompressed . Slice ( outputOffset , this . Width ) ;
54+ outputOffset += this . Width ;
55+ Span < ushort > row2 = decompressed . Slice ( outputOffset , this . Width ) ;
56+ outputOffset += this . Width ;
57+ Span < ushort > row3 = decompressed . Slice ( outputOffset , this . Width ) ;
58+ outputOffset += this . Width ;
6559
6660 int rowOffset = 0 ;
67- for ( int x = 0 ; x < this . width && bytesLeft > 0 ; x += 4 )
61+ for ( int x = 0 ; x < this . Width && bytesLeft > 0 ; x += 4 )
6862 {
6963 int bytesRead = stream . Read ( this . scratch , 0 , 3 ) ;
7064 if ( bytesRead == 0 )
7165 {
7266 ExrThrowHelper . ThrowInvalidImageContentException ( "Could not read enough data from the stream!" ) ;
7367 }
7468
69+ // Check if 3-byte encoded flat field.
7570 if ( this . scratch [ 2 ] >= 13 << 2 )
7671 {
7772 Unpack3 ( this . scratch , this . s ) ;
@@ -89,8 +84,8 @@ public override void Decompress(BufferedReadStream stream, uint compressedBytes,
8984 bytesLeft -= 14 ;
9085 }
9186
92- int n = x + 3 < this . width ? 4 : this . width - x ;
93- if ( y + 3 < this . rowsPerBlock )
87+ int n = x + 3 < this . Width ? 4 : this . Width - x ;
88+ if ( y + 3 < this . RowsPerBlock )
9489 {
9590 this . s . AsSpan ( 0 , n ) . CopyTo ( row0 [ rowOffset ..] ) ;
9691 this . s . AsSpan ( 4 , n ) . CopyTo ( row1 [ rowOffset ..] ) ;
@@ -100,12 +95,12 @@ public override void Decompress(BufferedReadStream stream, uint compressedBytes,
10095 else
10196 {
10297 this . s . AsSpan ( 0 , n ) . CopyTo ( row0 [ rowOffset ..] ) ;
103- if ( y + 1 < this . rowsPerBlock )
98+ if ( y + 1 < this . RowsPerBlock )
10499 {
105100 this . s . AsSpan ( 4 , n ) . CopyTo ( row1 [ rowOffset ..] ) ;
106101 }
107102
108- if ( y + 2 < this . rowsPerBlock )
103+ if ( y + 2 < this . RowsPerBlock )
109104 {
110105 this . s . AsSpan ( 8 , n ) . CopyTo ( row2 [ rowOffset ..] ) ;
111106 }
@@ -124,16 +119,16 @@ public override void Decompress(BufferedReadStream stream, uint compressedBytes,
124119 // Rearrange the decompressed data such that the data for each scan line form a contiguous block.
125120 int offsetDecompressed = 0 ;
126121 int offsetOutput = 0 ;
127- int blockSize = ( int ) ( this . width * this . rowsPerBlock ) ;
128- for ( int y = 0 ; y < this . rowsPerBlock ; y ++ )
122+ int blockSize = ( int ) ( this . Width * this . RowsPerBlock ) ;
123+ for ( int y = 0 ; y < this . RowsPerBlock ; y ++ )
129124 {
130125 for ( int i = 0 ; i < this . channelCount ; i ++ )
131126 {
132- decompressed . Slice ( offsetDecompressed + ( i * blockSize ) , this . width ) . CopyTo ( outputBuffer [ offsetOutput ..] ) ;
133- offsetOutput += this . width ;
127+ decompressed . Slice ( offsetDecompressed + ( i * blockSize ) , this . Width ) . CopyTo ( outputBuffer [ offsetOutput ..] ) ;
128+ offsetOutput += this . Width ;
134129 }
135130
136- offsetDecompressed += this . width ;
131+ offsetDecompressed += this . Width ;
137132 }
138133 }
139134
0 commit comments