diff options
| author | Manolo Gouy <Manolo> | 2016-02-13 14:48:13 +0000 |
|---|---|---|
| committer | Manolo Gouy <Manolo> | 2016-02-13 14:48:13 +0000 |
| commit | 4af616a7a27c3104938bf580502c762becd4417b (patch) | |
| tree | cf3ab60ea9727c887ccf91d0caca32e5ba523f78 /src/drivers/Quartz | |
| parent | c95169ea492a0d1b101f42b3f46d4e8607b9dd4a (diff) | |
New member function Fl_Quartz_Graphics_Driver::draw_CGImage() used internally for all image drawing.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11165 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/drivers/Quartz')
| -rw-r--r-- | src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx | 44 | ||||
| -rw-r--r-- | src/drivers/Quartz/Fl_Quartz_Graphics_Driver.h | 1 | ||||
| -rw-r--r-- | src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx | 15 |
3 files changed, 42 insertions, 18 deletions
diff --git a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx index a8ed4185e..81d916819 100644 --- a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx +++ b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx @@ -65,11 +65,8 @@ void Fl_Quartz_Graphics_Driver::copy_offscreen(int x,int y,int w,int h,Fl_Offscr CGDataProviderRef src_bytes = CGDataProviderCreateWithData( src, data, sw*sh*4, bmProviderRelease); CGImageRef img = CGImageCreate( sw, sh, 8, 4*8, 4*sw, lut, alpha, src_bytes, 0L, false, kCGRenderingIntentDefault); - // fl_push_clip(); - CGRect rect = CGRectMake(x, y, w, h); - Fl_X::q_begin_image(rect, srcx, srcy, sw, sh); - CGContextDrawImage(fl_gc, rect, img); - Fl_X::q_end_image(); + draw_CGImage(img, x, y, w, h, srcx, srcy, sw, sh); + CGImageRelease(img); CGColorSpaceRelease(lut); CGDataProviderRelease(src_bytes); @@ -153,7 +150,42 @@ void fl_end_offscreen() { /** @} */ - +void Fl_Quartz_Graphics_Driver::draw_CGImage(CGImageRef cgimg, int x, int y, int w, int h, int srcx, int srcy, int sw, int sh) +{ + CGRect rect = CGRectMake(x, y, w, h); + CGContextSaveGState(fl_gc); + CGContextClipToRect(fl_gc, CGRectOffset(rect, -0.5, -0.5 )); + // move graphics context to origin of vertically reversed image + // The 0.5 here cancels the 0.5 offset present in Quartz graphics contexts. + // Thus, image and surface pixels are in phase if there's no scaling. + CGContextTranslateCTM(fl_gc, rect.origin.x - srcx - 0.5, rect.origin.y - srcy + sh - 0.5); + CGContextScaleCTM(fl_gc, 1, -1); + CGAffineTransform at = CGContextGetCTM(fl_gc); + if (at.a == at.d && at.b == 0 && at.c == 0) { // proportional scaling, no rotation + // We handle x2 and /2 scalings that occur when drawing to + // a double-resolution bitmap, and when drawing a double-resolution bitmap to display. + bool doit = false; + // phase image with display pixels + CGFloat deltax = 0, deltay = 0; + if (at.a == 2) { // make .tx and .ty have even values + deltax = (at.tx/2 - round(at.tx/2)); + deltay = (at.ty/2 - round(at.ty/2)); + doit = true; + } else if (at.a == 0.5) { + doit = true; + if (Fl_Display_Device::high_resolution()) { // make .tx and .ty have int or half-int values + deltax = (at.tx*2 - round(at.tx*2)); + deltay = (at.ty*2 - round(at.ty*2)); + } else { // make .tx and .ty have integral values + deltax = (at.tx - round(at.tx))*2; + deltay = (at.ty - round(at.ty))*2; + } + } + if (doit) CGContextTranslateCTM(fl_gc, -deltax, -deltay); + } + CGContextDrawImage(fl_gc, CGRectMake(0, 0, sw, sh), cgimg); + CGContextRestoreGState(fl_gc); +} // // End of "$Id$". diff --git a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.h b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.h index 5d2c0ccb0..93fbbfeb3 100644 --- a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.h +++ b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.h @@ -64,6 +64,7 @@ public: static Fl_Offscreen create_offscreen_with_alpha(int w, int h); #endif void copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy); + void draw_CGImage(CGImageRef cgimg, int x, int y, int w, int h, int srcx, int srcy, int sw, int sh); protected: // --- implementation is in src/fl_rect.cxx which includes src/cfg_gfx/quartz_rect.cxx void point(int x, int y); diff --git a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx index 868d81ec8..c15e767a2 100644 --- a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx +++ b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx @@ -90,10 +90,7 @@ static void innards(const uchar *buf, int X, int Y, int W, int H, src, 0L, false, kCGRenderingIntentDefault); // draw the image into the destination context if (img) { - CGRect rect = CGRectMake( X, Y, W, H); - Fl_X::q_begin_image(rect, 0, 0, W, H); - CGContextDrawImage(fl_gc, rect, img); - Fl_X::q_end_image(); + ((Fl_Quartz_Graphics_Driver*)fl_graphics_driver)->draw_CGImage(img, X,Y,W,H, 0,0,W,H); // release all allocated resources CGImageRelease(img); } @@ -170,10 +167,7 @@ void Fl_Quartz_Graphics_Driver::draw(Fl_Bitmap *bm, int XP, int YP, int WP, int return; } if (bm->id_ && fl_gc) { - CGRect rect = { { (CGFloat)X, (CGFloat)Y }, { (CGFloat)W, (CGFloat)H } }; - Fl_X::q_begin_image(rect, cx, cy, bm->w(), bm->h()); - CGContextDrawImage(fl_gc, rect, (CGImageRef)bm->id_); - Fl_X::q_end_image(); + draw_CGImage((CGImageRef)bm->id_, X,Y,W,H, cx, cy, bm->w(), bm->h()); } } @@ -249,10 +243,7 @@ void Fl_Quartz_Graphics_Driver::draw(Fl_RGB_Image *img, int XP, int YP, int WP, CGColorSpaceRelease(lut); CGDataProviderRelease(src); } - CGRect rect = CGRectMake(X, Y, W, H); - Fl_X::q_begin_image(rect, cx, cy, img->w(), img->h()); - CGContextDrawImage(fl_gc, rect, (CGImageRef)img->id_); - Fl_X::q_end_image(); + draw_CGImage((CGImageRef)img->id_, X,Y,W,H, cx,cy, img->w(), img->h()); } } |
