Changeset 19960
- Timestamp:
- Oct 7, 2008, 12:23:06 PM (18 years ago)
- Location:
- trunk/psLib/src/imageops
- Files:
-
- 2 edited
-
psImageMap.c (modified) (9 diffs)
-
psImageMap.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/imageops/psImageMap.c
r15841 r19960 7 7 * @author Eugene Magnier, IfA 8 8 * 9 * @version $Revision: 1. 8$ $Name: not supported by cvs2svn $10 * @date $Date: 200 7-12-15 01:20:03$9 * @version $Revision: 1.9 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2008-10-07 22:23:06 $ 11 11 * 12 12 * Copyright 2007 Institute for Astronomy, University of Hawaii … … 37 37 #include "psImageMap.h" 38 38 39 static void psImageMapFree(psImageMap *map) { 40 41 if (!map) return; 42 39 static void imageMapFree(psImageMap *map) 40 { 43 41 psFree(map->map); 44 42 psFree(map->error); … … 49 47 } 50 48 51 psImageMap *psImageMapAlloc(const psImage *field, psImageBinning *binning, psStats *stats) { 52 PS_ASSERT_IMAGE_NON_NULL(field, NULL); 53 assert (binning); 54 assert (stats); 55 56 psImageMap *map = (psImageMap*)psAlloc(sizeof(psImageMap)); 57 psMemSetDeallocator(map, (psFreeFunc)psImageMapFree); 58 59 map->binning = psMemIncrRefCounter (binning); 60 map->stats = psMemIncrRefCounter (stats); 49 psImageMap *psImageMapAlloc(const psImage *field, psImageBinning *binning, psStats *stats) 50 { 51 psAssert(field, "Require field image"); 52 psAssert(binning, "Require binning"); 53 // stats may be NULL 54 55 psImageMap *map = psAlloc(sizeof(psImageMap)); 56 psMemSetDeallocator(map, (psFreeFunc)imageMapFree); 57 58 map->binning = psMemIncrRefCounter(binning); 59 map->stats = psMemIncrRefCounter(stats); 61 60 62 61 map->col0 = field->col0; … … 65 64 map->numRows = field->numRows; 66 65 67 map->map = psImageAlloc(binning->nXruff, binning->nYruff, PS_TYPE_F32);68 psImageInit (map->map, 0.0);69 70 map->error = psImageAlloc(binning->nXruff, binning->nYruff, PS_TYPE_F32);71 psImageInit (map->error, 0.0);72 73 psImageBinningSetScale (map->binning, PS_IMAGE_BINNING_CENTER);74 psImageBinningSetSkipByOffset (map->binning, map->col0, map->row0);66 map->map = psImageAlloc(binning->nXruff, binning->nYruff, PS_TYPE_F32); 67 psImageInit(map->map, 0.0); 68 69 map->error = psImageAlloc(binning->nXruff, binning->nYruff, PS_TYPE_F32); 70 psImageInit(map->error, 0.0); 71 72 psImageBinningSetScale(map->binning, PS_IMAGE_BINNING_CENTER); 73 psImageBinningSetSkipByOffset(map->binning, map->col0, map->row0); 75 74 76 75 return map; … … 80 79 { 81 80 PS_ASSERT_PTR(ptr, false); 82 return ( psMemGetDeallocator(ptr) == (psFreeFunc) psImageMapFree);81 return (psMemGetDeallocator(ptr) == (psFreeFunc)imageMapFree); 83 82 } 84 83 85 84 // allocate the image map using the psImageBinning supplied 86 psImageMap *psImageMapNoImageAlloc(psImageBinning *binning, psStats *stats) { 87 88 assert (binning); 89 assert (stats); 90 91 psImageMap *map = (psImageMap*)psAlloc(sizeof(psImageMap)); 92 psMemSetDeallocator(map, (psFreeFunc)psImageMapFree); 93 94 map->stats = psMemIncrRefCounter (stats); 95 map->binning = psMemIncrRefCounter (binning); 96 97 map->map = psImageAlloc (binning->nXruff, binning->nYruff, PS_TYPE_F32); 98 psImageInit (map->map, 0.0); 99 100 map->error = psImageAlloc (binning->nXruff, binning->nYruff, PS_TYPE_F32); 101 psImageInit (map->error, 0.0); 85 psImageMap *psImageMapNoImageAlloc(psImageBinning *binning, psStats *stats) 86 { 87 psAssert(binning, "Require binning"); 88 // stats may be NULL 89 90 psImageMap *map = psAlloc(sizeof(psImageMap)); 91 psMemSetDeallocator(map, (psFreeFunc)imageMapFree); 92 93 map->binning = psMemIncrRefCounter(binning); 94 map->stats = psMemIncrRefCounter(stats); 95 96 map->col0 = 0; 97 map->row0 = 0; 98 map->numCols = 0; 99 map->numRows = 0; 100 101 map->map = psImageAlloc(binning->nXruff, binning->nYruff, PS_TYPE_F32); 102 psImageInit(map->map, 0.0); 103 104 map->error = psImageAlloc(binning->nXruff, binning->nYruff, PS_TYPE_F32); 105 psImageInit(map->error, 0.0); 102 106 103 107 return map; … … 106 110 bool psImageMapModifyScale(psImageMap *map, int nXruff, int nYruff) 107 111 { 108 assert (map);112 PS_ASSERT_IMAGE_MAP_NON_NULL(map, false); 109 113 110 114 map->binning->nXruff = nXruff; 111 115 map->binning->nYruff = nYruff; 112 116 113 psImageRecycle(map->map, nXruff, nYruff, PS_TYPE_F32);114 psImageRecycle(map->error, nXruff, nYruff, PS_TYPE_F32);115 116 psImageBinningSetScale (map->binning, PS_IMAGE_BINNING_CENTER);117 psImageBinningSetSkipByOffset (map->binning, map->col0, map->row0);117 map->map = psImageRecycle(map->map, nXruff, nYruff, PS_TYPE_F32); 118 map->error = psImageRecycle(map->error, nXruff, nYruff, PS_TYPE_F32); 119 120 psImageBinningSetScale(map->binning, PS_IMAGE_BINNING_CENTER); 121 psImageBinningSetSkipByOffset(map->binning, map->col0, map->row0); 118 122 119 123 return true; … … 125 129 const psVector *f, const psVector *df, float badFrac) 126 130 { 127 // XXX asserts 131 PS_ASSERT_IMAGE_MAP_NON_NULL(map, false); 132 PS_ASSERT_IMAGE_MAP_STATS(map, false); 133 PS_ASSERT_VECTOR_NON_NULL(x, false); 134 PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F32, false); 135 PS_ASSERT_VECTOR_NON_NULL(y, false); 136 PS_ASSERT_VECTOR_TYPE(y, PS_TYPE_F32, false); 137 PS_ASSERT_VECTORS_SIZE_EQUAL(x, y, false); 138 PS_ASSERT_VECTOR_NON_NULL(f, false); 139 PS_ASSERT_VECTOR_TYPE(f, PS_TYPE_F32, false); 140 PS_ASSERT_VECTORS_SIZE_EQUAL(x, f, false); 141 if (df) { 142 PS_ASSERT_VECTOR_NON_NULL(df, false); 143 PS_ASSERT_VECTOR_TYPE(df, PS_TYPE_F32, false); 144 PS_ASSERT_VECTORS_SIZE_EQUAL(x, df, false); 145 } 128 146 129 147 psImage *mask = psImageAlloc (map->map->numCols, map->map->numRows, PS_TYPE_MASK); … … 260 278 const psVector *f, const psVector *df, float badFrac) 261 279 { 262 // XXX Asserts 280 PS_ASSERT_IMAGE_MAP_NON_NULL(map, false); 281 PS_ASSERT_IMAGE_MAP_STATS(map, false); 282 PS_ASSERT_VECTOR_NON_NULL(x, false); 283 PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F32, false); 284 PS_ASSERT_VECTOR_NON_NULL(y, false); 285 PS_ASSERT_VECTOR_TYPE(y, PS_TYPE_F32, false); 286 PS_ASSERT_VECTORS_SIZE_EQUAL(x, y, false); 287 PS_ASSERT_VECTOR_NON_NULL(f, false); 288 PS_ASSERT_VECTOR_TYPE(f, PS_TYPE_F32, false); 289 PS_ASSERT_VECTORS_SIZE_EQUAL(x, f, false); 290 if (df) { 291 PS_ASSERT_VECTOR_NON_NULL(df, false); 292 PS_ASSERT_VECTOR_TYPE(df, PS_TYPE_F32, false); 293 PS_ASSERT_VECTORS_SIZE_EQUAL(x, df, false); 294 } 263 295 264 296 int nXruff, nYruff; … … 304 336 305 337 // x,y are in fractional pixel coords of the fine image (pixel center: 0.5) 306 double psImageMapEval(const psImageMap *map, float x, float y) { 307 308 double result; 309 310 result = psImageUnbinPixel_V2(x, y, map->map, map->binning); 311 312 return result; 313 } 314 315 psVector *psImageMapEvalVector(const psImageMap *map, const psVector *x, const psVector *y) { 316 317 assert (x); 318 assert (y); 319 assert (x->n == y->n); 320 assert (map); 321 322 psVector *result = psVectorAlloc (x->n, PS_TYPE_F32); 338 double psImageMapEval(const psImageMap *map, float x, float y) 339 { 340 // This may be called in a type loop, so no assertions 341 return psImageUnbinPixel_V2(x, y, map->map, map->binning); 342 } 343 344 psVector *psImageMapEvalVector(const psImageMap *map, const psVector *x, const psVector *y) 345 { 346 PS_ASSERT_IMAGE_MAP_NON_NULL(map, NULL); 347 PS_ASSERT_VECTOR_NON_NULL(x, NULL); 348 PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F32, NULL); 349 PS_ASSERT_VECTOR_NON_NULL(y, NULL); 350 PS_ASSERT_VECTOR_TYPE(y, PS_TYPE_F32, NULL); 351 PS_ASSERT_VECTORS_SIZE_EQUAL(x, y, NULL); 352 353 psVector *result = psVectorAlloc(x->n, PS_TYPE_F32); // Results to return 323 354 324 355 for (int i = 0; i < x->n; i++) { -
trunk/psLib/src/imageops/psImageMap.h
r15841 r19960 7 7 * @author Eugene Magnier, IfA 8 8 * 9 * @version $Revision: 1. 7$ $Name: not supported by cvs2svn $10 * @date $Date: 200 7-12-15 01:20:03$9 * @version $Revision: 1.8 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2008-10-07 22:23:06 $ 11 11 * 12 12 * Copyright 2007 Institute for Astronomy, University of Hawaii … … 41 41 } psImageMap; 42 42 43 // Assertion for psImageMap 44 #define PS_ASSERT_IMAGE_MAP_NON_NULL(MAP, RVAL) \ 45 if (!(MAP) || !(MAP)->binning || !(MAP)->map || !(MAP)->error) { \ 46 psError(PS_ERR_UNEXPECTED_NULL, true, "Image map %s or its contents is NULL.", #MAP); \ 47 return RVAL; \ 48 } \ 49 PS_ASSERT_IMAGE_NON_NULL((MAP)->map, RVAL); \ 50 PS_ASSERT_IMAGE_NON_NULL((MAP)->error, RVAL); \ 51 PS_ASSERT_IMAGE_TYPE((MAP)->map, PS_TYPE_F32, RVAL); \ 52 PS_ASSERT_IMAGE_TYPE((MAP)->error, PS_TYPE_F32, RVAL); \ 53 PS_ASSERT_IMAGES_SIZE_EQUAL((MAP)->map, (MAP)->error, RVAL); 54 55 // Assertion for statistics in psImageMap 56 #define PS_ASSERT_IMAGE_MAP_STATS(MAP, RVAL) \ 57 if (!(MAP)->stats) { \ 58 psError(PS_ERR_UNEXPECTED_NULL, true, "Image map %s statistics is unset.", #MAP); \ 59 return RVAL; \ 60 } 61 62 43 63 psImageMap *psImageMapAlloc(const psImage *field, psImageBinning *binning, psStats *stats) PS_ATTR_MALLOC; 44 64 bool psMemCheckImageMap(psPtr ptr);
Note:
See TracChangeset
for help on using the changeset viewer.
