diff --git a/darwin/CMakeLists.txt b/darwin/CMakeLists.txt index c8d1f3be..2bc34ec9 100644 --- a/darwin/CMakeLists.txt +++ b/darwin/CMakeLists.txt @@ -21,6 +21,7 @@ list(APPEND _LIBUI_SOURCES darwin/form.m darwin/grid.m darwin/group.m + darwin/image.m darwin/label.m darwin/main.m darwin/map.m diff --git a/darwin/image.m b/darwin/image.m new file mode 100644 index 00000000..7ec98bad --- /dev/null +++ b/darwin/image.m @@ -0,0 +1,48 @@ +// 25 june 2016 +#import "uipriv_darwin.h" + +struct uiImage { + NSImage *i; + NSSize size; +}; + +uiImage *uiNewImage(double width, double height) +{ + uiImage *i; + + i = uiNew(uiImage); + i->size = NSMakeSize(width, height); + i->i = [[NSImage alloc] initWithSize:i->size]; + return i; +} + +void uiFreeImage(uiImage *i) +{ + [i->i release]; + uiFree(i); +} + +void uiImageAppend(uiImage *i, void *pixels, int pixelWidth, int pixelHeight, int pixelStride) +{ + NSBitmapImageRep *repCalibrated, *repsRGB; + char *pix[1]; + + pix[0] = (char *) pixels; + repCalibrated = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:pix + pixelsWide:pixelWidth + pixelsHigh:pixelHeight + bitsPerSample:8 + samplesPerPixel:4 + hasAlpha:YES + isPlanar:NO + colorSpaceName:NSCalibratedRGBColorSpace + bitmapFormat:0 + bytesPerRow:pixelStride + bitsPerPixel:32]; + repsRGB = [repCalibrated bitmapImageRepByRetaggingWithColorSpace:[NSColorSpace sRGBColorSpace]]; + [repCalibrated release]; + + [i->i addRepresentation:repsRGB]; + [repsRGB setSize:i->size]; + [repsRGB release]; +} diff --git a/uitable.h b/uitable.h index 5860bf57..4c6f5c3a 100644 --- a/uitable.h +++ b/uitable.h @@ -1,6 +1,12 @@ // 20 june 2016 // kept in a separate file for now +typedef struct uiImage uiImage; + +_UI_EXTERN uiImage *uiNewImage(double width, double height); +_UI_EXTERN void uiFreeImage(uiImage *i); +_UI_EXTERN void uiImageAppend(uiImage *i, void *pixels, int pixelWidth, int pixelHeight, int pixelStride); + typedef struct uiTableModel uiTableModel; typedef struct uiTableModelHandler uiTableModelHandler;