Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
Macros | Functions | Variables
getmex.c File Reference
#include <stdio.h>
#include <math.h>
#include "gl.h"
#include "device.h"
#include "rle.h"
Include dependency graph for getmex.c:

Go to the source code of this file.

Macros

#define MAX(i, j)    ( (i) > (j) ? (i) : (j) )
 
#define MIN(i, j)    ( (i) < (j) ? (i) : (j) )
 
#define levels   8 /* Compute 3 bits per channel. */
 
#define DMAP(v, x)   (modN[v]>row_ptr[x] ? divN[v] + 1 : divN[v])
 

Functions

 main (argc, char **argv)
 
 get_pic (FILE *infile, char *infname, char cmdname)
 
 update_pic ()
 
 map_scanline (rgb, n, y, Colorindex *line)
 
 init_dither ()
 
float getgamma ()
 
 makemap ()
 
FILE * configopen ()
 
float gammacorrect ()
 
float ungammacorrect ()
 
 gammapcolor (strchr, int strchr r, int strchr g, int strchr b)
 
static makegamtables ()
 
static fixup (unsigned char *cptr)
 
 gamgetmcolor (strchr, unsigned short *r, unsigned short *g, unsigned short *b)
 
float gammacorrect (float i, float gamma)
 
float ungammacorrect (float i, float gamma)
 
 newgamma ()
 
 newgamtables ()
 
 readgamtables ()
 
 setgamma (float gam)
 
 getcolorbal (unsigned int *r, unsigned int *g, unsigned int *b)
 
 setcolorbal (int r, int g, int b)
 
FILE * configopen (name, mode)
 

Variables

Colorindex color_start = 512
 
Colorindex bw_start = 128
 
long window_number
 
int x_size
 
int y_size
 
int dbg = 0
 
int forkflg = 0
 
int bwflag = 0
 
Colorindex * image
 
int modN [256]
 
int divN [256]
 
int dm16 [16][16]
 
static unsigned char rgamtable [256]
 
static unsigned char ggamtable [256]
 
static unsigned char bgamtable [256]
 
static unsigned char rungamtable [256]
 
static unsigned char gungamtable [256]
 
static unsigned char bungamtable [256]
 
static short firsted
 

Macro Definition Documentation

#define DMAP (   v,
  x 
)    (modN[v]>row_ptr[x] ? divN[v] + 1 : divN[v])
#define levels   8 /* Compute 3 bits per channel. */

Definition at line 31 of file getmex.c.

#define MAX (   i,
 
)    ( (i) > (j) ? (i) : (j) )

Definition at line 18 of file getmex.c.

#define MIN (   i,
 
)    ( (i) < (j) ? (i) : (j) )

Definition at line 19 of file getmex.c.

Function Documentation

FILE * configopen ( )

#include "math.h" #include "port.h" #include "gl.h" #include "stdio.h"

#include "stdio.h" #include "port.h" #include "gl.h"

FILE* configopen ( name  ,
mode   
)

Definition at line 636 of file getmex.c.

639 {
640  char homepath[100];
641  FILE *f;
642  char *cptr;
643 
644  cptr = (char *)getenv("HOME");
645  if (!cptr)
646  return 0;
647  strcpy(homepath,cptr);
648  strcat(homepath,"/");
649  strcat(homepath,name);
650  return fopen(homepath,mode);
651 }
static fixup ( unsigned char *  cptr)
static

Definition at line 469 of file getmex.c.

471 {
472  register short i, lowval;
473 
474  for (i=256; i--; ) {
475  if (*cptr == 0)
476  *cptr = lowval;
477  else
478  lowval = *cptr;
479  }
480 }
int i
Definition: rletorla.c:82
gamgetmcolor ( strchr  ,
unsigned short *  r,
unsigned short *  g,
unsigned short *  b 
)

Definition at line 482 of file getmex.c.

485 {
486  static short firsted;
487  unsigned short tr, tg, tb;
488 
489  if (!firsted) {
490  readgamtables();
491  firsted++;
492  }
493  getmcolor(index,&tr,&tg,&tb);
494  *r = rungamtable[tr&0xff];
495  *g = gungamtable[tg&0xff];
496  *b = bungamtable[tb&0xff];
497 }
static unsigned char g
Definition: getami.c:692
readgamtables()
Definition: getmex.c:534
static unsigned char r
Definition: getami.c:692
static unsigned char gungamtable[256]
Definition: getmex.c:423
static unsigned char b
Definition: getami.c:692
#define index
Definition: rle_config.h:96
static unsigned char bungamtable[256]
Definition: getmex.c:424
static short firsted
Definition: getmex.c:425
static unsigned char rungamtable[256]
Definition: getmex.c:422
float gammacorrect ( )
float gammacorrect ( float  i,
float  gamma 
)

Definition at line 499 of file getmex.c.

501 {
502  return pow(i,1.0/gamma);
503 }
int gamma(int x, float gamma_value)
Definition: gamma.c:24
int i
Definition: rletorla.c:82
gammapcolor ( strchr  ,
int strchr  r,
int strchr  g,
int strchr  b 
)

Definition at line 427 of file getmex.c.

429 {
430  short i;
431 
432  if (!firsted) {
433  readgamtables();
434  firsted++;
435  }
436  r = rgamtable[r&0xff];
437  g = ggamtable[g&0xff];
438  b = bgamtable[b&0xff];
439  mapcolor(index,r,g,b);
440 }
static unsigned char g
Definition: getami.c:692
readgamtables()
Definition: getmex.c:534
static unsigned char r
Definition: getami.c:692
static unsigned char ggamtable[256]
Definition: getmex.c:420
static unsigned char b
Definition: getami.c:692
#define index
Definition: rle_config.h:96
int i
Definition: rletorla.c:82
static short firsted
Definition: getmex.c:425
static unsigned char rgamtable[256]
Definition: getmex.c:419
static unsigned char bgamtable[256]
Definition: getmex.c:421
get_pic ( FILE *  infile,
char *  infname,
char  cmdname 
)

Definition at line 88 of file getmex.c.

91 {
92  register int i, y;
93  int ncolors;
94  unsigned char *scan[3];
95  rle_hdr hdr;
96 
97  /*
98  * Read setup info from file.
99  */
100  hdr = *rle_hdr_init( (rle_hdr *)NULL );
101  rle_names( &hdr, cmdname, infname, 0 );
102  hdr.rle_file = infile;
103  rle_get_setup_ok( &hdr, NULL, NULL );
104 
105  if ( dbg )
106  rle_debug( 1 );
107 
108  /* We`re only interested in R, G, & B */
109  RLE_CLR_BIT(hdr, RLE_ALPHA);
110  for (i = 3; i < hdr.ncolors; i++)
111  RLE_CLR_BIT(hdr, i);
112  ncolors = hdr.ncolors > 3 ? 3 : hdr.ncolors;
113  if ( ncolors == 1 ) bwflag = TRUE;
114 
115  /*
116  * Compute image size and allocate storage for colormapped image.
117  */
118  x_size = (hdr.xmax - hdr.xmin + 1);
119  y_size = (hdr.ymax - hdr.ymin + 1);
120  image = (Colorindex *) malloc(x_size * y_size * sizeof( Colorindex ));
121 
122  /*
123  * Set up for rle_getrow. Pretend image x origin is 0.
124  */
125  for (i = 0; i < 3; i++)
126  scan[i] = (unsigned char *) malloc(x_size);
127  hdr.xmax -= hdr.xmin;
128  hdr.xmin = 0;
129 
130  /* For each scan line, dither it into the image memory. */
131  while ((y = rle_getrow(&hdr, scan)) <= hdr.ymax)
132  {
133  if ( bwflag && ncolors > 1 )
134  {
135  rgb_to_bw( scan[0], scan[1], scan[ncolors - 1], scan[0], x_size );
136  /* Note: map_scanline only uses channel 0 for B&W */
137  }
138 
139  map_scanline( scan, x_size, y,
140  &image[(y - hdr.ymin) * x_size] );
141  }
142 
143  /*
144  * Free temp storage
145  */
146  for (i = 0; i < 3; i++)
147  free(scan[i]);
148 
149  /*
150  * Get a window of the right size (user positions it with the mouse).
151  */
152  if ( forkflg ) foreground(); /* Don`t fork. */
153  maxsize( x_size, y_size );
154  window_number = winopen( "getmex" );
155  if ( infname ) wintitle( infname );
156 
157  makemap(); /* Initialize the Iris color map. */
158 
159  qdevice( REDRAW );
160  qdevice( LEFTMOUSE ); /* Pan the image under mouse control. */
161  qdevice( SETUPKEY ); /* Reset panning. */
162  unqdevice( INPUTCHANGE ); /* We don`t pay attention to these. */
163 
164  /* There was a redraw event sent when the window was created,
165  * but we weren`t listening for them yet.
166  */
167  qenter( REDRAW, window_number );
168 }
int dbg
Definition: getmex.c:26
int xmin
Definition: rle.h:100
map_scanline(rgb, n, y, Colorindex *line)
Definition: getmex.c:300
int bwflag
Definition: getmex.c:28
rle_hdr hdr
Definition: iristorle.c:35
int ymin
Definition: rle.h:100
void rgb_to_bw(rle_pixel *red_row, rle_pixel *green_row, rle_pixel *blue_row, rle_pixel *bw_row, int rowlen)
Definition: rle_putrow.c:680
static int y
Definition: getami.c:691
unsigned char ** scan
Definition: rle.c:26
int y_size
Definition: getmex.c:25
string infname
Definition: getbob.c:68
void rle_names(rle_hdr *the_hdr, const char *pgmname, const char *fname, int img_num)
Definition: rle.h:96
int xmax
Definition: rle.h:100
#define TRUE
Definition: giftorle.c:38
#define RLE_CLR_BIT(glob, bit)
Definition: rle.h:124
long window_number
Definition: getmex.c:24
FILE * infile
Definition: targatorle.c:102
int ymax
Definition: rle.h:100
void rle_debug(int on_off)
Definition: rle_getrow.c:293
Colorindex * image
Definition: getmex.c:29
int x_size
Definition: getmex.c:25
void * malloc()
int i
Definition: rletorla.c:82
#define RLE_ALPHA
Definition: rle.h:65
makemap()
Definition: getmex.c:372
void rle_get_setup_ok(rle_hdr *the_hdr, const char *prog_name, const char *file_name)
int rle_getrow(rle_hdr *the_hdr, rle_pixel *scanline[])
int forkflg
Definition: getmex.c:27
FILE * rle_file
Definition: rle.h:114
int ncolors
Definition: rle.h:100
rle_hdr * rle_hdr_init(rle_hdr *the_hdr)
Definition: rle_hdr.c:267
getcolorbal ( unsigned int r,
unsigned int g,
unsigned int b 
)

Definition at line 598 of file getmex.c.

600 {
601  FILE *cbfile;
602 
603  if ((cbfile = configopen(".cbal","r")) ) {
604  if (fscanf(cbfile,"%d %d %d\n",r,g,b) == 3) {
605  if (*r>255)
606  *r = 255;
607  if (*g>255)
608  *g = 255;
609  if (*b>255)
610  *b = 255;
611  fclose(cbfile);
612  return;
613  } else
614  fclose(cbfile);
615  }
616  *r = 255;
617  *g = 255;
618  *b = 255;
619  return;
620 }
static unsigned char g
Definition: getami.c:692
static unsigned char r
Definition: getami.c:692
static unsigned char b
Definition: getami.c:692
FILE * configopen()
float getgamma ( )

NOTE: This is the makemap program from /usr/people/gifts/mextools/tools, with the gamma and getset routines from /usr/people/gifts/mextools/portlib appended. The only modification is that it only does the part of the map required here, and expands the RGB map to 512 colors.#include "gl.h" #include "gl2/port.h"

savecolors and restorecolors

Definition at line 569 of file getmex.c.

570 {
571  FILE *gamfile;
572  float gam;
573 
574  if ((gamfile = configopen(".gamma","r")) ) {
575  if (fscanf(gamfile,"%f\n",&gam) == 1) {
576  fclose(gamfile);
577  return gam;
578  } else
579  fclose(gamfile);
580  }
581  return 2.2;
582 }
float gam
Definition: get_orion.c:55
FILE * configopen()
init_dither ( )

Definition at line 346 of file getmex.c.

References divN, dm16, make_square(), and modN.

347 {
348  int i, j, k, l, planes, pixels[216];
349  unsigned int value;
350  float N;
351 
352  make_square( 255.0 / (levels - 1), divN, modN, dm16 );
353 }
void make_square(double N, int divN[256], int modN[256], int magic[16][16])
#define N(node)
Definition: mcut.c:45
#define levels
Definition: getmex.c:31
int divN[256]
Definition: getmex.c:32
int i
Definition: rletorla.c:82
int modN[256]
Definition: getmex.c:32
const char * value
Definition: rleClock.c:574
int dm16[16][16]
Definition: getmex.c:34

Here is the call graph for this function:

main ( argc  ,
char **  argv 
)

Definition at line 59 of file getmex.c.

61 {
62  int mapstart, mapflag = 0;
63  char *infname = NULL;
64  FILE * infile = stdin;
65 
66  /* Handle arguments. */
67  if ( scanargs( argc, argv, "% f%- w%- D%- m%-mapstart!d file%s\n(\
68 \tDisplay a URT image dithered in the window system.\n\
69 \t-f\tKeep program in foreground\n\
70 \t-w\tDisplay in black and white instead of color.\n\
71 \t-m\tStarting point in colormap (uses 512 entries for color).\n\
72 \tLeft mouse pans image, setup key recenters.)",
73  &forkflg, &bwflag, &dbg, &mapflag, &mapstart, &infname ) == 0 )
74  exit( 1 );
75  if ( mapflag )
76  if ( bwflag ) bw_start = mapstart; else color_start = mapstart;
77  infile = rle_open_f(cmd_name(argv), infname, "r");
78 
79  init_dither(); /* Set up the dither matrices. */
80  /* Read image and make a window for it. */
81  get_pic( infile, infname, cmd_name(argv) );
82  update_pic(); /* Keep drawing the window. */
83 }
int dbg
Definition: getmex.c:26
Colorindex color_start
Definition: getmex.c:22
int scanargs(int argc, char **argv, const char *format,...)
Definition: scanargs.c:94
update_pic()
Definition: getmex.c:173
int bwflag
Definition: getmex.c:28
Colorindex bw_start
Definition: getmex.c:23
get_pic(FILE *infile, char *infname, char cmdname)
Definition: getmex.c:88
string infname
Definition: getbob.c:68
FILE * infile
Definition: targatorle.c:102
FILE * rle_open_f(const char *prog_name, const char *f_name, const char *mode)
init_dither()
Definition: getmex.c:346
char * cmd_name(char **argv)
Definition: cmd_name.c:31
int forkflg
Definition: getmex.c:27
static makegamtables ( )
static

Definition at line 442 of file getmex.c.

References bgamtable, bungamtable, ggamtable, gungamtable, rgamtable, and rungamtable.

443 {
444  register float gamval;
445  register float val;
446  register short i;
447  int rbal, gbal, bbal;
448 
449  gamval = getgamma();
450  getcolorbal(&rbal,&gbal,&bbal);
451  for (i=0; i<256; i++) {
452  rgamtable[i] = 255*gammacorrect((rbal*i)/(255.0*255.0),gamval);
453  ggamtable[i] = 255*gammacorrect((gbal*i)/(255.0*255.0),gamval);
454  bgamtable[i] = 255*gammacorrect((bbal*i)/(255.0*255.0),gamval);
455  }
456  bzero(rungamtable,256);
457  bzero(gungamtable,256);
458  bzero(bungamtable,256);
459  for (i=0; i<256; i++) {
460  rungamtable[rgamtable[i]] = i;
461  gungamtable[ggamtable[i]] = i;
462  bungamtable[bgamtable[i]] = i;
463  }
467 }
static unsigned char gungamtable[256]
Definition: getmex.c:423
float getgamma()
Definition: getmex.c:569
static unsigned char ggamtable[256]
Definition: getmex.c:420
static unsigned char bungamtable[256]
Definition: getmex.c:424
float gammacorrect()
getcolorbal(unsigned int *r, unsigned int *g, unsigned int *b)
Definition: getmex.c:598
int i
Definition: rletorla.c:82
static fixup(unsigned char *cptr)
Definition: getmex.c:469
static unsigned char rgamtable[256]
Definition: getmex.c:419
static unsigned char bgamtable[256]
Definition: getmex.c:421
static unsigned char rungamtable[256]
Definition: getmex.c:422
makemap ( )

Position as specified, and only do it if showing a b&w image.

<

128>

<

but if more than 9 planes, make the map at 512, 512 colors long.

<

=>

512>

<

Definition at line 372 of file getmex.c.

References bwflag.

373 {
374  register int i, j, v;
375  register int r, g, b, w;
376  int planes;
377 
378  planes = getplanes();
379 
380 /* if there are more than 8 planes make a ramp at 128 */
382  if (planes > 8 && bwflag )
383  for (i=0; i<128; i++) {
384  gammapcolor(i+ bw_start ,i<<1,i<<1,i<<1);
385  }
386 
387 /* if there are more than 8 planes make an ordered color map at 256 */
389  if (planes > 9 && ! bwflag )
390  for (i=0; i<512; i++) {
391  r = (i>>0) & 7;
392  g = (i>>3) & 7;
393  b = (i>>6) & 7;
394  r = (255*r)/7;
395  g = (255*g)/7;
396  b = (255*b)/7;
397  gammapcolor(i+ color_start ,r,g,b);
398  }
399 }
static unsigned char g
Definition: getami.c:692
Colorindex color_start
Definition: getmex.c:22
static unsigned char r
Definition: getami.c:692
gammapcolor(strchr, int strchr r, int strchr g, int strchr b)
Definition: getmex.c:427
int bwflag
Definition: getmex.c:28
Colorindex bw_start
Definition: getmex.c:23
static unsigned char b
Definition: getami.c:692
int i
Definition: rletorla.c:82
map_scanline ( rgb  ,
,
y  ,
Colorindex *  line 
)

Definition at line 300 of file getmex.c.

303 {
304  register int i, col;
305  int row, *row_ptr;
306 
307 # define DMAP(v,x) (modN[v]>row_ptr[x] ? divN[v] + 1 : divN[v])
308 
309  row = y % 16;
310  row_ptr = dm16[ row ]; /* Cache ptr to row of dither array. */
311 
312  if ( !bwflag ) /* Color display. */
313  {
314  register unsigned char *r, *g, *b;
315  for ( col = 0, i = 0, r = rgb[0], g = rgb[1], b = rgb[2];
316  i < n; i++, r++, g++, b++, col = ((col + 1) & 15) )
317  {
318  /* Combine 3 3-bit colors into a 3/3/3 color map index. */
319  line[i] = color_start + DMAP(*r, col) + (DMAP(*g, col)<<3) +
320  (DMAP(*b, col)<<6);
321  }
322  }
323  else /* Gray scale display. */
324  {
325  register unsigned char *bw;
326 
327  for ( i = 0, bw = rgb[0]; i < n; i++, bw++ )
328  line[i] = bw_start + (*bw>>1);
329  }
330 }
static unsigned char g
Definition: getami.c:692
Colorindex color_start
Definition: getmex.c:22
static int bw
Definition: getami.c:106
rle_pixel rgb[3]
Definition: wasatchrle.c:47
static unsigned char r
Definition: getami.c:692
int bwflag
Definition: getmex.c:28
Colorindex bw_start
Definition: getmex.c:23
static int y
Definition: getami.c:691
static unsigned char b
Definition: getami.c:692
int i
Definition: rletorla.c:82
#define DMAP(v, x)
int row
Definition: rle.c:27
int dm16[16][16]
Definition: getmex.c:34
newgamma ( )

Definition at line 511 of file getmex.c.

References firsted.

512 {
513  firsted = firsted = 0;
514 }
static short firsted
Definition: getmex.c:425
newgamtables ( )

Definition at line 516 of file getmex.c.

References bgamtable, bungamtable, ggamtable, gungamtable, rgamtable, and rungamtable.

517 {
518  FILE *outf;
519 
520  if ((outf = configopen(".gamtables","w")) == 0) {
521  fprintf(stderr,"couldn't open .gamtables\n");
522  return;
523  }
524  makegamtables();
525  fwrite(rgamtable,256,1,outf);
526  fwrite(ggamtable,256,1,outf);
527  fwrite(bgamtable,256,1,outf);
528  fwrite(rungamtable,256,1,outf);
529  fwrite(gungamtable,256,1,outf);
530  fwrite(bungamtable,256,1,outf);
531  fclose(outf);
532 }
static makegamtables()
Definition: getmex.c:442
static unsigned char gungamtable[256]
Definition: getmex.c:423
static unsigned char ggamtable[256]
Definition: getmex.c:420
static unsigned char bungamtable[256]
Definition: getmex.c:424
FILE * configopen()
static unsigned char rgamtable[256]
Definition: getmex.c:419
static unsigned char bgamtable[256]
Definition: getmex.c:421
static unsigned char rungamtable[256]
Definition: getmex.c:422
readgamtables ( )

Definition at line 534 of file getmex.c.

References bgamtable, bungamtable, ggamtable, gungamtable, rgamtable, and rungamtable.

535 {
536  FILE *inf;
537 
538  if ((inf = configopen(".gamtables","r")) == 0) {
539  newgamtables();
540  if ((inf = configopen(".gamtables","r")) == 0) {
541  fprintf(stderr,"couldn't open .gamtables\n");
542  return;
543  }
544  }
545  fread(rgamtable,256,1,inf);
546  fread(ggamtable,256,1,inf);
547  fread(bgamtable,256,1,inf);
548  fread(rungamtable,256,1,inf);
549  fread(gungamtable,256,1,inf);
550  fread(bungamtable,256,1,inf);
551  fclose(inf);
552 }
newgamtables()
Definition: getmex.c:516
static unsigned char gungamtable[256]
Definition: getmex.c:423
static unsigned char ggamtable[256]
Definition: getmex.c:420
static unsigned char bungamtable[256]
Definition: getmex.c:424
FILE * configopen()
static unsigned char rgamtable[256]
Definition: getmex.c:419
static unsigned char bgamtable[256]
Definition: getmex.c:421
static unsigned char rungamtable[256]
Definition: getmex.c:422
setcolorbal ( int  r,
int  g,
int  b 
)

Definition at line 622 of file getmex.c.

624 {
625  FILE *cbfile;
626 
627  if ((cbfile = configopen(".cbal","w")) == 0) {
628  fprintf(stderr,"couldn't open .cbal\n");
629  return;
630  }
631  fprintf(cbfile,"%d %d %d\n",r,g,b);
632  fclose(cbfile);
633  newgamtables();
634 }
static unsigned char g
Definition: getami.c:692
newgamtables()
Definition: getmex.c:516
static unsigned char r
Definition: getami.c:692
static unsigned char b
Definition: getami.c:692
FILE * configopen()
setgamma ( float  gam)

Definition at line 584 of file getmex.c.

586 {
587  FILE *gamfile;
588 
589  if ((gamfile = configopen(".gamma","w")) == 0) {
590  fprintf(stderr,"couldn't open .gamma\n");
591  return;
592  }
593  fprintf(gamfile,"%f\n",gam);
594  fclose(gamfile);
595  newgamtables();
596 }
newgamtables()
Definition: getmex.c:516
float gam
Definition: get_orion.c:55
FILE * configopen()
float ungammacorrect ( )
float ungammacorrect ( float  i,
float  gamma 
)

Definition at line 505 of file getmex.c.

507 {
508  return pow(i,gamma);
509 }
int gamma(int x, float gamma_value)
Definition: gamma.c:24
int i
Definition: rletorla.c:82
update_pic ( )

Definition at line 173 of file getmex.c.

References x_size, and y_size.

174 {
175  short data;
176  long event;
177  int window_x_size, window_y_size, window_x_origin, window_y_origin;
178  int x_min, x_max, y_min, y_max, x_start, y_start, x_end, y_end, x_len;
179  int x_origin, y_origin, new_x_center, new_y_center;
180  int x_center, y_center, saved_x_center, saved_y_center;
181 
182  register int y;
183  register Colorindex *y_ptr;
184 
185  /* Looking at the center, at first. */
186  x_center = saved_x_center = x_size / 2;
187  y_center = saved_y_center = y_size / 2;
188 
189  /* Redraw the window when necessary. */
190  while ( TRUE )
191  {
192  event = qread( &data );
193 # ifdef DEBUG
194  printf( "event %d, data %d\n", event, data );
195 #endif
196  switch ( event )
197  {
198  case REDRAW:
199  winset( window_number );
200  reshapeviewport();
201  color( 22 );
202  clear();
203 
204  /* Lower left corner of screen, in image coordinates.
205  * (Keep the center of the image in the center of the window.)
206  */
207  getsize( &window_x_size, &window_y_size );
208  x_min = x_center - window_x_size/2;
209  x_max = x_min + (window_x_size-1);
210  y_min = y_center - window_y_size/2;
211  y_max = y_min + (window_y_size-1);
212 
213  /* Coordinate bounds have half a pixel added all around. */
214  ortho2( x_min - .5, x_max + .5, y_min - .5, y_max + .5 );
215 
216  /* Draw just the part of the image in the window. */
217  x_start = MAX( x_min, 0 );
218  y_start = MAX( y_min, 0 );
219  x_end = MIN( x_max, x_size-1 );
220  y_end = MIN( y_max, y_size-1 );
221  x_len = x_end - x_start + 1;
222 
223  /* Dump the scanlines. Check once in a while for another
224  * redraw event queued up, and quit early if one is seen.
225  */
226  for ( y = y_start, y_ptr = image + y_start*x_size + x_start;
227  y <= y_end && (y%16 != 0 || qtest() != REDRAW);
228  y++, y_ptr += x_size )
229  {
230  cmov2i( x_start, y );
231  writepixels( x_len, y_ptr );
232  }
233  break;
234 
235  /* Setup key - Reset viewing to look at the center of the image.
236  * Shift-Setup - Restores a saved view center.
237  * Control-Setup - Saves the current view center for Shift-Setup.
238  */
239  case SETUPKEY:
240  if ( data == 1 ) /* Ignore button up events. */
241  {
242  if ( getbutton(RIGHTSHIFTKEY) || getbutton(LEFTSHIFTKEY) )
243  {
244  x_center = saved_x_center; /* Restore. */
245  y_center = saved_y_center;
246  qenter( REDRAW, window_number );
247  }
248  else if ( getbutton(CTRLKEY) )
249  {
250  saved_x_center = x_center; /* Save. */
251  saved_y_center = y_center;
252  }
253  else
254  {
255  x_center = x_size / 2; /* Reset. */
256  y_center = y_size / 2;
257  qenter( REDRAW, window_number );
258  }
259 
260  }
261  break;
262 
263  /* Pan a point picked with the left mouse button to the center
264  * of attention. Beep if cursor is not on the image.
265  */
266  case LEFTMOUSE:
267  if ( data == 1 ) /* Ignore button up events. */
268  {
269  getorigin( &x_origin, &y_origin );
270  new_x_center = getvaluator( MOUSEX ) - x_origin + x_min;
271  new_y_center = getvaluator( MOUSEY ) - y_origin + y_min;
272  if ( new_x_center >= x_start &&
273  new_x_center <= x_end &&
274  new_y_center >= y_start &&
275  new_y_center <= y_end )
276  {
277  x_center = new_x_center;
278  y_center = new_y_center;
279  qenter( REDRAW, window_number );
280  }
281  else
282  ringbell();
283  }
284  break;
285  }
286  }
287 }
#define MIN(i, j)
Definition: getmex.c:19
static int y
Definition: getami.c:691
int y_size
Definition: getmex.c:25
gpr_ $event_t event
Definition: getap.c:105
#define TRUE
Definition: giftorle.c:38
long window_number
Definition: getmex.c:24
#define MAX(i, j)
Definition: getmex.c:18
Colorindex * image
Definition: getmex.c:29
int x_size
Definition: getmex.c:25

Variable Documentation

unsigned char bgamtable[256]
static

Definition at line 421 of file getmex.c.

Referenced by makegamtables(), newgamtables(), and readgamtables().

unsigned char bungamtable[256]
static

Definition at line 424 of file getmex.c.

Referenced by makegamtables(), newgamtables(), and readgamtables().

Colorindex bw_start = 128

Definition at line 23 of file getmex.c.

int bwflag = 0

Definition at line 28 of file getmex.c.

Colorindex color_start = 512

Definition at line 22 of file getmex.c.

int dbg = 0

Definition at line 26 of file getmex.c.

int divN[256]

Definition at line 32 of file getmex.c.

int dm16[16][16]

Definition at line 34 of file getmex.c.

short firsted
static

Definition at line 425 of file getmex.c.

Referenced by newgamma().

int forkflg = 0

Definition at line 27 of file getmex.c.

unsigned char ggamtable[256]
static

Definition at line 420 of file getmex.c.

Referenced by makegamtables(), newgamtables(), and readgamtables().

unsigned char gungamtable[256]
static

Definition at line 423 of file getmex.c.

Referenced by makegamtables(), newgamtables(), and readgamtables().

Colorindex* image

Definition at line 29 of file getmex.c.

int modN[256]

Definition at line 32 of file getmex.c.

unsigned char rgamtable[256]
static

Definition at line 419 of file getmex.c.

Referenced by makegamtables(), newgamtables(), and readgamtables().

unsigned char rungamtable[256]
static

Definition at line 422 of file getmex.c.

Referenced by makegamtables(), newgamtables(), and readgamtables().

long window_number

Definition at line 24 of file getmex.c.

int x_size

Definition at line 25 of file getmex.c.

Referenced by convertgreylevels(), and update_pic().

int y_size

Definition at line 25 of file getmex.c.

Referenced by convertgreylevels(), and update_pic().