summaryrefslogtreecommitdiff
path: root/src/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/Cairo/Fl_Cairo_Graphics_Driver.H4
-rw-r--r--src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx2
-rw-r--r--src/drivers/GDI/Fl_GDI_Graphics_Driver.H5
-rw-r--r--src/drivers/GDI/Fl_GDI_Graphics_Driver_image.cxx91
-rw-r--r--src/drivers/PostScript/Fl_PostScript_Graphics_Driver.H2
-rw-r--r--src/drivers/Quartz/Fl_Quartz_Graphics_Driver.H4
-rw-r--r--src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx6
-rw-r--r--src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H4
-rw-r--r--src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx6
9 files changed, 96 insertions, 28 deletions
diff --git a/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.H b/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.H
index 60c916fed..b291f63b0 100644
--- a/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.H
+++ b/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.H
@@ -140,8 +140,6 @@ public:
void draw_image_mono(const uchar* d, int x,int y,int w,int h, int delta=1, int ld=0);
void draw_image(Fl_Draw_Image_Cb call, void* data, int x,int y, int w, int h, int delta=3);
void draw_image_mono(Fl_Draw_Image_Cb call, void* data, int x,int y, int w, int h, int delta=1);
- // ---
- Fl_Bitmask create_bitmask(int /*w*/, int /*h*/, const uchar * /*array*/) { return 0L; }
void ps_origin(int x, int y);
void ps_translate(int, int);
@@ -154,7 +152,7 @@ public:
void uncache(Fl_RGB_Image *img, fl_uintptr_t &id_, fl_uintptr_t &mask_);
void draw_bitmap(Fl_Bitmap *bm,int XP, int YP, int WP, int HP, int cx, int cy);
void cache(Fl_Bitmap *img);
- void delete_bitmask(Fl_Bitmask bm);
+ virtual void delete_bitmask(fl_uintptr_t bm);
void cache(Fl_Pixmap *pxm);
void draw_pixmap(Fl_Pixmap *rgb,int XP, int YP, int WP, int HP, int cx, int cy);
void uncache_pixmap(fl_uintptr_t p);
diff --git a/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx b/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx
index 6c306e111..036fe5418 100644
--- a/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx
+++ b/src/drivers/Cairo/Fl_Cairo_Graphics_Driver.cxx
@@ -889,7 +889,7 @@ void Fl_Cairo_Graphics_Driver::uncache_pixmap(fl_uintptr_t p) {
}
-void Fl_Cairo_Graphics_Driver::delete_bitmask(Fl_Bitmask bm) {
+void Fl_Cairo_Graphics_Driver::delete_bitmask(fl_uintptr_t bm) {
cairo_pattern_t *pat = (cairo_pattern_t*)bm;
if (pat) {
cairo_surface_t *surf;
diff --git a/src/drivers/GDI/Fl_GDI_Graphics_Driver.H b/src/drivers/GDI/Fl_GDI_Graphics_Driver.H
index 0749ab798..c916fc65e 100644
--- a/src/drivers/GDI/Fl_GDI_Graphics_Driver.H
+++ b/src/drivers/GDI/Fl_GDI_Graphics_Driver.H
@@ -69,8 +69,9 @@ public:
virtual void *gc() {return gc_;}
// --- bitmap stuff
- Fl_Bitmask create_bitmask(int w, int h, const uchar *array);
- void delete_bitmask(Fl_Bitmask bm);
+ HBITMAP create_bitmask(int w, int h, const uchar *array); // NOT virtual
+ virtual void delete_bitmask(fl_uintptr_t bm);
+ HBITMAP create_alphamask(int w, int h, int d, int ld, const uchar *array);
virtual void draw_unscaled(const char* str, int n, int x, int y);
virtual void draw_unscaled(int angle, const char *str, int n, int x, int y);
virtual void rtl_draw_unscaled(const char* str, int n, int x, int y);
diff --git a/src/drivers/GDI/Fl_GDI_Graphics_Driver_image.cxx b/src/drivers/GDI/Fl_GDI_Graphics_Driver_image.cxx
index e10466088..4cfc745c9 100644
--- a/src/drivers/GDI/Fl_GDI_Graphics_Driver_image.cxx
+++ b/src/drivers/GDI/Fl_GDI_Graphics_Driver_image.cxx
@@ -334,11 +334,11 @@ void Fl_GDI_Graphics_Driver::colored_rectf(int x, int y, int w, int h, uchar r,
}
#endif
-// 'fl_create_bitmask()' - Create an N-bit bitmap for masking...
-Fl_Bitmask Fl_GDI_Graphics_Driver::create_bitmask(int w, int h, const uchar *data) {
+// Create an N-bit bitmap for masking...
+HBITMAP Fl_GDI_Graphics_Driver::create_bitmask(int w, int h, const uchar *data) {
// this won't work when the user changes display mode during run or
// has two screens with differnet depths
- Fl_Bitmask bm;
+ HBITMAP bm;
static uchar hiNibble[16] =
{ 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0 };
@@ -393,7 +393,7 @@ Fl_Bitmask Fl_GDI_Graphics_Driver::create_bitmask(int w, int h, const uchar *dat
return bm;
}
-void Fl_GDI_Graphics_Driver::delete_bitmask(Fl_Bitmask bm) {
+void Fl_GDI_Graphics_Driver::delete_bitmask(fl_uintptr_t bm) {
DeleteObject((HGDIOBJ)bm);
}
@@ -476,6 +476,78 @@ void Fl_GDI_Printer_Graphics_Driver::draw_bitmap(Fl_Bitmap *bm, int XP, int YP,
}
+// Create a 1-bit mask used for alpha blending
+HBITMAP Fl_GDI_Graphics_Driver::create_alphamask(int w, int h, int d, int ld, const uchar *array) {
+ HBITMAP bm;
+ int bmw = (w + 7) / 8;
+ uchar *bitmap = new uchar[bmw * h];
+ uchar *bitptr, bit;
+ const uchar *dataptr;
+ int x, y;
+ static uchar dither[16][16] = { // Simple 16x16 Floyd dither
+ { 0, 128, 32, 160, 8, 136, 40, 168,
+ 2, 130, 34, 162, 10, 138, 42, 170 },
+ { 192, 64, 224, 96, 200, 72, 232, 104,
+ 194, 66, 226, 98, 202, 74, 234, 106 },
+ { 48, 176, 16, 144, 56, 184, 24, 152,
+ 50, 178, 18, 146, 58, 186, 26, 154 },
+ { 240, 112, 208, 80, 248, 120, 216, 88,
+ 242, 114, 210, 82, 250, 122, 218, 90 },
+ { 12, 140, 44, 172, 4, 132, 36, 164,
+ 14, 142, 46, 174, 6, 134, 38, 166 },
+ { 204, 76, 236, 108, 196, 68, 228, 100,
+ 206, 78, 238, 110, 198, 70, 230, 102 },
+ { 60, 188, 28, 156, 52, 180, 20, 148,
+ 62, 190, 30, 158, 54, 182, 22, 150 },
+ { 252, 124, 220, 92, 244, 116, 212, 84,
+ 254, 126, 222, 94, 246, 118, 214, 86 },
+ { 3, 131, 35, 163, 11, 139, 43, 171,
+ 1, 129, 33, 161, 9, 137, 41, 169 },
+ { 195, 67, 227, 99, 203, 75, 235, 107,
+ 193, 65, 225, 97, 201, 73, 233, 105 },
+ { 51, 179, 19, 147, 59, 187, 27, 155,
+ 49, 177, 17, 145, 57, 185, 25, 153 },
+ { 243, 115, 211, 83, 251, 123, 219, 91,
+ 241, 113, 209, 81, 249, 121, 217, 89 },
+ { 15, 143, 47, 175, 7, 135, 39, 167,
+ 13, 141, 45, 173, 5, 133, 37, 165 },
+ { 207, 79, 239, 111, 199, 71, 231, 103,
+ 205, 77, 237, 109, 197, 69, 229, 101 },
+ { 63, 191, 31, 159, 55, 183, 23, 151,
+ 61, 189, 29, 157, 53, 181, 21, 149 },
+ { 254, 127, 223, 95, 247, 119, 215, 87,
+ 253, 125, 221, 93, 245, 117, 213, 85 }
+ };
+
+ // Generate a 1-bit "screen door" alpha mask; not always pretty, but
+ // definitely fast... In the future we may be able to support things
+ // like the RENDER extension in XFree86, when available, to provide
+ // true RGBA-blended rendering. See:
+ //
+ // http://www.xfree86.org/~keithp/render/protocol.html
+ //
+ // for more info on XRender...
+ //
+ memset(bitmap, 0, bmw * h);
+
+ for (dataptr = array + d - 1, y = 0; y < h; y ++, dataptr += ld)
+ for (bitptr = bitmap + y * bmw, bit = 1, x = 0; x < w; x ++, dataptr += d) {
+ if (*dataptr > dither[x & 15][y & 15])
+ *bitptr |= bit;
+ if (bit < 128) bit <<= 1;
+ else {
+ bit = 1;
+ bitptr ++;
+ }
+ }
+
+ bm = create_bitmask(w, h, bitmap);
+ delete[] bitmap;
+
+ return bm;
+}
+
+
void Fl_GDI_Graphics_Driver::cache(Fl_RGB_Image *img)
{
Fl_Image_Surface *surface = new Fl_Image_Surface(img->data_w(), img->data_h());
@@ -485,7 +557,7 @@ void Fl_GDI_Graphics_Driver::cache(Fl_RGB_Image *img)
} else {
fl_draw_image(img->array, 0, 0, img->data_w(), img->data_h(), img->d(), img->ld());
if (img->d() == 2 || img->d() == 4) {
- *Fl_Graphics_Driver::mask(img) = (fl_uintptr_t)fl_create_alphamask(img->data_w(), img->data_h(), img->d(), img->ld(), img->array);
+ *Fl_Graphics_Driver::mask(img) = (fl_uintptr_t)create_alphamask(img->data_w(), img->data_h(), img->d(), img->ld(), img->array);
}
}
Fl_Surface_Device::pop_current();
@@ -586,13 +658,13 @@ void Fl_GDI_Graphics_Driver::uncache(Fl_RGB_Image*, fl_uintptr_t &id_, fl_uintpt
}
if (mask_) {
- fl_delete_bitmask((Fl_Bitmask)mask_);
+ delete_bitmask(mask_);
mask_ = 0;
}
}
// 'fl_create_bitmap()' - Create a 1-bit bitmap for drawing...
-static Fl_Bitmask fl_create_bitmap(int w, int h, const uchar *data) {
+static HBITMAP fl_create_bitmap(int w, int h, const uchar *data) {
// we need to pad the lines out to words & swap the bits
// in each byte.
int w1 = (w + 7) / 8;
@@ -600,7 +672,7 @@ static Fl_Bitmask fl_create_bitmap(int w, int h, const uchar *data) {
uchar* newarray = new uchar[w2*h];
const uchar* src = data;
uchar* dest = newarray;
- Fl_Bitmask bm;
+ HBITMAP bm;
static uchar reverse[16] = /* Bit reversal lookup table */
{ 0x00, 0x88, 0x44, 0xcc, 0x22, 0xaa, 0x66, 0xee,
0x11, 0x99, 0x55, 0xdd, 0x33, 0xbb, 0x77, 0xff };
@@ -731,8 +803,7 @@ void Fl_GDI_Graphics_Driver::cache(Fl_Pixmap *img) {
fl_draw_pixmap(img->data(), 0, 0, FL_BLACK);
uchar *bitmap = *pbitmap;
if (bitmap) {
- // call fl_create_bitmask here because "this" is not the current graphics driver
- *Fl_Graphics_Driver::mask(img) = (fl_uintptr_t)fl_create_bitmask(img->data_w(), img->data_h(), bitmap);
+ *Fl_Graphics_Driver::mask(img) = (fl_uintptr_t)create_bitmask(img->data_w(), img->data_h(), bitmap);
delete[] bitmap;
}
*pbitmap = 0;
diff --git a/src/drivers/PostScript/Fl_PostScript_Graphics_Driver.H b/src/drivers/PostScript/Fl_PostScript_Graphics_Driver.H
index 5d14e571b..7d8b54dca 100644
--- a/src/drivers/PostScript/Fl_PostScript_Graphics_Driver.H
+++ b/src/drivers/PostScript/Fl_PostScript_Graphics_Driver.H
@@ -248,8 +248,6 @@ public:
void draw_bitmap(Fl_Bitmap * bitmap,int XP, int YP, int WP, int HP, int cx, int cy);
void draw_rgb(Fl_RGB_Image * rgb,int XP, int YP, int WP, int HP, int cx, int cy);
~Fl_PostScript_Graphics_Driver();
- // ---
- Fl_Bitmask create_bitmask(int /*w*/, int /*h*/, const uchar * /*array*/) { return 0L; }
virtual int has_feature(driver_feature feature_mask) { return feature_mask & PRINTER; }
void ps_origin(int x, int y);
diff --git a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.H b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.H
index d604233be..a62fae898 100644
--- a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.H
+++ b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver.H
@@ -65,8 +65,8 @@ public:
char can_do_alpha_blending();
// --- bitmap stuff
- Fl_Bitmask create_bitmask(int w, int h, const uchar *array);
- void delete_bitmask(Fl_Bitmask bm);
+ CGImageRef create_bitmask(int w, int h, const uchar *array); // NOT virtual
+ virtual void delete_bitmask(fl_uintptr_t bm);
void draw_pixmap(Fl_Pixmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy);
void draw_bitmap(Fl_Bitmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy);
void draw_rgb(Fl_RGB_Image *img, int XP, int YP, int WP, int HP, int cx, int cy);
diff --git a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx
index 739e5b2c9..558dc47c1 100644
--- a/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx
+++ b/src/drivers/Quartz/Fl_Quartz_Graphics_Driver_image.cxx
@@ -207,7 +207,7 @@ void Fl_Quartz_Graphics_Driver::draw_pixmap(Fl_Pixmap *pxm, int XP, int YP, int
draw_CGImage(cgimg, X,Y,W,H, cx,cy, pxm->w(), pxm->h());
}
-Fl_Bitmask Fl_Quartz_Graphics_Driver::create_bitmask(int w, int h, const uchar *array) {
+CGImageRef Fl_Quartz_Graphics_Driver::create_bitmask(int w, int h, const uchar *array) {
static uchar reverse[16] = /* Bit reversal lookup table */
{ 0x00, 0x88, 0x44, 0xcc, 0x22, 0xaa, 0x66, 0xee,
0x11, 0x99, 0x55, 0xdd, 0x33, 0xbb, 0x77, 0xff };
@@ -221,10 +221,10 @@ Fl_Bitmask Fl_Quartz_Graphics_Driver::create_bitmask(int w, int h, const uchar *
CGDataProviderRef srcp = CGDataProviderCreateWithData( NULL, bmask, rowBytes*h, dataReleaseCB);
CGImageRef id_ = CGImageMaskCreate( w, h, 1, 1, rowBytes, srcp, 0L, false);
CGDataProviderRelease(srcp);
- return (Fl_Bitmask)id_;
+ return id_;
}
-void Fl_Quartz_Graphics_Driver::delete_bitmask(Fl_Bitmask bm) {
+void Fl_Quartz_Graphics_Driver::delete_bitmask(fl_uintptr_t bm) {
if (bm) CGImageRelease((CGImageRef)bm);
}
diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H
index 807e82b5f..e22d10691 100644
--- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H
+++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver.H
@@ -119,8 +119,8 @@ public:
static int fl_overlay;
// --- bitmap stuff
- Fl_Bitmask create_bitmask(int w, int h, const uchar *array);
- void delete_bitmask(Fl_Bitmask bm);
+ unsigned long create_bitmask(int w, int h, const uchar *array); // NOT virtual
+ virtual void delete_bitmask(fl_uintptr_t bm);
virtual void draw_unscaled(const char* str, int n, int x, int y);
virtual void draw_unscaled(int angle, const char *str, int n, int x, int y);
virtual void rtl_draw_unscaled(const char* str, int n, int x, int y);
diff --git a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx
index 92ee52548..0ea0b0529 100644
--- a/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx
+++ b/src/drivers/Xlib/Fl_Xlib_Graphics_Driver_image.cxx
@@ -613,13 +613,13 @@ void Fl_Xlib_Graphics_Driver::colored_rectf(int x, int y, int w, int h, uchar r,
}
}
-Fl_Bitmask Fl_Xlib_Graphics_Driver::create_bitmask(int w, int h, const uchar *data) {
+unsigned long Fl_Xlib_Graphics_Driver::create_bitmask(int w, int h, const uchar *data) {
return XCreateBitmapFromData(fl_display, fl_window, (const char *)data,
(w+7)&-8, h);
}
-void Fl_Xlib_Graphics_Driver::delete_bitmask(Fl_Bitmask bm) {
- XFreePixmap(fl_display, bm);
+void Fl_Xlib_Graphics_Driver::delete_bitmask(fl_uintptr_t bm) {
+ XFreePixmap(fl_display, (unsigned long)bm);
}
void Fl_Xlib_Graphics_Driver::draw_fixed(Fl_Bitmap *bm, int X, int Y, int W, int H, int cx, int cy) {