summaryrefslogtreecommitdiff
path: root/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2016-04-03 06:51:09 +0000
committerManolo Gouy <Manolo>2016-04-03 06:51:09 +0000
commitf1ffe2f1fee001ffb3c9327c6c09f5e5d9dc91de (patch)
tree58a67c3e8a8f8d651e358efc70d04747321c251b /src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx
parentc88af210e775d90d2537f4277909bb081a9c064a (diff)
Rewrite fl_read_image.cxx under the driver model.
Files fl_read_image_mac.cxx and fl_read_image_win32.cxx are no longer used; their content is now in Fl_XXX_Screen_Driver.cxx git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11516 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx')
-rw-r--r--src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx b/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx
index 2c9f693fc..c23046e30 100644
--- a/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx
+++ b/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx
@@ -325,6 +325,51 @@ void Fl_Screen_Driver::font_name(int num, const char *name) {
s->first = 0;
}
+uchar * // O - Pixel buffer or NULL if failed
+Fl_Cocoa_Screen_Driver::read_image(uchar *p, // I - Pixel buffer or NULL to allocate
+ int x, // I - Left position
+ int y, // I - Top position
+ int w, // I - Width of area to read
+ int h, // I - Height of area to read
+ int alpha) // I - Alpha value for image (0 for none)
+{
+ uchar *base;
+ int rowBytes, delta;
+ if (fl_window == NULL) { // reading from an offscreen buffer
+ CGContextRef src = (CGContextRef)Fl_Surface_Device::surface()->driver()->gc(); // get bitmap context
+ base = (uchar *)CGBitmapContextGetData(src); // get data
+ if(!base) return NULL;
+ int sw = CGBitmapContextGetWidth(src);
+ int sh = CGBitmapContextGetHeight(src);
+ rowBytes = CGBitmapContextGetBytesPerRow(src);
+ delta = CGBitmapContextGetBitsPerPixel(src)/8;
+ if( (sw - x < w) || (sh - y < h) ) return NULL;
+ }
+ else { // reading from current window
+ base = Fl_X::bitmap_from_window_rect(Fl_Window::current(),x,y,w,h,&delta);
+ if (!base) return NULL;
+ rowBytes = delta*w;
+ x = y = 0;
+ }
+ // Allocate the image data array as needed...
+ int d = alpha ? 4 : 3;
+ if (!p) p = new uchar[w * h * d];
+ // Initialize the default colors/alpha in the whole image...
+ memset(p, alpha, w * h * d);
+ // Copy the image from the off-screen buffer to the memory buffer.
+ int idx, idy; // Current X & Y in image
+ uchar *pdst, *psrc;
+ for (idy = y, pdst = p; idy < h + y; idy ++) {
+ for (idx = 0, psrc = base + idy * rowBytes + x * delta; idx < w; idx ++, psrc += delta, pdst += d) {
+ pdst[0] = psrc[0]; // R
+ pdst[1] = psrc[1]; // G
+ pdst[2] = psrc[2]; // B
+ }
+ }
+ if(fl_window != NULL) delete[] base;
+ return p;
+}
+
//
// End of "$Id$".
//