| 1 |
greg |
1.1 |
#ifndef lint |
| 2 |
|
|
static char SCCSid[] = "$SunId$ LBL"; |
| 3 |
|
|
#endif |
| 4 |
|
|
|
| 5 |
|
|
/* Copyright (c) 1986 Regents of the University of California */ |
| 6 |
|
|
|
| 7 |
|
|
/* |
| 8 |
|
|
* glimage.c - program to dump pixel file NeWS window |
| 9 |
|
|
* |
| 10 |
|
|
* 1/24/89 |
| 11 |
|
|
*/ |
| 12 |
|
|
|
| 13 |
|
|
#include <stdio.h> |
| 14 |
|
|
|
| 15 |
|
|
#include <gl.h> |
| 16 |
|
|
|
| 17 |
|
|
#include "color.h" |
| 18 |
|
|
|
| 19 |
greg |
2.1 |
#include "resolu.h" |
| 20 |
greg |
1.1 |
|
| 21 |
greg |
2.1 |
|
| 22 |
greg |
1.1 |
main(argc, argv) /* print a picture */ |
| 23 |
|
|
int argc; |
| 24 |
|
|
char *argv[]; |
| 25 |
|
|
{ |
| 26 |
|
|
char *fname; |
| 27 |
|
|
FILE *input; |
| 28 |
|
|
int xres, yres; |
| 29 |
|
|
int winorgx, winorgy; |
| 30 |
|
|
COLR *scanline; |
| 31 |
|
|
long *winout; |
| 32 |
|
|
int i; |
| 33 |
|
|
register int j; |
| 34 |
|
|
|
| 35 |
|
|
fname = argv[1]; |
| 36 |
|
|
if (fname == NULL) { |
| 37 |
|
|
input = stdin; |
| 38 |
|
|
fname = "<stdin>"; |
| 39 |
|
|
} else if ((input = fopen(fname, "r")) == NULL) { |
| 40 |
|
|
perror(fname); |
| 41 |
|
|
exit(1); |
| 42 |
|
|
} |
| 43 |
|
|
/* discard header */ |
| 44 |
greg |
1.3 |
if (checkheader(input, COLRFMT, NULL) < 0) { |
| 45 |
|
|
fprintf(stderr, "%s: not a Radiance picture\n", fname); |
| 46 |
|
|
exit(1); |
| 47 |
|
|
} |
| 48 |
greg |
1.1 |
/* get picture dimensions */ |
| 49 |
greg |
2.1 |
if (fgetresolu(&xres, &yres, input) < 0) { |
| 50 |
greg |
1.1 |
fprintf(stderr, "%s: bad picture size\n", fname); |
| 51 |
|
|
exit(1); |
| 52 |
|
|
} |
| 53 |
|
|
prefsize(xres, yres); |
| 54 |
|
|
winopen("newsimage"); |
| 55 |
|
|
RGBmode(); |
| 56 |
|
|
gconfig(); |
| 57 |
|
|
RGBcolor(0,0,0); |
| 58 |
|
|
clear(); |
| 59 |
|
|
getorigin(&winorgx,&winorgy); |
| 60 |
|
|
winout = (long *)malloc(xres*sizeof(long)); |
| 61 |
|
|
scanline = (COLR *)malloc(xres*sizeof(COLR)); |
| 62 |
|
|
if (winout == NULL || scanline == NULL) { |
| 63 |
|
|
perror(argv[0]); |
| 64 |
|
|
exit(1); |
| 65 |
|
|
} |
| 66 |
|
|
for (i = yres-1; i >= 0; i--) { |
| 67 |
|
|
if (freadcolrs(scanline, xres, input) < 0) { |
| 68 |
|
|
fprintf(stderr, "%s: read error (y=%d)\n", fname, i); |
| 69 |
|
|
exit(1); |
| 70 |
|
|
} |
| 71 |
greg |
1.2 |
normcolrs(scanline, xres, 0); |
| 72 |
greg |
1.1 |
for (j = 0; j < xres; j++) { |
| 73 |
|
|
winout[j] = 255L<<24; |
| 74 |
|
|
winout[j] |= (long)scanline[j][BLU]<<16; |
| 75 |
|
|
winout[j] |= (long)scanline[j][GRN]<<8; |
| 76 |
|
|
winout[j] |= (long)scanline[j][RED]; |
| 77 |
|
|
} |
| 78 |
|
|
lrectwrite(0,i,xres-1,i,winout); |
| 79 |
|
|
} |
| 80 |
|
|
pause(); |
| 81 |
|
|
exit(0); |
| 82 |
|
|
} |