@@ -218,11 +218,17 @@ -(void)assertMono8: (NSString*)filename img:(CGImageRef)img expectedNumComponent
218218 size_t const stride = CGImageGetBytesPerRow (img);
219219 size_t const bitsPerPixel = CGImageGetBitsPerPixel (img);
220220 size_t const bytesPerPixel = bitsPerPixel/8 ;
221+ UInt8 const pix0 = *buf;
221222 XCTAssertEqual (1 , bytesPerPixel);
223+ int const threshold = 16 ;
222224 for (size_t y = 0 ; y < height; ++y) {
223225 for (size_t x = 0 ; x < width; ++x) {
224226 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+ }
226232 }
227233 }
228234end:
@@ -232,6 +238,7 @@ -(void)assertMono8: (NSString*)filename img:(CGImageRef)img expectedNumComponent
232238
233239-(void )assertMono16 : (NSString *)filename img : (CGImageRef)img expectedNumComponents : (size_t )expectedNumComponents
234240{
241+ int const threshold = 16 << 8 ;
235242 CFDataRef rawData = CGDataProviderCopyData (CGImageGetDataProvider (img));
236243 UInt8* const buf = (UInt8 *) CFDataGetBytePtr (rawData);
237244 size_t const width = CGImageGetWidth (img);
@@ -240,10 +247,15 @@ -(void)assertMono16: (NSString*)filename img:(CGImageRef)img expectedNumComponen
240247 size_t const bitsPerPixel = CGImageGetBitsPerPixel (img);
241248 size_t const bytesPerPixel = bitsPerPixel/8 ;
242249 XCTAssertEqual (2 , bytesPerPixel);
250+ UInt16 const pix0 = *((UInt16*)buf);
243251 for (size_t y = 0 ; y < height; ++y) {
244252 for (size_t x = 0 ; x < width; ++x) {
245253 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+ }
247259 }
248260 }
249261end:
0 commit comments