Home | History | Annotate | Download | only in mosaic
      1 /*
      2  * Copyright (C) 2011 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 ///////////////////////////////////////////////////////////
     18 // Interp.h
     19 // $Id: Interp.h,v 1.2 2011/06/17 13:35:48 mbansal Exp $
     20 
     21 #ifndef INTERP_H
     22 #define INTERP_H
     23 
     24 #include "Pyramid.h"
     25 
     26 #define CTAPS 40
     27 static double ciTable[81] = {
     28         1, 0.998461, 0.993938, 0.98657, 0.9765,
     29         0.963867, 0.948813, 0.931477, 0.912, 0.890523,
     30         0.867188, 0.842133, 0.8155, 0.78743, 0.758062,
     31         0.727539, 0.696, 0.663586, 0.630437, 0.596695,
     32         0.5625, 0.527992, 0.493312, 0.458602, 0.424,
     33         0.389648, 0.355687, 0.322258, 0.2895, 0.257555,
     34         0.226562, 0.196664, 0.168, 0.140711, 0.114937,
     35         0.0908203, 0.0685, 0.0481172, 0.0298125, 0.0137266,
     36         0, -0.0118828, -0.0225625, -0.0320859, -0.0405,
     37         -0.0478516, -0.0541875, -0.0595547, -0.064, -0.0675703,
     38         -0.0703125, -0.0722734, -0.0735, -0.0740391, -0.0739375,
     39         -0.0732422, -0.072, -0.0702578, -0.0680625, -0.0654609,
     40         -0.0625, -0.0592266, -0.0556875, -0.0519297, -0.048,
     41         -0.0439453, -0.0398125, -0.0356484, -0.0315, -0.0274141,
     42         -0.0234375, -0.0196172, -0.016, -0.0126328, -0.0095625,
     43         -0.00683594, -0.0045, -0.00260156, -0.0011875, -0.000304687, 0.0
     44 };
     45 
     46 inline double ciCalc(PyramidShort *img, int xi, int yi, double xfrac, double yfrac)
     47 {
     48   double tmpf[4];
     49 
     50   // Interpolate using 16 points
     51   ImageTypeShortBase *in = img->ptr[yi-1] + xi - 1;
     52   int off = (int)(xfrac * CTAPS);
     53 
     54   tmpf[0] = in[0] * ciTable[off + 40];
     55   tmpf[0] += in[1] * ciTable[off];
     56   tmpf[0] += in[2] * ciTable[40 - off];
     57   tmpf[0] += in[3] * ciTable[80 - off];
     58   in += img->pitch;
     59   tmpf[1] = in[0] * ciTable[off + 40];
     60   tmpf[1] += in[1] * ciTable[off];
     61   tmpf[1] += in[2] * ciTable[40 - off];
     62   tmpf[1] += in[3] * ciTable[80 - off];
     63   in += img->pitch;
     64   tmpf[2] = in[0] * ciTable[off + 40];
     65   tmpf[2] += in[1] * ciTable[off];
     66   tmpf[2] += in[2] * ciTable[40 - off];
     67   tmpf[2] += in[3] * ciTable[80 - off];
     68   in += img->pitch;
     69   tmpf[3] = in[0] * ciTable[off + 40];
     70   tmpf[3] += in[1] * ciTable[off];
     71   tmpf[3] += in[2] * ciTable[40 - off];
     72   tmpf[3] += in[3] * ciTable[80 - off];
     73 
     74   // this is the final interpolation
     75   off = (int)(yfrac * CTAPS);
     76   return (ciTable[off + 40] * tmpf[0] + ciTable[off] * tmpf[1] +
     77           ciTable[40 - off] * tmpf[2] + ciTable[80 - off] * tmpf[3]);
     78 }
     79 
     80 #endif
     81