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

  1. #ifndef lint
  2. static char SccsId[] = "%W%  %G%";
  3. #endif
  4.  
  5. /* Module:    dispbtmp.c (Display Bitmap)
  6.  * Purpose:    Routines to map 16 bit data to a single plane bitmap
  7.  * Subroutine:    init_halftone()            returns: void
  8.  * Subroutine:    select_halftone()        returns: void
  9.  * Subroutine:    make_halftone_panimage()    returns: void
  10.  * Subroutine:    make_halftone_display()        returns: void
  11.  * Xlib calls:    none
  12.  * Copyright:    1987, 1988, 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         31 December 1987
  19.  *        {1} MVH signed scalemap, some new names          3 December 1988
  20.  *        {2} MVH new color structure for use with X11      10 May 1989
  21.  *        {3} MVH update on partial display buffer     24 November 1989
  22.  *        {4} MVH changed calls for replcate zoom         21 June 1991
  23.  *        {n} <who> -- <does what> -- <when>
  24.  */
  25.  
  26. #include <stdio.h>            /* stderr, FILE, NULL, etc. */
  27. #include <X11/Xlib.h>            /* X window stuff */
  28. #include <X11/Xutil.h>            /* X window manager stuff */
  29. #include "hfiles/constant.h"        /* define codes */
  30. #include "hfiles/define.h"        /* MIN, MAX and more */
  31. #include "hfiles/struct.h"        /* all struct record types */
  32. #include "hfiles/extern.h"        /* major declared structs */
  33. #include "hfiles/scale.h"        /* scaling parameters & struct */
  34. #include "defs/dither.def"        /* halftoning tool buffers */
  35.  
  36. /*
  37.  * Subroutine:    init_halftone
  38.  * Purpose:    Initialize color struct pointers for halftoning
  39.  */
  40. void init_halftone ()
  41. {
  42.   color.halftone.errbuf = &errbuf[0];
  43.   switch( color.halftone.matrixID ) {
  44.   case BOP_Matrix2:
  45.     color.halftone.matrix = &dotmatrix2[0][0];
  46.     break;
  47.   case BOP_Matrix1:
  48.   default:
  49.     color.halftone.matrix = &dotmatrix1[0][0];
  50.     break;
  51.   }
  52. }
  53.  
  54. /*
  55.  * Subroutine:    select_halftone
  56.  * Purpose:    Respond to halftone selection command
  57.  */
  58. void select_halftone ()
  59. {
  60.   static void new_halftone();
  61.  
  62.   switch( control.response[1] ) {
  63.   case 0:
  64.     /*0 is main menu selection, change only main mode */
  65.     control.mode = BOP;
  66.     break;
  67.   case BOP_Invert:
  68.     /* invert is a toggle, switch cursor colors, redraw disp and pan boxes */
  69.     color.halftone.inverse = !color.halftone.inverse;
  70.     new_halftone(1);
  71.     break;
  72.   case BOP_Diffuse:
  73.     if( color.halftone.mode != BOP_Diffuse ) {
  74.       color.halftone.mode = BOP_Diffuse;
  75.       new_halftone(0);
  76.     }
  77.     break;
  78.   case BOP_Matrix1:
  79.     if( (color.halftone.mode != BOP_Dither) ||
  80.         (color.halftone.matrix != &dotmatrix1[0][0]) ) {
  81.       color.halftone.mode = BOP_Dither;
  82.       color.halftone.matrixID = BOP_Matrix1;
  83.       color.halftone.matrix = &dotmatrix1[0][0];
  84.       new_halftone(1);
  85.     }
  86.     break;
  87.   case BOP_Matrix2:
  88.     if( (color.halftone.mode != BOP_Dither) ||
  89.         (color.halftone.matrix != &dotmatrix2[0][0]) ) {
  90.       color.halftone.mode = BOP_Dither;
  91.       color.halftone.matrixID = BOP_Matrix2;
  92.       color.halftone.matrix = &dotmatrix2[0][0];
  93.       new_halftone(1);
  94.     }
  95.     break;
  96.   }
  97. }
  98.  
  99. /*
  100.  * Subroutine:    new_halftone
  101.  * Purpose:    Redo halftone images of both dispbox and panbox
  102.  */
  103. static void new_halftone ( magnifier )
  104.      int magnifier;    /* i: include-magnifier */
  105. {
  106.   void make_halftone_display(), disp_dispbox(), disp_panbox(), draw_colorbar();
  107.   void set_magnifier_matrix(), panimage_halftone(), map_halftone_colorbar();
  108.  
  109.   map_halftone_colorbar( 1, 0 );
  110.   if( magnifier )
  111.     set_magnifier_matrix(color.halftone.matrix, color.halftone.inverse);
  112.   make_halftone_display();
  113.   disp_dispbox();
  114.   panimage_halftone();
  115.   disp_panbox();
  116.   draw_colorbar(0);
  117. }
  118.  
  119. /*
  120.  * Subroutine:    make_halftone_panimage
  121.  * Purpose:    Make halftone bitmap for pan window (panbox)
  122.  */
  123. void panimage_halftone ( )
  124. {
  125.   void dither_sample(), diffuse_sample();
  126.  
  127.   bzero(panbox.image.data, panbox.image.bytes_per_line * panbox.yheight);
  128.   if( color.halftone.mode == BOP_Dither ) {
  129.     dither_sample(buffer.panbuf, panbox.xwidth, 1,
  130.           (unsigned char *)panbox.image.data,
  131.           panbox.image.bytes_per_line,
  132.           0, 0, panbox.xwidth, panbox.yheight,
  133.           buffer.scalemap + SCALEOFF, color.halftone.matrix,
  134.           color.halftone.inverse);
  135.   } else if( color.halftone.mode == BOP_Diffuse ) {
  136.     diffuse_sample(buffer.panbuf, panbox.xwidth, 1,
  137.            (unsigned char *)panbox.image.data,
  138.            panbox.image.bytes_per_line,
  139.            0, 0, panbox.xwidth, panbox.yheight,
  140.            buffer.scalemap + SCALEOFF, color.halftone.errbuf,
  141.            color.halftone.inverse);
  142.   } 
  143. }
  144.  
  145. /*
  146.  * Subroutine:    make_halftone_display
  147.  * Purpose:    Make halftone bitmap for display window (dispbox)
  148.  */
  149. void make_halftone_display ( )
  150. {
  151.   short *shortimage;
  152.   void diffuse_sample(), diffuse_replicate();
  153.   void dither_sample(), dither_replicate();
  154.   
  155.   /* point to where the image begins in the image BUFFER */
  156.   shortimage = buffer.shortbuf +
  157.     (coord.bd.srcY1 * coord.buf.width) + coord.bd.srcX1;
  158.   /* zero out display buffer for lines to draw (will | with existing bits) */
  159.   if( coord.bd.clip )
  160.     /* if leaving space due to panning/zooming, zero everything */
  161.     bzero(dispbox.image.data, dispbox.image.bytes_per_line * dispbox.yheight);
  162.   else
  163.     bzero(dispbox.image.data + (coord.bd.dstY1 * dispbox.image.bytes_per_line),
  164.       coord.bd.dstYhght * dispbox.image.bytes_per_line);
  165.   /* halftone black and white images */
  166.   if( coord.bd.block < 0 ) {
  167.     int xrep1, yrep1;
  168.     if( coord.bd.dst_x < 0 )
  169.       xrep1 = coord.bd.dst_x + ((coord.bd.src_x + 1) * (-coord.bd.block));
  170.     else
  171.       xrep1 = -coord.bd.block;
  172.     if( coord.bd.dst_y < 0 )
  173.       yrep1 = coord.bd.dst_y + ((coord.bd.src_y + 1) * (-coord.bd.block));
  174.     else
  175.       yrep1 = -coord.bd.block;
  176.     if( color.halftone.mode == BOP_Diffuse ) {
  177.       diffuse_replicate(shortimage, coord.buf.width, -coord.bd.block,
  178.             (unsigned char *)dispbox.image.data,
  179.             dispbox.image.bytes_per_line, xrep1, yrep1,
  180.             coord.bd.dstX1, coord.bd.dstY1,
  181.             coord.bd.dstXwdth-1, coord.bd.dstYhght-1,
  182.             buffer.scalemap + SCALEOFF, color.halftone.errbuf,
  183.             color.halftone.inverse);
  184.     } else {
  185.       dither_replicate(shortimage, coord.buf.width, -coord.bd.block,
  186.                (unsigned char *)dispbox.image.data,
  187.                dispbox.image.bytes_per_line, xrep1, yrep1,
  188.                coord.bd.dstX1, coord.bd.dstY1,
  189.                coord.bd.dstXwdth-1, coord.bd.dstYhght-1,
  190.                buffer.scalemap + SCALEOFF, color.halftone.matrix,
  191.                color.halftone.inverse);
  192.     }
  193.   } else {
  194.     if( color.halftone.mode == BOP_Diffuse ) {
  195.       diffuse_sample(shortimage, coord.buf.width, coord.bd.block,
  196.              (unsigned char *)dispbox.image.data,
  197.              dispbox.image.bytes_per_line, 
  198.              coord.bd.dstX1, coord.bd.dstY1,
  199.              coord.bd.dstXwdth, coord.bd.dstYhght,
  200.              buffer.scalemap + SCALEOFF, color.halftone.errbuf,
  201.              color.halftone.inverse);
  202.     } else {
  203.       dither_sample(shortimage, coord.buf.width, coord.bd.block,
  204.             (unsigned char *)dispbox.image.data,
  205.             dispbox.image.bytes_per_line,
  206.             coord.bd.dstX1, coord.bd.dstY1,
  207.             coord.bd.dstXwdth, coord.bd.dstYhght,
  208.             buffer.scalemap + SCALEOFF, color.halftone.matrix,
  209.             color.halftone.inverse);
  210.     }
  211.   }
  212. }
  213.