diff options
| author | Pietro Gagliardi <[email protected]> | 2014-08-30 23:02:02 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-08-30 23:02:02 -0400 |
| commit | 77bf566ebbcb62acd4d08d905d9542d6ff9b6b80 (patch) | |
| tree | eeb8e72bc3bf57f5be7f0c0af4319189ac6de838 /imagelist_darwin.m | |
| parent | 155899c65ed32245e2ccad4197a10c77017d835b (diff) | |
...in with the new.
Diffstat (limited to 'imagelist_darwin.m')
| -rw-r--r-- | imagelist_darwin.m | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/imagelist_darwin.m b/imagelist_darwin.m new file mode 100644 index 0000000..7433b12 --- /dev/null +++ b/imagelist_darwin.m @@ -0,0 +1,30 @@ +// 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; + + // we can't just hand it pixels; we need to make a copy + bitmap = [[NSBitmapImageRep alloc] + initWithBitmapDataPlanes:NULL + pixelsWide:toNSInteger(width) + pixelsHigh:toNSInteger(height) + bitsPerSample:8 + samplesPerPixel:4 + hasAlpha:YES + isPlanar:NO + colorSpaceName:NSDeviceRGBColorSpace + bitmapFormat:0 + bytesPerRow:toNSInteger(stride) + bitsPerPixel:32]; + memcpy((void *) [bitmap bitmapData], pixels, [bitmap bytesPerPlane]); + image = [[NSImage alloc] initWithSize:NSMakeSize((CGFloat) width, (CGFloat) height)]; + [image addRepresentation:bitmap]; + return (id) image; +} |
