Changeset 8480 for trunk/pois/src/poisMaskOps.c
- Timestamp:
- Aug 22, 2006, 2:48:04 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/pois/src/poisMaskOps.c (modified) (5 diffs)
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 1 17 /* 2 18 * Some utility routines that should be in psLib … … 8 24 #include "pois.h" 9 25 10 psImage *poisImageSetVal(psImage *restrict in, // Input image11 const psC64 val// set to this value26 psImage *poisImageSetVal(psImage *restrict in, // Input image 27 const psC64 val // set to this value 12 28 ) 13 29 { … … 16 32 switch (in->type.type) { 17 33 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; 29 45 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; 41 57 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; 45 61 } 46 62 … … 48 64 } 49 65 50 psImage *poisImageSetValInMask(psImage *out, // Image to update, or NULL51 const psImage *restrict in,// Input image52 const psImage *mask,// mask for image53 const psC64 val,// set to this value54 const unsigned long bits// set pixels where mask & bits != 066 psImage *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 55 71 ) 56 72 { … … 65 81 // Allocate the output image, if necessary 66 82 if (out == NULL) { 67 out = psImageCopy(NULL, in, in->type.type);83 out = psImageCopy(NULL, in, in->type.type); 68 84 } 69 85 70 86 switch (in->type.type) { 71 87 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 in76 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; 85 101 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; 89 105 } 90 106
Note:
See TracChangeset
for help on using the changeset viewer.
