1 |
|
#ifndef lint |
2 |
< |
static const char RCSid[] = "$Id$"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
4 |
|
/* |
5 |
|
* pvalue.c - program to print pixel values. |
7 |
|
* 4/23/86 |
8 |
|
*/ |
9 |
|
|
10 |
– |
#include "standard.h" |
11 |
– |
|
12 |
– |
#include "color.h" |
13 |
– |
|
10 |
|
#include <time.h> |
11 |
|
|
12 |
+ |
#include "standard.h" |
13 |
+ |
#include "platform.h" |
14 |
+ |
#include "color.h" |
15 |
|
#include "resolu.h" |
16 |
|
|
18 |
– |
typedef unsigned short uint16; /* sizeof (uint16) must == 2 */ |
19 |
– |
|
17 |
|
#define min(a,b) ((a)<(b)?(a):(b)) |
18 |
|
|
19 |
|
/* what to put out (also RED, GRN, BLU) */ |
20 |
|
#define ALL 3 |
21 |
|
#define BRIGHT 4 |
22 |
|
|
26 |
– |
#define brightonly (putprim==BRIGHT) |
27 |
– |
|
23 |
|
RESOLU picres; /* resolution of picture */ |
24 |
|
|
25 |
|
int uniq = 0; /* print only unique values? */ |
39 |
|
|
40 |
|
long skipbytes = 0; /* skip bytes in input? */ |
41 |
|
|
42 |
+ |
int swapbytes = 0; /* swap bytes in 16-bit words? */ |
43 |
+ |
|
44 |
|
int interleave = 1; /* file is interleaved? */ |
45 |
|
|
46 |
|
int resolution = 1; /* put/get resolution string? */ |
166 |
|
format = 'b'; |
167 |
|
fmtid = "byte"; |
168 |
|
break; |
169 |
+ |
case 'W': /* 16-bit swapped */ |
170 |
+ |
swapbytes = 1; |
171 |
|
case 'w': /* 16-bit */ |
172 |
|
dataonly = 1; |
173 |
|
format = 'w'; |
214 |
|
break; |
215 |
|
/* recognize special formats */ |
216 |
|
if (dataonly && format == 'b') |
217 |
< |
if (brightonly) |
219 |
< |
fmtid = "8-bit_grey"; |
220 |
< |
else |
217 |
> |
if (putprim == ALL) |
218 |
|
fmtid = "24-bit_rgb"; |
222 |
– |
if (dataonly && format == 'w') |
223 |
– |
if (brightonly) |
224 |
– |
fmtid = "16-bit_grey"; |
219 |
|
else |
220 |
+ |
fmtid = "8-bit_grey"; |
221 |
+ |
if (dataonly && format == 'w') |
222 |
+ |
if (putprim == ALL) |
223 |
|
fmtid = "48-bit_rgb"; |
224 |
+ |
else |
225 |
+ |
fmtid = "16-bit_grey"; |
226 |
|
/* assign reverse ordering */ |
227 |
|
rord[ord[0]] = 0; |
228 |
|
rord[ord[1]] = 1; |
236 |
|
progname, argv[i]); |
237 |
|
quit(1); |
238 |
|
} |
239 |
< |
if (reverse && !brightonly && i == argc-3) { |
239 |
> |
if (reverse && putprim != BRIGHT && i == argc-3) { |
240 |
|
if ((fin2 = fopen(argv[i+1], "r")) == NULL) { |
241 |
|
fprintf(stderr, "%s: can't open file \"%s\"\n", |
242 |
|
progname, argv[i+1]); |
250 |
|
interleave = -1; |
251 |
|
} else if (i != argc-1) |
252 |
|
fin = NULL; |
253 |
< |
if (reverse && !brightonly && !interleave) { |
253 |
> |
if (reverse && putprim != BRIGHT && !interleave) { |
254 |
|
fin2 = fopen(argv[i], "r"); |
255 |
|
fin3 = fopen(argv[i], "r"); |
256 |
|
} |
268 |
|
} |
269 |
|
|
270 |
|
if (reverse) { |
271 |
< |
#ifdef MSDOS |
272 |
< |
setmode(fileno(stdout), O_BINARY); |
271 |
> |
#ifdef _WIN32 |
272 |
> |
SET_FILE_BINARY(stdout); |
273 |
|
if (format != 'a' && format != 'i') |
274 |
< |
setmode(fileno(fin), O_BINARY); |
274 |
> |
SET_FILE_BINARY(fin); |
275 |
|
#endif |
276 |
|
/* get header */ |
277 |
|
if (header) { |
316 |
|
fputsresolu(&picres, stdout); /* always put resolution */ |
317 |
|
valtopix(); |
318 |
|
} else { |
319 |
< |
#ifdef MSDOS |
320 |
< |
setmode(fileno(fin), O_BINARY); |
319 |
> |
#ifdef _WIN32 |
320 |
> |
SET_FILE_BINARY(fin); |
321 |
|
if (format != 'a' && format != 'i') |
322 |
< |
setmode(fileno(stdout), O_BINARY); |
322 |
> |
SET_FILE_BINARY(stdout); |
323 |
|
#endif |
324 |
|
/* get header */ |
325 |
|
getheader(fin, checkhead, NULL); |
508 |
|
} |
509 |
|
|
510 |
|
|
511 |
+ |
swap16(wp, n) /* swap n 16-bit words */ |
512 |
+ |
register uint16 *wp; |
513 |
+ |
int n; |
514 |
+ |
{ |
515 |
+ |
while (n-- > 0) { |
516 |
+ |
*wp = *wp << 8 | ((*wp >> 8) & 0xff); |
517 |
+ |
wp++; |
518 |
+ |
} |
519 |
+ |
} |
520 |
+ |
|
521 |
|
getcascii(col) /* get an ascii color value from stream(s) */ |
522 |
|
COLOR col; |
523 |
|
{ |
629 |
|
fread((char *)(vw+2), sizeof(uint16), 1, fin3) != 1) |
630 |
|
return(-1); |
631 |
|
} |
632 |
+ |
if (swapbytes) |
633 |
+ |
swap16(vw, 3); |
634 |
|
setcolor(col, (vw[rord[RED]]+.5)/65536., |
635 |
|
(vw[rord[GRN]]+.5)/65536., (vw[rord[BLU]]+.5)/65536.); |
636 |
|
return(0); |
709 |
|
|
710 |
|
if (fread((char *)&vw, sizeof(uint16), 1, fin) != 1) |
711 |
|
return(-1); |
712 |
+ |
if (swapbytes) |
713 |
+ |
swap16(&vw, 1); |
714 |
|
d = (vw+.5)/65536.; |
715 |
|
setcolor(col, d, d, d); |
716 |
|
return(0); |
799 |
|
vw[1] = min(i,65535); |
800 |
|
i = colval(col,ord[2])*65536.; |
801 |
|
vw[2] = min(i,65535); |
802 |
+ |
if (swapbytes) |
803 |
+ |
swap16(vw, 3); |
804 |
|
fwrite((char *)vw, sizeof(uint16), 3, stdout); |
805 |
|
|
806 |
|
return(ferror(stdout) ? -1 : 0); |
871 |
|
|
872 |
|
i = (*mybright)(col)*65536.; |
873 |
|
vw = min(i,65535); |
874 |
+ |
if (swapbytes) |
875 |
+ |
swap16(&vw, 1); |
876 |
|
fwrite((char *)&vw, sizeof(uint16), 1, stdout); |
877 |
|
|
878 |
|
return(ferror(stdout) ? -1 : 0); |
943 |
|
|
944 |
|
i = colval(col,putprim)*65536.; |
945 |
|
vw = min(i,65535); |
946 |
+ |
if (swapbytes) |
947 |
+ |
swap16(&vw, 1); |
948 |
|
fwrite((char *)&vw, sizeof(uint16), 1, stdout); |
949 |
|
|
950 |
|
return(ferror(stdout) ? -1 : 0); |