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

Comparing ray/src/px/vgaimage.c (file contents):
Revision 2.1 by greg, Tue Oct 13 17:42:07 1992 UTC vs.
Revision 2.11 by schorsch, Fri Jan 2 12:47:01 2004 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1992 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  vgaimage.c - driver for VGA board under DOS
6   */
7  
8 + #include <stdio.h>
9 +
10   #include  "standard.h"
11   #include  <graph.h>
12   #include  "color.h"
# Line 16 | Line 15 | static char SCCSid[] = "$SunId$ LBL";
15   #include <dos.h>
16   #include <i86.h>
17  
18 < #define  M_RDOWN        0x8
19 < #define  M_RUP          0x10
20 < #define  M_LDOWN        0x2
21 < #define  M_LUP          0x4
22 < #define  M_MOTION       0x1
18 > #define  M_RDOWN        0x8
19 > #define  M_RUP          0x10
20 > #define  M_LDOWN        0x2
21 > #define  M_LUP          0x4
22 > #define  M_MOTION       0x1
23  
24   int crad;
26 #define right_button (mouse_event & M_RIGHTBUTT)
27 #define left_button (mouse_event & M_LEFTBUTT)
25   int mouse_event = 0;
26   int mouse_xpos = -1;
27   int mouse_ypos = -1;
28  
29 + #define  hide_cursor()  move_cursor(-1,-1)
30 + #define  show_cursor()  move_cursor(mouse_xpos,mouse_ypos)
31  
32 < #define  CTRL(c)        ((c)-'@')
32 > #define  CTRL(c)        ((c)-'@')
33  
34 < #define  MAXWIDTH       1024
35 < #define  MAXHEIGHT      768
34 > #define  MAXWIDTH       1024
35 > #define  MAXHEIGHT      768
36  
37   short  ourblack = 0; ourwhite = 1;
38  
39 < double  gamcor = 2.2;                   /* gamma correction */
39 > double  gamcor = 2.2;                   /* gamma correction */
40  
41 < int  dither = 1;                        /* dither colors? */
41 > int  dither = 1;                        /* dither colors? */
42  
43 < int  maxcolors = 0;                     /* maximum colors */
44 < int  minpix = 0;                        /* minimum pixel value */
45 < int  greyscale = 0;                     /* in grey */
43 > int  maxcolors = 0;                     /* maximum colors */
44 > int  minpix = 0;                        /* minimum pixel value */
45 > int  greyscale = 0;                     /* in grey */
46  
47 < int  scale = 0;                         /* scalefactor; power of two */
47 > int  scale = 0;                         /* scalefactor; power of two */
48  
49 < COLR  scanline[MAXWIDTH];               /* scan line buffer */
49 > COLR  scanline[MAXWIDTH];               /* scan line buffer */
50  
51 < int  xmax, ymax;                        /* picture dimensions */
52 < FILE  *fin = stdin;                     /* input file */
53 < long  scanpos[MAXHEIGHT];               /* scan line positions in file */
54 < int  cury = 0;                          /* current scan location */
51 > int  xmax, ymax;                        /* picture dimensions */
52 > FILE  *fin = stdin;                     /* input file */
53 > long  scanpos[MAXHEIGHT];               /* scan line positions in file */
54 > int  cury = 0;                          /* current scan location */
55  
56 < double  exposure = 1.0;                 /* exposure compensation used */
56 > double  exposure = 1.0;                 /* exposure compensation used */
57  
58 < int  wrongformat = 0;                   /* input in another format? */
58 > int  wrongformat = 0;                   /* input in another format? */
59  
60   struct {
61          int  xmin, ymin, xsiz, ysiz;
62 < }  box = {0, 0, 0, 0};                  /* current box */
62 > }  box = {0, 0, 0, 0};                  /* current box */
63  
64   int  initialized = 0;
65   int  cheight, cwidth;
66  
67 < #define postext(x,y)    _settextposition(1+(y)/cheight,1+(x)/cwidth)
67 > #define postext(x,y)    _settextposition(1+(y)/cheight,1+(x)/cwidth)
68  
69   char  *progname;
70  
71   char  errmsg[128];
72  
73 < extern BYTE  clrtab[256][3];            /* global color map */
73 > extern BYTE  clrtab[256][3];            /* global color map */
74  
75 < extern long  ftell();
75 > static gethfunc headline;
76  
77  
78   main(argc, argv)
# Line 82 | Line 81 | char  *argv[];
81   {
82          extern char  *getenv(), *fixargv0();
83          char  *gv;
85        int  headline();
84          int  i;
85 <        
85 >
86          progname = argv[0] = fixargv0(argv[0]);
87 <        if ((gv = getenv("GAMMA")) != NULL)
87 >        if ((gv = getenv("DISPLAY_GAMMA")) != NULL)
88                  gamcor = atof(gv);
89  
90          for (i = 1; i < argc; i++)
# Line 118 | Line 116 | char  *argv[];
116                  else
117                          break;
118  
119 <        if (i == argc-1) {              /* open picture */
119 >        if (i == argc-1) {              /* open picture */
120                  fin = fopen(argv[i], "r");
121                  if (fin == NULL) {
122                          sprintf(errmsg, "cannot open file \"%s\"", argv[i]);
# Line 135 | Line 133 | char  *argv[];
133          if (xmax > MAXWIDTH | ymax > MAXHEIGHT)
134                  quiterr("input picture too large for VGA");
135  
136 <        init();                 /* initialize and display */
136 >        init();                 /* initialize and display */
137  
138 <        while (docommand())     /* loop on command */
138 >        while (docommand())     /* loop on command */
139                  ;
140          quiterr(NULL);
141   userr:
# Line 147 | Line 145 | userr:
145   }
146  
147  
148 < headline(s)             /* get relevant info from header */
149 < char  *s;
148 > static int
149 > headline(               /* get relevant info from header */
150 >        char    *s,
151 >        void    *p
152 > )
153   {
154          char  fmt[32];
155  
# Line 158 | Line 159 | char  *s;
159                  formatval(fmt, s);
160                  wrongformat = strcmp(fmt, COLRFMT);
161          }
162 +        return(0);
163   }
164  
165  
166 < init()                  /* initialize and load display */
166 > init()                  /* initialize and load display */
167   {
168          static struct {
169 <                short   mode;
170 <                short   xsiz, ysiz;
171 <        } video[] = {    
169 >                short   mode;
170 >                short   xsiz, ysiz;
171 >        } video[] = {
172                  {_MRES256COLOR, 320, 200},
173 <                {_VRES256COLOR, 640, 400},
173 >                {_VRES256COLOR, 640, 480},
174                  {_SVRES256COLOR, 800, 600},
175                  {_XRES256COLOR, 1024, 768},
176 <                -1
176 >                {-1, 0, 0}
177          };
178 <        struct videoconfig      config;
179 <        register int    i;
178 >        struct videoconfig      config;
179 >        register int    i;
180                                  /* pick a card... */
181          for (i = 0; video[i].mode != -1; i++)
182                  if (video[i].xsiz >= xmax && video[i].ysiz >= ymax)
# Line 183 | Line 185 | init()                  /* initialize and load display
185                  quiterr("input picture too large");
186          if (_setvideomode(video[i].mode) == 0)
187                  quiterr("inadequate display card for picture");
188 +        ms_init();
189          initialized = 1;
190          _getvideoconfig(&config);
191 <        if (maxcolors == 0)
192 <                maxcolors = config.numcolors;
193 <        if (maxcolors > 4) {
194 <                maxcolors -= minpix = 2;
195 <                _settextcolor(ourwhite);
196 <        }
191 >        if (maxcolors == 0 | maxcolors > config.numcolors)
192 >                maxcolors = config.numcolors-2;
193 >        if (maxcolors <= config.numcolors-2)
194 >                minpix = 2;
195 >        else
196 >                ourwhite = maxcolors-1;
197 >        _settextcolor(ourwhite);
198          cheight = config.numypixels/config.numtextrows;
199          cwidth = config.numxpixels/config.numtextcols;
200                                  /* clear scan position array */
# Line 204 | Line 208 | init()                  /* initialize and load display
208   }
209  
210  
211 < quiterr(err)            /* print message and exit */
211 > quiterr(err)            /* print message and exit */
212   char  *err;
213   {
214 <        if (initialized)
214 >        if (initialized) {
215 >                ms_done();
216                  _setvideomode(_DEFAULTMODE);
217 +        }
218          if (err != NULL) {
219                  fprintf(stderr, "%s: %s\n", progname, err);
220                  exit(1);
# Line 218 | Line 224 | char  *err;
224  
225  
226   int
227 < docommand()                     /* execute command */
227 > docommand()                     /* execute command */
228   {
229          char  buf[64];
230          COLOR  cval;
231          int  com;
232 <        double  comp;
232 >        double  comp;
233  
234          while (!kbhit())
235                  watch_mouse();
236          com = getch();
237 <        switch (com) {                  /* interpret command */
237 >        switch (com) {                  /* interpret command */
238          case 'q':
239 <        case CTRL('Z'):                         /* quit */
239 >        case CTRL('Z'):                         /* quit */
240                  return(0);
241          case '\n':
242          case '\r':
243          case 'l':
244 <        case 'c':                               /* value */
244 >        case 'c':                               /* value */
245                  if (avgbox(cval) == -1)
246                          return(-1);
247                  switch (com) {
248                  case '\n':
249 <                case '\r':                              /* radiance */
249 >                case '\r':                              /* radiance */
250                          sprintf(buf, "%.3f", intens(cval)/exposure);
251                          break;
252 <                case 'l':                               /* luminance */
252 >                case 'l':                               /* luminance */
253                          sprintf(buf, "%.0fL", luminance(cval)/exposure);
254                          break;
255 <                case 'c':                               /* color */
255 >                case 'c':                               /* color */
256                          comp = pow(2.0, (double)scale);
257                          sprintf(buf, "(%.2f,%.2f,%.2f)",
258                                          colval(cval,RED)*comp,
# Line 255 | Line 261 | docommand()                     /* execute command */
261                          break;
262                  }
263                  postext(box.xmin+box.xsiz/2, box.ymin+box.ysiz/2);
264 +                hide_cursor();
265                  _outtext(buf);
266 +                show_cursor();
267                  return(1);
268          default:
269                  return(-1);
# Line 263 | Line 271 | docommand()                     /* execute command */
271   }
272  
273  
274 < watch_mouse()                   /* look after mousie */
274 > watch_mouse()                   /* look after mousie */
275   {
276 <        static int      mouse_installed = 0;
269 <        int     a_x, a_y, l_x, l_y;
276 >        int     a_x, a_y, l_x, l_y;
277  
271        if (!mouse_installed) {
272                ms_init();
273                mouse_installed = 1;
274        }
278          if (mouse_event & M_MOTION)
279                  move_cursor(mouse_xpos, mouse_ypos);
280          if (!(mouse_event & M_LDOWN))
281                  return;
282          l_x = a_x = mouse_xpos; l_y = a_y = mouse_ypos;
283 <        move_cursor(-1, -1);                    /* hide cursor */
284 <        revbox(a_x, a_y, l_x, l_y);             /* show box */
283 >        hide_cursor();
284 >        revbox(a_x, a_y, l_x, l_y);             /* show box */
285          do {
286                  mouse_event = 0;
287                  while (!mouse_event)
# Line 288 | Line 291 | watch_mouse()                   /* look after mousie *
291                          revbox(a_x, a_y, l_x=mouse_xpos, l_y=mouse_ypos);
292                  }
293          } while (!(mouse_event & M_LUP));
294 <        revbox(a_x, a_y, l_x, l_y);             /* hide box */
295 <        move_cursor(mouse_xpos, mouse_ypos);    /* show cursor */
294 >        revbox(a_x, a_y, l_x, l_y);             /* hide box */
295 >        show_cursor();
296          box.xmin = mouse_xpos;
297          box.ymin = mouse_ypos;
298          if (box.xmin > a_x) {
# Line 308 | Line 311 | watch_mouse()                   /* look after mousie *
311   }
312  
313  
314 < revbox(x0, y0, x1, y1)                  /* draw box with reversed lines */
314 > revbox(x0, y0, x1, y1)                  /* draw box with reversed lines */
315   int  x0, y0, x1, y1;
316   {
317          _setplotaction(_GXOR);
# Line 322 | Line 325 | int  x0, y0, x1, y1;
325  
326  
327   int
328 < avgbox(clr)                             /* average color over current box */
328 > avgbox(clr)                             /* average color over current box */
329   COLOR  clr;
330   {
331          static COLOR  lc;
332          static int  ll, lr, lt, lb;
333          int  left, right, top, bottom;
334          int  y;
335 <        double  d;
335 >        double  d;
336          COLOR  ctmp;
337          register int  x;
338  
# Line 370 | Line 373 | COLOR  clr;
373   }
374  
375  
376 < setpalette()                    /* set our palette using clrtab */
376 > setpalette()                    /* set our palette using clrtab */
377   {
378 <        long    cvals[256];
379 <        register int    i;
378 >        long    cvals[256];
379 >        register int    i;
380  
381 <        if (minpix >= 2) {
382 <                cvals[ourblack] = _BLACK; cvals[ourwhite] = _BRIGHTWHITE;
380 <        }
381 >        cvals[ourblack] = _BLACK;
382 >        cvals[ourwhite] = _BRIGHTWHITE;
383          for (i = 0; i < maxcolors; i++)
384 <                cvals[i+minpix] = clrtab[i][BLU]<<14 & 0x3f0000L |
384 >                cvals[i+minpix] = (long)clrtab[i][BLU]<<14 & 0x3f0000L |
385                                    clrtab[i][GRN]<<6 & 0x3f00 |
386                                    clrtab[i][RED]>>2;
387          _remapallpalette(cvals);
388   }
389  
390  
391 < greyimage()                     /* display greyscale image */
391 > greyimage()                     /* display greyscale image */
392   {
393 <        short   thiscolor, lastcolor = -1;
394 <        int     y;
395 <        register int    x;
393 >        short   thiscolor, lastcolor = -1;
394 >        int     y;
395 >        register int    x;
396                                          /* set gamma correction */
397          setcolrgam(gamcor);
398                                          /* set up color map */
399          for (x = 0; x < maxcolors; x++)
400 <                clrtab[x][RED] = clrtab[x][GRN] =
401 <                        clrtab[x][BLU] = ((long)x*256+maxcolors/2)/maxcolors;
400 >                clrtab[x][RED] = clrtab[x][GRN] = clrtab[x][BLU] =
401 >                                ((long)x*256 + 128)/maxcolors;
402          setpalette();
403          _setplotaction(_GPSET);
404                                          /* read and display file */
# Line 404 | Line 406 | greyimage()                     /* display greyscale i
406                  getscan(y);
407                  if (scale)
408                          shiftcolrs(scanline, xmax, scale);
409 +                for (x = 0; x < xmax; x++)
410 +                        scanline[x][GRN] = normbright(scanline[x]);
411                  colrs_gambs(scanline, xmax);
412                  if (maxcolors < 256)
413 <                        for (x = 0; x < xmax; x++) {
414 <                                thiscolor = ((long)normbright(scanline[x]) *
415 <                                        maxcolors + 128) >> 8;
413 >                        for (x = 0; x < xmax; x++) {
414 >                                thiscolor = ((long)scanline[x][GRN] *
415 >                                                maxcolors + maxcolors/2) / 256;
416                                  if (thiscolor != lastcolor)
417                                          _setcolor((lastcolor=thiscolor)+minpix);
418                                  _setpixel(x, y);
419                          }
420                  else
421                          for (x = 0; x < xmax; x++) {
422 <                                thiscolor = normbright(scanline[x]);
422 >                                thiscolor = scanline[x][GRN];
423                                  if (thiscolor != lastcolor)
424                                          _setcolor((lastcolor=thiscolor)+minpix);
425                                  _setpixel(x, y);
# Line 424 | Line 428 | greyimage()                     /* display greyscale i
428   }
429  
430  
431 < mappedimage()                   /* display color-mapped image */
431 > mappedimage()                   /* display color-mapped image */
432   {
433 <        BYTE    bscan[MAXWIDTH];
434 <        int     y;
435 <        register int    x;
433 >        BYTE    bscan[MAXWIDTH];
434 >        int     y;
435 >        register int    x;
436                                          /* set gamma correction */
437          setcolrgam(gamcor);
438                                          /* make histogram */
439 +        _outtext("Quantizing image -- Please wait...");
440          new_histo();
441          for (y = 0; y < ymax; y++) {
442                  if (getscan(y) < 0)
# Line 475 | Line 480 | int  y;
480                  if (fseek(fin, scanpos[y], 0) == -1)
481                          quiterr("fseek error");
482                  cury = y;
483 <        } else if (scanpos != NULL && scanpos[y] == -1)
483 >        } else if (fin != stdin && scanpos[y] == -1)
484                  scanpos[y] = ftell(fin);
485  
486          if (freadcolrs(scanline, xmax, fin) < 0)
# Line 497 | Line 502 | void _loadds far mouse_handler (int max, int mcx, int
502   #pragma aux mouse_handler parm [EAX] [ECX] [EDX]
503          mouse_event = max;
504          mouse_xpos = mcx;
505 <        mouse_ypos = mdx * (long)ymax / 200;       /* kludge */
501 <        if (mouse_xpos >= xmax) mouse_xpos = xmax-1;
502 <        if (mouse_ypos >= ymax) mouse_ypos = ymax-1;
505 >        mouse_ypos = mdx;
506   }
507   #pragma on (check_stack)
508  
509  
510   void
511 < move_cursor(newx, newy)         /* move cursor to new position */
511 > move_cursor(newx, newy)         /* move cursor to new position */
512   int  newx, newy;
513   {
514          static char  *imp = NULL;
515          static int  curx = -1, cury = -1;
516 < #define xcmin           (curx-crad<0 ? 0 : curx-crad)
517 < #define ycmin           (cury-crad<0 ? 0 : cury-crad)
518 < #define xcmax           (curx+crad>=xmax ? xmax-1 : curx+crad)
519 < #define ycmax           (cury+crad>=ymax ? ymax-1 : cury+crad)
516 > #define xcmin           (curx-crad<0 ? 0 : curx-crad)
517 > #define ycmin           (cury-crad<0 ? 0 : cury-crad)
518 > #define xcmax           (curx+crad>=xmax ? xmax-1 : curx+crad)
519 > #define ycmax           (cury+crad>=ymax ? ymax-1 : cury+crad)
520  
521          if (newx == curx & newy == cury)
522                  return;
523 <        if (imp == NULL &&
523 >        if (imp == NULL &&
524                  (imp = bmalloc(_imagesize(0,0,2*crad+1,2*crad+1))) == NULL) {
525                  quiterr("out of memory in move_cursor");
526          }
527 <        if (curx >= 0 & cury >= 0)      /* clear old cursor */
527 >        if (curx >= 0 & cury >= 0)      /* clear old cursor */
528                  _putimage(xcmin, ycmin, imp, _GPSET);
529                                          /* record new position */
530          curx = newx; cury = newy;
531          if (curx < 0 | cury < 0)
532 <                return;         /* no cursor */
532 >                return;         /* no cursor */
533                                          /* save under new cursor */
534          _getimage(xcmin, ycmin, xcmax, ycmax, imp);
535                                          /* draw new cursor */
# Line 565 | Line 568 | ms_init()
568      }
569  
570      crad = ymax/40;
571 <    
571 >
572 >    /* set screen limits */
573 >
574 >    inregs.w.ax = 0x7;          /* horizontal resolution */
575 >    inregs.w.cx = 0;
576 >    inregs.w.dx = xmax-1;
577 >    int386x( 0x33, &inregs, &outregs, &sregs );
578 >    inregs.w.ax = 0x8;          /* vertical resolution */
579 >    inregs.w.cx = 0;
580 >    inregs.w.dx = ymax-1;
581 >    int386x( 0x33, &inregs, &outregs, &sregs );
582 >
583      /* install watcher */
584  
585      inregs.w.ax = 0xC;
586      inregs.w.cx = M_LDOWN | M_LUP | M_MOTION;
587      function_ptr = mouse_handler;
588      inregs.x.edx = FP_OFF( function_ptr );
589 <    sregs.es     = FP_SEG( function_ptr );
589 >    sregs.es     = FP_SEG( function_ptr );
590      int386x( 0x33, &inregs, &outregs, &sregs );
591 <    
591 >
592      return(1);
593 + }
594 +
595 + ms_done()
596 + {
597 +    union REGS inregs, outregs;
598 +
599 +    /* uninstall watcher */
600 +
601 +    inregs.w.ax = 0;
602 +    int386 (0x33, &inregs, &outregs);
603   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines