Changeset 7663
- Timestamp:
- Jun 23, 2006, 2:22:54 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/mathtypes/psImage.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/mathtypes/psImage.c
r7656 r7663 9 9 * @author Ross Harman, MHPCC 10 10 * 11 * @version $Revision: 1.1 09$ $Name: not supported by cvs2svn $12 * @date $Date: 2006-06-2 3 21:17:52$11 * @version $Revision: 1.110 $ $Name: not supported by cvs2svn $ 12 * @date $Date: 2006-06-24 00:22:54 $ 13 13 * 14 14 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 113 113 } 114 114 115 116 // XXX these have been moved to psRegion* in src/math/117 # if 0118 psRegion psRegionSet(float x0,119 float x1,120 float y0,121 float y1)122 {123 psRegion out;124 125 out.x0 = x0;126 out.y0 = y0;127 out.x1 = x1;128 out.y1 = y1;129 130 return out;131 }132 133 psRegion psRegionFromString(const char* region)134 {135 psS32 col0;136 psS32 col1;137 psS32 row0;138 psS32 row1;139 140 // section should be of the form '[col0:col1,row0:row1]'141 if (region == NULL) {142 psError(PS_ERR_BAD_PARAMETER_NULL, true,143 PS_ERRORTEXT_psImage_SUBSECTION_NULL);144 return psRegionSet(NAN,NAN,NAN,NAN);145 }146 147 if (sscanf(region,"[%d:%d,%d:%d]",&col0,&col1,&row0,&row1) < 4) {148 psError(PS_ERR_BAD_PARAMETER_NULL, true,149 PS_ERRORTEXT_psImage_SUBSECTION_INVALID,150 region);151 return psRegionSet(NAN,NAN,NAN,NAN);152 }153 154 if (col0 > col1 || row0 > row1) {155 psError(PS_ERR_BAD_PARAMETER_VALUE, true,156 PS_ERRORTEXT_psImage_SUBSET_RANGE_MALFORMED,157 col0,col1,row0,row1);158 return psRegionSet(NAN,NAN,NAN,NAN);159 }160 161 return psRegionSet(col0-1,col1,row0-1,row1);162 }163 164 psString psRegionToString(const psRegion region)165 {166 char tmpText[256]; // big enough to store any region as text167 168 snprintf(tmpText,256,"[%g:%g,%g:%g]",169 region.x0+1, region.x1,170 region.y0+1, region.y1);171 172 return psStringCopy(tmpText);173 }174 175 // set actual region based on image parameters:176 // - compensate for negative upper limits177 // - force range to be on this image178 // - saturate on upper and lower limits of image179 // - flip x0,x1 if x0>x1180 // - flip y0,y1 if y0>y1181 // XXX EAM : psRegion refers to coordinates in the *parent* image182 psRegion psRegionForImage(psImage *image,183 psRegion in)184 {185 186 // if (image == NULL) {187 // return in;188 // }189 PS_ASSERT_IMAGE_NON_NULL(image, in);190 //if the region is [0,0,0,0], the whole image (or subimage) is to be included.191 if (in.x0 == 0 && in.x1 == 0 && in.y0 == 0 && in.y1 == 0) {192 in.x0 = image->col0;193 in.x1 = image->col0 + image->numCols - 1;194 in.y0 = image->row0;195 in.y1 = image->row0 + image->numRows - 1;196 return (in);197 }198 199 // convert non-positive upper-limits200 // XXX note that the upper limit in these cases is defined relative to the subimage201 // also note that truncation limits to the valid subimage pixels202 in.x1 = (in.x1 <= 0) ? (image->col0 + image->numCols + in.x1) : in.x1;203 in.y1 = (in.y1 <= 0) ? (image->row0 + image->numRows + in.y1) : in.y1;204 205 // force the upper-limits to be on the subimage206 in.x1 = PS_MIN(image->col0 + image->numCols, in.x1);207 in.y1 = PS_MIN(image->row0 + image->numRows, in.y1);208 209 // force the lower-limits to be on the subimage210 in.x0 = PS_MAX(image->col0, in.x0);211 in.y0 = PS_MAX(image->row0, in.y0);212 in.x0 = PS_MIN(image->col0 + image->numCols, in.x0);213 in.y0 = PS_MIN(image->row0 + image->numRows, in.y0);214 215 // flip start and end if out of order216 if (in.x0 > in.x1) {217 psError (PS_ERR_BAD_PARAMETER_VALUE, true,218 "Invalid region in psRegionForImage. x0 > x1. Values have been swapped.\n");219 PS_SWAP (in.x0, in.x1);220 }221 if (in.y0 > in.y1) {222 psError (PS_ERR_BAD_PARAMETER_VALUE, true,223 "Invalid region in psRegionForImage. y0 > y1. Values have been swapped.\n");224 PS_SWAP (in.y0, in.y1);225 }226 227 return (in);228 }229 230 // define a square region centered on the given coordinate231 psRegion psRegionForSquare(double x,232 double y,233 double radius)234 {235 psRegion region;236 region = psRegionSet (x - radius, x + radius + 1,237 y - radius, y + radius + 1);238 return (region);239 }240 # endif /* commented-out psRegion functions */241 242 115 bool psImageInit (psImage *image,...) 243 116 { … … 251 124 252 125 switch (image->type.type) { 253 #define IMAGEINIT_INTCASE(T TT,NATIVETYPE) \254 case PS_TYPE_##T TT: { \255 NATIVETYPE temp = va_arg (argp, NATIVETYPE); \256 if ( temp < PS_MIN_##T TT || temp > PS_MAX_##TTT) { \126 #define IMAGEINIT_INTCASE(TYPE,NATIVETYPE) \ 127 case PS_TYPE_##TYPE: { \ 128 NATIVETYPE temp = va_arg(argp, NATIVETYPE); \ 129 if ( temp < PS_MIN_##TYPE || temp > PS_MAX_##TYPE ) { \ 257 130 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Error: Value %d out of Range.\n", temp); \ 258 131 return false; \ 259 132 } \ 260 ps##TTT value = temp; \ 261 for (int iy = 0; iy < image->numRows; iy++) { \ 262 ps##TTT *row = image->data.TTT[iy]; \ 263 for (int ix = 0; ix < image->numCols; ix++) { \ 264 row[ix] = value; \ 133 ps##TYPE value = temp; \ 134 if (value == 0) { \ 135 size_t numBytes = image->numCols * sizeof(ps##TYPE); \ 136 for (int y = 0; y < image->numRows; y++) { \ 137 memset(image->data.TYPE[y], 0, numBytes); \ 138 } \ 139 } else { \ 140 for (int iy = 0; iy < image->numRows; iy++) { \ 141 ps##TYPE *row = image->data.TYPE[iy]; \ 142 for (int ix = 0; ix < image->numCols; ix++) { \ 143 row[ix] = value; \ 144 } \ 265 145 } \ 266 146 } \ 267 return (true); \147 return true; \ 268 148 } 269 149 … … 275 155 IMAGEINIT_INTCASE(S32,int) 276 156 277 #define IMAGEINIT_LONGCASE(TTT,NATIVETYPE) \ 278 case PS_TYPE_##TTT: { \ 279 ps##TTT value = va_arg (argp, NATIVETYPE); \ 280 for (int iy = 0; iy < image->numRows; iy++) { \ 281 ps##TTT *row = image->data.TTT[iy]; \ 282 for (int ix = 0; ix < image->numCols; ix++) { \ 283 row[ix] = value; \ 157 #define IMAGEINIT_LONGCASE(TYPE,NATIVETYPE) \ 158 case PS_TYPE_##TYPE: { \ 159 ps##TYPE value = va_arg(argp, NATIVETYPE); \ 160 if (value == 0) { \ 161 size_t numBytes = image->numCols * sizeof(ps##TYPE); \ 162 for (int y = 0; y < image->numRows; y++) { \ 163 memset(image->data.TYPE[y], 0, numBytes); \ 164 } \ 165 } else { \ 166 for (int iy = 0; iy < image->numRows; iy++) { \ 167 ps##TYPE *row = image->data.TYPE[iy]; \ 168 for (int ix = 0; ix < image->numCols; ix++) { \ 169 row[ix] = value; \ 170 } \ 284 171 } \ 285 172 } \ 286 return (true); \173 return true; \ 287 174 } 288 175 … … 290 177 IMAGEINIT_LONGCASE(S64,long) 291 178 292 #define IMAGEINIT_FLOATCASE(TTT) \ 293 case PS_TYPE_##TTT: { \ 294 ps##TTT value = va_arg(argp, psF64); \ 295 \ 296 for (int iy = 0; iy < image->numRows; iy++) { \ 297 ps##TTT *row = image->data.TTT[iy]; \ 298 for (int ix = 0; ix < image->numCols; ix++) { \ 299 row[ix] = value; \ 179 #define IMAGEINIT_FLOATCASE(TYPE) \ 180 case PS_TYPE_##TYPE: { \ 181 ps##TYPE value = va_arg(argp, psF64); \ 182 if (value == 0) { \ 183 size_t numBytes = image->numCols * sizeof(ps##TYPE); \ 184 for (int y = 0; y < image->numRows; y++) { \ 185 memset(image->data.TYPE[y], 0, numBytes); \ 186 } \ 187 } else { \ 188 for (int iy = 0; iy < image->numRows; iy++) { \ 189 ps##TYPE *row = image->data.TYPE[iy]; \ 190 for (int ix = 0; ix < image->numCols; ix++) { \ 191 row[ix] = value; \ 192 } \ 300 193 } \ 301 194 } \ 302 return (true); \195 return true; \ 303 196 } 304 197 … … 308 201 default: 309 202 psError (PS_ERR_BAD_PARAMETER_TYPE, true, "datatype %d not defined in psImageInit\n", image->type); 310 return (false);311 203 } 312 204 return (false);
Note:
See TracChangeset
for help on using the changeset viewer.
