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.8 by greg, Fri May 29 14:21:12 1992 UTC vs.
Revision 2.13 by greg, Mon Oct 12 12:59:22 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 55 | 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=1, ourwhite=0;  /* black and white for this visual */
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 104 | 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();
# Line 116 | Line 117 | main(argc, argv)
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] == '-')
# Line 240 | Line 245 | init()                 /* get data and open window */
245                          CWBackPixel|CWBorderPixel|CWColormap, &ourwinattr);
246          if (wind == 0)
247                  quiterr("cannot create window");
248 +        XFreeColormap(thedisplay, ourwinattr.colormap);
249          width = xmax;
250          height = ymax;
251          ourgc = XCreateGC(thedisplay, wind, 0, 0);
# Line 419 | Line 425 | static char  vistype[][12] = {
425                  greyscale = 1;
426          if (ourvis.depth <= 8 && ourvis.colormap_size < maxcolors)
427                  maxcolors = ourvis.colormap_size;
422        if (maxcolors > 4)
423                maxcolors -= 2;
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 = ~0;
442 >                ourwhite = ourvis.red_mask|ourvis.green_mask|ourvis.blue_mask;
443          }
444          XFree((char *)xvi);
445   }
# Line 437 | Line 447 | static char  vistype[][12] = {
447  
448   getras()                                /* get raster file */
449   {
440        colormap        ourmap;
450          XVisualInfo     vinfo;
451  
452          if (maxcolors <= 2) {           /* monochrome */
# Line 449 | Line 458 | getras()                               /* get raster file */
458                  if (ourras == NULL)
459                          goto fail;
460                  getmono();
461 <        } else if (ourvis.class == TrueColor || ourvis.class == DirectColor) {
461 >        } else if (ourvis.class == TrueColor | ourvis.class == DirectColor) {
462                  ourdata = (unsigned char *)malloc(4*xmax*ymax);
463                  if (ourdata == NULL)
464                          goto fail;
# Line 466 | Line 475 | getras()                               /* get raster file */
475                                  xmax, ymax, 8);
476                  if (ourras == NULL)
477                          goto fail;
478 <                if (ourvis.class == StaticGray)
478 >                if (greyscale | ourvis.class == StaticGray)
479                          getgrey();
480 <                else {
481 <                        if (greyscale)
482 <                                biq(dither,maxcolors,1,ourmap);
483 <                        else
475 <                                ciq(dither,maxcolors,1,ourmap);
476 <                        if (init_rcolors(ourras, ourmap[0],
477 <                                        ourmap[1], ourmap[2]) == 0)
478 <                                goto fail;
479 <                }
480 >                else
481 >                        getmapped();
482 >                if (ourvis.class != StaticGray && !init_rcolors(ourras,clrtab))
483 >                        goto fail;
484          }
485 <                return;
485 >        return;
486   fail:
487          quiterr("could not create raster image");
488   }
# Line 622 | Line 626 | XKeyPressedEvent  *ekey;
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 */
# Line 877 | Line 881 | getgrey()                      /* get greyscale data */
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 <                if (ourvis.colormap_size < 256)
889 >                if (maxcolors < 256)
890                          for (x = 0; x < xmax; x++)
891                                  *dp++ = ((long)normbright(scanline[x]) *
892 <                                        ourvis.colormap_size + 128) >> 8;
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;
# Line 930 | Line 970 | int  y;
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)
# Line 938 | Line 978 | int  y;
978  
979          cury++;
980          return(0);
941 }
942
943
944 picreadline3(y, l3)                     /* read in 3-byte scanline */
945 int  y;
946 register rgbpixel  *l3;
947 {
948        register int    i;
949                                                        /* read scanline */
950        if (getscan(y) < 0)
951                quiterr("cannot seek for picreadline");
952                                                        /* convert scanline */
953        normcolrs(scanline, xmax, scale);
954        add2icon(y, scanline);
955        for (i = 0; i < xmax; i++) {
956                l3[i].r = scanline[i][RED];
957                l3[i].g = scanline[i][GRN];
958                l3[i].b = scanline[i][BLU];
959        }
960 }
961
962
963 picwriteline(y, l)              /* add 8-bit scanline to image */
964 int  y;
965 pixel  *l;
966 {
967        bcopy((char *)l, (char *)ourdata+y*xmax, xmax);
968 }
969
970
971 picreadcm(map)                  /* do gamma correction */
972 colormap  map;
973 {
974        extern double  pow();
975        register int  i, val;
976
977        for (i = 0; i < 256; i++) {
978                val = pow((i+0.5)/256.0, 1.0/gamcor) * 256.0;
979                map[0][i] = map[1][i] = map[2][i] = val;
980        }
981 }
982
983
984 picwritecm(map)                 /* handled elsewhere */
985 colormap  map;
986 {
987 #if 0
988        register int i;
989
990        for (i = 0; i < 256; i++)
991                printf("%d %d %d\n", map[0][i],map[1][i],map[2][i]);
992 #endif
981   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines