summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael R Sweet <michael.r.sweet@gmail.com>2002-05-15 19:42:34 +0000
committerMichael R Sweet <michael.r.sweet@gmail.com>2002-05-15 19:42:34 +0000
commit33f05fa72a6a33fc072963f0523a8a1951716c10 (patch)
tree48ff5f3988a7a5dd7647775252b625ed6851f11d /src
parente217ac0564bea7d20ca69beaad13164e799d8243 (diff)
Fix loading of old BMP files.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@2227 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src')
-rw-r--r--src/Fl_BMP_Image.cxx56
1 files changed, 38 insertions, 18 deletions
diff --git a/src/Fl_BMP_Image.cxx b/src/Fl_BMP_Image.cxx
index 559b1427a..55a91fe66 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.1 2002/01/06 17:51:12 easysw Exp $"
+// "$Id: Fl_BMP_Image.cxx,v 1.1.2.2 2002/05/15 19:42:34 easysw Exp $"
//
// Fl_BMP_Image routines.
//
@@ -75,11 +75,11 @@ Fl_BMP_Image::Fl_BMP_Image(const char *bmp) // I - File to read
count, // Number of times to repeat
temp, // Temporary color
align; // Alignment bytes
+ long offbits; // Offset to image data
uchar bit, // Bit in image
byte; // Byte in image
uchar *ptr; // Pointer into pixels
- uchar colormap[256][4];// Colormap
-
+ uchar colormap[256][3];// Colormap
// Open the file...
if ((fp = fopen(bmp, "rb")) == NULL) return;
@@ -90,30 +90,50 @@ Fl_BMP_Image::Fl_BMP_Image(const char *bmp) // I - File to read
read_dword(fp); // Skip size
read_word(fp); // Skip reserved stuff
read_word(fp);
- read_dword(fp);
+ offbits = read_dword(fp); // Read offset to image data
// Then the bitmap information...
- info_size = read_dword(fp);
+ info_size = read_dword(fp);
w(read_long(fp));
h(read_long(fp));
read_word(fp);
- depth = read_word(fp);
- compression = read_dword(fp);
- read_dword(fp);
- read_long(fp);
- read_long(fp);
- colors_used = read_dword(fp);
- read_dword(fp);
-
- if (info_size > 40)
- for (info_size -= 40; info_size > 0; info_size --)
- getc(fp);
+ depth = read_word(fp);
+
+ if (info_size < 40) {
+ // Old Windows/OS2 BMP header...
+ compression = BI_RGB;
+ colors_used = 0;
+
+ count = info_size - 12;
+ } else {
+ // New BMP header...
+ compression = read_dword(fp);
+ read_dword(fp);
+ read_long(fp);
+ read_long(fp);
+ colors_used = read_dword(fp);
+ read_dword(fp);
+
+ count = info_size - 40;
+ }
+
+ // Skip remaining header bytes...
+ while (count > 0) {
+ getc(fp);
+ count --;
+ }
// Get colormap...
if (colors_used == 0 && depth <= 8)
colors_used = 1 << depth;
- fread(colormap, colors_used, 4, fp);
+ for (count = 0; count < colors_used; count ++) {
+ // Read BGR color...
+ fread(colormap, colors_used, 3, fp);
+
+ // Skip pad byte for new BMP files...
+ if (info_size > 12) getc(fp);
+ }
// Setup image and buffers...
d(3);
@@ -349,5 +369,5 @@ read_long(FILE *fp) { // I - File to read from
//
-// End of "$Id: Fl_BMP_Image.cxx,v 1.1.2.1 2002/01/06 17:51:12 easysw Exp $".
+// End of "$Id: Fl_BMP_Image.cxx,v 1.1.2.2 2002/05/15 19:42:34 easysw Exp $".
//