diff options
| author | Manolo Gouy <Manolo> | 2016-02-29 17:35:49 +0000 |
|---|---|---|
| committer | Manolo Gouy <Manolo> | 2016-02-29 17:35:49 +0000 |
| commit | 6d34c647ca0e83edd89fc7f1c0a98d485d569002 (patch) | |
| tree | 64ed74238c6ec542694cdcfecc0282b41f7ba1b3 /src/drivers/Quartz | |
| parent | 9f91e336a18d2d8ffa8c5216eeed210054685fdb (diff) | |
Accept fl_draw_image(buf, X,Y,W,H,D,L) with negative D and/or L arguments on the Mac OS platform.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11251 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/drivers/Quartz')
| -rw-r--r-- | src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx | 77 |
1 files changed, 21 insertions, 56 deletions
diff --git a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx index 3574adce5..daf26951c 100644 --- a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx +++ b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx @@ -53,91 +53,56 @@ static void innards(const uchar *buf, int X, int Y, int W, int H, int delta, int linedelta, int mono, Fl_Draw_Image_Cb cb, void* userdata, CGContextRef gc) { - if (!linedelta) linedelta = W*delta; + if (!linedelta) linedelta = W*abs(delta); const void *array = buf; uchar *tmpBuf = 0; if (cb || Fl_Surface_Device::surface() != Fl_Display_Device::display_device()) { - tmpBuf = new uchar[ H*W*delta ]; + tmpBuf = new uchar[ H*W*abs(delta) ]; if (cb) { for (int i=0; i<H; i++) { - cb(userdata, 0, i, W, tmpBuf+i*W*delta); + cb(userdata, 0, i, W, tmpBuf+i*W*abs(delta)); } } else { uchar *p = tmpBuf; for (int i=0; i<H; i++) { - memcpy(p, buf+i*linedelta, W*delta); - p += W*delta; + memcpy(p, buf+i*abs(linedelta), W*abs(delta)); + p += W*abs(delta); } } array = (void*)tmpBuf; - linedelta = W*delta; + linedelta = W*abs(delta); } // create an image context CGColorSpaceRef lut = 0; - if (delta<=2) + if (abs(delta)<=2) lut = CGColorSpaceCreateDeviceGray(); else lut = CGColorSpaceCreateDeviceRGB(); // a release callback is necessary when the gc is a print context because the image data // must be kept until the page is closed. Thus tmpBuf can't be deleted here. It's too early. - CGDataProviderRef src = CGDataProviderCreateWithData( 0L, array, linedelta*H, + CGDataProviderRef src = CGDataProviderCreateWithData( 0L, array, abs(linedelta)*H, tmpBuf ? dataReleaseCB : NULL ); - CGImageRef img = CGImageCreate( W, H, 8, 8*delta, linedelta, - lut, delta&1?kCGImageAlphaNone:kCGImageAlphaLast, + CGImageRef img = CGImageCreate( W, H, 8, 8*abs(delta), abs(linedelta), + lut, abs(delta)&1?kCGImageAlphaNone:kCGImageAlphaLast, src, 0L, false, kCGRenderingIntentDefault); - // draw the image into the destination context - if (img) { - ((Fl_Quartz_Graphics_Driver*)fl_graphics_driver)->draw_CGImage(img, X,Y,W,H, 0,0,W,H); - // release all allocated resources - CGImageRelease(img); - } CGColorSpaceRelease(lut); CGDataProviderRelease(src); - if (img) return; // else fall through to slow mode - // following the very save (and very slow) way to write the image into the give port - CGContextSetShouldAntialias(gc, false); - if ( cb ) - { - uchar *tmpBuf = new uchar[ W*4 ]; - for ( int i=0; i<H; i++ ) - { - uchar *src = tmpBuf; - cb( userdata, 0, i, W, tmpBuf ); - for ( int j=0; j<W; j++ ) - { - if ( mono ) - { fl_color( src[0], src[0], src[0] ); } - else - { fl_color( src[0], src[1], src[2] ); } - CGContextMoveToPoint(gc, X+j, Y+i); - CGContextAddLineToPoint(gc, X+j, Y+i); - CGContextStrokePath(gc); - src+=delta; - } + // draw the image into the destination context + if (img) { + CGContextTranslateCTM(gc, X, Y); + if (linedelta < 0) { + CGContextTranslateCTM(gc, 0, H-1); + CGContextScaleCTM(gc, 1, -1); } - delete[] tmpBuf; - } - else - { - for ( int i=0; i<H; i++ ) - { - const uchar *src = buf+i*linedelta; - for ( int j=0; j<W; j++ ) - { - if ( mono ) - fl_color( src[0], src[0], src[0] ); - else - fl_color( src[0], src[1], src[2] ); - CGContextMoveToPoint(gc, X+j, Y+i); - CGContextAddLineToPoint(gc, X+j, Y+i); - CGContextStrokePath(gc); - src += delta; - } + if (delta < 0) { + CGContextTranslateCTM(gc, W-1, 0); + CGContextScaleCTM(gc, -1, 1); } + ((Fl_Quartz_Graphics_Driver*)fl_graphics_driver)->draw_CGImage(img, 0,0,W,H, 0,0,W,H); + CGImageRelease(img); } - CGContextSetShouldAntialias(gc, true); } void Fl_Quartz_Graphics_Driver::draw_image(const uchar* buf, int x, int y, int w, int h, int d, int l){ |
