From a349dc994e686e99338e4b9b8aaf07fd1921e51d Mon Sep 17 00:00:00 2001 From: Manolo Gouy Date: Sun, 14 Feb 2016 06:02:12 +0000 Subject: Move Fl_Quartz_Graphics_Driver::draw_CGImage() to Fl_Quartz_Graphics_Driver_image.cxx git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11169 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx | 37 ---------------------- .../Quartz/Fl_Quartz_Graphics_Driver_image.cxx | 37 ++++++++++++++++++++++ 2 files changed, 37 insertions(+), 37 deletions(-) (limited to 'src/drivers/Quartz') diff --git a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx index 81d916819..44fe57403 100644 --- a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx +++ b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.cxx @@ -150,43 +150,6 @@ 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_image.cxx b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx index c15e767a2..f97dabf04 100644 --- a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx +++ b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx @@ -314,6 +314,43 @@ fl_uintptr_t Fl_Quartz_Graphics_Driver::cache(Fl_Pixmap *img, int w, int h, cons return (fl_uintptr_t)id; } +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$". // -- cgit v1.2.3