Author: AlbrechtS
Date: 2009-04-21 02:25:22 -0700 (Tue, 21 Apr 2009)
New Revision: 6773
Log:
Fixed gray scale w/alpha image drawing for Mac OS with Quartz (FLTK 1.1
with Quickdraw worked) in src/Fl_Images.cxx.

Changed test/unittest_images.cxx to use Fl_RGB_Image::draw() to draw images
with alpha channel, because  the current version of fl_draw_image()
supports alpha channels only on Mac. Tested on Windows[1], Linux, and Mac.

[1] Windows with GDI drawing doesn't work yet for gray+alpha (STR 2105).

To do: Check, if fl_draw_image() should support alpha channel images
on all platforms or not at all. The current documentation mentions only
RGB and gray scale images. IMHO the behavior is undefined for values of
abs(d) == 2 and abs(d) > 3. See also fl_draw_image_mono().


Modified:
   branches/branch-1.3/src/Fl_Image.cxx
   branches/branch-1.3/test/unittest_images.cxx

Modified: branches/branch-1.3/src/Fl_Image.cxx
===================================================================
--- branches/branch-1.3/src/Fl_Image.cxx        2009-04-21 09:09:37 UTC (rev 
6772)
+++ branches/branch-1.3/src/Fl_Image.cxx        2009-04-21 09:25:22 UTC (rev 
6773)
@@ -452,7 +452,11 @@
   if (H <= 0) return;
   if (!id) {
 #ifdef __APPLE_QUARTZ__
-    CGColorSpaceRef lut = CGColorSpaceCreateDeviceRGB();
+    CGColorSpaceRef lut = 0;
+    if (d()<=2)
+      lut = CGColorSpaceCreateDeviceGray();
+    else
+      lut = CGColorSpaceCreateDeviceRGB();
     CGDataProviderRef src = CGDataProviderCreateWithData( 0L, array, 
w()*h()*d(), 0L);
     id = CGImageCreate( w(), h(), 8, d()*8, ld()?ld():w()*d(),
         lut, (d()&1)?kCGImageAlphaNone:kCGImageAlphaLast,

Modified: branches/branch-1.3/test/unittest_images.cxx
===================================================================
--- branches/branch-1.3/test/unittest_images.cxx        2009-04-21 09:09:37 UTC 
(rev 6772)
+++ branches/branch-1.3/test/unittest_images.cxx        2009-04-21 09:25:22 UTC 
(rev 6773)
@@ -29,7 +29,7 @@
 #include <FL/fl_draw.H>
 
 //
-//------- test the line drawing capabilities of this implementation ----------
+//------- test the image drawing capabilities of this implementation ----------
 //
 class ImageTest : public Fl_Box {
 public: 
@@ -48,12 +48,16 @@
         *drgba++           = *dga++         = x+y;
       }
     }
+    i_rgba = new Fl_RGB_Image (img_rgba,128,128,4);
+    i_ga = new Fl_RGB_Image (img_gray_a,128,128,2);
     return new ImageTest(TESTAREA_X, TESTAREA_Y, TESTAREA_W, TESTAREA_H);
   }
   static uchar *img_gray;
   static uchar *img_gray_a;
   static uchar *img_rgb;
   static uchar *img_rgba;
+  static Fl_RGB_Image *i_rgba;
+  static Fl_RGB_Image *i_ga;
   ImageTest(int x, int y, int w, int h) : Fl_Box(x, y, w, h) {
     label("Testing Image Drawing\n\n"
        "This test renders four images, two of them with a checker board\n"
@@ -74,7 +78,8 @@
     fl_color(FL_BLACK); fl_rectf(xx, yy, 130, 130);
     fl_color(FL_WHITE); fl_rectf(xx+1, yy+1, 64, 64);
     fl_color(FL_WHITE); fl_rectf(xx+65, yy+65, 64, 64);
-    fl_draw_image(img_rgba, xx+1, yy+1, 128, 128, 4);
+    // fl_draw_image(img_rgba, xx+1, yy+1, 128, 128, 4);
+    i_rgba->draw(xx+1,yy+1);
     fl_color(FL_BLACK); fl_draw("RGBA", xx+134, yy+64);
 
     xx = x()+10+200; yy = y()+10;
@@ -86,7 +91,8 @@
     fl_color(FL_BLACK); fl_rectf(xx, yy, 130, 130);
     fl_color(FL_WHITE); fl_rectf(xx+1, yy+1, 64, 64);
     fl_color(FL_WHITE); fl_rectf(xx+65, yy+65, 64, 64);
-    fl_draw_image(img_gray_a, xx+1, yy+1, 128, 128, 2);
+    // fl_draw_image(img_gray_a, xx+1, yy+1, 128, 128, 2);
+    i_ga->draw(xx+1,yy+1);
     fl_color(FL_BLACK); fl_draw("Gray+Alpha", xx+134, yy+64);
   }
 };
@@ -95,6 +101,8 @@
 uchar *ImageTest::img_gray_a = 0;
 uchar *ImageTest::img_rgb = 0;
 uchar *ImageTest::img_rgba = 0;
+Fl_RGB_Image *ImageTest::i_rgba = 0;
+Fl_RGB_Image *ImageTest::i_ga = 0;
 
 UnitTest images("drawing images", ImageTest::create);
 

_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit

Reply via email to