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.4 by greg, Mon Nov 2 16:01:17 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 183 | Line 183 | init()                  /* initialize and load display
183                  quiterr("input picture too large");
184          if (_setvideomode(video[i].mode) == 0)
185                  quiterr("inadequate display card for picture");
186 +        ms_init();
187          initialized = 1;
188          _getvideoconfig(&config);
189          if (maxcolors == 0)
# Line 204 | Line 205 | init()                  /* initialize and load display
205   }
206  
207  
208 < quiterr(err)            /* print message and exit */
208 > quiterr(err)            /* print message and exit */
209   char  *err;
210   {
211 <        if (initialized)
211 >        if (initialized) {
212 >                ms_done();
213                  _setvideomode(_DEFAULTMODE);
214 +        }
215          if (err != NULL) {
216                  fprintf(stderr, "%s: %s\n", progname, err);
217                  exit(1);
# Line 218 | Line 221 | char  *err;
221  
222  
223   int
224 < docommand()                     /* execute command */
224 > docommand()                     /* execute command */
225   {
226          char  buf[64];
227          COLOR  cval;
228          int  com;
229 <        double  comp;
229 >        double  comp;
230  
231          while (!kbhit())
232                  watch_mouse();
233          com = getch();
234 <        switch (com) {                  /* interpret command */
234 >        switch (com) {                  /* interpret command */
235          case 'q':
236 <        case CTRL('Z'):                         /* quit */
236 >        case CTRL('Z'):                         /* quit */
237                  return(0);
238          case '\n':
239          case '\r':
240          case 'l':
241 <        case 'c':                               /* value */
241 >        case 'c':                               /* value */
242                  if (avgbox(cval) == -1)
243                          return(-1);
244                  switch (com) {
245                  case '\n':
246 <                case '\r':                              /* radiance */
246 >                case '\r':                              /* radiance */
247                          sprintf(buf, "%.3f", intens(cval)/exposure);
248                          break;
249 <                case 'l':                               /* luminance */
249 >                case 'l':                               /* luminance */
250                          sprintf(buf, "%.0fL", luminance(cval)/exposure);
251                          break;
252 <                case 'c':                               /* color */
252 >                case 'c':                               /* color */
253                          comp = pow(2.0, (double)scale);
254                          sprintf(buf, "(%.2f,%.2f,%.2f)",
255                                          colval(cval,RED)*comp,
# Line 265 | Line 268 | docommand()                     /* execute command */
268   }
269  
270  
271 < watch_mouse()                   /* look after mousie */
271 > watch_mouse()                   /* look after mousie */
272   {
273 <        static int      mouse_installed = 0;
271 <        int     a_x, a_y, l_x, l_y;
273 >        int     a_x, a_y, l_x, l_y;
274  
273        if (!mouse_installed) {
274                ms_init();
275                mouse_installed = 1;
276        }
275          if (mouse_event & M_MOTION)
276                  move_cursor(mouse_xpos, mouse_ypos);
277          if (!(mouse_event & M_LDOWN))
278                  return;
279          l_x = a_x = mouse_xpos; l_y = a_y = mouse_ypos;
280          hide_cursor();
281 <        revbox(a_x, a_y, l_x, l_y);             /* show box */
281 >        revbox(a_x, a_y, l_x, l_y);             /* show box */
282          do {
283                  mouse_event = 0;
284                  while (!mouse_event)
# Line 290 | Line 288 | watch_mouse()                   /* look after mousie *
288                          revbox(a_x, a_y, l_x=mouse_xpos, l_y=mouse_ypos);
289                  }
290          } while (!(mouse_event & M_LUP));
291 <        revbox(a_x, a_y, l_x, l_y);             /* hide box */
291 >        revbox(a_x, a_y, l_x, l_y);             /* hide box */
292          show_cursor();
293          box.xmin = mouse_xpos;
294          box.ymin = mouse_ypos;
# Line 310 | Line 308 | watch_mouse()                   /* look after mousie *
308   }
309  
310  
311 < revbox(x0, y0, x1, y1)                  /* draw box with reversed lines */
311 > revbox(x0, y0, x1, y1)                  /* draw box with reversed lines */
312   int  x0, y0, x1, y1;
313   {
314          _setplotaction(_GXOR);
# Line 324 | Line 322 | int  x0, y0, x1, y1;
322  
323  
324   int
325 < avgbox(clr)                             /* average color over current box */
325 > avgbox(clr)                             /* average color over current box */
326   COLOR  clr;
327   {
328          static COLOR  lc;
329          static int  ll, lr, lt, lb;
330          int  left, right, top, bottom;
331          int  y;
332 <        double  d;
332 >        double  d;
333          COLOR  ctmp;
334          register int  x;
335  
# Line 372 | Line 370 | COLOR  clr;
370   }
371  
372  
373 < setpalette()                    /* set our palette using clrtab */
373 > setpalette()                    /* set our palette using clrtab */
374   {
375 <        long    cvals[256];
376 <        register int    i;
375 >        long    cvals[256];
376 >        register int    i;
377  
378          if (minpix >= 2) {
379                  cvals[ourblack] = _BLACK; cvals[ourwhite] = _BRIGHTWHITE;
# Line 388 | Line 386 | setpalette()                    /* set our palette usi
386   }
387  
388  
389 < greyimage()                     /* display greyscale image */
389 > greyimage()                     /* display greyscale image */
390   {
391 <        short   thiscolor, lastcolor = -1;
392 <        int     y;
393 <        register int    x;
391 >        short   thiscolor, lastcolor = -1;
392 >        int     y;
393 >        register int    x;
394                                          /* set gamma correction */
395          setcolrgam(gamcor);
396                                          /* set up color map */
# Line 408 | Line 406 | greyimage()                     /* display greyscale i
406                          shiftcolrs(scanline, xmax, scale);
407                  colrs_gambs(scanline, xmax);
408                  if (maxcolors < 256)
409 <                        for (x = 0; x < xmax; x++) {
409 >                        for (x = 0; x < xmax; x++) {
410                                  thiscolor = ((long)normbright(scanline[x]) *
411                                          maxcolors + 128) >> 8;
412                                  if (thiscolor != lastcolor)
# Line 426 | Line 424 | greyimage()                     /* display greyscale i
424   }
425  
426  
427 < mappedimage()                   /* display color-mapped image */
427 > mappedimage()                   /* display color-mapped image */
428   {
429 <        BYTE    bscan[MAXWIDTH];
430 <        int     y;
431 <        register int    x;
429 >        BYTE    bscan[MAXWIDTH];
430 >        int     y;
431 >        register int    x;
432                                          /* set gamma correction */
433          setcolrgam(gamcor);
434                                          /* make histogram */
435 +        _outtext("Quantizing image -- Please wait...");
436          new_histo();
437          for (y = 0; y < ymax; y++) {
438                  if (getscan(y) < 0)
# Line 499 | Line 498 | void _loadds far mouse_handler (int max, int mcx, int
498   #pragma aux mouse_handler parm [EAX] [ECX] [EDX]
499          mouse_event = max;
500          mouse_xpos = mcx;
501 <        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;
501 >        mouse_ypos = mdx;
502   }
503   #pragma on (check_stack)
504  
505  
506   void
507 < move_cursor(newx, newy)         /* move cursor to new position */
507 > move_cursor(newx, newy)         /* move cursor to new position */
508   int  newx, newy;
509   {
510          static char  *imp = NULL;
511          static int  curx = -1, cury = -1;
512 < #define xcmin           (curx-crad<0 ? 0 : curx-crad)
513 < #define ycmin           (cury-crad<0 ? 0 : cury-crad)
514 < #define xcmax           (curx+crad>=xmax ? xmax-1 : curx+crad)
515 < #define ycmax           (cury+crad>=ymax ? ymax-1 : cury+crad)
512 > #define xcmin           (curx-crad<0 ? 0 : curx-crad)
513 > #define ycmin           (cury-crad<0 ? 0 : cury-crad)
514 > #define xcmax           (curx+crad>=xmax ? xmax-1 : curx+crad)
515 > #define ycmax           (cury+crad>=ymax ? ymax-1 : cury+crad)
516  
517          if (newx == curx & newy == cury)
518                  return;
519 <        if (imp == NULL &&
519 >        if (imp == NULL &&
520                  (imp = bmalloc(_imagesize(0,0,2*crad+1,2*crad+1))) == NULL) {
521                  quiterr("out of memory in move_cursor");
522          }
523 <        if (curx >= 0 & cury >= 0)      /* clear old cursor */
523 >        if (curx >= 0 & cury >= 0)      /* clear old cursor */
524                  _putimage(xcmin, ycmin, imp, _GPSET);
525                                          /* record new position */
526          curx = newx; cury = newy;
527          if (curx < 0 | cury < 0)
528 <                return;         /* no cursor */
528 >                return;         /* no cursor */
529                                          /* save under new cursor */
530          _getimage(xcmin, ycmin, xcmax, ycmax, imp);
531                                          /* draw new cursor */
# Line 567 | Line 564 | ms_init()
564      }
565  
566      crad = ymax/40;
567 <    
567 >
568 >    /* set screen limits */
569 >
570 >    inregs.w.ax = 0x7;          /* horizontal resolution */
571 >    inregs.w.cx = 0;
572 >    inregs.w.dx = xmax-1;
573 >    int386x( 0x33, &inregs, &outregs, &sregs );
574 >    inregs.w.ax = 0x8;          /* vertical resolution */
575 >    inregs.w.cx = 0;
576 >    inregs.w.dx = ymax-1;
577 >    int386x( 0x33, &inregs, &outregs, &sregs );
578 >
579      /* install watcher */
580  
581      inregs.w.ax = 0xC;
582      inregs.w.cx = M_LDOWN | M_LUP | M_MOTION;
583      function_ptr = mouse_handler;
584      inregs.x.edx = FP_OFF( function_ptr );
585 <    sregs.es     = FP_SEG( function_ptr );
585 >    sregs.es     = FP_SEG( function_ptr );
586      int386x( 0x33, &inregs, &outregs, &sregs );
587 <    
587 >
588      return(1);
589   }
590 +
591 + ms_done()
592 + {
593 +    union REGS inregs, outregs;
594 +
595 +    /* uninstall watcher */
596 +
597 +    inregs.w.ax = 0;
598 +    int386 (0x33, &inregs, &outregs);
599 + }
600 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines