| 1 |
|
#ifndef lint |
| 2 |
< |
static char SCCSid[] = "$SunId$ Auckuni"; |
| 2 |
> |
static const char RCSid[] = "$Id$"; |
| 3 |
|
#endif |
| 4 |
< |
|
| 5 |
< |
/* |
| 6 |
< |
* rad2pict - |
| 7 |
< |
* Convert an Radiance image to APPLE pict format. |
| 4 |
> |
/* Convert an Radiance image to APPLE pict format. |
| 5 |
|
* |
| 6 |
|
* Orginally Iris to PICT by Paul Haeberli - 1990 |
| 7 |
|
* Hacked into Rad to PICT by Russell Street 1990 |
| 16 |
|
* -- Added exposure level adjustment |
| 17 |
|
*/ |
| 18 |
|
|
| 19 |
< |
#include <stdio.h> |
| 23 |
< |
#include <stdlib.h> |
| 19 |
> |
#include <math.h> |
| 20 |
|
|
| 21 |
+ |
#include "rtio.h" |
| 22 |
+ |
#include "platform.h" |
| 23 |
|
#include "pict.h" |
| 24 |
|
#include "color.h" |
| 25 |
|
#include "resolu.h" |
| 27 |
|
int outbytes; /* This had better be 32 bits! */ |
| 28 |
|
char *progname; |
| 29 |
|
int verbose = 0; |
| 30 |
< |
float gamma = 2.0; |
| 30 |
> |
float gamcor = 2.0; |
| 31 |
|
int bradj = 0; |
| 32 |
|
|
| 33 |
< |
/* First some utility routines */ |
| 33 |
> |
static void putrect(int xorg, int yorg, int xsize, int ysize); |
| 34 |
> |
static void putfprect(int xorg, int yorg, int xsize, int ysize); |
| 35 |
> |
static void putalong(long l); |
| 36 |
> |
static void putashort(short s); |
| 37 |
> |
static void putbyte(int b); |
| 38 |
> |
static void putbytes(unsigned char *buf, int n ); |
| 39 |
> |
static void putpict(int xsize, int ysize); |
| 40 |
> |
static void getrow(FILE *in, char *cbuf, int xsize); |
| 41 |
> |
static int packbits(unsigned char *ibits, unsigned char *pbits, int nbits); |
| 42 |
> |
static void usage(void); |
| 43 |
|
|
| 44 |
< |
putrect(xorg,yorg,xsize,ysize) |
| 45 |
< |
int xorg, yorg, xsize, ysize; |
| 44 |
> |
|
| 45 |
> |
/* First some utility routines */ |
| 46 |
> |
static void |
| 47 |
> |
putrect( |
| 48 |
> |
int xorg, |
| 49 |
> |
int yorg, |
| 50 |
> |
int xsize, |
| 51 |
> |
int ysize |
| 52 |
> |
) |
| 53 |
|
{ |
| 54 |
|
putashort(yorg); |
| 55 |
|
putashort(xorg); |
| 57 |
|
putashort(xsize); |
| 58 |
|
} |
| 59 |
|
|
| 60 |
< |
putfprect(xorg,yorg,xsize,ysize) |
| 61 |
< |
int xorg, yorg, xsize, ysize; |
| 60 |
> |
static void |
| 61 |
> |
putfprect( |
| 62 |
> |
int xorg, |
| 63 |
> |
int yorg, |
| 64 |
> |
int xsize, |
| 65 |
> |
int ysize |
| 66 |
> |
) |
| 67 |
|
{ |
| 68 |
|
putalong(yorg<<16); |
| 69 |
|
putalong(xorg<<16); |
| 71 |
|
putalong(xsize<<16); |
| 72 |
|
} |
| 73 |
|
|
| 74 |
< |
putalong(l) |
| 75 |
< |
long l; |
| 74 |
> |
static void |
| 75 |
> |
putalong( |
| 76 |
> |
long l |
| 77 |
> |
) |
| 78 |
|
{ |
| 79 |
|
putbyte((l>>24)&0xff); |
| 80 |
|
putbyte((l>>16)&0xff); |
| 82 |
|
putbyte((l>>0)&0xff); |
| 83 |
|
} |
| 84 |
|
|
| 85 |
< |
putashort(s) |
| 86 |
< |
short s; |
| 85 |
> |
static void |
| 86 |
> |
putashort( |
| 87 |
> |
short s |
| 88 |
> |
) |
| 89 |
|
{ |
| 90 |
|
putbyte((s>>8)&0xff); |
| 91 |
|
putbyte((s>>0)&0xff); |
| 92 |
|
} |
| 93 |
|
|
| 94 |
< |
putbyte(b) |
| 95 |
< |
int b; |
| 94 |
> |
static void |
| 95 |
> |
putbyte( |
| 96 |
> |
int b |
| 97 |
> |
) |
| 98 |
|
{ |
| 99 |
|
if (putc(b,stdout) == EOF && ferror(stdout)) { |
| 100 |
|
fprintf(stderr,"%s: error on write\n", progname); |
| 103 |
|
outbytes++; |
| 104 |
|
} |
| 105 |
|
|
| 106 |
< |
putbytes(buf,n) |
| 107 |
< |
unsigned char *buf; |
| 108 |
< |
int n; |
| 106 |
> |
static void |
| 107 |
> |
putbytes( |
| 108 |
> |
unsigned char *buf, |
| 109 |
> |
int n |
| 110 |
> |
) |
| 111 |
|
{ |
| 112 |
|
if(!fwrite(buf,n,1,stdout)) { |
| 113 |
|
fprintf(stderr,"%s: error on write\n", progname); |
| 116 |
|
outbytes+=n; |
| 117 |
|
} |
| 118 |
|
|
| 119 |
< |
main(argc,argv) |
| 120 |
< |
int argc; |
| 121 |
< |
char **argv; |
| 119 |
> |
int |
| 120 |
> |
main( |
| 121 |
> |
int argc, |
| 122 |
> |
char **argv |
| 123 |
> |
) |
| 124 |
|
{ |
| 125 |
|
int xsize, ysize; |
| 126 |
|
int i, picsize; |
| 127 |
|
int ssizepos, lsizepos; |
| 128 |
< |
|
| 128 |
> |
SET_DEFAULT_BINARY(); |
| 129 |
> |
SET_FILE_BINARY(stdin); |
| 130 |
> |
SET_FILE_BINARY(stdout); |
| 131 |
|
progname = argv[0]; |
| 132 |
|
|
| 133 |
|
for (i = 1; i < argc ; i++) |
| 134 |
< |
if (argv[i][0] == '-') |
| 134 |
> |
if (argv[i][0] == '-') |
| 135 |
|
switch (argv[i][1]) { |
| 136 |
< |
case 'g': gamma = atof(argv[++i]); |
| 136 |
> |
case 'g': gamcor = atof(argv[++i]); |
| 137 |
|
break; |
| 138 |
|
|
| 139 |
|
case 'e': if (argv[i+1][0] != '+' && argv[i+1][0] != '-') |
| 153 |
|
goto outofparse; |
| 154 |
|
break; /* NOTREACHED */ |
| 155 |
|
|
| 156 |
< |
otherwise: usage(); |
| 156 |
> |
default: |
| 157 |
> |
usage(); |
| 158 |
|
break; |
| 159 |
|
} |
| 160 |
|
else |
| 179 |
|
|
| 180 |
|
#ifdef DEBUG |
| 181 |
|
fprintf(stderr, "Input file: %s\n", i <= argc - 1 ? argv[i] : "stdin"); |
| 182 |
< |
fprintf(stderr, "Outut file: %s\n", i <= argc - 2 ? argv[i+1] : "stdout" ); |
| 183 |
< |
fprintf(stderr, "Gamma: %f\n", gamma); |
| 182 |
> |
fprintf(stderr, "Outut file: %s\n", i <= argc - 2 ? argv[i+1] : "stdout" ); |
| 183 |
> |
fprintf(stderr, "Gamma: %f\n", gamcor); |
| 184 |
|
fprintf(stderr, "Brightness adjust: %d\n", bradj); |
| 185 |
< |
fprintf(stderr, "Verbose: %s\n", verbose ? "on" : "off"); |
| 185 |
> |
fprintf(stderr, "Verbose: %s\n", verbose ? "on" : "off"); |
| 186 |
|
#endif |
| 187 |
|
|
| 188 |
|
|
| 189 |
< |
/* OK. Now we read the size of the Radiance picture */ |
| 189 |
> |
/* OK. Now we read the size of the Radiance picture */ |
| 190 |
|
if (checkheader(stdin, COLRFMT, NULL) < 0 || |
| 191 |
< |
fgetresolu(&xsize, &ysize, stdin) < 0 /* != (YMAJOR|YDECR) */ ) { |
| 192 |
< |
fprintf(stderr, "%s: not a radiance picture\n", progname); |
| 193 |
< |
exit(1); |
| 191 |
> |
fgetresolu(&xsize, &ysize, stdin) < 0 /* != (YMAJOR|YDECR) */ ) { |
| 192 |
> |
fprintf(stderr, "%s: not a radiance picture\n", progname); |
| 193 |
> |
exit(1); |
| 194 |
|
} |
| 195 |
|
|
| 196 |
|
/* Set the gamma correction */ |
| 197 |
|
|
| 198 |
< |
setcolrgam(gamma); |
| 198 |
> |
setcolrgam(gamcor); |
| 199 |
|
|
| 200 |
|
for(i=0; i<HEADER_SIZE; i++) |
| 201 |
|
putbyte(0); |
| 202 |
|
|
| 203 |
|
ssizepos = outbytes; |
| 204 |
< |
putashort(0); /* low 16 bits of file size less HEADER_SIZE */ |
| 204 |
> |
putashort(0); /* low 16 bits of file size less HEADER_SIZE */ |
| 205 |
|
putrect(0,0,xsize,ysize); /* bounding box of picture */ |
| 206 |
|
putashort(PICT_picVersion); |
| 207 |
|
putashort(0x02ff); /* version 2 pict */ |
| 208 |
|
putashort(PICT_reservedHeader); /* reserved header opcode */ |
| 209 |
|
|
| 210 |
|
lsizepos = outbytes; |
| 211 |
< |
putalong(0); /* full size of the file */ |
| 212 |
< |
putfprect(0,0,xsize,ysize); /* fixed point bounding box of picture */ |
| 213 |
< |
putalong(0); /* reserved */ |
| 211 |
> |
putalong(0); /* full size of the file */ |
| 212 |
> |
putfprect(0,0,xsize,ysize); /* fixed point bounding box of picture */ |
| 213 |
> |
putalong(0); /* reserved */ |
| 214 |
|
|
| 215 |
< |
putashort(PICT_clipRgn); /* the clip region */ |
| 215 |
> |
putashort(PICT_clipRgn); /* the clip region */ |
| 216 |
|
putashort(10); |
| 217 |
|
putrect(0,0,xsize,ysize); |
| 218 |
|
|
| 219 |
|
if (verbose) |
| 220 |
|
fprintf(stderr, "%s: The picture is %d by %d, with a gamma of %f\n", |
| 221 |
< |
progname, xsize, ysize, gamma); |
| 221 |
> |
progname, xsize, ysize, gamcor); |
| 222 |
|
|
| 223 |
|
|
| 224 |
|
putpict(xsize, ysize); /* Here is where all the work is done */ |
| 238 |
|
return 0; /* lint fodder */ |
| 239 |
|
} |
| 240 |
|
|
| 241 |
< |
putpict(xsize, ysize) |
| 242 |
< |
int xsize; |
| 243 |
< |
int ysize; |
| 241 |
> |
static void |
| 242 |
> |
putpict( |
| 243 |
> |
int xsize, |
| 244 |
> |
int ysize |
| 245 |
> |
) |
| 246 |
|
{ |
| 247 |
|
int y; |
| 248 |
|
int nbytes, rowbytes; |
| 249 |
|
char *cbuf, *pbuf; |
| 250 |
|
|
| 251 |
< |
cbuf = malloc(4 * xsize); |
| 251 |
> |
cbuf = (char *)malloc(4 * xsize); |
| 252 |
|
|
| 253 |
|
if (cbuf == NULL) { |
| 254 |
|
fprintf(stderr, "%s: not enough memory\n", progname); |
| 255 |
|
exit(1); |
| 256 |
|
} |
| 257 |
|
|
| 258 |
< |
pbuf = malloc(4 * xsize); |
| 258 |
> |
pbuf = (char *)malloc(4 * xsize); |
| 259 |
|
|
| 260 |
|
if (pbuf == NULL) { |
| 261 |
|
fprintf(stderr, "%s: not enough memory\n", progname); |
| 269 |
|
|
| 270 |
|
if(rowbytes&1) |
| 271 |
|
rowbytes++; |
| 272 |
< |
putashort(rowbytes|0x8000); /* rowbytes */ |
| 272 |
> |
putashort(rowbytes|0x8000); /* rowbytes */ |
| 273 |
|
putrect(0,0,xsize,ysize); /* bounds */ |
| 274 |
|
putashort(0); /* version */ |
| 275 |
|
|
| 313 |
|
free(pbuf); |
| 314 |
|
} |
| 315 |
|
|
| 316 |
< |
int getrow(in, cbuf, xsize) |
| 317 |
< |
FILE *in; |
| 318 |
< |
char *cbuf; |
| 319 |
< |
int xsize; |
| 316 |
> |
static void |
| 317 |
> |
getrow( |
| 318 |
> |
FILE *in, |
| 319 |
> |
char *cbuf, |
| 320 |
> |
int xsize |
| 321 |
> |
) |
| 322 |
|
{ |
| 323 |
< |
extern char *tempbuffer(); /* defined in color.c */ |
| 323 |
> |
extern char *tempbuffer(); /* defined in color.c */ |
| 324 |
|
COLR *scanin = NULL; |
| 325 |
|
int x; |
| 326 |
|
|
| 330 |
|
} |
| 331 |
|
|
| 332 |
|
if (freadcolrs(scanin, xsize, in) < 0) { |
| 333 |
< |
fprintf(stderr, "%s: read error\n", progname); |
| 334 |
< |
exit(1); |
| 335 |
< |
} |
| 333 |
> |
fprintf(stderr, "%s: read error\n", progname); |
| 334 |
> |
exit(1); |
| 335 |
> |
} |
| 336 |
|
|
| 337 |
|
if (bradj) /* Adjust exposure level */ |
| 338 |
|
shiftcolrs(scanin, xsize, bradj); |
| 349 |
|
} |
| 350 |
|
|
| 351 |
|
|
| 352 |
< |
packbits(ibits,pbits,nbits) |
| 353 |
< |
unsigned char *ibits, *pbits; |
| 354 |
< |
int nbits; |
| 352 |
> |
static int |
| 353 |
> |
packbits( |
| 354 |
> |
unsigned char *ibits, |
| 355 |
> |
unsigned char *pbits, |
| 356 |
> |
int nbits |
| 357 |
> |
) |
| 358 |
|
{ |
| 320 |
– |
int bytes; /* UNUSED */ |
| 359 |
|
unsigned char *sptr; |
| 360 |
|
unsigned char *ibitsend; |
| 361 |
|
unsigned char *optr = pbits; |
| 368 |
|
ibits += 2; |
| 369 |
|
while((ibits<ibitsend)&&((ibits[-2]!=ibits[-1])||(ibits[-1]!=ibits[0]))) |
| 370 |
|
ibits++; |
| 371 |
< |
if(ibits != ibitsend) { |
| 371 |
> |
if(ibits != ibitsend) { |
| 372 |
|
ibits -= 2; |
| 373 |
|
} |
| 374 |
|
count = ibits-sptr; |
| 396 |
|
return optr-pbits; |
| 397 |
|
} |
| 398 |
|
|
| 399 |
< |
usage() |
| 399 |
> |
static void |
| 400 |
> |
usage(void) |
| 401 |
|
{ |
| 402 |
|
fprintf(stderr, "Usage: %s [-v] [-g gamma] [infile [outfile]]\n", |
| 403 |
|
progname); |