hb_get_preview -> CGImage / NSImage how?

Archive of historical development discussions
Discussions / Development has moved to GitHub
Forum rules
*******************************
Please be aware we are now using GitHub for issue tracking and feature requests.
- This section of the forum is now closed to new topics.

*******************************
Post Reply
nikwest
Posts: 14
Joined: Fri Feb 23, 2007 8:27 pm

hb_get_preview -> CGImage / NSImage how?

Post by nikwest »

Hi all,

I am struggling to create a CGImage (or an NSImage) out of the hb_get_preview data.

Could anybody enlighten me what kind of format the returned buffer have? I am really stuck :-(

Regards

NikWest
prigaux
Experienced
Posts: 94
Joined: Mon Jan 01, 2007 3:25 pm

Post by prigaux »

Yep, it's a 32bits RGB so the value are only the RGB colors not coded at all.

You can have look at the code of hb.c in libhb folder to see it generation.

Philippe
nikwest
Posts: 14
Joined: Fri Feb 23, 2007 8:27 pm

Solved

Post by nikwest »

Ok, thanks.

I solved it. In case somebody is wondering how, here is the code snippet:

Code: Select all

	CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
	CGContextRef cntxt = CGBitmapContextCreate(
											   [imageBuffer mutableBytes],
											   title->width+2,
											   title->height+2,
											   8,
											   (title->width+2)*4,
											   cs,
											   kCGImageAlphaNoneSkipFirst|kCGBitmapByteOrder32Little
											   );

	hb_get_preview( handle, title, fPicture,  [imageBuffer mutableBytes]);
	
	CGImageRef image = CGBitmapContextCreateImage(cntxt);
	CGContextRelease(cntxt);
	CGColorSpaceRelease(cs);
Problem was mostly because the buffer has a BGRA layout.

NikWest
Post Reply