Update of /cvsroot/pure-data/externals/gem2pdp In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5514
Added Files: help-pix_2pdp.pd pix_2pdp.cpp pix_2pdp.h Log Message: added pix_2pdp
--- NEW FILE: pix_2pdp.cpp --- /* * pix_2pdp : pix to pdp bridge * * Capture the contents of the Gem pix and transform it to a PDP Packet whenever a bang is received * * Based on code of gem2pdp by Yves Degoyon * Many thanks to IOhannes M Zmölnig * * Copyright (c) 2005 Georg Holzmann grh@mur.at * */
#include "pix_2pdp.h" #include "yuv.h"
CPPEXTERN_NEW(pix_2pdp)
pix_2pdp::pix_2pdp(void) { gem_image = NULL; m_pdpoutlet = outlet_new(this->x_obj, &s_anything); }
pix_2pdp::~pix_2pdp() { gem_image = NULL; gem_xsize = 0; gem_ysize = 0; gem_csize = 0; }
// Image processing void pix_2pdp::processImage(imageStruct &image) { gem_image = image.data; gem_xsize = image.xsize; gem_ysize = image.ysize; gem_csize = image.csize; gem_format = image.format; }
// pdp processing void pix_2pdp::bangMess() { t_int psize, px, py; short int *pY, *pU, *pV; unsigned char r,g,b; t_int helper;
if(gem_image) { if(gem_format == GL_RGBA) { // make pdp packet psize = gem_xsize * gem_ysize; m_packet0 = pdp_packet_new_image_YCrCb( gem_xsize, gem_ysize); m_header = pdp_packet_header(m_packet0); m_data = (short int *)pdp_packet_data(m_packet0);
pY = m_data; pV = m_data+psize; pU = m_data+psize+(psize>>2);
for ( py=0; py<gem_ysize; py++) { for ( px=0; px<gem_xsize; px++) { // the way to access the pixels: (C=chRed, chBlue, ...) // image[Y * xsize * csize + X * csize + C] helper = py*gem_xsize*gem_csize + px*gem_csize; r=gem_image[helper+chRed]; g=gem_image[helper+chGreen]; b=gem_image[helper+chBlue];
*(pY) = yuv_RGBtoY( (r<<16) + (g<<8) + b ) << 7; *(pV) = ( yuv_RGBtoV( (r<<16) + (g<<8) + b ) - 128 ) << 8; *(pU) = ( yuv_RGBtoU( (r<<16) + (g<<8) + b ) - 128 ) << 8; pY++; if ( (px%2==0) && (py%2==0) ) { pV++; pU++; } } }
pdp_packet_pass_if_valid(m_pdpoutlet, &m_packet0);
} else { post( "pix_2pdp: Sorry, Gem-input RGB only for now!" ); } } }
void pix_2pdp::obj_setupCallback(t_class *classPtr) { post( "pix_2pdp : a bridge between a Gem pix and PDP/PiDiP, Georg Holzmann 2005 grh@mur.at" ); class_addmethod(classPtr, (t_method)&pix_2pdp::bangMessCallback, gensym("bang"), A_NULL); }
void pix_2pdp::bangMessCallback(void *data) { GetMyClass(data)->bangMess(); }
--- NEW FILE: help-pix_2pdp.pd --- #N canvas 140 53 889 703 10; #X obj 92 298 gemwin; #X obj 338 264 gemhead; #X obj 151 557 pix_texture; #X obj 151 589 rectangle 4 4; #X obj 501 531 pdp_xv; #X msg 546 478 create; #X msg 546 502 destroy; #X obj 338 398 pix_2pdp; #X obj 338 341 t a b; #X obj 338 307 pix_film; #X floatatom 405 293 5 0 1000 0 - - -; #X msg 405 237 set open $1; #X text 446 293 <- frame; #X obj 405 214 openpanel; #X obj 405 194 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1; #X msg 405 262 open /home/Georg/pd-cvs/gem/Gem/examples/data/homer.avi ; #X msg 92 251 create , 1; #X msg 104 273 0 , destroy; #X text 90 229 Gem Control:; #X text 313 223 Gem input:; #X text 385 341 <- so you can trigger pdp automatically each frame ; #X text 401 403 pdp outlet; #X text 261 403 Gem outlet; #X obj 151 528 spigot; #X obj 188 508 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1; #X text 210 514 chain to save CPU; #X obj 368 369 spigot; #X obj 419 370 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1; #X text 441 370 <- turn on/off pdp processing; #X text 210 499 cut Gem render-; #X obj 500 578 pdp_rec~; #X text 498 598 (record a gem-pix !!!); #X text 45 321 (Gem rendering must be on ,; #X text 47 335 but you can cut the Gem; #X text 48 348 render-chain after pix_2pdp; #X text 46 362 and hide the Gem-window; #X text 46 376 to save CPU !); #X text 264 667 =%)!(%= (c) Georg Holzmann grh@mur.at , 2005 =%)!(%= ; #X text 27 79 pix_2pdp captures the contents of a Gem pix and transforms it to a PDP packet with almost no cpu power. So it's possible to convert from Gem to PDP to Gem to PDP to ... if you use the Gem pix objects! ; #X text 490 77 So what can you do with it?; #X text 503 96 - use pix_video/pix_2pdp for firewire input in PDP; #X text 503 111 - use pix_2pdp/pdp_rec~ to record Gem pixes; #X text 503 126 - maybe switch between Gem and PDP all the time; #X text 503 141 - ...; #X text 395 25 pix_2pdp; #X connect 1 0 9 0; #X connect 2 0 3 0; #X connect 5 0 4 0; #X connect 6 0 4 0; #X connect 7 0 23 0; #X connect 7 1 4 0; #X connect 7 1 30 0; #X connect 8 0 7 0; #X connect 8 1 26 0; #X connect 9 0 8 0; #X connect 10 0 9 1; #X connect 11 0 15 0; #X connect 13 0 11 0; #X connect 14 0 13 0; #X connect 15 0 9 0; #X connect 16 0 0 0; #X connect 17 0 0 0; #X connect 23 0 2 0; #X connect 24 0 23 1; #X connect 26 0 7 0; #X connect 27 0 26 1;
--- NEW FILE: pix_2pdp.h --- /* * pix_2pdp : pix to pdp bridge * * Capture the contents of the Gem pix and transform it to a PDP Packet whenever a bang is received * * Based on code of gem2pdp by Yves Degoyon * Many thanks to IOhannes M Zmölnig * * Copyright (c) 2005 Georg Holzmann grh@mur.at * */
#ifndef INCLUDE_PIX2PDP_H_ #define INCLUDE_PIX2PDP_H_
#include "Base/GemPixObj.h" #include "pdp-light.h"
class GEM_EXTERN pix_2pdp : public GemPixObj { CPPEXTERN_HEADER(pix_2pdp, GemPixObj)
public:
// Constructor pix_2pdp(void); protected:
// Destructor virtual ~pix_2pdp(void);
// Image processing virtual void processImage(imageStruct &image);
// pdp processing virtual void bangMess(void);
// the pixBlock with the current image unsigned char *gem_image; int gem_xsize; int gem_ysize; int gem_csize; int gem_format;
// pdp data t_outlet *m_pdpoutlet; int m_packet0; t_pdp *m_header; short int *m_data; private: static void bangMessCallback(void *data); };
#endif