Image Interpolation with Contour Stencils

nninterp.c

Go to the documentation of this file.
00001 
00016 #include <math.h>
00017 #include "nninterp.h"
00018 
00019 
00020 void NearestInterp(uint32_t *Output, int OutputWidth, int OutputHeight,
00021     uint32_t *Input, int InputWidth, int InputHeight, 
00022     float ScaleFactor, int CenteredGrid)
00023 {
00024     const float Start  = (CenteredGrid) ? (1/ScaleFactor - 1)/2 : 0;
00025     int x, y, ix, iy;
00026 
00027     
00028     for(y = 0; y < OutputHeight; y++, Output += OutputWidth)
00029     {
00030         iy = (int)floor(Start + y/ScaleFactor + 0.5);
00031         
00032         if(iy < 0)
00033             iy = 0;
00034         else if(iy >= InputHeight)
00035             iy = InputHeight - 1;
00036         
00037         for(x = 0; x < OutputWidth; x++)
00038         {
00039             ix = (int)floor(Start + x/ScaleFactor + 0.5);
00040             
00041             if(ix < 0)
00042                 ix = 0;
00043             else if(ix >= InputWidth)
00044                 ix = InputWidth - 1;
00045                         
00046             Output[x] = Input[ix + InputWidth*iy];                      
00047         }
00048     }
00049 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines