3 * Copyright (C) 2010 Marko Cebokli http://lea.hamradio.si/~s57uuu
4 * This file is a part of the Frei0r plugin "c0rners"
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.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 /*******************************************************************
22 * The remapping functions use a map aray, which contains a pair
23 * of floating values fo each pixel of the output image. These
24 * represent the location in the input image, from where the value
25 * of the given output pixel should be interpolated.
26 * They are given in pixels of the input image.
27 * If the output image is wo pixels wide, then the x coordinate
28 * of the pixel in row r and column c is at 2*(r*wo+c) in the map
29 * array, and y at 2*(r*wo+c)+1
31 * The map array is usually computation intensive to generate, and
32 * he purpose of the map array is to allow fast remapping of
33 * several images (video) using the same map array.
34 ******************************************************************/
37 //compile: gcc -c -O2 -Wall -std=c99 -fPIC interp.c -o interp.o
39 // -std=c99 za rintf()
40 // -fPIC da lahko linkas v .so (za frei0r)
43 #include <stdio.h> /* za debug printoute */
47 //#define TEST_XY_LIMITS
49 //--------------------------------------------------------
50 //pointer to an interpolating function
51 typedef int (*interpp)(unsigned char*, int, int, float, float, float, unsigned char*);
53 //************************************
56 //--------------------------------------------------------
57 // vhs = vhodna slika velikosti wi x hi
58 // izs = izhodna slika velikosti wo x ho
59 // map = za vsak pixel izs pove, kje ga vzamemo is vhs
60 // bgc = background color
61 // interp = kazalec na interpolacijsko funkcijo
62 void remap(int wi, int hi, int wo, int ho, unsigned char *vhs, unsigned char *izs, float *map, unsigned char bgc, interpp interp)
73 interp(vhs,wi,hi,x,y,1.0,&izs[wo*i+j]);
75 izs[wo*i+j]=bgc; //background fill
80 //--------------------------------------------------------
81 //for four byte (int, 32 bit) values (packed RGB color)
83 // vhs = vhodna slika velikosti wi x hi
84 // izs = izhodna slika velikosti wo x ho
85 // map = za vsak pixel izs pove, kje ga vzamemo is vhs
86 // bgc = background color
87 // interp = kazalec na interpolacijsko funkcijo
88 void remap32(int wi, int hi, int wo, int ho, unsigned char *vhs, unsigned char *izs, float *map, uint32_t bgc, interpp interp)
99 interp(vhs,wi,hi,x,y,1.0,&izs[4*(wo*i+j)]);
100 else //background fill
103 izs[4*(wo*i+j)+1]=bgc>>8;
104 izs[4*(wo*i+j)+2]=bgc>>16;
105 izs[4*(wo*i+j)+3]=bgc>>24;
110 //**************************************
111 //HERE BEGIN THE INTERPOLATION FUNCTIONS
113 //------------------------------------------------------
114 //za debugging - z izpisovanjem
115 //interpolacija "najblizji sosed" (ni prava interpolacija)
116 //za byte (char) vrednosti
117 // *sl vhodni array (slika)
118 // w,h dimenzija slike je wxh
119 // x,y tocka, za katero izracuna interpolirano vrednost
121 // *v interpolirana vrednost
122 int interpNNpr_b(unsigned char *sl, int w, int h, float x, float y, float o, unsigned char *v)
124 //printf("u=%5.2f v=%5.2f ",x,y);
125 printf("u=%5.3f v=%5.3f ",x/(w-1),y/(h-1));
126 //printf("U=%2d V=%2d ",(int)rintf(x),(int)rintf(y));
128 #ifdef TEST_XY_LIMITS
129 if ((x<0)||(x>=(w-1))||(y<0)||(y>=(h-1))) return -1;
132 *v=sl[(int)rintf(x)+(int)rintf(y)*w];
136 //------------------------------------------------------
137 //interpolacija "najblizji sosed" (ni prava interpolacija)
138 //za byte (char) vrednosti
139 // *sl vhodni array (slika)
140 // w,h dimenzija slike je wxh
141 // x,y tocka, za katero izracuna interpolirano vrednost
143 // *v interpolirana vrednost
144 int interpNN_b(unsigned char *sl, int w, int h, float x, float y, float o, unsigned char *v)
146 #ifdef TEST_XY_LIMITS
147 if ((x<0)||(x>=(w-1))||(y<0)||(y>=(h-1))) return -1;
150 *v=sl[(int)rintf(x)+(int)rintf(y)*w];
154 //------------------------------------------------------
155 //interpolacija "najblizji sosed" (ni prava interpolacija)
156 //za byte (char) vrednosti v packed color 32 bitnem formatu
158 // *sl vhodni array (slika)
159 // w,h dimenzija slike je wxh
160 // x,y tocka, za katero izracuna interpolirano vrednost
162 // *v interpolirana vrednost
163 int interpNN_b32(unsigned char *sl, int w, int h, float x, float y, float o, unsigned char *v)
165 #ifdef TEST_XY_LIMITS
166 if ((x<0)||(x>=(w-1))||(y<0)||(y>=(h-1))) return -1;
168 v[3]= sl[(int)rintf(x)*4+(int)rintf(y)*4*w+3];
169 float alpha = (float) v[3] / 255.0 * o;
170 v[0]= v[0] * (1.0 - alpha) + sl[(int)rintf(x)*4+(int)rintf(y)*4*w] * alpha;
171 v[1]= v[1] * (1.0 - alpha) + sl[(int)rintf(x)*4+(int)rintf(y)*4*w+1] * alpha;
172 v[2]= v[2] * (1.0 - alpha) + sl[(int)rintf(x)*4+(int)rintf(y)*4*w+2] * alpha;
177 //------------------------------------------------------
178 //bilinearna interpolacija
179 //za byte (char) vrednosti
180 // *sl vhodni array (slika)
181 // w,h dimenzija slike je wxh
182 // x,y tocka, za katero izracuna interpolirano vrednost
184 // *v interpolirana vrednost
185 int interpBL_b(unsigned char *sl, int w, int h, float x, float y, float o, unsigned char *v)
190 #ifdef TEST_XY_LIMITS
191 if ((x<0)||(x>=(w-1))||(y<0)||(y>=(h-1))) return -1;
194 m=(int)floorf(x); n=(int)floorf(y);
195 k=n*w+m; l=(n+1)*w+m;
196 a=sl[k]+(sl[k+1]-sl[k])*(x-(float)m);
197 b=sl[l]+(sl[l+1]-sl[l])*(x-(float)m);
198 *v=a+(b-a)*(y-(float)n);
202 //------------------------------------------------------
203 //bilinearna interpolacija
204 //za byte (char) vrednosti v packed color 32 bitnem formatu
205 int interpBL_b32(unsigned char *sl, int w, int h, float x, float y, float o, unsigned char *v)
207 int m,n,k,l,n1,l1,k1;
210 #ifdef TEST_XY_LIMITS
211 if ((x<0)||(x>=(w-1))||(y<0)||(y>=(h-1))) return -1;
214 m=(int)floorf(x); n=(int)floorf(y);
215 k=n*w+m; l=(n+1)*w+m;
216 k1=4*(k+1); l1=4*(l+1); n1=4*((n+1)*w+m);
219 a=sl[k+3]+(sl[k1+3]-sl[k+3])*(x-(float)m);
220 b=sl[l+3]+(sl[l1+3]-sl[n1+3])*(x-(float)m);
221 v[3]=a+(b-a)*(y-(float)n);
222 float alpha = (float) v[3] / 255.0 * o;
224 a=sl[k]+(sl[k1]-sl[k])*(x-(float)m);
225 b=sl[l]+(sl[l1]-sl[n1])*(x-(float)m);
226 v[0]= v[0] * (1.0 - alpha) + (a+(b-a)*(y-(float)n)) * alpha;
228 a=sl[k+1]+(sl[k1+1]-sl[k+1])*(x-(float)m);
229 b=sl[l+1]+(sl[l1+1]-sl[n1+1])*(x-(float)m);
230 v[1]= v[1] * (1.0 - alpha) + (a+(b-a)*(y-(float)n)) * alpha;
232 a=sl[k+2]+(sl[k1+2]-sl[k+2])*(x-(float)m);
233 b=sl[l+2]+(sl[l1+2]-sl[n1+2])*(x-(float)m);
234 v[2]= v[2] * (1.0 - alpha) + (a+(b-a)*(y-(float)n)) * alpha;
239 //------------------------------------------------------
240 //bikubicna interpolacija "smooth"
241 //za byte (char) vrednosti
242 //kar Aitken-Neville formula iz Bronstajna
243 // *sl vhodni array (slika)
244 // w,h dimenzija slike je wxh
245 // x,y tocka, za katero izracuna interpolirano vrednost
247 // *v interpolirana vrednost
248 int interpBC_b(unsigned char *sl, int w, int h, float x, float y, float o, unsigned char *v)
252 float p[4],p1[4],p2[4],p3[4],p4[4];
254 #ifdef TEST_XY_LIMITS
255 if ((x<0)||(x>=(w-1))||(y<0)||(y>=(h-1))) return -1;
258 m=(int)ceilf(x)-2; if (m<0) m=0; if ((m+5)>w) m=w-4;
259 n=(int)ceilf(y)-2; if (n<0) n=0; if ((n+5)>h) n=h-4;
261 //njaprej po y (stiri stolpce)
274 p1[i]=p1[i]+k*(p1[i]-p1[i-1]);
275 p2[i]=p2[i]+k*(p2[i]-p2[i-1]);
276 p3[i]=p3[i]+k*(p3[i]-p3[i-1]);
277 p4[i]=p4[i]+k*(p4[i]-p4[i-1]);
281 p[0]=p1[3]; p[1]=p2[3]; p[2]=p3[3]; p[3]=p4[3];
284 p[i]=p[i]+(x-i-m)/j*(p[i]-p[i-1]);
286 if (p[3]<0.0) p[3]=0.0; //printf("p=%f ",p[3]);
287 if (p[3]>256.0) p[3]=255.0; //printf("p=%f ",p[3]);
294 //------------------------------------------------------
295 //bikubicna interpolacija "smooth"
296 //za byte (char) vrednosti v packed color 32 bitnem formatu
297 int interpBC_b32(unsigned char *sl, int w, int h, float x, float y, float o, unsigned char *v)
301 float p[4],p1[4],p2[4],p3[4],p4[4];
304 #ifdef TEST_XY_LIMITS
305 if ((x<0)||(x>=(w-1))||(y<0)||(y>=(h-1))) return -1;
308 m=(int)ceilf(x)-2; if (m<0) m=0; if ((m+5)>w) m=w-4;
309 n=(int)ceilf(y)-2; if (n<0) n=0; if ((n+5)>h) n=h-4;
314 //njaprej po y (stiri stolpce)
327 p1[i]=p1[i]+k*(p1[i]-p1[i-1]);
328 p2[i]=p2[i]+k*(p2[i]-p2[i-1]);
329 p3[i]=p3[i]+k*(p3[i]-p3[i-1]);
330 p4[i]=p4[i]+k*(p4[i]-p4[i-1]);
334 p[0]=p1[3]; p[1]=p2[3]; p[2]=p3[3]; p[3]=p4[3];
337 p[i]=p[i]+(x-i-m)/j*(p[i]-p[i-1]);
339 if (p[3]<0.0) p[3]=0.0;
340 if (p[3]>256.0) p[3]=255.0;
342 v[b]= v[b] * (1.0 - alpha) + p[3] * alpha;
343 if (b == 3) alpha = v[b] / 255.0 * o;
349 //------------------------------------------------------
350 //bikubicna interpolacija "sharp"
351 //za byte (char) vrednosti
352 //Helmut Dersch polinom
353 // *sl vhodni array (slika)
354 // w,h dimenzija slike je wxh
355 // x,y tocka, za katero izracuna interpolirano vrednost
357 // *v interpolirana vrednost
358 //!!! ODKOD SUM??? (ze po eni rotaciji v interp_test !!)
359 //!!! v defish tega suma ni???
360 int interpBC2_b(unsigned char *sl, int w, int h, float x, float y, float o, unsigned char *v)
363 float pp,p[4],wx[4],wy[4],xx;
365 #ifdef TEST_XY_LIMITS
366 if ((x<0)||(x>=(w-1))||(y<0)||(y>=(h-1))) return -1;
369 m=(int)ceilf(x)-2; if (m<0) m=0; if ((m+5)>w) m=w-4;
370 n=(int)ceilf(y)-2; if (n<0) n=0; if ((n+5)>h) n=h-4;
373 //najprej po y (stiri stolpce)
374 xx=y-n; wy[0]=(-0.75*(xx-5.0)*xx-6.0)*xx+3.0;
375 xx=xx-1.0; wy[1]=(1.25*xx-2.25)*xx*xx+1.0;
376 xx=1.0-xx; wy[2]=(1.25*xx-2.25)*xx*xx+1.0;
377 xx=xx+1.0; wy[3]=(-0.75*(xx-5.0)*xx-6.0)*xx+3.0;
379 xx=x-m; wx[0]=(-0.75*(xx-5.0)*xx-6.0)*xx+3.0;
380 xx=xx-1.0; wx[1]=(1.25*xx-2.25)*xx*xx+1.0;
381 xx=1.0-xx; wx[2]=(1.25*xx-2.25)*xx*xx+1.0;
382 xx=xx+1.0; wx[3]=(-0.75*(xx-5.0)*xx-6.0)*xx+3.0;
389 p[i]=wy[0]*sl[l]; l+=w;
390 p[i]+=wy[1]*sl[l]; l+=w;
391 p[i]+=wy[2]*sl[l]; l+=w;
401 if (pp>256.0) pp=255.0;
407 //------------------------------------------------------
408 //bikubicna interpolacija "sharp"
409 //za byte (char) vrednosti v packed color 32 bitnem formatu
410 //!!! ODKOD SUM??? (ze po eni rotaciji v interp_test !!)
411 //!!! v defish tega suma ni???
412 int interpBC2_b32(unsigned char *sl, int w, int h, float x, float y, float o, unsigned char *v)
415 float pp,p[4],wx[4],wy[4],xx;
417 #ifdef TEST_XY_LIMITS
418 if ((x<0)||(x>=(w-1))||(y<0)||(y>=(h-1))) return -1;
421 m=(int)ceilf(x)-2; if (m<0) m=0; if ((m+5)>w) m=w-4;
422 n=(int)ceilf(y)-2; if (n<0) n=0; if ((n+5)>h) n=h-4;
424 //najprej po y (stiri stolpce)
425 xx=y-n; wy[0]=(-0.75*(xx-5.0)*xx-6.0)*xx+3.0;
426 xx=xx-1.0; wy[1]=(1.25*xx-2.25)*xx*xx+1.0;
427 xx=1.0-xx; wy[2]=(1.25*xx-2.25)*xx*xx+1.0;
428 xx=xx+1.0; wy[3]=(-0.75*(xx-5.0)*xx-6.0)*xx+3.0;
430 xx=x-m; wx[0]=(-0.75*(xx-5.0)*xx-6.0)*xx+3.0;
431 xx=xx-1.0; wx[1]=(1.25*xx-2.25)*xx*xx+1.0;
432 xx=1.0-xx; wx[2]=(1.25*xx-2.25)*xx*xx+1.0;
433 xx=xx+1.0; wx[3]=(-0.75*(xx-5.0)*xx-6.0)*xx+3.0;
442 p[i]=wy[0]*sl[l]; l+=u;
443 p[i]+=wy[1]*sl[l]; l+=u;
444 p[i]+=wy[2]*sl[l]; l+=u;
455 if (pp>256.0) pp=255.0;
463 //------------------------------------------------------
464 //spline 4x4 interpolacija
465 //za byte (char) vrednosti
466 //Helmut Dersch polinom
467 // *sl vhodni array (slika)
468 // w,h dimenzija slike je wxh
469 // x,y tocka, za katero izracuna interpolirano vrednost
471 // *v interpolirana vrednost
472 int interpSP4_b(unsigned char *sl, int w, int h, float x, float y, float o, unsigned char *v)
475 float pp,p[4],wx[4],wy[4],xx;
477 #ifdef TEST_XY_LIMITS
478 if ((x<0)||(x>=(w-1))||(y<0)||(y>=(h-1))) return -1;
481 m=(int)ceilf(x)-2; if (m<0) m=0; if ((m+5)>w) m=w-4;
482 n=(int)ceilf(y)-2; if (n<0) n=0; if ((n+5)>h) n=h-4;
484 //najprej po y (stiri stolpce)
485 xx=y-n; wy[0]=((-0.333333*(xx-1.0)+0.8)*(xx-1.0)-0.466667)*(xx-1.0);
486 xx=xx-1.0; wy[1]=((xx-1.8)*xx-0.2)*xx+1.0;
487 xx=1.0-xx; wy[2]=((xx-1.8)*xx-0.2)*xx+1.0;
488 xx=xx+1.0; wy[3]=((-0.333333*(xx-1.0)+0.8)*(xx-1.0)-0.466667)*(xx-1.0);
490 xx=x-m; wx[0]=((-0.333333*(xx-1.0)+0.8)*(xx-1.0)-0.466667)*(xx-1.0);
491 xx=xx-1.0; wx[1]=((xx-1.8)*xx-0.2)*xx+1.0;
492 xx=1.0-xx; wx[2]=((xx-1.8)*xx-0.2)*xx+1.0;
493 xx=xx+1.0; wx[3]=((-0.333333*(xx-1.0)+0.8)*(xx-1.0)-0.466667)*(xx-1.0);
500 p[i]=p[i]+wy[j]*sl[(j+n)*w+i+m];
509 if (pp>256.0) pp=255.0;
515 //------------------------------------------------------
516 //spline 4x4 interpolacija
517 //za byte (char) vrednosti v packed color 32 bitnem formatu
518 int interpSP4_b32(unsigned char *sl, int w, int h, float x, float y, float o, unsigned char *v)
521 float pp,p[4],wx[4],wy[4],xx;
523 #ifdef TEST_XY_LIMITS
524 if ((x<0)||(x>=(w-1))||(y<0)||(y>=(h-1))) return -1;
527 m=(int)ceilf(x)-2; if (m<0) m=0; if ((m+5)>w) m=w-4;
528 n=(int)ceilf(y)-2; if (n<0) n=0; if ((n+5)>h) n=h-4;
530 //najprej po y (stiri stolpce)
531 xx=y-n; wy[0]=((-0.333333*(xx-1.0)+0.8)*(xx-1.0)-0.466667)*(xx-1.0);
532 xx=xx-1.0; wy[1]=((xx-1.8)*xx-0.2)*xx+1.0;
533 xx=1.0-xx; wy[2]=((xx-1.8)*xx-0.2)*xx+1.0;
534 xx=xx+1.0; wy[3]=((-0.333333*(xx-1.0)+0.8)*(xx-1.0)-0.466667)*(xx-1.0);
536 xx=x-m; wx[0]=((-0.333333*(xx-1.0)+0.8)*(xx-1.0)-0.466667)*(xx-1.0);
537 xx=xx-1.0; wx[1]=((xx-1.8)*xx-0.2)*xx+1.0;
538 xx=1.0-xx; wx[2]=((xx-1.8)*xx-0.2)*xx+1.0;
539 xx=xx+1.0; wx[3]=((-0.333333*(xx-1.0)+0.8)*(xx-1.0)-0.466667)*(xx-1.0);
548 p[i]=p[i]+wy[j]*sl[4*((j+n)*w+i+m)+b];
557 if (pp>256.0) pp=255.0;
565 //------------------------------------------------------
566 //spline 6x6 interpolacija
567 //za byte (char) vrednosti
568 //Helmut Dersch polinom
569 // *sl vhodni array (slika)
570 // w,h dimenzija slike je wxh
571 // x,y tocka, za katero izracuna interpolirano vrednost
573 // *v interpolirana vrednost
574 //!!! PAZI, TOLE NE DELA CISTO PRAV ??? belina se siri
575 //!!! zaenkrat sem dodal fudge factor...
576 int interpSP6_b(unsigned char *sl, int w, int h, float x, float y, float o, unsigned char *v)
579 float pp,p[6],wx[6],wy[6],xx;
581 #ifdef TEST_XY_LIMITS
582 if ((x<0)||(x>=(w-1))||(y<0)||(y>=(h-1))) return -1;
585 m=(int)ceilf(x)-3; if (m<0) m=0; if ((m+7)>w) m=w-6;
586 n=(int)ceilf(y)-3; if (n<0) n=0; if ((n+7)>h) n=h-6;
588 //najprej po y (sest stolpcev)
590 wy[0]=((0.090909*(xx-2.0)-0.215311)*(xx-2.0)+0.124402)*(xx-2.0);
592 wy[1]=((-0.545455*(xx-1.0)+1.291866)*(xx-1.0)-0.746411)*(xx-1.0);
594 wy[2]=((1.181818*xx-2.167464)*xx+0.014354)*xx+1.0;
596 wy[3]=((1.181818*xx-2.167464)*xx+0.014354)*xx+1.0;
598 wy[4]=((-0.545455*(xx-1.0)+1.291866)*(xx-1.0)-0.746411)*(xx-1.0);
600 wy[5]=((0.090909*(xx-2.0)-0.215311)*(xx-2.0)+0.124402)*(xx-2.0);
603 wx[0]=((0.090909*(xx-2.0)-0.215311)*(xx-2.0)+0.124402)*(xx-2.0);
605 wx[1]=((-0.545455*(xx-1.0)+1.291866)*(xx-1.0)-0.746411)*(xx-1.0);
607 wx[2]=((1.181818*xx-2.167464)*xx+0.014354)*xx+1.0;
609 wx[3]=((1.181818*xx-2.167464)*xx+0.014354)*xx+1.0;
611 wx[4]=((-0.545455*(xx-1.0)+1.291866)*(xx-1.0)-0.746411)*(xx-1.0);
613 wx[5]=((0.090909*(xx-2.0)-0.215311)*(xx-2.0)+0.124402)*(xx-2.0);
621 p[i]=p[i]+wy[j]*sl[(j+n)*w+i+m];
629 pp=0.947*pp; //fudge factor...!!! cca 0.947...
631 if (pp>256.0) pp=255.0;
637 //------------------------------------------------------
638 //spline 6x6 interpolacija
639 //za byte (char) vrednosti v packed color 32 bitnem formatu
640 //!!! PAZI, TOLE NE DELA CISTO PRAV ??? belina se siri
641 //!!! zaenkrat sem dodal fudge factor...
642 int interpSP6_b32(unsigned char *sl, int w, int h, float x, float y, float o, unsigned char *v)
645 float pp,p[6],wx[6],wy[6],xx;
647 #ifdef TEST_XY_LIMITS
648 if ((x<0)||(x>=(w-1))||(y<0)||(y>=(h-1))) return -1;
651 m=(int)ceilf(x)-3; if (m<0) m=0; if ((m+7)>w) m=w-6;
652 n=(int)ceilf(y)-3; if (n<0) n=0; if ((n+7)>h) n=h-6;
654 //najprej po y (sest stolpcev)
656 wy[0]=((0.090909*(xx-2.0)-0.215311)*(xx-2.0)+0.124402)*(xx-2.0);
658 wy[1]=((-0.545455*(xx-1.0)+1.291866)*(xx-1.0)-0.746411)*(xx-1.0);
660 wy[2]=((1.181818*xx-2.167464)*xx+0.014354)*xx+1.0;
662 wy[3]=((1.181818*xx-2.167464)*xx+0.014354)*xx+1.0;
664 wy[4]=((-0.545455*(xx-1.0)+1.291866)*(xx-1.0)-0.746411)*(xx-1.0);
666 wy[5]=((0.090909*(xx-2.0)-0.215311)*(xx-2.0)+0.124402)*(xx-2.0);
669 wx[0]=((0.090909*(xx-2.0)-0.215311)*(xx-2.0)+0.124402)*(xx-2.0);
671 wx[1]=((-0.545455*(xx-1.0)+1.291866)*(xx-1.0)-0.746411)*(xx-1.0);
673 wx[2]=((1.181818*xx-2.167464)*xx+0.014354)*xx+1.0;
675 wx[3]=((1.181818*xx-2.167464)*xx+0.014354)*xx+1.0;
677 wx[4]=((-0.545455*(xx-1.0)+1.291866)*(xx-1.0)-0.746411)*(xx-1.0);
679 wx[5]=((0.090909*(xx-2.0)-0.215311)*(xx-2.0)+0.124402)*(xx-2.0);
689 p[i]=p[i]+wy[j]*sl[4*((j+n)*w+i+m)+b];
697 pp=0.947*pp; //fudge factor...!!! cca 0.947...
699 if (pp>256.0) pp=255.0;
707 //------------------------------------------------------
708 //truncated sinc "lanczos" 16x16 interpolacija
709 //za byte (char) vrednosti
710 // *sl vhodni array (slika)
711 // w,h dimenzija slike je wxh
712 // x,y tocka, za katero izracuna interpolirano vrednost
714 // *v interpolirana vrednost
715 int interpSC16_b(unsigned char *sl, int w, int h, float x, float y, float o, unsigned char *v)
718 float pp,p[16],wx[16],wy[16],xx,xxx,x1;
719 float PI=3.141592654;
721 #ifdef TEST_XY_LIMITS
722 if ((x<0)||(x>=(w-1))||(y<0)||(y>=(h-1))) return -1;
725 m=(int)ceilf(x)-8; if (m<0) m=0; if ((m+17)>w) m=w-16;
726 n=(int)ceilf(y)-8; if (n<0) n=0; if ((n+17)>h) n=h-16;
733 wy[7-i]=(sin(x1)/(x1))*(sin(x1*0.125)/(x1*0.125));
734 xxx=(float)(2*i+1)-xx;
736 wy[8+i]=(sin(x1)/(x1))*(sin(x1*0.125)/(x1*0.125));
744 wx[7-i]=(sin(x1)/(x1))*(sin(x1*0.125)/(x1*0.125));
745 xxx=(float)(2*i+1)-xx;
747 wx[8+i]=(sin(x1)/(x1))*(sin(x1*0.125)/(x1*0.125));
756 p[i]=p[i]+wy[j]*sl[(j+n)*w+i+m];
765 if (pp>256.0) pp=255.0;
771 //------------------------------------------------------
772 //truncated sinc "lanczos" 16x16 interpolacija
773 //za byte (char) vrednosti v packed color 32 bitnem formatu
774 int interpSC16_b32(unsigned char *sl, int w, int h, float x, float y, float o, unsigned char *v)
777 float pp,p[16],wx[16],wy[16],xx,xxx,x1;
778 float PI=3.141592654;
780 #ifdef TEST_XY_LIMITS
781 if ((x<0)||(x>=(w-1))||(y<0)||(y>=(h-1))) return -1;
784 m=(int)ceilf(x)-8; if (m<0) m=0; if ((m+17)>w) m=w-16;
785 n=(int)ceilf(y)-8; if (n<0) n=0; if ((n+17)>h) n=h-16;
792 wy[7-i]=(sin(x1)/(x1))*(sin(x1*0.125)/(x1*0.125));
793 xxx=(float)(2*i+1)-xx;
795 wy[8+i]=(sin(x1)/(x1))*(sin(x1*0.125)/(x1*0.125));
803 wx[7-i]=(sin(x1)/(x1))*(sin(x1*0.125)/(x1*0.125));
804 xxx=(float)(2*i+1)-xx;
806 wx[8+i]=(sin(x1)/(x1))*(sin(x1*0.125)/(x1*0.125));
817 p[i]=p[i]+wy[j]*sl[4*((j+n)*w+i+m)+b];
826 if (pp>256.0) pp=255.0;