summaryrefslogtreecommitdiff
path: root/redo/imagelist_darwin.m
blob: 00ad75a91e121d28889bbc1e30975c1d64ef5c0f (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
32
// 16 august 2014

#import "objc_darwin.h"
#import <Cocoa/Cocoa.h>

#define toNSInteger(x) ((NSInteger) (x))

// TODO top two pixels of 16x16 images are green?

id toImageListImage(void *pixels, intptr_t width, intptr_t height, intptr_t stride)
{
	unsigned char *planes[1];			// NSBitmapImageRep wants an array of planes; we have one plane
	NSBitmapImageRep *bitmap;
	NSImage *image;

	planes[0] = (unsigned char *) pixels;
	bitmap = [[NSBitmapImageRep alloc]
		initWithBitmapDataPlanes:planes
		pixelsWide:toNSInteger(width)
		pixelsHigh:toNSInteger(height)
		bitsPerSample:8
		samplesPerPixel:4
		hasAlpha:YES
		isPlanar:NO
		colorSpaceName:NSDeviceRGBColorSpace
		bitmapFormat:0
		bytesPerRow:toNSInteger(stride)
		bitsPerPixel:32];
	image = [[NSImage alloc] initWithSize:NSMakeSize((CGFloat) width, (CGFloat) height)];
	[image addRepresentation:bitmap];
	return (id) image;
}