IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 4, 2007, 12:54:56 PM (19 years ago)
Author:
Paul Price
Message:

Updating following API change to psImagePixelInterpolate

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pswarp/src/pswarpTransformReadout_Opt.c

    r12528 r12744  
    11# include "pswarp.h"
    2 psImageInterpolateMode psImageInterpolateModeFromString (char *name);
    32
    43// NOTE: in this function, the coordinates are transformed from the OUTPUT to the INPUT
     
    1110    psImageInterpolateMode interpolationMode = PS_INTERPOLATE_NONE;
    1211
    13     // XXX this implementation currently ignores the use of the region 
     12    // XXX this implementation currently ignores the use of the region
    1413    psImage *region = NULL;
    1514
     
    1918    psMetadata *recipe  = psMetadataLookupPtr (NULL, config->recipes, PSWARP_RECIPE);
    2019    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;
    2322    }
    24    
     23
    2524    int nGridX = psMetadataLookupS32 (&status, recipe, "GRID.NX");
    2625    if (!status) nGridX = 128;
     
    3029    char *name = psMetadataLookupStr (&status, recipe, "INTERPOLATION.MODE");
    3130    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");
    3433    } 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        }
    4039    }
    4140
    42     psPlane *inPix = psPlaneAlloc();    // Coordinates on the input detector
     41    psPlane *inPix = psPlaneAlloc();    // Coordinates on the input detector
    4342    psImage *inImage = input->image;
    4443    psF32 **outData = output->image->data.F32;
     
    6564    psLogMsg ("pswarp", 3, "maximum error using this grid sampling: %f\n", maxError);
    6665
    67     pswarpMapGridSetGrid (grid, minX, minY, &gridX, &gridY); 
     66    pswarpMapGridSetGrid (grid, minX, minY, &gridX, &gridY);
    6867    nextGridY = pswarpMapGridNextGrid_Y (grid, gridY);
    6968    map = grid->maps[gridX][gridY];
     
    7776    nextGridXo = pswarpMapGridNextGrid_X (grid, gridX);
    7877
     78    psImageInterpolateOptions *interp = psImageInterpolateOptionsAlloc(PS_INTERPOLATE_BILINEAR, inImage,
     79                                                                       NULL, NULL, 0, NAN, NAN, 0, 0, 0.0);
     80
    7981    // Iterate over the output image pixels (parent frame)
    8082    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        }
    8688
    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            }
    9698
    97             // Only transform those pixels requested
    98             if (region && region->data.U8[y][x]) continue;
     99            // Only transform those pixels requested
     100            if (region && region->data.U8[y][x]) continue;
    99101
    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);
    103105
    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;
    108110
    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        }
    114124    }
    115125
     126    psFree(interp);
    116127    psFree (inPix);
    117128    psFree (grid);
Note: See TracChangeset for help on using the changeset viewer.