To use Quick Look in the debugger, you need to create an image from this buffer, defining the width, height, bits per component, bytes per row, the CGBitmapInfo
(i.e. the order of the components in the buffer) in order to see it. Then you can use the standard debugger quick view features.
- (UIImage *)imageWithBuffer:(UInt32 *)buffer width:(size_t)width height:(size_t)height {
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(buffer, width, height, 8, width * 4, colorSpace, kCGImageAlphaPremultipliedLast);
CGImageRef imageRef = CGBitmapContextCreateImage(context);
UIImage *image = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
return image;
}

FYI, the above assumes that you populated your 32-bit values like so:
UInt32 value = red | green << 8 | blue << 16 | alpha << 24;
If your byte order is the other way around ...
UInt32 value = red << 24 | green << 16 | blue << 8 | alpha
... then you'd add kCGBitmapByteOrder32Little
for the bitmap info parameter of CGBitmapContextCreate
:
CGContextRef context = CGBitmapContextCreate(buffer, width, height, 8, width * 4, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Little);
As you can see, as the interpretation of the bitmap buffer can vary depending upon these parameters, so this is why the debugger needs to know more information than just the buffer in order for the debugger's Quick Look feature to be able to render the image for you.
Note, there was some concern that this was Objective-C code. It works from a C function in a .m
file, just changing the function signature as shown below:
UIImage *imageWithBuffer(UInt32 *buffer, size_t width, size_t height) {
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(buffer, width, height, 8, width * 4, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGImageRef imageRef = CGBitmapContextCreateImage(context);
UIImage *image = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
return image;
}
Yielding:

This, unfortunately, is still using UIImage
. According to the documentation, the CGImageRef
should work with Quick Look (obviating the need for the UIImage
), but in my experience, this has issues (ranging from crashing Xcode to simply showing you the annoying "Could not load Quick Look data for ..." message).