diff options
author | N.N. <sevyves@users.sourceforge.net> | 2009-09-17 17:04:10 +0000 |
---|---|---|
committer | N.N. <sevyves@users.sourceforge.net> | 2009-09-17 17:04:10 +0000 |
commit | c8914c3217d54862370902fd36b1f8496cea7c51 (patch) | |
tree | 733570baf9816d306006b750349e84d9684477cd /modules | |
parent | 571ab6c2132878c79a00227f81b42c4a48c1d91f (diff) |
P.i.D.i.P. version 0.12.24 (see CHANGES.LOG)
svn path=/trunk/externals/pidip/; revision=12385
Diffstat (limited to 'modules')
-rw-r--r-- | modules/pdp_binary.c | 67 | ||||
-rw-r--r-- | modules/pdp_cmap.c | 11 |
2 files changed, 58 insertions, 20 deletions
diff --git a/modules/pdp_binary.c b/modules/pdp_binary.c index aba8a15..128336a 100644 --- a/modules/pdp_binary.c +++ b/modules/pdp_binary.c @@ -25,6 +25,7 @@ #include "yuv.h" #include <math.h> #include <stdio.h> +#include "g_canvas.h" static char *pdp_binary_version = "pdp_binary: a image binarizer version 0.1 written by Yves Degoyon (ydegoyon@free.fr)"; @@ -43,6 +44,9 @@ typedef struct pdp_binary_struct int x_colorY; // YUV components of binary mask int x_colorU; int x_colorV; + int x_colorR; // RGB components of binary mask + int x_colorG; + int x_colorB; int x_cursX; // X position of the cursor int x_cursY; // Y position of the cursor int x_tolerance; // tolerance @@ -53,8 +57,26 @@ typedef struct pdp_binary_struct t_outlet *x_U; // output U component of selected color t_outlet *x_V; // output V component of selected color + t_canvas *x_canvas; + } t_pdp_binary; +static void pdp_binary_draw_color(t_pdp_binary *x) +{ + int width, height; + char color[32]; + + sprintf( color, "#%.2X%.2X%.2X", x->x_colorR, x->x_colorG, x->x_colorB ); + width = rtext_width( glist_findrtext( (t_glist*)x->x_canvas, (t_text *)x ) ); + height = rtext_height( glist_findrtext( (t_glist*)x->x_canvas, (t_text *)x ) ); + sys_vgui(".x%x.c delete rectangle %xCOLOR\n", x->x_canvas, x ); + sys_vgui(".x%x.c create rectangle %d %d %d %d -fill %s -tags %xCOLOR\n", + x->x_canvas, x->x_obj.te_xpix+width+5, x->x_obj.te_ypix, + x->x_obj.te_xpix+width+height+5, + x->x_obj.te_ypix+height, color, x ); +} + + static void pdp_binary_setcur(t_pdp_binary *x, t_floatarg fpx, t_floatarg fpy ) { if ( (fpx>=0.0) && (fpx<=1.0) && (fpy>=0.0) && (fpy<=1.0) ) @@ -66,28 +88,40 @@ static void pdp_binary_setcur(t_pdp_binary *x, t_floatarg fpx, t_floatarg fpy static void pdp_binary_y(t_pdp_binary *x, t_floatarg fy ) { - if ( fy <= 255. ) + if ( fy <= 255. && fy >= 0. ) { x->x_colorY = (int)fy; outlet_float( x->x_Y, x->x_colorY ); + x->x_colorR = yuv_YUVtoR( x->x_colorY, x->x_colorU, x->x_colorV ); + x->x_colorG = yuv_YUVtoG( x->x_colorY, x->x_colorU, x->x_colorV ); + x->x_colorB = yuv_YUVtoB( x->x_colorY, x->x_colorU, x->x_colorV ); + if (glist_isvisible(x->x_canvas)) pdp_binary_draw_color( x ); } } static void pdp_binary_u(t_pdp_binary *x, t_floatarg fu ) { - if ( fu <= 255. ) + if ( fu <= 255. && fu >= 0. ) { x->x_colorU = (int)fu; outlet_float( x->x_U, x->x_colorU ); + x->x_colorR = yuv_YUVtoR( x->x_colorY, x->x_colorU, x->x_colorV ); + x->x_colorG = yuv_YUVtoG( x->x_colorY, x->x_colorU, x->x_colorV ); + x->x_colorB = yuv_YUVtoB( x->x_colorY, x->x_colorU, x->x_colorV ); + if (glist_isvisible(x->x_canvas)) pdp_binary_draw_color( x ); } } static void pdp_binary_v(t_pdp_binary *x, t_floatarg fv ) { - if ( fv < 255 ) + if ( fv < 255 && fv >= 0. ) { x->x_colorV = (int)fv; outlet_float( x->x_V, x->x_colorV ); + x->x_colorR = yuv_YUVtoR( x->x_colorY, x->x_colorU, x->x_colorV ); + x->x_colorG = yuv_YUVtoG( x->x_colorY, x->x_colorU, x->x_colorV ); + x->x_colorB = yuv_YUVtoB( x->x_colorY, x->x_colorU, x->x_colorV ); + if (glist_isvisible(x->x_canvas)) pdp_binary_draw_color( x ); } } @@ -130,6 +164,10 @@ static void pdp_binary_pick(t_pdp_binary *x) outlet_float( x->x_Y, x->x_colorY ); outlet_float( x->x_V, x->x_colorV ); outlet_float( x->x_U, x->x_colorU ); + x->x_colorR = yuv_YUVtoR( x->x_colorY, x->x_colorU, x->x_colorV ); + x->x_colorG = yuv_YUVtoG( x->x_colorY, x->x_colorU, x->x_colorV ); + x->x_colorB = yuv_YUVtoB( x->x_colorY, x->x_colorU, x->x_colorV ); + if (glist_isvisible(x->x_canvas)) pdp_binary_draw_color( x ); } } @@ -171,16 +209,20 @@ static void pdp_binary_process_yv12(t_pdp_binary *x) x->x_vsize = x->x_vwidth*x->x_vheight; pdp_binary_allocate( x ); post( "pdp_binary : reallocated buffers" ); + outlet_float( x->x_Y, x->x_colorY ); + outlet_float( x->x_V, x->x_colorV ); + outlet_float( x->x_U, x->x_colorU ); } memcpy(x->x_frame, data, (x->x_vsize + (x->x_vsize>>1))<<1 ); - - // post( "pdp_binary : newheader:%x", newheader ); + memset(newdata, 0x0, (x->x_vsize + (x->x_vsize>>1))<<1 ); newheader->info.image.encoding = header->info.image.encoding; newheader->info.image.width = x->x_vwidth; newheader->info.image.height = x->x_vheight; + // post( "pdp_binary : y=%d, u=%d, v=%d", x->x_colorY, x->x_colorU, x->x_colorV ); + // binarize pfY = data; pfV = data+x->x_vsize; @@ -193,8 +235,6 @@ static void pdp_binary_process_yv12(t_pdp_binary *x) v = ((*pfV)>>8)+128; u = ((*pfU)>>8)+128; - // post( "pdp_binary : y=%d, u=%d, v=%d", y, u, v ); - diff = 0; if ( x->x_colorY >= 0 ) { @@ -213,10 +253,6 @@ static void pdp_binary_process_yv12(t_pdp_binary *x) { *(newdata+(py*x->x_vwidth+px)) = 0xff<<7; } - else - { - *(newdata+(py*x->x_vwidth+px)) = 0; - } pfY++; if ( (px%2==0) && (py%2==0) ) @@ -226,8 +262,6 @@ static void pdp_binary_process_yv12(t_pdp_binary *x) } } - memset( newdata+x->x_vsize, 0x0, (x->x_vsize>>1)<<1 ); - return; } @@ -319,6 +353,10 @@ void *pdp_binary_new(void) x->x_colorU = -1; x->x_colorV = -1; + x->x_colorR = yuv_YUVtoR( x->x_colorY, x->x_colorU, x->x_colorV ); + x->x_colorG = yuv_YUVtoG( x->x_colorY, x->x_colorU, x->x_colorV ); + x->x_colorB = yuv_YUVtoB( x->x_colorY, x->x_colorU, x->x_colorV ); + x->x_packet0 = -1; x->x_packet1 = -1; @@ -331,6 +369,8 @@ void *pdp_binary_new(void) x->x_vsize = -1; x->x_frame = NULL; + x->x_canvas = canvas_getcurrent(); + return (void *)x; } @@ -356,7 +396,6 @@ void pdp_binary_setup(void) class_addmethod(pdp_binary_class, (t_method)pdp_binary_pick, gensym("pick"), A_NULL); class_addmethod(pdp_binary_class, (t_method)pdp_binary_tolerance, gensym("tolerance"), A_FLOAT, A_NULL); class_addmethod(pdp_binary_class, (t_method)pdp_binary_setcur, gensym("setcur"), A_DEFFLOAT, A_DEFFLOAT, A_NULL); - } #ifdef __cplusplus diff --git a/modules/pdp_cmap.c b/modules/pdp_cmap.c index 994dc24..ec377fc 100644 --- a/modules/pdp_cmap.c +++ b/modules/pdp_cmap.c @@ -282,9 +282,9 @@ static void pdp_cmap_pick(t_pdp_cmap *x) x->x_colorG = yuv_YUVtoG( y, u, v ); x->x_colorB = yuv_YUVtoB( y, u, v ); if (glist_isvisible(x->x_canvas)) pdp_cmap_draw_color( x, x->x_colorR, x->x_colorG, x->x_colorB ); - x->x_colors[x->x_current].y = 255; - x->x_colors[x->x_current].u = 255; - x->x_colors[x->x_current].v = 255; + x->x_colors[x->x_current].y = rand() & 255; + x->x_colors[x->x_current].u = rand() & 255; + x->x_colors[x->x_current].v = rand() & 255; x->x_colors[x->x_current].on = 1; } } @@ -362,8 +362,8 @@ static void pdp_cmap_process_yv12(t_pdp_cmap *x) { // change color not luminosity // *pfY = x->x_colors[ci].y; - *pfV = x->x_colors[ci].v; - *pfU = x->x_colors[ci].u; + *pfV = ( x->x_colors[ci].v - 128 )<<8; + *pfU = ( x->x_colors[ci].u - 128 )<<8; } pfY++;poY++; @@ -533,7 +533,6 @@ void pdp_cmap_setup(void) class_addmethod(pdp_cmap_class, (t_method)pdp_cmap_delete, gensym("delete"), A_DEFFLOAT, A_NULL); class_addmethod(pdp_cmap_class, (t_method)pdp_cmap_resize, gensym("resize"), A_DEFFLOAT, A_NULL); class_addmethod(pdp_cmap_class, (t_method)pdp_cmap_setcur, gensym("setcur"), A_DEFFLOAT, A_DEFFLOAT, A_NULL); - } #ifdef __cplusplus |