summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael R Sweet <michael.r.sweet@gmail.com>2002-06-24 02:04:54 +0000
committerMichael R Sweet <michael.r.sweet@gmail.com>2002-06-24 02:04:54 +0000
commitbb056f78056e107d3ca25cb2c0d6bc99835edcaa (patch)
tree9ae01fb6e95b02fc80b9f93d225f2fd874caaade /src
parent04f6fbbe037c519f91cb0035e17b04ff4b9b805f (diff)
Update GCC test in configure script.
Add range checking to BMP loader, and fix colormap + 4-bit BMP file loading. Copy 2.0 window position fix for XFree86 4.x and others. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@2315 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
-rw-r--r--src/Fl_BMP_Image.cxx110
-rw-r--r--src/Fl_x.cxx44
2 files changed, 89 insertions, 65 deletions
diff --git a/src/Fl_BMP_Image.cxx b/src/Fl_BMP_Image.cxx
index 9df36f8c2..ed8ea6e00 100644
--- a/src/Fl_BMP_Image.cxx
+++ b/src/Fl_BMP_Image.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_BMP_Image.cxx,v 1.1.2.6 2002/06/13 18:18:33 easysw Exp $"
+// "$Id: Fl_BMP_Image.cxx,v 1.1.2.7 2002/06/24 02:04:54 easysw Exp $"
//
// Fl_BMP_Image routines.
//
@@ -85,8 +85,13 @@ Fl_BMP_Image::Fl_BMP_Image(const char *bmp) // I - File to read
if ((fp = fopen(bmp, "rb")) == NULL) return;
// Get the header...
- getc(fp); // Skip "BM" sync chars
- getc(fp);
+ byte = getc(fp); // Check "BM" sync chars
+ bit = getc(fp);
+ if (byte != 'B' || bit != 'M') {
+ fclose(fp);
+ return;
+ }
+
read_dword(fp); // Skip size
read_word(fp); // Skip reserved stuff
read_word(fp);
@@ -95,6 +100,8 @@ Fl_BMP_Image::Fl_BMP_Image(const char *bmp) // I - File to read
// Then the bitmap information...
info_size = read_dword(fp);
+// printf("offbits = %ld, info_size = %d\n", offbits, info_size);
+
if (info_size < 40) {
// Old Windows/OS2 BMP header...
w(read_word(fp));
@@ -121,19 +128,28 @@ Fl_BMP_Image::Fl_BMP_Image(const char *bmp) // I - File to read
count = info_size - 40;
}
+// printf("w() = %d, h() = %d, depth = %d, compression = %d, colors_used = %d, count = %d\n",
+// w(), h(), depth, compression, colors_used, count);
+
// Skip remaining header bytes...
while (count > 0) {
getc(fp);
count --;
}
+ // Check header data...
+ if (!w() || !h() || !depth) {
+ fclose(fp);
+ return;
+ }
+
// Get colormap...
if (colors_used == 0 && depth <= 8)
colors_used = 1 << depth;
for (count = 0; count < colors_used; count ++) {
// Read BGR color...
- fread(colormap[count], colors_used, 3, fp);
+ fread(colormap[count], 1, 3, fp);
// Skip pad byte for new BMP files...
if (info_size > 12) getc(fp);
@@ -141,7 +157,7 @@ Fl_BMP_Image::Fl_BMP_Image(const char *bmp) // I - File to read
// Setup image and buffers...
d(3);
- fseek(fp, offbits, SEEK_SET);
+ if (offbits) fseek(fp, offbits, SEEK_SET);
array = new uchar[w() * h() * d()];
alloc_array = 1;
@@ -187,58 +203,60 @@ Fl_BMP_Image::Fl_BMP_Image(const char *bmp) // I - File to read
case 4 : // 16-color
for (x = w(), bit = 0xf0; x > 0; x --) {
// Get a new count as needed...
- if (compression != BI_RLE4 && count == 0) {
- count = 2;
- color = -1;
- }
-
if (count == 0) {
- while (align > 0) {
- align --;
- getc(fp);
- }
+ if (compression != BI_RLE4) {
+ count = 2;
+ color = -1;
+ } else {
+ while (align > 0) {
+ align --;
+ getc(fp);
+ }
- if ((count = getc(fp)) == 0) {
if ((count = getc(fp)) == 0) {
- // End of line...
- x ++;
- continue;
- } else if (count == 1) {
- // End of image...
- break;
- } else if (count == 2) {
- // Delta...
- count = getc(fp) * getc(fp) * w();
- color = 0;
+ if ((count = getc(fp)) == 0) {
+ // End of line...
+ x ++;
+ continue;
+ } else if (count == 1) {
+ // End of image...
+ break;
+ } else if (count == 2) {
+ // Delta...
+ count = getc(fp) * getc(fp) * w();
+ color = 0;
+ } else {
+ // Absolute...
+ color = -1;
+ align = ((4 - (count & 3)) / 2) & 1;
+ }
} else {
- // Absolute...
- color = -1;
- align = ((4 - (count & 3)) / 2) & 1;
+ color = getc(fp);
}
- } else {
- color = getc(fp);
}
- }
+ }
// Get a new color as needed...
count --;
+ // Get the next color byte as needed...
+ if (color < 0) color = getc(fp);
+
+ // Extract the next pixel...
if (bit == 0xf0) {
- if (color < 0) temp = getc(fp);
- else temp = color;
-
- // Copy the color value...
- *ptr++ = colormap[temp >> 4][2];
- *ptr++ = colormap[temp >> 4][1];
- *ptr++ = colormap[temp >> 4][0];
- bit = 0x0f;
- } else {
- // Copy the color value...
- *ptr++ = colormap[temp & 15][2];
- *ptr++ = colormap[temp & 15][1];
- *ptr++ = colormap[temp & 15][0];
- bit = 0xf0;
+ temp = (color >> 4) & 15;
+ bit = 0x0f;
+ } else {
+ temp = color & 15;
+ bit = 0xf0;
}
+
+// printf("temp = %d\n", temp);
+
+ // Copy the color value...
+ *ptr++ = colormap[temp][2];
+ *ptr++ = colormap[temp][1];
+ *ptr++ = colormap[temp][0];
}
if (!compression) {
@@ -375,5 +393,5 @@ read_long(FILE *fp) { // I - File to read from
//
-// End of "$Id: Fl_BMP_Image.cxx,v 1.1.2.6 2002/06/13 18:18:33 easysw Exp $".
+// End of "$Id: Fl_BMP_Image.cxx,v 1.1.2.7 2002/06/24 02:04:54 easysw Exp $".
//
diff --git a/src/Fl_x.cxx b/src/Fl_x.cxx
index cdb4f8c84..483802e27 100644
--- a/src/Fl_x.cxx
+++ b/src/Fl_x.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_x.cxx,v 1.24.2.24.2.21 2002/05/25 13:38:25 easysw Exp $"
+// "$Id: Fl_x.cxx,v 1.24.2.24.2.22 2002/06/24 02:04:54 easysw Exp $"
//
// X specific code for the Fast Light Tool Kit (FLTK).
//
@@ -693,10 +693,6 @@ int fl_handle(const XEvent& xevent)
}
break;}
- case MapNotify:
- event = FL_SHOW;
- break;
-
case UnmapNotify:
event = FL_HIDE;
break;
@@ -858,21 +854,31 @@ int fl_handle(const XEvent& xevent)
fl_xmousewin = 0;
break;
+ // We cannot rely on the x,y position in the configure notify event.
+ // I now think this is an unavoidable problem with X: it is impossible
+ // for a window manager to prevent the "real" notify event from being
+ // sent when it resizes the contents, even though it can send an
+ // artificial event with the correct position afterwards (and some
+ // window managers do not send this fake event anyway)
+ // So anyway, do a round trip to find the correct x,y:
+ case MapNotify:
+ event = FL_SHOW;
+
case ConfigureNotify: {
- // We cannot rely on the x,y position in the configure notify event.
- // I now think this is an unavoidable problem with X: it is impossible
- // for a window manager to prevent the "real" notify event from being
- // sent when it resizes the contents, even though it can send an
- // artificial event with the correct position afterwards (and some
- // window managers do not send this fake event anyway)
- // So anyway, do a round trip to find the correct x,y:
- Window r, c; int X, Y, wX, wY; unsigned int m;
- XQueryPointer(fl_display, fl_xid(window), &r, &c, &X, &Y, &wX, &wY, &m);
- resize_bug_fix = window;
- window->resize(X-wX, Y-wY,
- xevent.xconfigure.width, xevent.xconfigure.height);
- return 1;}
+ if (window->parent()) break; // ignore child windows
+ // figure out where OS really put window
+ XWindowAttributes actual;
+ XGetWindowAttributes(fl_display, fl_xid(window), &actual);
+ Window cr; int X, Y, W = actual.width, H = actual.height;
+ XTranslateCoordinates(fl_display, fl_xid(window), actual.root,
+ 0, 0, &X, &Y, &cr);
+
+ // tell Fl_Window about it and set flag to prevent echoing:
+ resize_bug_fix = window;
+ window->resize(X, Y, W, H);
+ break; // allow add_handler to do something too
+ }
}
return Fl::handle(event, window);
@@ -1227,5 +1233,5 @@ void Fl_Window::make_current() {
#endif
//
-// End of "$Id: Fl_x.cxx,v 1.24.2.24.2.21 2002/05/25 13:38:25 easysw Exp $".
+// End of "$Id: Fl_x.cxx,v 1.24.2.24.2.22 2002/06/24 02:04:54 easysw Exp $".
//