summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2019-04-09 18:50:18 +0200
committerManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2019-04-09 18:50:18 +0200
commit8286e37b18dcbf788cea188a9f1df5824baf0731 (patch)
tree06d14a259807a71300c8851e639c9bbd0f9dd867
parent0ddf5e74a94132e00e117372d0350f798d537543 (diff)
Add public function Fl_RGB_Image *fl_capture_window_part()
In the context of HighDPI screens, the API of function fl_read_image() is inadequate because a rectangle of size WxH drawing units of a window may contain many more than W*H pixels. Function fl_capture_window_part() returns an Fl_RGB_Image object whose drawing size matches the size of the rectangle and whose data size matches the, possibly larger, size in pixels of the corresponding area of the mapped window.
-rw-r--r--FL/fl_draw.H1
-rw-r--r--src/fl_read_image.cxx19
2 files changed, 20 insertions, 0 deletions
diff --git a/FL/fl_draw.H b/FL/fl_draw.H
index f1a867071..3805190b3 100644
--- a/FL/fl_draw.H
+++ b/FL/fl_draw.H
@@ -794,6 +794,7 @@ inline void fl_draw_image_mono(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int
inline char fl_can_do_alpha_blending() {return Fl_Graphics_Driver::default_driver().can_do_alpha_blending();}
FL_EXPORT uchar *fl_read_image(uchar *p,int X,int Y,int W,int H,int alpha=0);
+FL_EXPORT Fl_RGB_Image *fl_capture_window_part(Fl_Window *win, int x, int y, int w, int h);
// pixmaps:
/**
diff --git a/src/fl_read_image.cxx b/src/fl_read_image.cxx
index 522d085c3..3498b03b6 100644
--- a/src/fl_read_image.cxx
+++ b/src/fl_read_image.cxx
@@ -36,6 +36,8 @@
The \p alpha parameter controls whether an alpha channel is created
and the value that is placed in the alpha channel. If 0, no alpha
channel is generated.
+
+ \see fl_capture_window_part()
*/
uchar *fl_read_image(uchar *p, int X, int Y, int w, int h, int alpha) {
uchar *image_data = NULL;
@@ -88,6 +90,23 @@ uchar *fl_read_image(uchar *p, int X, int Y, int w, int h, int alpha) {
return image_data;
}
+/** Captures the content of a rectangular zone of a mapped window.
+ \param win a mapped Fl_Window (derived types including Fl_Gl_Window are also possible)
+ \param x,y,w,h window area to be captured. Intersecting sub-windows are captured too.
+ \return The captured pixels as an Fl_RGB_Image. The raw and
+ drawing sizes of the image can differ. Returns NULL when capture was not successful.
+ The image depth may differ between platforms.
+ \version 1.4
+*/
+Fl_RGB_Image *fl_capture_window_part(Fl_Window *win, int x, int y, int w, int h)
+{
+ Fl_RGB_Image *rgb = NULL;
+ if (win->shown()) {
+ rgb = Fl_Screen_Driver::traverse_to_gl_subwindows(win, x, y, w, h, NULL);
+ if (rgb) rgb->scale(w, h, 0, 1);
+ }
+ return rgb;
+}
//
// End of "$Id$".
//