问题
In my application I am rendering graphics into a block of main memory using the CPU (please don't challenge this requirement). When it is time to draw this on the screen, the following code is used in order to blit a rectangular portion of this memory to the screen via "attaching" a NSBitmapImageRep
to it:
void* offsetBuffer = reinterpret_cast<void*>(_buffer + sourceY * bpr + sourceX * 4);
unsigned char** planes = (unsigned char**)&offsetBuffer;
NSRect destRect;
destRect.origin.x = destX;
destRect.origin.y = destY;
destRect.size.width = destWidth;
destRect.size.height = destHeight;
NSBitmapImageRep* imageRep = [NSBitmapImageRep alloc];
[imageRep initWithBitmapDataPlanes:planes
pixelsWide:sourceWidth
pixelsHigh:sourceHeight
bitsPerSample:8
samplesPerPixel:3
hasAlpha:NO
isPlanar:NO
colorSpaceName:NSDeviceRGBColorSpace
bitmapFormat:NSAlphaFirstBitmapFormat
bytesPerRow:bpr
bitsPerPixel:32];
NSGraphicsContext* graphicsState = reinterpret_cast<NSGraphicsContext*>(graphicsContextHandle);
[graphicsState saveGraphicsState];
NSAffineTransform* transform = [NSAffineTransform transform];
if (transform != NULL) {
[transform scaleXBy:1 yBy:-1];
[transform translateXBy:0 yBy:-(destHeight + 2 * destY)];
[transform concat];
[imageRep drawInRect:destRect];
}
[imageRep release];
[graphicsState restoreGraphicsState];
This get's pretty slow the larger the image. I've profiled it using the "Instruments" tool accessible from Xcode and it turns out that the majority of the time is spend in a function called convert_icc
. Like roughly 82%!
The point is that this image needs no color profile conversion. There is also no requirement for a particular color space -- I can render in any color space and with any correction curves that may be needed, in order to avoid the conversion at draw-time.
How can I find out what format I need to use so that it can be drawn directly? My Google searches have been unsuccessful, which I find very strange. I would have expected something in the Apple developer documentation like "for the best image drawing performance, use the bitmap format X".
Thanks for any help!
来源:https://stackoverflow.com/questions/65036326/how-to-avoid-image-color-profile-conversion-in-coregraphics