home *** CD-ROM | disk | FTP | other *** search
/ Encyclopedia of Graphics File Formats Companion / GFF_CD.ISO / software / unix / saoimage / sao1_07.tar / disppxmp.c < prev    next >
C/C++ Source or Header  |  1991-06-21  |  7KB  |  208 lines

  1. #ifndef lint
  2. static char SccsId[] = "%W%  %G%";
  3. #endif
  4.  
  5. /* Module:    disppxmp.c (Display Pixmap)
  6.  * Purpose:    Map short buffer to picturebox display buffer
  7.  * Subroutine:    map_buf_subzoom()        returns: void
  8.  * Subroutine:    map_buf_repzoom()        returns: void
  9.  * Subroutine:    map_buf_subzoom_adj()        returns: void
  10.  * Subroutine:    map_buf_repzoom_adj()        returns: void
  11.  * Copyright:    1987 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         31 December 1987
  18.  *        {1} MVH Replaced zoom rep code, dumped adj stuff 21 June 1991
  19.  *        {n} <who> -- <does what> -- <when>
  20.  */
  21.  
  22. #include "hfiles/coord.h"
  23.  
  24. /*
  25.  * Subroutine:    map_buf_subzoom
  26.  * Purpose:    Map data to a display buffer, zoomed down by sub-sampling
  27.  */
  28. void map_buf_subzoom ( coord, displaybuf, imagebuf, scalemap, block_sample )
  29.      struct coordRec *coord;
  30.      unsigned char *displaybuf;        /* i/o: pointer to display buffer */
  31.      short *imagebuf;            /* i: pointer to image buffer */
  32.      unsigned char *scalemap;        /* i: pointer to lookup table */
  33.      register int block_sample;        /* i: buf to disp sub-sampling count */
  34. {
  35.   register short *imgb;            /* l: value pointer in image buffer */
  36.   register unsigned char *lookup;    /* l: pointer in lookup table */
  37.   register unsigned char *display;    /* l: pointer in display buffer */
  38.   int disp_xwdth;            /* l: image display width in buffer */
  39.   short disp_advance;            /* l: move disp pointer to next line */
  40.   unsigned char *displayend;        /* l: display terminal ref point */
  41.   short image_advance;            /* l: move img pointer to next line */
  42.  
  43.   /* initialize parameter values */
  44.   {
  45.     register int disp_width;        /* l: row width in display buffer */
  46.  
  47.     /* set index between starts of lines, length of scan in one output line */
  48.     disp_width = coord->disp.width;
  49.     disp_xwdth = coord->bd.dstXwdth;
  50.     display = displaybuf + ((coord->bd.dstY1 * disp_width) + coord->bd.dstX1);
  51.     imgb = imagebuf +
  52.       ((coord->bd.srcY1 * coord->buf.width) + coord->bd.srcX1);
  53.     lookup = scalemap;
  54.     /* next line minus already ticked off (zoom * bwdth) - (zoom * dwdth) */
  55.     image_advance = (coord->buf.width - disp_xwdth) * block_sample;
  56.     disp_advance = disp_width - disp_xwdth; 
  57.     displayend = display + (coord->bd.dstYhght * disp_width);
  58.   }
  59.   /* loop through sub-sampling */
  60.   {
  61.     register unsigned char *displimit;
  62.  
  63.     while( display < displayend ) {
  64.       /* make a sub-sampled line */
  65.       displimit = display + disp_xwdth;
  66.       while( display < displimit ) {
  67.     *display++ = lookup[*imgb];
  68.     imgb += block_sample;
  69.       }
  70.       display += disp_advance;
  71.       imgb += image_advance;
  72.     }
  73.   }
  74. }
  75.  
  76. /*
  77.  * Subroutine:    map_buf_repzoom
  78.  * Purpose:    Put zoom replicated image data in the display buffer
  79.  */
  80. #ifdef ANSIC
  81. void map_buf_repzoom ( struct coordRec *coord, unsigned char *dst_buf,
  82.                short *src_buf, unsigned char *scalemap )
  83. #else
  84. void map_buf_repzoom ( coord, dst_buf, src_buf, scalemap )
  85.      struct coordRec *coord;
  86.      unsigned char *dst_buf;        /* i/o: pointer to display buffer */
  87.      short *src_buf;            /* i: pointer to image buffer */
  88.      unsigned char *scalemap;        /* i: pointer to lookup table */
  89. #endif
  90. {
  91.   register int zoom;            /* l: 1D pixel replication count */
  92.   register unsigned char *dst;        /* l: pointer in display buffer */
  93.   register unsigned char val;        /* l: value mapped from lookup table */
  94.   register unsigned char* xrep_limit;
  95.   register unsigned char *lookup;    /* l: pointer in lookup table */
  96.   register short *src;            /* l: value pointer in image buffer */
  97.   short *src_line;            /* l: line start in image buffer */
  98.   unsigned char* dst_x_limit;
  99.   unsigned char *dst_line;        /* l: start line in display buffer */
  100.   int y_dst_count;
  101.   int x_dst_count;
  102.   int dst_x, dst_y;
  103.   int dst_width, dst_height;
  104.   int src_x, src_y;
  105.   int src_width, src_height;
  106.   int yrep_limit;
  107.   int first_xrep;
  108.  
  109.   /*  Set basic parameters  */
  110.   zoom = -coord->bd.block;
  111.   dst_x = coord->bd.dst_x;
  112.   dst_y = coord->bd.dst_y;
  113.   dst_width = coord->disp.width;
  114.   dst_height = coord->disp.height;
  115.   src_width = coord->buf.width;
  116.   src_height = coord->buf.height;
  117.   /*  If buffer extends to or beyond lower edge  */
  118.   y_dst_count = dst_y + (src_height * zoom);
  119.   if( y_dst_count > dst_height )
  120.     y_dst_count = dst_height;
  121.   if( dst_y <= 0 ) {
  122.     /*  Compute starting offset in line, and first repetition count  */
  123.     src_y = -dst_y / zoom;
  124.     yrep_limit = dst_y + ((src_y + 1) * zoom);
  125.     dst_y = 0;
  126.   } else if( dst_y < dst_height ) {
  127.     src_y = 0;
  128.     yrep_limit = zoom;
  129.     y_dst_count -= dst_y;
  130.   } else
  131.     return;
  132.    
  133.   /*  If buffer extends to or beyond left edge  */
  134.   x_dst_count = dst_x + (src_width * zoom);
  135.   if( x_dst_count > dst_width )
  136.     x_dst_count = dst_width;
  137.   if( dst_x <= 0 ) {
  138.     /*  Compute starting offset in line, and first repetition count  */
  139.     src_x = -dst_x / zoom;
  140.     first_xrep = dst_x + ((src_x + 1) * zoom);
  141.     dst_x = 0;
  142.   } else if( dst_x < dst_width ) {
  143.     src_x = 0;
  144.     first_xrep = zoom;
  145.     x_dst_count -= dst_x;
  146.   } else
  147.     return;
  148.  
  149.   lookup = scalemap;
  150.   /*  Start pointers for display_data, and image_data  */
  151.   dst_line = dst_buf + ((dst_y * dst_width) + dst_x);
  152.   src_line = src_buf + ((src_y * src_width) + src_x);
  153.   dst_y = 0;
  154.  
  155.   {
  156.     register unsigned char *xreplimit;        /* loop comparison pointer */
  157.     register unsigned char *displaylimit;    /* limit comparison pointer */
  158.  
  159.     /*  Loop by image row  */
  160.     while( dst_y < y_dst_count ) {
  161.       /*  Update src and dst pointers  */
  162.       src = src_line;
  163.       dst = dst_line;
  164.       dst_x_limit = dst + x_dst_count;
  165.       /*  First pixel may be replicated less  */
  166.       xrep_limit = dst + first_xrep;
  167.       while( xrep_limit < dst_x_limit ) {
  168.     /* get output val */
  169.     val = lookup[*src++];
  170.     /*  Replicate  */
  171.     while( dst < xrep_limit ) {
  172.       *dst++ = val;
  173.     }
  174.     /*  Reset replication counter  */
  175.     xrep_limit += zoom;
  176.       }
  177.       /*  Repeat for last val (replicate to end)  */
  178.       val = lookup[*src++];
  179.       while( dst < dst_x_limit ) {
  180.     *dst++ = val;
  181.       }
  182.       /*  Get pointers to next line */
  183.       dst = dst_line;
  184.       dst_line += dst_width;
  185.       dst_y++;
  186.       /*  Make sure line copying doesn't go too far  */
  187.       if( yrep_limit > y_dst_count )
  188.           yrep_limit = y_dst_count;
  189.       /*  Replicate rows  */
  190.       while( dst_y < yrep_limit ) {
  191. #ifdef ANSIC
  192.     memcopy((char *)dst_line, (char *)dst, x_dst_count);
  193. #else
  194.     bcopy((char *)dst, (char *)dst_line, x_dst_count);
  195. #endif ANSIC
  196.     dst_line += dst_width;
  197.     dst_y++;
  198.       }
  199.       /*  Set up next line replication counter  */
  200.       yrep_limit += zoom;
  201.       /*  Advance image pointer to place in next line */
  202.       src = (src_line += src_width);
  203.     }
  204.   }
  205. }
  206.  
  207.  
  208.