forked from mojbro/gocoa
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0aa6fa8
commit 0512f30
Showing
5 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#import <Cocoa/Cocoa.h> | ||
|
||
typedef void *ImagePtr; | ||
ImagePtr Image_NewWithRGBA(int w, int h, unsigned char *rgba); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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; | ||
} |