about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2016-05-08 22:24:06 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2016-05-08 22:24:06 +0000
commit7a0dbb463c55783da12c0d25aaebf6f234a8e457 (patch)
tree43ac01de67af27d2bb6cf080969a0235894b4e73
parentc8c9f47432488ff8a25c446f3f2a244b455659da (diff)
downloadnetpbm-mirror-7a0dbb463c55783da12c0d25aaebf6f234a8e457.tar.gz
netpbm-mirror-7a0dbb463c55783da12c0d25aaebf6f234a8e457.tar.xz
netpbm-mirror-7a0dbb463c55783da12c0d25aaebf6f234a8e457.zip
cleanup
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@2769 9d0c8265-081b-0410-96cb-a4ca84ce46f8
-rw-r--r--converter/bmp.h56
-rw-r--r--converter/other/bmptopnm.c7
-rw-r--r--converter/ppm/ppmtobmp.c10
3 files changed, 56 insertions, 17 deletions
diff --git a/converter/bmp.h b/converter/bmp.h
index 803958c9..f2355929 100644
--- a/converter/bmp.h
+++ b/converter/bmp.h
@@ -85,6 +85,21 @@
 
 enum bmpClass {C_WIN, C_OS2};
 
+static __inline__ const char *
+BMPClassName(enum bmpClass const class) {
+
+    const char * name;
+
+    switch (class) {
+    case C_OS2: name = "OS/2 (v1)";    break;
+    case C_WIN: name = "Windows (v1)"; break;
+    }
+
+  return name;
+}
+
+
+
 static char const er_internal[] = "%s: internal error!";
 
 /* Values of the "compression" field of the BMP info header */
@@ -114,27 +129,46 @@ BMPCompTypeName(BMPCompType const compression) {
 
 
 static __inline__ unsigned int
-BMPlenfileheader(enum bmpClass const class) {
+BMPlenfileheader(void) {
 
-    unsigned int retval;
-
-    switch (class) {
-    case C_WIN: retval = 14; break;
-    case C_OS2: retval = 14; break;
-    }
-    return retval;
+    return 14;
 }
 
 
 
+enum BMPinfoHeaderLen {
+/*----------------------------------------------------------------------------
+   BMPs come in various kinds, distinguished by the length of their
+   info header, which is the first field in that header.
+
+   These are those lengths.
+-----------------------------------------------------------------------------*/
+    BMP_HDRLEN_OS2_1x =  12,
+        /* BITMAPCOREHEADER; since Windows 2.0, OS/2 1.x */
+    BMP_HDRLEN_OS2_2x =  64,
+        /* not documented by Microsoft; since OS/2 2.x */
+    BMP_HDRLEN_WIN_V1 =  40,
+        /* BITMAPINFOHEADER; since Windows NT 3, Windows 3.x */
+    BMP_HDRLEN_WIN_V2 =  52,
+        /* not documented by Microsoft */
+    BMP_HDRLEN_WIN_V3 =  56,
+        /* not documented by Microsoft */
+    BMP_HDRLEN_WIN_V4 = 108,
+        /* BITMAPV4HEADER; since Windows NT 4, Windows 95 */
+    BMP_HDRLEN_WIN_V5 = 124
+        /* BITMAPV5HEADER; since Windows 2000, Windows 98 */
+};
+
+
+
 static __inline__ unsigned int
 BMPleninfoheader(enum bmpClass const class) {
 
     unsigned int retval;
 
     switch (class) {
-    case C_WIN: retval = 40; break;
-    case C_OS2: retval = 12; break;
+    case C_WIN: retval = BMP_HDRLEN_WIN_V1; break;
+    case C_OS2: retval = BMP_HDRLEN_OS2_1x; break;
     }
     return retval;
 }
@@ -231,7 +265,7 @@ BMPoffbits(enum bmpClass const class,
 /*----------------------------------------------------------------------------
   return the offset to the BMP image bits.
 -----------------------------------------------------------------------------*/
-    return BMPlenfileheader(class)
+    return BMPlenfileheader()
         + BMPleninfoheader(class)
         + BMPlencolormap(class, bitcount, cmapsize);
 }
diff --git a/converter/other/bmptopnm.c b/converter/other/bmptopnm.c
index c5a77c2d..d57bfba9 100644
--- a/converter/other/bmptopnm.c
+++ b/converter/other/bmptopnm.c
@@ -266,6 +266,8 @@ bmpReadfileheader(FILE *         const ifP,
 
     *offBitsP = offBits;
 
+    assert(BMPlenfileheader() == 14);
+
     *bytesReadP = 14;
 }
 
@@ -1191,10 +1193,7 @@ reportHeader(struct bmpInfoHeader const header,
              unsigned int         const offBits) {
              
     pm_message("BMP image header says:");
-    pm_message("  Class of BMP: %s", 
-               header.class == C_WIN ? "Windows" : 
-               header.class == C_OS2 ? "OS/2" :
-               "???");
+    pm_message("  Class of BMP: %s", BMPClassName(header.class));
     pm_message("  Width: %d pixels", header.cols);
     pm_message("  Height: %d pixels", header.rows);
     pm_message("  Depth: %d planes", header.cPlanes);
diff --git a/converter/ppm/ppmtobmp.c b/converter/ppm/ppmtobmp.c
index 802f530f..dc053f05 100644
--- a/converter/ppm/ppmtobmp.c
+++ b/converter/ppm/ppmtobmp.c
@@ -208,6 +208,8 @@ BMPwritefileheader(FILE *        const fp,
     
     /* offBits */
     PutLong(fp, offBits);
+
+    assert(BMPlenfileheader() == 14);
     
     return 14;
 }
@@ -229,7 +231,7 @@ BMPwriteinfoheader(FILE *        const fp,
 
     switch (class) {
     case C_WIN: {
-        cbFix = 40;
+        cbFix = BMP_HDRLEN_WIN_V1;
         PutLong(fp, cbFix);
 
         PutLong(fp, x);         /* cx */
@@ -248,16 +250,20 @@ BMPwriteinfoheader(FILE *        const fp,
         PutLong(fp, 0);   /* YpixelsPerMeter */
         PutLong(fp, 0);   /* ColorsUsed */
         PutLong(fp, 0);   /* ColorsImportant */
+
+        assert(BMP_HDRLEN_OS2_1x == 40);  /* We wrote 40 bytes */
     }
     break;
     case C_OS2: {
-        cbFix = 12;
+        cbFix = BMP_HDRLEN_OS2_1x;
         PutLong(fp, cbFix);
 
         PutShort(fp, x);        /* cx */
         PutShort(fp, y);        /* cy */
         PutShort(fp, 1);        /* cPlanes */
         PutShort(fp, bitcount); /* cBitCount */
+
+        assert(BMP_HDRLEN_OS2_1x == 12);  /* We wrote 12 bytes */
     }
     break;
     }