Merge pull request #2101 from dreampiggy/performance_byte_align

Byte Alignment to 64 bytes to reduce memory usage
This commit is contained in:
Bogdan Poplauschi 2017-11-11 08:43:21 +02:00 committed by GitHub
commit 5872bd660b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 5 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, _width * 4, colorSpace, kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedFirst);
CGContextRef bmContext = CGBitmapContextCreate(NULL, _width, _height, 8, SDCGByteAlign(_width * 4, 64), 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);
@ -252,7 +252,7 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
width,
height,
kBitsPerComponent,
bytesPerRow,
SDCGByteAlign(bytesPerRow, 64),
colorspaceRef,
kCGBitmapByteOrderDefault|kCGImageAlphaNoneSkipLast);
if (context == NULL) {
@ -313,7 +313,7 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
destResolution.width,
destResolution.height,
kBitsPerComponent,
bytesPerRow,
SDCGByteAlign(bytesPerRow, 64),
colorspaceRef,
kCGBitmapByteOrderDefault|kCGImageAlphaNoneSkipLast);
@ -554,4 +554,9 @@ 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, 0, SDCGColorSpaceGetDeviceRGB(), bitmapInfo);
CGContextRef canvas = CGBitmapContextCreate(NULL, canvasWidth, canvasHeight, 8, SDCGByteAlign(canvasWidth * 4, 64), SDCGColorSpaceGetDeviceRGB(), bitmapInfo);
if (!canvas) {
WebPDemuxDelete(demuxer);
return nil;
@ -190,7 +190,7 @@
return nil;
}
CGContextRef canvas = CGBitmapContextCreate(NULL, width, height, 8, 0, SDCGColorSpaceGetDeviceRGB(), bitmapInfo);
CGContextRef canvas = CGBitmapContextCreate(NULL, width, height, 8, SDCGByteAlign(width * 4, 64), SDCGColorSpaceGetDeviceRGB(), bitmapInfo);
if (!canvas) {
CGImageRelease(imageRef);
return nil;
@ -417,6 +417,11 @@ 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