From 13e7d7639729cc0fb9b778ecd2e45d407d45d393 Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Mon, 19 Nov 2001 20:59:59 +0000 Subject: WIN32 fixes for the new image stuff... git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1705 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/Fl_Bitmap.cxx | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- src/Fl_Image.cxx | 10 +++--- src/Fl_Pixmap.cxx | 18 +++++----- src/Fl_win32.cxx | 5 ++- src/fl_draw.cxx | 6 ++-- 5 files changed, 113 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/Fl_Bitmap.cxx b/src/Fl_Bitmap.cxx index 18d474fb7..887d57603 100644 --- a/src/Fl_Bitmap.cxx +++ b/src/Fl_Bitmap.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Bitmap.cxx,v 1.5.2.4.2.3 2001/11/19 01:06:45 easysw Exp $" +// "$Id: Fl_Bitmap.cxx,v 1.5.2.4.2.4 2001/11/19 20:59:59 easysw Exp $" // // Bitmap drawing routines for the Fast Light Tool Kit (FLTK). // @@ -32,7 +32,94 @@ #include #ifdef WIN32 // Windows bitmask functions... +// 'fl_create_bitmap()' - Create a 1-bit bitmap for drawing... +static Fl_Bitmask 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; + int w2 = ((w+15)/16)*2; + uchar* newarray = new uchar[w2*h]; + const uchar* src = data; + uchar* dest = newarray; + Fl_Bitmask id; + static uchar reverse[16] = /* Bit reversal lookup table */ + { 0x00, 0x88, 0x44, 0xcc, 0x22, 0xaa, 0x66, 0xee, + 0x11, 0x99, 0x55, 0xdd, 0x33, 0xbb, 0x77, 0xff }; + + for (int y=0; y < h; y++) { + for (int n = 0; n < w1; n++, src++) + *dest++ = (reverse[*src & 0x0f] & 0xf0) | + (reverse[(*src >> 4) & 0x0f] & 0x0f); + dest += w2-w1; + } + + id = CreateBitmap(w, h, 1, 1, newarray); + + delete[] newarray; + + return id; +} + +// 'fl_create_bitmask()' - Create an N-bit bitmap for masking... Fl_Bitmask fl_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 id; + static uchar hiNibble[16] = + { 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, + 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0 }; + static uchar loNibble[16] = + { 0x00, 0x08, 0x04, 0x0c, 0x02, 0x0a, 0x06, 0x0e, + 0x01, 0x09, 0x05, 0x0d, 0x03, 0x0b, 0x07, 0x0f }; + int np = GetDeviceCaps(fl_gc, PLANES); //: was always one on sample machines + int bpp = GetDeviceCaps(fl_gc, BITSPIXEL);//: 1,4,8,16,24,32 and more odd stuff? + int Bpr = (bpp*w+7)/8; //: bytes per row + int pad = Bpr&1, w1 = (w+7)/8, shr = ((w-1)&7)+1; + if (bpp==4) shr = (shr+1)/2; + uchar *newarray = new uchar[(Bpr+pad)*h]; + uchar *dst = newarray; + const uchar *src = data; + + for (int i=0; i0; j--) { + uchar b = *src++; + if (bpp==1) { + *dst++ = ( hiNibble[b&15] ) | ( loNibble[(b>>4)&15] ); + } else if (bpp==4) { + for (int k=(j==1)?shr:4; k>0; k--) { + *dst++ = "\377\360\017\000"[b&3]; + b = b >> 2; + } + } else { + for (int k=(j==1)?shr:8; k>0; k--) { + if (b&1) { + *dst++=0; + if (bpp>8) *dst++=0; + if (bpp>16) *dst++=0; + if (bpp>24) *dst++=0; + } else { + *dst++=0xff; + if (bpp>8) *dst++=0xff; + if (bpp>16) *dst++=0xff; + if (bpp>24) *dst++=0xff; + } + + b = b >> 1; + } + } + } + + dst += pad; + } + + id = CreateBitmap(w, h, np, bpp, newarray); + delete[] newarray; + + return id; +} + +Fl_Bitmask fl_create_bitmask(int w, int h, const uchar *data, int for_mask) { // we need to pad the lines out to words & swap the bits // in each byte. int w1 = (w+7)/8; @@ -84,9 +171,9 @@ void Fl_Bitmap::draw(int XP, int YP, int WP, int HP, int cx, int cy) { if (cy < 0) {H += cy; Y -= cy; cy = 0;} if ((cy+H) > h()) H = h()-cy; if (H <= 0) return; - if (!id) id = fl_create_bitmask(w(), h(), array); - #ifdef WIN32 + if (!id) id = fl_create_bitmap(w(), h(), array); + HDC tempdc = CreateCompatibleDC(fl_gc); SelectObject(tempdc, (HGDIOBJ)id); SelectObject(fl_gc, fl_brush()); @@ -94,6 +181,8 @@ void Fl_Bitmap::draw(int XP, int YP, int WP, int HP, int cx, int cy) { BitBlt(fl_gc, X, Y, W, H, tempdc, cx, cy, 0xE20746L); DeleteDC(tempdc); #else + if (!id) id = fl_create_bitmask(w(), h(), array); + XSetStipple(fl_display, fl_gc, id); int ox = X-cx; if (ox < 0) ox += w(); int oy = Y-cy; if (oy < 0) oy += h(); @@ -106,7 +195,7 @@ void Fl_Bitmap::draw(int XP, int YP, int WP, int HP, int cx, int cy) { Fl_Bitmap::~Fl_Bitmap() { if (id) fl_delete_bitmask(id); - if (alloc_array) delete[] array; + if (alloc_array) delete[] (uchar *)array; } void Fl_Bitmap::label(Fl_Widget* w) { @@ -184,5 +273,5 @@ Fl_Image *Fl_Bitmap::copy(int W, int H) { } // -// End of "$Id: Fl_Bitmap.cxx,v 1.5.2.4.2.3 2001/11/19 01:06:45 easysw Exp $". +// End of "$Id: Fl_Bitmap.cxx,v 1.5.2.4.2.4 2001/11/19 20:59:59 easysw Exp $". // diff --git a/src/Fl_Image.cxx b/src/Fl_Image.cxx index 3663e4224..3359f5057 100644 --- a/src/Fl_Image.cxx +++ b/src/Fl_Image.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Image.cxx,v 1.5.2.3.2.3 2001/11/19 01:06:45 easysw Exp $" +// "$Id: Fl_Image.cxx,v 1.5.2.3.2.4 2001/11/19 20:59:59 easysw Exp $" // // Image drawing code for the Fast Light Tool Kit (FLTK). // @@ -58,7 +58,7 @@ void Fl_Image::label(Fl_Menu_Item* m) { Fl_RGB_Image::~Fl_RGB_Image() { if (id) fl_delete_offscreen((Fl_Offscreen)id); - if (alloc_array) delete[] array; + if (alloc_array) delete[] (uchar *)array; } Fl_Image *Fl_RGB_Image::copy(int W, int H) { @@ -212,7 +212,7 @@ void Fl_RGB_Image::desaturate() { } // Free the old array as needed, and then set the new pointers/values... - if (alloc_array) delete[] array; + if (alloc_array) delete[] (uchar *)array; array = new_array; alloc_array = 1; @@ -232,7 +232,7 @@ void Fl_RGB_Image::draw(int XP, int YP, int WP, int HP, int cx, int cy) { if (cy+H > h()) H = h()-cy; if (H <= 0) return; if (!id) { - id = (ulong)fl_create_offscreen(w(), h()); + id = fl_create_offscreen(w(), h()); fl_begin_offscreen((Fl_Offscreen)id); fl_draw_image(array, 0, 0, w(), h(), d, ld); fl_end_offscreen(); @@ -394,5 +394,5 @@ void Fl_RGB_Image::label(Fl_Menu_Item* m) { // -// End of "$Id: Fl_Image.cxx,v 1.5.2.3.2.3 2001/11/19 01:06:45 easysw Exp $". +// End of "$Id: Fl_Image.cxx,v 1.5.2.3.2.4 2001/11/19 20:59:59 easysw Exp $". // diff --git a/src/Fl_Pixmap.cxx b/src/Fl_Pixmap.cxx index 67a584238..0b3717f45 100644 --- a/src/Fl_Pixmap.cxx +++ b/src/Fl_Pixmap.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Pixmap.cxx,v 1.9.2.4.2.4 2001/11/19 01:06:45 easysw Exp $" +// "$Id: Fl_Pixmap.cxx,v 1.9.2.4.2.5 2001/11/19 20:59:59 easysw Exp $" // // Pixmap drawing code for the Fast Light Tool Kit (FLTK). // @@ -82,7 +82,7 @@ void Fl_Pixmap::draw(int XP, int YP, int WP, int HP, int cx, int cy) { mask = fl_create_bitmask(w(), h(), bitmap); #if 0 // Don't think this is needed; try using fl_create_bitmask()... #ifdef WIN32 // Matt: mask done - // this won't work ehen the user changes display mode during run or + // this won't work when the user changes display mode during run or // has two screens with differnet depths static uchar hiNibble[16] = { 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, @@ -387,7 +387,7 @@ void Fl_Pixmap::color_average(Fl_Color c, float i) { } #ifdef WIN32 - if (fl_parse_color(p, r, g, b) { + if (fl_parse_color(p, r, g, b)) { #else XColor x; if (XParseColor(fl_display, fl_colormap, p, &x)) { @@ -405,7 +405,7 @@ void Fl_Pixmap::color_average(Fl_Color c, float i) { data[color + 1][1], r, g, b); else sprintf(line, "%c c #%02X%02X%02X", data[color + 1][0], r, g, b); - delete[] data[color + 1]; + delete[] (char *)data[color + 1]; ((char **)data)[color + 1] = new char[strlen(line) + 1]; strcpy((char *)data[color + 1], line); } @@ -415,8 +415,8 @@ void Fl_Pixmap::color_average(Fl_Color c, float i) { void Fl_Pixmap::delete_data() { if (alloc_data) { - for (int i = 0; data[i]; i ++) delete[] data[i]; - delete[] data; + for (int i = 0; data[i]; i ++) delete[] (char *)data[i]; + delete[] (char **)data; } } @@ -471,7 +471,7 @@ void Fl_Pixmap::desaturate() { } #ifdef WIN32 - if (fl_parse_color(p, r, g, b) { + if (fl_parse_color(p, r, g, b)) { #else XColor x; if (XParseColor(fl_display, fl_colormap, p, &x)) { @@ -486,7 +486,7 @@ void Fl_Pixmap::desaturate() { data[i + 1][1], g, g, g); else sprintf(line, "%c c #%02X%02X%02X", data[i + 1][0], g, g, g); - delete[] data[i + 1]; + delete[] (char *)data[i + 1]; ((char **)data)[i + 1] = new char[strlen(line) + 1]; strcpy((char *)data[i + 1], line); } @@ -495,5 +495,5 @@ void Fl_Pixmap::desaturate() { } // -// End of "$Id: Fl_Pixmap.cxx,v 1.9.2.4.2.4 2001/11/19 01:06:45 easysw Exp $". +// End of "$Id: Fl_Pixmap.cxx,v 1.9.2.4.2.5 2001/11/19 20:59:59 easysw Exp $". // diff --git a/src/Fl_win32.cxx b/src/Fl_win32.cxx index a2f59b7b4..800374362 100644 --- a/src/Fl_win32.cxx +++ b/src/Fl_win32.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_win32.cxx,v 1.33.2.37.2.6 2001/10/29 21:59:15 easysw Exp $" +// "$Id: Fl_win32.cxx,v 1.33.2.37.2.7 2001/11/19 20:59:59 easysw Exp $" // // WIN32-specific code for the Fast Light Tool Kit (FLTK). // @@ -659,7 +659,6 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar #endif default: - DEFAULT: if (Fl::handle(0,0)) return 0; break; } @@ -1006,5 +1005,5 @@ void Fl_Window::make_current() { } // -// End of "$Id: Fl_win32.cxx,v 1.33.2.37.2.6 2001/10/29 21:59:15 easysw Exp $". +// End of "$Id: Fl_win32.cxx,v 1.33.2.37.2.7 2001/11/19 20:59:59 easysw Exp $". // diff --git a/src/fl_draw.cxx b/src/fl_draw.cxx index 2334941a5..107ea08ee 100644 --- a/src/fl_draw.cxx +++ b/src/fl_draw.cxx @@ -1,5 +1,5 @@ // -// "$Id: fl_draw.cxx,v 1.6.2.4.2.6 2001/11/03 05:11:34 easysw Exp $" +// "$Id: fl_draw.cxx,v 1.6.2.4.2.7 2001/11/19 20:59:59 easysw Exp $" // // Label drawing code for the Fast Light Tool Kit (FLTK). // @@ -30,6 +30,7 @@ // Expands all unprintable characters to ^X or \nnn notation // Aligns them against the inside of the box. +#define min(a,b) ((a)<(b)?(a):(b)) #include #include @@ -37,7 +38,6 @@ #include #define MAXBUF 1024 -#define min(a,b) ((a)<(b)?(a):(b)) char fl_draw_shortcut; // set by fl_labeltypes.cxx @@ -327,5 +327,5 @@ void fl_measure(const char* str, int& w, int& h, int draw_symbols) { } // -// End of "$Id: fl_draw.cxx,v 1.6.2.4.2.6 2001/11/03 05:11:34 easysw Exp $". +// End of "$Id: fl_draw.cxx,v 1.6.2.4.2.7 2001/11/19 20:59:59 easysw Exp $". // -- cgit v1.2.3