blob: 1b77e22a580e4429fac33bb54af824356d4fa820 (
plain)
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;
}
|