diff options
| author | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2022-03-24 10:00:01 +0100 |
|---|---|---|
| committer | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2022-03-24 10:00:01 +0100 |
| commit | 427e4dbc7a31407f3e8ca80f2dd2a84869af4b3d (patch) | |
| tree | e22d843aa4ab0760d69f4195ed4e3615e416e409 /src/drivers/GDI | |
| parent | 70f61a63f4cc6ff53d8d6e7c60dd21ff71b9414e (diff) | |
Remove platform-dependent type Fl_Bitmask (not in documented public API).
Diffstat (limited to 'src/drivers/GDI')
| -rw-r--r-- | src/drivers/GDI/Fl_GDI_Graphics_Driver.H | 5 | ||||
| -rw-r--r-- | src/drivers/GDI/Fl_GDI_Graphics_Driver_image.cxx | 91 |
2 files changed, 84 insertions, 12 deletions
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; |
