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

  1. #ifndef lint
  2. static char SccsId[] = "%W%  %G%";
  3. #endif
  4.  
  5. /* Module:    display.c (Display)
  6.  * Purpose:    Draw images in their windows, including the main display
  7.  * Subroutine:    disp_window()            returns: void
  8.  * Subroutine:    disp_dispbox()            returns: void
  9.  * Subroutine:    map_dispbox()            returns: void
  10.  * Subroutine:    clear_margins()            returns: void
  11.  * Xlib calls:    XPutImage(), XSync();
  12.  * Copyright:    1989 Smithsonian Astrophysical Observatory
  13.  *        You may do anything you like with this file except remove
  14.  *        this copyright.  The Smithsonian Astrophysical Observatory
  15.  *        makes no representations about the suitability of this
  16.  *        software for any purpose.  It is provided "as is" without
  17.  *        express or implied warranty.
  18.  * Modified:    {0} Michael VanHilst    initial version          26 May 1989
  19.  *        {n} <who> -- <does what> -- <when>
  20.  */
  21.  
  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_window
  31.  * Purpose:    Redraw the window's display image with no frills
  32.  * Xlib call:    XPutImage()
  33.  */
  34. void disp_window ( window )
  35.      struct windowRec *window;
  36. {
  37.   GC gc, set_gc(), set_gc_with_background();
  38.  
  39.   if( window->image.depth == 1 )
  40.     gc = set_gc_with_background(&(color.gcset.disp),
  41.                 color.gcset.disp.background);
  42.   else
  43.     gc = set_gc(&(color.gcset.disp));
  44.  
  45.   XPutImage(window->display, window->ID, gc, &window->image, 0, 0,
  46.         window->xzero, window->yzero,
  47.         (unsigned int)window->xwidth, (unsigned int)window->yheight);
  48. }
  49.  
  50. /*
  51.  * Subroutine:    disp_dispbox
  52.  * Purpose:    Redraw the dispbox window display including cursor graphics
  53.  */
  54. void disp_dispbox ( )
  55. {
  56.   void disp_window(), disp_regions(), disp_cursor();
  57.  
  58.   /* put up the image */
  59.   disp_window(&dispbox);
  60.   /* make sure image is up before proceeding */
  61.   XSync(dispbox.display, 0);
  62.   /* redraw the region outlines (if visible is indicated) */
  63.   disp_regions(&cursor);
  64.   /* redraw the cursor (if visible is indicated) */
  65.   disp_cursor(&cursor);
  66. }
  67.  
  68. /*
  69.  * Subroutine:    map_dispbox
  70.  * Purpose:    Redraw the main display buffer from the short image buffer
  71.  */
  72. void map_dispbox ( )
  73. {
  74.   void unset_blink(), clear_margins(), map_buf_repzoom(), map_buf_subzoom();
  75.   void map_buf_repzoom_adj(), make_halftone_display(), map_buf_subzoom_adj();
  76.  
  77.   /* restore original buffer if we were blinking */
  78.   unset_blink();
  79.   if( color.ncolors <= 1 ) {
  80.     /* contstruct XYBitmap image */
  81.     dispbox.image.format = XYBitmap;
  82.     dispbox.image.depth = 1;
  83.     dispbox.image.bits_per_pixel = 1;
  84.     dispbox.image.bytes_per_line = (dispbox.image.width + 7) / 8;
  85.     make_halftone_display();
  86.   } else {
  87.     /* construct ZPixmap image */
  88.     dispbox.image.format = ZPixmap;
  89.     dispbox.image.depth = color.screen_depth;
  90.     dispbox.image.bits_per_pixel = 8;
  91.     dispbox.image.bytes_per_line = dispbox.image.width;
  92.     if( coord.bd.clip ) {
  93.       /* if image does not fill display buffer, do something about it */
  94.       clear_margins((unsigned char *)dispbox.image.data, &coord.bd,
  95.             &coord.disp, 1, color.hard.std_white);
  96.     }
  97.     /* draw the image with the appropriate zoom */
  98. #ifdef SUMBLOCK
  99.     if( buffer.scalemap_summing != buffer.shortbuf_summing ) {
  100.       /* compensate for loading shortbuf with differently summed values */
  101.       if( coord.bd.block < -1 )
  102.     map_buf_repzoom_adj(&coord, (unsigned char *)dispbox.image.data,
  103.                 buffer.shortbuf, buffer.scalemap + SCALEOFF,
  104.                 buffer.scalemap_summing, buffer.shortbuf_summing);
  105.       else
  106.     map_buf_subzoom_adj(&coord, (unsigned char *)dispbox.image.data,
  107.                 buffer.shortbuf, buffer.scalemap + SCALEOFF,
  108.                 MAX(coord.bd.block, 1),
  109.                 buffer.scalemap_summing, buffer.shortbuf_summing);
  110.     } else {
  111. #endif
  112.       /* no special compensation */
  113.       if( coord.bd.block < -1 )
  114.     map_buf_repzoom(&coord, (unsigned char *)dispbox.image.data,
  115.             buffer.shortbuf, buffer.scalemap + SCALEOFF);
  116.       else
  117.     map_buf_subzoom(&coord, (unsigned char *)dispbox.image.data,
  118.             buffer.shortbuf, buffer.scalemap + SCALEOFF,
  119.             MAX(coord.bd.block, 1));
  120. #ifdef SUMBLOCK
  121.     }
  122. #endif
  123.   }
  124. }
  125.  
  126. /*
  127.  * Subroutine:    clear_margins
  128.  * Purpose:    Take action to indicate unfilled display margins
  129.  */
  130. void clear_margins ( destbuf, ab, bsys, clear, border_color )
  131.      unsigned char *destbuf;        /* destination buffer */
  132.      Edges *ab;                /* mapping parameters */
  133.      Coordsys *bsys;            /* destination parameters */
  134.      int clear;                /* clear unused part of buf */
  135.      register int border_color;        /* color for outline */
  136. {
  137.   register int dest_width;
  138.   int x1, x2, y1, y2;
  139.   short dest_Xwdth;
  140.  
  141.   dest_width = bsys->width;
  142.   dest_Xwdth = ab->dstXwdth;
  143.   x1 = ab->dstX1;
  144.   x2 = bsys->X2i - ab->dstX2;
  145.   y1 = ab->dstY1;
  146.   y2 = bsys->Y2i - ab->dstY2;
  147.  
  148.   /* if unused buffer is to be cleared */
  149.   if( clear ) {
  150.     /* if image leaves gap at top - clear top of buffer */
  151.     if( y1 > 0 ) {
  152.       bzero((char *)destbuf, y1 * dest_width);
  153.     }
  154.     /* if image leaves a gap at the bottom - clear bottom of buffer */
  155.     if( y2 > 0 ) {
  156.       bzero((char *)destbuf + ((y1 + ab->dstYhght) * dest_width),
  157.         y2 * dest_width);
  158.     }
  159.     /* if image leaves gap on either side */
  160.     if( (x1 > 0) || (x2 > 0) ) {
  161.       register unsigned char *dest;
  162.       register int count;
  163.       register int xtot;
  164.  
  165.       xtot = x1 + x2;
  166.       dest = destbuf + (y1 * dest_width);
  167.       /* clear first line on left */
  168.       if( x1 > 0 ) {
  169.     bzero((char *)dest, x1);
  170.       }
  171.       dest += x1 + dest_Xwdth;
  172.       count = ab->dstYhght;
  173.       /* repeatedly clear right and left together */
  174.       while( --count > 0 ) {
  175.     /* clear combination of line on right continued into line on left */
  176.     bzero((char *)dest, xtot);
  177.     dest += dest_width;
  178.       }
  179.       /* clear last line on right */
  180.       if( x2 > 0 ) {
  181.     bzero((char *)dest, x2);
  182.       }
  183.     }
  184.   }
  185.   /* if a border is to be drawn on exposed edges */
  186.   if( border_color != DONT_CARE ) {
  187.     if( x1 > 0 ) {
  188.       register unsigned char *dest;
  189.       register int count;
  190.  
  191.       dest = destbuf + ((y1 * dest_width) + x1 - 1);
  192.       count = ab->dstYhght;
  193.       while( count-- > 0 ) {
  194.     *dest = border_color;
  195.     dest += dest_width;
  196.       }
  197.       ++dest_Xwdth;
  198.       --x1;
  199.     }
  200.     if( x2 > 0 ) {
  201.       register unsigned char *dest;
  202.       register int count;
  203.  
  204.       dest = destbuf + ((y1 * dest_width) + ab->dstX2 + 1);
  205.       count = ab->dstYhght;
  206.       while (count-- > 0) {
  207.     *dest = border_color;
  208.     dest += dest_width;
  209.       }
  210.       ++dest_Xwdth;
  211.     }
  212.     if( y1 > 0 ) {
  213.       register unsigned char *dest;
  214.       register unsigned char *displimit;
  215.  
  216.       dest = destbuf + (((y1 - 1) * dest_width) + x1);
  217.       displimit = dest + dest_Xwdth;
  218.       while (dest < displimit) {
  219.     *(dest++) = border_color;
  220.       }
  221.     }
  222.     if( y2 > 0 ) {
  223.       register unsigned char *dest;
  224.       register unsigned char *displimit;
  225.  
  226.       dest = destbuf + (((ab->dstY2 + 1) * dest_width) + x1);
  227.       displimit = dest + dest_Xwdth;
  228.       while( dest < displimit ) {
  229.     *(dest++) = border_color;
  230.       }
  231.     }
  232.   }
  233. }
  234.