| 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 |
| 18 |
|
|
| 19 |
|
#include "standard.h" |
| 20 |
|
|
| 21 |
+ |
#include <string.h> |
| 22 |
|
#include <signal.h> |
| 23 |
+ |
#include <unistd.h> |
| 24 |
+ |
#include <sys/types.h> |
| 25 |
+ |
#include <sys/wait.h> |
| 26 |
|
#include <X11/Xlib.h> |
| 27 |
|
#include <X11/cursorfont.h> |
| 28 |
|
#include <X11/Xutil.h> |
| 30 |
|
|
| 31 |
|
#include "color.h" |
| 32 |
|
#include "tonemap.h" |
| 33 |
+ |
#include "clrtab.h" |
| 34 |
|
#include "view.h" |
| 35 |
|
#include "x11raster.h" |
| 36 |
|
#include "random.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 |
|
|
| 119 |
– |
extern long ftell(); |
| 127 |
|
|
| 121 |
– |
extern char *getenv(); |
| 122 |
– |
|
| 128 |
|
Display *thedisplay; |
| 129 |
|
Atom closedownAtom, wmProtocolsAtom; |
| 130 |
|
|
| 131 |
|
int sigrecv; |
| 132 |
|
|
| 133 |
< |
int onsig() { sigrecv++; } |
| 133 |
> |
void onsig(int i) { sigrecv++; } |
| 134 |
|
|
| 135 |
+ |
typedef void doboxf_t(COLR *scn, int n, void *); |
| 136 |
|
|
| 137 |
< |
main(argc, argv) |
| 138 |
< |
int argc; |
| 139 |
< |
char *argv[]; |
| 137 |
> |
static gethfunc headline; |
| 138 |
> |
static void init(int argc, char **argv); |
| 139 |
> |
static void quiterr(char *err); |
| 140 |
> |
static int viscmp(XVisualInfo *v1, XVisualInfo *v2); |
| 141 |
> |
static void getbestvis(void); |
| 142 |
> |
static void getras(void); |
| 143 |
> |
static void getevent(void); |
| 144 |
> |
static int traceray(int xpos, int ypos); |
| 145 |
> |
static int docom(XKeyPressedEvent *ekey); |
| 146 |
> |
static void moveimage(XButtonPressedEvent *ebut); |
| 147 |
> |
static void getbox(XButtonPressedEvent *ebut); |
| 148 |
> |
static void trackrays(XButtonPressedEvent *ebut); |
| 149 |
> |
static void revbox(int x0, int y0, int x1, int y1); |
| 150 |
> |
static doboxf_t colavg; |
| 151 |
> |
static doboxf_t addfix; |
| 152 |
> |
static int avgbox(COLOR cavg); |
| 153 |
> |
static int dobox(doboxf_t *f, void *p); |
| 154 |
> |
static void make_tonemap(void); |
| 155 |
> |
static void tmap_colrs(COLR *scn, int len); |
| 156 |
> |
static void getmono(void); |
| 157 |
> |
static void add2icon(int y, COLR *scan); |
| 158 |
> |
static void getfull(void); |
| 159 |
> |
static void getgrey(void); |
| 160 |
> |
static void getmapped(void); |
| 161 |
> |
static void scale_rcolors(XRASTER *xr, double sf); |
| 162 |
> |
static int getscan(int y); |
| 163 |
> |
|
| 164 |
> |
|
| 165 |
> |
int |
| 166 |
> |
main(int argc, char *argv[]) |
| 167 |
|
{ |
| 135 |
– |
int headline(); |
| 168 |
|
int i; |
| 169 |
|
int pid; |
| 170 |
|
|
| 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 |
|
} |
| 278 |
|
|
| 279 |
|
|
| 280 |
< |
int |
| 281 |
< |
headline(s) /* get relevant info from header */ |
| 282 |
< |
char *s; |
| 280 |
> |
static int |
| 281 |
> |
headline( /* get relevant info from header */ |
| 282 |
> |
char *s, |
| 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 |
|
|
| 301 |
|
|
| 302 |
< |
init(argc, argv) /* get data and open window */ |
| 303 |
< |
int argc; |
| 304 |
< |
char **argv; |
| 302 |
> |
static void |
| 303 |
> |
init( /* get data and open window */ |
| 304 |
> |
int argc, |
| 305 |
> |
char **argv |
| 306 |
> |
) |
| 307 |
|
{ |
| 308 |
|
XSetWindowAttributes ourwinattr; |
| 309 |
|
XClassHint xclshints; |
| 401 |
|
windowName.encoding = iconName.encoding = XA_STRING; |
| 402 |
|
windowName.format = iconName.format = 8; |
| 403 |
|
windowName.value = (u_char *)name; |
| 404 |
< |
windowName.nitems = strlen(windowName.value); |
| 404 |
> |
windowName.nitems = strlen((char *)windowName.value); |
| 405 |
|
iconName.value = (u_char *)name; |
| 406 |
< |
iconName.nitems = strlen(windowName.value); |
| 406 |
> |
iconName.nitems = strlen((char *)windowName.value); |
| 407 |
|
|
| 408 |
|
xclshints.res_name = NULL; |
| 409 |
|
xclshints.res_class = "Ximage"; |
| 417 |
|
} /* end of init */ |
| 418 |
|
|
| 419 |
|
|
| 420 |
< |
quiterr(err) /* print message and exit */ |
| 421 |
< |
char *err; |
| 420 |
> |
static void |
| 421 |
> |
quiterr( /* print message and exit */ |
| 422 |
> |
char *err |
| 423 |
> |
) |
| 424 |
|
{ |
| 425 |
|
register 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) |
| 432 |
|
XCloseDisplay(thedisplay); |
| 433 |
< |
if (parent < 0 & sigrecv == 0) |
| 433 |
> |
if ((parent < 0) & (sigrecv == 0)) |
| 434 |
|
kill(getppid(), SIGCONT); |
| 435 |
|
while (parent > 0 && wait(&cs) != -1) { /* wait for any children */ |
| 436 |
|
if (es == 0) |
| 442 |
|
|
| 443 |
|
|
| 444 |
|
static int |
| 445 |
< |
viscmp(v1,v2) /* compare visual to see which is better, descending */ |
| 446 |
< |
register XVisualInfo *v1, *v2; |
| 445 |
> |
viscmp( /* compare visual to see which is better, descending */ |
| 446 |
> |
register XVisualInfo *v1, |
| 447 |
> |
register XVisualInfo *v2 |
| 448 |
> |
) |
| 449 |
|
{ |
| 450 |
|
int bad1 = 0, bad2 = 0; |
| 451 |
|
register 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) |
| 485 |
|
} |
| 486 |
|
|
| 487 |
|
|
| 488 |
< |
getbestvis() /* get the best visual for this screen */ |
| 488 |
> |
static void |
| 489 |
> |
getbestvis(void) /* get the best visual for this screen */ |
| 490 |
|
{ |
| 491 |
|
#ifdef DEBUG |
| 492 |
|
static char vistype[][12] = { |
| 538 |
|
if (viscmp(&xvi[i],&ourvis) > 0) |
| 539 |
|
quiterr("inadequate visuals on this screen"); |
| 540 |
|
/* OK, we'll use it */ |
| 541 |
< |
copystruct(&ourvis, &xvi[i]); |
| 541 |
> |
ourvis = xvi[i]; |
| 542 |
|
#ifdef DEBUG |
| 543 |
|
fprintf(stderr, "Selected visual type %s, depth %d\n", |
| 544 |
|
vistype[ourvis.class], ourvis.depth); |
| 568 |
|
} |
| 569 |
|
|
| 570 |
|
|
| 571 |
< |
getras() /* get raster file */ |
| 571 |
> |
static void |
| 572 |
> |
getras(void) /* get raster file */ |
| 573 |
|
{ |
| 528 |
– |
XVisualInfo vinfo; |
| 529 |
– |
|
| 574 |
|
if (maxcolors <= 2) { /* monochrome */ |
| 575 |
|
ourdata = (unsigned char *)malloc(ymax*((xmax+7)/8)); |
| 576 |
|
if (ourdata == NULL) |
| 577 |
|
goto fail; |
| 578 |
< |
ourras = make_raster(thedisplay, &ourvis, 1, ourdata, |
| 578 |
> |
ourras = make_raster(thedisplay, &ourvis, 1, (char *)ourdata, |
| 579 |
|
xmax, ymax, 8); |
| 580 |
|
if (ourras == NULL) |
| 581 |
|
goto fail; |
| 582 |
|
getmono(); |
| 583 |
< |
} else if (ourvis.class == TrueColor | ourvis.class == DirectColor) { |
| 584 |
< |
int datsiz = ourvis.depth>16 ? sizeof(int4) : sizeof(int2); |
| 583 |
> |
} else if ((ourvis.class == TrueColor) | (ourvis.class == DirectColor)) { |
| 584 |
> |
int datsiz = ourvis.depth>16 ? sizeof(int32) : sizeof(int16); |
| 585 |
|
ourdata = (unsigned char *)malloc(datsiz*xmax*ymax); |
| 586 |
|
if (ourdata == NULL) |
| 587 |
|
goto fail; |
| 588 |
|
ourras = make_raster(thedisplay, &ourvis, datsiz*8, |
| 589 |
< |
ourdata, xmax, ymax, datsiz*8); |
| 589 |
> |
(char *)ourdata, xmax, ymax, datsiz*8); |
| 590 |
|
if (ourras == NULL) |
| 591 |
|
goto fail; |
| 592 |
|
getfull(); |
| 594 |
|
ourdata = (unsigned char *)malloc(xmax*ymax); |
| 595 |
|
if (ourdata == NULL) |
| 596 |
|
goto fail; |
| 597 |
< |
ourras = make_raster(thedisplay, &ourvis, 8, ourdata, |
| 597 |
> |
ourras = make_raster(thedisplay, &ourvis, 8, (char *)ourdata, |
| 598 |
|
xmax, ymax, 8); |
| 599 |
|
if (ourras == NULL) |
| 600 |
|
goto fail; |
| 611 |
|
} |
| 612 |
|
|
| 613 |
|
|
| 614 |
< |
getevent() /* process the next event */ |
| 614 |
> |
static void |
| 615 |
> |
getevent(void) /* process the next event */ |
| 616 |
|
{ |
| 617 |
|
XEvent xev; |
| 618 |
|
|
| 629 |
|
map_rcolors(ourras, wind); |
| 630 |
|
if (fast) |
| 631 |
|
make_rpixmap(ourras, wind); |
| 632 |
< |
if (!sequential & parent < 0 & sigrecv == 0) { |
| 632 |
> |
if ((!sequential) & (parent < 0) & (sigrecv == 0)) { |
| 633 |
|
kill(getppid(), SIGCONT); |
| 634 |
|
sigrecv--; |
| 635 |
|
} |
| 667 |
|
} |
| 668 |
|
|
| 669 |
|
|
| 670 |
< |
traceray(xpos, ypos) /* print requested pixel data */ |
| 671 |
< |
int xpos, ypos; |
| 670 |
> |
static int |
| 671 |
> |
traceray( /* print requested pixel data */ |
| 672 |
> |
int xpos, |
| 673 |
> |
int ypos |
| 674 |
> |
) |
| 675 |
|
{ |
| 676 |
< |
FLOAT hv[2]; |
| 676 |
> |
RREAL hv[2]; |
| 677 |
|
FVECT rorg, rdir; |
| 678 |
|
COLOR cval; |
| 679 |
|
register char *cp; |
| 713 |
|
} |
| 714 |
|
|
| 715 |
|
|
| 716 |
< |
docom(ekey) /* execute command */ |
| 717 |
< |
XKeyPressedEvent *ekey; |
| 716 |
> |
static int |
| 717 |
> |
docom( /* execute command */ |
| 718 |
> |
XKeyPressedEvent *ekey |
| 719 |
> |
) |
| 720 |
|
{ |
| 721 |
|
char buf[80]; |
| 722 |
|
COLOR cval; |
| 723 |
|
XColor cvx; |
| 724 |
|
int com, n; |
| 725 |
|
double comp; |
| 726 |
< |
FLOAT hv[2]; |
| 726 |
> |
RREAL hv[2]; |
| 727 |
|
|
| 728 |
|
n = XLookupString(ekey, buf, sizeof(buf), NULL, NULL); |
| 729 |
|
if (n == 0) |
| 843 |
|
free_rpixmap(ourras); |
| 844 |
|
return(0); |
| 845 |
|
case '0': /* recenter origin */ |
| 846 |
< |
if (xoff == 0 & yoff == 0) |
| 846 |
> |
if ((xoff == 0) & (yoff == 0)) |
| 847 |
|
return(0); |
| 848 |
|
xoff = yoff = 0; |
| 849 |
|
XClearWindow(thedisplay, wind); |
| 859 |
|
} |
| 860 |
|
|
| 861 |
|
|
| 862 |
< |
moveimage(ebut) /* shift the image */ |
| 863 |
< |
XButtonPressedEvent *ebut; |
| 862 |
> |
static void |
| 863 |
> |
moveimage( /* shift the image */ |
| 864 |
> |
XButtonPressedEvent *ebut |
| 865 |
> |
) |
| 866 |
|
{ |
| 867 |
|
XEvent e; |
| 868 |
|
int mxo, myo; |
| 886 |
|
} |
| 887 |
|
|
| 888 |
|
|
| 889 |
< |
getbox(ebut) /* get new bbox */ |
| 890 |
< |
XButtonPressedEvent *ebut; |
| 889 |
> |
static void |
| 890 |
> |
getbox( /* get new bbox */ |
| 891 |
> |
XButtonPressedEvent *ebut |
| 892 |
> |
) |
| 893 |
|
{ |
| 894 |
|
XEvent e; |
| 895 |
|
|
| 916 |
|
} |
| 917 |
|
|
| 918 |
|
|
| 919 |
< |
trackrays(ebut) /* trace rays as mouse moves */ |
| 920 |
< |
XButtonPressedEvent *ebut; |
| 919 |
> |
static void |
| 920 |
> |
trackrays( /* trace rays as mouse moves */ |
| 921 |
> |
XButtonPressedEvent *ebut |
| 922 |
> |
) |
| 923 |
|
{ |
| 924 |
|
XEvent e; |
| 925 |
|
unsigned long lastrept; |
| 937 |
|
} |
| 938 |
|
|
| 939 |
|
|
| 940 |
< |
revbox(x0, y0, x1, y1) /* draw bbox with reversed lines */ |
| 941 |
< |
int x0, y0, x1, y1; |
| 940 |
> |
static void |
| 941 |
> |
revbox( /* draw bbox with reversed lines */ |
| 942 |
> |
int x0, |
| 943 |
> |
int y0, |
| 944 |
> |
int x1, |
| 945 |
> |
int y1 |
| 946 |
> |
) |
| 947 |
|
{ |
| 948 |
|
revline(x0, y0, x1, y0); |
| 949 |
|
revline(x0, y1, x1, y1); |
| 952 |
|
} |
| 953 |
|
|
| 954 |
|
|
| 955 |
< |
int |
| 956 |
< |
colavg(scn, n, cavg) |
| 957 |
< |
register COLR *scn; |
| 958 |
< |
register int n; |
| 959 |
< |
COLOR cavg; |
| 955 |
> |
static void |
| 956 |
> |
colavg( |
| 957 |
> |
register COLR *scn, |
| 958 |
> |
register int n, |
| 959 |
> |
void *cavg |
| 960 |
> |
) |
| 961 |
|
{ |
| 962 |
|
COLOR col; |
| 963 |
|
|
| 964 |
|
while (n--) { |
| 965 |
|
colr_color(col, *scn++); |
| 966 |
< |
addcolor(cavg, col); |
| 966 |
> |
addcolor((COLORV*)cavg, col); |
| 967 |
|
} |
| 968 |
|
} |
| 969 |
|
|
| 970 |
|
|
| 971 |
< |
int |
| 972 |
< |
avgbox(cavg) /* average color over current bbox */ |
| 973 |
< |
COLOR cavg; |
| 971 |
> |
static int |
| 972 |
> |
avgbox( /* average color over current bbox */ |
| 973 |
> |
COLOR cavg |
| 974 |
> |
) |
| 975 |
|
{ |
| 976 |
|
double d; |
| 977 |
|
register int rval; |
| 978 |
|
|
| 979 |
|
setcolor(cavg, 0., 0., 0.); |
| 980 |
< |
rval = dobox(colavg, (char *)cavg); |
| 980 |
> |
rval = dobox(colavg, (void *)cavg); |
| 981 |
|
if (rval > 0) { |
| 982 |
|
d = 1./rval; |
| 983 |
|
scalecolor(cavg, d); |
| 986 |
|
} |
| 987 |
|
|
| 988 |
|
|
| 989 |
< |
int |
| 990 |
< |
dobox(f, p) /* run function over bbox */ |
| 991 |
< |
int (*f)(); /* function to call for each subscan */ |
| 992 |
< |
char *p; /* pointer to private data */ |
| 989 |
> |
static int |
| 990 |
> |
dobox( /* run function over bbox */ |
| 991 |
> |
//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 |
> |
) |
| 995 |
|
{ |
| 996 |
|
int left, right, top, bottom; |
| 997 |
|
int y; |
| 1021 |
|
} |
| 1022 |
|
|
| 1023 |
|
|
| 1024 |
< |
int |
| 1025 |
< |
addfix(scn, n) /* add fixation points to histogram */ |
| 1026 |
< |
COLR *scn; |
| 1027 |
< |
int n; |
| 1024 |
> |
static void |
| 1025 |
> |
addfix( /* add fixation points to histogram */ |
| 1026 |
> |
COLR *scn, |
| 1027 |
> |
int n, |
| 1028 |
> |
void *p |
| 1029 |
> |
) |
| 1030 |
|
{ |
| 1031 |
< |
if (tmCvColrs(lscan, TM_NOCHROM, scn, n)) |
| 1031 |
> |
TMstruct * tms = (TMstruct *)p; |
| 1032 |
> |
|
| 1033 |
> |
if (tmCvColrs(tms, lscan, TM_NOCHROM, scn, n)) |
| 1034 |
|
goto tmerr; |
| 1035 |
< |
if (tmAddHisto(lscan, n, FIXWEIGHT)) |
| 1035 |
> |
if (tmAddHisto(tms, lscan, n, FIXWEIGHT)) |
| 1036 |
|
goto tmerr; |
| 1037 |
|
return; |
| 1038 |
|
tmerr: |
| 1040 |
|
} |
| 1041 |
|
|
| 1042 |
|
|
| 1043 |
< |
make_tonemap() /* initialize tone mapping */ |
| 1043 |
> |
static void |
| 1044 |
> |
make_tonemap(void) /* initialize tone mapping */ |
| 1045 |
|
{ |
| 1046 |
|
int flags, y; |
| 1047 |
|
|
| 1056 |
|
} |
| 1057 |
|
flags = tmflags; /* histogram adjustment */ |
| 1058 |
|
if (greyscale) flags |= TM_F_BW; |
| 1059 |
< |
if (tmTop != NULL) { /* reuse old histogram if one */ |
| 1060 |
< |
tmDone(tmTop); |
| 1061 |
< |
tmTop->flags = flags; |
| 1059 |
> |
if (tmGlobal != NULL) { /* reuse old histogram if one */ |
| 1060 |
> |
tmDone(tmCurrent); tmCurrent = NULL; |
| 1061 |
> |
tmGlobal->flags = flags; |
| 1062 |
|
} else { /* else initialize */ |
| 1063 |
|
if ((lscan = (TMbright *)malloc(xmax*sizeof(TMbright))) == NULL) |
| 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 |
< |
if (tmInit(flags, stdprims, gamcor) == NULL) |
| 1073 |
> |
tmGlobal = tmInit(flags, stdprims, gamcor); |
| 1074 |
> |
if (tmGlobal == NULL) |
| 1075 |
|
goto memerr; |
| 1076 |
< |
if (tmSetSpace(stdprims, WHTEFFICACY/exposure)) |
| 1076 |
> |
if (tmSetSpace(tmGlobal, stdprims, WHTEFFICACY/exposure)) |
| 1077 |
|
goto tmerr; |
| 1078 |
|
/* compute picture histogram */ |
| 1079 |
|
for (y = 0; y < ymax; y++) { |
| 1080 |
|
getscan(y); |
| 1081 |
< |
if (tmCvColrs(lscan, TM_NOCHROM, scanline, xmax)) |
| 1081 |
> |
if (tmCvColrs(tmGlobal, lscan, TM_NOCHROM, |
| 1082 |
> |
scanline, xmax)) |
| 1083 |
|
goto tmerr; |
| 1084 |
< |
if (tmAddHisto(lscan, xmax, 1)) |
| 1084 |
> |
if (tmAddHisto(tmGlobal, lscan, xmax, 1)) |
| 1085 |
|
goto tmerr; |
| 1086 |
|
} |
| 1087 |
|
} |
| 1088 |
< |
tmDup(); /* add fixations to duplicate map */ |
| 1089 |
< |
dobox(addfix, NULL); |
| 1088 |
> |
tmCurrent = tmDup(tmGlobal); /* add fixations to duplicate map */ |
| 1089 |
> |
dobox(addfix, (void *)tmCurrent); |
| 1090 |
|
/* (re)compute tone mapping */ |
| 1091 |
< |
if (tmComputeMapping(gamcor, 0., 0.)) |
| 1091 |
> |
if (tmComputeMapping(tmCurrent, gamcor, 0., 0.)) |
| 1092 |
|
goto tmerr; |
| 1093 |
|
return; |
| 1094 |
|
memerr: |
| 1098 |
|
} |
| 1099 |
|
|
| 1100 |
|
|
| 1101 |
< |
tmap_colrs(scn, len) /* apply tone mapping to scanline */ |
| 1102 |
< |
register COLR *scn; |
| 1103 |
< |
int len; |
| 1101 |
> |
static void |
| 1102 |
> |
tmap_colrs( /* apply tone mapping to scanline */ |
| 1103 |
> |
register COLR *scn, |
| 1104 |
> |
int len |
| 1105 |
> |
) |
| 1106 |
|
{ |
| 1107 |
< |
register BYTE *ps; |
| 1107 |
> |
register uby8 *ps; |
| 1108 |
|
|
| 1109 |
|
if (tmflags == TM_F_LINEAR) { |
| 1110 |
|
if (scale) |
| 1114 |
|
} |
| 1115 |
|
if (len > xmax) |
| 1116 |
|
quiterr("code error 1 in tmap_colrs"); |
| 1117 |
< |
if (tmCvColrs(lscan, cscan, scn, len)) |
| 1117 |
> |
if (tmCvColrs(tmCurrent, lscan, cscan, scn, len)) |
| 1118 |
|
goto tmerr; |
| 1119 |
< |
if (tmMapPixels(pscan, lscan, cscan, len)) |
| 1119 |
> |
if (tmMapPixels(tmCurrent, pscan, lscan, cscan, len)) |
| 1120 |
|
goto tmerr; |
| 1121 |
|
ps = pscan; |
| 1122 |
|
if (greyscale) |
| 1139 |
|
} |
| 1140 |
|
|
| 1141 |
|
|
| 1142 |
< |
getmono() /* get monochrome data */ |
| 1142 |
> |
static void |
| 1143 |
> |
getmono(void) /* get monochrome data */ |
| 1144 |
|
{ |
| 1145 |
|
register unsigned char *dp; |
| 1146 |
|
register int x, err; |
| 1172 |
|
} |
| 1173 |
|
|
| 1174 |
|
|
| 1175 |
< |
add2icon(y, scan) /* add a scanline to our icon data */ |
| 1176 |
< |
int y; |
| 1177 |
< |
COLR *scan; |
| 1175 |
> |
static void |
| 1176 |
> |
add2icon( /* add a scanline to our icon data */ |
| 1177 |
> |
int y, |
| 1178 |
> |
COLR *scan |
| 1179 |
> |
) |
| 1180 |
|
{ |
| 1181 |
|
static short cerr[ICONSIZ]; |
| 1182 |
|
static int ynext; |
| 1226 |
|
} |
| 1227 |
|
|
| 1228 |
|
|
| 1229 |
< |
getfull() /* get full (24-bit) data */ |
| 1229 |
> |
static void |
| 1230 |
> |
getfull(void) /* get full (24-bit) data */ |
| 1231 |
|
{ |
| 1232 |
|
int y; |
| 1233 |
< |
register unsigned int4 *dp; |
| 1234 |
< |
register unsigned int2 *dph; |
| 1233 |
> |
register uint32 *dp; |
| 1234 |
> |
register uint16 *dph; |
| 1235 |
|
register int x; |
| 1236 |
|
/* initialize tone mapping */ |
| 1237 |
|
make_tonemap(); |
| 1238 |
|
/* read and convert file */ |
| 1239 |
< |
dp = (unsigned int4 *)ourdata; |
| 1240 |
< |
dph = (unsigned int2 *)ourdata; |
| 1239 |
> |
dp = (uint32 *)ourdata; |
| 1240 |
> |
dph = (uint16 *)ourdata; |
| 1241 |
|
for (y = 0; y < ymax; y++) { |
| 1242 |
|
getscan(y); |
| 1243 |
|
add2icon(y, scanline); |
| 1245 |
|
switch (ourras->image->blue_mask) { |
| 1246 |
|
case 0xff: /* 24-bit RGB */ |
| 1247 |
|
for (x = 0; x < xmax; x++) |
| 1248 |
< |
*dp++ = (unsigned int4)scanline[x][RED] << 16 | |
| 1249 |
< |
(unsigned int4)scanline[x][GRN] << 8 | |
| 1250 |
< |
(unsigned int4)scanline[x][BLU] ; |
| 1248 |
> |
*dp++ = (uint32)scanline[x][RED] << 16 | |
| 1249 |
> |
(uint32)scanline[x][GRN] << 8 | |
| 1250 |
> |
(uint32)scanline[x][BLU] ; |
| 1251 |
|
break; |
| 1252 |
|
case 0xff0000: /* 24-bit BGR */ |
| 1253 |
|
for (x = 0; x < xmax; x++) |
| 1254 |
< |
*dp++ = (unsigned int4)scanline[x][RED] | |
| 1255 |
< |
(unsigned int4)scanline[x][GRN] << 8 | |
| 1256 |
< |
(unsigned int4)scanline[x][BLU] << 16 ; |
| 1254 |
> |
*dp++ = (uint32)scanline[x][RED] | |
| 1255 |
> |
(uint32)scanline[x][GRN] << 8 | |
| 1256 |
> |
(uint32)scanline[x][BLU] << 16 ; |
| 1257 |
|
break; |
| 1258 |
|
#if 0 |
| 1259 |
|
case 0x1f: /* 15-bit RGB */ |
| 1294 |
|
} |
| 1295 |
|
|
| 1296 |
|
|
| 1297 |
< |
getgrey() /* get greyscale data */ |
| 1297 |
> |
static void |
| 1298 |
> |
getgrey(void) /* get greyscale data */ |
| 1299 |
|
{ |
| 1300 |
|
int y; |
| 1301 |
|
register unsigned char *dp; |
| 1310 |
|
tmap_colrs(scanline, xmax); |
| 1311 |
|
if (maxcolors < 256) |
| 1312 |
|
for (x = 0; x < xmax; x++) |
| 1313 |
< |
*dp++ = ((int4)scanline[x][GRN] * |
| 1313 |
> |
*dp++ = ((int32)scanline[x][GRN] * |
| 1314 |
|
maxcolors + maxcolors/2) >> 8; |
| 1315 |
|
else |
| 1316 |
|
for (x = 0; x < xmax; x++) |
| 1318 |
|
} |
| 1319 |
|
for (x = 0; x < maxcolors; x++) |
| 1320 |
|
clrtab[x][RED] = clrtab[x][GRN] = |
| 1321 |
< |
clrtab[x][BLU] = ((int4)x*256 + 128)/maxcolors; |
| 1321 |
> |
clrtab[x][BLU] = ((int32)x*256 + 128)/maxcolors; |
| 1322 |
|
} |
| 1323 |
|
|
| 1324 |
|
|
| 1325 |
< |
getmapped() /* get color-mapped data */ |
| 1325 |
> |
static void |
| 1326 |
> |
getmapped(void) /* get color-mapped data */ |
| 1327 |
|
{ |
| 1328 |
|
int y; |
| 1329 |
|
/* make sure we can do it first */ |
| 1332 |
|
/* initialize tone mapping */ |
| 1333 |
|
make_tonemap(); |
| 1334 |
|
/* make histogram */ |
| 1335 |
< |
if (new_histo((int4)xmax*ymax) == -1) |
| 1335 |
> |
if (new_histo((int32)xmax*ymax) == -1) |
| 1336 |
|
quiterr("cannot initialize histogram"); |
| 1337 |
|
for (y = 0; y < ymax; y++) { |
| 1338 |
|
if (getscan(y) < 0) |
| 1355 |
|
} |
| 1356 |
|
|
| 1357 |
|
|
| 1358 |
< |
scale_rcolors(xr, sf) /* scale color map */ |
| 1359 |
< |
register XRASTER *xr; |
| 1360 |
< |
double sf; |
| 1358 |
> |
static void |
| 1359 |
> |
scale_rcolors( /* scale color map */ |
| 1360 |
> |
register XRASTER *xr, |
| 1361 |
> |
double sf |
| 1362 |
> |
) |
| 1363 |
|
{ |
| 1364 |
|
register int i; |
| 1365 |
|
long maxv; |
| 1385 |
|
} |
| 1386 |
|
|
| 1387 |
|
|
| 1388 |
< |
getscan(y) |
| 1389 |
< |
int y; |
| 1388 |
> |
static int |
| 1389 |
> |
getscan( |
| 1390 |
> |
int y |
| 1391 |
> |
) |
| 1392 |
|
{ |
| 1393 |
|
static int trunced = -1; /* truncated file? */ |
| 1394 |
|
skipit: |
| 1395 |
|
if (trunced >= 0 && y >= trunced) { |
| 1396 |
< |
bzero(scanline, xmax*sizeof(COLR)); |
| 1396 |
> |
memset(scanline, '\0', xmax*sizeof(COLR)); |
| 1397 |
|
return(-1); |
| 1398 |
|
} |
| 1399 |
|
if (y != cury) { |
| 1405 |
|
} else if (scanpos != NULL && scanpos[y] == -1) |
| 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; |