1 |
< |
/* Copyright (c) 1993 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
4 |
> |
static char SCCSid[] = "$SunId$ SGI"; |
5 |
|
#endif |
6 |
|
|
7 |
|
/* |
27 |
|
#include <X11/Xutil.h> |
28 |
|
#include <X11/Xatom.h> |
29 |
|
|
30 |
+ |
#undef NOPROTO |
31 |
+ |
#define NOPROTO 1 |
32 |
|
#include "color.h" |
33 |
+ |
#include "tonemap.h" |
34 |
|
#include "view.h" |
35 |
|
#include "x11raster.h" |
36 |
|
#include "random.h" |
37 |
|
#include "resolu.h" |
38 |
|
|
36 |
– |
#ifdef __alpha |
37 |
– |
#define int4 int |
38 |
– |
#endif |
39 |
– |
#ifndef int4 |
40 |
– |
#define int4 long |
41 |
– |
#endif |
42 |
– |
|
39 |
|
#define FONTNAME "8x13" /* text font we'll use */ |
40 |
|
|
41 |
|
#define CTRL(c) ((c)-'@') |
44 |
|
|
45 |
|
#define ICONSIZ (8*10) /* maximum icon dimension (even 8) */ |
46 |
|
|
47 |
+ |
#define FIXWEIGHT 20 /* weight to add for fixation points */ |
48 |
+ |
|
49 |
|
#define ourscreen DefaultScreen(thedisplay) |
50 |
|
#define ourroot RootWindow(thedisplay,ourscreen) |
51 |
|
|
72 |
|
int yoff = 0; /* y image offset */ |
73 |
|
|
74 |
|
int parent = 0; /* number of children, -1 if child */ |
75 |
+ |
int sequential = 0; /* display images in sequence */ |
76 |
|
|
77 |
+ |
char *tout = "od"; /* output of 't' command */ |
78 |
+ |
int tinterv = 0; /* interval between mouse reports */ |
79 |
+ |
|
80 |
+ |
int tmflags = TM_F_LINEAR; /* tone mapping flags */ |
81 |
+ |
|
82 |
|
VIEW ourview = STDVIEW; /* image view parameters */ |
83 |
|
int gotview = 0; /* got parameters from file */ |
84 |
|
|
85 |
|
COLR *scanline; /* scan line buffer */ |
86 |
+ |
TMbright *lscan; /* encoded luminance scanline */ |
87 |
+ |
BYTE *cscan; /* encoded chroma scanline */ |
88 |
+ |
BYTE *pscan; /* compute pixel scanline */ |
89 |
|
|
90 |
|
RESOLU inpres; /* input resolution and ordering */ |
91 |
|
int xmax, ymax; /* picture dimensions */ |
92 |
|
int width, height; /* window size */ |
93 |
|
char *fname = NULL; /* input file name */ |
94 |
< |
FILE *fin = stdin; /* input file */ |
94 |
> |
FILE *fin = NULL; /* input file */ |
95 |
|
long *scanpos = NULL; /* scan line positions in file */ |
96 |
|
int cury = 0; /* current scan location */ |
97 |
|
|
120 |
|
|
121 |
|
char errmsg[128]; |
122 |
|
|
123 |
< |
extern BYTE clrtab[256][3]; /* global color map */ |
123 |
> |
BYTE clrtab[256][3]; /* global color map */ |
124 |
|
|
125 |
|
extern long ftell(); |
126 |
|
|
143 |
|
int pid; |
144 |
|
|
145 |
|
progname = argv[0]; |
146 |
+ |
fin = stdin; |
147 |
|
|
148 |
|
for (i = 1; i < argc; i++) |
149 |
|
if (argv[i][0] == '-') |
150 |
|
switch (argv[i][1]) { |
151 |
< |
case 'c': |
151 |
> |
case 'c': /* number of colors */ |
152 |
|
maxcolors = atoi(argv[++i]); |
153 |
|
break; |
154 |
< |
case 'b': |
154 |
> |
case 'b': /* greyscale only */ |
155 |
|
greyscale = !greyscale; |
156 |
|
break; |
157 |
< |
case 'm': |
157 |
> |
case 'm': /* monochrome */ |
158 |
> |
greyscale = 1; |
159 |
|
maxcolors = 2; |
160 |
|
break; |
161 |
< |
case 'd': |
161 |
> |
case 'd': /* display or dither */ |
162 |
|
if (argv[i][2] == 'i') |
163 |
|
dispname = argv[++i]; |
164 |
|
else |
165 |
|
dither = !dither; |
166 |
|
break; |
167 |
< |
case 'f': |
167 |
> |
case 'f': /* save pixmap */ |
168 |
|
fast = !fast; |
169 |
|
break; |
170 |
< |
case 'e': |
171 |
< |
if (argv[i+1][0] != '+' && argv[i+1][0] != '-') |
170 |
> |
case 's': /* one at a time */ |
171 |
> |
sequential = !sequential; |
172 |
> |
break; |
173 |
> |
case 'o': /* 't' output */ |
174 |
> |
tout = argv[i]+2; |
175 |
> |
break; |
176 |
> |
case 't': /* msec interval */ |
177 |
> |
tinterv = atoi(argv[++i]); |
178 |
> |
break; |
179 |
> |
case 'e': /* exposure comp. */ |
180 |
> |
i++; |
181 |
> |
if (argv[i][0] == 'a') { |
182 |
> |
tmflags = TM_F_CAMERA; |
183 |
> |
break; |
184 |
> |
} |
185 |
> |
if (argv[i][0] == 'h') { |
186 |
> |
tmflags = TM_F_HUMAN; |
187 |
> |
break; |
188 |
> |
} |
189 |
> |
if (argv[i][0] != '+' && argv[i][0] != '-') |
190 |
|
goto userr; |
191 |
< |
scale = atoi(argv[++i]); |
191 |
> |
scale = atoi(argv[i]); |
192 |
|
break; |
193 |
< |
case 'g': |
193 |
> |
case 'g': /* gamma comp. */ |
194 |
|
if (argv[i][2] == 'e') |
195 |
|
geometry = argv[++i]; |
196 |
|
else |
241 |
|
|
242 |
|
init(argc, argv); /* get file and open window */ |
243 |
|
|
217 |
– |
if (parent < 0) { |
218 |
– |
kill(getppid(), SIGCONT); /* signal parent if child */ |
219 |
– |
sigrecv--; |
220 |
– |
} |
244 |
|
for ( ; ; ) |
245 |
|
getevent(); /* main loop */ |
246 |
|
userr: |
247 |
|
fprintf(stderr, |
248 |
< |
"Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e +/-stops][-g gamcor] pic ..\n", |
248 |
> |
"Usage: %s [-di disp][[-ge] spec][-b][-m][-d][-f][-c nclrs][-e spec][-g gamcor][-s][-ospec][-t intvl] pic ..\n", |
249 |
|
progname); |
250 |
|
exit(1); |
251 |
|
} |
252 |
|
|
253 |
|
|
254 |
+ |
int |
255 |
|
headline(s) /* get relevant info from header */ |
256 |
|
char *s; |
257 |
|
{ |
259 |
|
|
260 |
|
if (isexpos(s)) |
261 |
|
exposure *= exposval(s); |
262 |
< |
else if (isformat(s)) { |
239 |
< |
formatval(fmt, s); |
262 |
> |
else if (formatval(fmt, s)) |
263 |
|
wrongformat = strcmp(fmt, COLRFMT); |
264 |
< |
} else if (isview(s) && sscanview(&ourview, s) > 0) |
264 |
> |
else if (isview(s) && sscanview(&ourview, s) > 0) |
265 |
|
gotview++; |
266 |
+ |
return(0); |
267 |
|
} |
268 |
|
|
269 |
|
|
300 |
|
if (gamstr == NULL) /* get it from the X server */ |
301 |
|
gamstr = XGetDefault(thedisplay, "radiance", "gamma"); |
302 |
|
if (gamstr == NULL) /* get it from the environment */ |
303 |
< |
gamstr = getenv("GAMMA"); |
303 |
> |
gamstr = getenv("DISPLAY_GAMMA"); |
304 |
|
if (gamstr != NULL) |
305 |
|
gamcor = atof(gamstr); |
306 |
|
/* get best visual for default screen */ |
329 |
|
} |
330 |
|
} |
331 |
|
/* open window */ |
332 |
+ |
i = CWEventMask|CWCursor|CWBackPixel|CWBorderPixel; |
333 |
|
ourwinattr.border_pixel = ourwhite; |
334 |
|
ourwinattr.background_pixel = ourblack; |
335 |
< |
ourwinattr.colormap = XCreateColormap(thedisplay, ourroot, |
336 |
< |
ourvis.visual, AllocNone); |
335 |
> |
if (ourvis.visual != DefaultVisual(thedisplay,ourscreen)) { |
336 |
> |
ourwinattr.colormap = newcmap(thedisplay, ourscreen, ourvis.visual); |
337 |
> |
i |= CWColormap; |
338 |
> |
} |
339 |
|
ourwinattr.event_mask = ExposureMask|KeyPressMask|ButtonPressMask| |
340 |
|
ButtonReleaseMask|ButtonMotionMask|StructureNotifyMask; |
341 |
|
ourwinattr.cursor = XCreateFontCursor(thedisplay, XC_diamond_cross); |
342 |
|
wind = XCreateWindow(thedisplay, ourroot, xszhints.x, xszhints.y, |
343 |
|
xszhints.width, xszhints.height, BORWIDTH, |
344 |
< |
ourvis.depth, InputOutput, ourvis.visual, CWEventMask| |
345 |
< |
CWCursor|CWBackPixel|CWBorderPixel|CWColormap, &ourwinattr); |
344 |
> |
ourvis.depth, InputOutput, ourvis.visual, |
345 |
> |
i, &ourwinattr); |
346 |
|
if (wind == 0) |
347 |
|
quiterr("cannot create window"); |
348 |
|
width = xmax; |
380 |
|
XSetWMProtocols(thedisplay, wind, &closedownAtom, 1); |
381 |
|
|
382 |
|
XMapWindow(thedisplay, wind); |
356 |
– |
return; |
383 |
|
} /* end of init */ |
384 |
|
|
385 |
|
|
392 |
|
if (es = err != NULL) |
393 |
|
fprintf(stderr, "%s: %s: %s\n", progname, |
394 |
|
fname==NULL?"<stdin>":fname, err); |
395 |
< |
if (parent > 0 & wind != 0) { |
396 |
< |
XDestroyWindow(thedisplay, wind); |
397 |
< |
XFlush(thedisplay); |
372 |
< |
} else if (parent < 0 & sigrecv == 0) |
395 |
> |
if (thedisplay != NULL) |
396 |
> |
XCloseDisplay(thedisplay); |
397 |
> |
if (parent < 0 & sigrecv == 0) |
398 |
|
kill(getppid(), SIGCONT); |
399 |
|
while (parent > 0 && wait(&cs) != -1) { /* wait for any children */ |
400 |
|
if (es == 0) |
558 |
|
xmax, ymax, 8); |
559 |
|
if (ourras == NULL) |
560 |
|
goto fail; |
561 |
< |
if (greyscale | ourvis.class == StaticGray) |
561 |
> |
if (greyscale) |
562 |
|
getgrey(); |
563 |
|
else |
564 |
|
getmapped(); |
588 |
|
map_rcolors(ourras, wind); |
589 |
|
if (fast) |
590 |
|
make_rpixmap(ourras, wind); |
591 |
+ |
if (!sequential & parent < 0 & sigrecv == 0) { |
592 |
+ |
kill(getppid(), SIGCONT); |
593 |
+ |
sigrecv--; |
594 |
+ |
} |
595 |
|
break; |
596 |
|
case UnmapNotify: |
597 |
|
if (!fast) |
604 |
|
case ButtonPress: |
605 |
|
if (xev.xbutton.state & (ShiftMask|ControlMask)) |
606 |
|
moveimage(&xev.xbutton); |
578 |
– |
else if (xev.xbutton.button == Button2) |
579 |
– |
traceray(xev.xbutton.x, xev.xbutton.y); |
607 |
|
else |
608 |
< |
getbox(&xev.xbutton); |
608 |
> |
switch (xev.xbutton.button) { |
609 |
> |
case Button1: |
610 |
> |
getbox(&xev.xbutton); |
611 |
> |
break; |
612 |
> |
case Button2: |
613 |
> |
traceray(xev.xbutton.x, xev.xbutton.y); |
614 |
> |
break; |
615 |
> |
case Button3: |
616 |
> |
trackrays(&xev.xbutton); |
617 |
> |
break; |
618 |
> |
} |
619 |
|
break; |
620 |
|
case ClientMessage: |
621 |
|
if ((xev.xclient.message_type == wmProtocolsAtom) && |
626 |
|
} |
627 |
|
|
628 |
|
|
629 |
< |
traceray(xpos, ypos) /* print ray corresponding to pixel */ |
629 |
> |
traceray(xpos, ypos) /* print requested pixel data */ |
630 |
|
int xpos, ypos; |
631 |
|
{ |
632 |
+ |
extern char *index(); |
633 |
|
FLOAT hv[2]; |
634 |
|
FVECT rorg, rdir; |
635 |
+ |
COLOR cval; |
636 |
+ |
register char *cp; |
637 |
|
|
638 |
< |
if (!gotview) { /* no view, no can do */ |
639 |
< |
XBell(thedisplay, 0); |
640 |
< |
return(-1); |
641 |
< |
} |
638 |
> |
box.xmin = xpos; box.xsiz = 1; |
639 |
> |
box.ymin = ypos; box.ysiz = 1; |
640 |
> |
avgbox(cval); |
641 |
> |
scalecolor(cval, 1./exposure); |
642 |
|
pix2loc(hv, &inpres, xpos-xoff, ypos-yoff); |
643 |
< |
if (viewray(rorg, rdir, &ourview, hv[0], hv[1]) < 0) |
644 |
< |
return(-1); |
645 |
< |
printf("%e %e %e ", rorg[0], rorg[1], rorg[2]); |
646 |
< |
printf("%e %e %e\n", rdir[0], rdir[1], rdir[2]); |
643 |
> |
if (!gotview || viewray(rorg, rdir, &ourview, hv[0], hv[1]) < 0) |
644 |
> |
rorg[0] = rorg[1] = rorg[2] = |
645 |
> |
rdir[0] = rdir[1] = rdir[2] = 0.; |
646 |
> |
|
647 |
> |
for (cp = tout; *cp; cp++) /* print what they asked for */ |
648 |
> |
switch (*cp) { |
649 |
> |
case 'o': /* origin */ |
650 |
> |
printf("%e %e %e ", rorg[0], rorg[1], rorg[2]); |
651 |
> |
break; |
652 |
> |
case 'd': /* direction */ |
653 |
> |
printf("%e %e %e ", rdir[0], rdir[1], rdir[2]); |
654 |
> |
break; |
655 |
> |
case 'v': /* radiance value */ |
656 |
> |
printf("%e %e %e ", colval(cval,RED), |
657 |
> |
colval(cval,GRN), colval(cval,BLU)); |
658 |
> |
break; |
659 |
> |
case 'l': /* luminance */ |
660 |
> |
printf("%e ", luminance(cval)); |
661 |
> |
break; |
662 |
> |
case 'p': /* pixel position */ |
663 |
> |
printf("%d %d ", (int)(hv[0]*inpres.xr), |
664 |
> |
(int)(hv[1]*inpres.yr)); |
665 |
> |
break; |
666 |
> |
} |
667 |
> |
putchar('\n'); |
668 |
|
fflush(stdout); |
669 |
|
return(0); |
670 |
|
} |
693 |
|
case '\r': |
694 |
|
case 'l': |
695 |
|
case 'c': /* value */ |
696 |
< |
if (avgbox(cval) == -1) |
696 |
> |
if (!avgbox(cval)) |
697 |
|
return(-1); |
698 |
|
switch (com) { |
699 |
|
case '\n': |
735 |
|
return(0); |
736 |
|
case 't': /* trace */ |
737 |
|
return(traceray(ekey->x, ekey->y)); |
738 |
+ |
case 'a': /* auto exposure */ |
739 |
+ |
if (fname == NULL) |
740 |
+ |
return(-1); |
741 |
+ |
tmflags = TM_F_CAMERA; |
742 |
+ |
strcpy(buf, "auto exposure..."); |
743 |
+ |
goto remap; |
744 |
+ |
case 'h': /* human response */ |
745 |
+ |
if (fname == NULL) |
746 |
+ |
return(-1); |
747 |
+ |
tmflags = TM_F_HUMAN; |
748 |
+ |
strcpy(buf, "human exposure..."); |
749 |
+ |
goto remap; |
750 |
|
case '=': /* adjust exposure */ |
751 |
|
case '@': /* adaptation level */ |
752 |
< |
if (avgbox(cval) == -1) |
752 |
> |
if (!avgbox(cval)) |
753 |
|
return(-1); |
754 |
|
comp = bright(cval); |
755 |
|
if (comp < 1e-20) { |
763 |
|
comp = .5/comp; |
764 |
|
comp = log(comp)/.69315 - scale; |
765 |
|
n = comp < 0 ? comp-.5 : comp+.5 ; /* round */ |
766 |
< |
if (n == 0) |
767 |
< |
return(0); |
768 |
< |
scale_rcolors(ourras, pow(2.0, (double)n)); |
766 |
> |
if (tmflags != TM_F_LINEAR) |
767 |
> |
tmflags = TM_F_LINEAR; /* turn off tone mapping */ |
768 |
> |
else { |
769 |
> |
if (n == 0) /* else check if any change */ |
770 |
> |
return(0); |
771 |
> |
scale_rcolors(ourras, pow(2.0, (double)n)); |
772 |
> |
} |
773 |
|
scale += n; |
774 |
|
sprintf(buf, "%+d", scale); |
775 |
+ |
remap: |
776 |
|
XDrawImageString(thedisplay, wind, ourgc, |
777 |
|
box.xmin, box.ymin+box.ysiz, buf, strlen(buf)); |
778 |
|
XFlush(thedisplay); |
867 |
|
} |
868 |
|
|
869 |
|
|
870 |
+ |
trackrays(ebut) /* trace rays as mouse moves */ |
871 |
+ |
XButtonPressedEvent *ebut; |
872 |
+ |
{ |
873 |
+ |
XEvent e; |
874 |
+ |
unsigned long lastrept; |
875 |
+ |
|
876 |
+ |
traceray(ebut->x, ebut->y); |
877 |
+ |
lastrept = ebut->time; |
878 |
+ |
XMaskEvent(thedisplay, ButtonReleaseMask|ButtonMotionMask, &e); |
879 |
+ |
while (e.type == MotionNotify) { |
880 |
+ |
if (e.xmotion.time >= lastrept + tinterv) { |
881 |
+ |
traceray(e.xmotion.x, e.xmotion.y); |
882 |
+ |
lastrept = e.xmotion.time; |
883 |
+ |
} |
884 |
+ |
XMaskEvent(thedisplay,ButtonReleaseMask|ButtonMotionMask,&e); |
885 |
+ |
} |
886 |
+ |
} |
887 |
+ |
|
888 |
+ |
|
889 |
|
revbox(x0, y0, x1, y1) /* draw box with reversed lines */ |
890 |
|
int x0, y0, x1, y1; |
891 |
|
{ |
896 |
|
} |
897 |
|
|
898 |
|
|
899 |
< |
avgbox(clr) /* average color over current box */ |
900 |
< |
COLOR clr; |
899 |
> |
int |
900 |
> |
colavg(scn, n, cavg) |
901 |
> |
register COLR *scn; |
902 |
> |
register int n; |
903 |
> |
COLOR cavg; |
904 |
|
{ |
905 |
< |
static COLOR lc; |
906 |
< |
static int ll, lr, lt, lb; |
905 |
> |
COLOR col; |
906 |
> |
|
907 |
> |
while (n--) { |
908 |
> |
colr_color(col, scn++); |
909 |
> |
addcolor(cavg, col); |
910 |
> |
} |
911 |
> |
} |
912 |
> |
|
913 |
> |
|
914 |
> |
int |
915 |
> |
avgbox(cavg) /* average color over current box */ |
916 |
> |
COLOR cavg; |
917 |
> |
{ |
918 |
> |
double d; |
919 |
> |
register int rval; |
920 |
> |
|
921 |
> |
setcolor(cavg, 0., 0., 0.); |
922 |
> |
rval = dobox(colavg, (char *)cavg); |
923 |
> |
if (rval > 0) { |
924 |
> |
d = 1./rval; |
925 |
> |
scalecolor(cavg, d); |
926 |
> |
} |
927 |
> |
return(rval); |
928 |
> |
} |
929 |
> |
|
930 |
> |
|
931 |
> |
int |
932 |
> |
dobox(f, p) /* run function over box */ |
933 |
> |
int (*f)(); /* function to call for each subscan */ |
934 |
> |
char *p; /* pointer to private data */ |
935 |
> |
{ |
936 |
|
int left, right, top, bottom; |
937 |
|
int y; |
809 |
– |
double d; |
810 |
– |
COLOR ctmp; |
811 |
– |
register int x; |
938 |
|
|
813 |
– |
setcolor(clr, 0.0, 0.0, 0.0); |
939 |
|
left = box.xmin - xoff; |
940 |
|
right = left + box.xsiz; |
941 |
|
if (left < 0) |
943 |
|
if (right > xmax) |
944 |
|
right = xmax; |
945 |
|
if (left >= right) |
946 |
< |
return(-1); |
946 |
> |
return(0); |
947 |
|
top = box.ymin - yoff; |
948 |
|
bottom = top + box.ysiz; |
949 |
|
if (top < 0) |
951 |
|
if (bottom > ymax) |
952 |
|
bottom = ymax; |
953 |
|
if (top >= bottom) |
829 |
– |
return(-1); |
830 |
– |
if (left == ll && right == lr && top == lt && bottom == lb) { |
831 |
– |
copycolor(clr, lc); |
954 |
|
return(0); |
833 |
– |
} |
955 |
|
for (y = top; y < bottom; y++) { |
956 |
|
if (getscan(y) == -1) |
957 |
|
return(-1); |
958 |
< |
for (x = left; x < right; x++) { |
959 |
< |
colr_color(ctmp, scanline[x]); |
960 |
< |
addcolor(clr, ctmp); |
958 |
> |
(*f)(scanline+left, right-left, p); |
959 |
> |
} |
960 |
> |
return((right-left)*(bottom-top)); |
961 |
> |
} |
962 |
> |
|
963 |
> |
|
964 |
> |
int |
965 |
> |
addfix(scn, n) /* add fixation points to histogram */ |
966 |
> |
COLR *scn; |
967 |
> |
int n; |
968 |
> |
{ |
969 |
> |
if (tmCvColrs(lscan, TM_NOCHROM, scn, n)) |
970 |
> |
goto tmerr; |
971 |
> |
if (tmAddHisto(lscan, n, FIXWEIGHT)) |
972 |
> |
goto tmerr; |
973 |
> |
return; |
974 |
> |
tmerr: |
975 |
> |
quiterr("tone mapping error"); |
976 |
> |
} |
977 |
> |
|
978 |
> |
|
979 |
> |
make_tonemap() /* initialize tone mapping */ |
980 |
> |
{ |
981 |
> |
int flags, y; |
982 |
> |
|
983 |
> |
if (tmflags != TM_F_LINEAR && fname == NULL) { |
984 |
> |
fprintf(stderr, "%s: cannot adjust tone of standard input\n", |
985 |
> |
progname); |
986 |
> |
tmflags = TM_F_LINEAR; |
987 |
> |
} |
988 |
> |
if (tmflags == TM_F_LINEAR) { /* linear with clamping */ |
989 |
> |
setcolrcor(pow, 1.0/gamcor); |
990 |
> |
return; |
991 |
> |
} |
992 |
> |
flags = tmflags; /* histogram adjustment */ |
993 |
> |
if (greyscale) flags |= TM_F_BW; |
994 |
> |
if (tmTop != NULL) { /* reuse old histogram if one */ |
995 |
> |
tmDone(tmTop); |
996 |
> |
tmTop->flags = flags; |
997 |
> |
} else { /* else initialize */ |
998 |
> |
if ((lscan = (TMbright *)malloc(xmax*sizeof(TMbright))) == NULL) |
999 |
> |
goto memerr; |
1000 |
> |
if (greyscale) { |
1001 |
> |
cscan = TM_NOCHROM; |
1002 |
> |
if ((pscan = (BYTE *)malloc(sizeof(BYTE)*xmax)) == NULL) |
1003 |
> |
goto memerr; |
1004 |
> |
} else if ((pscan=cscan = (BYTE *)malloc(3*sizeof(BYTE)*xmax)) |
1005 |
> |
== NULL) |
1006 |
> |
goto memerr; |
1007 |
> |
/* initialize tm library */ |
1008 |
> |
if (tmInit(flags, stdprims, gamcor) == NULL) |
1009 |
> |
goto memerr; |
1010 |
> |
if (tmSetSpace(stdprims, WHTEFFICACY/exposure)) |
1011 |
> |
goto tmerr; |
1012 |
> |
/* compute picture histogram */ |
1013 |
> |
for (y = 0; y < ymax; y++) { |
1014 |
> |
getscan(y); |
1015 |
> |
if (tmCvColrs(lscan, TM_NOCHROM, scanline, xmax)) |
1016 |
> |
goto tmerr; |
1017 |
> |
if (tmAddHisto(lscan, xmax, 1)) |
1018 |
> |
goto tmerr; |
1019 |
|
} |
1020 |
|
} |
1021 |
< |
d = 1.0/((right-left)*(bottom-top)); |
1022 |
< |
scalecolor(clr, d); |
1023 |
< |
ll = left; lr = right; lt = top; lb = bottom; |
1024 |
< |
copycolor(lc, clr); |
1025 |
< |
return(0); |
1021 |
> |
tmDup(); /* add fixations to duplicate map */ |
1022 |
> |
dobox(addfix, NULL); |
1023 |
> |
/* (re)compute tone mapping */ |
1024 |
> |
if (tmComputeMapping(gamcor, 0., 0.)) |
1025 |
> |
goto tmerr; |
1026 |
> |
return; |
1027 |
> |
memerr: |
1028 |
> |
quiterr("out of memory in make_tonemap"); |
1029 |
> |
tmerr: |
1030 |
> |
quiterr("tone mapping error"); |
1031 |
|
} |
1032 |
|
|
1033 |
|
|
1034 |
+ |
tmap_colrs(scn, len) /* apply tone mapping to scanline */ |
1035 |
+ |
register COLR *scn; |
1036 |
+ |
int len; |
1037 |
+ |
{ |
1038 |
+ |
register BYTE *ps; |
1039 |
+ |
|
1040 |
+ |
if (tmflags == TM_F_LINEAR) { |
1041 |
+ |
if (scale) |
1042 |
+ |
shiftcolrs(scn, len, scale); |
1043 |
+ |
colrs_gambs(scn, len); |
1044 |
+ |
return; |
1045 |
+ |
} |
1046 |
+ |
if (len > xmax) |
1047 |
+ |
quiterr("code error 1 in tmap_colrs"); |
1048 |
+ |
if (tmCvColrs(lscan, cscan, scn, len)) |
1049 |
+ |
goto tmerr; |
1050 |
+ |
if (tmMapPixels(pscan, lscan, cscan, len)) |
1051 |
+ |
goto tmerr; |
1052 |
+ |
ps = pscan; |
1053 |
+ |
if (greyscale) |
1054 |
+ |
while (len--) { |
1055 |
+ |
scn[0][RED] = scn[0][GRN] = scn[0][BLU] = *ps++; |
1056 |
+ |
scn[0][EXP] = COLXS; |
1057 |
+ |
scn++; |
1058 |
+ |
} |
1059 |
+ |
else |
1060 |
+ |
while (len--) { |
1061 |
+ |
scn[0][RED] = *ps++; |
1062 |
+ |
scn[0][GRN] = *ps++; |
1063 |
+ |
scn[0][BLU] = *ps++; |
1064 |
+ |
scn[0][EXP] = COLXS; |
1065 |
+ |
scn++; |
1066 |
+ |
} |
1067 |
+ |
return; |
1068 |
+ |
tmerr: |
1069 |
+ |
quiterr("tone mapping error"); |
1070 |
+ |
} |
1071 |
+ |
|
1072 |
+ |
|
1073 |
|
getmono() /* get monochrome data */ |
1074 |
|
{ |
1075 |
|
register unsigned char *dp; |
1159 |
|
int y; |
1160 |
|
register unsigned int4 *dp; |
1161 |
|
register int x; |
1162 |
< |
/* set gamma correction */ |
1163 |
< |
setcolrgam(gamcor); |
1162 |
> |
/* initialize tone mapping */ |
1163 |
> |
make_tonemap(); |
1164 |
|
/* read and convert file */ |
1165 |
|
dp = (unsigned int4 *)ourdata; |
1166 |
|
for (y = 0; y < ymax; y++) { |
1167 |
|
getscan(y); |
1168 |
|
add2icon(y, scanline); |
1169 |
< |
if (scale) |
947 |
< |
shiftcolrs(scanline, xmax, scale); |
948 |
< |
colrs_gambs(scanline, xmax); |
1169 |
> |
tmap_colrs(scanline, xmax); |
1170 |
|
if (ourras->image->blue_mask & 1) |
1171 |
|
for (x = 0; x < xmax; x++) |
1172 |
|
*dp++ = (unsigned int4)scanline[x][RED] << 16 | |
1186 |
|
int y; |
1187 |
|
register unsigned char *dp; |
1188 |
|
register int x; |
1189 |
< |
/* set gamma correction */ |
1190 |
< |
setcolrgam(gamcor); |
1189 |
> |
/* initialize tone mapping */ |
1190 |
> |
make_tonemap(); |
1191 |
|
/* read and convert file */ |
1192 |
|
dp = ourdata; |
1193 |
|
for (y = 0; y < ymax; y++) { |
1194 |
|
getscan(y); |
1195 |
|
add2icon(y, scanline); |
1196 |
< |
if (scale) |
976 |
< |
shiftcolrs(scanline, xmax, scale); |
977 |
< |
for (x = 0; x < xmax; x++) |
978 |
< |
scanline[x][GRN] = normbright(scanline[x]); |
979 |
< |
colrs_gambs(scanline, xmax); |
1196 |
> |
tmap_colrs(scanline, xmax); |
1197 |
|
if (maxcolors < 256) |
1198 |
|
for (x = 0; x < xmax; x++) |
1199 |
< |
*dp++ = ((long)scanline[x][GRN] * |
1199 |
> |
*dp++ = ((int4)scanline[x][GRN] * |
1200 |
|
maxcolors + maxcolors/2) >> 8; |
1201 |
|
else |
1202 |
|
for (x = 0; x < xmax; x++) |
1204 |
|
} |
1205 |
|
for (x = 0; x < maxcolors; x++) |
1206 |
|
clrtab[x][RED] = clrtab[x][GRN] = |
1207 |
< |
clrtab[x][BLU] = ((long)x*256 + 128)/maxcolors; |
1207 |
> |
clrtab[x][BLU] = ((int4)x*256 + 128)/maxcolors; |
1208 |
|
} |
1209 |
|
|
1210 |
|
|
1214 |
|
/* make sure we can do it first */ |
1215 |
|
if (fname == NULL) |
1216 |
|
quiterr("cannot map colors from standard input"); |
1217 |
< |
/* set gamma correction */ |
1218 |
< |
setcolrgam(gamcor); |
1217 |
> |
/* initialize tone mapping */ |
1218 |
> |
make_tonemap(); |
1219 |
|
/* make histogram */ |
1220 |
< |
new_histo(); |
1220 |
> |
if (new_histo((int4)xmax*ymax) == -1) |
1221 |
> |
quiterr("cannot initialize histogram"); |
1222 |
|
for (y = 0; y < ymax; y++) { |
1223 |
|
if (getscan(y) < 0) |
1224 |
|
break; |
1225 |
|
add2icon(y, scanline); |
1226 |
< |
if (scale) |
1009 |
< |
shiftcolrs(scanline, xmax, scale); |
1010 |
< |
colrs_gambs(scanline, xmax); |
1226 |
> |
tmap_colrs(scanline, xmax); |
1227 |
|
cnt_colrs(scanline, xmax); |
1228 |
|
} |
1229 |
|
/* map pixels */ |
1231 |
|
quiterr("cannot create color map"); |
1232 |
|
for (y = 0; y < ymax; y++) { |
1233 |
|
getscan(y); |
1234 |
< |
if (scale) |
1019 |
< |
shiftcolrs(scanline, xmax, scale); |
1020 |
< |
colrs_gambs(scanline, xmax); |
1234 |
> |
tmap_colrs(scanline, xmax); |
1235 |
|
if (dither) |
1236 |
|
dith_colrs(ourdata+y*xmax, scanline, xmax); |
1237 |
|
else |