Added test case `test28ThatNotTriggerCACopyImage` and `test28ThatDoTriggerCACopyImage`

This commit is contained in:
DreamPiggy 2023-07-11 17:45:40 +08:00
parent f6ca661537
commit 69c98c5f71
1 changed files with 56 additions and 0 deletions

View File

@ -448,6 +448,62 @@
expect(data2).notTo.beNil();
}
- (void)test28ThatNotTriggerCACopyImage {
// 10 * 8 pixels, RGBA8888
size_t width = 10;
size_t height = 8;
size_t bitsPerComponent = 8;
size_t components = 4;
size_t bitsPerPixel = bitsPerComponent * components;
size_t bytesPerRow = SDByteAlign(bitsPerPixel / 8 * width, SDImageCoderHelper.preferredByteAlignment);
size_t size = bytesPerRow * height;
uint8_t bitmap[size];
for (size_t i = 0; i < size; i++) {
bitmap[i] = 255;
}
CGColorSpaceRef colorspace = [SDImageCoderHelper colorSpaceGetDeviceRGB];
CGBitmapInfo bitmapInfo = [SDImageCoderHelper preferredBitmapInfo:YES];
CFDataRef data = CFDataCreateWithBytesNoCopy(NULL, bitmap, size, NULL);
CGDataProviderRef provider = CGDataProviderCreateWithCFData(data);
BOOL shouldInterpolate = YES;
CGColorRenderingIntent intent = kCGRenderingIntentDefault;
CGImageRef cgImage = CGImageCreate(width, height, bitsPerComponent, bitsPerPixel, bytesPerRow, colorspace, bitmapInfo, provider, NULL, shouldInterpolate, intent);
XCTAssert(cgImage);
BOOL result = [SDImageCoderHelper CGImageIsHardwareSupported:cgImage];
// Since it's 32 bytes aligned, return false
XCTAssertTrue(result);
}
- (void)test28ThatDoTriggerCACopyImage {
// 10 * 8 pixels, RGBA8888
size_t width = 10;
size_t height = 8;
size_t bitsPerComponent = 8;
size_t components = 4;
size_t bitsPerPixel = bitsPerComponent * components;
size_t bytesPerRow = bitsPerPixel / 8 * width;
size_t size = bytesPerRow * height;
uint8_t bitmap[size];
for (size_t i = 0; i < size; i++) {
bitmap[i] = 255;
}
CGColorSpaceRef colorspace = [SDImageCoderHelper colorSpaceGetDeviceRGB];
CGBitmapInfo bitmapInfo = [SDImageCoderHelper preferredBitmapInfo:YES];
CFDataRef data = CFDataCreateWithBytesNoCopy(NULL, bitmap, size, NULL);
CGDataProviderRef provider = CGDataProviderCreateWithCFData(data);
BOOL shouldInterpolate = YES;
CGColorRenderingIntent intent = kCGRenderingIntentDefault;
CGImageRef cgImage = CGImageCreate(width, height, bitsPerComponent, bitsPerPixel, bytesPerRow, colorspace, bitmapInfo, provider, NULL, shouldInterpolate, intent);
XCTAssert(cgImage);
BOOL result = [SDImageCoderHelper CGImageIsHardwareSupported:cgImage];
// Since it's not 32 bytes aligned, return false
XCTAssertFalse(result);
// Let's force-decode to check again
CGImageRef newCGImage = [SDImageCoderHelper CGImageCreateDecoded:cgImage];
BOOL newResult = [SDImageCoderHelper CGImageIsHardwareSupported:newCGImage];
XCTAssertTrue(newResult);
}
#pragma mark - Utils
- (void)verifyCoder:(id<SDImageCoder>)coder