@@ -29,6 +29,7 @@ @interface Tests : XCTestCase
29
29
30
30
{
31
31
@private
32
+ SDImageAVIFCoder* coder;
32
33
NSMutableArray <NSDictionary *>* blackList;
33
34
NSMutableArray <NSDictionary *>* whiteList;
34
35
NSMutableArray <NSDictionary *>* grayList;
@@ -44,7 +45,7 @@ @implementation Tests
44
45
- (void )setUp
45
46
{
46
47
[super setUp ];
47
-
48
+ self-> coder = [[SDImageAVIFCoder alloc ] init ];
48
49
self->blackList = [[NSMutableArray alloc ] init ];
49
50
self->whiteList = [[NSMutableArray alloc ] init ];
50
51
self->grayList = [[NSMutableArray alloc ] init ];
@@ -217,26 +218,11 @@ -(void)assertMono8: (NSString*)filename img:(CGImageRef)img expectedNumComponent
217
218
size_t const stride = CGImageGetBytesPerRow (img);
218
219
size_t const bitsPerPixel = CGImageGetBitsPerPixel (img);
219
220
size_t const bytesPerPixel = bitsPerPixel/8 ;
221
+ XCTAssertEqual (1 , bytesPerPixel);
220
222
for (size_t y = 0 ; y < height; ++y) {
221
223
for (size_t x = 0 ; x < width; ++x) {
222
- UInt16* pix = (UInt16*)(buf + (stride * y) + (bytesPerPixel * x));
223
- UInt16 color = 0 ;
224
- for (size_t c = 0 ; c < expectedNumComponents; ++c) {
225
- bool ok = false ;
226
- if (c == 0 ) {
227
- color = pix[c];
228
- }else if (pix[c] != color) {
229
- NSMutableString * colorStr = [[NSMutableString alloc ] initWithString: @" [" ];
230
- for (size_t d = 0 ; d < expectedNumComponents; ++d) {
231
- [colorStr appendFormat: @" %d , " , pix[d]];
232
- }
233
- [colorStr appendString: @" ]" ];
234
- XCTAssertTrue (ok = (pix[c] == color), " (x: %ld , y: %ld , c:%ld ): color=%@ (%@)" , x, y, c, colorStr, filename);
235
- }
236
- if (!ok) {
237
- goto end;
238
- }
239
- }
224
+ UInt8* pix = (buf + (stride * y) + (bytesPerPixel * x));
225
+ XCTAssertEqual (buf[0 ], *pix);
240
226
}
241
227
}
242
228
end:
@@ -253,26 +239,11 @@ -(void)assertMono16: (NSString*)filename img:(CGImageRef)img expectedNumComponen
253
239
size_t const stride = CGImageGetBytesPerRow (img);
254
240
size_t const bitsPerPixel = CGImageGetBitsPerPixel (img);
255
241
size_t const bytesPerPixel = bitsPerPixel/8 ;
242
+ XCTAssertEqual (2 , bytesPerPixel);
256
243
for (size_t y = 0 ; y < height; ++y) {
257
244
for (size_t x = 0 ; x < width; ++x) {
258
245
UInt16* pix = (UInt16*)(buf + (stride * y) + (bytesPerPixel * x));
259
- UInt16 color = 0 ;
260
- for (size_t c = 0 ; c < expectedNumComponents; ++c) {
261
- bool ok = false ;
262
- if (c == 0 ) {
263
- color = pix[c];
264
- }else if (pix[c] != color) {
265
- NSMutableString * colorStr = [[NSMutableString alloc ] initWithString: @" [" ];
266
- for (size_t d = 0 ; d < expectedNumComponents; ++d) {
267
- [colorStr appendFormat: @" %d , " , pix[d]];
268
- }
269
- [colorStr appendString: @" ]" ];
270
- XCTAssertTrue (ok = (pix[c] == color), " (x: %ld , y: %ld , c:%ld ): color=%@ (%@)" , x, y, c, colorStr, filename);
271
- }
272
- if (!ok) {
273
- goto end;
274
- }
275
- }
246
+ XCTAssertEqual (((UInt16*)buf)[0 ], *pix);
276
247
}
277
248
}
278
249
end:
@@ -282,7 +253,6 @@ -(void)assertMono16: (NSString*)filename img:(CGImageRef)img expectedNumComponen
282
253
- (void )assertImages : (NSMutableArray *) list colorName : (NSString *)colorName expectedColor8 : (UInt8*)expectedColor8 expectedNumComponents8 : (size_t )expectedNumComponents8
283
254
expectedColor16 : (UInt16*)expectedColor16 expectedNumComponents16 : (size_t )expectedNumComponents16
284
255
{
285
- SDImageAVIFCoder* const coder = [SDImageAVIFCoder sharedCoder ];
286
256
NSLog (@" Testing %lu [%@ ] images" , list.count , colorName);
287
257
[list enumerateObjectsUsingBlock: ^(NSDictionary * item, NSUInteger idx, BOOL *stop) {
288
258
NSString * convertedFilename = [item objectForKey: @" converted" ];
@@ -300,7 +270,13 @@ - (void)assertImages: (NSMutableArray*) list colorName:(NSString*)colorName expe
300
270
NSString * imgBundle = [[NSBundle mainBundle ] pathForResource: convertedFilename ofType: @" " ];
301
271
NSData * imgData = [[NSData alloc ] initWithContentsOfFile: imgBundle];
302
272
303
- UIImage* img = [coder decodedImageWithData: imgData options: nil ];
273
+ UIImage* img = [self ->coder decodedImageWithData: imgData options: nil ];
274
+ [self ->coder decodedImageWithData: imgData options: nil ];
275
+ [self ->coder decodedImageWithData: imgData options: nil ];
276
+ [self ->coder decodedImageWithData: imgData options: nil ];
277
+ [self ->coder decodedImageWithData: imgData options: nil ];
278
+ [self ->coder decodedImageWithData: imgData options: nil ];
279
+
304
280
bool hdr = CGImageGetBitsPerComponent (img.CGImage ) != 8 ;
305
281
// FIXME(ledyba-z): add images with alpha.
306
282
if ([color isEqual: @" mono" ]){
@@ -314,7 +290,6 @@ - (void)assertImages: (NSMutableArray*) list colorName:(NSString*)colorName expe
314
290
} else {
315
291
[self assertColor16: convertedFilename img: img.CGImage expectedColor: expectedColor16 expectedNumComponents: expectedNumComponents16];
316
292
}
317
-
318
293
}];
319
294
}
320
295
0 commit comments