Follow Apple doc and remove that manual calculation of byte alignment to make it more universal for different architecture device

This commit is contained in:
DreamPiggy 2017-11-30 11:24:32 +08:00
parent dbc6b6995d
commit 935eb1dc14
2 changed files with 5 additions and 18 deletions

View File

@ -160,7 +160,7 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
if (partialImageRef) {
const size_t partialHeight = CGImageGetHeight(partialImageRef);
CGColorSpaceRef colorSpace = SDCGColorSpaceGetDeviceRGB();
CGContextRef bmContext = CGBitmapContextCreate(NULL, _width, _height, 8, SDCGByteAlign(_width * 4, 64), colorSpace, kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedFirst);
CGContextRef bmContext = CGBitmapContextCreate(NULL, _width, _height, 8, 0, colorSpace, kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedFirst);
if (bmContext) {
CGContextDrawImage(bmContext, (CGRect){.origin.x = 0.0f, .origin.y = 0.0f, .size.width = _width, .size.height = partialHeight}, partialImageRef);
CGImageRelease(partialImageRef);
@ -243,7 +243,6 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
size_t width = CGImageGetWidth(imageRef);
size_t height = CGImageGetHeight(imageRef);
size_t bytesPerRow = kBytesPerPixel * width;
// kCGImageAlphaNone is not supported in CGBitmapContextCreate.
// Since the original image here has no alpha info, use kCGImageAlphaNoneSkipLast
@ -252,7 +251,7 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
width,
height,
kBitsPerComponent,
SDCGByteAlign(bytesPerRow, 64),
0,
colorspaceRef,
kCGBitmapByteOrderDefault|kCGImageAlphaNoneSkipLast);
if (context == NULL) {
@ -304,8 +303,6 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
// current color space
CGColorSpaceRef colorspaceRef = [[self class] colorSpaceForImageRef:sourceImageRef];
size_t bytesPerRow = kBytesPerPixel * destResolution.width;
// kCGImageAlphaNone is not supported in CGBitmapContextCreate.
// Since the original image here has no alpha info, use kCGImageAlphaNoneSkipLast
// to create bitmap graphics contexts without alpha info.
@ -313,7 +310,7 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
destResolution.width,
destResolution.height,
kBitsPerComponent,
SDCGByteAlign(bytesPerRow, 64),
0,
colorspaceRef,
kCGBitmapByteOrderDefault|kCGImageAlphaNoneSkipLast);
@ -554,9 +551,4 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
}
#endif
// 64 bytes align to avoid extra `CA::Render::aligned_malloc` call
static inline size_t SDCGByteAlign(size_t size, size_t alignment) {
return ((size + (alignment - 1)) / alignment) * alignment;
}
@end

View File

@ -77,7 +77,7 @@
} else {
bitmapInfo = kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast;
}
CGContextRef canvas = CGBitmapContextCreate(NULL, canvasWidth, canvasHeight, 8, SDCGByteAlign(canvasWidth * 4, 64), SDCGColorSpaceGetDeviceRGB(), bitmapInfo);
CGContextRef canvas = CGBitmapContextCreate(NULL, canvasWidth, canvasHeight, 8, 0, SDCGColorSpaceGetDeviceRGB(), bitmapInfo);
if (!canvas) {
WebPDemuxDelete(demuxer);
return nil;
@ -190,7 +190,7 @@
return nil;
}
CGContextRef canvas = CGBitmapContextCreate(NULL, width, height, 8, SDCGByteAlign(width * 4, 64), SDCGColorSpaceGetDeviceRGB(), bitmapInfo);
CGContextRef canvas = CGBitmapContextCreate(NULL, width, height, 8, 0, SDCGColorSpaceGetDeviceRGB(), bitmapInfo);
if (!canvas) {
CGImageRelease(imageRef);
return nil;
@ -417,11 +417,6 @@ static void FreeImageData(void *info, const void *data, size_t size) {
free((void *)data);
}
// 64 bytes align to avoid extra `CA::Render::aligned_malloc` call
static inline size_t SDCGByteAlign(size_t size, size_t alignment) {
return ((size + (alignment - 1)) / alignment) * alignment;
}
@end
#endif