Debian Codegraph @

src/filter/defish0r/defish0r.c

raw symbols SCIP
1 /* defish0r.c
2
3 * Copyright (C) 2010 Marko Cebokli http://lea.hamradio.si/~s57uuu
4 * This file is a Frei0r plugin.
5 *
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.
10 *
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.
15 *
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.
19 */
20
21
22
23 //compile: gcc -Wall -std=c99 -c -fPIC defish0r.c -o defish0r.o
24
25 //link: gcc -lm -shared -o defish0r.so defish0r.o
26
27 //skaliranje za center=1 se ne dela!!!!
28
29 #include <stdlib.h>
30 #include <stdio.h>
31 #include <math.h>
32
33 #include <frei0r.h>cxx . . $ `<file>/include/frei0r.h`/
34
35 #include "interp.h"cxx . . $ `<file>/src/filter/defish0r/interp.h`/
36
37
38 double PIcxx . . $ PI.=3.14159265358979;
39
40 //add simplified 'Elestic Scale' to fix superview
41 float stretchWidthcxx . . $ stretchWidth(d287910fd745093b).(int width, int widthCentre, float currentXPos, float stretchFactor)
42 {
43 double ratio, lowerWeight = 0.0, higherWeight = 0.0, linearRatio;
44 unsigned int lengthSection;
45 float relativeXPos = 0.0f;
46
47 //midline?
48 if (currentXPos < (float)widthCentre)
49 {
50 lengthSection = widthCentre - 1;
51 linearRatio = (double) ( currentXPos ) / lengthSection;
52 ratio = sin(linearRatio * PIcxx . . $ PI. - PIcxx . . $ PI.) * stretchFactor + linearRatio;
53 }
54 else
55 {
56 lengthSection = width - widthCentre - 1;
57 linearRatio = (double) ( currentXPos - widthCentre ) / lengthSection;
58 ratio = sin(linearRatio * PIcxx . . $ PI.) * stretchFactor + linearRatio;
59 }
60 ratio = ratio <= 0.0 ? 0.0 : ratio;
61
62 relativeXPos = (float) ( ratio * lengthSection );
63
64 if (currentXPos < (float)widthCentre)
65 relativeXPos -= currentXPos;
66 else
67 relativeXPos -= ( currentXPos - widthCentre );
68
69 return relativeXPos;
70 }
71
72
73 //---------------------------------------------------------
74 // r = 0...1 izhod = 0...maxr
75 //ta funkcija da popacenje v odvisnosti od r
76 float fishcxx . . $ fish(862d6589e008f424).(int n, float r, float f)
77 {
78 float rr,ff;
79
80 //printf("ff=%f\n",ff);
81 switch (n)
82 {
83 case 0: //equidistant
84 ff=f*2.0f/(float)PIcxx . . $ PI.;
85 rr=tanf(r/ff);
86 break;
87 case 1: //ortographic
88 ff=r/f;
89 if (ff>1.0)
90 rr=-1.0;
91 else
92 rr=tanf(asinf(ff));
93 break;
94 case 2: //equiarea
95 ff=r/2.0f/f;
96 if (ff>1.0f)
97 rr=-1.0f;
98 else
99 rr=tanf(2.0f*asinf(r/2.0f/f));
100 break;
101 case 3: //stereographic
102 ff=f*2.0f/(float)PIcxx . . $ PI.;
103 rr=tanf(2.0f*atanf(r/2.0f/ff));
104 break;
105 default:
106 // printf("Neznana fishitvena funkcija %d\n",n);
107 break;
108 }
109 return rr;
110 }
111
112 //---------------------------------------------------------
113 //ta funkcija da popacenje v odvisnosti od r
114 // r = 0...1 izhod = 0...1
115 float defishcxx . . $ defish(31033660b524a502).(int n, float r, float f, float mr)
116 {
117 float rr;
118
119 switch (n)
120 {
121 case 0: //equidistant
122 rr=f*2.0f/(float)PIcxx . . $ PI.*atanf(r*mr);
123 break;
124 case 1: //ortographic
125 rr=f*sinf(atanf(r*mr));
126 break;
127 case 2: //equiarea
128 rr=2.0f*f*sinf(atanf(r*mr)/2.0f);
129 break;
130 case 3: //stereographic
131 rr=f*4.0f/(float)PIcxx . . $ PI.*tanf(atanf(r*mr)/2.0f);
132 break;
133 default:
134 // printf("Neznana fishitvena funkcija %d\n",n);
135 break;
136 }
137 return rr;
138 }
139
140 //----------------------------------------------------------------
141 //nafila array map s polozaji pikslov
142 //locena funkcija, da jo poklicem samo enkrat na zacetku,
143 //array map[] potem uporablja funkcija remap()
144 //tako ni treba za vsak frame znova racunat teh sinusov itd...
145 //wi,hi,wo ho = input.output image width/height
146 //n = 0..3 function select
147 //f = focal ratio (amount of distortion)
148 //scal = scaling factor
149 //pari, paro = pixel aspect ratio (input / output)
150 //dx, dy offset on input (for non-cosited chroma subsampling)
151 void fishmapcxx . . $ fishmap(464500b64b8c6a89).(int wi, int hi, int wo, int ho, int n, float f, float scal, float pari, float paro, float dx, float dy, float *map
152 , float stretchFactor, float yScale)
153 {
154 float rmax,maxr,r,kot,x,y,imax;
155 int i, j, ww;
156 float ii,jj,sc;
157 int wiMid = wi/2;
158 int hiMid = hi/2;
159
160 rmax=hypotf(ho/2.0f,wo/2.0f*paro);
161 maxr=fishcxx . . $ fish(862d6589e008f424).(n,1.0,f);
162 imax=hypotf(hi/2.0f,wi/2.0f*pari);
163 sc=imax/maxr;
164
165 //printf("Fishmap: F=%5.2f Rmax= %7.2f Maxr=%6.2f sc=%6.2f scal=%6.2f\n",f,rmax,maxr,sc,scal);
166
167 for (i=0;i<hi;i++)
168 {
169 ii=(float)(i-hiMid)*yScale; //add Y scale
170 for (j=0;j<wi;j++)
171 {
172 jj=(j-wiMid)*paro;
173 r=hypotf(ii,jj);
174 kot=atan2f(ii,jj);
175 r=fishcxx . . $ fish(862d6589e008f424).(n,r/rmax*scal,f)*sc;
176 ww=2*(wo*i+j);
177 if (r<0.0)
178 {
179 map[ww]=-1;
180 map[ww+1]=-1;
181 }
182 else
183 {
184 x=wiMid+r*cosf(kot)/pari;
185 y=hiMid+r*sinf(kot);
186 if ((x>0)&(x<(wi-1))&(y>0)&(y<(hi-1)))
187 {
188 if (stretchFactor != 0.0f)
189 x += stretchWidthcxx . . $ stretchWidth(d287910fd745093b).(wo, wiMid, x, stretchFactor); //add stretch
190 map[ww]=x+dx;
191 map[ww+1]=y+dy;
192 }
193 else
194 {
195 map[ww]=-1;
196 map[ww+1]=-1;
197 }
198 }
199 }
200 }
201 }
202
203
204 //----------------------------------------------------------------
205 //nafila array map s polozaji pikslov
206 //locena funkcija, da jo poklicem samo enkrat na zacetku,
207 //array map[] potem uporablja funkcija remap()
208 //tako ni treba za vsak frame znova racunat teh sinusov itd...
209 //wi,hi,wo ho = input.output image width/height
210 //n = 0..3 function select
211 //f = focal ratio (amount of distortion)
212 //scal = scaling factor
213 //pari,paro = pixel aspect ratio (input / output)
214 //dx, dy offset on input (for non-cosited chroma subsampling)
215 //lbox = letterbox
216 //stretch = dynamic stretch, convert between 4:3 and 16:9
217 //yScale = -0.5.. 0.5 change aspect ratio on y access only
218 void defishmapcxx . . $ defishmap(de6059d5d6736e4f).(int wi, int hi, int wo, int ho, int n, float f, float scal, float pari, float paro, float dx, float dy, float *map
219 , int lbox, float stretchFactor, float yScale)
220 {
221 float rmax,maxr,r,kot,x,y,imax;
222 int i,j,ww;
223 float ii,jj,sc;
224 int wiMid = wi/2;
225 int hiMid = hi/2;
226
227 rmax=hypotf(ho/2.0f,wo/2.0f*paro);
228 maxr=fishcxx . . $ fish(862d6589e008f424).(n,1.0,f);
229 imax=hypotf(hi/2.0f,wi/2.0f*pari);
230 sc=imax/maxr;
231
232 //printf("Defishmap: F=%f rmax= %f Maxr=%f sc=%6.2f scal=%6.2f\n",f,rmax,maxr,sc,scal);
233
234 for (i=0;i<hi;i++)
235 {
236 ii = (float)(i-hiMid)*yScale; //add Y scale
237 for (j=0;j<wi;j++)
238 {
239 jj=(j-wiMid)*paro; //aspect....
240 r=hypotf(ii,jj)/scal;
241 kot=atan2f(ii,jj);
242 ww=2*(wi*i+j);
243 r=defishcxx . . $ defish(31033660b524a502).(n,r/sc,f,1.0)*imax;
244 if (r<0.0)
245 {
246 map[ww]=-1;
247 map[ww+1]=-1;
248 }
249 else
250 {
251 x=wiMid+r*cosf(kot)/pari;
252 y=hiMid+r*sinf(kot);
253
254 if ((x>0)&&(x<(wi-1))&&(y>0)&&(y<(hi-1)))
255 {
256 if (stretchFactor != 0.0f)
257 x += stretchWidthcxx . . $ stretchWidth(d287910fd745093b).(wi, wiMid, x, stretchFactor); //add stretch
258
259 map[ww]=x;
260 map[ww+1]=y;
261 }
262 else
263 {
264 map[ww]=-1;
265 map[ww+1]=-1;
266 }
267 }
268 }
269 }
270
271 //crop all 4 borders
272 if (lbox)
273 { //top/bottom
274 for (i = 0; i < hi; i++)
275 {
276 ww = 2 * (wi*i + wiMid);
277 if (map[ww] <= 0)
278 {
279 for (j = 0; j < wi; j++)
280 { //clear entire row
281 ww = 2 * (wi*i + j);
282 map[ww] = -1;
283 map[ww + 1] = -1;
284 }
285 }
286 }
287 //left/right
288 for (i = 0; i < wi; i++)
289 {
290 ww = 2 * (wi*hiMid +i);
291 if (map[ww] <= 0)
292 {
293 for (j = 0; j < hi; j++)
294 { //clear entire column
295 ww = 2 * (wi*j + i);
296 map[ww] = -1;
297 map[ww + 1] = -1;
298 }
299 }
300 }
301 }
302 }
303
304 //=====================================================
305 //kao instanca frei0r
306 //w,h: image dimensions in pixels
307 //f: focal ratio
308 //dir: 0=defish 1=fish
309 //type: 0..3 equidistant, ortographic, equiarea, stereographic
310 //scal: 0..3 image to fill, keep center scale, image to fit, manu
311 //intp: 0..6 type of interpolator
312 //aspt: 0..4 aspect type square, PAL, NTSC, HDV, manual
313 //par: pixel aspect ratio
314 //lbox: 1=letterbox
315 //stretch 0..1 stretch video to fix superview distortion
316 typedef structcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#
317 {
318 int wcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#w.;
319 int hcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#h.;
320 float fcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#f.;
321 int dircxx . . $ $anonymous_type_f8dc895c8cc1a502_0#dir.;
322 int typecxx . . $ $anonymous_type_f8dc895c8cc1a502_0#type.;
323 int scalcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#scal.;
324 int intpcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#intp.;
325 float mscalecxx . . $ $anonymous_type_f8dc895c8cc1a502_0#mscale.;
326 int asptcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#aspt.;
327 float mparcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#mpar.;
328 float parcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#par.;
329 float *mapcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#map.;
330 int lboxcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#lbox.;
331 float stretchcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#stretch.;
332 float yScalecxx . . $ $anonymous_type_f8dc895c8cc1a502_0#yScale.;
333 interppcxx . . $ interpp# interpolcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#interpol.;
334 } paramcxx . . $ param#;
335
336
337
338 //-------------------------------------------------------
339 interppcxx . . $ interpp# set_intpcxx . . $ set_intp(5c93ed66aba9f6ce).(paramcxx . . $ param# p)
340 {
341 switch (p.intpcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#intp.) //katero interpolacijo bo uporabil
342 {
343 // case -1:return interpNNpr_b; //nearest neighbor+print
344 case 0: return interpNN_b32cxx . . $ interpNN_b32(bb2946d2180fb79f).; //nearest neighbor
345 case 1: return interpBL_b32cxx . . $ interpBL_b32(bb2946d2180fb79f).; //bilinear
346 case 2: return interpBC_b32cxx . . $ interpBC_b32(bb2946d2180fb79f).; //bicubic smooth
347 case 3: return interpBC2_b32cxx . . $ interpBC2_b32(bb2946d2180fb79f).; //bicibic sharp
348 case 4: return interpSP4_b32cxx . . $ interpSP4_b32(bb2946d2180fb79f).; //spline 4x4
349 case 5: return interpSP6_b32cxx . . $ interpSP6_b32(bb2946d2180fb79f).; //spline 6x6
350 case 6: return interpSC16_b32cxx . . $ interpSC16_b32(bb2946d2180fb79f).; //lanczos 8x8
351 default: return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
352 }
353 }
354
355 //--------------------------------------------------------
356 void make_mapcxx . . $ make_map(fcf38672f8021438).(paramcxx . . $ param# p)
357 {
358 float rmax,maxr,imax,fscal,dscal;
359
360 rmax=hypotf(p.hcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#h./2.0,p.wcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#w./2.0*p.parcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#par.);
361 maxr=fishcxx . . $ fish(862d6589e008f424).(p.typecxx . . $ $anonymous_type_f8dc895c8cc1a502_0#type.,1.0,p.fcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#f.);
362 imax=hypotf(p.hcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#h./2.0,p.wcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#w./2.0*p.parcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#par.);
363
364 if (p.dircxx . . $ $anonymous_type_f8dc895c8cc1a502_0#dir.==0) //defish
365 {
366 switch (p.scalcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#scal.)
367 {
368 case 0: //fill
369 dscal=maxr*p.hcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#h./2.0/rmax/fishcxx . . $ fish(862d6589e008f424).(p.typecxx . . $ $anonymous_type_f8dc895c8cc1a502_0#type.,p.hcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#h./2.0/rmax,p.fcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#f.);
370 break;
371 case 1: //keep
372 dscal=maxr*p.fcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#f.;
373 if ((p.typecxx . . $ $anonymous_type_f8dc895c8cc1a502_0#type.==0)||(p.typecxx . . $ $anonymous_type_f8dc895c8cc1a502_0#type.==3)) dscal=dscal/PIcxx . . $ PI.*2.0;break;
374 case 2: //fit
375 dscal=1.0; break;
376 case 3: //manual
377 dscal=p.mscalecxx . . $ $anonymous_type_f8dc895c8cc1a502_0#mscale.; break;
378 }
379 defishmapcxx . . $ defishmap(de6059d5d6736e4f).(p.wcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#w. ,p.hcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#h. ,p.wcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#w. ,p.hcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#h., p.typecxx . . $ $anonymous_type_f8dc895c8cc1a502_0#type., p.fcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#f., dscal, p.parcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#par., p.parcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#par., 0.0, 0.0, p.mapcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#map., p.lboxcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#lbox., p.stretchcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#stretch., p.yScalecxx . . $ $anonymous_type_f8dc895c8cc1a502_0#yScale.);
380 }
381 else //fish
382 {
383 switch (p.scalcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#scal.)
384 {
385 case 0: //fill
386 fscal=1.0;break;
387 case 1: //keep
388 fscal=maxr*p.fcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#f.;
389 if ((p.typecxx . . $ $anonymous_type_f8dc895c8cc1a502_0#type.==0)||(p.typecxx . . $ $anonymous_type_f8dc895c8cc1a502_0#type.==3)) fscal=fscal/PIcxx . . $ PI.*2.0;
390 break;
391 case 2: //fit
392 fscal=2.0*defishcxx . . $ defish(31033660b524a502).(p.typecxx . . $ $anonymous_type_f8dc895c8cc1a502_0#type.,p.hcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#h./2.0*maxr/imax,p.fcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#f.,1.0)/p.hcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#h.*rmax;
393 break;
394 case 3: //manual
395 fscal=1.0/p.mscalecxx . . $ $anonymous_type_f8dc895c8cc1a502_0#mscale.; break;
396 }
397 fishmapcxx . . $ fishmap(464500b64b8c6a89).(p.wcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#w., p.hcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#h., p.wcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#w. ,p.hcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#h., p.typecxx . . $ $anonymous_type_f8dc895c8cc1a502_0#type., p.fcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#f., fscal, p.parcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#par., p.parcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#par., 0.0, 0.0, p.mapcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#map., p.stretchcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#stretch., p.yScalecxx . . $ $anonymous_type_f8dc895c8cc1a502_0#yScale.);
398 }
399
400 }
401
402 //*********************************************************
403 // OBVEZNE FREI0R FUNKCIJE
404
405 //-----------------------------------------------
406 int f0r_initcxx . . $ f0r_init(b126dc7c1de90089).()
407 {
408 return 1;
409 }
410
411 //------------------------------------------------
412 void f0r_deinitcxx . . $ f0r_deinit(49f6e7a06ebc5aa8).()
413 {
414 }
415
416 //-----------------------------------------------
417 void f0r_get_plugin_infocxx . . $ f0r_get_plugin_info(35d753456c0ea59c).(f0r_plugin_info_tcxx . . $ f0r_plugin_info_t#* info)
418 {
419
420 info->namecxx . . $ f0r_plugin_info#name.="Defish0r";
421 info->authorcxx . . $ f0r_plugin_info#author.="Marko Cebokli";
422 info->plugin_typecxx . . $ f0r_plugin_info#plugin_type.=F0R_PLUGIN_TYPE_FILTERcxx . . $ `include/frei0r.h:247:9`!;
423 info->color_modelcxx . . $ f0r_plugin_info#color_model.=F0R_COLOR_MODEL_RGBA8888cxx . . $ `include/frei0r.h:308:9`!;
424 info->frei0r_versioncxx . . $ f0r_plugin_info#frei0r_version.=FREI0R_MAJOR_VERSIONcxx . . $ `include/frei0r.h:217:9`!;
425 info->major_versioncxx . . $ f0r_plugin_info#major_version.=0;
426 info->minor_versioncxx . . $ f0r_plugin_info#minor_version.=4;
427 info->num_paramscxx . . $ f0r_plugin_info#num_params.=11;
428 info->explanationcxx . . $ f0r_plugin_info#explanation.="Non rectilinear lens mappings";
429 }
430
431 //--------------------------------------------------
432 void f0r_get_param_infocxx . . $ f0r_get_param_info(a9f9aa7954cc4a37).(f0r_param_info_tcxx . . $ f0r_param_info_t#* info, int param_index)
433 {
434 switch(param_index)
435 {
436 case 0:
437 info->namecxx . . $ f0r_param_info#name. = "Amount";
438 info->typecxx . . $ f0r_param_info#type. = F0R_PARAM_DOUBLEcxx . . $ `include/frei0r.h:383:9`!;
439 info->explanationcxx . . $ f0r_param_info#explanation. = "Focal Ratio";
440 break;
441 case 1:
442 info->namecxx . . $ f0r_param_info#name. = "DeFish";
443 info->typecxx . . $ f0r_param_info#type. = F0R_PARAM_BOOLcxx . . $ `include/frei0r.h:377:9`!;
444 info->explanationcxx . . $ f0r_param_info#explanation. = "Fish or Defish";
445 break;
446 case 2:
447 info->namecxx . . $ f0r_param_info#name. = "Type";
448 info->typecxx . . $ f0r_param_info#type. = F0R_PARAM_DOUBLEcxx . . $ `include/frei0r.h:383:9`!;
449 info->explanationcxx . . $ f0r_param_info#explanation. = "Mapping function";
450 break;
451 case 3:
452 info->namecxx . . $ f0r_param_info#name. = "Scaling";
453 info->typecxx . . $ f0r_param_info#type. = F0R_PARAM_DOUBLEcxx . . $ `include/frei0r.h:383:9`!;
454 info->explanationcxx . . $ f0r_param_info#explanation. = "Scaling method";
455 break;
456 case 4:
457 info->namecxx . . $ f0r_param_info#name. = "Manual Scale";
458 info->typecxx . . $ f0r_param_info#type. = F0R_PARAM_DOUBLEcxx . . $ `include/frei0r.h:383:9`!;
459 info->explanationcxx . . $ f0r_param_info#explanation. = "Manual Scale";
460 break;
461 case 5:
462 info->namecxx . . $ f0r_param_info#name. = "Interpolator";
463 info->typecxx . . $ f0r_param_info#type. = F0R_PARAM_DOUBLEcxx . . $ `include/frei0r.h:383:9`!;
464 info->explanationcxx . . $ f0r_param_info#explanation. = "Quality of interpolation";
465 break;
466 case 6:
467 info->namecxx . . $ f0r_param_info#name. = "Aspect type";
468 info->typecxx . . $ f0r_param_info#type. = F0R_PARAM_DOUBLEcxx . . $ `include/frei0r.h:383:9`!;
469 info->explanationcxx . . $ f0r_param_info#explanation. = "Pixel aspect ratio presets";
470 break;
471 case 7:
472 info->namecxx . . $ f0r_param_info#name. = "Manual Aspect";
473 info->typecxx . . $ f0r_param_info#type. = F0R_PARAM_DOUBLEcxx . . $ `include/frei0r.h:383:9`!;
474 info->explanationcxx . . $ f0r_param_info#explanation. = "Manual Pixel Aspect ratio";
475 break;
476 case 8:
477 info->namecxx . . $ f0r_param_info#name. = "Crop";
478 info->typecxx . . $ f0r_param_info#type. = F0R_PARAM_BOOLcxx . . $ `include/frei0r.h:377:9`!;
479 info->explanationcxx . . $ f0r_param_info#explanation. = "Straighten all edges of video frame";
480 break;
481 case 9:
482 info->namecxx . . $ f0r_param_info#name. = "Non-Linear scale";
483 info->typecxx . . $ f0r_param_info#type. = F0R_PARAM_DOUBLEcxx . . $ `include/frei0r.h:383:9`!;
484 info->explanationcxx . . $ f0r_param_info#explanation. = "Fix camera scaling between 4:3 and 16:9";
485 break;
486 case 10:
487 info->namecxx . . $ f0r_param_info#name. = "Y Scale";
488 info->typecxx . . $ f0r_param_info#type. = F0R_PARAM_DOUBLEcxx . . $ `include/frei0r.h:383:9`!;
489 info->explanationcxx . . $ f0r_param_info#explanation. = "Scale Y to affect aspect ratio";
490 break;
491 }
492
493 }
494
495 //--------------------------------------------------------
496 //kao constructor za frei0r
497 f0r_instance_tcxx . . $ f0r_instance_t# f0r_constructcxx . . $ f0r_construct(da3f471cd007a696).(unsigned int width, unsigned int height)
498 {
499 paramcxx . . $ param# *p;
500
501 p=(paramcxx . . $ param#*)calloccxx . . $ calloc(63a7bf2941bfcd7a).(1, sizeof(paramcxx . . $ param#));
502
503 p->wcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#w.=width;
504 p->hcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#h.=height;
505 p->fcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#f.=20.0; //defaults (not used??)
506 p->dircxx . . $ $anonymous_type_f8dc895c8cc1a502_0#dir.=1;
507 p->typecxx . . $ $anonymous_type_f8dc895c8cc1a502_0#type.=2;
508 p->scalcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#scal.=2;
509 p->intpcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#intp.=1;
510 p->mscalecxx . . $ $anonymous_type_f8dc895c8cc1a502_0#mscale.=1.0;
511 p->asptcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#aspt.=0; //square pixels
512 p->parcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#par.=1.0; //square pixels
513 p->mparcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#mpar.=1.0;
514 p->lboxcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#lbox.=0; //letterbox
515 p->stretchcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#stretch. = 0.0f; //dynamic stretch
516 p->yScalecxx . . $ $anonymous_type_f8dc895c8cc1a502_0#yScale. = 1.0f; //separate Y stretch
517
518 p->mapcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#map.=(float*)calloccxx . . $ calloc(63a7bf2941bfcd7a).(1, sizeof(float)*(p->wcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#w.*p->hcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#h.*2+2));
519 p->interpolcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#interpol.=set_intpcxx . . $ set_intp(5c93ed66aba9f6ce).(*p);
520
521 make_mapcxx . . $ make_map(fcf38672f8021438).(*p);
522
523 //printf("Construct, w=%d h=%d\n",width,height);
524
525 return (f0r_instance_tcxx . . $ f0r_instance_t#)p;
526 }
527
528 //---------------------------------------------------
529 void f0r_destructcxx . . $ f0r_destruct(5d22bdacc48458e8).(f0r_instance_tcxx . . $ f0r_instance_t# instance)
530 {
531 paramcxx . . $ param# *p;
532 p=(paramcxx . . $ param#*)instance;
533
534 freecxx . . $ free(5d22bdacc48458e8).(p->mapcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#map.);
535 freecxx . . $ free(5d22bdacc48458e8).(instance);
536 }
537
538 //----------------------------------------------------
539 //not used in frei0r plugin
540 void change_paramcxx . . $ change_param(29f090450ec92829).(paramcxx . . $ param# *p, int w, int h, float f, int dir, int type, int scal, int intp)
541 {
542 p->fcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#f.=f;
543 p->dircxx . . $ $anonymous_type_f8dc895c8cc1a502_0#dir.=dir;
544 p->typecxx . . $ $anonymous_type_f8dc895c8cc1a502_0#type.=type;
545 p->scalcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#scal.=scal;
546 p->intpcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#intp.=intp;
547
548 if ((w!=p->wcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#w.)||(h!=p->hcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#h.))
549 {
550 freecxx . . $ free(5d22bdacc48458e8).(p->mapcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#map.);
551 p->mapcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#map.=(float*)calloccxx . . $ calloc(63a7bf2941bfcd7a).(1, sizeof(float)*(w*h*2+2));
552 p->wcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#w.=w;
553 p->hcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#h.=h;
554 }
555
556 p->interpolcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#interpol.=set_intpcxx . . $ set_intp(5c93ed66aba9f6ce).(*p);
557 make_mapcxx . . $ make_map(fcf38672f8021438).(*p);
558 }
559
560 //-----------------------------------------------------
561 void print_paramcxx . . $ print_param(fcf38672f8021438).(paramcxx . . $ param# p)
562 //not used in frei0r plugin
563 {
564 printfcxx . . $ printf(581fddd72a8db8fc).("Param: w=%d h=%d f=%f dir=%d",p.wcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#w., p.hcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#h., p.fcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#f., p.dircxx . . $ $anonymous_type_f8dc895c8cc1a502_0#dir.);
565 printfcxx . . $ printf(581fddd72a8db8fc).(" type=%d scal=%d intp=%d",p.typecxx . . $ $anonymous_type_f8dc895c8cc1a502_0#type., p.scalcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#scal., p.intpcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#intp.);
566 printfcxx . . $ printf(581fddd72a8db8fc).(" mscale=%f par=%f mpar=%f\n",p.mscalecxx . . $ $anonymous_type_f8dc895c8cc1a502_0#mscale., p.parcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#par., p.mparcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#mpar.);
567 }
568
569 //------------------------------------------------------
570 //computes x to the power p
571 //only for positive x
572 float pwrcxx . . $ pwr(d59a45cd3bfd2eda).(float x, float p)
573 {
574 if (x<=0) return 0;
575 //printf("exp(%f)=%f\n",x,expf(p*logf(x)));
576 return expf(p*logf(x));
577 }
578
579 //-----------------------------------------------------
580 //stretch [0...1] to parameter range [min...max] logarithmic
581 //min and max must be positive!
582 float map_value_forward_logcxx . . $ map_value_forward_log(1935fda23fc189b2).(double v, float min, float max)
583 {
584 float sr,k;
585
586 sr=sqrtf(min*max);
587 k=2.0*log(max/sr);
588 return sr*expf(k*(v-0.5));
589 }
590
591 //-----------------------------------------------------
592 //collapse from parameter range [min...max] to [0...1] logarithmic
593 //min and max must be positive!
594 double map_value_backward_logcxx . . $ map_value_backward_log(937b104db0ceee62).(float v, float min, float max)
595 {
596 float sr,k;
597
598 sr=sqrtf(min*max);
599 k=2.0*log(max/sr);
600 return logf(v/sr)/k+0.5;
601 }
602
603 //-----------------------------------------------------
604 //stretch [0...1] to parameter range [min...max] linear
605 float map_value_forwardcxx . . $ map_value_forward(1935fda23fc189b2).(double v, float min, float max)
606 {
607 return min+(max-min)*v;
608 }
609
610 //-----------------------------------------------------
611 //collapse from parameter range [min...max] to [0...1] linear
612 double map_value_backwardcxx . . $ map_value_backward(937b104db0ceee62).(float v, float min, float max)
613 {
614 return (v-min)/(max-min);
615 }
616
617 //-----------------------------------------------------
618 //smisele vrednosti za parameter f: (za fish)
619 // tip 0: (0.3) 1.001...10; tip 1: 1.000...10
620 // tip 2: (0.5) 0.75...10.0 tip 3: (0.1) 0.78...10
621 //za defish:
622 // tip 0: 0.1...10 tip 1: 1.0...10
623 // tip 2: 0.5...10 tip 3: (0.1) 0.5...10
624 void f0r_set_param_valuecxx . . $ f0r_set_param_value(5be095a8278d2bf5).(f0r_instance_tcxx . . $ f0r_instance_t# instance, f0r_param_tcxx . . $ f0r_param_t# parm, int param_index)
625 {
626 paramcxx . . $ param# *p;
627 int chg,tmpi;
628 float tmpf;
629
630 p=(paramcxx . . $ param#*)instance;
631
632 //printf("set parm: index=%d, value=%f\n",param_index,*(float*)parm);
633 chg=0;
634 switch(param_index)
635 {
636 case 0: //f
637 tmpf=pwrcxx . . $ pwr(d59a45cd3bfd2eda).(*((double*)parm),1.0/5.0);
638 // tmpf=map_value_forward(*((double*)parm), 10.0, 0.1);
639 tmpf=map_value_forwardcxx . . $ map_value_forward(1935fda23fc189b2).(tmpf, 20.0, 0.1);
640 if (p->fcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#f. != tmpf) chg=1;
641 p->fcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#f.=tmpf;
642 break;
643 case 1: //fish
644 tmpi=map_value_forwardcxx . . $ map_value_forward(1935fda23fc189b2).(*((double*)parm), 1.0, 0.0);//BOOL!!
645 if (p->dircxx . . $ $anonymous_type_f8dc895c8cc1a502_0#dir. != tmpi) chg=1;
646 p->dircxx . . $ $anonymous_type_f8dc895c8cc1a502_0#dir.=tmpi;
647 break;
648 case 2: //type
649 tmpi=map_value_forwardcxx . . $ map_value_forward(1935fda23fc189b2).(*((double*)parm), 0.0, 3.999);
650 if (p->typecxx . . $ $anonymous_type_f8dc895c8cc1a502_0#type. != tmpi) chg=1;
651 p->typecxx . . $ $anonymous_type_f8dc895c8cc1a502_0#type.=tmpi;
652 break;
653 case 3: //scaling
654 tmpi=map_value_forwardcxx . . $ map_value_forward(1935fda23fc189b2).(*((double*)parm), 0.0, 3.999);
655 if (p->scalcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#scal. != tmpi) chg=1;
656 p->scalcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#scal.=tmpi;
657 break;
658 case 4: //manual scale
659 tmpf=map_value_forward_logcxx . . $ map_value_forward_log(1935fda23fc189b2).(*((double*)parm), 0.01, 100.0);
660 if (p->mscalecxx . . $ $anonymous_type_f8dc895c8cc1a502_0#mscale. != tmpf) chg=1;
661 p->mscalecxx . . $ $anonymous_type_f8dc895c8cc1a502_0#mscale.=tmpf;
662 break;
663 case 5: //interpolator
664 tmpi=map_value_forwardcxx . . $ map_value_forward(1935fda23fc189b2).(*((double*)parm), 0.0, 6.999);
665 if (p->intpcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#intp. != tmpi) chg=1;
666 p->intpcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#intp.=tmpi;
667 break;
668 case 6: //aspect type
669 tmpi=map_value_forwardcxx . . $ map_value_forward(1935fda23fc189b2).(*((double*)parm), 0.0, 4.999);
670 if (p->asptcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#aspt. != tmpi) chg=1;
671 p->asptcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#aspt.=tmpi;
672 break;
673 case 7: //manual aspect
674 tmpf=map_value_forward_logcxx . . $ map_value_forward_log(1935fda23fc189b2).(*((double*)parm), 0.5, 2.0);
675 if (p->mparcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#mpar. != tmpf) chg=1;
676 p->mparcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#mpar.=tmpf;
677 break;
678 case 8: //letterbox
679 tmpi=(int)map_value_forwardcxx . . $ map_value_forward(1935fda23fc189b2).(*((double*)parm), 0.0f, 1.0f);//BOOL!!
680 if (p->lboxcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#lbox. != tmpi) chg=1;
681 p->lboxcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#lbox.=tmpi;
682 break;
683 case 9: //stretch
684 tmpf=map_value_forwardcxx . . $ map_value_forward(1935fda23fc189b2).(*((double*)parm), -0.2f, 0.2f);
685 if (p->stretchcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#stretch. != tmpf) chg=1;
686 p->stretchcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#stretch.=tmpf;
687 break;
688 case 10: //Y scale
689 tmpf=map_value_forwardcxx . . $ map_value_forward(1935fda23fc189b2).(*((double*)parm), 1.5f, 0.5f);
690 if (p->yScalecxx . . $ $anonymous_type_f8dc895c8cc1a502_0#yScale. != tmpf) chg=1;
691 p->yScalecxx . . $ $anonymous_type_f8dc895c8cc1a502_0#yScale.=tmpf;
692 break;
693 }
694
695 if (chg!=0)
696 {
697 switch (p->asptcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#aspt.) //pixel aspect ratio
698 {
699 case 0: p->parcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#par.=1.000;break; //square pixels
700 case 1: p->parcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#par.=1.067;break; //PAL DV
701 case 2: p->parcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#par.=0.889;break; //NTSC DV
702 case 3: p->parcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#par.=1.333;break; //HDV
703 case 4: p->parcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#par.=p->mparcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#mpar.;break; //manual
704 }
705 p->interpolcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#interpol.=set_intpcxx . . $ set_intp(5c93ed66aba9f6ce).(*p);
706 make_mapcxx . . $ make_map(fcf38672f8021438).(*p);
707 }
708
709 //print_param(*p);
710 }
711
712 //--------------------------------------------------
713 void f0r_get_param_valuecxx . . $ f0r_get_param_value(5be095a8278d2bf5).(f0r_instance_tcxx . . $ f0r_instance_t# instance, f0r_param_tcxx . . $ f0r_param_t# parm, int param_index)
714 {
715 paramcxx . . $ param# *p;
716 float tmpf;
717
718 p=(paramcxx . . $ param#*)instance;
719
720 switch(param_index)
721 {
722 case 0: //f
723 // *((double*)parm)=map_value_backward(p->f, 10.0, 0.1);
724 tmpf=map_value_backwardcxx . . $ map_value_backward(937b104db0ceee62).(p->fcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#f., 20.0, 0.1);
725 *((double*)parm)=pwrcxx . . $ pwr(d59a45cd3bfd2eda).(tmpf, 5.0);
726 break;
727 case 1: //fish
728 *((double*)parm)=map_value_backwardcxx . . $ map_value_backward(937b104db0ceee62).(p->dircxx . . $ $anonymous_type_f8dc895c8cc1a502_0#dir., 1.0, 0.0); //BOOL!!
729 break;
730 case 2: //type
731 *((double*)parm)=map_value_backwardcxx . . $ map_value_backward(937b104db0ceee62).(p->typecxx . . $ $anonymous_type_f8dc895c8cc1a502_0#type., 0.0, 3.0);
732 break;
733 case 3: //scaling
734 *((double*)parm)=map_value_backwardcxx . . $ map_value_backward(937b104db0ceee62).(p->scalcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#scal., 0.0, 3.0);
735 break;
736 case 4: //manual scale
737 *((double*)parm)=map_value_backward_logcxx . . $ map_value_backward_log(937b104db0ceee62).(p->mscalecxx . . $ $anonymous_type_f8dc895c8cc1a502_0#mscale., 0.01, 100.0);
738 break;
739 case 5: //interpolator
740 *((double*)parm)=map_value_backwardcxx . . $ map_value_backward(937b104db0ceee62).(p->intpcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#intp., 0.0, 6.0);
741 break;
742 case 6: //aspect type
743 *((double*)parm)=map_value_backwardcxx . . $ map_value_backward(937b104db0ceee62).(p->asptcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#aspt., 0.0, 4.999);
744 break;
745 case 7: //manual aspect
746 *((double*)parm)=map_value_backward_logcxx . . $ map_value_backward_log(937b104db0ceee62).(p->mparcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#mpar., 0.5, 2.0);
747 break;
748 case 8: //letterbox
749 *((double*)parm)=map_value_backwardcxx . . $ map_value_backward(937b104db0ceee62).((float)p->lboxcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#lbox., 0.0f, 1.0f); //BOOL!!
750 break;
751 case 9: //stretch/upscale fix
752 *((double*)parm)=map_value_backward_logcxx . . $ map_value_backward_log(937b104db0ceee62).(p->stretchcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#stretch., -0.2f, 0.2f);
753 break;
754 case 10: //Y scale
755 *((double*)parm)=map_value_backwardcxx . . $ map_value_backward(937b104db0ceee62).(p->yScalecxx . . $ $anonymous_type_f8dc895c8cc1a502_0#yScale., 1.5f, 0.5f);
756 break;
757 }
758 }
759
760 //-------------------------------------------------
761 void f0r_updatecxx . . $ f0r_update(96cd7b27f2fca8a7).(f0r_instance_tcxx . . $ f0r_instance_t# instance, double time, const uint32_tcxx . . $ uint32_t#* inframe, uint32_tcxx . . $ uint32_t#* outframe)
762 {
763 paramcxx . . $ param# *p;
764
765 p=(paramcxx . . $ param#*)instance;
766
767 remap32cxx . . $ remap32(c5b0480a77d4b7b2).(p->wcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#w., p->hcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#h., p->wcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#w., p->hcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#h., (unsigned char*) inframe, (unsigned char*) outframe, p->mapcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#map., 0, p->interpolcxx . . $ $anonymous_type_f8dc895c8cc1a502_0#interpol.);
768
769 }