diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2009-01-24 18:14:24 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2009-01-24 18:14:24 +0000 |
commit | 914aa66f02258b05ded20281a4fd26ce8d9fe7c2 (patch) | |
tree | 73844711de7cf31f8a7eee0f46c9dc0ea5c7a00c /converter/other | |
parent | add5f8a273d879c2bf6e83a60ec5fd46af90bae7 (diff) | |
download | netpbm-mirror-914aa66f02258b05ded20281a4fd26ce8d9fe7c2.tar.gz netpbm-mirror-914aa66f02258b05ded20281a4fd26ce8d9fe7c2.tar.xz netpbm-mirror-914aa66f02258b05ded20281a4fd26ce8d9fe7c2.zip |
Fix garbage output when input is little endian floating point FITS
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@825 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter/other')
-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; |