11// Copyright (c) Six Labors.
22// Licensed under the Six Labors Split License.
33
4+ using System . Runtime . Intrinsics . Arm ;
5+ using System . Runtime . Intrinsics . X86 ;
46using SixLabors . ImageSharp . ColorSpaces ;
57using SixLabors . ImageSharp . ColorSpaces . Conversion ;
68using SixLabors . ImageSharp . Formats . Jpeg . Components ;
@@ -69,6 +71,171 @@ internal void GetConverterReturnsValidConverter(JpegColorSpace colorSpace, int p
6971 Assert . Equal ( precision , converter . Precision ) ;
7072 }
7173
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+
72239 [ Theory ]
73240 [ InlineData ( JpegColorSpace . Grayscale , 1 ) ]
74241 [ InlineData ( JpegColorSpace . Ycck , 4 ) ]
@@ -242,15 +409,17 @@ static void RunTest(string arg) =>
242409 [ Theory ]
243410 [ MemberData ( nameof ( Seeds ) ) ]
244411 public void FromYCbCrAvx2 ( int seed ) =>
245- this . TestConversionToRgb ( new JpegColorConverterBase . YCbCrAvx ( 8 ) ,
412+ this . TestConversionToRgb (
413+ new JpegColorConverterBase . YCbCrAvx ( 8 ) ,
246414 3 ,
247415 seed ,
248416 new JpegColorConverterBase . YCbCrScalar ( 8 ) ) ;
249417
250418 [ Theory ]
251419 [ MemberData ( nameof ( Seeds ) ) ]
252420 public void FromRgbToYCbCrAvx2 ( int seed ) =>
253- this . TestConversionFromRgb ( new JpegColorConverterBase . YCbCrAvx ( 8 ) ,
421+ this . TestConversionFromRgb (
422+ new JpegColorConverterBase . YCbCrAvx ( 8 ) ,
254423 3 ,
255424 seed ,
256425 new JpegColorConverterBase . YCbCrScalar ( 8 ) ,
@@ -259,15 +428,17 @@ public void FromRgbToYCbCrAvx2(int seed) =>
259428 [ Theory ]
260429 [ MemberData ( nameof ( Seeds ) ) ]
261430 public void FromCmykAvx2 ( int seed ) =>
262- this . TestConversionToRgb ( new JpegColorConverterBase . CmykAvx ( 8 ) ,
431+ this . TestConversionToRgb (
432+ new JpegColorConverterBase . CmykAvx ( 8 ) ,
263433 4 ,
264434 seed ,
265435 new JpegColorConverterBase . CmykScalar ( 8 ) ) ;
266436
267437 [ Theory ]
268438 [ MemberData ( nameof ( Seeds ) ) ]
269439 public void FromRgbToCmykAvx2 ( int seed ) =>
270- this . TestConversionFromRgb ( new JpegColorConverterBase . CmykAvx ( 8 ) ,
440+ this . TestConversionFromRgb (
441+ new JpegColorConverterBase . CmykAvx ( 8 ) ,
271442 4 ,
272443 seed ,
273444 new JpegColorConverterBase . CmykScalar ( 8 ) ,
@@ -276,15 +447,17 @@ public void FromRgbToCmykAvx2(int seed) =>
276447 [ Theory ]
277448 [ MemberData ( nameof ( Seeds ) ) ]
278449 public void FromCmykArm ( int seed ) =>
279- this . TestConversionToRgb ( new JpegColorConverterBase . CmykArm64 ( 8 ) ,
450+ this . TestConversionToRgb (
451+ new JpegColorConverterBase . CmykArm64 ( 8 ) ,
280452 4 ,
281453 seed ,
282454 new JpegColorConverterBase . CmykScalar ( 8 ) ) ;
283455
284456 [ Theory ]
285457 [ MemberData ( nameof ( Seeds ) ) ]
286458 public void FromRgbToCmykArm ( int seed ) =>
287- this . TestConversionFromRgb ( new JpegColorConverterBase . CmykArm64 ( 8 ) ,
459+ this . TestConversionFromRgb (
460+ new JpegColorConverterBase . CmykArm64 ( 8 ) ,
288461 4 ,
289462 seed ,
290463 new JpegColorConverterBase . CmykScalar ( 8 ) ,
@@ -293,15 +466,17 @@ public void FromRgbToCmykArm(int seed) =>
293466 [ Theory ]
294467 [ MemberData ( nameof ( Seeds ) ) ]
295468 public void FromGrayscaleAvx2 ( int seed ) =>
296- this . TestConversionToRgb ( new JpegColorConverterBase . GrayscaleAvx ( 8 ) ,
469+ this . TestConversionToRgb (
470+ new JpegColorConverterBase . GrayscaleAvx ( 8 ) ,
297471 1 ,
298472 seed ,
299473 new JpegColorConverterBase . GrayscaleScalar ( 8 ) ) ;
300474
301475 [ Theory ]
302476 [ MemberData ( nameof ( Seeds ) ) ]
303477 public void FromRgbToGrayscaleAvx2 ( int seed ) =>
304- this . TestConversionFromRgb ( new JpegColorConverterBase . GrayscaleAvx ( 8 ) ,
478+ this . TestConversionFromRgb (
479+ new JpegColorConverterBase . GrayscaleAvx ( 8 ) ,
305480 1 ,
306481 seed ,
307482 new JpegColorConverterBase . GrayscaleScalar ( 8 ) ,
@@ -327,31 +502,35 @@ public void FromRgbToGrayscaleArm(int seed) =>
327502 [ Theory ]
328503 [ MemberData ( nameof ( Seeds ) ) ]
329504 public void FromRgbAvx2 ( int seed ) =>
330- this . TestConversionToRgb ( new JpegColorConverterBase . RgbAvx ( 8 ) ,
505+ this . TestConversionToRgb (
506+ new JpegColorConverterBase . RgbAvx ( 8 ) ,
331507 3 ,
332508 seed ,
333509 new JpegColorConverterBase . RgbScalar ( 8 ) ) ;
334510
335511 [ Theory ]
336512 [ MemberData ( nameof ( Seeds ) ) ]
337513 public void FromRgbArm ( int seed ) =>
338- this . TestConversionToRgb ( new JpegColorConverterBase . RgbArm ( 8 ) ,
514+ this . TestConversionToRgb (
515+ new JpegColorConverterBase . RgbArm ( 8 ) ,
339516 3 ,
340517 seed ,
341518 new JpegColorConverterBase . RgbScalar ( 8 ) ) ;
342519
343520 [ Theory ]
344521 [ MemberData ( nameof ( Seeds ) ) ]
345522 public void FromYccKAvx2 ( int seed ) =>
346- this . TestConversionToRgb ( new JpegColorConverterBase . YccKAvx ( 8 ) ,
523+ this . TestConversionToRgb (
524+ new JpegColorConverterBase . YccKAvx ( 8 ) ,
347525 4 ,
348526 seed ,
349527 new JpegColorConverterBase . YccKScalar ( 8 ) ) ;
350528
351529 [ Theory ]
352530 [ MemberData ( nameof ( Seeds ) ) ]
353531 public void FromRgbToYccKAvx2 ( int seed ) =>
354- this . TestConversionFromRgb ( new JpegColorConverterBase . YccKAvx ( 8 ) ,
532+ this . TestConversionFromRgb (
533+ new JpegColorConverterBase . YccKAvx ( 8 ) ,
355534 4 ,
356535 seed ,
357536 new JpegColorConverterBase . YccKScalar ( 8 ) ,
0 commit comments