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 */ |
118 |
|
char icondata[ICONSIZ*ICONSIZ/8]; /* icon bitmap data */ |
119 |
|
int iconwidth = 0, iconheight = 0; |
120 |
|
|
121 |
– |
char *progname; |
122 |
– |
|
121 |
|
char errmsg[128]; |
122 |
|
|
123 |
< |
BYTE clrtab[256][3]; /* global color map */ |
123 |
> |
uby8 clrtab[256][3]; /* global color map */ |
124 |
|
|
125 |
|
|
126 |
|
Display *thedisplay; |
166 |
|
int i; |
167 |
|
int pid; |
168 |
|
|
169 |
< |
progname = argv[0]; |
169 |
> |
fixargv0(argv[0]); /* sets global progname */ |
170 |
|
fin = stdin; |
171 |
|
|
172 |
|
for (i = 1; i < argc; i++) |
269 |
|
getevent(); /* main loop */ |
270 |
|
userr: |
271 |
|
fprintf(stderr, |
272 |
< |
"Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e spec][-g gamcor][-s][-ospec][-t intvl] pic ..\n", |
272 |
> |
"Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e spec][-g gamcor][-s][-ospec][-t intvl] hdr ..\n", |
273 |
|
progname); |
274 |
|
exit(1); |
275 |
|
} |
281 |
|
void *p |
282 |
|
) |
283 |
|
{ |
284 |
< |
char fmt[32]; |
284 |
> |
char fmt[MAXFMTLEN]; |
285 |
|
|
286 |
|
if (isexpos(s)) |
287 |
|
exposure *= exposval(s); |
288 |
|
else if (formatval(fmt, s)) |
289 |
< |
wrongformat = strcmp(fmt, COLRFMT); |
290 |
< |
else if (isview(s) && sscanview(&ourview, s) > 0) |
291 |
< |
gotview++; |
289 |
> |
wrongformat = strcmp(fmt, COLRFMT) && strcmp(fmt, SPECFMT); |
290 |
> |
else if (isview(s)) |
291 |
> |
gotview += sscanview(&ourview, s); |
292 |
> |
else if (isncomp(s)) |
293 |
> |
NCSAMP = ncompval(s); |
294 |
> |
else if (iswlsplit(s)) |
295 |
> |
wlsplitval(WLPART, s); |
296 |
|
return(0); |
297 |
|
} |
298 |
|
|
310 |
|
XTextProperty windowName, iconName; |
311 |
|
XGCValues xgcv; |
312 |
|
char *name; |
313 |
< |
register int i; |
313 |
> |
int i; |
314 |
|
|
315 |
|
if (fname != NULL) { |
316 |
|
scanpos = (long *)malloc(ymax*sizeof(long)); |
399 |
|
windowName.encoding = iconName.encoding = XA_STRING; |
400 |
|
windowName.format = iconName.format = 8; |
401 |
|
windowName.value = (u_char *)name; |
402 |
< |
windowName.nitems = strlen(windowName.value); |
402 |
> |
windowName.nitems = strlen((char *)windowName.value); |
403 |
|
iconName.value = (u_char *)name; |
404 |
< |
iconName.nitems = strlen(windowName.value); |
404 |
> |
iconName.nitems = strlen((char *)windowName.value); |
405 |
|
|
406 |
|
xclshints.res_name = NULL; |
407 |
|
xclshints.res_class = "Ximage"; |
420 |
|
char *err |
421 |
|
) |
422 |
|
{ |
423 |
< |
register int es; |
423 |
> |
int es; |
424 |
|
int cs; |
425 |
|
|
426 |
< |
if ( (es = err != NULL) ) |
426 |
> |
if ( (es = (err != NULL)) ) |
427 |
|
fprintf(stderr, "%s: %s: %s\n", progname, |
428 |
|
fname==NULL?"<stdin>":fname, err); |
429 |
|
if (thedisplay != NULL) |
441 |
|
|
442 |
|
static int |
443 |
|
viscmp( /* compare visual to see which is better, descending */ |
444 |
< |
register XVisualInfo *v1, |
445 |
< |
register XVisualInfo *v2 |
444 |
> |
XVisualInfo *v1, |
445 |
> |
XVisualInfo *v2 |
446 |
|
) |
447 |
|
{ |
448 |
|
int bad1 = 0, bad2 = 0; |
449 |
< |
register int *rp; |
449 |
> |
int *rp; |
450 |
|
|
451 |
|
if (v1->class == v2->class) { |
452 |
< |
if (v1->class == TrueColor || v1->class == DirectColor) { |
453 |
< |
/* prefer 24-bit to 32-bit */ |
454 |
< |
if (v1->depth == 24 && v2->depth == 32) |
452 |
> |
if ((v1->class == TrueColor) | (v1->class == DirectColor)) { |
453 |
> |
/* prefer 24-bit */ |
454 |
> |
if ((v1->depth == 24) & (v2->depth > 24)) |
455 |
|
return(-1); |
456 |
< |
if (v1->depth == 32 && v2->depth == 24) |
456 |
> |
if ((v1->depth > 24) & (v2->depth == 24)) |
457 |
|
return(1); |
458 |
|
/* go for maximum depth otherwise */ |
459 |
|
return(v2->depth - v1->depth); |
460 |
|
} |
461 |
|
/* don't be too greedy */ |
462 |
< |
if (maxcolors <= 1<<v1->depth && maxcolors <= 1<<v2->depth) |
462 |
> |
if ((maxcolors <= 1<<v1->depth) & (maxcolors <= 1<<v2->depth)) |
463 |
|
return(v1->depth - v2->depth); |
464 |
|
return(v2->depth - v1->depth); |
465 |
|
} |
466 |
|
/* prefer Pseudo when < 15-bit */ |
467 |
< |
if ((v1->class == TrueColor || v1->class == DirectColor) && |
467 |
> |
if ((v1->class == TrueColor) | (v1->class == DirectColor) && |
468 |
|
v1->depth < 15) |
469 |
|
bad1 = 1; |
470 |
< |
if ((v2->class == TrueColor || v2->class == DirectColor) && |
470 |
> |
if ((v2->class == TrueColor) | (v2->class == DirectColor) && |
471 |
|
v2->depth < 15) |
472 |
|
bad2 = -1; |
473 |
|
if (bad1 | bad2) |
503 |
|
}; |
504 |
|
XVisualInfo *xvi; |
505 |
|
int vismatched; |
506 |
< |
register int i, j; |
506 |
> |
int i, j; |
507 |
|
|
508 |
|
if (greyscale) { |
509 |
|
ourrank = rankings[2]; |
573 |
|
ourdata = (unsigned char *)malloc(ymax*((xmax+7)/8)); |
574 |
|
if (ourdata == NULL) |
575 |
|
goto fail; |
576 |
< |
ourras = make_raster(thedisplay, &ourvis, 1, ourdata, |
576 |
> |
ourras = make_raster(thedisplay, &ourvis, 1, (char *)ourdata, |
577 |
|
xmax, ymax, 8); |
578 |
|
if (ourras == NULL) |
579 |
|
goto fail; |
584 |
|
if (ourdata == NULL) |
585 |
|
goto fail; |
586 |
|
ourras = make_raster(thedisplay, &ourvis, datsiz*8, |
587 |
< |
ourdata, xmax, ymax, datsiz*8); |
587 |
> |
(char *)ourdata, xmax, ymax, datsiz*8); |
588 |
|
if (ourras == NULL) |
589 |
|
goto fail; |
590 |
|
getfull(); |
592 |
|
ourdata = (unsigned char *)malloc(xmax*ymax); |
593 |
|
if (ourdata == NULL) |
594 |
|
goto fail; |
595 |
< |
ourras = make_raster(thedisplay, &ourvis, 8, ourdata, |
595 |
> |
ourras = make_raster(thedisplay, &ourvis, 8, (char *)ourdata, |
596 |
|
xmax, ymax, 8); |
597 |
|
if (ourras == NULL) |
598 |
|
goto fail; |
674 |
|
RREAL hv[2]; |
675 |
|
FVECT rorg, rdir; |
676 |
|
COLOR cval; |
677 |
< |
register char *cp; |
677 |
> |
char *cp; |
678 |
|
|
679 |
|
bbox.xmin = xpos; bbox.xsiz = 1; |
680 |
|
bbox.ymin = ypos; bbox.ysiz = 1; |
952 |
|
|
953 |
|
static void |
954 |
|
colavg( |
955 |
< |
register COLR *scn, |
956 |
< |
register int n, |
955 |
> |
COLR *scn, |
956 |
> |
int n, |
957 |
|
void *cavg |
958 |
|
) |
959 |
|
{ |
960 |
|
COLOR col; |
961 |
|
|
962 |
|
while (n--) { |
963 |
< |
colr_color(col, *scn++); |
963 |
> |
colr_color(col, *scn); |
964 |
|
addcolor((COLORV*)cavg, col); |
965 |
+ |
scn++; |
966 |
|
} |
967 |
|
} |
968 |
|
|
973 |
|
) |
974 |
|
{ |
975 |
|
double d; |
976 |
< |
register int rval; |
976 |
> |
int rval; |
977 |
|
|
978 |
|
setcolor(cavg, 0., 0., 0.); |
979 |
< |
rval = dobox(colavg, (void *)cavg); |
979 |
> |
rval = dobox(colavg, cavg); |
980 |
|
if (rval > 0) { |
981 |
|
d = 1./rval; |
982 |
|
scalecolor(cavg, d); |
987 |
|
|
988 |
|
static int |
989 |
|
dobox( /* run function over bbox */ |
987 |
– |
//void (*f)(), /* function to call for each subscan */ |
990 |
|
doboxf_t *f, /* function to call for each subscan */ |
991 |
|
void *p /* pointer to private data */ |
992 |
|
) |
1011 |
|
if (top >= bottom) |
1012 |
|
return(0); |
1013 |
|
for (y = top; y < bottom; y++) { |
1014 |
< |
if (getscan(y) == -1) |
1014 |
> |
if (getscan(y) < 0) |
1015 |
|
return(-1); |
1016 |
|
(*f)(scanline+left, right-left, p); |
1017 |
|
} |
1062 |
|
goto memerr; |
1063 |
|
if (greyscale) { |
1064 |
|
cscan = TM_NOCHROM; |
1065 |
< |
if ((pscan = (BYTE *)malloc(sizeof(BYTE)*xmax)) == NULL) |
1065 |
> |
if ((pscan = (uby8 *)malloc(sizeof(uby8)*xmax)) == NULL) |
1066 |
|
goto memerr; |
1067 |
< |
} else if ((pscan=cscan = (BYTE *)malloc(3*sizeof(BYTE)*xmax)) |
1067 |
> |
} else if ((pscan=cscan = (uby8 *)malloc(3*sizeof(uby8)*xmax)) |
1068 |
|
== NULL) |
1069 |
|
goto memerr; |
1070 |
|
/* initialize tm library */ |
1084 |
|
} |
1085 |
|
} |
1086 |
|
tmCurrent = tmDup(tmGlobal); /* add fixations to duplicate map */ |
1087 |
< |
dobox(addfix, (void *)tmCurrent); |
1087 |
> |
dobox(addfix, tmCurrent); |
1088 |
|
/* (re)compute tone mapping */ |
1089 |
|
if (tmComputeMapping(tmCurrent, gamcor, 0., 0.)) |
1090 |
|
goto tmerr; |
1098 |
|
|
1099 |
|
static void |
1100 |
|
tmap_colrs( /* apply tone mapping to scanline */ |
1101 |
< |
register COLR *scn, |
1101 |
> |
COLR *scn, |
1102 |
|
int len |
1103 |
|
) |
1104 |
|
{ |
1105 |
< |
register BYTE *ps; |
1105 |
> |
uby8 *ps; |
1106 |
|
|
1107 |
|
if (tmflags == TM_F_LINEAR) { |
1108 |
|
if (scale) |
1140 |
|
static void |
1141 |
|
getmono(void) /* get monochrome data */ |
1142 |
|
{ |
1143 |
< |
register unsigned char *dp; |
1144 |
< |
register int x, err; |
1143 |
> |
unsigned char *dp; |
1144 |
> |
int x, err; |
1145 |
|
int y, errp; |
1146 |
|
short *cerr; |
1147 |
|
|
1166 |
|
cerr[x] = err + errp; |
1167 |
|
} |
1168 |
|
} |
1169 |
< |
free((void *)cerr); |
1169 |
> |
free(cerr); |
1170 |
|
} |
1171 |
|
|
1172 |
|
|
1180 |
|
static int ynext; |
1181 |
|
static char *dp; |
1182 |
|
COLR clr; |
1183 |
< |
register int err; |
1184 |
< |
register int x, ti; |
1183 |
> |
int err; |
1184 |
> |
int x, ti; |
1185 |
|
int errp; |
1186 |
|
|
1187 |
|
if (iconheight == 0) { /* initialize */ |
1228 |
|
getfull(void) /* get full (24-bit) data */ |
1229 |
|
{ |
1230 |
|
int y; |
1231 |
< |
register uint32 *dp; |
1232 |
< |
register uint16 *dph; |
1233 |
< |
register int x; |
1231 |
> |
uint32 *dp; |
1232 |
> |
uint16 *dph; |
1233 |
> |
int x; |
1234 |
|
/* initialize tone mapping */ |
1235 |
|
make_tonemap(); |
1236 |
|
/* read and convert file */ |
1296 |
|
getgrey(void) /* get greyscale data */ |
1297 |
|
{ |
1298 |
|
int y; |
1299 |
< |
register unsigned char *dp; |
1300 |
< |
register int x; |
1299 |
> |
unsigned char *dp; |
1300 |
> |
int x; |
1301 |
|
/* initialize tone mapping */ |
1302 |
|
make_tonemap(); |
1303 |
|
/* read and convert file */ |
1355 |
|
|
1356 |
|
static void |
1357 |
|
scale_rcolors( /* scale color map */ |
1358 |
< |
register XRASTER *xr, |
1358 |
> |
XRASTER *xr, |
1359 |
|
double sf |
1360 |
|
) |
1361 |
|
{ |
1362 |
< |
register int i; |
1362 |
> |
int i; |
1363 |
|
long maxv; |
1364 |
|
|
1365 |
|
if (xr->pixels == NULL) |
1390 |
|
{ |
1391 |
|
static int trunced = -1; /* truncated file? */ |
1392 |
|
skipit: |
1393 |
< |
if (trunced >= 0 && y >= trunced) { |
1394 |
< |
memset(scanline, '\0', xmax*sizeof(COLR)); |
1393 |
> |
if (y == cury-1) /* already got it? */ |
1394 |
> |
return(0); |
1395 |
> |
if ((trunced >= 0) & (y >= trunced)) { |
1396 |
> |
memset(scanline, 0, xmax*sizeof(COLR)); |
1397 |
|
return(-1); |
1398 |
|
} |
1399 |
|
if (y != cury) { |
1400 |
< |
if (scanpos == NULL || scanpos[y] == -1) |
1400 |
> |
if (scanpos == NULL || scanpos[y] < 0) |
1401 |
|
return(-1); |
1402 |
< |
if (fseek(fin, scanpos[y], 0) == -1) |
1402 |
> |
if (fseek(fin, scanpos[y], 0) < 0) |
1403 |
|
quiterr("fseek error"); |
1404 |
|
cury = y; |
1405 |
< |
} else if (scanpos != NULL && scanpos[y] == -1) |
1405 |
> |
} else if (scanpos != NULL && scanpos[y] < 0) |
1406 |
|
scanpos[y] = ftell(fin); |
1407 |
|
|
1408 |
< |
if (freadcolrs(scanline, xmax, fin) < 0) { |
1408 |
> |
if (fread2colrs(scanline, xmax, fin, NCSAMP, WLPART) < 0) { |
1409 |
|
fprintf(stderr, "%s: %s: unfinished picture\n", |
1410 |
|
progname, fname==NULL?"<stdin>":fname); |
1411 |
|
trunced = y; |