Changeset 12744 for trunk/pswarp/src/pswarpTransformReadout_Opt.c
- Timestamp:
- Apr 4, 2007, 12:54:56 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/pswarp/src/pswarpTransformReadout_Opt.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pswarp/src/pswarpTransformReadout_Opt.c
r12528 r12744 1 1 # include "pswarp.h" 2 psImageInterpolateMode psImageInterpolateModeFromString (char *name);3 2 4 3 // NOTE: in this function, the coordinates are transformed from the OUTPUT to the INPUT … … 11 10 psImageInterpolateMode interpolationMode = PS_INTERPOLATE_NONE; 12 11 13 // XXX this implementation currently ignores the use of the region 12 // XXX this implementation currently ignores the use of the region 14 13 psImage *region = NULL; 15 14 … … 19 18 psMetadata *recipe = psMetadataLookupPtr (NULL, config->recipes, PSWARP_RECIPE); 20 19 if (!recipe) { 21 psError(PSWARP_ERR_CONFIG, true, "Can't find PSWARP recipe!\n");22 return false;20 psError(PSWARP_ERR_CONFIG, true, "Can't find PSWARP recipe!\n"); 21 return false; 23 22 } 24 23 25 24 int nGridX = psMetadataLookupS32 (&status, recipe, "GRID.NX"); 26 25 if (!status) nGridX = 128; … … 30 29 char *name = psMetadataLookupStr (&status, recipe, "INTERPOLATION.MODE"); 31 30 if (!name) { 32 interpolationMode = PS_INTERPOLATE_BILINEAR;33 psLogMsg ("pswarp", 3, "defaulting to bilinear interpolation\n");31 interpolationMode = PS_INTERPOLATE_BILINEAR; 32 psLogMsg ("pswarp", 3, "defaulting to bilinear interpolation\n"); 34 33 } else { 35 interpolationMode = psImageInterpolateModeFromString (name);36 if (interpolationMode == PS_INTERPOLATE_NONE) {37 interpolationMode = PS_INTERPOLATE_BILINEAR;38 psLogMsg ("pswarp", 3, "unknown interpolation mode %s, defaulting to bilinear interpolation\n", name);39 }34 interpolationMode = psImageInterpolateModeFromString (name); 35 if (interpolationMode == PS_INTERPOLATE_NONE) { 36 interpolationMode = PS_INTERPOLATE_BILINEAR; 37 psLogMsg ("pswarp", 3, "unknown interpolation mode %s, defaulting to bilinear interpolation\n", name); 38 } 40 39 } 41 40 42 psPlane *inPix = psPlaneAlloc(); // Coordinates on the input detector41 psPlane *inPix = psPlaneAlloc(); // Coordinates on the input detector 43 42 psImage *inImage = input->image; 44 43 psF32 **outData = output->image->data.F32; … … 65 64 psLogMsg ("pswarp", 3, "maximum error using this grid sampling: %f\n", maxError); 66 65 67 pswarpMapGridSetGrid (grid, minX, minY, &gridX, &gridY); 66 pswarpMapGridSetGrid (grid, minX, minY, &gridX, &gridY); 68 67 nextGridY = pswarpMapGridNextGrid_Y (grid, gridY); 69 68 map = grid->maps[gridX][gridY]; … … 77 76 nextGridXo = pswarpMapGridNextGrid_X (grid, gridX); 78 77 78 psImageInterpolateOptions *interp = psImageInterpolateOptionsAlloc(PS_INTERPOLATE_BILINEAR, inImage, 79 NULL, NULL, 0, NAN, NAN, 0, 0, 0.0); 80 79 81 // Iterate over the output image pixels (parent frame) 80 82 for (int y = minY; y < maxY; y++) { 81 if (y >= nextGridY) {82 gridY ++;83 nextGridY = pswarpMapGridNextGrid_Y (grid, gridY);84 map = grid->maps[gridX][gridY];85 }83 if (y >= nextGridY) { 84 gridY ++; 85 nextGridY = pswarpMapGridNextGrid_Y (grid, gridY); 86 map = grid->maps[gridX][gridY]; 87 } 86 88 87 gridX = gridXo;88 nextGridX = nextGridXo;89 map = grid->maps[gridX][gridY];90 for (int x = minX; x < maxX; x++) {91 if (x >= nextGridX) {92 gridX ++;93 nextGridX = pswarpMapGridNextGrid_X (grid, gridX);94 map = grid->maps[gridX][gridY];95 }89 gridX = gridXo; 90 nextGridX = nextGridXo; 91 map = grid->maps[gridX][gridY]; 92 for (int x = minX; x < maxX; x++) { 93 if (x >= nextGridX) { 94 gridX ++; 95 nextGridX = pswarpMapGridNextGrid_X (grid, gridX); 96 map = grid->maps[gridX][gridY]; 97 } 96 98 97 // Only transform those pixels requested98 if (region && region->data.U8[y][x]) continue;99 // Only transform those pixels requested 100 if (region && region->data.U8[y][x]) continue; 99 101 100 // pswarpMapApply converts the output coordinate (x,y) to the input coordinate.101 // both are in the parent frames of the input and output images.102 pswarpMapApply (&inPix->x, &inPix->y, map, x + 0.5, y + 0.5);102 // pswarpMapApply converts the output coordinate (x,y) to the input coordinate. 103 // both are in the parent frames of the input and output images. 104 pswarpMapApply (&inPix->x, &inPix->y, map, x + 0.5, y + 0.5); 103 105 104 if (inPix->x - inCol0 < 0) continue;105 if (inPix->x - inCol0 >= inImage->numCols) continue;106 if (inPix->y - inRow0 < 0) continue;107 if (inPix->y - inRow0 >= inImage->numRows) continue;106 if (inPix->x - inCol0 < 0) continue; 107 if (inPix->x - inCol0 >= inImage->numCols) continue; 108 if (inPix->y - inRow0 < 0) continue; 109 if (inPix->y - inRow0 >= inImage->numRows) continue; 108 110 109 // XXX include mask 110 // XXX apply scale and offset? 111 // psImagePixelInterpolate determines the value at pixel coordinate (x,y) in child coordinates 112 outData[y-outRow0][x-outCol0] = (psF32)psImagePixelInterpolate(inImage, inPix->x - inCol0, inPix->y - inRow0, NULL, 1, NAN, interpolationMode); 113 } 111 // XXX include mask 112 // XXX apply scale and offset? 113 // psImagePixelInterpolate determines the value at pixel coordinate (x,y) in child coordinates 114 double value; 115 if (!psImageInterpolate(&value, NULL, NULL, inPix->x - inCol0, inPix->y - inRow0, interp)) { 116 psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image."); 117 psFree(interp); 118 psFree (inPix); 119 psFree (grid); 120 return false; 121 } 122 outData[y-outRow0][x-outCol0] = value; 123 } 114 124 } 115 125 126 psFree(interp); 116 127 psFree (inPix); 117 128 psFree (grid);
Note:
See TracChangeset
for help on using the changeset viewer.
