summaryrefslogtreecommitdiff
path: root/src/drivers/Cocoa
diff options
context:
space:
mode:
Diffstat (limited to 'src/drivers/Cocoa')
-rw-r--r--src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.H1
-rw-r--r--src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx45
2 files changed, 46 insertions, 0 deletions
diff --git a/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.H b/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.H
index 59cd6ce1e..3f475a637 100644
--- a/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.H
+++ b/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.H
@@ -86,6 +86,7 @@ public:
int insertion_point_location(int *px, int *py, int *pheight);
virtual int dnd(int use_selection);
virtual int compose(int &del);
+ virtual uchar *read_image(uchar *p, int x, int y, int w, int h, int alpha);
};
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$".
//