83 |
|
|
84 |
|
COLR *scanline; /* scan line buffer */ |
85 |
|
TMbright *lscan; /* encoded luminance scanline */ |
86 |
< |
BYTE *cscan; /* encoded chroma scanline */ |
87 |
< |
BYTE *pscan; /* compute pixel scanline */ |
86 |
> |
uby8 *cscan; /* encoded chroma scanline */ |
87 |
> |
uby8 *pscan; /* compute pixel scanline */ |
88 |
|
|
89 |
|
RESOLU inpres; /* input resolution and ordering */ |
90 |
|
int xmax, ymax; /* picture dimensions */ |
122 |
|
|
123 |
|
char errmsg[128]; |
124 |
|
|
125 |
< |
BYTE clrtab[256][3]; /* global color map */ |
125 |
> |
uby8 clrtab[256][3]; /* global color map */ |
126 |
|
|
127 |
|
|
128 |
|
Display *thedisplay; |
271 |
|
getevent(); /* main loop */ |
272 |
|
userr: |
273 |
|
fprintf(stderr, |
274 |
< |
"Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e spec][-g gamcor][-s][-ospec][-t intvl] pic ..\n", |
274 |
> |
"Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e spec][-g gamcor][-s][-ospec][-t intvl] hdr ..\n", |
275 |
|
progname); |
276 |
|
exit(1); |
277 |
|
} |
283 |
|
void *p |
284 |
|
) |
285 |
|
{ |
286 |
< |
char fmt[32]; |
286 |
> |
char fmt[MAXFMTLEN]; |
287 |
|
|
288 |
|
if (isexpos(s)) |
289 |
|
exposure *= exposval(s); |
290 |
|
else if (formatval(fmt, s)) |
291 |
< |
wrongformat = strcmp(fmt, COLRFMT); |
292 |
< |
else if (isview(s) && sscanview(&ourview, s) > 0) |
293 |
< |
gotview++; |
291 |
> |
wrongformat = strcmp(fmt, COLRFMT) && strcmp(fmt, SPECFMT); |
292 |
> |
else if (isview(s)) |
293 |
> |
gotview += sscanview(&ourview, s); |
294 |
> |
else if (isncomp(s)) |
295 |
> |
NCSAMP = ncompval(s); |
296 |
> |
else if (iswlsplit(s)) |
297 |
> |
wlsplitval(WLPART, s); |
298 |
|
return(0); |
299 |
|
} |
300 |
|
|
312 |
|
XTextProperty windowName, iconName; |
313 |
|
XGCValues xgcv; |
314 |
|
char *name; |
315 |
< |
register int i; |
315 |
> |
int i; |
316 |
|
|
317 |
|
if (fname != NULL) { |
318 |
|
scanpos = (long *)malloc(ymax*sizeof(long)); |
422 |
|
char *err |
423 |
|
) |
424 |
|
{ |
425 |
< |
register int es; |
425 |
> |
int es; |
426 |
|
int cs; |
427 |
|
|
428 |
< |
if ( (es = err != NULL) ) |
428 |
> |
if ( (es = (err != NULL)) ) |
429 |
|
fprintf(stderr, "%s: %s: %s\n", progname, |
430 |
|
fname==NULL?"<stdin>":fname, err); |
431 |
|
if (thedisplay != NULL) |
443 |
|
|
444 |
|
static int |
445 |
|
viscmp( /* compare visual to see which is better, descending */ |
446 |
< |
register XVisualInfo *v1, |
447 |
< |
register XVisualInfo *v2 |
446 |
> |
XVisualInfo *v1, |
447 |
> |
XVisualInfo *v2 |
448 |
|
) |
449 |
|
{ |
450 |
|
int bad1 = 0, bad2 = 0; |
451 |
< |
register int *rp; |
451 |
> |
int *rp; |
452 |
|
|
453 |
|
if (v1->class == v2->class) { |
454 |
< |
if (v1->class == TrueColor || v1->class == DirectColor) { |
455 |
< |
/* prefer 24-bit to 32-bit */ |
456 |
< |
if (v1->depth == 24 && v2->depth == 32) |
454 |
> |
if ((v1->class == TrueColor) | (v1->class == DirectColor)) { |
455 |
> |
/* prefer 24-bit */ |
456 |
> |
if ((v1->depth == 24) & (v2->depth > 24)) |
457 |
|
return(-1); |
458 |
< |
if (v1->depth == 32 && v2->depth == 24) |
458 |
> |
if ((v1->depth > 24) & (v2->depth == 24)) |
459 |
|
return(1); |
460 |
|
/* go for maximum depth otherwise */ |
461 |
|
return(v2->depth - v1->depth); |
462 |
|
} |
463 |
|
/* don't be too greedy */ |
464 |
< |
if (maxcolors <= 1<<v1->depth && maxcolors <= 1<<v2->depth) |
464 |
> |
if ((maxcolors <= 1<<v1->depth) & (maxcolors <= 1<<v2->depth)) |
465 |
|
return(v1->depth - v2->depth); |
466 |
|
return(v2->depth - v1->depth); |
467 |
|
} |
468 |
|
/* prefer Pseudo when < 15-bit */ |
469 |
< |
if ((v1->class == TrueColor || v1->class == DirectColor) && |
469 |
> |
if ((v1->class == TrueColor) | (v1->class == DirectColor) && |
470 |
|
v1->depth < 15) |
471 |
|
bad1 = 1; |
472 |
< |
if ((v2->class == TrueColor || v2->class == DirectColor) && |
472 |
> |
if ((v2->class == TrueColor) | (v2->class == DirectColor) && |
473 |
|
v2->depth < 15) |
474 |
|
bad2 = -1; |
475 |
|
if (bad1 | bad2) |
505 |
|
}; |
506 |
|
XVisualInfo *xvi; |
507 |
|
int vismatched; |
508 |
< |
register int i, j; |
508 |
> |
int i, j; |
509 |
|
|
510 |
|
if (greyscale) { |
511 |
|
ourrank = rankings[2]; |
676 |
|
RREAL hv[2]; |
677 |
|
FVECT rorg, rdir; |
678 |
|
COLOR cval; |
679 |
< |
register char *cp; |
679 |
> |
char *cp; |
680 |
|
|
681 |
|
bbox.xmin = xpos; bbox.xsiz = 1; |
682 |
|
bbox.ymin = ypos; bbox.ysiz = 1; |
954 |
|
|
955 |
|
static void |
956 |
|
colavg( |
957 |
< |
register COLR *scn, |
958 |
< |
register int n, |
957 |
> |
COLR *scn, |
958 |
> |
int n, |
959 |
|
void *cavg |
960 |
|
) |
961 |
|
{ |
962 |
|
COLOR col; |
963 |
|
|
964 |
|
while (n--) { |
965 |
< |
colr_color(col, *scn++); |
965 |
> |
colr_color(col, *scn); |
966 |
|
addcolor((COLORV*)cavg, col); |
967 |
+ |
scn++; |
968 |
|
} |
969 |
|
} |
970 |
|
|
975 |
|
) |
976 |
|
{ |
977 |
|
double d; |
978 |
< |
register int rval; |
978 |
> |
int rval; |
979 |
|
|
980 |
|
setcolor(cavg, 0., 0., 0.); |
981 |
< |
rval = dobox(colavg, (void *)cavg); |
981 |
> |
rval = dobox(colavg, cavg); |
982 |
|
if (rval > 0) { |
983 |
|
d = 1./rval; |
984 |
|
scalecolor(cavg, d); |
989 |
|
|
990 |
|
static int |
991 |
|
dobox( /* run function over bbox */ |
987 |
– |
//void (*f)(), /* function to call for each subscan */ |
992 |
|
doboxf_t *f, /* function to call for each subscan */ |
993 |
|
void *p /* pointer to private data */ |
994 |
|
) |
1013 |
|
if (top >= bottom) |
1014 |
|
return(0); |
1015 |
|
for (y = top; y < bottom; y++) { |
1016 |
< |
if (getscan(y) == -1) |
1016 |
> |
if (getscan(y) < 0) |
1017 |
|
return(-1); |
1018 |
|
(*f)(scanline+left, right-left, p); |
1019 |
|
} |
1064 |
|
goto memerr; |
1065 |
|
if (greyscale) { |
1066 |
|
cscan = TM_NOCHROM; |
1067 |
< |
if ((pscan = (BYTE *)malloc(sizeof(BYTE)*xmax)) == NULL) |
1067 |
> |
if ((pscan = (uby8 *)malloc(sizeof(uby8)*xmax)) == NULL) |
1068 |
|
goto memerr; |
1069 |
< |
} else if ((pscan=cscan = (BYTE *)malloc(3*sizeof(BYTE)*xmax)) |
1069 |
> |
} else if ((pscan=cscan = (uby8 *)malloc(3*sizeof(uby8)*xmax)) |
1070 |
|
== NULL) |
1071 |
|
goto memerr; |
1072 |
|
/* initialize tm library */ |
1073 |
|
tmGlobal = tmInit(flags, stdprims, gamcor); |
1074 |
|
if (tmGlobal == NULL) |
1075 |
|
goto memerr; |
1076 |
< |
if (tmSetSpace(tmGlobal, stdprims, WHTEFFICACY/exposure, NULL)) |
1076 |
> |
if (tmSetSpace(tmGlobal, stdprims, WHTEFFICACY/exposure)) |
1077 |
|
goto tmerr; |
1078 |
|
/* compute picture histogram */ |
1079 |
|
for (y = 0; y < ymax; y++) { |
1086 |
|
} |
1087 |
|
} |
1088 |
|
tmCurrent = tmDup(tmGlobal); /* add fixations to duplicate map */ |
1089 |
< |
dobox(addfix, (void *)tmCurrent); |
1089 |
> |
dobox(addfix, tmCurrent); |
1090 |
|
/* (re)compute tone mapping */ |
1091 |
|
if (tmComputeMapping(tmCurrent, gamcor, 0., 0.)) |
1092 |
|
goto tmerr; |
1100 |
|
|
1101 |
|
static void |
1102 |
|
tmap_colrs( /* apply tone mapping to scanline */ |
1103 |
< |
register COLR *scn, |
1103 |
> |
COLR *scn, |
1104 |
|
int len |
1105 |
|
) |
1106 |
|
{ |
1107 |
< |
register BYTE *ps; |
1107 |
> |
uby8 *ps; |
1108 |
|
|
1109 |
|
if (tmflags == TM_F_LINEAR) { |
1110 |
|
if (scale) |
1142 |
|
static void |
1143 |
|
getmono(void) /* get monochrome data */ |
1144 |
|
{ |
1145 |
< |
register unsigned char *dp; |
1146 |
< |
register int x, err; |
1145 |
> |
unsigned char *dp; |
1146 |
> |
int x, err; |
1147 |
|
int y, errp; |
1148 |
|
short *cerr; |
1149 |
|
|
1168 |
|
cerr[x] = err + errp; |
1169 |
|
} |
1170 |
|
} |
1171 |
< |
free((void *)cerr); |
1171 |
> |
free(cerr); |
1172 |
|
} |
1173 |
|
|
1174 |
|
|
1182 |
|
static int ynext; |
1183 |
|
static char *dp; |
1184 |
|
COLR clr; |
1185 |
< |
register int err; |
1186 |
< |
register int x, ti; |
1185 |
> |
int err; |
1186 |
> |
int x, ti; |
1187 |
|
int errp; |
1188 |
|
|
1189 |
|
if (iconheight == 0) { /* initialize */ |
1230 |
|
getfull(void) /* get full (24-bit) data */ |
1231 |
|
{ |
1232 |
|
int y; |
1233 |
< |
register uint32 *dp; |
1234 |
< |
register uint16 *dph; |
1235 |
< |
register int x; |
1233 |
> |
uint32 *dp; |
1234 |
> |
uint16 *dph; |
1235 |
> |
int x; |
1236 |
|
/* initialize tone mapping */ |
1237 |
|
make_tonemap(); |
1238 |
|
/* read and convert file */ |
1298 |
|
getgrey(void) /* get greyscale data */ |
1299 |
|
{ |
1300 |
|
int y; |
1301 |
< |
register unsigned char *dp; |
1302 |
< |
register int x; |
1301 |
> |
unsigned char *dp; |
1302 |
> |
int x; |
1303 |
|
/* initialize tone mapping */ |
1304 |
|
make_tonemap(); |
1305 |
|
/* read and convert file */ |
1357 |
|
|
1358 |
|
static void |
1359 |
|
scale_rcolors( /* scale color map */ |
1360 |
< |
register XRASTER *xr, |
1360 |
> |
XRASTER *xr, |
1361 |
|
double sf |
1362 |
|
) |
1363 |
|
{ |
1364 |
< |
register int i; |
1364 |
> |
int i; |
1365 |
|
long maxv; |
1366 |
|
|
1367 |
|
if (xr->pixels == NULL) |
1392 |
|
{ |
1393 |
|
static int trunced = -1; /* truncated file? */ |
1394 |
|
skipit: |
1395 |
< |
if (trunced >= 0 && y >= trunced) { |
1396 |
< |
memset(scanline, '\0', xmax*sizeof(COLR)); |
1395 |
> |
if (y == cury-1) /* already got it? */ |
1396 |
> |
return(0); |
1397 |
> |
if ((trunced >= 0) & (y >= trunced)) { |
1398 |
> |
memset(scanline, 0, xmax*sizeof(COLR)); |
1399 |
|
return(-1); |
1400 |
|
} |
1401 |
|
if (y != cury) { |
1402 |
< |
if (scanpos == NULL || scanpos[y] == -1) |
1402 |
> |
if (scanpos == NULL || scanpos[y] < 0) |
1403 |
|
return(-1); |
1404 |
< |
if (fseek(fin, scanpos[y], 0) == -1) |
1404 |
> |
if (fseek(fin, scanpos[y], 0) < 0) |
1405 |
|
quiterr("fseek error"); |
1406 |
|
cury = y; |
1407 |
< |
} else if (scanpos != NULL && scanpos[y] == -1) |
1407 |
> |
} else if (scanpos != NULL && scanpos[y] < 0) |
1408 |
|
scanpos[y] = ftell(fin); |
1409 |
|
|
1410 |
< |
if (freadcolrs(scanline, xmax, fin) < 0) { |
1410 |
> |
if (fread2colrs(scanline, xmax, fin, NCSAMP, WLPART) < 0) { |
1411 |
|
fprintf(stderr, "%s: %s: unfinished picture\n", |
1412 |
|
progname, fname==NULL?"<stdin>":fname); |
1413 |
|
trunced = y; |