--- ray/src/px/pvalue.c 2003/02/25 16:22:05 2.15 +++ ray/src/px/pvalue.c 2003/06/05 19:29:34 2.18 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: pvalue.c,v 2.15 2003/02/25 16:22:05 greg Exp $"; +static const char RCSid[] = "$Id: pvalue.c,v 2.18 2003/06/05 19:29:34 schorsch Exp $"; #endif /* * pvalue.c - program to print pixel values. @@ -7,12 +7,10 @@ static const char RCSid[] = "$Id: pvalue.c,v 2.15 2003 * 4/23/86 */ -#include "standard.h" - -#include "color.h" - #include +#include "standard.h" +#include "color.h" #include "resolu.h" typedef unsigned short uint16; /* sizeof (uint16) must == 2 */ @@ -23,8 +21,6 @@ typedef unsigned short uint16; /* sizeof (uint16) must #define ALL 3 #define BRIGHT 4 -#define brightonly (putprim==BRIGHT) - RESOLU picres; /* resolution of picture */ int uniq = 0; /* print only unique values? */ @@ -44,6 +40,8 @@ int header = 1; /* do header? */ long skipbytes = 0; /* skip bytes in input? */ +int swapbytes = 0; /* swap bytes in 16-bit words? */ + int interleave = 1; /* file is interleaved? */ int resolution = 1; /* put/get resolution string? */ @@ -169,6 +167,8 @@ char **argv; format = 'b'; fmtid = "byte"; break; + case 'W': /* 16-bit swapped */ + swapbytes = 1; case 'w': /* 16-bit */ dataonly = 1; format = 'w'; @@ -215,15 +215,15 @@ unkopt: break; /* recognize special formats */ if (dataonly && format == 'b') - if (brightonly) - fmtid = "8-bit_grey"; - else + if (putprim == ALL) fmtid = "24-bit_rgb"; - if (dataonly && format == 'w') - if (brightonly) - fmtid = "16-bit_grey"; else + fmtid = "8-bit_grey"; + if (dataonly && format == 'w') + if (putprim == ALL) fmtid = "48-bit_rgb"; + else + fmtid = "16-bit_grey"; /* assign reverse ordering */ rord[ord[0]] = 0; rord[ord[1]] = 1; @@ -237,7 +237,7 @@ unkopt: progname, argv[i]); quit(1); } - if (reverse && !brightonly && i == argc-3) { + if (reverse && putprim != BRIGHT && i == argc-3) { if ((fin2 = fopen(argv[i+1], "r")) == NULL) { fprintf(stderr, "%s: can't open file \"%s\"\n", progname, argv[i+1]); @@ -251,7 +251,7 @@ unkopt: interleave = -1; } else if (i != argc-1) fin = NULL; - if (reverse && !brightonly && !interleave) { + if (reverse && putprim != BRIGHT && !interleave) { fin2 = fopen(argv[i], "r"); fin3 = fopen(argv[i], "r"); } @@ -269,10 +269,10 @@ unkopt: } if (reverse) { -#ifdef MSDOS - setmode(fileno(stdout), O_BINARY); +#ifdef _WIN32 + SET_FILE_BINARY(stdout); if (format != 'a' && format != 'i') - setmode(fileno(fin), O_BINARY); + SET_FILE_BINARY(fin); #endif /* get header */ if (header) { @@ -317,10 +317,10 @@ unkopt: fputsresolu(&picres, stdout); /* always put resolution */ valtopix(); } else { -#ifdef MSDOS - setmode(fileno(fin), O_BINARY); +#ifdef _WIN32 + SET_FILE_BINARY(fin); if (format != 'a' && format != 'i') - setmode(fileno(stdout), O_BINARY); + SET_FILE_BINARY(stdout); #endif /* get header */ getheader(fin, checkhead, NULL); @@ -509,6 +509,16 @@ int code; } +swap16(wp, n) /* swap n 16-bit words */ +register uint16 *wp; +int n; +{ + while (n-- > 0) { + *wp = *wp << 8 | ((*wp >> 8) & 0xff); + wp++; + } +} + getcascii(col) /* get an ascii color value from stream(s) */ COLOR col; { @@ -620,6 +630,8 @@ COLOR col; fread((char *)(vw+2), sizeof(uint16), 1, fin3) != 1) return(-1); } + if (swapbytes) + swap16(vw, 3); setcolor(col, (vw[rord[RED]]+.5)/65536., (vw[rord[GRN]]+.5)/65536., (vw[rord[BLU]]+.5)/65536.); return(0); @@ -698,6 +710,8 @@ COLOR col; if (fread((char *)&vw, sizeof(uint16), 1, fin) != 1) return(-1); + if (swapbytes) + swap16(&vw, 1); d = (vw+.5)/65536.; setcolor(col, d, d, d); return(0); @@ -786,6 +800,8 @@ COLOR col; vw[1] = min(i,65535); i = colval(col,ord[2])*65536.; vw[2] = min(i,65535); + if (swapbytes) + swap16(vw, 3); fwrite((char *)vw, sizeof(uint16), 3, stdout); return(ferror(stdout) ? -1 : 0); @@ -856,6 +872,8 @@ COLOR col; i = (*mybright)(col)*65536.; vw = min(i,65535); + if (swapbytes) + swap16(&vw, 1); fwrite((char *)&vw, sizeof(uint16), 1, stdout); return(ferror(stdout) ? -1 : 0); @@ -926,6 +944,8 @@ COLOR col; i = colval(col,putprim)*65536.; vw = min(i,65535); + if (swapbytes) + swap16(&vw, 1); fwrite((char *)&vw, sizeof(uint16), 1, stdout); return(ferror(stdout) ? -1 : 0);