| 1 |
|
#ifndef lint |
| 2 |
< |
static const char RCSid[] = "$Id"; |
| 2 |
> |
static const char RCSid[] = "$Id$"; |
| 3 |
|
#endif |
| 4 |
|
/* |
| 5 |
|
* x11image.c - driver for X-windows |
| 22 |
|
#include <signal.h> |
| 23 |
|
#include <unistd.h> |
| 24 |
|
#include <sys/types.h> |
| 25 |
< |
#include <wait.h> |
| 25 |
> |
#include <sys/wait.h> |
| 26 |
|
#include <X11/Xlib.h> |
| 27 |
|
#include <X11/cursorfont.h> |
| 28 |
|
#include <X11/Xutil.h> |
| 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 */ |
| 98 |
|
|
| 99 |
|
int wrongformat = 0; /* input in another format? */ |
| 100 |
|
|
| 101 |
+ |
TMstruct *tmGlobal; /* base tone-mapping */ |
| 102 |
+ |
TMstruct *tmCurrent; /* curren tone-mapping */ |
| 103 |
+ |
|
| 104 |
|
GC ourgc; /* standard graphics context */ |
| 105 |
|
GC revgc; /* graphics context with GXinvert */ |
| 106 |
|
|
| 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 |
|
} |
| 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"; |
| 421 |
|
register 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) |
| 447 |
|
register 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) |
| 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; |
| 973 |
|
register int rval; |
| 974 |
|
|
| 975 |
|
setcolor(cavg, 0., 0., 0.); |
| 976 |
< |
rval = dobox(colavg, (char *)cavg); |
| 976 |
> |
rval = dobox(colavg, (void *)cavg); |
| 977 |
|
if (rval > 0) { |
| 978 |
|
d = 1./rval; |
| 979 |
|
scalecolor(cavg, d); |
| 1021 |
|
addfix( /* add fixation points to histogram */ |
| 1022 |
|
COLR *scn, |
| 1023 |
|
int n, |
| 1024 |
< |
void *p /*NOTUSED*/ |
| 1024 |
> |
void *p |
| 1025 |
|
) |
| 1026 |
|
{ |
| 1027 |
< |
if (tmCvColrs(lscan, TM_NOCHROM, scn, n)) |
| 1027 |
> |
TMstruct * tms = (TMstruct *)p; |
| 1028 |
> |
|
| 1029 |
> |
if (tmCvColrs(tms, lscan, TM_NOCHROM, scn, n)) |
| 1030 |
|
goto tmerr; |
| 1031 |
< |
if (tmAddHisto(lscan, n, FIXWEIGHT)) |
| 1031 |
> |
if (tmAddHisto(tms, lscan, n, FIXWEIGHT)) |
| 1032 |
|
goto tmerr; |
| 1033 |
|
return; |
| 1034 |
|
tmerr: |
| 1052 |
|
} |
| 1053 |
|
flags = tmflags; /* histogram adjustment */ |
| 1054 |
|
if (greyscale) flags |= TM_F_BW; |
| 1055 |
< |
if (tmTop != NULL) { /* reuse old histogram if one */ |
| 1056 |
< |
tmDone(tmTop); |
| 1057 |
< |
tmTop->flags = flags; |
| 1055 |
> |
if (tmGlobal != NULL) { /* reuse old histogram if one */ |
| 1056 |
> |
tmDone(tmCurrent); tmCurrent = NULL; |
| 1057 |
> |
tmGlobal->flags = flags; |
| 1058 |
|
} else { /* else initialize */ |
| 1059 |
|
if ((lscan = (TMbright *)malloc(xmax*sizeof(TMbright))) == NULL) |
| 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 |
< |
if (tmInit(flags, stdprims, gamcor) == NULL) |
| 1069 |
> |
tmGlobal = tmInit(flags, stdprims, gamcor); |
| 1070 |
> |
if (tmGlobal == NULL) |
| 1071 |
|
goto memerr; |
| 1072 |
< |
if (tmSetSpace(stdprims, WHTEFFICACY/exposure)) |
| 1072 |
> |
if (tmSetSpace(tmGlobal, stdprims, WHTEFFICACY/exposure, NULL)) |
| 1073 |
|
goto tmerr; |
| 1074 |
|
/* compute picture histogram */ |
| 1075 |
|
for (y = 0; y < ymax; y++) { |
| 1076 |
|
getscan(y); |
| 1077 |
< |
if (tmCvColrs(lscan, TM_NOCHROM, scanline, xmax)) |
| 1077 |
> |
if (tmCvColrs(tmGlobal, lscan, TM_NOCHROM, |
| 1078 |
> |
scanline, xmax)) |
| 1079 |
|
goto tmerr; |
| 1080 |
< |
if (tmAddHisto(lscan, xmax, 1)) |
| 1080 |
> |
if (tmAddHisto(tmGlobal, lscan, xmax, 1)) |
| 1081 |
|
goto tmerr; |
| 1082 |
|
} |
| 1083 |
|
} |
| 1084 |
< |
tmDup(); /* add fixations to duplicate map */ |
| 1085 |
< |
dobox(addfix, NULL); |
| 1084 |
> |
tmCurrent = tmDup(tmGlobal); /* add fixations to duplicate map */ |
| 1085 |
> |
dobox(addfix, (void *)tmCurrent); |
| 1086 |
|
/* (re)compute tone mapping */ |
| 1087 |
< |
if (tmComputeMapping(gamcor, 0., 0.)) |
| 1087 |
> |
if (tmComputeMapping(tmCurrent, gamcor, 0., 0.)) |
| 1088 |
|
goto tmerr; |
| 1089 |
|
return; |
| 1090 |
|
memerr: |
| 1100 |
|
int len |
| 1101 |
|
) |
| 1102 |
|
{ |
| 1103 |
< |
register BYTE *ps; |
| 1103 |
> |
register uby8 *ps; |
| 1104 |
|
|
| 1105 |
|
if (tmflags == TM_F_LINEAR) { |
| 1106 |
|
if (scale) |
| 1110 |
|
} |
| 1111 |
|
if (len > xmax) |
| 1112 |
|
quiterr("code error 1 in tmap_colrs"); |
| 1113 |
< |
if (tmCvColrs(lscan, cscan, scn, len)) |
| 1113 |
> |
if (tmCvColrs(tmCurrent, lscan, cscan, scn, len)) |
| 1114 |
|
goto tmerr; |
| 1115 |
< |
if (tmMapPixels(pscan, lscan, cscan, len)) |
| 1115 |
> |
if (tmMapPixels(tmCurrent, pscan, lscan, cscan, len)) |
| 1116 |
|
goto tmerr; |
| 1117 |
|
ps = pscan; |
| 1118 |
|
if (greyscale) |