/* * This program 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 2 of the License, or * (at your option) any later version. * * This program 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA */ #ifndef __INTERP__ #define __INTERP__ /* fractional input interpolation interp = nearest, bi_linear, bi_cubic typical use: type **in_rows = (type**)in->get_rows(); type **out_rows = (type**)out->get_rows(); int ow = out->get_w(), oh = out->get_h(); type offset[4] = { 0, chroma, chroma, 0 }; type bkgrnd[4] = { 0, chroma, chroma, 0 }; INTERP_SETUP(in_rows, max, 0,0, width,height); for( int oy=0; oy mx ? mx : v; } static inline float interp_linear(float dx, float p1, float p2) { return p1 * (1-dx) + p2 * dx; } static inline float interp_cubic(float dx, float p0, float p1, float p2, float p3) { /* Catmull-Rom - not bad */ return ((( (- p0 + 3*p1 - 3*p2 + p3) * dx + ( 2*p0 - 5*p1 + 4*p2 - p3 ) ) * dx + ( - p0 + p2 ) ) * dx + (p1 + p1)) / 2; } #define INTERP_SETUP(rows, max, x_in_min,y_in_min, x_in_max,y_in_max) \ void **interp_rows = (void **)(rows); float in_max = (max); \ int in_min_x = (x_in_min), in_max_x = (x_in_max); \ int in_min_y = (y_in_min), in_max_y = (y_in_max) #define nearest_SETUP(typ, components, tx, ty) \ int itx = (tx), ity = (ty), in_comps = (components); \ int c0 = itx+0, r0 = ity+0; \ typ *r0p = r0>=in_min_y && r0=in_min_x && c0=in_min_y && r0=in_min_y && r1=in_min_x && c0=in_min_x && c1=in_min_y && rp=in_min_y && r0=in_min_y && r1=in_min_y && r2=in_min_x && cp=in_min_x && c0=in_min_x && c1=in_min_x && c2