@@ -42,7 +42,6 @@ public static void ProcessInterlacedGrayscaleScanline<TPixel>(
42
42
where TPixel : unmanaged, IPixel < TPixel >
43
43
{
44
44
uint offset = pixelOffset + frameControl . XOffset ;
45
- TPixel pixel = default ;
46
45
ref byte scanlineSpanRef = ref MemoryMarshal . GetReference ( scanlineSpan ) ;
47
46
ref TPixel rowSpanRef = ref MemoryMarshal . GetReference ( rowSpan ) ;
48
47
int scaleFactor = 255 / ( ColorNumerics . GetColorCountForBitDepth ( bitDepth ) - 1 ) ;
@@ -55,17 +54,15 @@ public static void ProcessInterlacedGrayscaleScanline<TPixel>(
55
54
for ( nuint x = offset ; x < frameControl . XMax ; x += increment , o += 2 )
56
55
{
57
56
ushort luminance = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o , 2 ) ) ;
58
- pixel . FromL16 ( Unsafe . As < ushort , L16 > ( ref luminance ) ) ;
59
- Unsafe . Add ( ref rowSpanRef , x ) = pixel;
57
+ Unsafe . Add ( ref rowSpanRef , x ) = TPixel. FromL16 ( Unsafe . As < ushort , L16 > ( ref luminance ) ) ;
60
58
}
61
59
}
62
60
else
63
61
{
64
62
for ( nuint x = offset , o = 0 ; x < frameControl . XMax ; x += increment , o ++ )
65
63
{
66
64
byte luminance = ( byte ) ( Unsafe . Add ( ref scanlineSpanRef , o ) * scaleFactor ) ;
67
- pixel . FromL8 ( Unsafe . As < byte , L8 > ( ref luminance ) ) ;
68
- Unsafe . Add ( ref rowSpanRef , x ) = pixel;
65
+ Unsafe . Add ( ref rowSpanRef , x ) = TPixel. FromL8 ( Unsafe . As < byte , L8 > ( ref luminance ) ) ;
69
66
}
70
67
}
71
68
@@ -75,30 +72,22 @@ public static void ProcessInterlacedGrayscaleScanline<TPixel>(
75
72
if ( bitDepth == 16 )
76
73
{
77
74
L16 transparent = transparentColor . Value . ToPixel < L16 > ( ) ;
78
- La32 source = default ;
79
75
int o = 0 ;
80
76
for ( nuint x = offset ; x < frameControl . XMax ; x += increment , o += 2 )
81
77
{
82
78
ushort luminance = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o , 2 ) ) ;
83
- source . L = luminance ;
84
- source . A = luminance . Equals ( transparent . PackedValue ) ? ushort . MinValue : ushort . MaxValue ;
85
-
86
- pixel . FromLa32 ( source ) ;
87
- Unsafe . Add ( ref rowSpanRef , x ) = pixel;
79
+ La32 source = new ( luminance , luminance . Equals ( transparent . PackedValue ) ? ushort . MinValue : ushort . MaxValue ) ;
80
+ Unsafe . Add ( ref rowSpanRef , x ) = TPixel. FromLa32 ( source ) ;
88
81
}
89
82
}
90
83
else
91
84
{
92
85
byte transparent = ( byte ) ( transparentColor . Value . ToPixel < L8 > ( ) . PackedValue * scaleFactor ) ;
93
- La16 source = default ;
94
86
for ( nuint x = offset , o = 0 ; x < frameControl . XMax ; x += increment , o ++ )
95
87
{
96
88
byte luminance = ( byte ) ( Unsafe . Add ( ref scanlineSpanRef , o ) * scaleFactor ) ;
97
- source . L = luminance ;
98
- source . A = luminance . Equals ( transparent ) ? byte . MinValue : byte . MaxValue ;
99
-
100
- pixel . FromLa16 ( source ) ;
101
- Unsafe . Add ( ref rowSpanRef , x ) = pixel;
89
+ La16 source = new ( luminance , luminance . Equals ( transparent ) ? byte . MinValue : byte . MaxValue ) ;
90
+ Unsafe . Add ( ref rowSpanRef , x ) = TPixel. FromLa16 ( source ) ;
102
91
}
103
92
}
104
93
}
@@ -133,34 +122,28 @@ public static void ProcessInterlacedGrayscaleWithAlphaScanline<TPixel>(
133
122
where TPixel : unmanaged, IPixel < TPixel >
134
123
{
135
124
uint offset = pixelOffset + frameControl . XOffset ;
136
- TPixel pixel = default ;
137
125
ref byte scanlineSpanRef = ref MemoryMarshal . GetReference ( scanlineSpan ) ;
138
126
ref TPixel rowSpanRef = ref MemoryMarshal . GetReference ( rowSpan ) ;
139
127
140
128
if ( bitDepth == 16 )
141
129
{
142
- La32 source = default ;
143
130
int o = 0 ;
144
131
for ( nuint x = offset ; x < frameControl . XMax ; x += increment , o += 4 )
145
132
{
146
- source . L = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o , 2 ) ) ;
147
- source . A = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o + 2 , 2 ) ) ;
133
+ ushort l = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o , 2 ) ) ;
134
+ ushort a = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o + 2 , 2 ) ) ;
148
135
149
- pixel . FromLa32 ( source ) ;
150
- Unsafe . Add ( ref rowSpanRef , ( uint ) x ) = pixel;
136
+ Unsafe . Add ( ref rowSpanRef , ( uint ) x ) = TPixel. FromLa32 ( new ( l , a ) ) ;
151
137
}
152
138
}
153
139
else
154
140
{
155
- La16 source = default ;
156
141
nuint offset2 = 0 ;
157
142
for ( nuint x = offset ; x < frameControl . XMax ; x += increment )
158
143
{
159
- source . L = Unsafe . Add ( ref scanlineSpanRef , offset2 ) ;
160
- source . A = Unsafe . Add ( ref scanlineSpanRef , offset2 + bytesPerSample ) ;
161
-
162
- pixel . FromLa16 ( source ) ;
163
- Unsafe . Add ( ref rowSpanRef , x ) = pixel;
144
+ byte l = Unsafe . Add ( ref scanlineSpanRef , offset2 ) ;
145
+ byte a = Unsafe . Add ( ref scanlineSpanRef , offset2 + bytesPerSample ) ;
146
+ Unsafe . Add ( ref rowSpanRef , x ) = TPixel. FromLa16 ( new ( l , a ) ) ;
164
147
offset2 += bytesPerPixel ;
165
148
}
166
149
}
@@ -194,16 +177,14 @@ public static void ProcessInterlacedPaletteScanline<TPixel>(
194
177
PngThrowHelper . ThrowMissingPalette ( ) ;
195
178
}
196
179
197
- TPixel pixel = default ;
198
180
ref byte scanlineSpanRef = ref MemoryMarshal . GetReference ( scanlineSpan ) ;
199
181
ref TPixel rowSpanRef = ref MemoryMarshal . GetReference ( rowSpan ) ;
200
182
ref Color paletteBase = ref MemoryMarshal . GetReference ( palette . Value . Span ) ;
201
183
202
184
for ( nuint x = pixelOffset , o = 0 ; x < frameControl . XMax ; x += increment , o ++ )
203
185
{
204
186
uint index = Unsafe . Add ( ref scanlineSpanRef , o ) ;
205
- pixel . FromRgba32 ( Unsafe . Add ( ref paletteBase , index ) . ToPixel < Rgba32 > ( ) ) ;
206
- Unsafe . Add ( ref rowSpanRef , x ) = pixel;
187
+ Unsafe . Add ( ref rowSpanRef , x ) = TPixel. FromRgba32 ( Unsafe . Add ( ref paletteBase , index ) . ToPixel < Rgba32 > ( ) ) ;
207
188
}
208
189
}
209
190
@@ -243,25 +224,20 @@ public static void ProcessInterlacedRgbScanline<TPixel>(
243
224
where TPixel : unmanaged, IPixel < TPixel >
244
225
{
245
226
uint offset = pixelOffset + frameControl . XOffset ;
246
-
247
- TPixel pixel = default ;
248
227
ref byte scanlineSpanRef = ref MemoryMarshal . GetReference ( scanlineSpan ) ;
249
228
ref TPixel rowSpanRef = ref MemoryMarshal . GetReference ( rowSpan ) ;
250
229
251
230
if ( transparentColor is null )
252
231
{
253
232
if ( bitDepth == 16 )
254
233
{
255
- Rgb48 rgb48 = default ;
256
234
int o = 0 ;
257
235
for ( nuint x = offset ; x < frameControl . XMax ; x += increment , o += bytesPerPixel )
258
236
{
259
- rgb48 . R = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o , bytesPerSample ) ) ;
260
- rgb48 . G = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o + bytesPerSample , bytesPerSample ) ) ;
261
- rgb48 . B = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o + ( 2 * bytesPerSample ) , bytesPerSample ) ) ;
262
-
263
- pixel . FromRgb48 ( rgb48 ) ;
264
- Unsafe . Add ( ref rowSpanRef , x ) = pixel;
237
+ ushort r = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o , bytesPerSample ) ) ;
238
+ ushort g = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o + bytesPerSample , bytesPerSample ) ) ;
239
+ ushort b = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o + ( 2 * bytesPerSample ) , bytesPerSample ) ) ;
240
+ Unsafe . Add ( ref rowSpanRef , x ) = TPixel. FromRgb48 ( new ( r , g , b ) ) ;
265
241
}
266
242
}
267
243
else if ( pixelOffset == 0 && increment == 1 )
@@ -274,16 +250,13 @@ public static void ProcessInterlacedRgbScanline<TPixel>(
274
250
}
275
251
else
276
252
{
277
- Rgb24 rgb = default ;
278
253
int o = 0 ;
279
254
for ( nuint x = offset ; x < frameControl . XMax ; x += increment , o += bytesPerPixel )
280
255
{
281
- rgb . R = Unsafe . Add ( ref scanlineSpanRef , ( uint ) o ) ;
282
- rgb . G = Unsafe . Add ( ref scanlineSpanRef , ( uint ) ( o + bytesPerSample ) ) ;
283
- rgb . B = Unsafe . Add ( ref scanlineSpanRef , ( uint ) ( o + ( 2 * bytesPerSample ) ) ) ;
284
-
285
- pixel . FromRgb24 ( rgb ) ;
286
- Unsafe . Add ( ref rowSpanRef , x ) = pixel;
256
+ byte r = Unsafe . Add ( ref scanlineSpanRef , ( uint ) o ) ;
257
+ byte g = Unsafe . Add ( ref scanlineSpanRef , ( uint ) ( o + bytesPerSample ) ) ;
258
+ byte b = Unsafe . Add ( ref scanlineSpanRef , ( uint ) ( o + ( 2 * bytesPerSample ) ) ) ;
259
+ Unsafe . Add ( ref rowSpanRef , x ) = TPixel. FromRgb24 ( new ( r , g , b ) ) ;
287
260
}
288
261
}
289
262
@@ -293,27 +266,20 @@ public static void ProcessInterlacedRgbScanline<TPixel>(
293
266
if ( bitDepth == 16 )
294
267
{
295
268
Rgb48 transparent = transparentColor . Value . ToPixel < Rgb48 > ( ) ;
296
-
297
- Rgb48 rgb48 = default ;
298
- Rgba64 rgba64 = default ;
269
+ Rgba64 rgba = default ;
299
270
int o = 0 ;
300
271
for ( nuint x = offset ; x < frameControl . XMax ; x += increment , o += bytesPerPixel )
301
272
{
302
- rgb48 . R = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o , bytesPerSample ) ) ;
303
- rgb48 . G = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o + bytesPerSample , bytesPerSample ) ) ;
304
- rgb48 . B = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o + ( 2 * bytesPerSample ) , bytesPerSample ) ) ;
305
-
306
- rgba64 . Rgb = rgb48 ;
307
- rgba64 . A = rgb48 . Equals ( transparent ) ? ushort . MinValue : ushort . MaxValue ;
308
-
309
- pixel . FromRgba64 ( rgba64 ) ;
310
- Unsafe . Add ( ref rowSpanRef , x ) = pixel;
273
+ rgba . R = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o , bytesPerSample ) ) ;
274
+ rgba . G = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o + bytesPerSample , bytesPerSample ) ) ;
275
+ rgba . B = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o + ( 2 * bytesPerSample ) , bytesPerSample ) ) ;
276
+ rgba . A = rgba . Rgb . Equals ( transparent ) ? ushort . MinValue : ushort . MaxValue ;
277
+ Unsafe . Add ( ref rowSpanRef , x ) = TPixel. FromRgba64 ( rgba ) ;
311
278
}
312
279
}
313
280
else
314
281
{
315
282
Rgb24 transparent = transparentColor . Value . ToPixel < Rgb24 > ( ) ;
316
-
317
283
Rgba32 rgba = default ;
318
284
int o = 0 ;
319
285
for ( nuint x = offset ; x < frameControl . XMax ; x += increment , o += bytesPerPixel )
@@ -322,9 +288,7 @@ public static void ProcessInterlacedRgbScanline<TPixel>(
322
288
rgba . G = Unsafe . Add ( ref scanlineSpanRef , ( uint ) ( o + bytesPerSample ) ) ;
323
289
rgba . B = Unsafe . Add ( ref scanlineSpanRef , ( uint ) ( o + ( 2 * bytesPerSample ) ) ) ;
324
290
rgba . A = transparent . Equals ( rgba . Rgb ) ? byte . MinValue : byte . MaxValue ;
325
-
326
- pixel . FromRgba32 ( rgba ) ;
327
- Unsafe . Add ( ref rowSpanRef , x ) = pixel;
291
+ Unsafe . Add ( ref rowSpanRef , x ) = TPixel. FromRgba32 ( rgba ) ;
328
292
}
329
293
}
330
294
}
@@ -362,22 +326,18 @@ public static void ProcessInterlacedRgbaScanline<TPixel>(
362
326
where TPixel : unmanaged, IPixel < TPixel >
363
327
{
364
328
uint offset = pixelOffset + frameControl . XOffset ;
365
- TPixel pixel = default ;
366
329
ref TPixel rowSpanRef = ref MemoryMarshal . GetReference ( rowSpan ) ;
367
330
368
331
if ( bitDepth == 16 )
369
332
{
370
- Rgba64 rgba64 = default ;
371
333
int o = 0 ;
372
334
for ( nuint x = offset ; x < frameControl . XMax ; x += increment , o += bytesPerPixel )
373
335
{
374
- rgba64 . R = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o , bytesPerSample ) ) ;
375
- rgba64 . G = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o + bytesPerSample , bytesPerSample ) ) ;
376
- rgba64 . B = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o + ( 2 * bytesPerSample ) , bytesPerSample ) ) ;
377
- rgba64 . A = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o + ( 3 * bytesPerSample ) , bytesPerSample ) ) ;
378
-
379
- pixel . FromRgba64 ( rgba64 ) ;
380
- Unsafe . Add ( ref rowSpanRef , x ) = pixel;
336
+ ushort r = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o , bytesPerSample ) ) ;
337
+ ushort g = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o + bytesPerSample , bytesPerSample ) ) ;
338
+ ushort b = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o + ( 2 * bytesPerSample ) , bytesPerSample ) ) ;
339
+ ushort a = BinaryPrimitives . ReadUInt16BigEndian ( scanlineSpan . Slice ( o + ( 3 * bytesPerSample ) , bytesPerSample ) ) ;
340
+ Unsafe . Add ( ref rowSpanRef , x ) = TPixel. FromRgba64 ( new ( r , g , b , a ) ) ;
381
341
}
382
342
}
383
343
else if ( pixelOffset == 0 && increment == 1 )
@@ -391,17 +351,14 @@ public static void ProcessInterlacedRgbaScanline<TPixel>(
391
351
else
392
352
{
393
353
ref byte scanlineSpanRef = ref MemoryMarshal . GetReference ( scanlineSpan ) ;
394
- Rgba32 rgba = default ;
395
354
int o = 0 ;
396
355
for ( nuint x = offset ; x < frameControl . XMax ; x += increment , o += bytesPerPixel )
397
356
{
398
- rgba . R = Unsafe . Add ( ref scanlineSpanRef , ( uint ) o ) ;
399
- rgba . G = Unsafe . Add ( ref scanlineSpanRef , ( uint ) ( o + bytesPerSample ) ) ;
400
- rgba . B = Unsafe . Add ( ref scanlineSpanRef , ( uint ) ( o + ( 2 * bytesPerSample ) ) ) ;
401
- rgba . A = Unsafe . Add ( ref scanlineSpanRef , ( uint ) ( o + ( 3 * bytesPerSample ) ) ) ;
402
-
403
- pixel . FromRgba32 ( rgba ) ;
404
- Unsafe . Add ( ref rowSpanRef , x ) = pixel;
357
+ byte r = Unsafe . Add ( ref scanlineSpanRef , ( uint ) o ) ;
358
+ byte g = Unsafe . Add ( ref scanlineSpanRef , ( uint ) ( o + bytesPerSample ) ) ;
359
+ byte b = Unsafe . Add ( ref scanlineSpanRef , ( uint ) ( o + ( 2 * bytesPerSample ) ) ) ;
360
+ byte a = Unsafe . Add ( ref scanlineSpanRef , ( uint ) ( o + ( 3 * bytesPerSample ) ) ) ;
361
+ Unsafe . Add ( ref rowSpanRef , x ) = TPixel. FromRgba32 ( new ( r , g , b , a ) ) ;
405
362
}
406
363
}
407
364
}
0 commit comments