forked from andlabs/ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage_darwin.m
31 lines (27 loc) · 844 Bytes
/
image_darwin.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// 16 august 2014
#import "objc_darwin.h"
#import <Cocoa/Cocoa.h>
#define toNSInteger(x) ((NSInteger) (x))
id toTableImage(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];
// TODO release bitmap?
return (id) image;
}