30 enum Colour { c_black , c_white , c_yellow , c_cyan , c_green , c_magenta ,
31 c_red , c_blue , c_orange , c_purple , c__max } ;
51 Colour colour(
int x ,
int y )
const ;
56 template <
typename T>
BarsGenerator(
bool in_rows ,
int dx ,
int dy ,
int speed , T c_begin , T c_end ) ;
64 std::vector<Colour> m_colours ;
73 BarsImp(
int dx ,
int dy ,
const std::string & type ) ;
82 std::vector<triple_t> m_colour_yuv ;
90 int type(
const std::string & config )
96 Gv::BarsImp::BarsImp(
int dx ,
int dy ,
const std::string & config ) :
99 m_generator(BarsGenerator::make(m_dx,m_dy,type(config)))
101 m_colour_yuv.resize( c__max , triple_t(0,0,0) ) ;
114 void Gv::BarsImp::fillBuffer(
Gv::CaptureBuffer & b ,
const CaptureBufferScale & scale )
116 G_ASSERT(
int(scale.m_dx) == m_dx &&
int(scale.m_dy) == m_dy ) ;
119 unsigned char * p_row = b.
begin() ;
120 for(
int y = 0 ; y < m_dy ; ++y , p_row += (m_dx*2) )
122 unsigned char * p = p_row ;
123 for(
int x = 0 ; x < m_dx ; x++ , p += 2 )
125 triple_t
yuv = m_colour_yuv.at(m_generator.colour(x,y)) ;
126 if( (p+1) >= b.
end() )
return ;
128 p[1] = ( (long)p & 2 ) ? yuv.v() : yuv.u() ;
136 m_imp(new
BarsImp(dx,dy,config))
152 m_imp->fillBuffer( b , scale ) ;
157 template <
typename T>
158 Gv::BarsGenerator::BarsGenerator(
bool in_rows ,
int dx ,
int dy ,
int speed , T c_begin , T c_end ) :
164 m_colours(c_begin,c_end)
168 void Gv::BarsGenerator::move()
170 m_offset += m_speed ;
171 if( ( m_in_rows && m_offset == m_dy ) || m_offset == m_dx )
175 Colour Gv::BarsGenerator::colour(
int x ,
int y )
const
179 m_colours.at( (colours()*(y+m_offset)/m_dy) % colours() ) :
180 m_colours.at( (colours()*(x+m_offset)/m_dx) % colours() ) ;
183 int Gv::BarsGenerator::colours()
const
185 return static_cast<int>(m_colours.size()) ;
192 Colour colours[] = { c_black , c_white , c_yellow , c_cyan , c_green , c_magenta , c_red , c_blue } ;
193 return BarsGenerator(
false , dx , dy , 1 , colours , colours+8 ) ;
197 Colour colours[] = { c_red , c_orange , c_yellow , c_green , c_blue , c_purple } ;
198 return BarsGenerator(
true , dx , dy , 1 , colours , colours+6 ) ;
Bars(int dx, int dy, const std::string &config)
Constructor.
virtual void fillBuffer(CaptureBuffer &, const CaptureBufferScale &) override
Override from Gv::ImageGenerator.
const unsigned char * begin() const
Returns a pointer to start of the dword-aligned data buffer.
const unsigned char * end() const
Returns a pointer off the end of the raw data buffer.
virtual ~Bars()
Destructor.
A implementation class for Gv::BarsImp.
virtual bool init() override
Override from Gv::ImageGenerator.
A video-capture buffer class to hold image data, with overloaded constructors for the various V4l i/o...
static bool splitMatch(const std::string &in, const std::string &s, const std::string &ws=Str::ws())
Returns true if any of the split parts of 'in' are equal to 's'.
A structure holding capture buffer dimensions.
triple< unsigned char > yuv(triple< unsigned char > rgb) g__noexcept
A top-level function that calculates yuv from rgb with default implementation options.
A pimple-pattern implementation class for Gv::Bars.
triple< unsigned char > yuv_int(triple< unsigned char > rgb) g__noexcept
A fast conversion from rgb to yuv.