summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2010-06-18 16:31:15 +0000
committerManolo Gouy <Manolo>2010-06-18 16:31:15 +0000
commit2425499352346fcf92e66c785a242afa0bd0e254 (patch)
treecba06488c2b6db6d0e116f270ea5c0cbfbb87721
parent006e5ff9c0013b054664dc9d3a45f980398ca2e3 (diff)
Fixed STR 2257. fl_read_image now accepts also reading from an off-screen buffer, as documented.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7650 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
-rw-r--r--src/fl_read_image_mac.cxx27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/fl_read_image_mac.cxx b/src/fl_read_image_mac.cxx
index d195873d7..5493ff3ca 100644
--- a/src/fl_read_image_mac.cxx
+++ b/src/fl_read_image_mac.cxx
@@ -29,7 +29,7 @@
extern unsigned char *MACbitmapFromRectOfWindow(Fl_Window *win, int x, int y, int w, int h, int *bytesPerPixel);
//
-// 'fl_read_image()' - Read an image from the current window.
+// 'fl_read_image()' - Read an image from the current window or off-screen buffer.
//
uchar * // O - Pixel buffer or NULL if failed
@@ -39,11 +39,24 @@ fl_read_image(uchar *p, // I - Pixel buffer or NULL to allocate
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)
- Fl_Window *window = Fl_Window::current();
- while(window->window()) window = window->window();
- int delta;
- uchar *base = MACbitmapFromRectOfWindow(window,x,y,w,h,&delta);
- int rowBytes = delta*w;
+ uchar *base;
+ int rowBytes, delta;
+ if(fl_window == NULL) { // reading from an offscreen buffer
+ CGContextRef src = (CGContextRef)fl_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
+ Fl_Window *window = Fl_Window::current();
+ while(window->window()) window = window->window();
+ base = MACbitmapFromRectOfWindow(window,x,y,w,h,&delta);
+ rowBytes = delta*w;
+ }
// Allocate the image data array as needed...
int d = alpha ? 4 : 3;
if (!p) p = new uchar[w * h * d];
@@ -59,7 +72,7 @@ fl_read_image(uchar *p, // I - Pixel buffer or NULL to allocate
pdst[2] = psrc[2]; // B
}
}
- delete base;
+ if(fl_window != NULL) delete base;
return p;
}