diff options
| author | Manolo Gouy <Manolo> | 2016-02-12 11:49:32 +0000 |
|---|---|---|
| committer | Manolo Gouy <Manolo> | 2016-02-12 11:49:32 +0000 |
| commit | bc83464b642caad491c70e3b54677dd50f6324b2 (patch) | |
| tree | 8bf8b6c7701423c40ba6e2290c89879600c8676a /src/Fl_Image_Surface.cxx | |
| parent | 50ee3bcd66c4baa6bb3388f5b955d726bfc6bdd8 (diff) | |
Add Fl_Shared_Image *Fl_Image_Surface::highres_image() to draw into high-resolution bitmap.
This new member function returns a high resolution bitmap image scaled to the adequate
drawing size. This allows to create a bitmap image able to fill all pixels of a high resolution
display. This is functional only for the Mac OS platform. On other platforms,
the new member function returns an unscaled bitmap.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11158 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_Image_Surface.cxx')
| -rw-r--r-- | src/Fl_Image_Surface.cxx | 60 |
1 files changed, 55 insertions, 5 deletions
diff --git a/src/Fl_Image_Surface.cxx b/src/Fl_Image_Surface.cxx index 83f6a8560..6800c4e09 100644 --- a/src/Fl_Image_Surface.cxx +++ b/src/Fl_Image_Surface.cxx @@ -32,18 +32,48 @@ #else #endif +#ifdef __APPLE__ +class Fl_Quartz_Scaled_Graphics_Driver_ : public Fl_Quartz_Graphics_Driver { +protected: + virtual void push_clip(int x, int y, int w, int h) { + CGContextRestoreGState(fl_gc); + CGContextSaveGState(fl_gc); + CGContextTranslateCTM(fl_gc, 0, CGBitmapContextGetHeight(fl_gc)/2); + CGContextScaleCTM(fl_gc, 1.0f, -1.0f); + CGContextClipToRect(fl_gc, CGRectMake(x, y, w, h)); + } + virtual void pop_clip() { + CGContextRestoreGState(fl_gc); + CGContextSaveGState(fl_gc); + CGContextTranslateCTM(fl_gc, 0, CGBitmapContextGetHeight(fl_gc)/2); + CGContextScaleCTM(fl_gc, 1.0f, -1.0f); + } +}; +#endif + const char *Fl_Image_Surface::class_id = "Fl_Image_Surface"; -/** The constructor. +/** Constructor with optional high resolution. \param w and \param h give the size in pixels of the resulting image. + \param highres if non-zero, the surface pixel size is twice as high and wide as w and h, + which is useful to draw it later on a high resolution display (e.g., retina display). + This is implemented for the Mac OS platform only. + If \p highres is non-zero, use Fl_Image_Surface::highres_image() to get the image data. + \version 1.3.4 (1.3.3 without the highres parameter) */ -Fl_Image_Surface::Fl_Image_Surface(int w, int h) : Fl_Surface_Device(NULL) { +Fl_Image_Surface::Fl_Image_Surface(int w, int h, int highres) : Fl_Surface_Device(NULL) { width = w; height = h; #ifdef __APPLE__ // PORTME: platform image surface - offscreen = fl_create_offscreen(w, h); + offscreen = fl_create_offscreen(highres ? 2*w : w, highres ? 2*h : h); helper = new Fl_Quartz_Flipped_Surface_(width, height); + if (highres) { + delete helper->driver(); + helper->driver(new Fl_Quartz_Scaled_Graphics_Driver_); + CGContextScaleCTM(offscreen, 2, 2); + } driver(helper->driver()); + CGContextSetShouldAntialias(offscreen, false); CGContextSaveGState(offscreen); CGContextTranslateCTM(offscreen, 0, height); CGContextScaleCTM(offscreen, 1.0f, -1.0f); @@ -95,9 +125,13 @@ Fl_Image_Surface::~Fl_Image_Surface() { Fl_RGB_Image* Fl_Image_Surface::image() { unsigned char *data; + int W = width, H = height; #ifdef __APPLE__ // PORTME: platform image surface CGContextFlush(offscreen); - data = fl_read_image(NULL, 0, 0, width, height, 0); + W = CGBitmapContextGetWidth(offscreen); + H = CGBitmapContextGetHeight(offscreen); + Fl_X::set_high_resolution(0); + data = fl_read_image(NULL, 0, 0, W, H, 0); fl_gc = 0; #elif defined(WIN32) fl_pop_clip(); @@ -115,11 +149,26 @@ Fl_RGB_Image* Fl_Image_Surface::image() fl_window = pre_window; previous->set_current(); #endif - Fl_RGB_Image *image = new Fl_RGB_Image(data, width, height); + Fl_RGB_Image *image = new Fl_RGB_Image(data, W, H); image->alloc_array = 1; return image; } + +/** Returns a possibly high resolution image made of all drawings sent to the Fl_Image_Surface object. + The Fl_Image_Surface object should have been constructed with Fl_Image_Surface(W, H, 1). + The returned image is scaled to a size of WxH drawing units and may have a pixel size twice as wide and high. + The returned object should be deallocated with Fl_Shared_Image::release() after use. + \version 1.3.4 + */ +Fl_Shared_Image* Fl_Image_Surface::highres_image() +{ + Fl_Shared_Image *s_img = Fl_Shared_Image::get(image()); + s_img->scale(width, height); + return s_img; +} + + /** Draws a widget in the image surface \param widget any FLTK widget (e.g., standard, custom, window, GL view) to draw in the image @@ -137,6 +186,7 @@ void Fl_Image_Surface::set_current() #if defined(__APPLE__) // PORTME: platform image surface fl_gc = offscreen; fl_window = 0; Fl_Surface_Device::set_current(); + Fl_X::set_high_resolution( CGBitmapContextGetWidth(offscreen) > width ); #elif defined(WIN32) _sgc=fl_gc; _sw=fl_window; |
