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.16 by greg, Thu Oct 22 17:51:05 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();
111  
111 extern double  pow(), log();
112
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 240 | 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);
# Line 302 | Line 307 | char  *err;
307   }
308  
309  
305 eputs(s)
306 char    *s;
307 {
308        fputs(s, stderr);
309 }
310
311
312 quit(code)
313 int  code;
314 {
315        exit(code);
316 }
317
318
310   static int
311   viscmp(v1,v2)           /* compare visual to see which is better, descending */
312   register XVisualInfo    *v1, *v2;
# Line 419 | Line 410 | static char  vistype[][12] = {
410                  greyscale = 1;
411          if (ourvis.depth <= 8 && ourvis.colormap_size < maxcolors)
412                  maxcolors = ourvis.colormap_size;
422        if (maxcolors > 4)
423                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 = ~0;
427 >                ourwhite = ourvis.red_mask|ourvis.green_mask|ourvis.blue_mask;
428          }
429          XFree((char *)xvi);
430   }
# Line 437 | Line 432 | static char  vistype[][12] = {
432  
433   getras()                                /* get raster file */
434   {
440        colormap        ourmap;
435          XVisualInfo     vinfo;
436  
437          if (maxcolors <= 2) {           /* monochrome */
# Line 449 | 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 466 | 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
475 <                                ciq(dither,maxcolors,1,ourmap);
476 <                        if (init_rcolors(ourras, ourmap[0],
477 <                                        ourmap[1], ourmap[2]) == 0)
478 <                                goto fail;
479 <                }
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 622 | 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 736 | 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 765 | 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)
769 <                        quiterr("seek error in getmono");
770 <                normcolrs(scanline, xmax, scale);
757 >                getscan(y);
758                  add2icon(y, scanline);
759 +                normcolrs(scanline, xmax, scale);
760                  err = 0;
761                  for (x = 0; x < xmax; x++) {
762                          if (!(x&7))
# Line 794 | Line 782 | COLR  *scan;
782          static short  cerr[ICONSIZ];
783          static int  ynext;
784          static char  *dp;
785 +        double  sf;
786 +        COLOR  col;
787          register int  err;
788          register int    x, ti;
789          int  errp;
# Line 818 | Line 808 | COLR  *scan;
808          }
809          if (y < ynext*ymax/iconheight)  /* skip this one */
810                  return;
811 +        sf = pow(2.0, (double)(scale+8));
812          err = 0;
813          for (x = 0; x < iconwidth; x++) {
814                  if (!(x&7))
815                          *++dp = 0;
816                  errp = err;
817                  ti = x*xmax/iconwidth;
818 <                err += normbright(scan[ti]) + cerr[x];
818 >                colr_color(col, scan[ti]);
819 >                ti = sf*bright(col);
820 >                if (ti > 255) ti = 255;
821 >                err += ti + cerr[x];
822                  if (err > 127)
823                          err -= 255;
824                  else
# Line 846 | Line 840 | getfull()                      /* get full (24-bit) data */
840                                          /* read and convert file */
841          dp = (unsigned long *)ourdata;
842          for (y = 0; y < ymax; y++) {
843 <                if (getscan(y) < 0)
844 <                        quiterr("seek error in getfull");
843 >                getscan(y);
844 >                add2icon(y, scanline);
845                  if (scale)
846                          shiftcolrs(scanline, xmax, scale);
847                  colrs_gambs(scanline, xmax);
854                add2icon(y, scanline);
848                  if (ourras->image->blue_mask & 1)
849                          for (x = 0; x < xmax; x++)
850                                  *dp++ = scanline[x][RED] << 16 |
# Line 876 | Line 869 | getgrey()                      /* get greyscale data */
869                                          /* read and convert file */
870          dp = ourdata;
871          for (y = 0; y < ymax; y++) {
872 <                if (getscan(y) < 0)
873 <                        quiterr("seek error in getfull");
872 >                getscan(y);
873 >                add2icon(y, scanline);
874                  if (scale)
875                          shiftcolrs(scanline, xmax, scale);
876                  colrs_gambs(scanline, xmax);
877 <                add2icon(y, scanline);
885 <                if (ourvis.colormap_size < 256)
877 >                if (maxcolors < 256)
878                          for (x = 0; x < xmax; x++)
879                                  *dp++ = ((long)normbright(scanline[x]) *
880 <                                        ourvis.colormap_size + 128) >> 8;
880 >                                        maxcolors + 128) >> 8;
881                  else
882                          for (x = 0; x < xmax; x++)
883                                  *dp++ = normbright(scanline[x]);
884          }
885 +        for (x = 0; x < maxcolors; x++)
886 +                clrtab[x][RED] = clrtab[x][GRN] =
887 +                        clrtab[x][BLU] = ((long)x*256+maxcolors/2)/maxcolors;
888   }
889  
890  
891 + getmapped()                     /* get color-mapped data */
892 + {
893 +        int     y;
894 +                                        /* set gamma correction */
895 +        setcolrgam(gamcor);
896 +                                        /* make histogram */
897 +        new_histo();
898 +        for (y = 0; y < ymax; y++) {
899 +                if (getscan(y) < 0)
900 +                        quiterr("seek error in getmapped");
901 +                add2icon(y, scanline);
902 +                if (scale)
903 +                        shiftcolrs(scanline, xmax, scale);
904 +                colrs_gambs(scanline, xmax);
905 +                cnt_colrs(scanline, xmax);
906 +        }
907 +                                        /* map pixels */
908 +        if (!new_clrtab(maxcolors))
909 +                quiterr("cannot create color map");
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 +                if (dither)
917 +                        dith_colrs(ourdata+y*xmax, scanline, xmax);
918 +                else
919 +                        map_colrs(ourdata+y*xmax, scanline, xmax);
920 +        }
921 + }
922 +
923 +
924   scale_rcolors(xr, sf)                   /* scale color map */
925   register XRASTER        *xr;
926   double  sf;
# Line 930 | Line 958 | int  y;
958                  if (fseek(fin, scanpos[y], 0) == -1)
959                          quiterr("fseek error");
960                  cury = y;
961 <        } else if (scanpos != NULL)
961 >        } else if (scanpos != NULL && scanpos[y] == -1)
962                  scanpos[y] = ftell(fin);
963  
964          if (freadcolrs(scanline, xmax, fin) < 0)
# Line 938 | Line 966 | int  y;
966  
967          cury++;
968          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
969   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines