2727static UInt16 kBlue16 [] = {0 ,0 ,65535 };
2828static UInt16 kSpecial16 [] = {0xe4 << 8 ,0x7a << 8 ,0x8c << 8 };
2929
30+ static avifNclxColourPrimaries const kNumPrimaries = AVIF_NCLX_COLOUR_PRIMARIES_EBU3213E;
31+ static avifNclxTransferCharacteristics const kNumTransfers = AVIF_NCLX_TRANSFER_CHARACTERISTICS_BT2100_HLG;
32+
33+
3034// FIXME(ledyba-z): libavif does not respect MatrixCoefficients in AV1 Sequence Header.
3135// Instead, it uses ColorPrimaries to calculate MatrixCoefficients.
3236// This threashold can be less if libavif respects MatrixCoefficients...
@@ -156,10 +160,8 @@ - (void)testSpecialTest
156160
157161-(void )testAllColorSpaceSupportsOutput
158162{
159- static avifNclxColourPrimaries const numPrimaries = AVIF_NCLX_COLOUR_PRIMARIES_EBU3213E;
160- static avifNclxTransferCharacteristics const numTransfers = AVIF_NCLX_TRANSFER_CHARACTERISTICS_BT2100_HLG;
161- for (avifNclxColourPrimaries primaries = 0 ; primaries < numPrimaries; ++primaries) {
162- for (avifNclxTransferCharacteristics transfer = 0 ; transfer < numTransfers; ++transfer) {
163+ for (avifNclxColourPrimaries primaries = 0 ; primaries < kNumPrimaries ; ++primaries) {
164+ for (avifNclxTransferCharacteristics transfer = 0 ; transfer < kNumTransfers ; ++transfer) {
163165 CGColorSpaceRef space = NULL ;
164166
165167 space = CreateColorSpaceRGB (primaries, transfer);
@@ -174,6 +176,82 @@ -(void)testAllColorSpaceSupportsOutput
174176 }
175177}
176178
179+ -(void )testCalcNCLXColorSpaceFromAVIFImage
180+ {
181+ avifImage* img = avifImageCreate (100 , 100 , 8 , AVIF_PIXEL_FORMAT_YUV420);
182+ for (avifNclxColourPrimaries primaries = 0 ; primaries < kNumPrimaries ; ++primaries) {
183+ for (avifNclxTransferCharacteristics transfer = 0 ; transfer < kNumTransfers ; ++transfer) {
184+ avifNclxColorProfile nclx;
185+ nclx.colourPrimaries = primaries;
186+ nclx.transferCharacteristics = transfer;
187+ avifImageSetProfileNCLX (img, &nclx);
188+ avifImageAllocatePlanes (img, AVIF_PLANES_YUV);
189+
190+ CGColorSpaceRef space = NULL ;
191+ BOOL shouldRelease = FALSE ;
192+
193+ CalcColorSpaceRGB (img, &space, &shouldRelease);
194+ XCTAssertTrue (CGColorSpaceSupportsOutput (space));
195+ if (shouldRelease) {
196+ CGColorSpaceRelease (space);
197+ }
198+
199+ // monochrome
200+ free (img->yuvPlanes [AVIF_CHAN_U]);
201+ img->yuvPlanes [AVIF_CHAN_U] = NULL ;
202+ img->yuvRowBytes [AVIF_CHAN_U] = 0 ;
203+ free (img->yuvPlanes [AVIF_CHAN_V]);
204+ img->yuvPlanes [AVIF_CHAN_V] = NULL ;
205+ img->yuvRowBytes [AVIF_CHAN_V] = 0 ;
206+
207+ CalcColorSpaceMono (img, &space, &shouldRelease);
208+ XCTAssertTrue (CGColorSpaceSupportsOutput (space));
209+ if (shouldRelease) {
210+ CGColorSpaceRelease (space);
211+ }
212+
213+ avifImageFreePlanes (img, AVIF_PLANES_ALL);
214+ }
215+ }
216+ avifImageDestroy (img);
217+ }
218+
219+ -(void )testCalcICCColorSpaceFromAVIFImage
220+ {
221+ NSData *iccProfile = (__bridge_transfer NSData *)CGColorSpaceCopyICCProfile ([SDImageCoderHelper colorSpaceGetDeviceRGB ]);
222+ avifImage* img = avifImageCreate (100 , 100 , 8 , AVIF_PIXEL_FORMAT_YUV420);
223+ avifImageSetProfileICC (img, (uint8_t *)iccProfile.bytes , iccProfile.length );
224+
225+ avifImageAllocatePlanes (img, AVIF_PLANES_YUV);
226+
227+ CGColorSpaceRef space = NULL ;
228+ BOOL shouldRelease = FALSE ;
229+
230+ CalcColorSpaceRGB (img, &space, &shouldRelease);
231+ XCTAssertTrue (CGColorSpaceSupportsOutput (space));
232+ if (shouldRelease) {
233+ CGColorSpaceRelease (space);
234+ }
235+
236+ // monochrome
237+ free (img->yuvPlanes [AVIF_CHAN_U]);
238+ img->yuvPlanes [AVIF_CHAN_U] = NULL ;
239+ img->yuvRowBytes [AVIF_CHAN_U] = 0 ;
240+ free (img->yuvPlanes [AVIF_CHAN_V]);
241+ img->yuvPlanes [AVIF_CHAN_V] = NULL ;
242+ img->yuvRowBytes [AVIF_CHAN_V] = 0 ;
243+
244+ CalcColorSpaceMono (img, &space, &shouldRelease);
245+ XCTAssertTrue (CGColorSpaceSupportsOutput (space));
246+ if (shouldRelease) {
247+ CGColorSpaceRelease (space);
248+ }
249+
250+ avifImageFreePlanes (img, AVIF_PLANES_ALL);
251+
252+ avifImageDestroy (img);
253+ }
254+
177255-(void )assertColor8 : (NSString *)filename img : (CGImageRef)img expectedColor : (UInt8*)expectedColor
178256{
179257 CFDataRef rawData = CGDataProviderCopyData (CGImageGetDataProvider (img));
0 commit comments