ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/x11image.c
(Generate patch)

Comparing ray/src/px/x11image.c (file contents):
Revision 2.7 by greg, Thu May 28 09:43:09 1992 UTC vs.
Revision 2.15 by greg, Tue Oct 13 16:43:39 1992 UTC

# Line 1 | Line 1
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";
# Line 27 | Line 27 | 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"
# Line 41 | Line 40 | static char SCCSid[] = "$SunId$ LBL";
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)
44  
45   #define  revline(x0,y0,x1,y1)   XDrawLine(thedisplay,wind,revgc,x0,y0,x1,y1)
# Line 57 | Line 54 | int  fast = 0;                         /* keep picture in Pixmap? */
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 */
# Line 105 | Line 103 | char  *progname;
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();
111  
112 extern double  pow(), log();
113
112   Display  *thedisplay;
113  
114 +
115   main(argc, argv)
116   int  argc;
117   char  *argv[];
118   {
119 +        extern char  *getenv();
120 +        char  *gv;
121          int  headline();
122          int  i;
123          
124          progname = argv[0];
125 +        if ((gv = getenv("GAMMA")) != NULL)
126 +                gamcor = atof(gv);
127  
128          for (i = 1; i < argc; i++)
129                  if (argv[i][0] == '-')
# Line 241 | Line 244 | init()                 /* get data and open window */
244                          CWBackPixel|CWBorderPixel|CWColormap, &ourwinattr);
245          if (wind == 0)
246                  quiterr("cannot create window");
247 +        XFreeColormap(thedisplay, ourwinattr.colormap);
248          width = xmax;
249          height = ymax;
250          ourgc = XCreateGC(thedisplay, wind, 0, 0);
251 <        XSetState(thedisplay, ourgc, BlackPixel(thedisplay,ourscreen),
248 <                        WhitePixel(thedisplay,ourscreen), GXcopy, AllPlanes);
251 >        XSetState(thedisplay, ourgc, ourblack, ourwhite, GXcopy, AllPlanes);
252          revgc = XCreateGC(thedisplay, wind, 0, 0);
253          XSetFunction(thedisplay, revgc, GXinvert);
254          fontid = XLoadFont(thedisplay, FONTNAME);
# Line 304 | Line 307 | char  *err;
307   }
308  
309  
307 eputs(s)
308 char    *s;
309 {
310        fputs(s, stderr);
311 }
312
313
314 quit(code)
315 int  code;
316 {
317        exit(code);
318 }
319
320
310   static int
311   viscmp(v1,v2)           /* compare visual to see which is better, descending */
312   register XVisualInfo    *v1, *v2;
# Line 416 | Line 405 | static char  vistype[][12] = {
405          fprintf(stderr, "Selected visual type %s, depth %d\n",
406                          vistype[ourvis.class], ourvis.depth);
407   #endif
408 +                                        /* make appropriate adjustments */
409          if (ourvis.class == GrayScale || ourvis.class == StaticGray)
410                  greyscale = 1;
411          if (ourvis.depth <= 8 && ourvis.colormap_size < maxcolors)
412                  maxcolors = ourvis.colormap_size;
413 <        if (maxcolors > 4)
414 <                maxcolors -= 2;
413 >        if (ourvis.class == StaticGray) {
414 >                ourblack = 0;
415 >                ourwhite = 255;
416 >        } else if (ourvis.class == PseudoColor) {
417 >                ourblack = BlackPixel(thedisplay,ourscreen);
418 >                ourwhite = WhitePixel(thedisplay,ourscreen);
419 >                if ((ourblack|ourwhite) & ~255L) {
420 >                        ourblack = 0;
421 >                        ourwhite = 1;
422 >                }
423 >                if (maxcolors > 4)
424 >                        maxcolors -= 2;
425 >        } else {
426 >                ourblack = 0;
427 >                ourwhite = ourvis.red_mask|ourvis.green_mask|ourvis.blue_mask;
428 >        }
429          XFree((char *)xvi);
430   }
431  
432  
433   getras()                                /* get raster file */
434   {
431        colormap        ourmap;
435          XVisualInfo     vinfo;
436  
437          if (maxcolors <= 2) {           /* monochrome */
# Line 440 | Line 443 | getras()                               /* get raster file */
443                  if (ourras == NULL)
444                          goto fail;
445                  getmono();
446 <        } else if (ourvis.class == TrueColor || ourvis.class == DirectColor) {
446 >        } else if (ourvis.class == TrueColor | ourvis.class == DirectColor) {
447                  ourdata = (unsigned char *)malloc(4*xmax*ymax);
448                  if (ourdata == NULL)
449                          goto fail;
# Line 457 | Line 460 | getras()                               /* get raster file */
460                                  xmax, ymax, 8);
461                  if (ourras == NULL)
462                          goto fail;
463 <                if (ourvis.class == StaticGray)
463 >                if (greyscale | ourvis.class == StaticGray)
464                          getgrey();
465 <                else {
466 <                        if (greyscale)
467 <                                biq(dither,maxcolors,1,ourmap);
468 <                        else
466 <                                ciq(dither,maxcolors,1,ourmap);
467 <                        if (init_rcolors(ourras, ourmap[0],
468 <                                        ourmap[1], ourmap[2]) == 0)
469 <                                goto fail;
470 <                }
465 >                else
466 >                        getmapped();
467 >                if (ourvis.class != StaticGray && !init_rcolors(ourras,clrtab))
468 >                        goto fail;
469          }
470 <                return;
470 >        return;
471   fail:
472          quiterr("could not create raster image");
473   }
# Line 613 | Line 611 | XKeyPressedEvent  *ekey;
611                  XClearWindow(thedisplay, wind);
612                  map_rcolors(ourras, wind);
613                  if (fast)
614 <                        make_rpixmap(ourras);
614 >                        make_rpixmap(ourras, wind);
615                  redraw(0, 0, width, height);
616                  return(0);
617          case ' ':                               /* clear */
# Line 727 | Line 725 | COLOR  clr;
725                  return(-1);
726          if (left == ll && right == lr && top == lt && bottom == lb) {
727                  copycolor(clr, lc);
728 <                return;
728 >                return(0);
729          }
730          for (y = top; y < bottom; y++) {
731                  if (getscan(y) == -1)
# Line 756 | Line 754 | getmono()                      /* get monochrome data */
754                  quiterr("out of memory in getmono");
755          dp = ourdata - 1;
756          for (y = 0; y < ymax; y++) {
757 <                if (getscan(y) < 0)
760 <                        quiterr("seek error in getmono");
757 >                getscan(y);
758                  normcolrs(scanline, xmax, scale);
759                  add2icon(y, scanline);
760                  err = 0;
# Line 837 | Line 834 | getfull()                      /* get full (24-bit) data */
834                                          /* read and convert file */
835          dp = (unsigned long *)ourdata;
836          for (y = 0; y < ymax; y++) {
837 <                if (getscan(y) < 0)
841 <                        quiterr("seek error in getfull");
837 >                getscan(y);
838                  if (scale)
839                          shiftcolrs(scanline, xmax, scale);
840                  colrs_gambs(scanline, xmax);
# Line 867 | Line 863 | getgrey()                      /* get greyscale data */
863                                          /* read and convert file */
864          dp = ourdata;
865          for (y = 0; y < ymax; y++) {
866 <                if (getscan(y) < 0)
871 <                        quiterr("seek error in getfull");
866 >                getscan(y);
867                  if (scale)
868                          shiftcolrs(scanline, xmax, scale);
869                  colrs_gambs(scanline, xmax);
870                  add2icon(y, scanline);
871 <                if (ourvis.colormap_size < 256)
871 >                if (maxcolors < 256)
872                          for (x = 0; x < xmax; x++)
873                                  *dp++ = ((long)normbright(scanline[x]) *
874 <                                        ourvis.colormap_size + 128) >> 8;
874 >                                        maxcolors + 128) >> 8;
875                  else
876                          for (x = 0; x < xmax; x++)
877                                  *dp++ = normbright(scanline[x]);
878          }
879 +        for (x = 0; x < maxcolors; x++)
880 +                clrtab[x][RED] = clrtab[x][GRN] =
881 +                        clrtab[x][BLU] = ((long)x*256+maxcolors/2)/maxcolors;
882   }
883  
884  
885 + getmapped()                     /* get color-mapped data */
886 + {
887 +        int     y;
888 +                                        /* set gamma correction */
889 +        setcolrgam(gamcor);
890 +                                        /* make histogram */
891 +        new_histo();
892 +        for (y = 0; y < ymax; y++) {
893 +                if (getscan(y) < 0)
894 +                        quiterr("seek error in getmapped");
895 +                if (scale)
896 +                        shiftcolrs(scanline, xmax, scale);
897 +                colrs_gambs(scanline, xmax);
898 +                add2icon(y, scanline);
899 +                cnt_colrs(scanline, xmax);
900 +        }
901 +                                        /* map pixels */
902 +        if (!new_clrtab(maxcolors))
903 +                quiterr("cannot create color map");
904 +        for (y = 0; y < ymax; y++) {
905 +                if (getscan(y) < 0)
906 +                        quiterr("seek error in getmapped");
907 +                if (scale)
908 +                        shiftcolrs(scanline, xmax, scale);
909 +                colrs_gambs(scanline, xmax);
910 +                if (dither)
911 +                        dith_colrs(ourdata+y*xmax, scanline, xmax);
912 +                else
913 +                        map_colrs(ourdata+y*xmax, scanline, xmax);
914 +        }
915 + }
916 +
917 +
918   scale_rcolors(xr, sf)                   /* scale color map */
919   register XRASTER        *xr;
920   double  sf;
# Line 921 | Line 952 | int  y;
952                  if (fseek(fin, scanpos[y], 0) == -1)
953                          quiterr("fseek error");
954                  cury = y;
955 <        } else if (scanpos != NULL)
955 >        } else if (scanpos != NULL && scanpos[y] == -1)
956                  scanpos[y] = ftell(fin);
957  
958          if (freadcolrs(scanline, xmax, fin) < 0)
# Line 929 | Line 960 | int  y;
960  
961          cury++;
962          return(0);
932 }
933
934
935 picreadline3(y, l3)                     /* read in 3-byte scanline */
936 int  y;
937 register rgbpixel  *l3;
938 {
939        register int    i;
940                                                        /* read scanline */
941        if (getscan(y) < 0)
942                quiterr("cannot seek for picreadline");
943                                                        /* convert scanline */
944        normcolrs(scanline, xmax, scale);
945        add2icon(y, scanline);
946        for (i = 0; i < xmax; i++) {
947                l3[i].r = scanline[i][RED];
948                l3[i].g = scanline[i][GRN];
949                l3[i].b = scanline[i][BLU];
950        }
951 }
952
953
954 picwriteline(y, l)              /* add 8-bit scanline to image */
955 int  y;
956 pixel  *l;
957 {
958        bcopy((char *)l, (char *)ourdata+y*xmax, xmax);
959 }
960
961
962 picreadcm(map)                  /* do gamma correction */
963 colormap  map;
964 {
965        extern double  pow();
966        register int  i, val;
967
968        for (i = 0; i < 256; i++) {
969                val = pow((i+0.5)/256.0, 1.0/gamcor) * 256.0;
970                map[0][i] = map[1][i] = map[2][i] = val;
971        }
972 }
973
974
975 picwritecm(map)                 /* handled elsewhere */
976 colormap  map;
977 {
978 #if 0
979        register int i;
980
981        for (i = 0; i < 256; i++)
982                printf("%d %d %d\n", map[0][i],map[1][i],map[2][i]);
983 #endif
963   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines