Image Interpolation with Contour Stencils
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
nninterp.c
Go to the documentation of this file.
1 
16 #include <math.h>
17 #include "nninterp.h"
18 
19 
20 void NearestInterp(uint32_t *Output, int OutputWidth, int OutputHeight,
21  uint32_t *Input, int InputWidth, int InputHeight,
22  float ScaleFactor, int CenteredGrid)
23 {
24  const float Start = (CenteredGrid) ? (1/ScaleFactor - 1)/2 : 0;
25  int x, y, ix, iy;
26 
27 
28  for(y = 0; y < OutputHeight; y++, Output += OutputWidth)
29  {
30  iy = (int)floor(Start + y/ScaleFactor + 0.5);
31 
32  if(iy < 0)
33  iy = 0;
34  else if(iy >= InputHeight)
35  iy = InputHeight - 1;
36 
37  for(x = 0; x < OutputWidth; x++)
38  {
39  ix = (int)floor(Start + x/ScaleFactor + 0.5);
40 
41  if(ix < 0)
42  ix = 0;
43  else if(ix >= InputWidth)
44  ix = InputWidth - 1;
45 
46  Output[x] = Input[ix + InputWidth*iy];
47  }
48  }
49 }