summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbrecht Schlosser <albrechts.fltk@online.de>2009-06-29 07:44:25 +0000
committerAlbrecht Schlosser <albrechts.fltk@online.de>2009-06-29 07:44:25 +0000
commit7e7a74203a4e5bbbba2fcc8879311732b75cf221 (patch)
treea2e5fa7fe2b3ec26565f8447ed208cf70506731e
parent121138fa9333e32a1419d8f3eb3c45f784625d77 (diff)
Fixed gray-scale images with alpha channel (STR #2105).
Note: Windows needs RGBA Bitmaps (4 bytes) to do alpha blending. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6804 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
-rw-r--r--CHANGES1
-rw-r--r--src/Fl_Image.cxx2
-rw-r--r--src/fl_draw_image_win32.cxx16
3 files changed, 14 insertions, 5 deletions
diff --git a/CHANGES b/CHANGES
index 558fcc444..b92153e2d 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,6 @@
CHANGES IN FLTK 1.3.0
+ - Fixed gray-scale images with alpha channel (STR #2105)
- Fixed unexpected shortcut behavior for Win32 (STR #2199)
- Fixed documentation for Fl_Progress (STR #2209)
- Fluid printing used wrong colors under Windows (STR #2195)
diff --git a/src/Fl_Image.cxx b/src/Fl_Image.cxx
index f9c07cb9a..849d43f90 100644
--- a/src/Fl_Image.cxx
+++ b/src/Fl_Image.cxx
@@ -465,7 +465,7 @@ void Fl_RGB_Image::draw(int XP, int YP, int WP, int HP, int cx, int cy) {
CGDataProviderRelease(src);
#elif defined(WIN32)
id = fl_create_offscreen(w(), h());
- if (d() == 2 || d() == 4 && fl_can_do_alpha_blending()) {
+ if ((d() == 2 || d() == 4) && fl_can_do_alpha_blending()) {
fl_begin_offscreen((Fl_Offscreen)id);
fl_draw_image(array, 0, 0, w(), h(), d()|FL_IMAGE_WITH_ALPHA, ld());
fl_end_offscreen();
diff --git a/src/fl_draw_image_win32.cxx b/src/fl_draw_image_win32.cxx
index 1d4495b1a..d43f90e6c 100644
--- a/src/fl_draw_image_win32.cxx
+++ b/src/fl_draw_image_win32.cxx
@@ -153,7 +153,7 @@ static void innards(const uchar *buf, int X, int Y, int W, int H,
bmi.bmiColors[i].rgbBlue = (uchar)i;
bmi.bmiColors[i].rgbGreen = (uchar)i;
bmi.bmiColors[i].rgbRed = (uchar)i;
- bmi.bmiColors[i].rgbReserved = (uchar)i;
+ bmi.bmiColors[i].rgbReserved = (uchar)0; // must be zero
}
}
bmi.bmiHeader.biWidth = w;
@@ -164,6 +164,10 @@ static void innards(const uchar *buf, int X, int Y, int W, int H,
bmi.bmiHeader.biBitCount = depth*8;
int pixelsize = depth;
#endif
+ if (depth==2) { // special case: gray with alpha
+ bmi.bmiHeader.biBitCount = 32;
+ pixelsize = 4;
+ }
int linesize = (pixelsize*w+3)&~3;
static U32* buffer;
@@ -218,9 +222,13 @@ static void innards(const uchar *buf, int X, int Y, int W, int H,
for (i=w; i--; from += delta) *to++ = *from;
break;
case 2:
- for (i=w; i--; from += delta) {
- *to++ = *from;
- *to++ = *from;
+ for (i=w; i--; from += delta, to += 4) {
+ uchar a = from[1];
+ uchar gray = (from[0]*a)>>8;
+ to[0] = gray;
+ to[1] = gray;
+ to[2] = gray;
+ to[3] = a;
}
break;
case 3: