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 ) ,
@@ -276,15 +445,17 @@ public void FromRgbToYCbCrArm(int seed) =>
276445 [ Theory ]
277446 [ MemberData ( nameof ( Seeds ) ) ]
278447 public void FromCmykAvx2 ( int seed ) =>
279- this . TestConversionToRgb ( new JpegColorConverterBase . CmykAvx ( 8 ) ,
448+ this . TestConversionToRgb (
449+ new JpegColorConverterBase . CmykAvx ( 8 ) ,
280450 4 ,
281451 seed ,
282452 new JpegColorConverterBase . CmykScalar ( 8 ) ) ;
283453
284454 [ Theory ]
285455 [ MemberData ( nameof ( Seeds ) ) ]
286456 public void FromRgbToCmykAvx2 ( int seed ) =>
287- this . TestConversionFromRgb ( new JpegColorConverterBase . CmykAvx ( 8 ) ,
457+ this . TestConversionFromRgb (
458+ new JpegColorConverterBase . CmykAvx ( 8 ) ,
288459 4 ,
289460 seed ,
290461 new JpegColorConverterBase . CmykScalar ( 8 ) ,
@@ -293,15 +464,17 @@ public void FromRgbToCmykAvx2(int seed) =>
293464 [ Theory ]
294465 [ MemberData ( nameof ( Seeds ) ) ]
295466 public void FromCmykArm ( int seed ) =>
296- this . TestConversionToRgb ( new JpegColorConverterBase . CmykArm64 ( 8 ) ,
467+ this . TestConversionToRgb (
468+ new JpegColorConverterBase . CmykArm64 ( 8 ) ,
297469 4 ,
298470 seed ,
299471 new JpegColorConverterBase . CmykScalar ( 8 ) ) ;
300472
301473 [ Theory ]
302474 [ MemberData ( nameof ( Seeds ) ) ]
303475 public void FromRgbToCmykArm ( int seed ) =>
304- this . TestConversionFromRgb ( new JpegColorConverterBase . CmykArm64 ( 8 ) ,
476+ this . TestConversionFromRgb (
477+ new JpegColorConverterBase . CmykArm64 ( 8 ) ,
305478 4 ,
306479 seed ,
307480 new JpegColorConverterBase . CmykScalar ( 8 ) ,
@@ -310,15 +483,17 @@ public void FromRgbToCmykArm(int seed) =>
310483 [ Theory ]
311484 [ MemberData ( nameof ( Seeds ) ) ]
312485 public void FromGrayscaleAvx2 ( int seed ) =>
313- this . TestConversionToRgb ( new JpegColorConverterBase . GrayscaleAvx ( 8 ) ,
486+ this . TestConversionToRgb (
487+ new JpegColorConverterBase . GrayscaleAvx ( 8 ) ,
314488 1 ,
315489 seed ,
316490 new JpegColorConverterBase . GrayscaleScalar ( 8 ) ) ;
317491
318492 [ Theory ]
319493 [ MemberData ( nameof ( Seeds ) ) ]
320494 public void FromRgbToGrayscaleAvx2 ( int seed ) =>
321- this . TestConversionFromRgb ( new JpegColorConverterBase . GrayscaleAvx ( 8 ) ,
495+ this . TestConversionFromRgb (
496+ new JpegColorConverterBase . GrayscaleAvx ( 8 ) ,
322497 1 ,
323498 seed ,
324499 new JpegColorConverterBase . GrayscaleScalar ( 8 ) ,
@@ -344,31 +519,35 @@ public void FromRgbToGrayscaleArm(int seed) =>
344519 [ Theory ]
345520 [ MemberData ( nameof ( Seeds ) ) ]
346521 public void FromRgbAvx2 ( int seed ) =>
347- this . TestConversionToRgb ( new JpegColorConverterBase . RgbAvx ( 8 ) ,
522+ this . TestConversionToRgb (
523+ new JpegColorConverterBase . RgbAvx ( 8 ) ,
348524 3 ,
349525 seed ,
350526 new JpegColorConverterBase . RgbScalar ( 8 ) ) ;
351527
352528 [ Theory ]
353529 [ MemberData ( nameof ( Seeds ) ) ]
354530 public void FromRgbArm ( int seed ) =>
355- this . TestConversionToRgb ( new JpegColorConverterBase . RgbArm ( 8 ) ,
531+ this . TestConversionToRgb (
532+ new JpegColorConverterBase . RgbArm ( 8 ) ,
356533 3 ,
357534 seed ,
358535 new JpegColorConverterBase . RgbScalar ( 8 ) ) ;
359536
360537 [ Theory ]
361538 [ MemberData ( nameof ( Seeds ) ) ]
362539 public void FromYccKAvx2 ( int seed ) =>
363- this . TestConversionToRgb ( new JpegColorConverterBase . YccKAvx ( 8 ) ,
540+ this . TestConversionToRgb (
541+ new JpegColorConverterBase . YccKAvx ( 8 ) ,
364542 4 ,
365543 seed ,
366544 new JpegColorConverterBase . YccKScalar ( 8 ) ) ;
367545
368546 [ Theory ]
369547 [ MemberData ( nameof ( Seeds ) ) ]
370548 public void FromRgbToYccKAvx2 ( int seed ) =>
371- this . TestConversionFromRgb ( new JpegColorConverterBase . YccKAvx ( 8 ) ,
549+ this . TestConversionFromRgb (
550+ new JpegColorConverterBase . YccKAvx ( 8 ) ,
372551 4 ,
373552 seed ,
374553 new JpegColorConverterBase . YccKScalar ( 8 ) ,
0 commit comments