source: src/filter/measure/pr0file.c @ b4e184

Revision b4e184, 26.5 KB checked in by Marko Cebokli <mc@…>, 3 years ago (diff)

pr0be, pr0file: fixed forstr() and /255

  • Property mode set to 100644
Line 
1/*
2pr0file.c
3
4This frei0r plugin ia an "2D video oscilloscope"
5Version 0.1     jun 2010
6
7Copyright (C) 2010  Marko Cebokli    http://lea.hamradio.si/~s57uuu
8
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23
24*/
25
26//compile: gcc -c -fPIC -Wall pr0file.c -o pr0file.o
27//link: gcc -shared -o pr0file.so pr0file.o
28
29#include <frei0r.h>
30
31#include <stdio.h>
32#include <stdlib.h>
33#include <math.h>
34#include <string.h>
35#include <assert.h>
36
37#include "font2.h"
38#include "measure.h"
39
40double PI=3.14159265358979;
41
42//---------------------------------------------------------------
43void draw_rectangle(float_rgba *s, int w, int h, float x, float y, float wr, float hr, float_rgba c)
44{
45int i,j;
46int zx,kx,zy,ky;
47
48zx=x;  if (zx<0) zx=0;
49zy=y;  if (zy<0) zy=0;
50kx=x+wr;  if (kx>w) kx=w;
51ky=y+hr;  if (ky>h) ky=h;
52for (i=zy;i<ky;i++)
53        for (j=zx;j<kx;j++)
54                s[w*i+j]=c;
55
56}
57
58//---------------------------------------------------------------
59//d=dim value   0.0=black   1.0=no dimming
60void darken_rectangle(float_rgba *s, int w, int h, float x, float y, float wr, float hr, float d)
61{
62int i,j;
63int zx,kx,zy,ky;
64
65zx=x;  if (zx<0) zx=0;
66zy=y;  if (zy<0) zy=0;
67kx=x+wr;  if (kx>w) kx=w;
68ky=y+hr;  if (ky>h) ky=h;
69for (i=zy;i<ky;i++)
70        for (j=zx;j<kx;j++)
71                {
72                s[w*i+j].r=d*s[w*i+j].r;
73                s[w*i+j].g=d*s[w*i+j].g;
74                s[w*i+j].b=d*s[w*i+j].b;
75                }
76}
77
78//--------------------------------------------------------
79//uses a 8x16 font from a .xbm image 32 char wide x 3 char high
80void draw_char(float_rgba *sl, int w, int h, int x, int y, unsigned char c, float_rgba col)
81{
82int i,j,z;
83
84if ((c<32)||(c>127)) return;
85if (x<0) return;
86if ((x+8)>=w) return;
87if (y<0) return;
88if ((y+16)>=h)return;
89
90z=(c-32)%32+((c-32)/32)*512;    //position in font image
91
92for (i=0;i<16;i++)
93        for (j=0;j<8;j++)
94                if ((font2_bits[z+32*i]&(1<<j))!=0)
95                        sl[(i+y)*w+j+x]=col;
96
97}
98
99//-----------------------------------------------------------
100void draw_string(float_rgba *sl, int w, int h, int x, int y, char *c, float_rgba col)
101{
102int i;
103
104i=0;
105while (c[i]!=0)
106        {
107        draw_char(sl,w,h,x+8*i,y,c[i],col);
108        i++;
109        }
110}
111
112//--------------------------------------------------------
113//generates format string for 6 chars wide number, right
114//justified
115//p=0 one decimal place    p=1 three decimal places
116//m=1 always show sign
117void forstr(float a, int p, int m, char *s)
118{
119float b;
120char *p3=" %5.3f";
121char *p3m="%+5.3f";
122char *p1=" %5.1f";
123char *p1m1=" %+4.1f";
124char *p1m2="  %+3.1f";
125char *ss;
126
127b=fabsf(a);
128
129if (p==1)
130        {
131        if (m==0) ss=p3; else ss=p3m;
132        }
133else
134        {
135        if (m==0)
136                ss=p1;
137        else
138                {
139                if (b<10.0) ss=p1m2;
140                if ((b>=10.0)&&(b<100.0)) ss=p1m1;
141                ss=p3m;
142                }
143        }
144sprintf(s,"%s",ss);
145}
146
147//-------------------------------------------------------------
148//draws a simple line (no antialiasing)
149//xz,yz=start point
150//xk,yk=end point
151void draw_line(float_rgba *s, int w, int h, int xz, int yz, int xk, int yk, float_rgba c)
152{
153int x,y,d,i;
154
155d =  (abs(xk-xz)>abs(yk-yz)) ? abs(xk-xz) : abs(yk-yz);
156if (d==0) return;
157for (i=0;i<d;i++)
158  {
159  x=xz+(float)i/d*(xk-xz);
160  y=yz+(float)i/d*(yk-yz);
161  if((x>=0)&&(x<w)&&(y>=0)&&(y<h))
162    s[y*w+x]=c;
163  }
164}
165
166//-------------------------------------------------------------
167//mark position of the profile on the image
168void pmarker(float_rgba *s, int w, int h, int xz, int yz, int xk, int yk, int sir, float_rgba c, float m1, float m2)
169{
170float dx,dy,dd;
171float s2,s3,xm,ym;
172
173dx=(float)(xk-xz);
174dy=(float)(yk-yz);
175dd=sqrtf(dx*dx+dy*dy);
176if (dd==0.0) return;
177dx=dx/dd;
178dy=dy/dd;
179
180s2=1.415;
181s3=10.0;
182
183//lower line
184draw_line(s, w, h, xz-s2*dy, yz+s2*dx, xk-s2*dy, yk+s2*dx, c);
185//upper line
186draw_line(s, w, h, xz+s2*dy, yz-s2*dx, xk+s2*dy, yk-s2*dx, c);
187
188//left end mark
189draw_line(s, w, h, xz-s3*dy, yz+s3*dx, xz+s3*dy, yz-s3*dx, c);
190//right end mark
191draw_line(s, w, h, xk+s3*dy, yk-s3*dx, xk-s3*dy, yk+s3*dx, c);
192
193//marker ticks
194s2=2.5;
195if (m1>0.0)
196  {
197  xm=xz+dd*dx*m1;
198  ym=yz+dd*dy*m1;
199  draw_line(s, w, h, xm+s2*dy, ym-s2*dx, xm+s3*dy, ym-s3*dx, c);
200  draw_line(s, w, h, xm-s2*dy, ym+s2*dx, xm-s3*dy, ym+s3*dx, c);
201  }
202if (m2>0.0)
203  {
204  xm=xz+dd*dx*m2;
205  ym=yz+dd*dy*m2;
206  draw_line(s, w, h, xm+s2*dy, ym-s2*dx, xm+s3*dy, ym-s3*dx, c);
207  draw_line(s, w, h, xm-s2*dy, ym+s2*dx, xm-s3*dy, ym+s3*dx, c);
208  }
209}
210
211//--------------------------------------------------------
212//select one of 8 colors for the crosshair
213float_rgba mcolor(int c)
214{
215float_rgba wh={1.0,1.0,1.0,1.0};
216float_rgba ye={1.0,1.0,0.0,1.0};
217float_rgba cy={0.0,1.0,1.0,1.0};
218float_rgba gr={0.0,1.0,0.0,1.0};
219float_rgba mg={1.0,0.0,1.0,1.0};
220float_rgba rd={1.0,0.0,0.0,1.0};
221float_rgba bl={0.0,0.0,1.0,1.0};
222float_rgba bk={0.0,0.0,0.0,1.0};
223
224switch (c)
225  {
226  case 0: return wh;    //white
227  case 1: return ye;    //yellow
228  case 2: return cy;    //cyan
229  case 3: return gr;    //green
230  case 4: return mg;    //magenta
231  case 5: return rd;    //red
232  case 6: return bl;    //blue
233  case 7: return bk;    //black
234  default: return bk;   //black
235  }
236}
237
238//--------------------------------------------------------
239//graph p[], p[]+ofs should be between 0.0 and 1.0
240void draw_trace(float_rgba *s, int w, int h, int x0, int y0, int vx, int vy, float p[], int n, float ofs, float_rgba c)
241{
242int i,x,y,xs,ys;
243
244if (n==0) return;
245xs=x0; ys=y0+vy*(1.0-p[0]-ofs);
246for (i=0;i<n;i++)
247  {
248  x=x0+(i+1)*vx/n;
249  if (x<0) x=0; if (x>=w) x=w-1;
250  y=y0+(vy-1)*(1.0-p[i]-ofs)+1;
251  if (y<y0) y=y0; if (y>=(y0+vy)) y=y0+vy-1; if (y>=h) y=h-1;
252  draw_line(s, w, h, xs, ys, xs, y, c);
253  draw_line(s, w, h, xs, y, x, y, c);
254  xs=x; ys=y;
255  }
256}
257
258//-------------------------------------------------------------
259//numeric display below the "oscilloscope"
260//m=which channel to display (one of seven)
261//dit=what data to display (display items flags)
262//m1,m2 marker positions as indexes into p.x arrays
263//output is written into string *str
264void izpis(profdata p, char *str, int m, int u, int m1, int m2, int dit)
265{
266int i;
267char fs[256],frs[16];
268float data[8];
269
270for (i=0;i<8;i++) data[i]=0;
271
272switch (m>>24)  //select channel  (r,g,b....)  & copy data
273  {
274  case 0:       //display nothing
275    return;
276  case 1:       //display R channel
277    data[0]=p.r[m1]; data[1]=p.r[m2]; data[2]=data[1]-data[0];
278    data[3]=p.sr.avg; data[4]=p.sr.rms; data[5]=p.sr.min;
279    data[6]=p.sr.max;
280    break;
281  case 2:       //display G channel
282    data[0]=p.g[m1]; data[1]=p.g[m2]; data[2]=data[1]-data[0];
283    data[3]=p.sg.avg; data[4]=p.sg.rms; data[5]=p.sg.min;
284    data[6]=p.sg.max;
285    break;
286  case 3:       //display B channel
287    data[0]=p.b[m1]; data[1]=p.b[m2]; data[2]=data[1]-data[0];
288    data[3]=p.sb.avg; data[4]=p.sb.rms; data[5]=p.sb.min;
289    data[6]=p.sb.max;
290    break;
291  case 4:       //display Y channel
292    data[0]=p.y[m1]; data[1]=p.y[m2]; data[2]=data[1]-data[0];
293    data[3]=p.sy.avg; data[4]=p.sy.rms; data[5]=p.sy.min;
294    data[6]=p.sy.max;
295    break;
296  case 5:       //display Pr channel
297    data[0]=p.u[m1]; data[1]=p.u[m2]; data[2]=data[1]-data[0];
298    data[3]=p.su.avg; data[4]=p.su.rms; data[5]=p.su.min;
299    data[6]=p.su.max;
300    break;
301  case 6:       //display Pb channel
302    data[0]=p.v[m1]; data[1]=p.v[m2]; data[2]=data[1]-data[0];
303    data[3]=p.sv.avg; data[4]=p.sv.rms; data[5]=p.sv.min;
304    data[6]=p.sv.max;
305    break;
306  case 7:       //display alpha channel
307    data[0]=p.a[m1]; data[1]=p.a[m2]; data[2]=data[1]-data[0];
308    data[3]=p.sa.avg; data[4]=p.sa.rms; data[5]=p.sa.min;
309    data[6]=p.sa.max;
310    break;
311  default:
312    break;
313  }
314
315if (u!=0) for (i=0;i<256;i++) data[i]=data[i]*255.0;
316
317for (i=0;i<256;i++) {fs[i]=0; str[i]=0;}
318if ((dit&0x00000001)!=0)        //marker 1 value
319  {
320  if (m1>=0)
321    {
322    forstr(data[0],1-u,0,frs);
323    sprintf(fs,"%%s Mk1=%s", frs);
324    sprintf(str,fs,str,data[0]);
325    }
326  else
327    sprintf(str,"%s %s",str,"Mk1= -----");
328  }
329if ((dit&0x00000004)!=0)        //marker 2 value
330  {
331  if (m2>=0)
332    {
333    forstr(data[1],1-u,0,frs);
334    sprintf(fs,"%%s Mk2=%s", frs);
335    sprintf(str,fs,str,data[1]);
336    }
337  else
338    sprintf(str,"%s %s",str,"Mk2= -----");
339  }
340if ((dit&0x00000010)!=0)        //difference marker2-marker1
341  {
342  if ((m2>=0)&&(m1>=0))
343    {
344    forstr(data[2],1-u,0,frs);
345    sprintf(fs,"%%s D=%s", frs);
346    sprintf(str,fs,str,data[2]);
347    }
348  else
349    sprintf(str,"%s %s",str,"D= -----");
350  }
351if ((dit&0x00000020)!=0)        //average of profile
352  {
353  forstr(data[3],1-u,0,frs);
354  sprintf(fs,"%%s Avg=%s", frs);
355  sprintf(str,fs,str,data[3]);
356  }
357if ((dit&0x00000040)!=0)        //RMS of profile
358  {
359  forstr(data[4],1-u,0,frs);
360  sprintf(fs,"%%s RMS=%s", frs);
361  sprintf(str,fs,str,data[4]);
362  }
363if ((dit&0x00000080)!=0)        //MIN of profile
364  {
365  forstr(data[5],1-u,0,frs);
366  sprintf(fs,"%%s Min=%s", frs);
367  sprintf(str,fs,str,data[5]);
368  }
369if ((dit&0x00000100)!=0)        //MAX of profile
370  {
371  forstr(data[6],1-u,0,frs);
372  sprintf(fs,"%%s Max=%s", frs);
373  sprintf(str,fs,str,data[6]);
374  }
375}
376
377//--------------------------------------------------------------
378//draw info window
379//sx,sy=size of probe   (must be odd)
380//poz=position of info window   0=left   1=right
381//m=measurement channel, trace/numeric display
382//u=units    0=0.0-1.0    1=0-255
383//as = auto scale
384//m1,m2=marker positions
385//dit=display items flags
386//cc=crosshair color [0...7]
387//cm=0 rec 601, cm=1 rec 709
388void prof(float_rgba *s, int w, int h, int *poz, int x, int y, float tilt, int len, int sir, int m, int u, int as, int m1, int m2, int dit, int cc, int cm, profdata *p)
389{
390int x0,y0,vx,vy;
391int xz,xk,yz,yk;        //zacetna in koncna tocka
392char string[256];
393int i,sl;
394float_rgba white={1.0,1.0,1.0,1.0};
395float_rgba lgray={0.7,0.7,0.7,1.0};
396float_rgba gray={0.5,0.5,0.5,1.0};
397float_rgba dgray={0.3,0.3,0.3,1.0};
398float_rgba red={1.0,0.0,0.0,1.0};
399float_rgba dgreen={0.0,0.7,0.0,1.0};
400float_rgba lblue={0.3,0.3,1.0,1.0};
401float_rgba yellow={0.7,0.7,0.0,1.0};
402float_rgba pink={0.8,0.4,0.5,1.0};
403float_rgba magenta={0.8,0.0,0.8,1.0};
404float_rgba cyan={0.0,0.7,0.8,1.0};
405
406//position and size of info window
407if (y<h/2-20) *poz=1;   //bottom
408if (y>h/2+20) *poz=0;   //top
409x0=h/20;
410vx=w*15/16;
411vy = h*6/16;
412y0 = (*poz==0) ? h/20 : h-h/20-vy;
413
414//end points of profile
415xz=x-len/2.0*cosf(tilt);
416xk=x+len/2.0*cosf(tilt);
417yz=y-len/2.0*sinf(tilt);
418yk=y+len/2.0*sinf(tilt);
419
420//measure
421meriprof(s, w, h, xz, yz, xk, yk, sir, p);
422prof_yuv(p,cm);
423prof_stat(p);
424
425//draw crosshair
426pmarker(s, w, h, xz, yz, xk, yk, sir, mcolor(cc), (float)m1/p->n, (float)m2/p->n);
427
428//info window background
429darken_rectangle(s, w, h, x0, y0, vx, vy, 0.4);
430
431//draw scope
432//background
433//draw_rectangle(s, w, h, x0+50, y0+5, vx-55, vy-40, black);
434//grid
435yz=y0+6; yk=y0+vy-36;
436for (i=0;i<9;i++)
437  {
438  xz=x0+49+(i+1)*(vx-55)/10;
439  draw_line(s, w, h, xz, yz, xz, yk, dgray);
440  }
441xz=x0+50;xk=x0+vx-6;
442for (i=0;i<3;i++)
443  {
444  yz=y0+5+(i+1)*(vy-40)/4;
445  draw_line(s, w, h, xz, yz, xk, yz, dgray);
446  }
447//traces
448if ((m&0x00000001)!=0)          //R
449  draw_trace(s, w, h, x0+50, y0+5, vx-55, vy-40, p->r, p->n, 0.0, red);
450if ((m&0x00000002)!=0)          //G
451  draw_trace(s, w, h, x0+50, y0+5, vx-55, vy-40, p->g, p->n, 0.0, dgreen);
452if ((m&0x00000004)!=0)          //B
453  draw_trace(s, w, h, x0+50, y0+5, vx-55, vy-40, p->b, p->n, 0.0, lblue);
454if ((m&0x00000008)!=0)          //Y
455  draw_trace(s, w, h, x0+50, y0+5, vx-55, vy-40, p->y, p->n, 0.0, lgray);
456if ((m&0x00000010)!=0)          //Pr
457  draw_trace(s, w, h, x0+50, y0+5, vx-55, vy-40, p->u, p->n, 0.5, magenta);
458if ((m&0x00000020)!=0)          //Pb
459  draw_trace(s, w, h, x0+50, y0+5, vx-55, vy-40, p->v, p->n, 0.5, cyan);
460if ((m&0x00000040)!=0)          //alpha
461  draw_trace(s, w, h, x0+50, y0+5, vx-55, vy-40, p->a, p->n, 0.0, gray);
462//markers
463if ((m1>=0)&&(m1<p->n))
464  {
465  draw_line(s, w, h, x0+50+(m1+0.5)*(vx-55)/p->n, y0+5, x0+50+(m1+0.5)*(vx-55)/p->n, y0+vy-35, yellow);
466  }
467if ((m2>=0)&&(m2<p->n))
468  {
469  draw_line(s, w, h, x0+50+(m2+0.5)*(vx-55)/p->n, y0+5, x0+50+(m2+0.5)*(vx-55)/p->n, y0+vy-35, pink);
470  }
471//frame
472draw_line(s, w, h, x0+49, y0+5, x0+vx-5, y0+5, gray);
473draw_line(s, w, h, x0+49, y0+vy-35, x0+vx-5, y0+vy-35, gray);
474draw_line(s, w, h, x0+49, y0+5, x0+49, y0+vy-35, gray);
475draw_line(s, w, h, x0+vx-5, y0+5, x0+vx-5, y0+vy-35, gray);
476
477//numeric display
478izpis(*p,string,m,u,m1,m2,dit);
479sl=strlen(string);
480if (sl>((vx-55)/8))
481  {
482  sprintf(string,"<- NOT ENOUGH SPACE ->");
483  draw_string(s, w, h, x0+vx/2-88, y0+vy-25, string, white);
484  return;
485  }
486switch (m>>24)  //which channel data under the scope
487  {
488  case 0:
489    break;
490  case 1:
491    draw_string(s, w, h, x0+20, y0+vy-25, "R", red);
492    draw_string(s, w, h, x0+60, y0+vy-25, string, red);
493    break;
494  case 2:
495    draw_string(s, w, h, x0+20, y0+vy-25, "G", dgreen);
496    draw_string(s, w, h, x0+60, y0+vy-25, string, dgreen);
497    break;
498  case 3:
499    draw_string(s, w, h, x0+20, y0+vy-25, "B", lblue);
500    draw_string(s, w, h, x0+60, y0+vy-25, string, lblue);
501    break;
502  case 4:
503    draw_string(s, w, h, x0+20, y0+vy-25, "Y", lgray);
504    draw_string(s, w, h, x0+60, y0+vy-25, string, lgray);
505    break;
506  case 5:
507    draw_string(s, w, h, x0+20, y0+vy-25, "Pr", magenta);
508    draw_string(s, w, h, x0+60, y0+vy-25, string, magenta);
509    break;
510  case 6:
511    draw_string(s, w, h, x0+20, y0+vy-25, "Pb", cyan);
512    draw_string(s, w, h, x0+60, y0+vy-25, string, cyan);
513    break;
514  case 7:
515    draw_string(s, w, h, x0+20, y0+vy-25, "a", gray);
516    draw_string(s, w, h, x0+60, y0+vy-25, string, gray);
517    break;
518  default:
519    break;
520  }
521
522}
523
524//-----------------------------------------------------
525//converts the internal RGBA float image into
526//Frei0r rgba8888 color
527void floatrgba2color(float_rgba *sl, uint32_t* outframe, int w , int h)
528{
529int i;
530uint32_t p;
531
532for (i=0;i<w*h;i++)
533        {
534        p=(uint32_t)(255.0*sl[i].a) & 0xFF;
535        p=(p<<8) + ((uint32_t)(255.0*sl[i].b) & 0xFF);
536        p=(p<<8) + ((uint32_t)(255.0*sl[i].g) & 0xFF);
537        p=(p<<8) + ((uint32_t)(255.0*sl[i].r) & 0xFF);
538        outframe[i]=p;
539        }
540}
541
542//-----------------------------------------------------
543//converts the Frei0r rgba8888 color image into
544//internal float RGBA
545void color2floatrgba(uint32_t* inframe, float_rgba *sl, int w , int h)
546{
547int i;
548
549for (i=0;i<w*h;i++)
550        {
551        sl[i].r=((float)(inframe[i] & 0x000000FF))*0.00392157;
552        sl[i].g=((float)((inframe[i] & 0x0000FF00)>>8))*0.00392157;
553        sl[i].b=((float)((inframe[i] & 0x00FF0000)>>16))*0.00392157;
554        sl[i].a=((float)((inframe[i] & 0xFF000000)>>24))*0.00392157;
555        }
556}
557
558//-----------------------------------------------------
559//stretch [0...1] to parameter range [min...max] linear
560float map_value_forward(double v, float min, float max)
561{
562return min+(max-min)*v;
563}
564
565//-----------------------------------------------------
566//collapse from parameter range [min...max] to [0...1] linear
567double map_value_backward(float v, float min, float max)
568{
569return (v-min)/(max-min);
570}
571
572//----------------------------------------
573//struktura za instanco efekta
574typedef struct
575{
576int h;
577int w;
578
579int x;          //horizontal position
580int y;          //vertical position
581float tilt;     //tilt of profile
582int len;        //length of profile
583int chn;        //channel for numeric display
584int m1;         //marker 1 position along profile
585int m2;         //marker 2 position along profile
586int rt;         //show r trace          BOOL
587int gt;         //show g trace          BOOL
588int bt;         //show b trace          BOOL
589int yt;         //show Y' trace         BOOL
590int ut;         //show Pr trace         BOOL
591int vt;         //show Pb trace         BOOL
592int at;         //show alpha trace      BOOL
593int davg;       //display average       BOOL
594int drms;       //display rms           BOOL
595int dmin;       //display minimum       BOOL
596int dmax;       //display maximum       BOOL
597int un;         //0...255 units         BOOL
598int col;        //color, rec 601 or rec 709
599int chc;        //crosshair color  [0...7]
600
601int poz;
602int mer;        //display channel + trace flags
603int dit;        //numeric display items flags
604
605float_rgba *sl;
606profdata *p;
607
608} inst;
609
610//***********************************************
611// OBVEZNE FREI0R FUNKCIJE
612
613//-----------------------------------------------
614int f0r_init()
615{
616return 1;
617}
618
619//------------------------------------------------
620void f0r_deinit()
621{
622}
623
624//-----------------------------------------------
625void f0r_get_plugin_info(f0r_plugin_info_t* info)
626{
627
628info->name="pr0file";
629info->author="Marko Cebokli";
630info->plugin_type=F0R_PLUGIN_TYPE_FILTER;
631info->color_model=F0R_COLOR_MODEL_RGBA8888;
632info->frei0r_version=FREI0R_MAJOR_VERSION;
633info->major_version=0;
634info->minor_version=1;
635info->num_params=21;
636info->explanation="2D video oscilloscope";
637}
638
639//--------------------------------------------------
640void f0r_get_param_info(f0r_param_info_t* info, int param_index)
641{
642
643switch(param_index)
644        {
645        case 0:
646                info->name = "X";
647                info->type = F0R_PARAM_DOUBLE;
648                info->explanation = "X position of profile";
649                break;
650        case 1:
651                info->name = "Y";
652                info->type = F0R_PARAM_DOUBLE;
653                info->explanation = "Y position of profile";
654                break;
655        case 2:
656                info->name = "Tilt";
657                info->type = F0R_PARAM_DOUBLE;
658                info->explanation = "Tilt of profile";
659                break;
660        case 3:
661                info->name = "Length";
662                info->type = F0R_PARAM_DOUBLE;
663                info->explanation = "Length of profile";
664                break;
665        case 4:
666                info->name = "Channel";
667                info->type = F0R_PARAM_DOUBLE;
668                info->explanation = "Channel to numerically display";
669                break;
670        case 5:
671                info->name = "Marker 1";
672                info->type = F0R_PARAM_DOUBLE;
673                info->explanation = "Position of marker 1";
674                break;
675        case 6:
676                info->name = "Marker 2";
677                info->type = F0R_PARAM_DOUBLE;
678                info->explanation = "Position of marker 2";
679                break;
680        case 7:
681                info->name = "R trace";
682                info->type = F0R_PARAM_BOOL;
683                info->explanation = "Show R trace on scope";
684                break;
685        case 8:
686                info->name = "G trace";
687                info->type = F0R_PARAM_BOOL;
688                info->explanation = "Show G trace on scope";
689                break;
690        case 9:
691                info->name = "B trace";
692                info->type = F0R_PARAM_BOOL;
693                info->explanation = "Show B trace on scope";
694                break;
695        case 10:
696                info->name = "Y trace";
697                info->type = F0R_PARAM_BOOL;
698                info->explanation = "Show Y' trace on scope";
699                break;
700        case 11:
701                info->name = "Pr trace";
702                info->type = F0R_PARAM_BOOL;
703                info->explanation = "Show Pr trace on scope";
704                break;
705        case 12:
706                info->name = "Pb trace";
707                info->type = F0R_PARAM_BOOL;
708                info->explanation = "Show Pb trace on scope";
709                break;
710        case 13:
711                info->name = "Alpha trace";
712                info->type = F0R_PARAM_BOOL;
713                info->explanation = "Show Alpha trace on scope";
714                break;
715        case 14:
716                info->name = "Display average";
717                info->type = F0R_PARAM_BOOL;
718                info->explanation = "e";
719                break;
720        case 15:
721                info->name = "Display RMS";
722                info->type = F0R_PARAM_BOOL;
723                info->explanation = "";
724                break;
725        case 16:
726                info->name = "Display minimum";
727                info->type = F0R_PARAM_BOOL;
728                info->explanation = "";
729                break;
730        case 17:
731                info->name = "Display maximum";
732                info->type = F0R_PARAM_BOOL;
733                info->explanation = "";
734                break;
735        case 18:
736                info->name = "256 scale";
737                info->type = F0R_PARAM_BOOL;
738                info->explanation = "use 0-255 instead of 0.0-1.0";
739                break;
740        case 19:
741                info->name = "Color";
742                info->type = F0R_PARAM_DOUBLE;
743                info->explanation = "rec 601 or rec 709";
744                break;
745        case 20:
746                info->name = "Crosshair color";
747                info->type = F0R_PARAM_DOUBLE;
748                info->explanation = "Color of the profile marker";
749                break;
750        }
751}
752
753//----------------------------------------------
754f0r_instance_t f0r_construct(unsigned int width, unsigned int height)
755{
756inst *in;
757
758in=calloc(1,sizeof(inst));
759in->w=width;
760in->h=height;
761
762in->x=width/2;
763in->y=height/2;
764in->tilt=0.0;
765in->len=3*width/4;
766in->chn=3;
767in->m1=-1;
768in->m2=-1;
769in->rt=1;
770in->gt=1;
771in->bt=1;
772in->yt=0;
773in->ut=0;
774in->vt=0;
775in->at=0;
776in->davg=1;
777in->drms=1;
778in->dmin=0;
779in->dmax=0;
780in->un=0;
781in->col=0;
782in->chc=0;
783
784in->poz=1;
785in->mer=(3<<24)+7;      //Y display + R,G,B traces
786in->dit=32+64;          //avg+RMS
787
788in->sl=(float_rgba*)calloc(width*height,sizeof(float_rgba));
789in->p=(profdata*)calloc(1,sizeof(profdata));
790
791in->p->n=5;
792
793return (f0r_instance_t)in;
794}
795
796//---------------------------------------------------
797void f0r_destruct(f0r_instance_t instance)
798{
799inst *in;
800
801in=(inst*)instance;
802
803free(in->sl);
804free(in->p);
805free(instance);
806}
807
808//-----------------------------------------------------
809void f0r_set_param_value(f0r_instance_t instance, f0r_param_t parm, int param_index)
810{
811inst *p;
812double tmpf;
813int tmpi,chg;
814
815p=(inst*)instance;
816
817chg=0;
818switch(param_index)
819        {
820        case 0:         //X
821                tmpi=map_value_forward(*((double*)parm), 0.0, p->w);
822                if (tmpi != p->x) chg=1;
823                p->x=tmpi;
824                break;
825        case 1:         //Y
826                tmpi=map_value_forward(*((double*)parm), 0.0, p->h);
827                if (tmpi != p->y) chg=1;
828                p->y=tmpi;
829                break;
830        case 2:         //tilt
831                tmpf=map_value_forward(*((double*)parm), -PI/2.0, PI/2.0);
832                if (tmpf != p->tilt) chg=1;
833                p->tilt=tmpf;
834                break;
835        case 3:         //length
836                tmpi=map_value_forward(*((double*)parm), 20.0, sqrtf(p->w*p->w+p->h*p->h));
837                if (tmpi != p->len) chg=1;
838                p->len=tmpi;
839                break;
840        case 4:         //channel
841                tmpi=map_value_forward(*((double*)parm), 1.0, 7.9999);
842                if (tmpi != p->chn) chg=1;
843                p->chn=tmpi;
844                break;
845        case 5:         //marker 1
846                tmpi=map_value_forward(*((double*)parm), -1.0, p->p->n);
847                if (tmpi != p->m1) chg=1;
848                p->m1=tmpi;
849                break;
850        case 6:         //marker 2
851                tmpi=map_value_forward(*((double*)parm), -1.0, p->p->n);
852                if (tmpi != p->m2) chg=1;
853                p->m2=tmpi;
854                break;
855        case 7:         //R trace
856                tmpi=map_value_forward(*((double*)parm), 0.0, 1.0); //BOOL!!
857                if (p->rt != tmpi) chg=1;
858                p->rt=tmpi;
859                break;
860        case 8:         //G trace
861                tmpi=map_value_forward(*((double*)parm), 0.0, 1.0); //BOOL!!
862                if (p->gt != tmpi) chg=1;
863                p->gt=tmpi;
864                break;
865        case 9:         //B trace
866                tmpi=map_value_forward(*((double*)parm), 0.0, 1.0); //BOOL!!
867                if (p->bt != tmpi) chg=1;
868                p->bt=tmpi;
869                break;
870        case 10:        //Y trace
871                tmpi=map_value_forward(*((double*)parm), 0.0, 1.0); //BOOL!!
872                if (p->yt != tmpi) chg=1;
873                p->yt=tmpi;
874                break;
875        case 11:        //U trace
876                tmpi=map_value_forward(*((double*)parm), 0.0, 1.0); //BOOL!!
877                if (p->ut != tmpi) chg=1;
878                p->ut=tmpi;
879                break;
880        case 12:        //V trace
881                tmpi=map_value_forward(*((double*)parm), 0.0, 1.0); //BOOL!!
882                if (p->vt != tmpi) chg=1;
883                p->vt=tmpi;
884                break;
885        case 13:        //alpha trace
886                tmpi=map_value_forward(*((double*)parm), 0.0, 1.0); //BOOL!!
887                if (p->at != tmpi) chg=1;
888                p->at=tmpi;
889                break;
890        case 14:        //display avg
891                tmpi=map_value_forward(*((double*)parm), 0.0, 1.0); //BOOL!!
892                if (p->davg != tmpi) chg=1;
893                p->davg=tmpi;
894                break;
895        case 15:        //display RMS
896                tmpi=map_value_forward(*((double*)parm), 0.0, 1.0); //BOOL!!
897                if (p->drms != tmpi) chg=1;
898                p->drms=tmpi;
899                break;
900        case 16:        //display min
901                tmpi=map_value_forward(*((double*)parm), 0.0, 1.0); //BOOL!!
902                if (p->dmin != tmpi) chg=1;
903                p->dmin=tmpi;
904                break;
905        case 17:        //display max
906                tmpi=map_value_forward(*((double*)parm), 0.0, 1.0); //BOOL!!
907                if (p->dmax != tmpi) chg=1;
908                p->dmax=tmpi;
909                break;
910        case 18:        //256 units
911                tmpi=map_value_forward(*((double*)parm), 0.0, 1.0); //BOOL!!
912                if (p->un != tmpi) chg=1;
913                p->un=tmpi;
914                break;
915        case 19:        //color mode
916                tmpi=map_value_forward(*((double*)parm), 0.0, 1.9999);
917                if (p->col != tmpi) chg=1;
918                p->col=tmpi;
919                break;
920        case 20:        //Crosshair color
921                tmpi=map_value_forward(*((double*)parm), 0.0, 7.9999);
922                if (p->chc != tmpi) chg=1;
923                p->chc=tmpi;
924                break;
925        }
926
927if (chg==0) return;
928
929p->mer=p->chn<<24;
930p->mer=p->mer+p->rt;
931p->mer=p->mer+2*p->gt;
932p->mer=p->mer+4*p->bt;
933p->mer=p->mer+8*p->yt;
934p->mer=p->mer+16*p->ut;
935p->mer=p->mer+32*p->vt;
936p->mer=p->mer+64*p->at;
937
938p->dit=0;
939if (p->m1>=0) p->dit=p->dit+1;
940if (p->m2>=0) p->dit=p->dit+4;
941if ((p->m1>=0)&&(p->m2>=0)) p->dit=p->dit+16;
942p->dit=p->dit+32*p->davg;
943p->dit=p->dit+64*p->drms;
944p->dit=p->dit+128*p->dmin;
945p->dit=p->dit+256*p->dmax;
946
947}
948
949//--------------------------------------------------
950void f0r_get_param_value(f0r_instance_t instance, f0r_param_t param, int param_index)
951{
952inst *p;
953double tmpf;
954int tmpi;
955
956p=(inst*)instance;
957
958switch(param_index)
959        {
960        case 0:
961                *((double*)param)=map_value_backward(p->x, 0.0, p->w);
962                break;
963        case 1:
964                *((double*)param)=map_value_backward(p->y, 0.0, p->h);
965                break;
966        case 2:
967                *((double*)param)=map_value_backward(p->tilt, -PI/2.0, PI/2.0);
968                break;
969        case 3:
970                *((double*)param)=map_value_backward(p->len, 20.0, sqrtf(p->w*p->w+p->h*p->h));
971                break;
972        case 4:
973                *((double*)param)=map_value_backward(p->chn, 0.0, 7.9999);
974                break;
975        case 5:
976                *((double*)param)=map_value_backward(p->m1, 0.0, p->p->n);
977                break;
978        case 6:
979                *((double*)param)=map_value_backward(p->m2, 0.0, p->p->n);
980                break;
981        case 7:
982                *((double*)param)=map_value_backward(p->rt, 0.0, 1.0);//BOOL!!
983                break;
984        case 8:
985                *((double*)param)=map_value_backward(p->gt, 0.0, 1.0);//BOOL!!
986                break;
987        case 9:
988                *((double*)param)=map_value_backward(p->bt, 0.0, 1.0);//BOOL!!
989                break;
990        case 10:
991                *((double*)param)=map_value_backward(p->yt, 0.0, 1.0);//BOOL!!
992                break;
993        case 11:
994                *((double*)param)=map_value_backward(p->ut, 0.0, 1.0);//BOOL!!
995                break;
996        case 12:
997                *((double*)param)=map_value_backward(p->vt, 0.0, 1.0);//BOOL!!
998                break;
999        case 13:
1000                *((double*)param)=map_value_backward(p->at, 0.0, 1.0);//BOOL!!
1001                break;
1002        case 14:
1003                *((double*)param)=map_value_backward(p->davg, 0.0, 1.0);//BOOL!!
1004                break;
1005        case 15:
1006                *((double*)param)=map_value_backward(p->drms, 0.0, 1.0);//BOOL!!
1007                break;
1008        case 16:
1009                *((double*)param)=map_value_backward(p->dmin, 0.0, 1.0);//BOOL!!
1010                break;
1011        case 17:
1012                *((double*)param)=map_value_backward(p->dmax, 0.0, 1.0);//BOOL!!
1013                break;
1014        case 18:
1015                *((double*)param)=map_value_backward(p->un, 0.0, 1.0);//BOOL!!
1016                break;
1017        case 19:
1018                *((double*)param)=map_value_backward(p->col, 0.0, 1.9999);
1019                break;
1020        case 20:
1021                *((double*)param)=map_value_backward(p->chc, 0.0, 7.9999);
1022                break;
1023        }
1024}
1025
1026//-------------------------------------------------
1027void f0r_update(f0r_instance_t instance, double time, const uint32_t* inframe, uint32_t* outframe)
1028{
1029inst *in;
1030float l;
1031unsigned char lc;
1032int i;
1033
1034assert(instance);
1035in=(inst*)instance;
1036
1037color2floatrgba(inframe, in->sl, in->w , in->h);
1038
1039prof(in->sl, in->w, in->h, &in->poz, in->x, in->y, in->tilt, in->len, 1, in->mer, in->un, 0, in->m1, in->m2, in->dit, in->chc, in->col, in->p);
1040
1041floatrgba2color(in->sl, outframe, in->w , in->h);
1042}
1043
Note: See TracBrowser for help on using the repository browser.