home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / hips / libsrc / h_addmask.c next >
Encoding:
C/C++ Source or Header  |  1991-09-17  |  4.8 KB  |  200 lines

  1.  
  2. /* addmask.c                                 Brian Tierney, LBL   4/90
  3.  *
  4.  *   usage:   addmask [-n] mask_image < image > new_image
  5.  *
  6.  *   creates new image which is the input image where the mask
  7.  *    value is > 0, and zero everywhere else.
  8.  *
  9.  *  Works with data types: Byte, short, int, float, and complex.
  10.  *
  11.  *  converted to HIPS2:  Felix Huang
  12.  */
  13.  
  14. /*   This program is copyright (C) 1990, Regents  of  the
  15. University  of  California.   Anyone may reproduce this software,
  16. in whole or in part, provided that:
  17. (1)  Any copy  or  redistribution  must  show  the
  18.      Regents  of  the  University of California, through its
  19.      Lawrence Berkeley Laboratory, as the source,  and  must
  20.      include this notice;
  21. (2)  Any use of this software must reference this  distribu-
  22.      tion,  state that the software copyright is held by the
  23.      Regents of the University of California, and  that  the
  24.      software is used by their permission.
  25.  
  26.      It is acknowledged that the U.S. Government has  rights
  27. to this software under  Contract DE-AC03-765F00098 between the U.S.
  28. Department of Energy and the University of California.
  29.  
  30.      This software is provided as a professional  academic  contribu-
  31. tion  for  joint exchange.  Thus it is experimental, is pro-
  32. vided ``as is'', with no warranties of any kind  whatsoever,
  33. no  support,  promise  of updates, or printed documentation.
  34. Bug reports or fixes may be sent to the author, who may or may
  35. not act on them as he desires.
  36. */
  37.  
  38. /*   Author:  Brian L. Tierney
  39.  *            Lawrence Berkeley Laboratory
  40.  *            Imaging Technologies Group
  41.  *            email: bltierney@lbl.gov
  42. */
  43.  
  44. #include <stdio.h>
  45. #include <sys/types.h>
  46. #include <math.h>
  47.  
  48. #include <hipl_format.h>
  49.  
  50. extern Boolean neg;
  51.  
  52. extern struct header m_hd2;    /* mask image header             */
  53.  
  54. int       m_ocol;
  55.  
  56. int       nrow;
  57. int       ncol;
  58. int       i_ocol;
  59.  
  60. byte     *bmask;        /* binary mask     */
  61.  
  62. h_addmask(hdi, hdo)
  63.     struct header *hdi, *hdo;
  64. {
  65.     m_ocol = m_hd2.ocols;    /* mask column difference  */
  66.  
  67.     nrow = hdi->rows;
  68.     ncol = hdi->cols;
  69.     i_ocol = hdi->ocols;
  70.  
  71.     bmask = m_hd2.image + hdi->frow * m_hd2.ocols + hdi->fcol;
  72.  
  73.     switch (hdi->pixel_format) {
  74.     case PFBYTE:
  75.     return h_addm_b(hdi->firstpix, hdo->firstpix);
  76.     case PFSHORT:
  77.     return h_addm_s((short *) hdi->firstpix,
  78.             (short *) hdo->firstpix);
  79.     case PFINT:
  80.     return h_addm_i((int *) hdi->firstpix,
  81.             (int *) hdo->firstpix);
  82.     case PFFLOAT:
  83.     return h_addm_f((float *) hdi->firstpix,
  84.             (float *) hdo->firstpix);
  85.     case PFCOMPLEX:
  86.     return h_addm_c((float *) hdi->firstpix,
  87.             (float *) hdo->firstpix);
  88.     }
  89.  
  90. }                /* end of h_addmask (hdi, hdo)     */
  91.  
  92. h_addm_b(imagei, imageo)
  93.     byte     *imagei;
  94.     byte     *imageo;
  95. {
  96.     int       x, y;
  97.  
  98.     for (y = 0; y < nrow; y++, imagei = imagei + i_ocol,
  99.      imageo = imageo + i_ocol,
  100.      bmask = bmask + m_ocol) {
  101.     for (x = 0; x < ncol; x++) {
  102.         if ((neg == FALSE && bmask[x] != 0) ||
  103.         (neg == TRUE && bmask[x] == 0))
  104.         imageo[x] = imagei[x];
  105.         else
  106.         imageo[x] = 0;
  107.     }
  108.     }
  109.  
  110. }                /* end of  h_addm_b ( imagei, imageo )     */
  111.  
  112.  
  113. h_addm_s(imagei, imageo)
  114.     short    *imagei;
  115.     short    *imageo;
  116. {
  117.     int       x, y;
  118.  
  119.     for (y = 0; y < nrow; y++, imagei = imagei + i_ocol,
  120.      imageo = imageo + i_ocol,
  121.      bmask = bmask + m_ocol) {
  122.     for (x = 0; x < ncol; x++) {
  123.         if ((neg == FALSE && bmask[x] != 0) ||
  124.         (neg == TRUE && bmask[x] == 0))
  125.         imageo[x] = imagei[x];
  126.         else
  127.         imageo[x] = 0;
  128.     }
  129.     }
  130.  
  131. }                /* end of  h_addm_s ( imagei, imageo )     */
  132.  
  133.  
  134. h_addm_i(imagei, imageo)
  135.     int      *imagei;
  136.     int      *imageo;
  137. {
  138.     int       x, y;
  139.  
  140.     for (y = 0; y < nrow; y++, imagei = imagei + i_ocol,
  141.      imageo = imageo + i_ocol,
  142.      bmask = bmask + m_ocol) {
  143.     for (x = 0; x < ncol; x++) {
  144.         if ((neg == FALSE && bmask[x] != 0) ||
  145.         (neg == TRUE && bmask[x] == 0))
  146.         imageo[x] = imagei[x];
  147.         else
  148.         imageo[x] = 0;
  149.     }
  150.     }
  151.  
  152. }                /* end of  h_addm_i ( imagei, imageo )     */
  153.  
  154.  
  155. h_addm_f(imagei, imageo)
  156.     float    *imagei;
  157.     float    *imageo;
  158. {
  159.     int       x, y;
  160.  
  161.     for (y = 0; y < nrow; y++, imagei = imagei + i_ocol,
  162.      imageo = imageo + i_ocol,
  163.      bmask = bmask + m_ocol) {
  164.     for (x = 0; x < ncol; x++) {
  165.         if ((neg == FALSE && bmask[x] != 0) ||
  166.         (neg == TRUE && bmask[x] == 0))
  167.         imageo[x] = imagei[x];
  168.         else
  169.         imageo[x] = 0;
  170.     }
  171.     }
  172.  
  173. }                /* end of  h_addm_f ( imagei, imageo )     */
  174.  
  175.  
  176. h_addm_c(imagei, imageo)
  177.     float    *imagei;
  178.     float    *imageo;
  179. {
  180.     int       x, y;
  181.     int       j;
  182.  
  183.     for (y = 0; y < nrow; y++, imagei = imagei + 2 * i_ocol,
  184.      imageo = imageo + 2 * i_ocol,
  185.      bmask = bmask + m_ocol) {
  186.     for (x = 0; x < ncol; x++) {
  187.         j = 2 * x;
  188.         if ((neg == FALSE && bmask[x] != 0) ||
  189.         (neg == TRUE && bmask[x] == 0)) {
  190.         imageo[j] = imagei[j];
  191.         imageo[j + 1] = imagei[j + 1];
  192.         } else {
  193.         imageo[j] = 0;
  194.         imageo[j + 1] = 0;
  195.         }
  196.     }
  197.     }
  198.  
  199. }                /* end of  h_addm_c ( imagei, imageo )     */
  200.