/* test_pat_R This frei0r plugin generates resolution test patterns Version 0.1 may 2010 Copyright (C) 2010 Marko Cebokli http://lea.hamradio.si/~s57uuu This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /*********************************************************** Test patterns: Resolution and spatial frequency response The patterns are drawn into a temporary float array, for two reasons: 1. drawing routines are color model independent, 2. drawing is done only when a parameter changes. only the function float2color() needs to care about color models, endianness, DV legality etc. *************************************************************/ //compile: gcc -Wall -std=c99 -c -fPIC test_pat_R.c -o test_pat_R.o //link: gcc -lm -shared -o test_pat_R.so test_pat_R.o #include #include #include #include #include "frei0r.h" double PI=3.14159265358979; typedef struct { float r; float g; float b; float a; } float_rgba; //---------------------------------------------------------- void draw_rectangle(float *sl, int w, int h, int x, int y, int wr, int hr, float gray) { int i,j; int zx,kx,zy,ky; zx=x; if (zx<0) zx=0; zy=y; if (zy<0) zy=0; kx=x+wr; if (kx>w) kx=w; ky=y+hr; if (ky>h) ky=h; for (i=zy;i9)) return; if ((seg[d]&0x80)!=0) draw_rectangle(sl,w,h,x, y-2*v,v,1,gray); if ((seg[d]&0x40)!=0) draw_rectangle(sl,w,h,x, y-2*v,1,v,gray); if ((seg[d]&0x20)!=0) draw_rectangle(sl,w,h,x+v,y-2*v,1,v,gray); if ((seg[d]&0x10)!=0) draw_rectangle(sl,w,h,x, y-v, v,1,gray); if ((seg[d]&0x08)!=0) draw_rectangle(sl,w,h,x, y-v, 1,v,gray); if ((seg[d]&0x04)!=0) draw_rectangle(sl,w,h,x+v,y-v, 1,v,gray); if ((seg[d]&0x02)!=0) draw_rectangle(sl,w,h,x ,y, v,1,gray); } //----------------------------------------------------------------- //draw a floating point number, using disp7s() //v=size //n=number //f=format (as in printf, for example %5.1f) void dispF(float *sl, int w, int h, int x, int y, int v, float n, char *f, float gray) { char str[64]; int i; sprintf(str,f,n); i=0; while (str[i]!=0) { if (str[i]=='-') draw_rectangle(sl,w,h,x+i*(v+v/3+1),y-v,v,1,gray); else disp7s(sl,w,h,x+i*(v+v/3+1),y,v,str[i]-48,gray); i++; } } //----------------------------------------------------------- //sweep parallel with bars //x,y,wr,hr same as in draw_rectangle() //f1, f2 as fraction of Nyquist //a = amplitude, 1.0=100% mod [0.0...1.0] //dir: 0=vertical 1=horizontal sweep //linp: 0=linear frequency sweep 1=linear period sweep void draw_sweep_1(float *sl, int w, int h, int x, int y, int wr, int hr, float f1, float f2, float a, int dir, int linp) { int i,j; int zx,kx,zy,ky; double p,dp,dp1,dp2,dt,dt1,dt2; zx=x; if (zx<0) zx=0; zy=y; if (zy<0) zy=0; kx=x+wr; if (kx>w) kx=w; ky=y+hr; if (ky>h) ky=h; if (f1==0.0) f1=1.0E-12; if (f2==0.0) f2=1.0E-12; dp1=PI*f1; dp2=PI*f2; //phase steps dt1=1.0/dp1; dt2=1.0/dp2; a=a/2.0; p=0; if (dir==0) { for (i=zy;iw) kx=w; ky=y+hr; if (ky>h) ky=h; if (f1==0.0) f1=1.0E-12; if (f2==0.0) f2=1.0E-12; dp1=PI*f1; dp2=PI*f2; //phase steps dt1=1.0/dp1; dt2=1.0/dp2; a=a/2.0; p=0; if (dir==0) { for (i=zy;i=0.0)&&(xl<=1.0)) { x=w/8-60; y=h/16+xl*(14*h/16); draw_rectangle(sl,w,h,w/8-15,y,10,3,0.9); dispF(sl,w,h,x,y+6,6,lf1[i],"%5.2f",0.9); } } for (i=0;i=0.0)&&(xl<=1.0)) { x=7*w/8+10; y=h/16+xl*(14*h/16); draw_rectangle(sl,w,h,7*w/8+5,y,10,3,0.9); dispF(sl,w,h,x,y+6,6,lf3[i],"%4.0f",0.9); } } } else //lin period sweep { for (i=0;i=0.0)&&(xl<=1.0)) { x=w/8-60; y=h/16+xl*(14*h/16); draw_rectangle(sl,w,h,w/8-15,y,10,3,0.9); dispF(sl,w,h,x,y+6,6,lf2[i],"%5.2f",0.9); } } for (i=0;i=0.0)&&(xl<=1.0)) { x=7*w/8+10; y=h/16+xl*(14*h/16); draw_rectangle(sl,w,h,7*w/8+5,y,10,3,0.9); dispF(sl,w,h,x,y+6,6,lf4[i],"%4.0f",0.9); } } } } //-------------------------------------------------------------- //horizontal sweep with labels (frequency changes with x) //a=axis 0=horizontal frequencies 1=vert freqs //amp = amplitude //lps: 0=lin f sweep 1=lin p sweep //ar = pixel aspect ratio (used only for LPPH labels on hor f) //sf,ef start,end freqs in Nyquists //LPPH (lines per picture height) labels are in "TV lines", //not line pairs. Line pairs = TV lines / 2.0 //lf* arrays determine where the labels will be drawn void sweep_h(float *sl, int w, int h, int a, float amp, int lps, float ar, float sf, float ef) { float xl,nf; float lf1[]={0.05,0.2,0.3,0.4,0.5,0.6,0.7}; //label lin f nyq float lf2[]={0.05,0.07,0.1,0.15,0.3,0.7}; //label lin p nyq float lf3[]={100.0,200.0,300.0,400.0,500.0,600.0,700.0,800.0,900.0}; float lf4[]={10.0,25.0,50.0,100.0,200.0,400.0,800.0}; int i,x,y; for (x=0;x=0.0)&&(xl<=1.0)) { y=7*h/8+25; x=w/16+xl*(14*w/16); draw_rectangle(sl,w,h,x,y-20,3,10,0.9); dispF(sl,w,h,x-20,y+6,6,lf1[i],"%5.2f",0.9); } } for (i=0;i=0.0)&&(xl<=1.0)) { y=h/8-25; x=w/16+xl*(14*w/16); draw_rectangle(sl,w,h,x,y+8,3,10,0.9); dispF(sl,w,h,x-20,y+2,6,lf3[i],"%4.0f",0.9); } } } else //lin period sweep { for (i=0;i=0.0)&&(xl<=1.0)) { y=7*h/8+25; x=w/16+xl*(14*w/16); draw_rectangle(sl,w,h,x,y-20,3,10,0.9); dispF(sl,w,h,x-20,y+6,6,lf2[i],"%5.2f",0.9); } } for (i=0;i=0.0)&&(xl<=1.0)) { y=h/8-25; x=w/16+xl*(14*w/16); draw_rectangle(sl,w,h,x,y+8,3,10,0.9); dispF(sl,w,h,x-20,y+2,6,lf4[i],"%4.0f",0.9); } } } } //---------------------------------------------------------- //draws a "Siemens star" pattern //ar = pixel aspect ratio (not used currently) //np = numbers of periods around the circle void radials(float *sl, int w, int h, float a, float ar, float np) { float an,s,c,g,da,r,rmin,rmax; int x,y; da=PI/2000.0; for (x=0;xname = "test_pat_R"; tp_info->author = "Marko Cebokli"; tp_info->plugin_type = F0R_PLUGIN_TYPE_SOURCE; // tp_info->plugin_type = F0R_PLUGIN_TYPE_FILTER; tp_info->color_model = F0R_COLOR_MODEL_RGBA8888; tp_info->frei0r_version = FREI0R_MAJOR_VERSION; tp_info->major_version = 0; tp_info->minor_version = 2; tp_info->num_params = 8; tp_info->explanation = "Generates resolution test patterns"; } //-------------------------------------------------- void f0r_get_param_info(f0r_param_info_t* info, int param_index) { switch (param_index) { case 0: info->name = "Type"; info->type = F0R_PARAM_DOUBLE; info->explanation = "Type of test pattern"; break; case 1: info->name ="Channel"; info->type = F0R_PARAM_DOUBLE; info->explanation = "Into which color channel to draw"; break; case 2: info->name = "Amplitude"; info->type = F0R_PARAM_DOUBLE; info->explanation = "Amplitude (contrast) of the pattern"; break; case 3: info->name = "Lin P swp"; info->type = F0R_PARAM_BOOL; info->explanation = "Use linear period sweep"; break; case 4: info->name = "Freq 1"; info->type = F0R_PARAM_DOUBLE; info->explanation = "Pattern 7 H frequency"; break; case 5: info->name = "Freq 2"; info->type = F0R_PARAM_DOUBLE; info->explanation = "Pattern 7 V frequency"; break; case 6: info->name ="Aspect type"; info->type = F0R_PARAM_DOUBLE; info->explanation = "Pixel aspect ratio presets"; break; case 7: info->name = "Manual aspect"; info->type = F0R_PARAM_DOUBLE; info->explanation = "Manual pixel aspect ratio"; break; } } //-------------------------------------------------- f0r_instance_t f0r_construct(unsigned int width, unsigned int height) { tp_inst_t* inst = calloc(1, sizeof(*inst)); inst->w = width; inst->h = height; inst->type=0; inst->chan=0; inst->amp=0.8; inst->linp=0; inst->f1=0.03; inst->f2=0.03; inst->aspt=0; inst->mpar=1.0; inst->par=1.0; inst->sl=(float*)calloc(width*height,sizeof(float)); sweep_v(inst->sl, inst->w, inst->h, 0, inst->amp, inst->linp, inst->par, 0.05, 0.7); return (f0r_instance_t)inst; } //-------------------------------------------------- void f0r_destruct(f0r_instance_t instance) { tp_inst_t* inst = (tp_inst_t*)instance; free(inst->sl); free(inst); } //-------------------------------------------------- void f0r_set_param_value(f0r_instance_t instance, f0r_param_t param, int param_index) { tp_inst_t* inst = (tp_inst_t*)instance; f0r_param_double* p = (f0r_param_double*) param; int chg,tmpi; float tmpf; chg=0; switch (param_index) { case 0: //type tmpf=*((double*)p); if (tmpf>=1.0) tmpi=(int)tmpf; else tmpi = map_value_forward(tmpf, 0.0, 9.9999); if ((tmpi<0)||(tmpi>9.0)) break; if (inst->type != tmpi) chg=1; inst->type = tmpi; break; case 1: //channel tmpf=*((double*)p); if (tmpf>=1.0) tmpi=(int)tmpf; else tmpi = map_value_forward(tmpf, 0.0, 7.9999); if ((tmpi<0)||(tmpi>7.0)) break; if (inst->chan != tmpi) chg=1; inst->chan = tmpi; case 2: //amplitude tmpf = map_value_forward(*((double*)p), 0.0, 1.0); if (inst->amp != tmpf) chg=1; inst->amp = tmpf; break; case 3: //linear period sweep tmpi = map_value_forward(*((double*)p), 0.0, 1.0); if (inst->linp != tmpi) chg=1; inst->linp = tmpi; break; case 4: //frequency 1 tmpf = map_value_forward(*((double*)p), 0.0, 1.0); if (inst->f1 != tmpf) chg=1; inst->f1 = tmpf; break; case 5: //frequency 2 tmpf = map_value_forward(*((double*)p), 0.0, 1.0); if (inst->f2 != tmpf) chg=1; inst->f2 = tmpf; break; case 6: //aspect type tmpf=*((double*)p); if (tmpf>=1.0) tmpi=(int)tmpf; else tmpi = map_value_forward(tmpf, 0.0, 6.9999); if ((tmpi<0)||(tmpi>6.0)) break; if (inst->aspt != tmpi) chg=1; inst->aspt = tmpi; switch (inst->aspt) //pixel aspect ratio { case 0: inst->par=1.000;break; //square pixels case 1: inst->par=1.067;break; //PAL DV case 2: inst->par=1.455;break; //PAL wide case 3: inst->par=0.889;break; //NTSC DV case 4: inst->par=1.212;break; //NTSC wide case 5: inst->par=1.333;break; //HDV case 6: inst->par=inst->mpar;break; //manual } break; case 7: //manual aspect tmpf = map_value_forward_log(*((double*)p), 0.5, 2.0); if (inst->mpar != tmpf) chg=1; inst->mpar = tmpf; if (inst->aspt==6) inst->par=inst->mpar; break; } if (chg==0) return; switch (inst->type) { case 0: //hor freq ver sweep sweep_v(inst->sl, inst->w, inst->h, 0, inst->amp, inst->linp, inst->par, 0.05, 0.7); break; case 1: //hor freq hor sweep sweep_h(inst->sl, inst->w, inst->h, 0, inst->amp, inst->linp, inst->par, 0.05, 0.7); break; case 2: //ver freq ver sweep sweep_v(inst->sl, inst->w, inst->h, 1, inst->amp, inst->linp, inst->par, 0.05, 0.7); //ver f ver sw break; case 3: //ver freq hor sweep sweep_h(inst->sl, inst->w, inst->h, 1, inst->amp, inst->linp, inst->par, 0.05, 0.7); break; case 4: // "Siemens star" radials(inst->sl, inst->w, inst->h, inst->amp, inst->par, 60.0); break; case 5: //rings outwards rings(inst->sl, inst->w, inst->h, inst->amp, inst->par, inst->linp, 0.05, 0.7); break; case 6: //rings inwards rings(inst->sl, inst->w, inst->h, inst->amp, inst->par, inst->linp, 0.7, 0.05); break; case 7: //uniform 2D spatial frequency diags(inst->sl, inst->w, inst->h, inst->amp, inst->par, inst->f1, inst->f2); break; case 8: // "Nyquist blocks" nblocks(inst->sl, inst->w, inst->h, inst->amp); break; case 9: //square bars at integer Nyquist fractions sqbars(inst->sl, inst->w, inst->h, inst->amp); break; default: break; } } //------------------------------------------------- void f0r_get_param_value(f0r_instance_t instance, f0r_param_t param, int param_index) { tp_inst_t* inst = (tp_inst_t*)instance; f0r_param_double* p = (f0r_param_double*) param; switch (param_index) { case 0: //type *p = map_value_backward(inst->type, 0.0, 9.9999); break; case 1: //channel *p = map_value_backward(inst->chan, 0.0, 7.9999); break; case 2: //amplitude *p = map_value_backward(inst->amp, 0.0, 1.0); break; case 3: //linear period sweep *p = map_value_backward(inst->linp, 0.0, 1.0); break; case 4: //frequency 1 *p = map_value_backward(inst->f1, 0.0, 1.0); break; case 5: //frequency 2 *p = map_value_backward(inst->f2, 0.0, 1.0); break; case 6: //aspect type *p = map_value_backward(inst->aspt, 0.0, 6.9999); break; case 7: //manual aspect *p = map_value_backward_log(inst->mpar, 0.5, 2.0); break; } } //--------------------------------------------------- void f0r_update(f0r_instance_t instance, double time, const uint32_t* inframe, uint32_t* outframe) { assert(instance); tp_inst_t* inst = (tp_inst_t*)instance; float2color(inst->sl, outframe, inst->w , inst->h, inst->chan); }