| 1 |
< |
/* Copyright (c) 1986 Regents of the University of California */ |
| 1 |
> |
/* Copyright (c) 1991 Regents of the University of California */ |
| 2 |
|
|
| 3 |
|
#ifndef lint |
| 4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
| 13 |
|
|
| 14 |
|
#include <stdio.h> |
| 15 |
|
|
| 16 |
+ |
#ifdef MSDOS |
| 17 |
+ |
#include <fcntl.h> |
| 18 |
+ |
#endif |
| 19 |
+ |
|
| 20 |
+ |
#include <math.h> |
| 21 |
+ |
|
| 22 |
|
#include "color.h" |
| 23 |
|
|
| 24 |
+ |
#include "resolu.h" |
| 25 |
+ |
|
| 26 |
|
#include "random.h" |
| 27 |
|
|
| 28 |
|
#include "targa.h" |
| 40 |
|
|
| 41 |
|
extern char *ecalloc(), *emalloc(); |
| 42 |
|
|
| 43 |
< |
extern double atof(), pow(); |
| 43 |
> |
double gamma = 2.2; /* gamma correction */ |
| 44 |
|
|
| 45 |
< |
double gamma = 2.0; /* gamma correction */ |
| 45 |
> |
int bradj = 0; /* brightness adjustment */ |
| 46 |
|
|
| 47 |
|
char *progname; |
| 48 |
|
|
| 56 |
|
struct hdStruct head; |
| 57 |
|
int reverse = 0; |
| 58 |
|
int i; |
| 59 |
< |
|
| 59 |
> |
#ifdef MSDOS |
| 60 |
> |
extern int _fmode; |
| 61 |
> |
_fmode = O_BINARY; |
| 62 |
> |
setmode(fileno(stdin), O_BINARY); |
| 63 |
> |
setmode(fileno(stdout), O_BINARY); |
| 64 |
> |
#endif |
| 65 |
|
progname = argv[0]; |
| 66 |
|
|
| 67 |
|
head.dataBits = 16; |
| 80 |
|
case '3': |
| 81 |
|
head.dataBits = 24; |
| 82 |
|
break; |
| 83 |
+ |
case 'e': |
| 84 |
+ |
if (argv[i+1][0] != '+' && argv[i+1][0] != '-') |
| 85 |
+ |
goto userr; |
| 86 |
+ |
bradj = atoi(argv[++i]); |
| 87 |
+ |
break; |
| 88 |
|
default: |
| 89 |
|
goto userr; |
| 90 |
|
} |
| 114 |
|
quiterr("incompatible format"); |
| 115 |
|
/* put header */ |
| 116 |
|
printargs(i, argv, stdout); |
| 117 |
+ |
fputformat(COLRFMT, stdout); |
| 118 |
|
putchar('\n'); |
| 119 |
< |
fputresolu(YMAJOR|YDECR, head.x, head.y, stdout); |
| 119 |
> |
fprtresolu(head.x, head.y, stdout); |
| 120 |
|
/* convert file */ |
| 121 |
|
tg2ra(&head); |
| 122 |
|
} else { |
| 123 |
< |
getheader(stdin, NULL); |
| 124 |
< |
if (fgetresolu(&head.x, &head.y, stdin) != (YMAJOR|YDECR)) |
| 123 |
> |
if (checkheader(stdin, COLRFMT, NULL) < 0 || |
| 124 |
> |
fgetresolu(&head.x, &head.y, stdin) < 0) |
| 125 |
|
quiterr("bad picture file"); |
| 126 |
|
/* assign header */ |
| 127 |
|
head.textSize = 0; |
| 137 |
|
} |
| 138 |
|
exit(0); |
| 139 |
|
userr: |
| 140 |
< |
fprintf(stderr, "Usage: %s [-2|-3|-r][-g gamma] [input [output]]\n", |
| 140 |
> |
fprintf(stderr, "Usage: %s [-2|-3|-r][-g gamma][-e +/-stops] [input [output]]\n", |
| 141 |
|
progname); |
| 142 |
|
exit(1); |
| 143 |
|
} |
| 285 |
|
} |
| 286 |
|
} |
| 287 |
|
gambs_colrs(scanline, hp->x); |
| 288 |
+ |
if (bradj) |
| 289 |
+ |
shiftcolrs(scanline, hp->x, bradj); |
| 290 |
|
if (fwritecolrs(scanline, hp->x, stdout) < 0) |
| 291 |
|
quiterr("error writing RADIANCE file"); |
| 292 |
|
} |
| 308 |
|
for (j = hp->y-1; j >= 0; j--) { |
| 309 |
|
if (freadcolrs(inl, hp->x, stdin) < 0) |
| 310 |
|
quiterr("error reading RADIANCE file"); |
| 311 |
+ |
if (bradj) |
| 312 |
+ |
shiftcolrs(inl, hp->x, bradj); |
| 313 |
|
colrs_gambs(inl, hp->x); |
| 314 |
|
if (hp->dataBits == 16) { |
| 315 |
|
register unsigned short *dp; |
| 316 |
+ |
register int v; |
| 317 |
|
dp = (unsigned short *)tarData + j*hp->x; |
| 318 |
|
for (i = 0; i < hp->x; i++) { |
| 319 |
< |
*dp = ((inl[i][RED]+(random()&7)) & 0xf8)<<7; |
| 320 |
< |
*dp |= ((inl[i][GRN]+(random()&7)) & 0xf8)<<2; |
| 321 |
< |
*dp++ |= (inl[i][BLU]+(random()&7))>>3; |
| 319 |
> |
v = inl[i][RED] + (random()&7); |
| 320 |
> |
if (v > 255) v = 255; |
| 321 |
> |
*dp = (v&0xf8)<<7; |
| 322 |
> |
v = inl[i][GRN] + (random()&7); |
| 323 |
> |
if (v > 255) v = 255; |
| 324 |
> |
*dp |= (v&0xf8)<<2; |
| 325 |
> |
v = inl[i][BLU] + (random()&7); |
| 326 |
> |
if (v > 255) v = 255; |
| 327 |
> |
*dp++ |= v>>3; |
| 328 |
|
} |
| 329 |
|
} else { /* hp->dataBits == 24 */ |
| 330 |
|
register unsigned char *dp; |