#include <rdr/Exception.h>
+#include "cocoa.h"
#include "Surface.h"
-static CGImageRef create_image(const unsigned char* data,
+static CGColorSpaceRef srgb = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
+
+static CGImageRef create_image(CGColorSpaceRef lut,
+ const unsigned char* data,
int w, int h)
{
- CGColorSpaceRef lut;
CGDataProviderRef provider;
CGImageRef image;
- lut = CGDisplayCopyColorSpace(kCGDirectMainDisplay);
- if (!lut) {
- lut = CGColorSpaceCreateDeviceRGB();
- if (!lut)
- throw rdr::Exception("CGColorSpaceCreateDeviceRGB");
- }
-
provider = CGDataProviderCreateWithData(NULL, data,
w * h * 4, NULL);
if (!provider)
image = CGImageCreate(w, h, 8, 32, w * 4, lut,
kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little,
provider, NULL, false, kCGRenderingIntentDefault);
- CGColorSpaceRelease(lut);
CGDataProviderRelease(provider);
if (!image)
throw rdr::Exception("CGImageCreate");
return image;
}
-static void render(CGContextRef gc,
+static void render(CGContextRef gc, CGColorSpaceRef lut,
const unsigned char* data,
CGBlendMode mode, CGFloat alpha,
int src_x, int src_y, int src_w, int src_h,
CGRect rect;
CGImageRef image, subimage;
- image = create_image(data, src_w, src_h);
+ image = create_image(lut, data, src_w, src_h);
rect.origin.x = src_x;
rect.origin.y = src_y;
static CGContextRef make_bitmap(int width, int height, unsigned char* data)
{
- CGColorSpaceRef lut;
CGContextRef bitmap;
- lut = CGDisplayCopyColorSpace(kCGDirectMainDisplay);
- if (!lut) {
- lut = CGColorSpaceCreateDeviceRGB();
- if (!lut)
- throw rdr::Exception("CGColorSpaceCreateDeviceRGB");
- }
-
- bitmap = CGBitmapContextCreate(data, width, height, 8, width*4, lut,
+ bitmap = CGBitmapContextCreate(data, width, height, 8, width*4, srgb,
kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little);
- CGColorSpaceRelease(lut);
if (!bitmap)
throw rdr::Exception("CGBitmapContextCreate");
void Surface::draw(int src_x, int src_y, int x, int y, int w, int h)
{
+ CGColorSpaceRef lut;
+
CGContextSaveGState(fl_gc);
// Reset the transformation matrix back to the default identity
// macOS Coordinates are from bottom left, not top left
y = Fl_Window::current()->h() - (y + h);
- render(fl_gc, data, kCGBlendModeCopy, 1.0,
+ lut = cocoa_win_color_space(Fl_Window::current());
+ render(fl_gc, lut, data, kCGBlendModeCopy, 1.0,
src_x, src_y, width(), height(), x, y, w, h);
+ CGColorSpaceRelease(lut);
CGContextRestoreGState(fl_gc);
}
// macOS Coordinates are from bottom left, not top left
y = dst->height() - (y + h);
- render(bitmap, data, kCGBlendModeCopy, 1.0,
+ render(bitmap, srgb, data, kCGBlendModeCopy, 1.0,
src_x, src_y, width(), height(), x, y, w, h);
CGContextRelease(bitmap);
void Surface::blend(int src_x, int src_y, int x, int y, int w, int h, int a)
{
+ CGColorSpaceRef lut;
+
CGContextSaveGState(fl_gc);
// Reset the transformation matrix back to the default identity
// macOS Coordinates are from bottom left, not top left
y = Fl_Window::current()->h() - (y + h);
- render(fl_gc, data, kCGBlendModeNormal, (CGFloat)a/255.0,
+ lut = cocoa_win_color_space(Fl_Window::current());
+ render(fl_gc, lut, data, kCGBlendModeNormal, (CGFloat)a/255.0,
src_x, src_y, width(), height(), x, y, w, h);
+ CGColorSpaceRelease(lut);
CGContextRestoreGState(fl_gc);
}
// macOS Coordinates are from bottom left, not top left
y = dst->height() - (y + h);
- render(bitmap, data, kCGBlendModeNormal, (CGFloat)a/255.0,
+ render(bitmap, srgb, data, kCGBlendModeNormal, (CGFloat)a/255.0,
src_x, src_y, width(), height(), x, y, w, h);
CGContextRelease(bitmap);