IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 22, 2006, 2:48:04 PM (20 years ago)
Author:
Paul Price
Message:

Adding GPL stuff, for distribution

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pois/src/poisMaskOps.c

    r3806 r8480  
     1// Copyright (C) 2006  Paul A. Price (price@ifa.hawaii.edu)
     2//
     3// This program is free software; you can redistribute it and/or modify
     4// it under the terms of the GNU General Public License as published by
     5// the Free Software Foundation; either version 2 of the License, or
     6// (at your option) any later version.
     7//
     8// This program is distributed in the hope that it will be useful,
     9// but WITHOUT ANY WARRANTY; without even the implied warranty of
     10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11// GNU General Public License for more details.
     12//
     13// You should have received a copy of the GNU General Public License
     14// along with this program; if not, write to the Free Software
     15// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     16
    117/*
    218 * Some utility routines that should be in psLib
     
    824#include "pois.h"
    925
    10 psImage *poisImageSetVal(psImage *restrict in,       // Input image
    11                          const psC64 val             // set to this value
     26psImage *poisImageSetVal(psImage *restrict in,       // Input image
     27                         const psC64 val             // set to this value
    1228    )
    1329{
     
    1632    switch (in->type.type) {
    1733      case PS_TYPE_U8:
    18         {
    19             const int numCols = in->numCols;
    20             psU8 *row0 = in->data.U8[0];
    21             for (int c = 0; c < numCols; c++) {
    22                 row0[c] = val;
    23             }
    24             for (int r = 1; r < in->numRows; r++) {
    25                 memcpy(in->data.U8[r], row0, numCols*sizeof(psU8));
    26             }
    27         }
    28         break;
     34        {
     35            const int numCols = in->numCols;
     36            psU8 *row0 = in->data.U8[0];
     37            for (int c = 0; c < numCols; c++) {
     38                row0[c] = val;
     39            }
     40            for (int r = 1; r < in->numRows; r++) {
     41                memcpy(in->data.U8[r], row0, numCols*sizeof(psU8));
     42            }
     43        }
     44        break;
    2945      case PS_TYPE_F32:
    30         {
    31             const int numCols = in->numCols;
    32             psF32 *row0 = in->data.F32[0];
    33             for (int c = 0; c < numCols; c++) {
    34                 row0[c] = val;
    35             }
    36             for (int r = 1; r < in->numRows; r++) {
    37                 memcpy(in->data.F32[r], row0, numCols*sizeof(psF32));
    38             }
    39         }
    40         break;
     46        {
     47            const int numCols = in->numCols;
     48            psF32 *row0 = in->data.F32[0];
     49            for (int c = 0; c < numCols; c++) {
     50                row0[c] = val;
     51            }
     52            for (int r = 1; r < in->numRows; r++) {
     53                memcpy(in->data.F32[r], row0, numCols*sizeof(psF32));
     54            }
     55        }
     56        break;
    4157      default:
    42         psError(POIS_ERR_UNSUPPORTED_TYPE, true,
    43                 "Type %d is not supported", in->type.type);
    44         return NULL;
     58        psError(POIS_ERR_UNSUPPORTED_TYPE, true,
     59                "Type %d is not supported", in->type.type);
     60        return NULL;
    4561    }
    4662
     
    4864}
    4965
    50 psImage *poisImageSetValInMask(psImage *out,                    // Image to update, or NULL
    51                                const psImage *restrict in,      // Input image
    52                                const psImage *mask,             // mask for image
    53                                const psC64 val,                 // set to this value
    54                                const unsigned long bits         // set pixels where mask & bits != 0
     66psImage *poisImageSetValInMask(psImage *out,                    // Image to update, or NULL
     67                               const psImage *restrict in,      // Input image
     68                               const psImage *mask,             // mask for image
     69                               const psC64 val,                 // set to this value
     70                               const unsigned long bits         // set pixels where mask & bits != 0
    5571    )
    5672{
     
    6581    // Allocate the output image, if necessary
    6682    if (out == NULL) {
    67         out = psImageCopy(NULL, in, in->type.type);
     83        out = psImageCopy(NULL, in, in->type.type);
    6884    }
    6985
    7086    switch (in->type.type) {
    7187      case PS_TYPE_F32:
    72         {
    73             const int numCols = in->numCols;
    74             for (int r = 0; r < in->numRows; r++) {
    75                 psF32 *row = out->data.F32[r]; // n.b. a copy of in
    76                 psU8 *mrow = mask->data.U8[r];
    77                 for (int c = 0; c < numCols; c++) {
    78                     if (mrow[c] & bits) {
    79                         row[c] = val;
    80                     }
    81                 }
    82             }
    83         }
    84         break;
     88        {
     89            const int numCols = in->numCols;
     90            for (int r = 0; r < in->numRows; r++) {
     91                psF32 *row = out->data.F32[r]; // n.b. a copy of in
     92                psU8 *mrow = mask->data.U8[r];
     93                for (int c = 0; c < numCols; c++) {
     94                    if (mrow[c] & bits) {
     95                        row[c] = val;
     96                    }
     97                }
     98            }
     99        }
     100        break;
    85101      default:
    86         psError(POIS_ERR_UNSUPPORTED_TYPE, true,
    87                 "Type %d is not supported", in->type.type);
    88         return NULL;
     102        psError(POIS_ERR_UNSUPPORTED_TYPE, true,
     103                "Type %d is not supported", in->type.type);
     104        return NULL;
    89105    }
    90106
Note: See TracChangeset for help on using the changeset viewer.