4 * Copyright (c) 2008 Lenny <leonardo.masoni@gmail.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
24 rs_ctx *rs_init(int nc, int nr) {
26 rs_ctx *rs = (rs_ctx *)malloc(sizeof(rs_ctx));
28 rs->tf = (unsigned char *)malloc(nc * nr * 3 * sizeof(unsigned char));
36 void rs_resample(int* lanc_kernels,rs_ctx *rs, unsigned char *f, vc *p) {
40 for (y = 0; y < rs->nr; y ++) {
43 int xd = floor(p[y].x);
45 int *lk = select_lanc_kernel(lanc_kernels,p[y].x);
47 for (x = 0; x < rs->nc; x ++) {
49 int pd = (yp + x) * 3;
52 for (c = 0; c < 3; c ++)
55 for (i = -3; i < 5; i ++) {
57 int ps = (yp + clamp(x + xd + i, 0, rs->nc - 1)) * 3;
59 for (c = 0; c < 3; c ++)
60 a[c] += f[ps + c] * lk[i + 3];
63 for (c = 0; c < 3; c ++)
64 rs->tf[pd + c] = clamp(a[c] / 1024, 0, 255);
68 for (y = 0; y < rs->nr; y ++) {
71 int yd = floor(p[y].y);
73 int *lk = select_lanc_kernel(lanc_kernels,p[y].y);
75 for (x = 0; x < rs->nc; x ++) {
77 int pd = (yp + x) * 3;
80 for (c = 0; c < 3; c ++)
83 for (i = -3; i < 5; i ++) {
85 int ps = (clamp(y + yd + i, 0, rs->nr - 1) * rs->nc + x) * 3;
87 for (c = 0; c < 3; c ++)
88 a[c] += rs->tf[ps + c] * lk[i + 3];
91 for (c = 0; c < 3; c ++)
92 f[pd + c] = clamp(a[c] / 1024, 0, 255);
97 void rs_free(rs_ctx *rs) {