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.2 by greg, Wed Oct 14 18:56:58 1992 UTC vs.
Revision 2.3 by greg, Fri Oct 16 13:09:36 1992 UTC

# Line 16 | Line 16 | static char SCCSid[] = "$SunId$ LBL";
16   #include <dos.h>
17   #include <i86.h>
18  
19 < #define  M_RDOWN        0x8
20 < #define  M_RUP          0x10
21 < #define  M_LDOWN        0x2
22 < #define  M_LUP          0x4
23 < #define  M_MOTION       0x1
19 > #define  M_RDOWN        0x8
20 > #define  M_RUP          0x10
21 > #define  M_LDOWN        0x2
22 > #define  M_LUP          0x4
23 > #define  M_MOTION       0x1
24  
25   int crad;
26   int mouse_event = 0;
27   int mouse_xpos = -1;
28   int mouse_ypos = -1;
29  
30 < #define  hide_cursor    move_cursor(-1,-1)
31 < #define  show_cursor    move_cursor(mouse_xpos,mouse_ypos)
30 > #define  hide_cursor()  move_cursor(-1,-1)
31 > #define  show_cursor()  move_cursor(mouse_xpos,mouse_ypos)
32  
33 < #define  CTRL(c)        ((c)-'@')
33 > #define  CTRL(c)        ((c)-'@')
34  
35 < #define  MAXWIDTH       1024
36 < #define  MAXHEIGHT      768
35 > #define  MAXWIDTH       1024
36 > #define  MAXHEIGHT      768
37  
38   short  ourblack = 0; ourwhite = 1;
39  
40 < double  gamcor = 2.2;                   /* gamma correction */
40 > double  gamcor = 2.2;                   /* gamma correction */
41  
42 < int  dither = 1;                        /* dither colors? */
42 > int  dither = 1;                        /* dither colors? */
43  
44 < int  maxcolors = 0;                     /* maximum colors */
45 < int  minpix = 0;                        /* minimum pixel value */
46 < int  greyscale = 0;                     /* in grey */
44 > int  maxcolors = 0;                     /* maximum colors */
45 > int  minpix = 0;                        /* minimum pixel value */
46 > int  greyscale = 0;                     /* in grey */
47  
48 < int  scale = 0;                         /* scalefactor; power of two */
48 > int  scale = 0;                         /* scalefactor; power of two */
49  
50 < COLR  scanline[MAXWIDTH];               /* scan line buffer */
50 > COLR  scanline[MAXWIDTH];               /* scan line buffer */
51  
52 < int  xmax, ymax;                        /* picture dimensions */
53 < FILE  *fin = stdin;                     /* input file */
54 < long  scanpos[MAXHEIGHT];               /* scan line positions in file */
55 < int  cury = 0;                          /* current scan location */
52 > int  xmax, ymax;                        /* picture dimensions */
53 > FILE  *fin = stdin;                     /* input file */
54 > long  scanpos[MAXHEIGHT];               /* scan line positions in file */
55 > int  cury = 0;                          /* current scan location */
56  
57 < double  exposure = 1.0;                 /* exposure compensation used */
57 > double  exposure = 1.0;                 /* exposure compensation used */
58  
59 < int  wrongformat = 0;                   /* input in another format? */
59 > int  wrongformat = 0;                   /* input in another format? */
60  
61   struct {
62          int  xmin, ymin, xsiz, ysiz;
63 < }  box = {0, 0, 0, 0};                  /* current box */
63 > }  box = {0, 0, 0, 0};                  /* current box */
64  
65   int  initialized = 0;
66   int  cheight, cwidth;
67  
68 < #define postext(x,y)    _settextposition(1+(y)/cheight,1+(x)/cwidth)
68 > #define postext(x,y)    _settextposition(1+(y)/cheight,1+(x)/cwidth)
69  
70   char  *progname;
71  
72   char  errmsg[128];
73  
74 < extern BYTE  clrtab[256][3];            /* global color map */
74 > extern BYTE  clrtab[256][3];            /* global color map */
75  
76   extern long  ftell();
77  
# Line 84 | Line 84 | char  *argv[];
84          char  *gv;
85          int  headline();
86          int  i;
87 <        
87 >
88          progname = argv[0] = fixargv0(argv[0]);
89          if ((gv = getenv("GAMMA")) != NULL)
90                  gamcor = atof(gv);
# Line 118 | Line 118 | char  *argv[];
118                  else
119                          break;
120  
121 <        if (i == argc-1) {              /* open picture */
121 >        if (i == argc-1) {              /* open picture */
122                  fin = fopen(argv[i], "r");
123                  if (fin == NULL) {
124                          sprintf(errmsg, "cannot open file \"%s\"", argv[i]);
# Line 135 | Line 135 | char  *argv[];
135          if (xmax > MAXWIDTH | ymax > MAXHEIGHT)
136                  quiterr("input picture too large for VGA");
137  
138 <        init();                 /* initialize and display */
138 >        init();                 /* initialize and display */
139  
140 <        while (docommand())     /* loop on command */
140 >        while (docommand())     /* loop on command */
141                  ;
142          quiterr(NULL);
143   userr:
# Line 147 | Line 147 | userr:
147   }
148  
149  
150 < headline(s)             /* get relevant info from header */
150 > headline(s)             /* get relevant info from header */
151   char  *s;
152   {
153          char  fmt[32];
# Line 161 | Line 161 | char  *s;
161   }
162  
163  
164 < init()                  /* initialize and load display */
164 > init()                  /* initialize and load display */
165   {
166          static struct {
167 <                short   mode;
168 <                short   xsiz, ysiz;
169 <        } video[] = {    
167 >                short   mode;
168 >                short   xsiz, ysiz;
169 >        } video[] = {
170                  {_MRES256COLOR, 320, 200},
171                  {_VRES256COLOR, 640, 400},
172                  {_SVRES256COLOR, 800, 600},
173                  {_XRES256COLOR, 1024, 768},
174                  -1
175          };
176 <        struct videoconfig      config;
177 <        register int    i;
176 >        struct videoconfig      config;
177 >        register int    i;
178                                  /* pick a card... */
179          for (i = 0; video[i].mode != -1; i++)
180                  if (video[i].xsiz >= xmax && video[i].ysiz >= ymax)
# Line 204 | Line 204 | init()                  /* initialize and load display
204   }
205  
206  
207 < quiterr(err)            /* print message and exit */
207 > quiterr(err)            /* print message and exit */
208   char  *err;
209   {
210          if (initialized)
# Line 218 | Line 218 | char  *err;
218  
219  
220   int
221 < docommand()                     /* execute command */
221 > docommand()                     /* execute command */
222   {
223          char  buf[64];
224          COLOR  cval;
225          int  com;
226 <        double  comp;
226 >        double  comp;
227  
228          while (!kbhit())
229                  watch_mouse();
230          com = getch();
231 <        switch (com) {                  /* interpret command */
231 >        switch (com) {                  /* interpret command */
232          case 'q':
233 <        case CTRL('Z'):                         /* quit */
233 >        case CTRL('Z'):                         /* quit */
234                  return(0);
235          case '\n':
236          case '\r':
237          case 'l':
238 <        case 'c':                               /* value */
238 >        case 'c':                               /* value */
239                  if (avgbox(cval) == -1)
240                          return(-1);
241                  switch (com) {
242                  case '\n':
243 <                case '\r':                              /* radiance */
243 >                case '\r':                              /* radiance */
244                          sprintf(buf, "%.3f", intens(cval)/exposure);
245                          break;
246 <                case 'l':                               /* luminance */
246 >                case 'l':                               /* luminance */
247                          sprintf(buf, "%.0fL", luminance(cval)/exposure);
248                          break;
249 <                case 'c':                               /* color */
249 >                case 'c':                               /* color */
250                          comp = pow(2.0, (double)scale);
251                          sprintf(buf, "(%.2f,%.2f,%.2f)",
252                                          colval(cval,RED)*comp,
# Line 265 | Line 265 | docommand()                     /* execute command */
265   }
266  
267  
268 < watch_mouse()                   /* look after mousie */
268 > watch_mouse()                   /* look after mousie */
269   {
270 <        static int      mouse_installed = 0;
271 <        int     a_x, a_y, l_x, l_y;
270 >        static int      mouse_installed = 0;
271 >        int     a_x, a_y, l_x, l_y;
272  
273          if (!mouse_installed) {
274                  ms_init();
# Line 280 | Line 280 | watch_mouse()                   /* look after mousie *
280                  return;
281          l_x = a_x = mouse_xpos; l_y = a_y = mouse_ypos;
282          hide_cursor();
283 <        revbox(a_x, a_y, l_x, l_y);             /* show box */
283 >        revbox(a_x, a_y, l_x, l_y);             /* show box */
284          do {
285                  mouse_event = 0;
286                  while (!mouse_event)
# Line 290 | Line 290 | watch_mouse()                   /* look after mousie *
290                          revbox(a_x, a_y, l_x=mouse_xpos, l_y=mouse_ypos);
291                  }
292          } while (!(mouse_event & M_LUP));
293 <        revbox(a_x, a_y, l_x, l_y);             /* hide box */
293 >        revbox(a_x, a_y, l_x, l_y);             /* hide box */
294          show_cursor();
295          box.xmin = mouse_xpos;
296          box.ymin = mouse_ypos;
# Line 310 | Line 310 | watch_mouse()                   /* look after mousie *
310   }
311  
312  
313 < revbox(x0, y0, x1, y1)                  /* draw box with reversed lines */
313 > revbox(x0, y0, x1, y1)                  /* draw box with reversed lines */
314   int  x0, y0, x1, y1;
315   {
316          _setplotaction(_GXOR);
# Line 324 | Line 324 | int  x0, y0, x1, y1;
324  
325  
326   int
327 < avgbox(clr)                             /* average color over current box */
327 > avgbox(clr)                             /* average color over current box */
328   COLOR  clr;
329   {
330          static COLOR  lc;
331          static int  ll, lr, lt, lb;
332          int  left, right, top, bottom;
333          int  y;
334 <        double  d;
334 >        double  d;
335          COLOR  ctmp;
336          register int  x;
337  
# Line 372 | Line 372 | COLOR  clr;
372   }
373  
374  
375 < setpalette()                    /* set our palette using clrtab */
375 > setpalette()                    /* set our palette using clrtab */
376   {
377 <        long    cvals[256];
378 <        register int    i;
377 >        long    cvals[256];
378 >        register int    i;
379  
380          if (minpix >= 2) {
381                  cvals[ourblack] = _BLACK; cvals[ourwhite] = _BRIGHTWHITE;
# Line 388 | Line 388 | setpalette()                    /* set our palette usi
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 */
# Line 408 | Line 408 | greyimage()                     /* display greyscale i
408                          shiftcolrs(scanline, xmax, scale);
409                  colrs_gambs(scanline, xmax);
410                  if (maxcolors < 256)
411 <                        for (x = 0; x < xmax; x++) {
411 >                        for (x = 0; x < xmax; x++) {
412                                  thiscolor = ((long)normbright(scanline[x]) *
413                                          maxcolors + 128) >> 8;
414                                  if (thiscolor != lastcolor)
# Line 426 | Line 426 | greyimage()                     /* display greyscale i
426   }
427  
428  
429 < mappedimage()                   /* display color-mapped image */
429 > mappedimage()                   /* display color-mapped image */
430   {
431 <        BYTE    bscan[MAXWIDTH];
432 <        int     y;
433 <        register int    x;
431 >        BYTE    bscan[MAXWIDTH];
432 >        int     y;
433 >        register int    x;
434                                          /* set gamma correction */
435          setcolrgam(gamcor);
436                                          /* make histogram */
# Line 499 | Line 499 | void _loadds far mouse_handler (int max, int mcx, int
499   #pragma aux mouse_handler parm [EAX] [ECX] [EDX]
500          mouse_event = max;
501          mouse_xpos = mcx;
502 <        mouse_ypos = mdx * (long)ymax / 200;       /* kludge */
503 <        if (mouse_xpos >= xmax) mouse_xpos = xmax-1;
504 <        if (mouse_ypos >= ymax) mouse_ypos = ymax-1;
502 >        mouse_ypos = mdx;
503   }
504   #pragma on (check_stack)
505  
506  
507   void
508 < move_cursor(newx, newy)         /* move cursor to new position */
508 > move_cursor(newx, newy)         /* move cursor to new position */
509   int  newx, newy;
510   {
511          static char  *imp = NULL;
512          static int  curx = -1, cury = -1;
513 < #define xcmin           (curx-crad<0 ? 0 : curx-crad)
514 < #define ycmin           (cury-crad<0 ? 0 : cury-crad)
515 < #define xcmax           (curx+crad>=xmax ? xmax-1 : curx+crad)
516 < #define ycmax           (cury+crad>=ymax ? ymax-1 : cury+crad)
513 > #define xcmin           (curx-crad<0 ? 0 : curx-crad)
514 > #define ycmin           (cury-crad<0 ? 0 : cury-crad)
515 > #define xcmax           (curx+crad>=xmax ? xmax-1 : curx+crad)
516 > #define ycmax           (cury+crad>=ymax ? ymax-1 : cury+crad)
517  
518          if (newx == curx & newy == cury)
519                  return;
520 <        if (imp == NULL &&
520 >        if (imp == NULL &&
521                  (imp = bmalloc(_imagesize(0,0,2*crad+1,2*crad+1))) == NULL) {
522                  quiterr("out of memory in move_cursor");
523          }
524 <        if (curx >= 0 & cury >= 0)      /* clear old cursor */
524 >        if (curx >= 0 & cury >= 0)      /* clear old cursor */
525                  _putimage(xcmin, ycmin, imp, _GPSET);
526                                          /* record new position */
527          curx = newx; cury = newy;
528          if (curx < 0 | cury < 0)
529 <                return;         /* no cursor */
529 >                return;         /* no cursor */
530                                          /* save under new cursor */
531          _getimage(xcmin, ycmin, xcmax, ycmax, imp);
532                                          /* draw new cursor */
# Line 567 | Line 565 | ms_init()
565      }
566  
567      crad = ymax/40;
568 <    
568 >
569 >    /* set screen limits */
570 >
571 >    inregs.w.ax = 0x7;          /* horizontal resolution */
572 >    inregs.w.cx = 0;
573 >    inregs.w.dx = xmax-1;
574 >    int386x( 0x33, &inregs, &outregs, &sregs );
575 >    inregs.w.ax = 0x8;          /* vertical resolution */
576 >    inregs.w.cx = 0;
577 >    inregs.w.dx = ymax-1;
578 >    int386x( 0x33, &inregs, &outregs, &sregs );
579 >
580      /* install watcher */
581  
582      inregs.w.ax = 0xC;
583      inregs.w.cx = M_LDOWN | M_LUP | M_MOTION;
584      function_ptr = mouse_handler;
585      inregs.x.edx = FP_OFF( function_ptr );
586 <    sregs.es     = FP_SEG( function_ptr );
586 >    sregs.es     = FP_SEG( function_ptr );
587      int386x( 0x33, &inregs, &outregs, &sregs );
588 <    
588 >
589      return(1);
590   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines