Revision: 4441 http://pd-gem.svn.sourceforge.net/pd-gem/?rev=4441&view=rev Author: zmoelnig Date: 2011-08-08 14:33:28 +0000 (Mon, 08 Aug 2011)
Log Message: ----------- videoTEST plugin for test images Added Paths: ----------- trunk/Gem/plugins/videoTEST/ trunk/Gem/plugins/videoTEST/Makefile.am trunk/Gem/plugins/videoTEST/videoTEST.cpp trunk/Gem/plugins/videoTEST/videoTEST.h Added: trunk/Gem/plugins/videoTEST/Makefile.am =================================================================== --- trunk/Gem/plugins/videoTEST/Makefile.am (rev 0) +++ trunk/Gem/plugins/videoTEST/Makefile.am 2011-08-08 14:33:28 UTC (rev 4441) @@ -0,0 +1,23 @@ + +ACLOCAL_AMFLAGS = -I $(top_srcdir)/m4 +AM_CPPFLAGS = -I$(top_srcdir)/src + +pkglib_LTLIBRARIES= + +pkglib_LTLIBRARIES+=gem_videoTEST.la + +gem_videoTEST_la_CXXFLAGS = +gem_videoTEST_la_LDFLAGS = -module -avoid-version -shared +gem_videoTEST_la_LIBADD = + +# RTE +gem_videoTEST_la_CXXFLAGS += @GEM_RTE_CFLAGS@ @GEM_ARCH_CXXFLAGS@ +gem_videoTEST_la_LDFLAGS += @GEM_RTE_LIBS@ @GEM_ARCH_LDFLAGS@ + +# convenience symlinks +include $(srcdir)/../symlink_ltlib.mk + + +### SOURCES +gem_videoTEST_la_SOURCES= videoTEST.cpp videoTEST.h + Added: trunk/Gem/plugins/videoTEST/videoTEST.cpp =================================================================== --- trunk/Gem/plugins/videoTEST/videoTEST.cpp (rev 0) +++ trunk/Gem/plugins/videoTEST/videoTEST.cpp 2011-08-08 14:33:28 UTC (rev 4441) @@ -0,0 +1,168 @@ +#include "videoTEST.h" +#include "plugins/PluginFactory.h" +using namespace gem::plugins; + +REGISTER_VIDEOFACTORY("test", videoTEST); + +static double getRandom(void) { + static unsigned int random_nextseed = 1489853723; + random_nextseed = random_nextseed * 435898247 + 938284281; + return random_nextseed * (1./4294967296.);; +} + +videoTEST::videoTEST() : + m_name(std::string("test")), + m_open(false), + m_type(0) +{ + m_pixBlock.image.xsize = 64; + m_pixBlock.image.ysize = 64; + m_pixBlock.image.setCsizeByFormat(GL_RGBA); + m_pixBlock.image.reallocate(); +} + +videoTEST::~videoTEST(void) { +} + +bool videoTEST::open(gem::Properties&props) { + setProperties(props); + return (m_open); +} + +static void setNoise(unsigned char*data, unsigned int count) { + unsigned int i=0; + for(i=0; i<count;i++) { + *data++=(255*getRandom()); + *data++=(255*getRandom()); + *data++=(255*getRandom()); + *data++=255; + } +} +static void setRed(unsigned char*data, unsigned int count) { + unsigned int i=0; + for(i=0; i<count;i++) { + data[chRed]=255; + data[chGreen]=0; + data[chBlue]=0; + data[chAlpha]=255; + data+=4; + } +} +static void setGreen(unsigned char*data, unsigned int count) { + unsigned int i=0; + for(i=0; i<count;i++) { + data[chRed]=0; + data[chGreen]=255; + data[chBlue]=0; + data[chAlpha]=255; + data+=4; + } +} +static void setBlue(unsigned char*data, unsigned int count) { + unsigned int i=0; + for(i=0; i<count;i++) { + data[chRed]=0; + data[chGreen]=0; + data[chBlue]=255; + data[chAlpha]=255; + data+=4; + } +} + +pixBlock*videoTEST::getFrame(void) { + m_pixBlock.image.setCsizeByFormat(GL_RGBA); + m_pixBlock.image.reallocate(); + const unsigned int count = m_pixBlock.image.xsize * m_pixBlock.image.ysize; + unsigned int i=0; + unsigned char*data=m_pixBlock.image.data; + + switch(m_type) { + case 1: setRed(data, count); break; + case 2: setGreen(data, count); break; + case 3: setBlue(data, count); break; + default: setNoise(data, count); break; + } + + m_pixBlock.newimage = true; + + return &m_pixBlock; +} + +std::vector<std::string>videoTEST::enumerate(void) { + std::vector<std::string>result; + result.push_back("test"); + return result; +} + +bool videoTEST::setDevice(int ID) { + m_open=(0==ID); + return m_open; +} +bool videoTEST::setDevice(std::string device) { + m_open=("test"==device); + return m_open; +} +bool videoTEST::enumProperties(gem::Properties&readable, + gem::Properties&writeable) { + readable.clear(); + writeable.clear(); + + + writeable.set("width", 64); readable.set("width", 64); + writeable.set("height", 64); readable.set("height", 64); + + writeable.set("type", std::string("noise")); +} +void videoTEST::setProperties(gem::Properties&props) { + m_props=props; + + double d; + if(props.get("width", d)) { + if(d>0) + m_pixBlock.image.xsize = d; + } + if(props.get("height", d)) { + if(d>0) + m_pixBlock.image.ysize = d; + } + std::string s; + if(props.get("type", s)) { + if("noise"==s) + m_type=0; + else if("red"==s) + m_type=1; + else if("green"==s) + m_type=2; + else if("blue"==s) + m_type=3; + } +} +void videoTEST::getProperties(gem::Properties&props) { + std::vector<std::string>keys=props.keys(); + double d; + int i; + for(i=0; i<keys.size(); i++) { + if("width"==keys[i]) { + props.set(keys[i], m_pixBlock.image.xsize); + } + if("height"==keys[i]) { + props.set(keys[i], m_pixBlock.image.ysize); + } + } +} + +std::vector<std::string>videoTEST::dialogs(void) { + std::vector<std::string>result; + return result; +} +bool videoTEST::provides(const std::string name) { + return (name==m_name); +} +std::vector<std::string>videoTEST::provides(void) { + std::vector<std::string>result; + result.push_back(m_name); + return result; +} +const std::string videoTEST::getName(void) { + return m_name; +} Added: trunk/Gem/plugins/videoTEST/videoTEST.h =================================================================== --- trunk/Gem/plugins/videoTEST/videoTEST.h (rev 0) +++ trunk/Gem/plugins/videoTEST/videoTEST.h 2011-08-08 14:33:28 UTC (rev 4441) @@ -0,0 +1,57 @@ +#ifndef INCLUDE_GEM_VIDEOTEST_H_ +#define INCLUDE_GEM_VIDEOTEST_H_ + +#include "plugins/video.h" +#include "Gem/Image.h" + +namespace gem { namespace plugins { + class GEM_EXTERN videoTEST : public video { + private: + std::string m_name; + bool m_open; + pixBlock m_pixBlock; + Properties m_props; + unsigned int m_type; + public: + videoTEST(void); + + virtual ~videoTEST(void); + + virtual bool open(gem::Properties&props); + virtual pixBlock *getFrame(void); + + virtual std::vector<std::string>enumerate(void); + virtual bool setDevice(int ID); + virtual bool setDevice(const std::string); + + + virtual bool enumProperties(gem::Properties&readable, + gem::Properties&writeable); + virtual void setProperties(gem::Properties&props); + virtual void getProperties(gem::Properties&props); + + virtual std::vector<std::string>dialogs(void); + // for pix_video: query whether this backend provides access to this class of devices + // (e.g. "dv") + virtual bool provides(const std::string); + // get a list of all provided devices + virtual std::vector<std::string>provides(void); + + // get's the name of the backend (e.g. "v4l") + virtual const std::string getName(void); + + virtual bool isThreadable(void) {return true;} + virtual bool reset(void) {return true;} + virtual void releaseFrame(void) {} + virtual bool grabAsynchronous(bool) {return true;} + virtual bool dialog(std::vector<std::string>names=std::vector<std::string>()) {return false;} + virtual bool setColor(int) {return false;} + + + virtual void close(void) {}; + virtual bool start(void) {}; + virtual bool stop(void) {}; +}; +};}; // namespace + +#endif // for header file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA The must-attend event for mobile developers. Connect with experts. Get tools for creating Super Apps. See the latest technologies. Sessions, hands-on labs, demos & much more. Register early & save! http://p.sf.net/sfu/rim-blackberry-1 _______________________________________________ pd-gem-CVS mailing list pd-gem-CVS@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/pd-gem-cvs