home *** CD-ROM | disk | FTP | other *** search
/ Encyclopedia of Graphics File Formats Companion / GFF_CD.ISO / software / unix / saoimage / sao1_07.tar / panimage.c < prev    next >
C/C++ Source or Header  |  1990-04-20  |  5KB  |  167 lines

  1. #ifndef lint
  2. static char SccsId[] = "%W%  %G%";
  3. #endif
  4.  
  5. /* Module:    panimage.c (Pan Image)
  6.  * Purpose:    Make and put the pan window display
  7.  * Subroutine:    disp_panbox()            returns: void
  8.  * Subroutine:    map_panbox()            returns: void
  9.  * Subroutine:    show_dispcoords()        returns: void
  10.  * Xlib calls:    XSync()
  11.  * Copyright:    1989 Smithsonian Astrophysical Observatory
  12.  *        You may do anything you like with this file except remove
  13.  *        this copyright.  The Smithsonian Astrophysical Observatory
  14.  *        makes no representations about the suitability of this
  15.  *        software for any purpose.  It is provided "as is" without
  16.  *        express or implied warranty.
  17.  * Modified:    {0} Michael VanHilst    initial version         29 May 1989
  18.  *        {n} <who> -- <does what> -- <when>
  19.  */
  20.  
  21. #include <stdio.h>        /* define stderr, NULL, etc. */
  22. #include <X11/Xlib.h>        /* X window stuff */
  23. #include <X11/Xutil.h>        /* X window manager stuff */
  24. #include "hfiles/define.h"    /* define MIN, MAX, DONT_CARE, etc. */
  25. #include "hfiles/struct.h"    /* declare structure types */
  26. #include "hfiles/extern.h"    /* extern main parameter structures */
  27. #include "hfiles/scale.h"    /* define scaling constants */
  28.  
  29. /*
  30.  * Subroutine:    disp_panbox
  31.  * Purpose:    Redraw the panbox window display
  32.  * Xlib calls:    XSync()
  33.  */
  34. void disp_panbox ( )
  35. {
  36.   void disp_window(), draw_pancursor();
  37.  
  38.   /* put up the image and make sure it is up before drawing the cursor */
  39.   disp_window(&panbox);
  40.   XSync(panbox.display, 0);
  41.   draw_pancursor();
  42. }
  43.  
  44. /*
  45.  * Subroutine:    map_panbox
  46.  * Purpose:    Fill the panbox display buffer, mapping from its short buffer
  47.  */
  48. void map_panbox ( )
  49. {
  50.   static void map_panbuf();
  51. #ifdef SUMBLOCK
  52.   static void map_adj_panbuf();
  53. #endif
  54.   void panimage_halftone();
  55.  
  56.   if( color.ncolors <= 1 ) {
  57.     panbox.image.format = XYBitmap;
  58.     panbox.image.depth = 1;
  59.     panbox.image.bits_per_pixel = 1;
  60.     panbox.image.bytes_per_line = (panbox.image.width + 7) / 8;
  61.     panimage_halftone();
  62.   } else {
  63.     panbox.image.format = ZPixmap;
  64.     panbox.image.depth = color.screen_depth;
  65.     panbox.image.bits_per_pixel = 8;
  66.     panbox.image.bytes_per_line = panbox.image.width;
  67. #ifdef SUMBLOCK
  68.     /* CHANGE SCALE WHEN SUMMED ZOOMING GAVE A DIFFERENT VALUE RANGE */
  69.     if( buffer.panbuf_summing != buffer.scalemap_summing ) {
  70.       int ratio_num, ratio_denom;
  71.  
  72.       /* select largest denominator which won't overflow */
  73.       /* WARNING: make sure panbuf_max > 0!!! */
  74.       ratio_denom = 32767 / buffer.scale_max;
  75.       ratio_num = (ratio_denom * buffer.scale_max) / buffer.panbuf_max;
  76.       map_adj_panbuf(ratio_num, ratio_denom);
  77.     } else
  78. #endif
  79.       map_panbuf();
  80.   }
  81. }
  82.  
  83. /*
  84.  * Subroutine:    show_dispcoords
  85.  * Purpose:    Print the file coordinates of the display's center and zoom
  86.  */
  87. void show_dispcoords ( )
  88. {
  89.   float cenX, cenY;
  90.   float zoom;
  91.   void d_transform();
  92.  
  93.   /* calculate file coords of center of display */
  94.   d_transform(&coord.imgtofile,
  95.           (double)coord.id.cenX, (double)coord.id.cenY, &cenX, &cenY);
  96.   if( coord.filetoimg.inx_outx != 0.0 )
  97.     zoom = coord.filetoimg.inx_outx * coord.imgtodisp.inx_outx;
  98.   else
  99.     zoom = coord.filetoimg.iny_outx * coord.imgtodisp.inx_outx;
  100.   /* take abs */
  101.   if( zoom < 0.0 ) zoom = -zoom;
  102.   (void)printf("Display from image file:\n");
  103.   if( zoom < 1.0 )
  104.     (void)printf("Center: X=%.2f, Y=%.2f, Blocking: %.4f (%d)\n",
  105.          (double)cenX, (double)cenY, zoom, (int)(-1.0/zoom));
  106.   else
  107.     (void)printf("Center: X=%.2f, Y=%.2f, Blocking: %.1f\n",
  108.          (double)cenX, (double)cenY, zoom);
  109. }
  110.  
  111. /*
  112.  * Subroutine:    map_panbuf
  113.  * Purpose:    Map short image data to display buffer
  114.  * Exception:    Buffers both buffers have same size
  115.  */
  116. static void map_panbuf ( )
  117. {
  118.   register unsigned char *display;    /* l: pointer to display buffer */
  119.   register unsigned char *dispend;    /* l: end of display buffer ptr */
  120.   register short *image;        /* l: pointer to short integer data */
  121.   register unsigned char *lookup;    /* l: pointer to lookup table */
  122.  
  123.   image = buffer.panbuf;
  124.   lookup = buffer.scalemap + SCALEOFF;
  125.   display = (unsigned char *)panbox.image.data;
  126.   dispend = display + (panbox.xwidth * panbox.yheight);
  127.   /* loop through both buffers */
  128.   while( display < dispend ) {
  129.     *display++ = lookup[*image++];
  130.   }
  131. }
  132.  
  133. #ifdef SUMBLOCK
  134. /*
  135.  * Subroutine:    map_adj_panbuf
  136.  * Purpose:    Map short integer data to byte display buffer, adjusting
  137.  *        for value changes due to summed blocking applied to short buf.
  138.  * Exception:    Buffers have same size
  139.  * Note:    Blocking factor may differ from that used for scale map.
  140.  */
  141. static void map_adj_panbuf ( numerator, denominator )
  142.      register int numerator;        /* i: scale adjustment numberator */
  143.      register int denominator;        /* i: scale adjustment denominator */
  144. {
  145.   register unsigned char *display;    /* l: pointer to display buffer */
  146.   register unsigned char *dispend;    /* l: end of display buffer ptr */
  147.   register short *image;        /* l: pointer to short integer data */
  148.   register unsigned char *lookup;    /* l: pointer to lookup table */
  149.   register int imval, round;
  150.  
  151.   image = buffer.panbuf;
  152.   lookup = buffer.scalemap + SCALEOFF;
  153.   display = panbox.byteimage;
  154.   dispend = display + (panbox.xwidth * panbox.yheight);
  155.   round = (denominator + 1) / 2;
  156.   while( display < dispend ) {
  157.     if( (imval = *image++) != 0 ) {
  158.       if (imval > 0)
  159.     imval = ((imval * numerator) + round) / denominator;
  160.       else
  161.     imval = ((imval * numerator) - round) / denominator;
  162.     }
  163.     *display++ = lookup[imval];
  164.   }
  165. }
  166. #endif
  167.