about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--converter/other/fitstopnm.c17
-rw-r--r--doc/HISTORY3
2 files changed, 20 insertions, 0 deletions
diff --git a/converter/other/fitstopnm.c b/converter/other/fitstopnm.c
index 9df47be3..b41e0960 100644
--- a/converter/other/fitstopnm.c
+++ b/converter/other/fitstopnm.c
@@ -43,6 +43,7 @@
 #include "mallocvar.h"
 #include "shhopt.h"
 #include "pnm.h"
+#include "pm_config.h"
 
 
 
@@ -155,6 +156,20 @@ struct FITS_Header {
 };
 
 
+static void
+swapbytes(void *       const p,
+          unsigned int const nbytes) {
+#if BYTE_ORDER == LITTLE_ENDIAN
+    unsigned char * const c = p;
+    unsigned int i;
+    for (i = 0; i < nbytes/2; ++i) {
+        unsigned char const orig = c[i];
+        c[i] = c[nbytes-(i+1)];
+        c[nbytes-(i+1)] = orig;
+    }
+#endif
+}
+
 
 /*
  ** This code will deal properly with integers, no matter what the byte order
@@ -227,6 +242,7 @@ readVal(FILE *   const ifP,
                 pm_error("EOF / read error");
             c[i] = ich;
         }
+        swapbytes(c, 4);
         *vP = *((float *)c);
     } break;
       
@@ -240,6 +256,7 @@ readVal(FILE *   const ifP,
                 pm_error("EOF / read error");
             c[i] = ich;
         }
+        swapbytes(c, 8);
         *vP = *((double *)c);
     } break;
       
diff --git a/doc/HISTORY b/doc/HISTORY
index 7ec012d4..5f45a390 100644
--- a/doc/HISTORY
+++ b/doc/HISTORY
@@ -11,6 +11,9 @@ not yet  BJH  Release 10.46.00
               pnmcut: finally make it just an alias of pamcut, which
               obsoleted it in 9.20.
 
+              fitstopnm: fix garbage output when input is little endian
+              floating point FITS.
+
               picttoppm: Fix crash with -fullres and all-text PICT image.
               Also issue warning that program omits text with -fullres.