18 |
|
|
19 |
|
#include "standard.h" |
20 |
|
|
21 |
– |
#include <string.h> |
21 |
|
#include <signal.h> |
23 |
– |
#include <unistd.h> |
24 |
– |
#include <sys/types.h> |
22 |
|
#include <sys/wait.h> |
23 |
|
#include <X11/Xlib.h> |
24 |
|
#include <X11/cursorfont.h> |
25 |
|
#include <X11/Xutil.h> |
26 |
|
#include <X11/Xatom.h> |
27 |
|
|
28 |
+ |
#include "paths.h" |
29 |
|
#include "color.h" |
30 |
|
#include "tonemap.h" |
31 |
|
#include "clrtab.h" |
81 |
|
|
82 |
|
COLR *scanline; /* scan line buffer */ |
83 |
|
TMbright *lscan; /* encoded luminance scanline */ |
84 |
< |
BYTE *cscan; /* encoded chroma scanline */ |
85 |
< |
BYTE *pscan; /* compute pixel scanline */ |
84 |
> |
uby8 *cscan; /* encoded chroma scanline */ |
85 |
> |
uby8 *pscan; /* compute pixel scanline */ |
86 |
|
|
87 |
|
RESOLU inpres; /* input resolution and ordering */ |
88 |
|
int xmax, ymax; /* picture dimensions */ |
116 |
|
char icondata[ICONSIZ*ICONSIZ/8]; /* icon bitmap data */ |
117 |
|
int iconwidth = 0, iconheight = 0; |
118 |
|
|
121 |
– |
char *progname; |
122 |
– |
|
119 |
|
char errmsg[128]; |
120 |
|
|
121 |
< |
BYTE clrtab[256][3]; /* global color map */ |
121 |
> |
uby8 clrtab[256][3]; /* global color map */ |
122 |
|
|
123 |
|
|
124 |
|
Display *thedisplay; |
164 |
|
int i; |
165 |
|
int pid; |
166 |
|
|
167 |
< |
progname = argv[0]; |
167 |
> |
fixargv0(argv[0]); /* sets global progname */ |
168 |
|
fin = stdin; |
169 |
|
|
170 |
|
for (i = 1; i < argc; i++) |
267 |
|
getevent(); /* main loop */ |
268 |
|
userr: |
269 |
|
fprintf(stderr, |
270 |
< |
"Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e spec][-g gamcor][-s][-ospec][-t intvl] pic ..\n", |
270 |
> |
"Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e spec][-g gamcor][-s][-ospec][-t intvl] hdr ..\n", |
271 |
|
progname); |
272 |
|
exit(1); |
273 |
|
} |
279 |
|
void *p |
280 |
|
) |
281 |
|
{ |
282 |
< |
char fmt[32]; |
282 |
> |
char fmt[MAXFMTLEN]; |
283 |
|
|
284 |
|
if (isexpos(s)) |
285 |
|
exposure *= exposval(s); |
286 |
|
else if (formatval(fmt, s)) |
287 |
< |
wrongformat = strcmp(fmt, COLRFMT); |
288 |
< |
else if (isview(s) && sscanview(&ourview, s) > 0) |
289 |
< |
gotview++; |
287 |
> |
wrongformat = strcmp(fmt, COLRFMT) && strcmp(fmt, SPECFMT); |
288 |
> |
else if (isview(s)) |
289 |
> |
gotview += sscanview(&ourview, s); |
290 |
> |
else if (isncomp(s)) |
291 |
> |
NCSAMP = ncompval(s); |
292 |
> |
else if (iswlsplit(s)) |
293 |
> |
wlsplitval(WLPART, s); |
294 |
|
return(0); |
295 |
|
} |
296 |
|
|
308 |
|
XTextProperty windowName, iconName; |
309 |
|
XGCValues xgcv; |
310 |
|
char *name; |
311 |
< |
register int i; |
311 |
> |
int i; |
312 |
|
|
313 |
|
if (fname != NULL) { |
314 |
|
scanpos = (long *)malloc(ymax*sizeof(long)); |
397 |
|
windowName.encoding = iconName.encoding = XA_STRING; |
398 |
|
windowName.format = iconName.format = 8; |
399 |
|
windowName.value = (u_char *)name; |
400 |
< |
windowName.nitems = strlen(windowName.value); |
400 |
> |
windowName.nitems = strlen((char *)windowName.value); |
401 |
|
iconName.value = (u_char *)name; |
402 |
< |
iconName.nitems = strlen(windowName.value); |
402 |
> |
iconName.nitems = strlen((char *)windowName.value); |
403 |
|
|
404 |
|
xclshints.res_name = NULL; |
405 |
|
xclshints.res_class = "Ximage"; |
418 |
|
char *err |
419 |
|
) |
420 |
|
{ |
421 |
< |
register int es; |
421 |
> |
int es; |
422 |
|
int cs; |
423 |
|
|
424 |
< |
if ( (es = err != NULL) ) |
424 |
> |
if ( (es = (err != NULL)) ) |
425 |
|
fprintf(stderr, "%s: %s: %s\n", progname, |
426 |
|
fname==NULL?"<stdin>":fname, err); |
427 |
|
if (thedisplay != NULL) |
439 |
|
|
440 |
|
static int |
441 |
|
viscmp( /* compare visual to see which is better, descending */ |
442 |
< |
register XVisualInfo *v1, |
443 |
< |
register XVisualInfo *v2 |
442 |
> |
XVisualInfo *v1, |
443 |
> |
XVisualInfo *v2 |
444 |
|
) |
445 |
|
{ |
446 |
|
int bad1 = 0, bad2 = 0; |
447 |
< |
register int *rp; |
447 |
> |
int *rp; |
448 |
|
|
449 |
|
if (v1->class == v2->class) { |
450 |
< |
if (v1->class == TrueColor || v1->class == DirectColor) { |
451 |
< |
/* prefer 24-bit to 32-bit */ |
452 |
< |
if (v1->depth == 24 && v2->depth == 32) |
450 |
> |
if ((v1->class == TrueColor) | (v1->class == DirectColor)) { |
451 |
> |
/* prefer 24-bit */ |
452 |
> |
if ((v1->depth == 24) & (v2->depth > 24)) |
453 |
|
return(-1); |
454 |
< |
if (v1->depth == 32 && v2->depth == 24) |
454 |
> |
if ((v1->depth > 24) & (v2->depth == 24)) |
455 |
|
return(1); |
456 |
|
/* go for maximum depth otherwise */ |
457 |
|
return(v2->depth - v1->depth); |
458 |
|
} |
459 |
|
/* don't be too greedy */ |
460 |
< |
if (maxcolors <= 1<<v1->depth && maxcolors <= 1<<v2->depth) |
460 |
> |
if ((maxcolors <= 1<<v1->depth) & (maxcolors <= 1<<v2->depth)) |
461 |
|
return(v1->depth - v2->depth); |
462 |
|
return(v2->depth - v1->depth); |
463 |
|
} |
464 |
|
/* prefer Pseudo when < 15-bit */ |
465 |
< |
if ((v1->class == TrueColor || v1->class == DirectColor) && |
465 |
> |
if ((v1->class == TrueColor) | (v1->class == DirectColor) && |
466 |
|
v1->depth < 15) |
467 |
|
bad1 = 1; |
468 |
< |
if ((v2->class == TrueColor || v2->class == DirectColor) && |
468 |
> |
if ((v2->class == TrueColor) | (v2->class == DirectColor) && |
469 |
|
v2->depth < 15) |
470 |
|
bad2 = -1; |
471 |
|
if (bad1 | bad2) |
501 |
|
}; |
502 |
|
XVisualInfo *xvi; |
503 |
|
int vismatched; |
504 |
< |
register int i, j; |
504 |
> |
int i, j; |
505 |
|
|
506 |
|
if (greyscale) { |
507 |
|
ourrank = rankings[2]; |
571 |
|
ourdata = (unsigned char *)malloc(ymax*((xmax+7)/8)); |
572 |
|
if (ourdata == NULL) |
573 |
|
goto fail; |
574 |
< |
ourras = make_raster(thedisplay, &ourvis, 1, ourdata, |
574 |
> |
ourras = make_raster(thedisplay, &ourvis, 1, (char *)ourdata, |
575 |
|
xmax, ymax, 8); |
576 |
|
if (ourras == NULL) |
577 |
|
goto fail; |
582 |
|
if (ourdata == NULL) |
583 |
|
goto fail; |
584 |
|
ourras = make_raster(thedisplay, &ourvis, datsiz*8, |
585 |
< |
ourdata, xmax, ymax, datsiz*8); |
585 |
> |
(char *)ourdata, xmax, ymax, datsiz*8); |
586 |
|
if (ourras == NULL) |
587 |
|
goto fail; |
588 |
|
getfull(); |
590 |
|
ourdata = (unsigned char *)malloc(xmax*ymax); |
591 |
|
if (ourdata == NULL) |
592 |
|
goto fail; |
593 |
< |
ourras = make_raster(thedisplay, &ourvis, 8, ourdata, |
593 |
> |
ourras = make_raster(thedisplay, &ourvis, 8, (char *)ourdata, |
594 |
|
xmax, ymax, 8); |
595 |
|
if (ourras == NULL) |
596 |
|
goto fail; |
672 |
|
RREAL hv[2]; |
673 |
|
FVECT rorg, rdir; |
674 |
|
COLOR cval; |
675 |
< |
register char *cp; |
675 |
> |
char *cp; |
676 |
|
|
677 |
|
bbox.xmin = xpos; bbox.xsiz = 1; |
678 |
|
bbox.ymin = ypos; bbox.ysiz = 1; |
950 |
|
|
951 |
|
static void |
952 |
|
colavg( |
953 |
< |
register COLR *scn, |
954 |
< |
register int n, |
953 |
> |
COLR *scn, |
954 |
> |
int n, |
955 |
|
void *cavg |
956 |
|
) |
957 |
|
{ |
958 |
|
COLOR col; |
959 |
|
|
960 |
|
while (n--) { |
961 |
< |
colr_color(col, *scn++); |
961 |
> |
colr_color(col, *scn); |
962 |
|
addcolor((COLORV*)cavg, col); |
963 |
+ |
scn++; |
964 |
|
} |
965 |
|
} |
966 |
|
|
971 |
|
) |
972 |
|
{ |
973 |
|
double d; |
974 |
< |
register int rval; |
974 |
> |
int rval; |
975 |
|
|
976 |
|
setcolor(cavg, 0., 0., 0.); |
977 |
< |
rval = dobox(colavg, (void *)cavg); |
977 |
> |
rval = dobox(colavg, cavg); |
978 |
|
if (rval > 0) { |
979 |
|
d = 1./rval; |
980 |
|
scalecolor(cavg, d); |
985 |
|
|
986 |
|
static int |
987 |
|
dobox( /* run function over bbox */ |
987 |
– |
//void (*f)(), /* function to call for each subscan */ |
988 |
|
doboxf_t *f, /* function to call for each subscan */ |
989 |
|
void *p /* pointer to private data */ |
990 |
|
) |
1009 |
|
if (top >= bottom) |
1010 |
|
return(0); |
1011 |
|
for (y = top; y < bottom; y++) { |
1012 |
< |
if (getscan(y) == -1) |
1012 |
> |
if (getscan(y) < 0) |
1013 |
|
return(-1); |
1014 |
|
(*f)(scanline+left, right-left, p); |
1015 |
|
} |
1060 |
|
goto memerr; |
1061 |
|
if (greyscale) { |
1062 |
|
cscan = TM_NOCHROM; |
1063 |
< |
if ((pscan = (BYTE *)malloc(sizeof(BYTE)*xmax)) == NULL) |
1063 |
> |
if ((pscan = (uby8 *)malloc(sizeof(uby8)*xmax)) == NULL) |
1064 |
|
goto memerr; |
1065 |
< |
} else if ((pscan=cscan = (BYTE *)malloc(3*sizeof(BYTE)*xmax)) |
1065 |
> |
} else if ((pscan=cscan = (uby8 *)malloc(3*sizeof(uby8)*xmax)) |
1066 |
|
== NULL) |
1067 |
|
goto memerr; |
1068 |
|
/* initialize tm library */ |
1069 |
|
tmGlobal = tmInit(flags, stdprims, gamcor); |
1070 |
|
if (tmGlobal == NULL) |
1071 |
|
goto memerr; |
1072 |
< |
if (tmSetSpace(tmGlobal, stdprims, WHTEFFICACY/exposure, NULL)) |
1072 |
> |
if (tmSetSpace(tmGlobal, stdprims, WHTEFFICACY/exposure)) |
1073 |
|
goto tmerr; |
1074 |
|
/* compute picture histogram */ |
1075 |
|
for (y = 0; y < ymax; y++) { |
1082 |
|
} |
1083 |
|
} |
1084 |
|
tmCurrent = tmDup(tmGlobal); /* add fixations to duplicate map */ |
1085 |
< |
dobox(addfix, (void *)tmCurrent); |
1085 |
> |
dobox(addfix, tmCurrent); |
1086 |
|
/* (re)compute tone mapping */ |
1087 |
|
if (tmComputeMapping(tmCurrent, gamcor, 0., 0.)) |
1088 |
|
goto tmerr; |
1096 |
|
|
1097 |
|
static void |
1098 |
|
tmap_colrs( /* apply tone mapping to scanline */ |
1099 |
< |
register COLR *scn, |
1099 |
> |
COLR *scn, |
1100 |
|
int len |
1101 |
|
) |
1102 |
|
{ |
1103 |
< |
register BYTE *ps; |
1103 |
> |
uby8 *ps; |
1104 |
|
|
1105 |
|
if (tmflags == TM_F_LINEAR) { |
1106 |
|
if (scale) |
1138 |
|
static void |
1139 |
|
getmono(void) /* get monochrome data */ |
1140 |
|
{ |
1141 |
< |
register unsigned char *dp; |
1142 |
< |
register int x, err; |
1141 |
> |
unsigned char *dp; |
1142 |
> |
int x, err; |
1143 |
|
int y, errp; |
1144 |
|
short *cerr; |
1145 |
|
|
1164 |
|
cerr[x] = err + errp; |
1165 |
|
} |
1166 |
|
} |
1167 |
< |
free((void *)cerr); |
1167 |
> |
free(cerr); |
1168 |
|
} |
1169 |
|
|
1170 |
|
|
1178 |
|
static int ynext; |
1179 |
|
static char *dp; |
1180 |
|
COLR clr; |
1181 |
< |
register int err; |
1182 |
< |
register int x, ti; |
1181 |
> |
int err; |
1182 |
> |
int x, ti; |
1183 |
|
int errp; |
1184 |
|
|
1185 |
|
if (iconheight == 0) { /* initialize */ |
1226 |
|
getfull(void) /* get full (24-bit) data */ |
1227 |
|
{ |
1228 |
|
int y; |
1229 |
< |
register uint32 *dp; |
1230 |
< |
register uint16 *dph; |
1231 |
< |
register int x; |
1229 |
> |
uint32 *dp; |
1230 |
> |
uint16 *dph; |
1231 |
> |
int x; |
1232 |
|
/* initialize tone mapping */ |
1233 |
|
make_tonemap(); |
1234 |
|
/* read and convert file */ |
1294 |
|
getgrey(void) /* get greyscale data */ |
1295 |
|
{ |
1296 |
|
int y; |
1297 |
< |
register unsigned char *dp; |
1298 |
< |
register int x; |
1297 |
> |
unsigned char *dp; |
1298 |
> |
int x; |
1299 |
|
/* initialize tone mapping */ |
1300 |
|
make_tonemap(); |
1301 |
|
/* read and convert file */ |
1353 |
|
|
1354 |
|
static void |
1355 |
|
scale_rcolors( /* scale color map */ |
1356 |
< |
register XRASTER *xr, |
1356 |
> |
XRASTER *xr, |
1357 |
|
double sf |
1358 |
|
) |
1359 |
|
{ |
1360 |
< |
register int i; |
1360 |
> |
int i; |
1361 |
|
long maxv; |
1362 |
|
|
1363 |
|
if (xr->pixels == NULL) |
1388 |
|
{ |
1389 |
|
static int trunced = -1; /* truncated file? */ |
1390 |
|
skipit: |
1391 |
< |
if (trunced >= 0 && y >= trunced) { |
1392 |
< |
memset(scanline, '\0', xmax*sizeof(COLR)); |
1391 |
> |
if (y == cury-1) /* already got it? */ |
1392 |
> |
return(0); |
1393 |
> |
if ((trunced >= 0) & (y >= trunced)) { |
1394 |
> |
memset(scanline, 0, xmax*sizeof(COLR)); |
1395 |
|
return(-1); |
1396 |
|
} |
1397 |
|
if (y != cury) { |
1398 |
< |
if (scanpos == NULL || scanpos[y] == -1) |
1398 |
> |
if (scanpos == NULL || scanpos[y] < 0) |
1399 |
|
return(-1); |
1400 |
< |
if (fseek(fin, scanpos[y], 0) == -1) |
1400 |
> |
if (fseek(fin, scanpos[y], 0) < 0) |
1401 |
|
quiterr("fseek error"); |
1402 |
|
cury = y; |
1403 |
< |
} else if (scanpos != NULL && scanpos[y] == -1) |
1403 |
> |
} else if (scanpos != NULL && scanpos[y] < 0) |
1404 |
|
scanpos[y] = ftell(fin); |
1405 |
|
|
1406 |
< |
if (freadcolrs(scanline, xmax, fin) < 0) { |
1406 |
> |
if (fread2colrs(scanline, xmax, fin, NCSAMP, WLPART) < 0) { |
1407 |
|
fprintf(stderr, "%s: %s: unfinished picture\n", |
1408 |
|
progname, fname==NULL?"<stdin>":fname); |
1409 |
|
trunced = y; |