summaryrefslogtreecommitdiff
path: root/image_darwin.m
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2015-02-18 23:04:14 -0500
committerPietro Gagliardi <[email protected]>2015-02-18 23:04:14 -0500
commit1d091637d8a958b648fe77dd1ce5a9760737dfc1 (patch)
tree10126d366e05ed7328b60fe9149d6ac79a2b5904 /image_darwin.m
parent8ec518dfe8813feebf8a408113499ec54254927a (diff)
Migrated the Mac OS X Table implementation. Untested due to VM issues.
Diffstat (limited to 'image_darwin.m')
-rw-r--r--image_darwin.m31
1 files changed, 31 insertions, 0 deletions
diff --git a/image_darwin.m b/image_darwin.m
new file mode 100644
index 0000000..1b77e22
--- /dev/null
+++ b/image_darwin.m
@@ -0,0 +1,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;
+}