1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
|
#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(void) :
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(GEM_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[chRed]=(255*getRandom());
data[chGreen]=(255*getRandom());
data[chBlue]=(255*getRandom());
data[chAlpha]=255;
data+=4;
}
}
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(GEM_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(const 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"));
return true;
}
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();
unsigned 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;
}
|