Set depth of image returned by Fl_Image_Surface::image() back to 3 on Mac OS X.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11119 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Manolo Gouy 2016-02-02 08:38:55 +00:00
parent 816e0c1ab4
commit 5866281d4f
2 changed files with 5 additions and 13 deletions

View File

@ -86,12 +86,6 @@ Fl_RGB_Image* prepare_shape(int w)
Fl_RGB_Image* img = surf->image(); Fl_RGB_Image* img = surf->image();
delete surf; delete surf;
current->set_current(); current->set_current();
if (img->d() == 4) { // if RGBA image, set its A component equal to its R component
for (int i = 0; i < img->h(); i ++) {
uchar *q = (uchar*)img->array + i * img->ld();
for (int j = 0; j < img->w(); j++, q += 4) *(q+3) = *q;
}
}
return img; // return white image on black background return img; // return white image on black background
} }

View File

@ -41,12 +41,14 @@ Fl_Image_Surface::Fl_Image_Surface(int w, int h) : Fl_Surface_Device(NULL) {
width = w; width = w;
height = h; height = h;
#ifdef __APPLE__ #ifdef __APPLE__
offscreen = Fl_Quartz_Graphics_Driver::create_offscreen_with_alpha(w, h); offscreen = fl_create_offscreen(w, h);
helper = new Fl_Quartz_Flipped_Surface_(width, height); helper = new Fl_Quartz_Flipped_Surface_(width, height);
driver(helper->driver()); driver(helper->driver());
CGContextSaveGState(offscreen); CGContextSaveGState(offscreen);
CGContextTranslateCTM(offscreen, 0, height); CGContextTranslateCTM(offscreen, 0, height);
CGContextScaleCTM(offscreen, 1.0f, -1.0f); CGContextScaleCTM(offscreen, 1.0f, -1.0f);
CGContextSetRGBFillColor(offscreen, 1, 1, 1, 1);
CGContextFillRect(offscreen, CGRectMake(0,0,w,h));
#elif defined(WIN32) #elif defined(WIN32)
offscreen = fl_create_offscreen(w, h); offscreen = fl_create_offscreen(w, h);
helper = new Fl_GDI_Surface_(); helper = new Fl_GDI_Surface_();
@ -93,13 +95,9 @@ Fl_Image_Surface::~Fl_Image_Surface() {
Fl_RGB_Image* Fl_Image_Surface::image() Fl_RGB_Image* Fl_Image_Surface::image()
{ {
unsigned char *data; unsigned char *data;
int depth = 3, ld = 0;
#ifdef __APPLE__ #ifdef __APPLE__
CGContextFlush(offscreen); CGContextFlush(offscreen);
ld = CGBitmapContextGetBytesPerRow(offscreen); data = fl_read_image(NULL, 0, 0, width, height, 0);
data = (uchar*)malloc(ld * height);
memcpy(data, (uchar *)CGBitmapContextGetData(offscreen), ld * height);
depth = 4;
fl_gc = 0; fl_gc = 0;
#elif defined(WIN32) #elif defined(WIN32)
fl_pop_clip(); fl_pop_clip();
@ -117,7 +115,7 @@ Fl_RGB_Image* Fl_Image_Surface::image()
fl_window = pre_window; fl_window = pre_window;
previous->set_current(); previous->set_current();
#endif #endif
Fl_RGB_Image *image = new Fl_RGB_Image(data, width, height, depth, ld); Fl_RGB_Image *image = new Fl_RGB_Image(data, width, height);
image->alloc_array = 1; image->alloc_array = 1;
return image; return image;
} }