Changeset 19395 for trunk/pswarp/src/pswarpTransformTile.c
- Timestamp:
- Sep 5, 2008, 12:37:59 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/pswarp/src/pswarpTransformTile.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pswarp/src/pswarpTransformTile.c
r19149 r19395 1 # include "pswarp.h"1 #include "pswarp.h" 2 2 3 void pswarpTransformTileArgsFree (pswarpTransformTileArgs *args) { 4 if (!args) return; 3 static void transformTileArgsFree(pswarpTransformTileArgs *args) 4 { 5 psFree(args->input); 6 psFree(args->output); 7 psFree(args->grid); 8 psFree(args->interp); 9 psFree(args->region); 5 10 return; 6 11 } 7 12 8 pswarpTransformTileArgs *pswarpTransformTileArgsAlloc() {9 10 pswarpTransformTileArgs *args = (pswarpTransformTileArgs *)psAlloc(sizeof(pswarpTransformTileArgs));11 psMemSetDeallocator(args, (psFreeFunc) pswarpTransformTileArgsFree);13 pswarpTransformTileArgs *pswarpTransformTileArgsAlloc() 14 { 15 pswarpTransformTileArgs *args = psAlloc(sizeof(pswarpTransformTileArgs)); 16 psMemSetDeallocator(args, (psFreeFunc)transformTileArgsFree); 12 17 13 18 args->input = NULL; … … 21 26 22 27 args->goodPixels = 0; 28 args->xMin = PS_MAX_S32; 29 args->xMax = PS_MIN_S32; 30 args->yMin = PS_MAX_S32; 31 args->yMax = PS_MIN_S32; 23 32 24 33 return args; 25 34 } 26 35 27 bool pswarpTransformTile (pswarpTransformTileArgs *args) { 36 bool pswarpTransformTile(pswarpTransformTileArgs *args) 37 { 38 psImage *inImage = args->input->image; // Input image 39 psImage *outImage = args->output->image; // Output image 28 40 29 // int inCol0 = args->input->image->col0; 30 // int inRow0 = args->input->image->row0; 31 int inNcol = args->input->image->numCols; 32 int inNrow = args->input->image->numRows; 41 int inNumCols = inImage->numCols, inNumRows = inImage->numRows; // Size of input image 42 int outNumCols = outImage->numCols, outNumRows = outImage->numRows; // Size of output image 43 int outCol0 = outImage->col0, outRow0 = outImage->row0; // Offset of output image 33 44 34 int outCol0 = args->output->image->col0; 35 int outRow0 = args->output->image->row0; 36 int outNcol = args->output->image->numCols; 37 int outNrow = args->output->image->numRows; 45 psPlane minPt, maxPt; // Minimum and maximum points for this tile 46 pswarpMapGridCoordRange(args->grid, args->gridX, args->gridY, &minPt, &maxPt); 38 47 39 // get the coordinate range for this grid tile 40 psPlane minPt, maxPt; 41 pswarpMapGridCoordRange (args->grid, args->gridX, args->gridY, &minPt, &maxPt); 42 43 psF32 **outImageData = (args->output->image) ? args->output->image->data.F32 : NULL; 48 // Dereference images for convenience 49 psF32 **outImageData = args->output->image->data.F32; 44 50 psF32 **outVarData = (args->output->weight) ? args->output->weight->data.F32 : NULL; 45 51 psMaskType **outMaskData = (args->output->mask) ? args->output->mask->data.PS_TYPE_MASK_DATA : NULL; 46 52 psMaskType **inMaskData = (args->input->mask) ? args->input->mask->data.PS_TYPE_MASK_DATA : NULL; 47 53 48 pswarpMap *map = args->grid->maps[args->gridX][args->gridY]; 49 50 psImage *region = args->region; 51 52 double xInRaw, yInRaw; 53 54 // output values for this pixel 55 double imageValue; 56 double varValue; 57 psMaskType maskValue; 54 pswarpMap *map = args->grid->maps[args->gridX][args->gridY]; // Map for this tile 55 psImage *region = args->region; // Region to transform 58 56 59 57 // Bounds for iteration 60 58 int xMin = PS_MAX(minPt.x, 0); 61 int xMax = PS_MIN(maxPt.x, outN col);59 int xMax = PS_MIN(maxPt.x, outNumCols); 62 60 int yMin = PS_MAX(minPt.y, 0); 63 int yMax = PS_MIN(maxPt.y, outNrow); 64 61 int yMax = PS_MIN(maxPt.y, outNumRows); 65 62 66 63 // Iterate over the output image pixels (parent frame) … … 70 67 71 68 // Only transform those pixels requested 72 if (region && region->data.U8[y][x]) continue; 69 if (region && region->data.U8[y][x]) { 70 continue; 71 } 73 72 74 73 // pswarpMapApply converts the output coordinate (x,y) to the input coordinate. 75 74 // both are in the parent frames of the input and output images. 76 pswarpMapApply (&xInRaw, &yInRaw, map, x + 0.5, y + 0.5); 77 78 double xIn = xInRaw - outCol0; // Position on input image 79 double yIn = yInRaw - outRow0; // Position on input image 80 81 if (xIn < 0) continue; 82 if (yIn >= inNcol) continue; 83 if (yIn < 0) continue; 84 if (yIn >= inNrow) continue; 85 86 goodPixels++; 75 double xInRaw, yInRaw; // Input raw pixel coordinates 76 pswarpMapApply(&xInRaw, &yInRaw, map, x + 0.5, y + 0.5); 77 double xIn = xInRaw - outCol0, yIn = yInRaw - outRow0; // Position on input image 78 if (xIn < 0 || xIn >= inNumCols || yIn < 0 || yIn >= inNumRows) { 79 continue; 80 } 87 81 88 82 // psImagePixelInterpolate determines the value at pixel coordinate (x,y) in child coordinates 89 maskValue = inMaskData ? inMaskData[(int)yIn][(int)xIn] : 0; 83 double imageValue, varValue; // Value of image and variance map 84 psMaskType maskValue = inMaskData ? inMaskData[(int)yIn][(int)xIn] : 0; // Value of mask 90 85 if (!psImageInterpolate(&imageValue, &varValue, &maskValue, xIn, yIn, args->interp)) { 91 86 psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image."); … … 93 88 } 94 89 95 int xOut = x - outCol0; // Position on output image 96 int yOut = y - outRow0; // Position on output image 90 int xOut = x - outCol0, yOut = y - outRow0; // Position on output image 97 91 98 // not all images need be transformed99 92 if (outImageData) { 100 93 outImageData[yOut][xOut] = imageValue; … … 106 99 outMaskData[yOut][xOut] = maskValue; 107 100 } 101 102 goodPixels++; 108 103 } 109 104 } 105 110 106 args->goodPixels = goodPixels; 107 args->xMin = xMin; 108 args->xMax = xMax; 109 args->yMin = yMin; 110 args->yMax = yMax; 111 111 112 return true; 112 113 }
Note:
See TracChangeset
for help on using the changeset viewer.
