1 |
+ |
/* Copyright (c) 1992 Regents of the University of California */ |
2 |
+ |
|
3 |
|
#ifndef lint |
4 |
< |
static char SCCSid[] = "$SunId$ Auckuni"; |
4 |
> |
static char SCCSid[] = "$SunId$ LBL"; |
5 |
|
#endif |
6 |
|
|
7 |
< |
/* |
6 |
< |
* rad2pict - |
7 |
< |
* Convert an Radiance image to APPLE pict format. |
7 |
> |
/* Convert an Radiance image to APPLE pict format. |
8 |
|
* |
9 |
|
* Orginally Iris to PICT by Paul Haeberli - 1990 |
10 |
|
* Hacked into Rad to PICT by Russell Street 1990 |
20 |
|
*/ |
21 |
|
|
22 |
|
#include <stdio.h> |
23 |
+ |
#include <math.h> |
24 |
+ |
#ifdef MSDOS |
25 |
+ |
#include <fcntl.h> |
26 |
+ |
#endif |
27 |
|
|
28 |
|
#include "pict.h" |
29 |
|
#include "color.h" |
30 |
|
#include "resolu.h" |
31 |
|
|
28 |
– |
extern double atof(); |
32 |
|
extern char *malloc(); |
33 |
|
|
34 |
|
int outbytes; /* This had better be 32 bits! */ |
35 |
|
char *progname; |
36 |
|
int verbose = 0; |
37 |
< |
float gamma = 2.0; |
37 |
> |
float gamcor = 2.0; |
38 |
|
int bradj = 0; |
39 |
|
|
40 |
|
/* First some utility routines */ |
101 |
|
int xsize, ysize; |
102 |
|
int i, picsize; |
103 |
|
int ssizepos, lsizepos; |
104 |
< |
|
104 |
> |
#ifdef MSDOS |
105 |
> |
extern int _fmode; |
106 |
> |
_fmode = O_BINARY; |
107 |
> |
setmode(fileno(stdin), O_BINARY); |
108 |
> |
setmode(fileno(stdout), O_BINARY); |
109 |
> |
#endif |
110 |
|
progname = argv[0]; |
111 |
|
|
112 |
|
for (i = 1; i < argc ; i++) |
113 |
< |
if (argv[i][0] == '-') |
113 |
> |
if (argv[i][0] == '-') |
114 |
|
switch (argv[i][1]) { |
115 |
< |
case 'g': gamma = atof(argv[++i]); |
115 |
> |
case 'g': gamcor = atof(argv[++i]); |
116 |
|
break; |
117 |
|
|
118 |
|
case 'e': if (argv[i+1][0] != '+' && argv[i+1][0] != '-') |
157 |
|
|
158 |
|
#ifdef DEBUG |
159 |
|
fprintf(stderr, "Input file: %s\n", i <= argc - 1 ? argv[i] : "stdin"); |
160 |
< |
fprintf(stderr, "Outut file: %s\n", i <= argc - 2 ? argv[i+1] : "stdout" ); |
161 |
< |
fprintf(stderr, "Gamma: %f\n", gamma); |
160 |
> |
fprintf(stderr, "Outut file: %s\n", i <= argc - 2 ? argv[i+1] : "stdout" ); |
161 |
> |
fprintf(stderr, "Gamma: %f\n", gamcor); |
162 |
|
fprintf(stderr, "Brightness adjust: %d\n", bradj); |
163 |
< |
fprintf(stderr, "Verbose: %s\n", verbose ? "on" : "off"); |
163 |
> |
fprintf(stderr, "Verbose: %s\n", verbose ? "on" : "off"); |
164 |
|
#endif |
165 |
|
|
166 |
|
|
167 |
< |
/* OK. Now we read the size of the Radiance picture */ |
167 |
> |
/* OK. Now we read the size of the Radiance picture */ |
168 |
|
if (checkheader(stdin, COLRFMT, NULL) < 0 || |
169 |
< |
fgetresolu(&xsize, &ysize, stdin) < 0 /* != (YMAJOR|YDECR) */ ) { |
170 |
< |
fprintf(stderr, "%s: not a radiance picture\n", progname); |
171 |
< |
exit(1); |
169 |
> |
fgetresolu(&xsize, &ysize, stdin) < 0 /* != (YMAJOR|YDECR) */ ) { |
170 |
> |
fprintf(stderr, "%s: not a radiance picture\n", progname); |
171 |
> |
exit(1); |
172 |
|
} |
173 |
|
|
174 |
|
/* Set the gamma correction */ |
175 |
|
|
176 |
< |
setcolrgam(gamma); |
176 |
> |
setcolrgam(gamcor); |
177 |
|
|
178 |
|
for(i=0; i<HEADER_SIZE; i++) |
179 |
|
putbyte(0); |
180 |
|
|
181 |
|
ssizepos = outbytes; |
182 |
< |
putashort(0); /* low 16 bits of file size less HEADER_SIZE */ |
182 |
> |
putashort(0); /* low 16 bits of file size less HEADER_SIZE */ |
183 |
|
putrect(0,0,xsize,ysize); /* bounding box of picture */ |
184 |
|
putashort(PICT_picVersion); |
185 |
|
putashort(0x02ff); /* version 2 pict */ |
186 |
|
putashort(PICT_reservedHeader); /* reserved header opcode */ |
187 |
|
|
188 |
|
lsizepos = outbytes; |
189 |
< |
putalong(0); /* full size of the file */ |
190 |
< |
putfprect(0,0,xsize,ysize); /* fixed point bounding box of picture */ |
191 |
< |
putalong(0); /* reserved */ |
189 |
> |
putalong(0); /* full size of the file */ |
190 |
> |
putfprect(0,0,xsize,ysize); /* fixed point bounding box of picture */ |
191 |
> |
putalong(0); /* reserved */ |
192 |
|
|
193 |
< |
putashort(PICT_clipRgn); /* the clip region */ |
193 |
> |
putashort(PICT_clipRgn); /* the clip region */ |
194 |
|
putashort(10); |
195 |
|
putrect(0,0,xsize,ysize); |
196 |
|
|
197 |
|
if (verbose) |
198 |
|
fprintf(stderr, "%s: The picture is %d by %d, with a gamma of %f\n", |
199 |
< |
progname, xsize, ysize, gamma); |
199 |
> |
progname, xsize, ysize, gamcor); |
200 |
|
|
201 |
|
|
202 |
|
putpict(xsize, ysize); /* Here is where all the work is done */ |
245 |
|
|
246 |
|
if(rowbytes&1) |
247 |
|
rowbytes++; |
248 |
< |
putashort(rowbytes|0x8000); /* rowbytes */ |
248 |
> |
putashort(rowbytes|0x8000); /* rowbytes */ |
249 |
|
putrect(0,0,xsize,ysize); /* bounds */ |
250 |
|
putashort(0); /* version */ |
251 |
|
|
294 |
|
char *cbuf; |
295 |
|
int xsize; |
296 |
|
{ |
297 |
< |
extern char *tempbuffer(); /* defined in color.c */ |
297 |
> |
extern char *tempbuffer(); /* defined in color.c */ |
298 |
|
COLR *scanin = NULL; |
299 |
|
int x; |
300 |
|
|
304 |
|
} |
305 |
|
|
306 |
|
if (freadcolrs(scanin, xsize, in) < 0) { |
307 |
< |
fprintf(stderr, "%s: read error\n", progname); |
308 |
< |
exit(1); |
309 |
< |
} |
307 |
> |
fprintf(stderr, "%s: read error\n", progname); |
308 |
> |
exit(1); |
309 |
> |
} |
310 |
|
|
311 |
|
if (bradj) /* Adjust exposure level */ |
312 |
|
shiftcolrs(scanin, xsize, bradj); |
340 |
|
ibits += 2; |
341 |
|
while((ibits<ibitsend)&&((ibits[-2]!=ibits[-1])||(ibits[-1]!=ibits[0]))) |
342 |
|
ibits++; |
343 |
< |
if(ibits != ibitsend) { |
343 |
> |
if(ibits != ibitsend) { |
344 |
|
ibits -= 2; |
345 |
|
} |
346 |
|
count = ibits-sptr; |