forked from mojbro/gocoa
-
Notifications
You must be signed in to change notification settings - Fork 1
/
image.m
24 lines (20 loc) · 739 Bytes
/
image.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
#import "image.h"
#include "_cgo_export.h"
ImagePtr Image_NewWithRGBA(int w, int h, unsigned char *rgba) {
NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:NULL
pixelsWide:w
pixelsHigh:h
bitsPerSample:8
samplesPerPixel:4
hasAlpha:YES
isPlanar:NO
colorSpaceName:NSCalibratedRGBColorSpace
bytesPerRow:w * 4
bitsPerPixel:32];
unsigned char *bitmapData = [bitmap bitmapData];
memcpy(bitmapData, rgba, w * h * 4);
NSImage *theImage = [[NSImage alloc] init];
[theImage addRepresentation:bitmap];
return (ImagePtr)theImage;
}