2014-08-16 20:49:43 -05:00
|
|
|
// 16 august 2014
|
|
|
|
|
|
|
|
#import "objc_darwin.h"
|
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
|
|
|
|
#define toNSInteger(x) ((NSInteger) (x))
|
|
|
|
|
|
|
|
id toImageListImage(void *pixels, intptr_t width, intptr_t height, intptr_t stride)
|
|
|
|
{
|
|
|
|
NSBitmapImageRep *bitmap;
|
|
|
|
NSImage *image;
|
|
|
|
|
2014-08-16 21:50:25 -05:00
|
|
|
// we can't just hand it pixels; we need to make a copy
|
2014-08-16 20:49:43 -05:00
|
|
|
bitmap = [[NSBitmapImageRep alloc]
|
2014-08-16 21:50:25 -05:00
|
|
|
initWithBitmapDataPlanes:NULL
|
2014-08-16 20:49:43 -05:00
|
|
|
pixelsWide:toNSInteger(width)
|
|
|
|
pixelsHigh:toNSInteger(height)
|
|
|
|
bitsPerSample:8
|
|
|
|
samplesPerPixel:4
|
|
|
|
hasAlpha:YES
|
|
|
|
isPlanar:NO
|
|
|
|
colorSpaceName:NSDeviceRGBColorSpace
|
|
|
|
bitmapFormat:0
|
|
|
|
bytesPerRow:toNSInteger(stride)
|
|
|
|
bitsPerPixel:32];
|
2014-08-16 21:50:25 -05:00
|
|
|
memcpy((void *) [bitmap bitmapData], pixels, [bitmap bytesPerPlane]);
|
2014-08-16 20:49:43 -05:00
|
|
|
image = [[NSImage alloc] initWithSize:NSMakeSize((CGFloat) width, (CGFloat) height)];
|
|
|
|
[image addRepresentation:bitmap];
|
|
|
|
return (id) image;
|
|
|
|
}
|