| 1 | /* |
| 2 | pr0be.c |
| 3 | |
| 4 | This frei0r plugin measures pixels in video |
| 5 | Version 0.1 jun 2010 |
| 6 | |
| 7 | Copyright (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 pr0be.c -o pr0be.o |
| 27 | //link: gcc -shared -o pr0be.so pr0be.o |
| 28 | |
| 29 | #include <stdio.h> |
| 30 | #include <frei0r.h> |
| 31 | #include <stdlib.h> |
| 32 | #include <math.h> |
| 33 | #include <assert.h> |
| 34 | |
| 35 | #include "font2.h" |
| 36 | #include "measure.h" |
| 37 | |
| 38 | double PI=3.14159265358979; |
| 39 | |
| 40 | //--------------------------------------------------------------- |
| 41 | static inline void draw_rectangle(float_rgba *s, int w, int h, float x, float y, float wr, float hr, float_rgba c) |
| 42 | { |
| 43 | int i,j; |
| 44 | int zx,kx,zy,ky; |
| 45 | |
| 46 | zx=x; if (zx<0) zx=0; |
| 47 | zy=y; if (zy<0) zy=0; |
| 48 | kx=x+wr; if (kx>w) kx=w; |
| 49 | ky=y+hr; if (ky>h) ky=h; |
| 50 | for (i=zy;i<ky;i++) |
| 51 | for (j=zx;j<kx;j++) |
| 52 | s[w*i+j]=c; |
| 53 | |
| 54 | } |
| 55 | |
| 56 | //--------------------------------------------------------------- |
| 57 | //d=dim value 0.0=black 1.0=no dimming |
| 58 | void darken_rectangle(float_rgba *s, int w, int h, float x, float y, float wr, float hr, float d) |
| 59 | { |
| 60 | int i,j; |
| 61 | int zx,kx,zy,ky; |
| 62 | |
| 63 | zx=x; if (zx<0) zx=0; |
| 64 | zy=y; if (zy<0) zy=0; |
| 65 | kx=x+wr; if (kx>w) kx=w; |
| 66 | ky=y+hr; if (ky>h) ky=h; |
| 67 | for (i=zy;i<ky;i++) |
| 68 | for (j=zx;j<kx;j++) |
| 69 | { |
| 70 | s[w*i+j].r=d*s[w*i+j].r; |
| 71 | s[w*i+j].g=d*s[w*i+j].g; |
| 72 | s[w*i+j].b=d*s[w*i+j].b; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | //-------------------------------------------------------- |
| 77 | //uses a 8x16 font from a .xbm image 32 char wide x 3 char high |
| 78 | void draw_char(float_rgba *sl, int w, int h, int x, int y, unsigned char c, float_rgba col) |
| 79 | { |
| 80 | int i,j,z; |
| 81 | |
| 82 | if ((c<32)||(c>127)) return; |
| 83 | if (x<0) return; |
| 84 | if ((x+8)>=w) return; |
| 85 | if (y<0) return; |
| 86 | if ((y+16)>=h)return; |
| 87 | |
| 88 | z=(c-32)%32+((c-32)/32)*512; |
| 89 | |
| 90 | for (i=0;i<16;i++) |
| 91 | for (j=0;j<8;j++) |
| 92 | if ((font2_bits[z+32*i]&(1<<j))!=0) |
| 93 | sl[(i+y)*w+j+x]=col; |
| 94 | |
| 95 | } |
| 96 | |
| 97 | //----------------------------------------------------------- |
| 98 | void draw_string(float_rgba *sl, int w, int h, int x, int y, char *c, float_rgba col) |
| 99 | { |
| 100 | int i; |
| 101 | |
| 102 | i=0; |
| 103 | while (c[i]!=0) |
| 104 | { |
| 105 | draw_char(sl,w,h,x+8*i,y,c[i],col); |
| 106 | i++; |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | //---------------------------------------------------------- |
| 111 | //marker (crosshair) |
| 112 | //v=size of cross legs |
| 113 | void crosshair(float_rgba *s, int w, int h, int x, int y, int sx, int sy, int v) |
| 114 | { |
| 115 | float x1,y1; |
| 116 | float_rgba white={1.0,1.0,1.0,1.0}; |
| 117 | float_rgba black={0.0,0.0,0.0,1.0}; |
| 118 | |
| 119 | x1=x-1; y1=y-v-sy/2; |
| 120 | draw_rectangle(s, w, h, x1, y1, 3, v, white); //top |
| 121 | draw_rectangle(s, w, h, x-sx/2, y-sy/2, sx, 1, white); |
| 122 | draw_rectangle(s, w, h, x1+1, y1, 1, v, black); |
| 123 | x1=x-v-sx/2; y1=y-1; |
| 124 | draw_rectangle(s, w, h, x1, y1, v, 3, white); //left |
| 125 | draw_rectangle(s, w, h, x-sx/2, y-sy/2, 1, sy, white); |
| 126 | draw_rectangle(s, w, h, x1, y1+1, v, 1, black); |
| 127 | x1=x-1; y1=y+sy/2+1; |
| 128 | draw_rectangle(s, w, h, x1, y1, 3, v, white); //bottom |
| 129 | draw_rectangle(s, w, h, x-sx/2, y+sy/2, sx, 1, white); |
| 130 | draw_rectangle(s, w, h, x1+1, y1, 1, v, black); |
| 131 | x1=x+sx/2+1; y1=y-1; |
| 132 | draw_rectangle(s, w, h, x1, y1, v, 3, white); //right |
| 133 | draw_rectangle(s, w, h, x+sx/2, y-sy/2, 1, sy, white); |
| 134 | draw_rectangle(s, w, h, x1, y1+1, v, 1, black); |
| 135 | } |
| 136 | |
| 137 | //-------------------------------------------------------- |
| 138 | //generates format string for 6 chars wide number, right |
| 139 | //justified |
| 140 | //p=0 one decimal place p=1 three decimal places |
| 141 | //m=1 always show sign |
| 142 | inline static void forstr(float a, int p, int m, char *s) |
| 143 | { |
| 144 | float b; |
| 145 | char *p3=" %5.3f"; |
| 146 | char *p3m="%+5.3f"; |
| 147 | char *p1=" %5.1f"; |
| 148 | char *p1m1=" %+4.1f"; |
| 149 | char *p1m2=" %+3.1f"; |
| 150 | char *ss; |
| 151 | |
| 152 | b=fabsf(a); |
| 153 | |
| 154 | if (p==1) |
| 155 | { |
| 156 | if (m==0) ss=p3; else ss=p3m; |
| 157 | } |
| 158 | else |
| 159 | { |
| 160 | if (m==0) |
| 161 | ss=p1; |
| 162 | else |
| 163 | { |
| 164 | if (b<10.0) ss=p1m2; |
| 165 | if ((b>=10.0)&&(b<100.0)) ss=p1m1; |
| 166 | ss=p3m; |
| 167 | } |
| 168 | } |
| 169 | sprintf(s,"%s",ss); |
| 170 | } |
| 171 | |
| 172 | //------------------------------------------------------------- |
| 173 | //print avg,rms,min,max into a string |
| 174 | //u=units 0=0.0-1.0 1=0-255 |
| 175 | //m=sign 0=unsigned |
| 176 | //mm=1 print min/max |
| 177 | void izpis(char *str, char *lab, stat s, int u, int m, int mm) |
| 178 | { |
| 179 | char fs[256],as[16],rs[16],ns[16],xs[16]; |
| 180 | |
| 181 | if (u==1) |
| 182 | { |
| 183 | s.avg=255.0*s.avg; |
| 184 | s.rms=255.0*s.rms; |
| 185 | s.min=255.0*s.min; |
| 186 | s.max=255.0*s.max; |
| 187 | } |
| 188 | |
| 189 | if (mm==1) |
| 190 | { |
| 191 | forstr(s.avg,1-u,m,as); |
| 192 | forstr(s.rms,1-u,0,rs); |
| 193 | forstr(s.min,1-u,m,ns); |
| 194 | forstr(s.max,1-u,m,xs); |
| 195 | snprintf(fs,255,"%s%s%s %s%s", lab, as, rs, ns, xs); |
| 196 | sprintf(str,fs,s.avg,s.rms,s.min,s.max); |
| 197 | } |
| 198 | else |
| 199 | { |
| 200 | forstr(s.avg,1-u,m,as); |
| 201 | forstr(s.rms,1-u,0,rs); |
| 202 | snprintf(fs,255,"%s%s%s", lab, as, rs); |
| 203 | sprintf(str,fs,s.avg,s.rms); |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | //----------------------------------------------------------- |
| 208 | //probe size markers in the magnifier display |
| 209 | void sxmarkers(float_rgba *s, int w, int h, int x0, int y0, int np, int sx, int sy, int vp) |
| 210 | { |
| 211 | int np2,x,y,i,j; |
| 212 | float_rgba white={1.0,1.0,1.0,1.0}; |
| 213 | |
| 214 | np2=np/2+1; |
| 215 | |
| 216 | //top left |
| 217 | x=x0+(np2-sx/2)*vp-1; if (sx>np) x=x0; |
| 218 | y=y0+(np2-sy/2)*vp-1; if (sy>np) y=y0; |
| 219 | if (sx<=np) draw_rectangle(s, w, h, x, y, 1, vp, white); |
| 220 | if (sy<=np) draw_rectangle(s, w, h, x, y, vp, 1, white); |
| 221 | //top right |
| 222 | x=x0+(np2+sx/2+1)*vp-1; |
| 223 | y=y0+(np2-sy/2)*vp-1; if (sy>np) y=y0; |
| 224 | if (sx<=np) draw_rectangle(s, w, h, x, y, 1, vp, white); |
| 225 | x=x0+(np2+sx/2)*vp; |
| 226 | y=y0+(np2-sy/2)*vp-1; if (sx>np) x=x0+(np+1)*vp-1; |
| 227 | if (sy<=np) draw_rectangle(s, w, h, x, y, vp, 1, white); |
| 228 | //bottom left |
| 229 | x=x0+(np2-sx/2)*vp-1; |
| 230 | y=y0+(np2+sy/2)*vp; if (sy>np) y=y0+(np+1)*vp; |
| 231 | if (sx<=np) draw_rectangle(s, w, h, x, y, 1, vp, white); |
| 232 | x=x0+(np2-sx/2)*vp-1; if (sx>np) x=x0; |
| 233 | y=y0+(np2+sy/2+1)*vp-1; |
| 234 | if (sy<=np) draw_rectangle(s, w, h, x, y, vp, 1, white); |
| 235 | //bottom right |
| 236 | x=x0+(np2+sx/2)*vp+vp-1; |
| 237 | y=y0+(np2+sy/2)*vp; if (sy>np) y=y0+(np+1)*vp; |
| 238 | if (sx<=np) draw_rectangle(s, w, h, x, y, 1, vp, white); |
| 239 | x=x0+(np2+sx/2)*vp; |
| 240 | y=y0+(np2+sy/2+1)*vp-1; if (sx>np) x=x0+(np+1)*vp-1; |
| 241 | if (sy<=np) draw_rectangle(s, w, h, x, y, vp, 1, white); |
| 242 | |
| 243 | //"out of box" arrows |
| 244 | if (sx>np) |
| 245 | { |
| 246 | for (i=1;i<vp;i++) |
| 247 | for (j=-i/2;j<=i/2;j++) |
| 248 | { |
| 249 | y=y0+np2*vp+j+vp/2; |
| 250 | x=x0+i; |
| 251 | s[w*y+x]=white; |
| 252 | x=x0+(np+2)*vp-i-1; |
| 253 | s[w*y+x]=white; |
| 254 | } |
| 255 | } |
| 256 | if (sy>np) |
| 257 | { |
| 258 | for (i=1;i<vp;i++) |
| 259 | for (j=-i/2;j<=i/2;j++) |
| 260 | { |
| 261 | x=x0+np2*vp+j+vp/2; |
| 262 | y=y0+i; |
| 263 | s[w*y+x]=white; |
| 264 | y=y0+(np+2)*vp-i-1; |
| 265 | s[w*y+x]=white; |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | } |
| 270 | |
| 271 | //-------------------------------------------------------------- |
| 272 | //draw info window |
| 273 | //sx,sy=size of probe (must be odd) |
| 274 | //poz=position of info window 0=left 1=right |
| 275 | //m=type of measurement: 0=rgba 1=Y'CrCba 2=HSVa |
| 276 | //u=units 0=0.0-1.0 1=0-255 |
| 277 | //sha=1 show alpha |
| 278 | //bw=1 big window |
| 279 | void sonda(float_rgba *s, int w, int h, int x, int y, int sx, int sy, int *poz, int m, int u, int sha, int bw) |
| 280 | { |
| 281 | int x0,y0,vx,vy,vp,np,np2,xn,yn; |
| 282 | int i,j,xp,yp; |
| 283 | char string[256]; |
| 284 | stat yy,rr,gg,bb,aa,uu,vv; |
| 285 | float al,be,h2,c1,c2,ss,va,li; |
| 286 | |
| 287 | float_rgba white={1.0,1.0,1.0,1.0}; |
| 288 | float_rgba gray={0.5,0.5,0.5,1.0}; |
| 289 | float_rgba black={0.0,0.0,0.0,1.0}; |
| 290 | float_rgba red={1.0,0.0,0.0,1.0}; |
| 291 | float_rgba dgreen={0.0,0.7,0.0,1.0}; |
| 292 | float_rgba lblue={0.3,0.3,1.0,1.0}; |
| 293 | |
| 294 | //position and size of info window |
| 295 | //if (x<5*w/12) *poz=1; //right |
| 296 | //if (x>7*w/12) *poz=0; //left |
| 297 | if (x<w/2-30) *poz=1; //right |
| 298 | if (x>w/2+30) *poz=0; //left |
| 299 | vp=9; //pixel size in magnifier |
| 300 | y0=h/20; |
| 301 | if (bw==1) //big window |
| 302 | { |
| 303 | vx=240; |
| 304 | vy = (m<=2) ? 320 : 300; |
| 305 | x0 = (*poz==0) ? h/20 : w-h/20-vx; |
| 306 | np=25; //size of magnifier |
| 307 | xn = (m<=2) ? x0+8 : x0+70; |
| 308 | yn=y0+(np+1)*vp+8; |
| 309 | } |
| 310 | else //small window |
| 311 | { |
| 312 | vx=152; |
| 313 | vy = (m<=2) ? 230 : 210; |
| 314 | x0 = (*poz==0) ? h/20 : w-h/20-vx; |
| 315 | np=15; //size of magnifier |
| 316 | xn = (m<=2) ? x0+15 : x0+25; |
| 317 | yn=y0+(np+1)*vp+8; |
| 318 | } |
| 319 | np2=np/2+1; |
| 320 | if (sha==1) vy=vy+20; |
| 321 | |
| 322 | //keep probe inside |
| 323 | if (x<sx/2) x=sx/2; |
| 324 | if (x>=(w-sx/2)) x=w-sx/2-1; |
| 325 | if (y<sy/2) y=sy/2; |
| 326 | if (y>=(h-sy/2)) y=h-sy/2-1; |
| 327 | |
| 328 | //info window background |
| 329 | darken_rectangle(s, w, h, x0, y0, vx, vy, 0.4); |
| 330 | |
| 331 | //magnifier background |
| 332 | draw_rectangle(s, w, h, x0+vp-1, y0+vp-1, np*vp+1, np*vp+1, black); |
| 333 | //sx,sy marks |
| 334 | sxmarkers(s, w, h, x0, y0, np, sx, sy, vp); |
| 335 | //magnifier pixels |
| 336 | for (i=0;i<np;i++) |
| 337 | for (j=0;j<np;j++) |
| 338 | { |
| 339 | xp=x-np2+j+1; |
| 340 | yp=y-np2+i+1; |
| 341 | if ((xp>=0)&&(xp<w)&&(yp>=0)&&(yp<h)) |
| 342 | draw_rectangle(s, w, h, x0+(j+1)*vp, y0+(i+1)*vp, vp-1, vp-1, s[yp*w+xp]); |
| 343 | } |
| 344 | |
| 345 | //title |
| 346 | if (m<=2) |
| 347 | { |
| 348 | if (bw==1) |
| 349 | draw_string(s, w, h, xn, yn+5, "CHN AVG RMS MIN MAX", white); |
| 350 | else |
| 351 | draw_string(s, w, h, xn, yn+5, "CHN AVG RMS", white); |
| 352 | } |
| 353 | //measurements |
| 354 | switch (m) |
| 355 | { |
| 356 | case 0: //display RGBa |
| 357 | meri_rgb(s, &rr, &gg, &bb, x, y, w, sx, sy); |
| 358 | izpis(string, " R ", rr, u, 0, bw); |
| 359 | draw_string(s, w, h, xn, yn+22, string, red); |
| 360 | izpis(string, " G ", gg, u, 0, bw); |
| 361 | draw_string(s, w, h, xn, yn+39, string, dgreen); |
| 362 | izpis(string, " B ", bb, u, 0, bw); |
| 363 | draw_string(s, w, h, xn, yn+56, string, lblue); |
| 364 | if (sha==1) |
| 365 | { |
| 366 | meri_a(s, &aa, x, y, w, sx, sy); |
| 367 | izpis(string, " a ", aa, u, 0, bw); |
| 368 | draw_string(s, w, h, xn, yn+73, string, gray); |
| 369 | } |
| 370 | break; |
| 371 | case 1: //display Y'PrPba |
| 372 | case 2: |
| 373 | if (m==1) |
| 374 | { |
| 375 | meri_y(s, &yy, 0, x, y, w, sx, sy); |
| 376 | meri_uv(s, &uu, &vv, 0, x, y, w, sx, sy); |
| 377 | } |
| 378 | else |
| 379 | { |
| 380 | meri_y(s, &yy, 1, x, y, w, sx, sy); |
| 381 | meri_uv(s, &uu, &vv, 1, x, y, w, sx, sy); |
| 382 | } |
| 383 | izpis(string, " Y ", yy, u, 0, bw); |
| 384 | draw_string(s, w, h, xn, yn+22, string, white); |
| 385 | izpis(string, " Pr", uu, u, 1, bw); |
| 386 | draw_string(s, w, h, xn, yn+39, string, red); |
| 387 | izpis(string, " Pb", vv, u, 1, bw); |
| 388 | draw_string(s, w, h, xn, yn+56, string, lblue); |
| 389 | if (sha==1) |
| 390 | { |
| 391 | meri_a(s, &aa, x, y, w, sx, sy); |
| 392 | izpis(string, " a ", aa, u, 0, bw); |
| 393 | draw_string(s, w, h, xn, yn+73, string, gray); |
| 394 | } |
| 395 | break; |
| 396 | case 3: //display HSV |
| 397 | meri_rgb(s, &rr, &gg, &bb, x, y, w, sx, sy); |
| 398 | al=(rr.avg+gg.avg+bb.avg)/2.0; |
| 399 | be=sqrtf(3.0)/2.0*(gg.avg-bb.avg); |
| 400 | h2=atan2f(be,al); |
| 401 | c2=sqrtf(al*al+be*be); |
| 402 | va=rr.avg; |
| 403 | if (gg.avg>va) va=gg.avg; if (bb.avg>va) va=bb.avg; |
| 404 | li=rr.avg; |
| 405 | if (gg.avg<li) li=gg.avg; if (bb.avg<li) li=bb.avg; |
| 406 | c1=va-li; |
| 407 | if (c1==0.0) ss=0.0; else ss=c1/va; |
| 408 | h2=h2*180.0/PI; if (h2<0.0) h2=h2+180.0; |
| 409 | sprintf(string," Hue = %5.1f",h2); |
| 410 | draw_string(s, w, h, xn, yn+5, string, white); |
| 411 | sprintf(string," Sat = %5.3f",ss); |
| 412 | draw_string(s, w, h, xn, yn+22, string, white); |
| 413 | sprintf(string," Val = %5.3f",va); |
| 414 | draw_string(s, w, h, xn, yn+39, string, white); |
| 415 | if (sha==1) |
| 416 | { |
| 417 | meri_a(s, &aa, x, y, w, sx, sy); |
| 418 | sprintf(string," a = %5.3f",aa.avg); |
| 419 | draw_string(s, w, h, xn, yn+56, string, gray); |
| 420 | } |
| 421 | break; |
| 422 | case 4: //display HSL |
| 423 | meri_rgb(s, &rr, &gg, &bb, x, y, w, sx, sy); |
| 424 | al=(rr.avg+gg.avg+bb.avg)/2.0; |
| 425 | be=sqrtf(3.0)/2.0*(gg.avg-bb.avg); |
| 426 | h2=atan2f(be,al); |
| 427 | c2=sqrtf(al*al+be*be); |
| 428 | va=rr.avg; |
| 429 | if (gg.avg>va) va=gg.avg; if (bb.avg>va) va=bb.avg; |
| 430 | li=rr.avg; |
| 431 | if (gg.avg<li) li=gg.avg; if (bb.avg<li) li=bb.avg; |
| 432 | c1=va-li; |
| 433 | li=(li+va)/2.0; |
| 434 | if (c1==0.0) |
| 435 | ss=0.0; |
| 436 | else |
| 437 | { |
| 438 | if (li<=0.5) ss=c1/2.0/li; else ss=c1/(2.0-2.0*li); |
| 439 | } |
| 440 | h2=h2*180.0/PI; if (h2<0.0) h2=h2+180.0; |
| 441 | sprintf(string," Hue = %5.1f",h2); |
| 442 | draw_string(s, w, h, xn, yn+5, string, white); |
| 443 | sprintf(string," Sat = %5.3f",ss); |
| 444 | draw_string(s, w, h, xn, yn+22, string, white); |
| 445 | sprintf(string," Lgt = %5.3f",li); |
| 446 | draw_string(s, w, h, xn, yn+39, string, white); |
| 447 | if (sha==1) |
| 448 | { |
| 449 | meri_a(s, &aa, x, y, w, sx, sy); |
| 450 | sprintf(string," a = %5.3f",aa.avg); |
| 451 | draw_string(s, w, h, xn, yn+56, string, gray); |
| 452 | } |
| 453 | break; |
| 454 | default: |
| 455 | break; |
| 456 | } |
| 457 | |
| 458 | } |
| 459 | |
| 460 | //----------------------------------------------------- |
| 461 | //converts the internal RGBA float image into |
| 462 | //Frei0r rgba8888 color |
| 463 | void floatrgba2color(float_rgba *sl, uint32_t* outframe, int w , int h) |
| 464 | { |
| 465 | int i; |
| 466 | uint32_t p; |
| 467 | |
| 468 | for (i=0;i<w*h;i++) |
| 469 | { |
| 470 | p=(uint32_t)(255.0*sl[i].a) & 0xFF; |
| 471 | p=(p<<8) + ((uint32_t)(255.0*sl[i].b) & 0xFF); |
| 472 | p=(p<<8) + ((uint32_t)(255.0*sl[i].g) & 0xFF); |
| 473 | p=(p<<8) + ((uint32_t)(255.0*sl[i].r) & 0xFF); |
| 474 | outframe[i]=p; |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | //----------------------------------------------------- |
| 479 | //converts the Frei0r rgba8888 color image into |
| 480 | //internal float RGBA |
| 481 | void color2floatrgba(const uint32_t* inframe, float_rgba *sl, int w , int h) |
| 482 | { |
| 483 | int i; |
| 484 | |
| 485 | for (i=0;i<w*h;i++) |
| 486 | { |
| 487 | sl[i].r=((float)(inframe[i] & 0x000000FF))*0.00392157; |
| 488 | sl[i].g=((float)((inframe[i] & 0x0000FF00)>>8))*0.00392157; |
| 489 | sl[i].b=((float)((inframe[i] & 0x00FF0000)>>16))*0.00392157; |
| 490 | sl[i].a=((float)((inframe[i] & 0xFF000000)>>24))*0.00392157; |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | //----------------------------------------------------- |
| 495 | //stretch [0...1] to parameter range [min...max] linear |
| 496 | float map_value_forward(double v, float min, float max) |
| 497 | { |
| 498 | return min+(max-min)*v; |
| 499 | } |
| 500 | |
| 501 | //----------------------------------------------------- |
| 502 | //collapse from parameter range [min...max] to [0...1] linear |
| 503 | double map_value_backward(float v, float min, float max) |
| 504 | { |
| 505 | return (v-min)/(max-min); |
| 506 | } |
| 507 | |
| 508 | //---------------------------------------- |
| 509 | //struktura za instanco efekta |
| 510 | typedef struct |
| 511 | { |
| 512 | int h; |
| 513 | int w; |
| 514 | |
| 515 | int mer; |
| 516 | int x; |
| 517 | int y; |
| 518 | int sx; |
| 519 | int sy; |
| 520 | int un; |
| 521 | int sha; |
| 522 | int bw; |
| 523 | |
| 524 | int poz; |
| 525 | float_rgba *sl; |
| 526 | } inst; |
| 527 | |
| 528 | //*********************************************** |
| 529 | // OBVEZNE FREI0R FUNKCIJE |
| 530 | |
| 531 | //----------------------------------------------- |
| 532 | int f0r_init() |
| 533 | { |
| 534 | return 1; |
| 535 | } |
| 536 | |
| 537 | //------------------------------------------------ |
| 538 | void f0r_deinit() |
| 539 | { |
| 540 | } |
| 541 | |
| 542 | //----------------------------------------------- |
| 543 | void f0r_get_plugin_info(f0r_plugin_info_t* info) |
| 544 | { |
| 545 | |
| 546 | info->name="pr0be"; |
| 547 | info->author="Marko Cebokli"; |
| 548 | info->plugin_type=F0R_PLUGIN_TYPE_FILTER; |
| 549 | info->color_model=F0R_COLOR_MODEL_RGBA8888; |
| 550 | info->frei0r_version=FREI0R_MAJOR_VERSION; |
| 551 | info->major_version=0; |
| 552 | info->minor_version=1; |
| 553 | info->num_params=8; |
| 554 | info->explanation="Measure video values"; |
| 555 | } |
| 556 | |
| 557 | //-------------------------------------------------- |
| 558 | void f0r_get_param_info(f0r_param_info_t* info, int param_index) |
| 559 | { |
| 560 | switch(param_index) |
| 561 | { |
| 562 | case 0: |
| 563 | info->name = "Measurement"; |
| 564 | info->type = F0R_PARAM_DOUBLE; |
| 565 | info->explanation = "What measurement to display"; |
| 566 | break; |
| 567 | case 1: |
| 568 | info->name = "X"; |
| 569 | info->type = F0R_PARAM_DOUBLE; |
| 570 | info->explanation = "X position of probe"; |
| 571 | break; |
| 572 | case 2: |
| 573 | info->name = "Y"; |
| 574 | info->type = F0R_PARAM_DOUBLE; |
| 575 | info->explanation = "Y position of probe"; |
| 576 | break; |
| 577 | case 3: |
| 578 | info->name = "X size"; |
| 579 | info->type = F0R_PARAM_DOUBLE; |
| 580 | info->explanation = "X size of probe"; |
| 581 | break; |
| 582 | case 4: |
| 583 | info->name = "Y size"; |
| 584 | info->type = F0R_PARAM_DOUBLE; |
| 585 | info->explanation = "Y size of probe"; |
| 586 | break; |
| 587 | case 5: |
| 588 | info->name = "256 scale"; |
| 589 | info->type = F0R_PARAM_BOOL; |
| 590 | info->explanation = "use 0-255 instead of 0.0-1.0"; |
| 591 | break; |
| 592 | case 6: |
| 593 | info->name = "Show alpha"; |
| 594 | info->type = F0R_PARAM_BOOL; |
| 595 | info->explanation = "Display alpha value too"; |
| 596 | break; |
| 597 | case 7: |
| 598 | info->name = "Big window"; |
| 599 | info->type = F0R_PARAM_BOOL; |
| 600 | info->explanation = "Display more data"; |
| 601 | break; |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | //---------------------------------------------- |
| 606 | f0r_instance_t f0r_construct(unsigned int width, unsigned int height) |
| 607 | { |
| 608 | inst *in; |
| 609 | |
| 610 | in=calloc(1,sizeof(inst)); |
| 611 | in->w=width; |
| 612 | in->h=height; |
| 613 | |
| 614 | in->mer=0; |
| 615 | in->x=width/2; |
| 616 | in->y=height/2; |
| 617 | in->sx=3; |
| 618 | in->sy=3; |
| 619 | in->un=0; |
| 620 | in->sha=0; |
| 621 | in->bw=0; |
| 622 | |
| 623 | in->poz=0; |
| 624 | in->sl=(float_rgba*)calloc(width*height,sizeof(float_rgba)); |
| 625 | |
| 626 | return (f0r_instance_t)in; |
| 627 | } |
| 628 | |
| 629 | //--------------------------------------------------- |
| 630 | void f0r_destruct(f0r_instance_t instance) |
| 631 | { |
| 632 | inst *in; |
| 633 | |
| 634 | in=(inst*)instance; |
| 635 | |
| 636 | free(in->sl); |
| 637 | free(instance); |
| 638 | } |
| 639 | |
| 640 | //----------------------------------------------------- |
| 641 | void f0r_set_param_value(f0r_instance_t instance, f0r_param_t parm, int param_index) |
| 642 | { |
| 643 | inst *p; |
| 644 | int tmpi,chg; |
| 645 | |
| 646 | p=(inst*)instance; |
| 647 | |
| 648 | chg=0; |
| 649 | switch(param_index) |
| 650 | { |
| 651 | case 0: |
| 652 | tmpi=map_value_forward(*((double*)parm), 0.0, 4.9999); |
| 653 | if (tmpi != p->mer) chg=1; |
| 654 | p->mer=tmpi; |
| 655 | break; |
| 656 | case 1: |
| 657 | tmpi=map_value_forward(*((double*)parm), 0.0, p->w); |
| 658 | if (tmpi != p->x) chg=1; |
| 659 | p->x=tmpi; |
| 660 | break; |
| 661 | case 2: |
| 662 | tmpi=map_value_forward(*((double*)parm), 0.0, p->h); |
| 663 | if (tmpi != p->y) chg=1; |
| 664 | p->y=tmpi; |
| 665 | break; |
| 666 | case 3: |
| 667 | tmpi=map_value_forward(*((double*)parm), 0.0, 12.0); |
| 668 | if (tmpi != p->sx) chg=1; |
| 669 | p->sx=tmpi; |
| 670 | break; |
| 671 | case 4: |
| 672 | tmpi=map_value_forward(*((double*)parm), 0.0, 12.0); |
| 673 | if (tmpi != p->sy) chg=1; |
| 674 | p->sy=tmpi; |
| 675 | break; |
| 676 | case 5: |
| 677 | tmpi=map_value_forward(*((double*)parm), 0.0, 1.0); //BOOL!! |
| 678 | if (p->un != tmpi) chg=1; |
| 679 | p->un=tmpi; |
| 680 | break; |
| 681 | case 6: |
| 682 | tmpi=map_value_forward(*((double*)parm), 0.0, 1.0); //BOOL!! |
| 683 | if (p->sha != tmpi) chg=1; |
| 684 | p->sha=tmpi; |
| 685 | break; |
| 686 | case 7: |
| 687 | tmpi=map_value_forward(*((double*)parm), 0.0, 1.0); //BOOL!! |
| 688 | if (p->bw != tmpi) chg=1; |
| 689 | p->bw=tmpi; |
| 690 | break; |
| 691 | } |
| 692 | |
| 693 | if (chg==0) return; |
| 694 | |
| 695 | } |
| 696 | |
| 697 | //-------------------------------------------------- |
| 698 | void f0r_get_param_value(f0r_instance_t instance, f0r_param_t param, int param_index) |
| 699 | { |
| 700 | inst *p; |
| 701 | |
| 702 | p=(inst*)instance; |
| 703 | |
| 704 | switch(param_index) |
| 705 | { |
| 706 | case 0: |
| 707 | *((double*)param)=map_value_backward(p->mer, 0.0, 4.9999); |
| 708 | break; |
| 709 | case 1: |
| 710 | *((double*)param)=map_value_backward(p->x, 0.0, p->w); |
| 711 | break; |
| 712 | case 2: |
| 713 | *((double*)param)=map_value_backward(p->y, 0.0, p->h); |
| 714 | break; |
| 715 | case 3: |
| 716 | *((double*)param)=map_value_backward(p->sx, 0.0, 12.0); |
| 717 | break; |
| 718 | case 4: |
| 719 | *((double*)param)=map_value_backward(p->sy, 0.0, 12.0); |
| 720 | break; |
| 721 | case 5: |
| 722 | *((double*)param)=map_value_backward(p->un, 0.0, 1.0);//BOOL!! |
| 723 | break; |
| 724 | case 6: |
| 725 | *((double*)param)=map_value_backward(p->sha, 0.0, 1.0);//BOOL!! |
| 726 | break; |
| 727 | case 7: |
| 728 | *((double*)param)=map_value_backward(p->bw, 0.0, 1.0);//BOOL!! |
| 729 | break; |
| 730 | } |
| 731 | } |
| 732 | |
| 733 | //------------------------------------------------- |
| 734 | void f0r_update(f0r_instance_t instance, double time, const uint32_t* inframe, uint32_t* outframe) |
| 735 | { |
| 736 | inst *in; |
| 737 | |
| 738 | assert(instance); |
| 739 | in=(inst*)instance; |
| 740 | |
| 741 | color2floatrgba(inframe, in->sl, in->w , in->h); |
| 742 | |
| 743 | sonda(in->sl, in->w, in->h, in->x, in->y, 2*in->sx+1, 2*in->sy+1, &in->poz, in->mer, in->un, in->sha, in->bw); |
| 744 | crosshair(in->sl, in->w, in->h, in->x, in->y, 2*in->sx+1, 2*in->sy+1, 15); |
| 745 | |
| 746 | floatrgba2color(in->sl, outframe, in->w , in->h); |
| 747 | } |