summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael R Sweet <michael.r.sweet@gmail.com>2001-12-05 00:19:26 +0000
committerMichael R Sweet <michael.r.sweet@gmail.com>2001-12-05 00:19:26 +0000
commita8f3f02214d1b3b862e7c5217b259b109cac4400 (patch)
tree82cc9a1a698e113a551a1855c292d15f047d7a8e
parent2fbee9c1500a7b3862732bdfa2ad6fef9dcc3092 (diff)
Add support for 2-byte XPM files.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1810 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
-rw-r--r--CHANGES2
-rw-r--r--src/Fl_File_Icon2.cxx42
2 files changed, 24 insertions, 20 deletions
diff --git a/CHANGES b/CHANGES
index e8810a4ce..e9472a3a0 100644
--- a/CHANGES
+++ b/CHANGES
@@ -8,6 +8,8 @@ CHANGES IN FLTK 1.1.0b7
- Fl_File_Icon::load_image() could cause segfaults
(NULL data and incrementing the data pointer too
often.)
+ - Fl_File_Icon::load_image() now handles 2-byte
+ per color XPM files.
- Some Win32 drivers would draw into wrong buffers
after OpenGL mode change.
- Message handling and Resources for MacOS port.
diff --git a/src/Fl_File_Icon2.cxx b/src/Fl_File_Icon2.cxx
index 1f8e77783..1e1c0011b 100644
--- a/src/Fl_File_Icon2.cxx
+++ b/src/Fl_File_Icon2.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Fl_File_Icon2.cxx,v 1.1.2.5 2001/12/05 00:06:41 easysw Exp $"
+// "$Id: Fl_File_Icon2.cxx,v 1.1.2.6 2001/12/05 00:19:26 easysw Exp $"
//
// Fl_File_Icon system icon routines.
//
@@ -410,7 +410,7 @@ Fl_File_Icon::load_image(const char *ifile) // I - File to read from
*const*ptr; // Pointer into data array
int ncolors, // Number of colors
chars_per_color; // Characters per color
- Fl_Color colors[256]; // Colors
+ Fl_Color *colors; // Colors
int red, green, blue; // Red, green, and blue values
int x, y; // X & Y in image
int startx; // Starting X coord
@@ -419,15 +419,11 @@ Fl_File_Icon::load_image(const char *ifile) // I - File to read from
// Get the pixmap data...
ptr = img->data();
sscanf(*ptr, "%*d%*d%d%d", &ncolors, &chars_per_color);
- if (chars_per_color > 1) {
- Fl::warning("Fl_Icon_File::load(): Unable to load 2-byte XPM file \"%s\"!",
- ifile);
- img->release();
- return (-1);
- }
+
+ colors = new Fl_Color[1 << (chars_per_color * 8)];
// Read the colormap...
- memset(colors, 0, sizeof(colors));
+ memset(colors, 0, sizeof(Fl_Color) << (chars_per_color * 8));
bg = ' ';
ptr ++;
@@ -448,6 +444,8 @@ Fl_File_Icon::load_image(const char *ifile) // I - File to read from
lineptr = *ptr;
ch = *lineptr++;
+ if (chars_per_color > 1) ch = (ch << 8) | *lineptr++;
+
// Get the color value...
if ((lineptr = strstr(lineptr, "c ")) == NULL) {
// No color; make this black...
@@ -516,17 +514,18 @@ Fl_File_Icon::load_image(const char *ifile) // I - File to read from
}
// Read the image data...
- for (y = 0; y < img->h(); y ++, ptr ++)
- {
+ for (y = 0; y < img->h(); y ++, ptr ++) {
lineptr = *ptr;
startx = 0;
ch = bg;
- for (x = 0; x < img->w(); x ++, lineptr ++)
- if (*lineptr != ch)
- {
- if (ch != bg)
- {
+ for (x = 0; x < img->w(); x ++) {
+ newch = *lineptr++;
+
+ if (chars_per_color > 1) newch = (newch << 8) | *lineptr++;
+
+ if (newch != ch) {
+ if (ch != bg) {
add_color(colors[ch]);
add(POLYGON);
add_vertex(startx * 9000 / img->w() + 1000, 9500 - y * 9000 / img->h());
@@ -536,12 +535,12 @@ Fl_File_Icon::load_image(const char *ifile) // I - File to read from
add(END);
}
- ch = *lineptr;
+ ch = newch;
startx = x;
}
+ }
- if (ch != bg)
- {
+ if (ch != bg) {
add_color(colors[ch]);
add(POLYGON);
add_vertex(startx * 9000 / img->w() + 1000, 9500 - y * 9000 / img->h());
@@ -551,6 +550,9 @@ Fl_File_Icon::load_image(const char *ifile) // I - File to read from
add(END);
}
}
+
+ // Free the colormap...
+ delete[] colors;
}
img->release();
@@ -923,5 +925,5 @@ get_kde_val(char *str,
//
-// End of "$Id: Fl_File_Icon2.cxx,v 1.1.2.5 2001/12/05 00:06:41 easysw Exp $".
+// End of "$Id: Fl_File_Icon2.cxx,v 1.1.2.6 2001/12/05 00:19:26 easysw Exp $".
//