From 27b80972be922c09f431ee9418cab698477b10d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?llu=C3=ADs=20g=C3=B3mez=20i=20bigord=C3=A0?= Date: Sun, 25 Jan 2009 01:14:06 +0000 Subject: new tlc-sockets procedure to get frame data and paint into the canvas svn path=/trunk/externals/pdvjtools/; revision=10627 --- pix_preview/pix_preview.cc | 223 ++++++++++++++++----------------------------- 1 file changed, 81 insertions(+), 142 deletions(-) diff --git a/pix_preview/pix_preview.cc b/pix_preview/pix_preview.cc index df744a2..63bb9c3 100644 --- a/pix_preview/pix_preview.cc +++ b/pix_preview/pix_preview.cc @@ -1,27 +1,10 @@ -//////////////////////////////////////////////////////// -// -// GEM - Graphics Environment for Multimedia -// -// zmoelnig@iem.kug.ac.at -// -// Implementation file -// -// Copyright (c) 1997-1998 Mark Danks. -// Copyright (c) Günther Geiger. -// Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::für::umläute. IEM -// Copyright (c) 2002 James Tittle & Chris Clepper -// For information on usage and redistribution, and for a DISCLAIMER OF ALL -// WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution. -// -///////////////////////////////////////////////////////// ///////////////////////////////////////////////////////// // // pix_preview // -// 0409:forum::für::umläute:2000 -// IOhannes m zmoelnig -// mailto:zmoelnig@iem.kug.ac.at +// Lluis Gomez i Bigorda +// mailto:lluis@artefacte.org // ///////////////////////////////////////////////////////// @@ -30,7 +13,12 @@ #include using namespace std; #include "stdio.h" - +#include +#include +#include +#include +#include +#include #include "m_pd.h" #include "m_imp.h" @@ -39,46 +27,15 @@ using namespace std; #include "pix_preview.h" -int guidebug=0; - -#define COLORGRID_SYS_VGUI2(a,b) if (guidebug) \ - post(a,b);\ - sys_vgui(a,b) - -#define COLORGRID_SYS_VGUI3(a,b,c) if (guidebug) \ - post(a,b,c);\ - sys_vgui(a,b,c) - -#define COLORGRID_SYS_VGUI4(a,b,c,d) if (guidebug) \ - post(a,b,c,d);\ - sys_vgui(a,b,c,d) +#define initialport 1234 -#define COLORGRID_SYS_VGUI5(a,b,c,d,e) if (guidebug) \ - post(a,b,c,d,e);\ - sys_vgui(a,b,c,d,e) +int guidebug=1; -#define COLORGRID_SYS_VGUI6(a,b,c,d,e,f) if (guidebug) \ - post(a,b,c,d,e,f);\ - sys_vgui(a,b,c,d,e,f) - -#define COLORGRID_SYS_VGUI7(a,b,c,d,e,f,g) if (guidebug) \ - post(a,b,c,d,e,f,g );\ - sys_vgui(a,b,c,d,e,f,g) - -#define COLORGRID_SYS_VGUI8(a,b,c,d,e,f,g,h) if (guidebug) \ - post(a,b,c,d,e,f,g,h );\ - sys_vgui(a,b,c,d,e,f,g,h) - -#define COLORGRID_SYS_VGUI9(a,b,c,d,e,f,g,h,i) if (guidebug) \ - post(a,b,c,d,e,f,g,h,i );\ - sys_vgui(a,b,c,d,e,f,g,h,i) - - - char *fdata="R0lGODlhHAAcAIABAAAAAP///ywAAAAAHAAcAAACGoSPqcvtD6OctNqLs968+w+G4kiW5omm6ooUADs="; +char *fdata="R0lGODlhHAAcAIABAAAAAP///ywAAAAAHAAcAAACGoSPqcvtD6OctNqLs968+w+G4kiW5omm6ooUADs="; +int pix_preview::counter; /* base64 conversion*/ - static const std::string base64_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" @@ -128,19 +85,6 @@ std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_ } - - - - - - - - - - - - - CPPEXTERN_NEW_WITH_TWO_ARGS(pix_preview, t_floatarg, A_DEFFLOAT, t_floatarg, A_DEFFLOAT) @@ -153,8 +97,11 @@ CPPEXTERN_NEW_WITH_TWO_ARGS(pix_preview, t_floatarg, A_DEFFLOAT, t_floatarg, A_D // ///////////////////////////////////////////////////////// pix_preview :: pix_preview(t_floatarg fx, t_floatarg fy) -{ +{ + counter++; + whoami = counter; #include "pix_preview.tk2c" + sys_vgui("Echo_Server%d %d\n",whoami, 1233+whoami); xsize = (int)fx; ysize = (int)fy; m_csize = 3; @@ -190,7 +137,28 @@ CPPEXTERN_NEW_WITH_TWO_ARGS(pix_preview, t_floatarg, A_DEFFLOAT, t_floatarg, A_D m_buffer = new t_atom[m_bufsize]; + widgetwidth = 0; + widgetheight = 0; + //m_dataOut = outlet_new(this->x_obj, &s_list); + + // Try to connect (not working now , using connectMes) + memset(&hints, 0, sizeof hints); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + + std::ostringstream ostr; + ostr << 1233+whoami; + std::string str; + str = ostr.str(); + + getaddrinfo("localhost", reinterpret_cast(str.c_str()), &hints, &res); + + fprintf(stderr,"trying to connect...\n"); + s = socket(res->ai_family, res->ai_socktype, 0); + connect(s, res->ai_addr, res->ai_addrlen); + + //fprintf(stderr,"We have %d pixpreviews\n",counter); } ///////////////////////////////////////////////////////// @@ -205,6 +173,24 @@ pix_preview :: ~pix_preview() // processImage // ///////////////////////////////////////////////////////// +void pix_preview :: connectMess() +{ + memset(&hints, 0, sizeof hints); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + + std::ostringstream ostr; + ostr << 1233+whoami; + std::string str; + str = ostr.str(); + + getaddrinfo("localhost", reinterpret_cast(str.c_str()), &hints, &res); + + fprintf(stderr,"trying to connect...\n"); + s = socket(res->ai_family, res->ai_socktype, 0); + connect(s, res->ai_addr, res->ai_addrlen); +} + void pix_preview :: processImage(imageStruct &image) { int x = m_xsize, y = m_ysize, c = m_csize; @@ -272,6 +258,7 @@ void pix_preview :: processYUVImage(imageStruct &image) void pix_preview :: trigger() { if (!m_data) return; + int n = m_ysize, m = 0; int i = 0; @@ -279,7 +266,7 @@ void pix_preview :: trigger() unsigned char *data, *line; stringstream sx,sy; - fprintf (stderr,"%d %d %d %d %d %d \n",xsize, ysize,m_xsize, m_ysize,oldimagex,oldimagey); + //fprintf (stderr,"%d %d %d %d %d %d \n",xsize, ysize,m_xsize, m_ysize,oldimagex,oldimagey); std::string pnm; std::string pnm64; @@ -291,54 +278,20 @@ void pix_preview :: trigger() pnm += sy.str(); pnm += "\n255\n"; - //fprintf (stderr,"%s",pnm.c_str()); - - /*/escriu el contingut de data a un arxiu.*/ - char* ig_path = "/tmp/pixdump01.pnm"; - FILE * fp = fopen(ig_path, "w"); - fprintf (fp, "P6\n%d %d\n255\n", m_xsize, m_ysize); data = line = m_data; switch(m_csize){ case 4: -/* - while (n > 0) { - while (m < m_xsize) { - int r, g, b, a; - r = (int)data[chRed]; - fprintf (fp, "%c", (char)r); - i++; - g = (int)data[chGreen]; - fprintf (fp, "%c", (char)g); - i++; - b = (int)data[chBlue]; - fprintf (fp, "%c", (char)b); - i++; - a = (int)data[chAlpha]; - i++; - m++; - data = line + (int)(m_xstep * (float)m); - } - m = 0; - n--; - line = m_data + (int)(m_ystep*n); - data = line; - } - fclose (fp); -*/ while (n > 0) { while (m < m_xsize) { int r, g, b, a; r = (int)data[chRed]; pnm += (char)r; - fprintf (fp, "%c", (char)r); i++; g = (int)data[chGreen]; pnm += (char)g; - fprintf (fp, "%c", (char)g); i++; b = (int)data[chBlue]; pnm += (char)b; - fprintf (fp, "%c", (char)b); i++; a = (int)data[chAlpha]; i++; @@ -350,26 +303,22 @@ void pix_preview :: trigger() line = m_data + (int)(m_ystep*n); data = line; } - fclose (fp); //std::cout << "NOT encoded: " << pnm << std::endl; pnm64 = base64_encode(reinterpret_cast(pnm.c_str()), pnm.length()); - //std::cout << "encoded: " << pnm64 << std::endl; + + pnm64 += "\n"; - + send(s, reinterpret_cast(pnm64.c_str()), pnm64.length(), 0); - m_glist = (t_glist *) canvas_getcurrent(); - + //m_glist = (t_glist *) canvas_getcurrent(); - sys_vgui("img%x configure -data {%s}\n", this->x_obj, reinterpret_cast(pnm64.c_str()) ); -// image_drawme((pix_preview *)this->x_obj, (t_glist *) this->getCanvas(), 0, m_xsize, m_ysize); sys_vgui(".x%x.c coords %xS %d %d\n", this->getCanvas(), this->x_obj, text_xpix(this->x_obj, (t_glist *)this->getCanvas()) + (m_xsize/2), text_ypix(this->x_obj, (t_glist *)this->getCanvas()) + (m_ysize/2)); - //fprintf (stderr, "%x %x - %d %d\n",x,(t_object*)x, text_xpix((t_object*)x, glist), text_ypix((t_object*)x, glist)); break; case 2: @@ -417,6 +366,7 @@ void pix_preview :: trigger() void pix_preview :: obj_setupCallback(t_class *classPtr) { class_addbang(classPtr, (t_method)&pix_preview::triggerMessCallback); + class_addmethod(classPtr, (t_method)&pix_preview::connectMessCallback, gensym("connect"), A_NULL); } void pix_preview :: triggerMessCallback(void *data) @@ -424,37 +374,22 @@ void pix_preview :: triggerMessCallback(void *data) GetMyClass(data)->trigger(); } - - - -/* widget helper functions */ +void pix_preview :: connectMessCallback(void *data) +{ + GetMyClass(data)->connectMess(); +} +/* widget helper functions */ void pix_preview :: image_drawme(pix_preview *x, t_glist *glist, int firsttime, int m_xsize, int m_ysize) { - char* ig_path = "/tmp/pixdump01.pnm"; if (firsttime) { - - sys_vgui("image create photo img%x -data {%s}\n",x,fdata); - sys_vgui(".x%x.c create image %d %d -image img%x -tags %xS\n", - glist_getcanvas(glist),text_xpix((t_object*)x, glist)+14, text_ypix((t_object*)x, glist)+14,x,x); - //fprintf (stderr, "%x %x - %d %d \n",x,(t_object*)x, text_xpix((t_object*)x, glist), text_ypix((t_object*)x, glist)); + sys_vgui("image create photo imgPREVIEW%d -data {%s}\n",x->counter,fdata); + fprintf(stderr,"image create photo imgPREVIEW%d -data {%s}\n",x->counter,fdata); + sys_vgui(".x%x.c create image %d %d -image imgPREVIEW%d -tags %xS\n", glist_getcanvas(glist),text_xpix((t_object*)x, glist)+14, text_ypix((t_object*)x, glist)+14,x->counter,x); } - else { - sys_vgui(".x%x.c delete %xS\n", glist_getcanvas(glist), x); - sys_vgui(".x%x.c delete img%x\n", glist_getcanvas(glist), x); - sys_vgui("image create photo img%x -file %s\n",x,ig_path); - sys_vgui(".x%x.c create image %d %d -image img%x -tags %xS\n", - glist_getcanvas(glist),text_xpix((t_object*)x, glist)+(m_xsize/2), text_ypix((t_object*)x, glist)+(m_ysize/2),x,x); - //sys_vgui(".x%x.c coords %xS \ -%d %d\n", - // glist_getcanvas(glist), x, - // text_xpix((t_object*)x, glist), text_ypix((t_object*)x, glist)); - //fprintf (stderr, "%x %x - %d %d\n",x,(t_object*)x, text_xpix((t_object*)x, glist), text_ypix((t_object*)x, glist)); - } - } void pix_preview :: image_erase(pix_preview* x,t_glist* glist) @@ -462,7 +397,6 @@ void pix_preview :: image_erase(pix_preview* x,t_glist* glist) int n; sys_vgui(".x%x.c delete %xS\n", glist_getcanvas(glist), x); - } @@ -473,15 +407,13 @@ void pix_preview :: image_getrect(t_gobj *z, t_glist *glist, int *xp1, int *yp1, int *xp2, int *yp2) { int width, height; - pix_preview* x = (pix_preview*)z; + pix_preview *x = (pix_preview *)z; - width = 250; - height = 50; *xp1 = text_xpix((t_object*)x, glist); *yp1 = text_ypix((t_object*)x, glist); - *xp2 = text_xpix((t_object*)x, glist) + width; - *yp2 = text_ypix((t_object*)x, glist) + height; + *xp2 = text_xpix((t_object*)x, glist) + x->widgetwidth; + *yp2 = text_ypix((t_object*)x, glist) + x->widgetheight; } void pix_preview :: image_displace(t_gobj *z, t_glist *glist, @@ -500,7 +432,9 @@ void pix_preview :: image_displace(t_gobj *z, t_glist *glist, } void pix_preview :: image_select(t_gobj *z, t_glist *glist, int state) -{ t_object *x = (t_object *)z; + { + t_object *x = (t_object *)z; + pix_preview *s = (pix_preview *)z; if (state) { sys_vgui(".x%x.c create rectangle \ %d %d %d %d -tags %xSEL -outline blue\n", @@ -508,10 +442,14 @@ void pix_preview :: image_select(t_gobj *z, t_glist *glist, int state) text_xpix(x, glist), text_ypix(x, glist), text_xpix(x, glist) + 25, text_ypix(x, glist) + 25, x); + s->widgetwidth = 28; + s->widgetheight = 28; } else { sys_vgui(".x%x.c delete %xSEL\n", glist_getcanvas(glist), x); + s->widgetwidth = 0; + s->widgetheight = 0; } } @@ -535,5 +473,6 @@ void pix_preview :: image_vis(t_gobj *z, t_glist *glist, int vis) pix_preview* s = (pix_preview*)z; if (vis) image_drawme(s, glist, 1, 28, 28); + } -- cgit v1.2.1