Revision: 10627 http://pure-data.svn.sourceforge.net/pure-data/?rev=10627&view=rev Author: lluisbigorda Date: 2009-01-25 01:14:06 +0000 (Sun, 25 Jan 2009)
Log Message: ----------- new tlc-sockets procedure to get frame data and paint into the canvas
Modified Paths: -------------- trunk/externals/pdvjtools/pix_preview/pix_preview.cc
Modified: trunk/externals/pdvjtools/pix_preview/pix_preview.cc =================================================================== --- trunk/externals/pdvjtools/pix_preview/pix_preview.cc 2009-01-25 01:12:52 UTC (rev 10626) +++ trunk/externals/pdvjtools/pix_preview/pix_preview.cc 2009-01-25 01:14:06 UTC (rev 10627) @@ -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\xFCnther Geiger. -// Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::f\xFCr::uml\xE4ute. 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\xFCr::uml\xE4ute:2000 -// IOhannes m zmoelnig -// mailto:zmoelnig@iem.kug.ac.at +// Lluis Gomez i Bigorda +// mailto:lluis@artefacte.org // /////////////////////////////////////////////////////////
@@ -30,8 +13,13 @@ #include <sstream> using namespace std; #include "stdio.h" +#include <sys/types.h> +#include <netinet/in.h> +#include <sys/socket.h> +#include <arpa/inet.h> +#include <netdb.h> +#include <errno.h>
- #include "m_pd.h" #include "m_imp.h" #include "g_canvas.h" @@ -39,46 +27,15 @@
#include "pix_preview.h"
-int guidebug=0; +#define initialport 1234
-#define COLORGRID_SYS_VGUI2(a,b) if (guidebug) \ - post(a,b);\ - sys_vgui(a,b) +int guidebug=1;
-#define COLORGRID_SYS_VGUI3(a,b,c) if (guidebug) \ - post(a,b,c);\ - sys_vgui(a,b,c) +char *fdata="R0lGODlhHAAcAIABAAAAAP///ywAAAAAHAAcAAACGoSPqcvtD6OctNqLs968+w+G4kiW5omm6ooUADs=";
-#define COLORGRID_SYS_VGUI4(a,b,c,d) if (guidebug) \ - post(a,b,c,d);\ - sys_vgui(a,b,c,d) +int pix_preview::counter;
-#define COLORGRID_SYS_VGUI5(a,b,c,d,e) if (guidebug) \ - post(a,b,c,d,e);\ - sys_vgui(a,b,c,d,e) - -#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="; - - /* base64 conversion*/ - static const std::string base64_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" @@ -128,19 +85,6 @@ }
- - - - - - - - - - - - - CPPEXTERN_NEW_WITH_TWO_ARGS(pix_preview, t_floatarg, A_DEFFLOAT, t_floatarg, A_DEFFLOAT)
@@ -153,8 +97,11 @@ // ///////////////////////////////////////////////////////// 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 @@
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<const char*>(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 @@ // 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<const char*>(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 :: trigger() { if (!m_data) return; +
int n = m_ysize, m = 0; int i = 0; @@ -279,7 +266,7 @@ 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 @@ 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 @@ line = m_data + (int)(m_ystep*n); data = line; } - fclose (fp);
//std::cout << "NOT encoded: " << pnm << std::endl;
pnm64 = base64_encode(reinterpret_cast<const unsigned char*>(pnm.c_str()), pnm.length()); - //std::cout << "encoded: " << pnm64 << std::endl; + + pnm64 += "\n";
- + send(s, reinterpret_cast<const unsigned char*>(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<const unsigned char*>(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 :: 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 @@ GetMyClass(data)->trigger(); }
+void pix_preview :: connectMessCallback(void *data) +{ + GetMyClass(data)->connectMess(); +}
-/* widget helper functions */
- - - +/* 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 @@ int n; sys_vgui(".x%x.c delete %xS\n", glist_getcanvas(glist), x); - }
@@ -473,15 +407,13 @@ 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_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 @@ 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 @@ pix_preview* s = (pix_preview*)z; if (vis) image_drawme(s, glist, 1, 28, 28); + }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.