From fbd01308b987713ed7487014f15abb99dd5ae2d2 Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Thu, 18 Jan 2007 15:25:09 +0000 Subject: [PATCH] Fixed Quartz image drawing and screen reading git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@5614 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- CHANGES | 4 +++- src/fl_draw_image_mac.cxx | 6 +++--- src/fl_overlay.cxx | 18 +++++++++--------- src/fl_read_image_mac.cxx | 19 ++++++++++--------- test/hello.cxx | 3 +++ 5 files changed, 28 insertions(+), 22 deletions(-) diff --git a/CHANGES b/CHANGES index 3800670c9..88d586c03 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,8 @@ CHANGES IN FLTK 1.1.8 - - overlay drawing is now avoiding XOR mode (STR #1438) + - Fixed Quartz image drawing bug (STR #1438) + - Fixed Quartz fl_read_image + - Overlay drawing is now avoiding XOR mode (STR #1438) - Fixed Scroll crash in Fluid Live Mode (STR #1524) - Fixed mousewheel event propagation (STR #1521) - Fixed drawing issues of a tile in a scroll (STR #1507) diff --git a/src/fl_draw_image_mac.cxx b/src/fl_draw_image_mac.cxx index f70d180c0..fb493b487 100644 --- a/src/fl_draw_image_mac.cxx +++ b/src/fl_draw_image_mac.cxx @@ -175,7 +175,7 @@ static void innards(const uchar *buf, int X, int Y, int W, int H, cb(userdata, 0, i, W, tmpBuf+i*W*delta); } array = (void*)tmpBuf; - linedelta = W; + linedelta = W*delta; } // create an image context CGColorSpaceRef lut = 0; @@ -183,8 +183,8 @@ static void innards(const uchar *buf, int X, int Y, int W, int H, lut = CGColorSpaceCreateDeviceGray(); else lut = CGColorSpaceCreateDeviceRGB(); - CGDataProviderRef src = CGDataProviderCreateWithData( 0L, array, linedelta*H*delta, 0L); - CGImageRef img = CGImageCreate( W, H, 8, 8*delta, linedelta*delta, + CGDataProviderRef src = CGDataProviderCreateWithData( 0L, array, linedelta*H, 0L); + CGImageRef img = CGImageCreate( W, H, 8, 8*delta, linedelta, lut, delta&1?kCGImageAlphaNone:kCGImageAlphaNoneSkipLast, src, 0L, false, kCGRenderingIntentDefault); // draw the image into the destination context diff --git a/src/fl_overlay.cxx b/src/fl_overlay.cxx index d24af5611..21da3f9c3 100644 --- a/src/fl_overlay.cxx +++ b/src/fl_overlay.cxx @@ -73,17 +73,17 @@ static void draw_current_rect() { if (bgE) { free(bgE); bgE = 0L; } if (bgW) { free(bgW); bgW = 0L; } if (pw>0 && ph>0) { - bgN = fl_read_image(0L, px, py, pw, 1); + bgE = fl_read_image(0L, px+pw-1, py, 1, ph); + bgW = fl_read_image(0L, px, py, 1, ph); bgS = fl_read_image(0L, px, py+ph-1, pw, 1); - bgE = fl_read_image(0L, px, py, 1, ph); - bgW = fl_read_image(0L, px+pw-1, py, 1, ph); + bgN = fl_read_image(0L, px, py, pw, 1); bgx = px; bgy = py; bgw = pw; bgh = ph; } - fl_color(FL_BLACK); + fl_color(FL_WHITE); fl_line_style(FL_SOLID); fl_rect(px, py, pw, ph); - fl_color(FL_WHITE); + fl_color(FL_BLACK); fl_line_style(FL_DOT); fl_rect(px, py, pw, ph); fl_line_style(FL_SOLID); @@ -98,10 +98,10 @@ static void erase_current_rect() { draw_current_rect(); # endif #else - if (bgN) fl_draw_image(bgN, px, py, pw, 1); - if (bgS) fl_draw_image(bgS, px, py+ph-1, pw, 1); - if (bgE) fl_draw_image(bgE, px, py, 1, ph); - if (bgW) fl_draw_image(bgW, px+pw-1, py, 1, ph); + if (bgN) fl_draw_image(bgN, bgx, bgy, bgw, 1); + if (bgS) fl_draw_image(bgS, bgx, bgy+bgh-1, bgw, 1); + if (bgW) fl_draw_image(bgW, bgx, bgy, 1, bgh); + if (bgE) fl_draw_image(bgE, bgx+bgw-1, bgy, 1, bgh); #endif } diff --git a/src/fl_read_image_mac.cxx b/src/fl_read_image_mac.cxx index 3cdbd48c4..6a1ba7a67 100644 --- a/src/fl_read_image_mac.cxx +++ b/src/fl_read_image_mac.cxx @@ -43,7 +43,7 @@ fl_read_image(uchar *p, // I - Pixel buffer or NULL to allocate int alpha) { // I - Alpha value for image (0 for none) Rect src, // Source rectangle dst; // Destination rectangle - Fl_Offscreen osbuffer; // Temporary off-screen buffer for copy + GWorldPtr osbuffer; // Temporary off-screen buffer for copy GrafPtr srcPort; // Source port RGBColor rgb; // RGB colors for copy mask... PixMapHandle pm; // Pixmap handle for off-screen buffer @@ -54,12 +54,6 @@ fl_read_image(uchar *p, // I - Pixel buffer or NULL to allocate int d; // Depth of image int rowBytes; // Number of bytes per row... - - // Get an off-screen buffer for copying the image... - osbuffer = fl_create_offscreen(w,h); - - if (!osbuffer) return 0; - // Set the source and destination rectangles... src.top = y; src.left = x; @@ -71,6 +65,14 @@ fl_read_image(uchar *p, // I - Pixel buffer or NULL to allocate dst.bottom = h; dst.right = w; + // Get an off-screen buffer for copying the image... + QDErr err = NewGWorld(&osbuffer, 0, &dst, 0L, 0L, 0); + if (!osbuffer) return 0; + if (err!=noErr) { + DisposeGWorld(osbuffer); + return 0; + } + // Get the source port... GetPort(&srcPort); @@ -121,10 +123,9 @@ fl_read_image(uchar *p, // I - Pixel buffer or NULL to allocate pdst[2] = psrc[2]; } #endif // __i386__ - // Unlock and delete the off-screen buffer, then return... UnlockPixels(pm); - fl_delete_offscreen(osbuffer); + DisposeGWorld(osbuffer); SetPort(srcPort); return p; diff --git a/test/hello.cxx b/test/hello.cxx index 178d52934..a8622c122 100644 --- a/test/hello.cxx +++ b/test/hello.cxx @@ -28,8 +28,11 @@ #include #include #include +#include int main(int argc, char **argv) { + char b[1024]; + fl_filename_relative(b, 1024, "/Users/matt/proj/source"); Fl_Window *window = new Fl_Window(300,180); Fl_Box *box = new Fl_Box(FL_UP_BOX,20,40,260,100,"Hello, World!"); box->labelfont(FL_BOLD+FL_ITALIC);