1 |
< |
/* Copyright (c) 1991 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1992 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
27 |
|
|
28 |
|
#include "color.h" |
29 |
|
#include "view.h" |
30 |
– |
#include "pic.h" |
30 |
|
#include "x11raster.h" |
31 |
|
#include "random.h" |
32 |
|
#include "resolu.h" |
40 |
|
#define ICONSIZ (8*10) /* maximum icon dimension (even 8) */ |
41 |
|
|
42 |
|
#define ourscreen DefaultScreen(thedisplay) |
44 |
– |
#define ourblack BlackPixel(thedisplay,ourscreen) |
45 |
– |
#define ourwhite WhitePixel(thedisplay,ourscreen) |
43 |
|
#define ourroot RootWindow(thedisplay,ourscreen) |
47 |
– |
#define ourgc DefaultGC(thedisplay,ourscreen) |
44 |
|
|
45 |
|
#define revline(x0,y0,x1,y1) XDrawLine(thedisplay,wind,revgc,x0,y0,x1,y1) |
46 |
|
|
51 |
|
int dither = 1; /* dither colors? */ |
52 |
|
int fast = 0; /* keep picture in Pixmap? */ |
53 |
|
|
54 |
+ |
char *dispname = NULL; /* our display name */ |
55 |
+ |
|
56 |
|
Window wind = 0; /* our output window */ |
57 |
+ |
unsigned long ourblack=0, ourwhite=1; /* black and white for this visual */ |
58 |
|
Font fontid; /* our font */ |
59 |
|
|
60 |
|
int maxcolors = 0; /* maximum colors */ |
82 |
|
|
83 |
|
int wrongformat = 0; /* input in another format? */ |
84 |
|
|
85 |
+ |
GC ourgc; /* standard graphics context */ |
86 |
|
GC revgc; /* graphics context with GXinvert */ |
87 |
|
|
88 |
< |
XRASTER *ourras; /* our stored image */ |
88 |
> |
int *ourrank; /* our visual class ranking */ |
89 |
> |
XVisualInfo ourvis; /* our visual */ |
90 |
> |
XRASTER *ourras; /* our stored image */ |
91 |
|
unsigned char *ourdata; /* our image data */ |
92 |
|
|
93 |
|
struct { |
103 |
|
|
104 |
|
char errmsg[128]; |
105 |
|
|
106 |
+ |
extern BYTE clrtab[256][3]; /* global color map */ |
107 |
+ |
|
108 |
|
extern long ftell(); |
109 |
|
|
110 |
|
extern char *malloc(), *calloc(); |
117 |
|
int argc; |
118 |
|
char *argv[]; |
119 |
|
{ |
120 |
+ |
extern char *getenv(); |
121 |
+ |
char *gv; |
122 |
|
int headline(); |
123 |
|
int i; |
124 |
|
|
125 |
|
progname = argv[0]; |
126 |
+ |
if ((gv = getenv("GAMMA")) != NULL) |
127 |
+ |
gamcor = atof(gv); |
128 |
|
|
129 |
|
for (i = 1; i < argc; i++) |
130 |
|
if (argv[i][0] == '-') |
139 |
|
maxcolors = 2; |
140 |
|
break; |
141 |
|
case 'd': |
142 |
< |
dither = !dither; |
142 |
> |
if (argv[i][2] == 'i') |
143 |
> |
dispname = argv[++i]; |
144 |
> |
else |
145 |
> |
dither = !dither; |
146 |
|
break; |
147 |
|
case 'f': |
148 |
|
fast = !fast; |
153 |
|
scale = atoi(argv[++i]); |
154 |
|
break; |
155 |
|
case 'g': |
156 |
< |
if (!strcmp(argv[i], "-geometry")) |
156 |
> |
if (argv[i][2] == 'e') |
157 |
|
geometry = argv[++i]; |
158 |
|
else |
159 |
|
gamcor = atof(argv[++i]); |
170 |
|
fname = argv[i]; |
171 |
|
fin = fopen(fname, "r"); |
172 |
|
if (fin == NULL) { |
173 |
< |
sprintf(errmsg, "can't open file \"%s\"", fname); |
173 |
> |
sprintf(errmsg, "cannot open file \"%s\"", fname); |
174 |
|
quiterr(errmsg); |
175 |
|
} |
176 |
|
} else if (i != argc) |
194 |
|
getevent(); /* main loop */ |
195 |
|
userr: |
196 |
|
fprintf(stderr, |
197 |
< |
"Usage: %s [-geometry spec][-b][-m][-d][-f][-c ncolors][-e +/-stops] file\n", |
197 |
> |
"Usage: %s [-display disp][-geometry spec][-b][-m][-d][-f][-c ncolors][-e +/-stops] file\n", |
198 |
|
progname); |
199 |
|
quit(1); |
200 |
|
} |
219 |
|
{ |
220 |
|
XWMHints ourxwmhints; |
221 |
|
XSetWindowAttributes ourwinattr; |
222 |
< |
XSizeHints oursizhints; |
223 |
< |
register int i; |
222 |
> |
XSizeHints oursizhints; |
223 |
> |
register int i; |
224 |
|
|
225 |
|
if (fname != NULL) { |
226 |
|
scanpos = (long *)malloc(ymax*sizeof(long)); |
229 |
|
for (i = 0; i < ymax; i++) |
230 |
|
scanpos[i] = -1; |
231 |
|
} |
232 |
< |
if ((thedisplay = XOpenDisplay(NULL)) == NULL) |
233 |
< |
quiterr("can't open display; DISPLAY variable set?"); |
234 |
< |
if (maxcolors == 0) { /* get number of available colors */ |
235 |
< |
i = DisplayPlanes(thedisplay,ourscreen); |
225 |
< |
maxcolors = i > 8 ? 256 : 1<<i; |
226 |
< |
if (maxcolors > 4) maxcolors -= 2; |
227 |
< |
} |
232 |
> |
if ((thedisplay = XOpenDisplay(dispname)) == NULL) |
233 |
> |
quiterr("cannot open display"); |
234 |
> |
/* get best visual for default screen */ |
235 |
> |
getbestvis(); |
236 |
|
/* store image */ |
237 |
|
getras(); |
238 |
|
/* open window */ |
239 |
|
ourwinattr.border_pixel = ourblack; |
240 |
|
ourwinattr.background_pixel = ourwhite; |
241 |
+ |
ourwinattr.colormap = XCreateColormap(thedisplay, ourroot, |
242 |
+ |
ourvis.visual, AllocNone); |
243 |
|
wind = XCreateWindow(thedisplay, ourroot, 0, 0, xmax, ymax, BORWIDTH, |
244 |
< |
0, InputOutput, ourras->visual, |
245 |
< |
CWBackPixel|CWBorderPixel, &ourwinattr); |
244 |
> |
ourvis.depth, InputOutput, ourvis.visual, |
245 |
> |
CWBackPixel|CWBorderPixel|CWColormap, &ourwinattr); |
246 |
|
if (wind == 0) |
247 |
< |
quiterr("can't create window"); |
247 |
> |
quiterr("cannot create window"); |
248 |
> |
XFreeColormap(thedisplay, ourwinattr.colormap); |
249 |
|
width = xmax; |
250 |
|
height = ymax; |
251 |
+ |
ourgc = XCreateGC(thedisplay, wind, 0, 0); |
252 |
+ |
XSetState(thedisplay, ourgc, ourblack, ourwhite, GXcopy, AllPlanes); |
253 |
+ |
revgc = XCreateGC(thedisplay, wind, 0, 0); |
254 |
+ |
XSetFunction(thedisplay, revgc, GXinvert); |
255 |
|
fontid = XLoadFont(thedisplay, FONTNAME); |
256 |
|
if (fontid == 0) |
257 |
< |
quiterr("can't get font"); |
257 |
> |
quiterr("cannot get font"); |
258 |
|
XSetFont(thedisplay, ourgc, fontid); |
244 |
– |
revgc = XCreateGC(thedisplay, wind, 0, 0); |
245 |
– |
XSetFunction(thedisplay, revgc, GXinvert); |
259 |
|
XDefineCursor(thedisplay, wind, XCreateFontCursor(thedisplay, |
260 |
|
XC_diamond_cross)); |
261 |
|
XStoreName(thedisplay, wind, fname == NULL ? progname : fname); |
322 |
|
} |
323 |
|
|
324 |
|
|
325 |
+ |
static int |
326 |
+ |
viscmp(v1,v2) /* compare visual to see which is better, descending */ |
327 |
+ |
register XVisualInfo *v1, *v2; |
328 |
+ |
{ |
329 |
+ |
int bad1 = 0, bad2 = 0; |
330 |
+ |
register int *rp; |
331 |
+ |
|
332 |
+ |
if (v1->class == v2->class) { |
333 |
+ |
if (v1->class == TrueColor || v1->class == DirectColor) { |
334 |
+ |
/* prefer 24-bit to 32-bit */ |
335 |
+ |
if (v1->depth == 24 && v2->depth == 32) |
336 |
+ |
return(-1); |
337 |
+ |
if (v1->depth == 32 && v2->depth == 24) |
338 |
+ |
return(1); |
339 |
+ |
return(0); |
340 |
+ |
} |
341 |
+ |
/* don't be too greedy */ |
342 |
+ |
if (maxcolors <= 1<<v1->depth && maxcolors <= 1<<v2->depth) |
343 |
+ |
return(v1->depth - v2->depth); |
344 |
+ |
return(v2->depth - v1->depth); |
345 |
+ |
} |
346 |
+ |
/* prefer Pseudo when < 24-bit */ |
347 |
+ |
if ((v1->class == TrueColor || v1->class == DirectColor) && |
348 |
+ |
v1->depth < 24) |
349 |
+ |
bad1 = 1; |
350 |
+ |
if ((v2->class == TrueColor || v2->class == DirectColor) && |
351 |
+ |
v2->depth < 24) |
352 |
+ |
bad2 = -1; |
353 |
+ |
if (bad1 | bad2) |
354 |
+ |
return(bad1+bad2); |
355 |
+ |
/* otherwise, use class ranking */ |
356 |
+ |
for (rp = ourrank; *rp != -1; rp++) { |
357 |
+ |
if (v1->class == *rp) |
358 |
+ |
return(-1); |
359 |
+ |
if (v2->class == *rp) |
360 |
+ |
return(1); |
361 |
+ |
} |
362 |
+ |
return(0); |
363 |
+ |
} |
364 |
+ |
|
365 |
+ |
|
366 |
+ |
getbestvis() /* get the best visual for this screen */ |
367 |
+ |
{ |
368 |
+ |
#ifdef DEBUG |
369 |
+ |
static char vistype[][12] = { |
370 |
+ |
"StaticGray", |
371 |
+ |
"GrayScale", |
372 |
+ |
"StaticColor", |
373 |
+ |
"PseudoColor", |
374 |
+ |
"TrueColor", |
375 |
+ |
"DirectColor" |
376 |
+ |
}; |
377 |
+ |
#endif |
378 |
+ |
static int rankings[3][6] = { |
379 |
+ |
{TrueColor,DirectColor,PseudoColor,GrayScale,StaticGray,-1}, |
380 |
+ |
{PseudoColor,GrayScale,StaticGray,-1}, |
381 |
+ |
{PseudoColor,GrayScale,StaticGray,-1} |
382 |
+ |
}; |
383 |
+ |
XVisualInfo *xvi; |
384 |
+ |
int vismatched; |
385 |
+ |
register int i, j; |
386 |
+ |
|
387 |
+ |
if (greyscale) { |
388 |
+ |
ourrank = rankings[2]; |
389 |
+ |
if (maxcolors < 2) maxcolors = 256; |
390 |
+ |
} else if (maxcolors >= 2 && maxcolors <= 256) |
391 |
+ |
ourrank = rankings[1]; |
392 |
+ |
else { |
393 |
+ |
ourrank = rankings[0]; |
394 |
+ |
maxcolors = 256; |
395 |
+ |
} |
396 |
+ |
/* find best visual */ |
397 |
+ |
ourvis.screen = ourscreen; |
398 |
+ |
xvi = XGetVisualInfo(thedisplay,VisualScreenMask,&ourvis,&vismatched); |
399 |
+ |
if (xvi == NULL) |
400 |
+ |
quiterr("no visuals for this screen!"); |
401 |
+ |
#ifdef DEBUG |
402 |
+ |
fprintf(stderr, "Supported visuals:\n"); |
403 |
+ |
for (i = 0; i < vismatched; i++) |
404 |
+ |
fprintf(stderr, "\ttype %s, depth %d\n", |
405 |
+ |
vistype[xvi[i].class], xvi[i].depth); |
406 |
+ |
#endif |
407 |
+ |
for (i = 0, j = 1; j < vismatched; j++) |
408 |
+ |
if (viscmp(&xvi[i],&xvi[j]) > 0) |
409 |
+ |
i = j; |
410 |
+ |
/* compare to least acceptable */ |
411 |
+ |
for (j = 0; ourrank[j++] != -1; ) |
412 |
+ |
; |
413 |
+ |
ourvis.class = ourrank[--j]; |
414 |
+ |
ourvis.depth = 1; |
415 |
+ |
if (viscmp(&xvi[i],&ourvis) > 0) |
416 |
+ |
quiterr("inadequate visuals on this screen"); |
417 |
+ |
/* OK, we'll use it */ |
418 |
+ |
copystruct(&ourvis, &xvi[i]); |
419 |
+ |
#ifdef DEBUG |
420 |
+ |
fprintf(stderr, "Selected visual type %s, depth %d\n", |
421 |
+ |
vistype[ourvis.class], ourvis.depth); |
422 |
+ |
#endif |
423 |
+ |
/* make appropriate adjustments */ |
424 |
+ |
if (ourvis.class == GrayScale || ourvis.class == StaticGray) |
425 |
+ |
greyscale = 1; |
426 |
+ |
if (ourvis.depth <= 8 && ourvis.colormap_size < maxcolors) |
427 |
+ |
maxcolors = ourvis.colormap_size; |
428 |
+ |
if (ourvis.class == StaticGray) { |
429 |
+ |
ourblack = 0; |
430 |
+ |
ourwhite = 255; |
431 |
+ |
} else if (ourvis.class == PseudoColor) { |
432 |
+ |
ourblack = BlackPixel(thedisplay,ourscreen); |
433 |
+ |
ourwhite = WhitePixel(thedisplay,ourscreen); |
434 |
+ |
if ((ourblack|ourwhite) & ~255L) { |
435 |
+ |
ourblack = 0; |
436 |
+ |
ourwhite = 1; |
437 |
+ |
} |
438 |
+ |
if (maxcolors > 4) |
439 |
+ |
maxcolors -= 2; |
440 |
+ |
} else { |
441 |
+ |
ourblack = 0; |
442 |
+ |
ourwhite = ourvis.red_mask|ourvis.green_mask|ourvis.blue_mask; |
443 |
+ |
} |
444 |
+ |
XFree((char *)xvi); |
445 |
+ |
} |
446 |
+ |
|
447 |
+ |
|
448 |
|
getras() /* get raster file */ |
449 |
|
{ |
314 |
– |
colormap ourmap; |
450 |
|
XVisualInfo vinfo; |
451 |
|
|
452 |
|
if (maxcolors <= 2) { /* monochrome */ |
453 |
|
ourdata = (unsigned char *)malloc(ymax*((xmax+7)/8)); |
454 |
|
if (ourdata == NULL) |
455 |
|
goto fail; |
456 |
< |
ourras = make_raster(thedisplay, ourscreen, 1, ourdata, |
456 |
> |
ourras = make_raster(thedisplay, &ourvis, 1, ourdata, |
457 |
|
xmax, ymax, 8); |
458 |
|
if (ourras == NULL) |
459 |
|
goto fail; |
460 |
|
getmono(); |
461 |
< |
} else if (XMatchVisualInfo(thedisplay,ourscreen,24,TrueColor,&vinfo) |
462 |
< |
/* kludge for DirectColor */ |
328 |
< |
|| XMatchVisualInfo(thedisplay,ourscreen,24,DirectColor,&vinfo)) { |
329 |
< |
ourdata = (unsigned char *)malloc(xmax*ymax*3); |
461 |
> |
} else if (ourvis.class == TrueColor | ourvis.class == DirectColor) { |
462 |
> |
ourdata = (unsigned char *)malloc(4*xmax*ymax); |
463 |
|
if (ourdata == NULL) |
464 |
|
goto fail; |
465 |
< |
ourras = make_raster(thedisplay, ourscreen, 24, ourdata, |
466 |
< |
xmax, ymax, 8); |
465 |
> |
ourras = make_raster(thedisplay, &ourvis, 32, |
466 |
> |
ourdata, xmax, ymax, 32); |
467 |
|
if (ourras == NULL) |
468 |
|
goto fail; |
469 |
|
getfull(); |
471 |
|
ourdata = (unsigned char *)malloc(xmax*ymax); |
472 |
|
if (ourdata == NULL) |
473 |
|
goto fail; |
474 |
< |
ourras = make_raster(thedisplay, ourscreen, 8, ourdata, |
474 |
> |
ourras = make_raster(thedisplay, &ourvis, 8, ourdata, |
475 |
|
xmax, ymax, 8); |
476 |
|
if (ourras == NULL) |
477 |
|
goto fail; |
478 |
< |
if (greyscale) |
479 |
< |
biq(dither,maxcolors,1,ourmap); |
478 |
> |
if (greyscale | ourvis.class == StaticGray) |
479 |
> |
getgrey(); |
480 |
|
else |
481 |
< |
ciq(dither,maxcolors,1,ourmap); |
482 |
< |
if (init_rcolors(ourras, ourmap[0], ourmap[1], ourmap[2]) == 0) |
481 |
> |
getmapped(); |
482 |
> |
if (ourvis.class != StaticGray && !init_rcolors(ourras,clrtab)) |
483 |
|
goto fail; |
484 |
|
} |
485 |
|
return; |
510 |
|
case MapNotify: |
511 |
|
map_rcolors(ourras, wind); |
512 |
|
if (fast) |
513 |
< |
make_rpixmap(ourras); |
513 |
> |
make_rpixmap(ourras, wind); |
514 |
|
break; |
515 |
|
case UnmapNotify: |
516 |
< |
unmap_rcolors(ourras); |
516 |
> |
if (!fast) |
517 |
> |
unmap_rcolors(ourras); |
518 |
|
break; |
519 |
|
case Expose: |
520 |
|
redraw(e.e.x, e.e.y, e.e.width, e.e.height); |
626 |
|
XClearWindow(thedisplay, wind); |
627 |
|
map_rcolors(ourras, wind); |
628 |
|
if (fast) |
629 |
< |
make_rpixmap(ourras); |
629 |
> |
make_rpixmap(ourras, wind); |
630 |
|
redraw(0, 0, width, height); |
631 |
|
return(0); |
632 |
|
case ' ': /* clear */ |
843 |
|
getfull() /* get full (24-bit) data */ |
844 |
|
{ |
845 |
|
int y; |
846 |
+ |
register unsigned long *dp; |
847 |
+ |
register int x; |
848 |
+ |
/* set gamma correction */ |
849 |
+ |
setcolrgam(gamcor); |
850 |
+ |
/* read and convert file */ |
851 |
+ |
dp = (unsigned long *)ourdata; |
852 |
+ |
for (y = 0; y < ymax; y++) { |
853 |
+ |
if (getscan(y) < 0) |
854 |
+ |
quiterr("seek error in getfull"); |
855 |
+ |
if (scale) |
856 |
+ |
shiftcolrs(scanline, xmax, scale); |
857 |
+ |
colrs_gambs(scanline, xmax); |
858 |
+ |
add2icon(y, scanline); |
859 |
+ |
if (ourras->image->blue_mask & 1) |
860 |
+ |
for (x = 0; x < xmax; x++) |
861 |
+ |
*dp++ = scanline[x][RED] << 16 | |
862 |
+ |
scanline[x][GRN] << 8 | |
863 |
+ |
scanline[x][BLU] ; |
864 |
+ |
else |
865 |
+ |
for (x = 0; x < xmax; x++) |
866 |
+ |
*dp++ = scanline[x][RED] | |
867 |
+ |
scanline[x][GRN] << 8 | |
868 |
+ |
scanline[x][BLU] << 16 ; |
869 |
+ |
} |
870 |
+ |
} |
871 |
+ |
|
872 |
+ |
|
873 |
+ |
getgrey() /* get greyscale data */ |
874 |
+ |
{ |
875 |
+ |
int y; |
876 |
|
register unsigned char *dp; |
877 |
|
register int x; |
878 |
|
/* set gamma correction */ |
881 |
|
dp = ourdata; |
882 |
|
for (y = 0; y < ymax; y++) { |
883 |
|
if (getscan(y) < 0) |
884 |
< |
quiterr("seek error in getfull"); |
884 |
> |
quiterr("seek error in getgrey"); |
885 |
|
if (scale) |
886 |
|
shiftcolrs(scanline, xmax, scale); |
887 |
|
colrs_gambs(scanline, xmax); |
888 |
|
add2icon(y, scanline); |
889 |
< |
for (x = 0; x < xmax; x++) { /* BGR byte ordering */ |
890 |
< |
*dp++ = scanline[x][BLU]; |
891 |
< |
*dp++ = scanline[x][GRN]; |
892 |
< |
*dp++ = scanline[x][RED]; |
893 |
< |
} |
889 |
> |
if (maxcolors < 256) |
890 |
> |
for (x = 0; x < xmax; x++) |
891 |
> |
*dp++ = ((long)normbright(scanline[x]) * |
892 |
> |
maxcolors + 128) >> 8; |
893 |
> |
else |
894 |
> |
for (x = 0; x < xmax; x++) |
895 |
> |
*dp++ = normbright(scanline[x]); |
896 |
|
} |
897 |
+ |
for (x = 0; x < maxcolors; x++) |
898 |
+ |
clrtab[x][RED] = clrtab[x][GRN] = |
899 |
+ |
clrtab[x][BLU] = (x*256+maxcolors/2)/maxcolors; |
900 |
|
} |
901 |
|
|
902 |
|
|
903 |
+ |
getmapped() /* get color-mapped data */ |
904 |
+ |
{ |
905 |
+ |
int y; |
906 |
+ |
/* set gamma correction */ |
907 |
+ |
setcolrgam(gamcor); |
908 |
+ |
/* make histogram */ |
909 |
+ |
new_histo(); |
910 |
+ |
for (y = 0; y < ymax; y++) { |
911 |
+ |
if (getscan(y) < 0) |
912 |
+ |
quiterr("seek error in getmapped"); |
913 |
+ |
if (scale) |
914 |
+ |
shiftcolrs(scanline, xmax, scale); |
915 |
+ |
colrs_gambs(scanline, xmax); |
916 |
+ |
add2icon(y, scanline); |
917 |
+ |
cnt_colrs(scanline, xmax); |
918 |
+ |
} |
919 |
+ |
/* map pixels */ |
920 |
+ |
if (!new_clrtab(maxcolors)) |
921 |
+ |
quiterr("cannot create color map"); |
922 |
+ |
for (y = 0; y < ymax; y++) { |
923 |
+ |
if (getscan(y) < 0) |
924 |
+ |
quiterr("seek error in getmapped"); |
925 |
+ |
if (scale) |
926 |
+ |
shiftcolrs(scanline, xmax, scale); |
927 |
+ |
colrs_gambs(scanline, xmax); |
928 |
+ |
if (dither) |
929 |
+ |
dith_colrs(ourdata+y*xmax, scanline, xmax); |
930 |
+ |
else |
931 |
+ |
map_colrs(ourdata+y*xmax, scanline, xmax); |
932 |
+ |
} |
933 |
+ |
} |
934 |
+ |
|
935 |
+ |
|
936 |
|
scale_rcolors(xr, sf) /* scale color map */ |
937 |
|
register XRASTER *xr; |
938 |
|
double sf; |
970 |
|
if (fseek(fin, scanpos[y], 0) == -1) |
971 |
|
quiterr("fseek error"); |
972 |
|
cury = y; |
973 |
< |
} else if (scanpos != NULL) |
973 |
> |
} else if (scanpos != NULL && scanpos[y] == -1) |
974 |
|
scanpos[y] = ftell(fin); |
975 |
|
|
976 |
|
if (freadcolrs(scanline, xmax, fin) < 0) |
978 |
|
|
979 |
|
cury++; |
980 |
|
return(0); |
779 |
– |
} |
780 |
– |
|
781 |
– |
|
782 |
– |
picreadline3(y, l3) /* read in 3-byte scanline */ |
783 |
– |
int y; |
784 |
– |
register rgbpixel *l3; |
785 |
– |
{ |
786 |
– |
register int i; |
787 |
– |
/* read scanline */ |
788 |
– |
if (getscan(y) < 0) |
789 |
– |
quiterr("cannot seek for picreadline"); |
790 |
– |
/* convert scanline */ |
791 |
– |
normcolrs(scanline, xmax, scale); |
792 |
– |
add2icon(y, scanline); |
793 |
– |
for (i = 0; i < xmax; i++) { |
794 |
– |
l3[i].r = scanline[i][RED]; |
795 |
– |
l3[i].g = scanline[i][GRN]; |
796 |
– |
l3[i].b = scanline[i][BLU]; |
797 |
– |
} |
798 |
– |
} |
799 |
– |
|
800 |
– |
|
801 |
– |
picwriteline(y, l) /* add 8-bit scanline to image */ |
802 |
– |
int y; |
803 |
– |
pixel *l; |
804 |
– |
{ |
805 |
– |
bcopy((char *)l, (char *)ourdata+y*xmax, xmax); |
806 |
– |
} |
807 |
– |
|
808 |
– |
|
809 |
– |
picreadcm(map) /* do gamma correction */ |
810 |
– |
colormap map; |
811 |
– |
{ |
812 |
– |
extern double pow(); |
813 |
– |
register int i, val; |
814 |
– |
|
815 |
– |
for (i = 0; i < 256; i++) { |
816 |
– |
val = pow((i+0.5)/256.0, 1.0/gamcor) * 256.0; |
817 |
– |
map[0][i] = map[1][i] = map[2][i] = val; |
818 |
– |
} |
819 |
– |
} |
820 |
– |
|
821 |
– |
|
822 |
– |
picwritecm(map) /* handled elsewhere */ |
823 |
– |
colormap map; |
824 |
– |
{ |
825 |
– |
#ifdef DEBUG |
826 |
– |
register int i; |
827 |
– |
|
828 |
– |
for (i = 0; i < 256; i++) |
829 |
– |
printf("%d %d %d\n", map[0][i],map[1][i],map[2][i]); |
830 |
– |
#endif |
981 |
|
} |