imacarthur wrote:
- Like what Matthias has done with the alpha blending, shame it doesn't
work yet on other platforms.
I was wondering why, and I did some tests (see attached diff file).
All tested versions worked okay with "normal" images w/o alpha
channel.
The first (now commented) version added "|FL_IMAGE_WITH_ALPHA" to
the depth argument, but this:
- didn't fix it (changed the appearance on Windows, though)
- crashed on Linux
(I didn't try on Mac).
The optional "|FL_IMAGE_WITH_ALPHA" is currently _only_ checked
in src/fl_draw_image_win32.cxx (Windows-only)! I don't know if
it is documented, but it's inconsistent and should be checked.
The second (now active) version uses an image (FL_RGB_Image)
with d=4 or d=2. This works on Linux (RGBA and Gray+Alpha),
Windows and Mac (RGBA), but has different problems with
Gray+Alpha on Windows and Mac, AFAICT.
Windows: cf. http://www.fltk.org/str.php?L2105
Mac: looks as if only the checker board background is drawn
and outputs to stderr:
"... <Error>: CGImageCreate: invalid image bits/pixel: 16."
Looks as if we have more than one problem with gray images
with alpha channel (and with fl_draw_image*). :-(
I don't think that the attached diff is a _solution_,
but it should show the different problems I found when
testing. IMHO _both_ solutions (fl_draw_image* and my
patched version) should work on all platforms...
I'll do more researching tomorrow, but if anybody
knows this image and drawing stuff well, then please
shout out loud ;-)
FWIW: I also attached another demo alpha.cxx. You can
"play" with the background color and drawing functions.
Albrecht
Index: test/unittest_images.cxx
===================================================================
--- test/unittest_images.cxx (revision 6770)
+++ test/unittest_images.cxx (working copy)
@@ -31,6 +31,9 @@
//
//------- test the line drawing capabilities of this implementation ----------
//
+static Fl_RGB_Image *i_rgba = 0;
+static Fl_RGB_Image *i_ga = 0;
+
class ImageTest : public Fl_Box {
public:
static Fl_Widget *create() {
@@ -48,6 +51,8 @@
*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;
@@ -74,7 +79,9 @@
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);
+ // fl_draw_image(img_rgba, xx+1, yy+1, 128, 128, 4|FL_IMAGE_WITH_ALPHA);
+ 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 +93,9 @@
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);
+ // fl_draw_image(img_gray_a, xx+1, yy+1, 128, 128, 2|FL_IMAGE_WITH_ALPHA);
+ i_ga->draw(xx+1,yy+1);
fl_color(FL_BLACK); fl_draw("Gray+Alpha", xx+134, yy+64);
}
};
//
// Image drawing with alpha channel test and demo.
// This is extracted and modified from test/unittest_images.cxx
//
// compile with:
//
// fltk-config --use-images --compile alpha.cxx
//
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_RGB_Image.H>
#include <FL/Fl_Box.H>
#include <FL/fl_draw.H>
#include <stdlib.h>
class ImageTest : public Fl_Box {
public:
ImageTest(int x, int y, int w, int h, int D) : Fl_Box(x, y, w, h) {
box(FL_NO_BOX);
create(w,h,D);
}
private:
uchar *img_a;
Fl_RGB_Image *img;
void create(int W, int H, int D) {
uchar *dga = (uchar*)malloc(W*W*D);
img_a = dga;
int x,y;
for (y=0; y<H; y++) {
for (x=0; x<W; x++) {
*dga++ = y<<1; // r or gray
if (D==4) {
*dga++ = x<<1; // g
*dga++ = (128-y)<<1; // b
}
*dga++ = 128; // alpha
}
}
img = new Fl_RGB_Image (img_a,W,H,D);
}
void draw() {
// draw box
fl_color(color()); // background color
fl_rectf(x(), y(), w(), h()); // background
fl_color(FL_BLACK); // box color
fl_rect (x(), y(), w(), h()); // box
// fl_draw_image(img_a, x(), y(), w(), h(), img->d());
// fl_draw_image(img_a, x(), y(), w(), h(), img->d()|FL_IMAGE_WITH_ALPHA);
img->draw(x(),y());
}
};
int main (int argc, char **argv)
{
Fl_Window win (300,300);
ImageTest it_a ( 10, 10,128,128,4);
it_a.color(FL_WHITE);
ImageTest it_b (148, 10,128,128,4);
it_b.color(FL_BLACK);
ImageTest it_c ( 10,148,128,128,2);
it_c.color(FL_WHITE);
ImageTest it_d (148,148,128,128,2);
it_d.color(FL_BLACK);
win.end();
win.show(argc,argv);
Fl::run();
}
_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev