/* test_pat_B This frei0r plugin generates TV test card approximations 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: Broadcast test cards This plugin draws a set of test patterns, similar to popular TV test cards 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 floatrgba2color() needs to care about color models, endianness, DV legality etc. *************************************************************/ //compile: gcc -Wall -c -fPIC test_pat_B.c -o test_pat_B.o //link: gcc -lm -shared -o test_pat_B.so test_pat_B.o #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_rgba *s, int w, int h, float x, float y, float wr, float hr, float_rgba c) { 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;iw) kx=w; ky=y+rz+1; if (ky>h) ky=h; rmin=(float)rn; rmax=(float)rz; for (i=zy;i=rmin)&&(rr<=rmax)) sl[w*i+j]=c; } } //------------------------------------------------------------------ //ar = pixel aspect ratio //x,y = center //xb,yb = upper left corner of box //vx,vy = size of box void draw_boxed_circle(float_rgba *s, int w, int h, float x, float y, float r, float xb, float yb, float vx, float vy, float ar, float_rgba c) { int xz,yz,xk,yk; int i,j; float rr; xz=x-r/ar-1; if (xz<0) xz=0; if (xzw) xk=w; if (xk>(xb+vx)) xk=xb+vx; yz=y-r-1; if (yz<0) yz=0; if (yzh) yk=h; if (yk>(yb+vy)) yk=yb+vy; for (i=yz;ivkx) x0=x0-vkx; y0=(h-vky*14)/2; rk=6.7*vky; c.a=1.0; //ozadje c.r=0.25; c.g=0.25; c.b=0.25; for (i=0;iname = "test_pat_B"; 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 = 1; tp_info->num_params = 3; tp_info->explanation = "Generates test card lookalikes"; } //-------------------------------------------------- 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 = "8 choices, select test pattern"; break; case 1: info->name ="Aspect type"; info->type = F0R_PARAM_DOUBLE; info->explanation = "7 choices, pixel aspect ratio"; break; case 2: info->name = "Manual Aspect"; info->type = F0R_PARAM_DOUBLE; info->explanation = "Manual pixel aspect ratio (Aspect type 6)"; 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->aspt=0; inst->mpar=1.0; inst->par=1.0; inst->sl=(float_rgba*)calloc(width*height,sizeof(float_rgba)); bars_simple(inst->sl, inst->w, inst->h, 0, 0); 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, 7.9999); if ((tmpi<0)||(tmpi>7.0)) break; if (inst->type != tmpi) chg=1; inst->type = tmpi; break; case 1: //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 2: //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==4) inst->par=inst->mpar; break; } if (chg==0) return; switch (inst->type) { case 0: //100% PAL color bars bars_simple(inst->sl, inst->w, inst->h, 0, 0); break; case 1: //PAL color bars with red bars_simple(inst->sl, inst->w, inst->h, 0, 1); break; case 2: //95% BBC color bars bars_simple(inst->sl, inst->w, inst->h, 1, 0); break; case 3: //75% EBU color bars bars_simple(inst->sl, inst->w, inst->h, 2, 0); break; case 4: //SMPTE color bars bars_smpte(inst->sl, inst->w, inst->h); break; case 5: //philips PM5544 draw_pm(inst->sl, inst->w, inst->h, inst->par); break; case 6: //FuBK draw_fu(inst->sl, inst->w, inst->h, inst->par, 0); break; case 7: //simplified FuBK draw_fu(inst->sl, inst->w, inst->h, inst->par, 1); 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, 7.9999); break; case 1: //aspect type *p = map_value_backward(inst->aspt, 0.0, 6.9999); break; case 2: //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; floatrgba2color(inst->sl, outframe, inst->w , inst->h); }