diff options
Diffstat (limited to 'converter')
-rw-r--r-- | converter/other/fitstopnm.c | 17 |
1 files changed, 17 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; |