1
1
// Copyright (c) Six Labors.
2
2
// Licensed under the Six Labors Split License.
3
3
4
+ using System . Runtime . Intrinsics . Arm ;
5
+ using System . Runtime . Intrinsics . X86 ;
4
6
using SixLabors . ImageSharp . ColorSpaces ;
5
7
using SixLabors . ImageSharp . ColorSpaces . Conversion ;
6
8
using SixLabors . ImageSharp . Formats . Jpeg . Components ;
@@ -69,6 +71,171 @@ internal void GetConverterReturnsValidConverter(JpegColorSpace colorSpace, int p
69
71
Assert . Equal ( precision , converter . Precision ) ;
70
72
}
71
73
74
+ [ Fact ]
75
+ public void GetConverterReturnsCorrectConverterWithRgbColorSpace ( )
76
+ {
77
+ FeatureTestRunner . RunWithHwIntrinsicsFeature (
78
+ RunTest ,
79
+ HwIntrinsics . AllowAll | HwIntrinsics . DisableAVX2 | HwIntrinsics . DisableSSE2 | HwIntrinsics . DisableHWIntrinsic ) ;
80
+
81
+ static void RunTest ( string arg )
82
+ {
83
+ // arrange
84
+ Type expectedType = typeof ( JpegColorConverterBase . RgbScalar ) ;
85
+ if ( Avx . IsSupported )
86
+ {
87
+ expectedType = typeof ( JpegColorConverterBase . RgbAvx ) ;
88
+ }
89
+ else if ( Sse2 . IsSupported )
90
+ {
91
+ expectedType = typeof ( JpegColorConverterBase . RgbVector ) ;
92
+ }
93
+ else if ( AdvSimd . IsSupported )
94
+ {
95
+ expectedType = typeof ( JpegColorConverterBase . RgbArm ) ;
96
+ }
97
+
98
+ // act
99
+ JpegColorConverterBase converter = JpegColorConverterBase . GetConverter ( JpegColorSpace . RGB , 8 ) ;
100
+ Type actualType = converter . GetType ( ) ;
101
+
102
+ // assert
103
+ Assert . Equal ( expectedType , actualType ) ;
104
+ }
105
+ }
106
+
107
+ [ Fact ]
108
+ public void GetConverterReturnsCorrectConverterWithGrayScaleColorSpace ( )
109
+ {
110
+ FeatureTestRunner . RunWithHwIntrinsicsFeature (
111
+ RunTest ,
112
+ HwIntrinsics . AllowAll | HwIntrinsics . DisableAVX2 | HwIntrinsics . DisableSSE2 | HwIntrinsics . DisableHWIntrinsic ) ;
113
+
114
+ static void RunTest ( string arg )
115
+ {
116
+ // arrange
117
+ Type expectedType = typeof ( JpegColorConverterBase . GrayscaleScalar ) ;
118
+ if ( Avx . IsSupported )
119
+ {
120
+ expectedType = typeof ( JpegColorConverterBase . GrayscaleAvx ) ;
121
+ }
122
+ else if ( Sse2 . IsSupported )
123
+ {
124
+ expectedType = typeof ( JpegColorConverterBase . GrayScaleVector ) ;
125
+ }
126
+ else if ( AdvSimd . IsSupported )
127
+ {
128
+ expectedType = typeof ( JpegColorConverterBase . GrayscaleArm ) ;
129
+ }
130
+
131
+ // act
132
+ JpegColorConverterBase converter = JpegColorConverterBase . GetConverter ( JpegColorSpace . Grayscale , 8 ) ;
133
+ Type actualType = converter . GetType ( ) ;
134
+
135
+ // assert
136
+ Assert . Equal ( expectedType , actualType ) ;
137
+ }
138
+ }
139
+
140
+ [ Fact ]
141
+ public void GetConverterReturnsCorrectConverterWithCmykColorSpace ( )
142
+ {
143
+ FeatureTestRunner . RunWithHwIntrinsicsFeature (
144
+ RunTest ,
145
+ HwIntrinsics . AllowAll | HwIntrinsics . DisableAVX2 | HwIntrinsics . DisableSSE2 | HwIntrinsics . DisableHWIntrinsic ) ;
146
+
147
+ static void RunTest ( string arg )
148
+ {
149
+ // arrange
150
+ Type expectedType = typeof ( JpegColorConverterBase . CmykScalar ) ;
151
+ if ( Avx . IsSupported )
152
+ {
153
+ expectedType = typeof ( JpegColorConverterBase . CmykAvx ) ;
154
+ }
155
+ else if ( Sse2 . IsSupported )
156
+ {
157
+ expectedType = typeof ( JpegColorConverterBase . CmykVector ) ;
158
+ }
159
+ else if ( AdvSimd . IsSupported )
160
+ {
161
+ expectedType = typeof ( JpegColorConverterBase . CmykArm64 ) ;
162
+ }
163
+
164
+ // act
165
+ JpegColorConverterBase converter = JpegColorConverterBase . GetConverter ( JpegColorSpace . Cmyk , 8 ) ;
166
+ Type actualType = converter . GetType ( ) ;
167
+
168
+ // assert
169
+ Assert . Equal ( expectedType , actualType ) ;
170
+ }
171
+ }
172
+
173
+ [ Fact ]
174
+ public void GetConverterReturnsCorrectConverterWithYCbCrColorSpace ( )
175
+ {
176
+ FeatureTestRunner . RunWithHwIntrinsicsFeature (
177
+ RunTest ,
178
+ HwIntrinsics . AllowAll | HwIntrinsics . DisableAVX2 | HwIntrinsics . DisableSSE2 | HwIntrinsics . DisableHWIntrinsic ) ;
179
+
180
+ static void RunTest ( string arg )
181
+ {
182
+ // arrange
183
+ Type expectedType = typeof ( JpegColorConverterBase . YCbCrScalar ) ;
184
+ if ( Avx . IsSupported )
185
+ {
186
+ expectedType = typeof ( JpegColorConverterBase . YCbCrAvx ) ;
187
+ }
188
+ else if ( Sse2 . IsSupported )
189
+ {
190
+ expectedType = typeof ( JpegColorConverterBase . YCbCrVector ) ;
191
+ }
192
+ else if ( AdvSimd . IsSupported )
193
+ {
194
+ expectedType = typeof ( JpegColorConverterBase . YCbCrVector ) ;
195
+ }
196
+
197
+ // act
198
+ JpegColorConverterBase converter = JpegColorConverterBase . GetConverter ( JpegColorSpace . YCbCr , 8 ) ;
199
+ Type actualType = converter . GetType ( ) ;
200
+
201
+ // assert
202
+ Assert . Equal ( expectedType , actualType ) ;
203
+ }
204
+ }
205
+
206
+ [ Fact ]
207
+ public void GetConverterReturnsCorrectConverterWithYcckColorSpace ( )
208
+ {
209
+ FeatureTestRunner . RunWithHwIntrinsicsFeature (
210
+ RunTest ,
211
+ HwIntrinsics . AllowAll | HwIntrinsics . DisableAVX2 | HwIntrinsics . DisableSSE2 | HwIntrinsics . DisableHWIntrinsic ) ;
212
+
213
+ static void RunTest ( string arg )
214
+ {
215
+ // arrange
216
+ Type expectedType = typeof ( JpegColorConverterBase . YccKScalar ) ;
217
+ if ( Avx . IsSupported )
218
+ {
219
+ expectedType = typeof ( JpegColorConverterBase . YccKAvx ) ;
220
+ }
221
+ else if ( Sse2 . IsSupported )
222
+ {
223
+ expectedType = typeof ( JpegColorConverterBase . YccKVector ) ;
224
+ }
225
+ else if ( AdvSimd . IsSupported )
226
+ {
227
+ expectedType = typeof ( JpegColorConverterBase . YccKVector ) ;
228
+ }
229
+
230
+ // act
231
+ JpegColorConverterBase converter = JpegColorConverterBase . GetConverter ( JpegColorSpace . Ycck , 8 ) ;
232
+ Type actualType = converter . GetType ( ) ;
233
+
234
+ // assert
235
+ Assert . Equal ( expectedType , actualType ) ;
236
+ }
237
+ }
238
+
72
239
[ Theory ]
73
240
[ InlineData ( JpegColorSpace . Grayscale , 1 ) ]
74
241
[ InlineData ( JpegColorSpace . Ycck , 4 ) ]
@@ -242,15 +409,17 @@ static void RunTest(string arg) =>
242
409
[ Theory ]
243
410
[ MemberData ( nameof ( Seeds ) ) ]
244
411
public void FromYCbCrAvx2 ( int seed ) =>
245
- this . TestConversionToRgb ( new JpegColorConverterBase . YCbCrAvx ( 8 ) ,
412
+ this . TestConversionToRgb (
413
+ new JpegColorConverterBase . YCbCrAvx ( 8 ) ,
246
414
3 ,
247
415
seed ,
248
416
new JpegColorConverterBase . YCbCrScalar ( 8 ) ) ;
249
417
250
418
[ Theory ]
251
419
[ MemberData ( nameof ( Seeds ) ) ]
252
420
public void FromRgbToYCbCrAvx2 ( int seed ) =>
253
- this . TestConversionFromRgb ( new JpegColorConverterBase . YCbCrAvx ( 8 ) ,
421
+ this . TestConversionFromRgb (
422
+ new JpegColorConverterBase . YCbCrAvx ( 8 ) ,
254
423
3 ,
255
424
seed ,
256
425
new JpegColorConverterBase . YCbCrScalar ( 8 ) ,
@@ -276,15 +445,17 @@ public void FromRgbToYCbCrArm(int seed) =>
276
445
[ Theory ]
277
446
[ MemberData ( nameof ( Seeds ) ) ]
278
447
public void FromCmykAvx2 ( int seed ) =>
279
- this . TestConversionToRgb ( new JpegColorConverterBase . CmykAvx ( 8 ) ,
448
+ this . TestConversionToRgb (
449
+ new JpegColorConverterBase . CmykAvx ( 8 ) ,
280
450
4 ,
281
451
seed ,
282
452
new JpegColorConverterBase . CmykScalar ( 8 ) ) ;
283
453
284
454
[ Theory ]
285
455
[ MemberData ( nameof ( Seeds ) ) ]
286
456
public void FromRgbToCmykAvx2 ( int seed ) =>
287
- this . TestConversionFromRgb ( new JpegColorConverterBase . CmykAvx ( 8 ) ,
457
+ this . TestConversionFromRgb (
458
+ new JpegColorConverterBase . CmykAvx ( 8 ) ,
288
459
4 ,
289
460
seed ,
290
461
new JpegColorConverterBase . CmykScalar ( 8 ) ,
@@ -293,15 +464,17 @@ public void FromRgbToCmykAvx2(int seed) =>
293
464
[ Theory ]
294
465
[ MemberData ( nameof ( Seeds ) ) ]
295
466
public void FromCmykArm ( int seed ) =>
296
- this . TestConversionToRgb ( new JpegColorConverterBase . CmykArm64 ( 8 ) ,
467
+ this . TestConversionToRgb (
468
+ new JpegColorConverterBase . CmykArm64 ( 8 ) ,
297
469
4 ,
298
470
seed ,
299
471
new JpegColorConverterBase . CmykScalar ( 8 ) ) ;
300
472
301
473
[ Theory ]
302
474
[ MemberData ( nameof ( Seeds ) ) ]
303
475
public void FromRgbToCmykArm ( int seed ) =>
304
- this . TestConversionFromRgb ( new JpegColorConverterBase . CmykArm64 ( 8 ) ,
476
+ this . TestConversionFromRgb (
477
+ new JpegColorConverterBase . CmykArm64 ( 8 ) ,
305
478
4 ,
306
479
seed ,
307
480
new JpegColorConverterBase . CmykScalar ( 8 ) ,
@@ -310,15 +483,17 @@ public void FromRgbToCmykArm(int seed) =>
310
483
[ Theory ]
311
484
[ MemberData ( nameof ( Seeds ) ) ]
312
485
public void FromGrayscaleAvx2 ( int seed ) =>
313
- this . TestConversionToRgb ( new JpegColorConverterBase . GrayscaleAvx ( 8 ) ,
486
+ this . TestConversionToRgb (
487
+ new JpegColorConverterBase . GrayscaleAvx ( 8 ) ,
314
488
1 ,
315
489
seed ,
316
490
new JpegColorConverterBase . GrayscaleScalar ( 8 ) ) ;
317
491
318
492
[ Theory ]
319
493
[ MemberData ( nameof ( Seeds ) ) ]
320
494
public void FromRgbToGrayscaleAvx2 ( int seed ) =>
321
- this . TestConversionFromRgb ( new JpegColorConverterBase . GrayscaleAvx ( 8 ) ,
495
+ this . TestConversionFromRgb (
496
+ new JpegColorConverterBase . GrayscaleAvx ( 8 ) ,
322
497
1 ,
323
498
seed ,
324
499
new JpegColorConverterBase . GrayscaleScalar ( 8 ) ,
@@ -344,31 +519,35 @@ public void FromRgbToGrayscaleArm(int seed) =>
344
519
[ Theory ]
345
520
[ MemberData ( nameof ( Seeds ) ) ]
346
521
public void FromRgbAvx2 ( int seed ) =>
347
- this . TestConversionToRgb ( new JpegColorConverterBase . RgbAvx ( 8 ) ,
522
+ this . TestConversionToRgb (
523
+ new JpegColorConverterBase . RgbAvx ( 8 ) ,
348
524
3 ,
349
525
seed ,
350
526
new JpegColorConverterBase . RgbScalar ( 8 ) ) ;
351
527
352
528
[ Theory ]
353
529
[ MemberData ( nameof ( Seeds ) ) ]
354
530
public void FromRgbArm ( int seed ) =>
355
- this . TestConversionToRgb ( new JpegColorConverterBase . RgbArm ( 8 ) ,
531
+ this . TestConversionToRgb (
532
+ new JpegColorConverterBase . RgbArm ( 8 ) ,
356
533
3 ,
357
534
seed ,
358
535
new JpegColorConverterBase . RgbScalar ( 8 ) ) ;
359
536
360
537
[ Theory ]
361
538
[ MemberData ( nameof ( Seeds ) ) ]
362
539
public void FromYccKAvx2 ( int seed ) =>
363
- this . TestConversionToRgb ( new JpegColorConverterBase . YccKAvx ( 8 ) ,
540
+ this . TestConversionToRgb (
541
+ new JpegColorConverterBase . YccKAvx ( 8 ) ,
364
542
4 ,
365
543
seed ,
366
544
new JpegColorConverterBase . YccKScalar ( 8 ) ) ;
367
545
368
546
[ Theory ]
369
547
[ MemberData ( nameof ( Seeds ) ) ]
370
548
public void FromRgbToYccKAvx2 ( int seed ) =>
371
- this . TestConversionFromRgb ( new JpegColorConverterBase . YccKAvx ( 8 ) ,
549
+ this . TestConversionFromRgb (
550
+ new JpegColorConverterBase . YccKAvx ( 8 ) ,
372
551
4 ,
373
552
seed ,
374
553
new JpegColorConverterBase . YccKScalar ( 8 ) ,
0 commit comments