@@ -218,11 +218,17 @@ -(void)assertMono8: (NSString*)filename img:(CGImageRef)img expectedNumComponent
218
218
size_t const stride = CGImageGetBytesPerRow (img);
219
219
size_t const bitsPerPixel = CGImageGetBitsPerPixel (img);
220
220
size_t const bytesPerPixel = bitsPerPixel/8 ;
221
+ UInt8 const pix0 = *buf;
221
222
XCTAssertEqual (1 , bytesPerPixel);
223
+ int const threshold = 16 ;
222
224
for (size_t y = 0 ; y < height; ++y) {
223
225
for (size_t x = 0 ; x < width; ++x) {
224
226
UInt8* pix = (buf + (stride * y) + (bytesPerPixel * x));
225
- XCTAssertEqual (buf[0 ], *pix);
227
+ bool ok = false ;
228
+ XCTAssertTrue (ok = (abs (pix0 - *pix) <= threshold), " (x: %ld , y: %ld ): result=%d vs expected=%d (%@)" , x, y, *pix, pix0, filename);
229
+ if (!ok) {
230
+ return ;
231
+ }
226
232
}
227
233
}
228
234
end:
@@ -232,6 +238,7 @@ -(void)assertMono8: (NSString*)filename img:(CGImageRef)img expectedNumComponent
232
238
233
239
-(void )assertMono16 : (NSString *)filename img : (CGImageRef)img expectedNumComponents : (size_t )expectedNumComponents
234
240
{
241
+ int const threshold = 16 << 8 ;
235
242
CFDataRef rawData = CGDataProviderCopyData (CGImageGetDataProvider (img));
236
243
UInt8* const buf = (UInt8 *) CFDataGetBytePtr (rawData);
237
244
size_t const width = CGImageGetWidth (img);
@@ -240,10 +247,15 @@ -(void)assertMono16: (NSString*)filename img:(CGImageRef)img expectedNumComponen
240
247
size_t const bitsPerPixel = CGImageGetBitsPerPixel (img);
241
248
size_t const bytesPerPixel = bitsPerPixel/8 ;
242
249
XCTAssertEqual (2 , bytesPerPixel);
250
+ UInt16 const pix0 = *((UInt16*)buf);
243
251
for (size_t y = 0 ; y < height; ++y) {
244
252
for (size_t x = 0 ; x < width; ++x) {
245
253
UInt16* pix = (UInt16*)(buf + (stride * y) + (bytesPerPixel * x));
246
- XCTAssertEqual (((UInt16*)buf)[0 ], *pix);
254
+ bool ok = false ;
255
+ XCTAssertTrue (ok = (abs (pix0 - *pix) <= threshold), " (x: %ld , y: %ld ): result=%d vs expected=%d (%@)" , x, y, *pix, pix0, filename);
256
+ if (!ok) {
257
+ return ;
258
+ }
247
259
}
248
260
}
249
261
end:
0 commit comments