diff options
| author | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2020-10-14 09:56:41 +0200 |
|---|---|---|
| committer | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2020-10-14 09:56:53 +0200 |
| commit | 966e15fe376cb931e543c69371627cfa00bfc6a8 (patch) | |
| tree | 9a9eb6815e4ec91401f907c3982b71552d9a948b | |
| parent | 0d8385a652441440d8fa2db15bd40d4d5cf4e734 (diff) | |
Simpler implementation of Fl_Quartz_Image_Surface_Driver::image()
| -rw-r--r-- | src/drivers/Quartz/Fl_Quartz_Image_Surface_Driver.cxx | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/drivers/Quartz/Fl_Quartz_Image_Surface_Driver.cxx b/src/drivers/Quartz/Fl_Quartz_Image_Surface_Driver.cxx index 61068cf87..e0146c8b7 100644 --- a/src/drivers/Quartz/Fl_Quartz_Image_Surface_Driver.cxx +++ b/src/drivers/Quartz/Fl_Quartz_Image_Surface_Driver.cxx @@ -114,10 +114,19 @@ Fl_RGB_Image* Fl_Quartz_Image_Surface_Driver::image() CGContextFlush(offscreen); int W = CGBitmapContextGetWidth(offscreen); int H = CGBitmapContextGetHeight(offscreen); - int save_w = width, save_h = height; - width = W; height = H; - unsigned char *data = fl_read_image(NULL, 0, 0, W, H, 0); - width = save_w; height = save_h; + int bpr = CGBitmapContextGetBytesPerRow(offscreen); + int bpp = CGBitmapContextGetBitsPerPixel(offscreen)/8; + uchar *base = (uchar*)CGBitmapContextGetData(offscreen); + int idx, idy; + uchar *pdst, *psrc; + unsigned char *data = new uchar[W * H * 3]; + for (idy = 0, pdst = data; idy < H; idy ++) { + for (idx = 0, psrc = base + idy * bpr; idx < W; idx ++, psrc += bpp, pdst += 3) { + pdst[0] = psrc[0]; // R + pdst[1] = psrc[1]; // G + pdst[2] = psrc[2]; // B + } + } Fl_RGB_Image *image = new Fl_RGB_Image(data, W, H); image->alloc_array = 1; return image; |
