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 ) ,
@@ -259,15 +428,17 @@ public void FromRgbToYCbCrAvx2(int seed) =>
259
428
[ Theory ]
260
429
[ MemberData ( nameof ( Seeds ) ) ]
261
430
public void FromCmykAvx2 ( int seed ) =>
262
- this . TestConversionToRgb ( new JpegColorConverterBase . CmykAvx ( 8 ) ,
431
+ this . TestConversionToRgb (
432
+ new JpegColorConverterBase . CmykAvx ( 8 ) ,
263
433
4 ,
264
434
seed ,
265
435
new JpegColorConverterBase . CmykScalar ( 8 ) ) ;
266
436
267
437
[ Theory ]
268
438
[ MemberData ( nameof ( Seeds ) ) ]
269
439
public void FromRgbToCmykAvx2 ( int seed ) =>
270
- this . TestConversionFromRgb ( new JpegColorConverterBase . CmykAvx ( 8 ) ,
440
+ this . TestConversionFromRgb (
441
+ new JpegColorConverterBase . CmykAvx ( 8 ) ,
271
442
4 ,
272
443
seed ,
273
444
new JpegColorConverterBase . CmykScalar ( 8 ) ,
@@ -276,15 +447,17 @@ public void FromRgbToCmykAvx2(int seed) =>
276
447
[ Theory ]
277
448
[ MemberData ( nameof ( Seeds ) ) ]
278
449
public void FromCmykArm ( int seed ) =>
279
- this . TestConversionToRgb ( new JpegColorConverterBase . CmykArm64 ( 8 ) ,
450
+ this . TestConversionToRgb (
451
+ new JpegColorConverterBase . CmykArm64 ( 8 ) ,
280
452
4 ,
281
453
seed ,
282
454
new JpegColorConverterBase . CmykScalar ( 8 ) ) ;
283
455
284
456
[ Theory ]
285
457
[ MemberData ( nameof ( Seeds ) ) ]
286
458
public void FromRgbToCmykArm ( int seed ) =>
287
- this . TestConversionFromRgb ( new JpegColorConverterBase . CmykArm64 ( 8 ) ,
459
+ this . TestConversionFromRgb (
460
+ new JpegColorConverterBase . CmykArm64 ( 8 ) ,
288
461
4 ,
289
462
seed ,
290
463
new JpegColorConverterBase . CmykScalar ( 8 ) ,
@@ -293,15 +466,17 @@ public void FromRgbToCmykArm(int seed) =>
293
466
[ Theory ]
294
467
[ MemberData ( nameof ( Seeds ) ) ]
295
468
public void FromGrayscaleAvx2 ( int seed ) =>
296
- this . TestConversionToRgb ( new JpegColorConverterBase . GrayscaleAvx ( 8 ) ,
469
+ this . TestConversionToRgb (
470
+ new JpegColorConverterBase . GrayscaleAvx ( 8 ) ,
297
471
1 ,
298
472
seed ,
299
473
new JpegColorConverterBase . GrayscaleScalar ( 8 ) ) ;
300
474
301
475
[ Theory ]
302
476
[ MemberData ( nameof ( Seeds ) ) ]
303
477
public void FromRgbToGrayscaleAvx2 ( int seed ) =>
304
- this . TestConversionFromRgb ( new JpegColorConverterBase . GrayscaleAvx ( 8 ) ,
478
+ this . TestConversionFromRgb (
479
+ new JpegColorConverterBase . GrayscaleAvx ( 8 ) ,
305
480
1 ,
306
481
seed ,
307
482
new JpegColorConverterBase . GrayscaleScalar ( 8 ) ,
@@ -327,31 +502,35 @@ public void FromRgbToGrayscaleArm(int seed) =>
327
502
[ Theory ]
328
503
[ MemberData ( nameof ( Seeds ) ) ]
329
504
public void FromRgbAvx2 ( int seed ) =>
330
- this . TestConversionToRgb ( new JpegColorConverterBase . RgbAvx ( 8 ) ,
505
+ this . TestConversionToRgb (
506
+ new JpegColorConverterBase . RgbAvx ( 8 ) ,
331
507
3 ,
332
508
seed ,
333
509
new JpegColorConverterBase . RgbScalar ( 8 ) ) ;
334
510
335
511
[ Theory ]
336
512
[ MemberData ( nameof ( Seeds ) ) ]
337
513
public void FromRgbArm ( int seed ) =>
338
- this . TestConversionToRgb ( new JpegColorConverterBase . RgbArm ( 8 ) ,
514
+ this . TestConversionToRgb (
515
+ new JpegColorConverterBase . RgbArm ( 8 ) ,
339
516
3 ,
340
517
seed ,
341
518
new JpegColorConverterBase . RgbScalar ( 8 ) ) ;
342
519
343
520
[ Theory ]
344
521
[ MemberData ( nameof ( Seeds ) ) ]
345
522
public void FromYccKAvx2 ( int seed ) =>
346
- this . TestConversionToRgb ( new JpegColorConverterBase . YccKAvx ( 8 ) ,
523
+ this . TestConversionToRgb (
524
+ new JpegColorConverterBase . YccKAvx ( 8 ) ,
347
525
4 ,
348
526
seed ,
349
527
new JpegColorConverterBase . YccKScalar ( 8 ) ) ;
350
528
351
529
[ Theory ]
352
530
[ MemberData ( nameof ( Seeds ) ) ]
353
531
public void FromRgbToYccKAvx2 ( int seed ) =>
354
- this . TestConversionFromRgb ( new JpegColorConverterBase . YccKAvx ( 8 ) ,
532
+ this . TestConversionFromRgb (
533
+ new JpegColorConverterBase . YccKAvx ( 8 ) ,
355
534
4 ,
356
535
seed ,
357
536
new JpegColorConverterBase . YccKScalar ( 8 ) ,
0 commit comments