/* * This file is part of RawTherapee. * * Copyright (c) 2004-2010 Gabor Horvath * * RawTherapee is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * RawTherapee is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with RawTherapee. If not, see . */ #include #include #include #include "rt_math.h" #include "utils.h" #include "rt_math.h" using namespace std; namespace rtengine { void bilinearInterp (const unsigned char* src, int sw, int sh, unsigned char* dst, int dw, int dh) { int ix = 0; for (int i=0; i=sh) sy = sh-1; double dy = (double)i*sh/dh - sy; int ny = sy+1; if (ny>=sh) ny = sy; int or1 = 3*sw*sy; int or2 = 3*sw*ny; for (int j=0; j=sw) sx = sw; double dx = (double)j*sw/dw - sx; int nx = sx+1; if (nx>=sw) nx = sx; int ofs11 = or1 + 3*sx; int ofs12 = or1 + 3*nx; int ofs21 = or2 + 3*sx; int ofs22 = or2 + 3*nx; unsigned int val = src[ofs11]*(1-dx)*(1-dy) + src[ofs12]*dx*(1-dy) + src[ofs21]*(1-dx)*dy + src[ofs22]*dx*dy; dst[ix++] = val; ofs11++; ofs12++; ofs21++; ofs22++; val = src[ofs11]*(1-dx)*(1-dy) + src[ofs12]*dx*(1-dy) + src[ofs21]*(1-dx)*dy + src[ofs22]*dx*dy; dst[ix++] = val; ofs11++; ofs12++; ofs21++; ofs22++; val = src[ofs11]*(1-dx)*(1-dy) + src[ofs12]*dx*(1-dy) + src[ofs21]*(1-dx)*dy + src[ofs22]*dx*dy; dst[ix++] = val; } } } void nearestInterp (const unsigned char* src, int sw, int sh, unsigned char* dst, int dw, int dh) { int ix = 0; for (int i=0; i