@@ -22,11 +22,6 @@ internal sealed class TgaEncoderCore : IImageEncoderInternals
22
22
/// </summary>
23
23
private readonly MemoryAllocator memoryAllocator ;
24
24
25
- /// <summary>
26
- /// The global configuration.
27
- /// </summary>
28
- private Configuration ? configuration ;
29
-
30
25
/// <summary>
31
26
/// Reusable buffer for writing data.
32
27
/// </summary>
@@ -67,7 +62,6 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream, CancellationToken
67
62
Guard . NotNull ( image , nameof ( image ) ) ;
68
63
Guard . NotNull ( stream , nameof ( stream ) ) ;
69
64
70
- this . configuration = image . GetConfiguration ( ) ;
71
65
ImageMetadata metadata = image . Metadata ;
72
66
TgaMetadata tgaMetadata = metadata . GetTgaMetadata ( ) ;
73
67
this . bitsPerPixel ??= tgaMetadata . BitsPerPixel ;
@@ -123,7 +117,7 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream, CancellationToken
123
117
}
124
118
else
125
119
{
126
- this . WriteImage ( stream , image . Frames . RootFrame ) ;
120
+ this . WriteImage ( image . GetConfiguration ( ) , stream , image . Frames . RootFrame ) ;
127
121
}
128
122
129
123
stream . Flush ( ) ;
@@ -133,30 +127,31 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream, CancellationToken
133
127
/// Writes the pixel data to the binary stream.
134
128
/// </summary>
135
129
/// <typeparam name="TPixel">The pixel format.</typeparam>
130
+ /// <param name="configuration">The global configuration.</param>
136
131
/// <param name="stream">The <see cref="Stream"/> to write to.</param>
137
132
/// <param name="image">
138
133
/// The <see cref="ImageFrame{TPixel}"/> containing pixel data.
139
134
/// </param>
140
- private void WriteImage < TPixel > ( Stream stream , ImageFrame < TPixel > image )
135
+ private void WriteImage < TPixel > ( Configuration configuration , Stream stream , ImageFrame < TPixel > image )
141
136
where TPixel : unmanaged, IPixel < TPixel >
142
137
{
143
138
Buffer2D < TPixel > pixels = image . PixelBuffer ;
144
139
switch ( this . bitsPerPixel )
145
140
{
146
141
case TgaBitsPerPixel . Pixel8 :
147
- this . Write8Bit ( stream , pixels ) ;
142
+ this . Write8Bit ( configuration , stream , pixels ) ;
148
143
break ;
149
144
150
145
case TgaBitsPerPixel . Pixel16 :
151
- this . Write16Bit ( stream , pixels ) ;
146
+ this . Write16Bit ( configuration , stream , pixels ) ;
152
147
break ;
153
148
154
149
case TgaBitsPerPixel . Pixel24 :
155
- this . Write24Bit ( stream , pixels ) ;
150
+ this . Write24Bit ( configuration , stream , pixels ) ;
156
151
break ;
157
152
158
153
case TgaBitsPerPixel . Pixel32 :
159
- this . Write32Bit ( stream , pixels ) ;
154
+ this . Write32Bit ( configuration , stream , pixels ) ;
160
155
break ;
161
156
}
162
157
}
@@ -226,7 +221,7 @@ private void WritePixel<TPixel>(Stream stream, TPixel currentPixel, Rgba32 color
226
221
227
222
case TgaBitsPerPixel . Pixel16 :
228
223
Bgra5551 bgra5551 = new ( color . ToVector4 ( ) ) ;
229
- BinaryPrimitives . TryWriteInt16LittleEndian ( this . buffer , ( short ) bgra5551 . PackedValue ) ;
224
+ BinaryPrimitives . WriteInt16LittleEndian ( this . buffer , ( short ) bgra5551 . PackedValue ) ;
230
225
stream . WriteByte ( this . buffer [ 0 ] ) ;
231
226
stream . WriteByte ( this . buffer [ 1 ] ) ;
232
227
@@ -320,9 +315,10 @@ private IMemoryOwner<byte> AllocateRow(int width, int bytesPerPixel)
320
315
/// Writes the 8bit pixels uncompressed to the stream.
321
316
/// </summary>
322
317
/// <typeparam name="TPixel">The pixel format.</typeparam>
318
+ /// <param name="configuration">The global configuration.</param>
323
319
/// <param name="stream">The <see cref="Stream"/> to write to.</param>
324
320
/// <param name="pixels">The <see cref="Buffer2D{TPixel}"/> containing pixel data.</param>
325
- private void Write8Bit < TPixel > ( Stream stream , Buffer2D < TPixel > pixels )
321
+ private void Write8Bit < TPixel > ( Configuration configuration , Stream stream , Buffer2D < TPixel > pixels )
326
322
where TPixel : unmanaged, IPixel < TPixel >
327
323
{
328
324
using IMemoryOwner < byte > row = this . AllocateRow ( pixels . Width , 1 ) ;
@@ -332,7 +328,7 @@ private void Write8Bit<TPixel>(Stream stream, Buffer2D<TPixel> pixels)
332
328
{
333
329
Span < TPixel > pixelSpan = pixels . DangerousGetRowSpan ( y ) ;
334
330
PixelOperations < TPixel > . Instance . ToL8Bytes (
335
- this . configuration ,
331
+ configuration ,
336
332
pixelSpan ,
337
333
rowSpan ,
338
334
pixelSpan . Length ) ;
@@ -344,9 +340,10 @@ private void Write8Bit<TPixel>(Stream stream, Buffer2D<TPixel> pixels)
344
340
/// Writes the 16bit pixels uncompressed to the stream.
345
341
/// </summary>
346
342
/// <typeparam name="TPixel">The pixel format.</typeparam>
343
+ /// <param name="configuration">The global configuration.</param>
347
344
/// <param name="stream">The <see cref="Stream"/> to write to.</param>
348
345
/// <param name="pixels">The <see cref="Buffer2D{TPixel}"/> containing pixel data.</param>
349
- private void Write16Bit < TPixel > ( Stream stream , Buffer2D < TPixel > pixels )
346
+ private void Write16Bit < TPixel > ( Configuration configuration , Stream stream , Buffer2D < TPixel > pixels )
350
347
where TPixel : unmanaged, IPixel < TPixel >
351
348
{
352
349
using IMemoryOwner < byte > row = this . AllocateRow ( pixels . Width , 2 ) ;
@@ -356,7 +353,7 @@ private void Write16Bit<TPixel>(Stream stream, Buffer2D<TPixel> pixels)
356
353
{
357
354
Span < TPixel > pixelSpan = pixels . DangerousGetRowSpan ( y ) ;
358
355
PixelOperations < TPixel > . Instance . ToBgra5551Bytes (
359
- this . configuration ,
356
+ configuration ,
360
357
pixelSpan ,
361
358
rowSpan ,
362
359
pixelSpan . Length ) ;
@@ -368,9 +365,10 @@ private void Write16Bit<TPixel>(Stream stream, Buffer2D<TPixel> pixels)
368
365
/// Writes the 24bit pixels uncompressed to the stream.
369
366
/// </summary>
370
367
/// <typeparam name="TPixel">The pixel format.</typeparam>
368
+ /// <param name="configuration">The global configuration.</param>
371
369
/// <param name="stream">The <see cref="Stream"/> to write to.</param>
372
370
/// <param name="pixels">The <see cref="Buffer2D{TPixel}"/> containing pixel data.</param>
373
- private void Write24Bit < TPixel > ( Stream stream , Buffer2D < TPixel > pixels )
371
+ private void Write24Bit < TPixel > ( Configuration configuration , Stream stream , Buffer2D < TPixel > pixels )
374
372
where TPixel : unmanaged, IPixel < TPixel >
375
373
{
376
374
using IMemoryOwner < byte > row = this . AllocateRow ( pixels . Width , 3 ) ;
@@ -380,7 +378,7 @@ private void Write24Bit<TPixel>(Stream stream, Buffer2D<TPixel> pixels)
380
378
{
381
379
Span < TPixel > pixelSpan = pixels . DangerousGetRowSpan ( y ) ;
382
380
PixelOperations < TPixel > . Instance . ToBgr24Bytes (
383
- this . configuration ,
381
+ configuration ,
384
382
pixelSpan ,
385
383
rowSpan ,
386
384
pixelSpan . Length ) ;
@@ -392,9 +390,10 @@ private void Write24Bit<TPixel>(Stream stream, Buffer2D<TPixel> pixels)
392
390
/// Writes the 32bit pixels uncompressed to the stream.
393
391
/// </summary>
394
392
/// <typeparam name="TPixel">The pixel format.</typeparam>
393
+ /// <param name="configuration">The global configuration.</param>
395
394
/// <param name="stream">The <see cref="Stream"/> to write to.</param>
396
395
/// <param name="pixels">The <see cref="Buffer2D{TPixel}"/> containing pixel data.</param>
397
- private void Write32Bit < TPixel > ( Stream stream , Buffer2D < TPixel > pixels )
396
+ private void Write32Bit < TPixel > ( Configuration configuration , Stream stream , Buffer2D < TPixel > pixels )
398
397
where TPixel : unmanaged, IPixel < TPixel >
399
398
{
400
399
using IMemoryOwner < byte > row = this . AllocateRow ( pixels . Width , 4 ) ;
@@ -404,7 +403,7 @@ private void Write32Bit<TPixel>(Stream stream, Buffer2D<TPixel> pixels)
404
403
{
405
404
Span < TPixel > pixelSpan = pixels . DangerousGetRowSpan ( y ) ;
406
405
PixelOperations < TPixel > . Instance . ToBgra32Bytes (
407
- this . configuration ,
406
+ configuration ,
408
407
pixelSpan ,
409
408
rowSpan ,
410
409
pixelSpan . Length ) ;
0 commit comments