42 const char * image ,
size_t image_dx ,
size_t image_dy ,
int offset_x ,
int offset_y ,
43 triple_t fg ,
bool draw_bg =
false ,
size_t lhs_blank = 0U ) ;
44 int hex_value(
char c ) ;
53 size_t image_dx ,
size_t image_dy ,
size_t offset_x ,
size_t offset_y ,
55 void operator()(
bool b ,
size_t ) ;
57 unsigned char * m_row ;
59 unsigned char * m_lhs ;
60 unsigned char * m_rhs ;
97 if( scale.m_dx != 640 || scale.m_dy != 480 || scale.m_buffersize != (scale.m_dx*scale.m_dy*3U) )
98 throw std::runtime_error(
"unexpected frame buffer size for demo image" ) ;
99 m_imp->drawScene( b , scale ) ;
108 m_bg(triple_t(255U,240U,240U))
112 void Gv::DemoImp::jitter()
114 for(
int i = 0 ; i < 12 ; i++ )
115 m_j[i] = std::rand() % 5 ;
118 void Gv::DemoImp::still()
120 for(
int i = 0 ; i < 12 ; i++ )
124 void Gv::DemoImp::drawScene( CaptureBuffer & b ,
const CaptureBufferScale & scale )
126 Out::clear( b , m_bg ) ;
129 triple_t c[] = { triple_t(0,0,70) , triple_t(50,0,80) , triple_t(70,0,100) } ;
133 drawItem( b , scale , data::cars_data , data::cars_dx , data::cars_dy ,
134 270+m_cars_pos , 141 , c[2] ,
false , m_cars_pos < 212U ? (212U-m_cars_pos) : 0U ) ;
136 if( m_cars_pos == 420U )
142 drawItem( b , scale , data::base_data , data::base_dx , data::base_dy , 65 , 10 , c[0] ) ;
150 if( (now.s % 9) == 0 )
152 drawItem( b , scale , data::finger_1_data , data::finger_1_dx , data::finger_1_dy , finger_x+m_j[0] , finger_y+m_j[1] , c[0] ) ;
153 drawItem( b , scale , data::finger_2_data , data::finger_2_dx , data::finger_2_dy , finger_x+m_j[2] , finger_y+m_j[3] , c[0] ) ;
154 drawItem( b , scale , data::finger_3_data , data::finger_3_dx , data::finger_3_dy , finger_x+m_j[4] , finger_y+m_j[5] , c[0] ) ;
155 drawItem( b , scale , data::finger_4_data , data::finger_4_dx , data::finger_4_dy , finger_x+m_j[6] , finger_y+m_j[7] , c[0] ) ;
156 drawItem( b , scale , data::finger_5_data , data::finger_5_dx , data::finger_5_dy , finger_x+m_j[8] , finger_y+m_j[9] , c[0] ) ;
157 drawItem( b , scale , data::finger_6_data , data::finger_6_dx , data::finger_6_dy , finger_x+m_j[10] , finger_y+m_j[11] , c[0] ) ;
162 if( time.minutes() == 0 && time.seconds() < 3 )
163 drawItem( b , scale , data::bird_data , data::bird_dx , data::bird_dy , 7 , 120 , c[1] ) ;
168 if( m_blink == 0 || now.s == m_blink )
170 if( now.us < 150000 )
171 drawItem( b , scale , data::blink_data , data::blink_dx , data::blink_dy , 256 , 112 , c[0] ,
true ) ;
173 m_blink = now.s + 5 ;
179 if( (now.s % 19) < 2 )
180 drawItem( b , scale , data::grimace_data , data::grimace_dx , data::grimace_dy , 245 , 160 , c[0] ,
true ) ;
185 int minute_index = time.minutes() ;
186 int hour_index = ((time.hours() % 12)*5) + time.minutes()/12 ;
187 G_ASSERT(
sizeof(data::minute_hand_data)/
sizeof(data::minute_hand_data[0]) == 60 ) ;
188 G_ASSERT(
sizeof(data::hour_hand_data)/
sizeof(data::hour_hand_data[0]) == 60 ) ;
189 minute_index %= 60 ; hour_index %= 60 ;
190 drawItem( b , scale , data::minute_hand_data[minute_index] , data::minute_hand_dx , data::minute_hand_dy , 97 , 42 , c[0] ) ;
191 drawItem( b , scale , data::hour_hand_data[hour_index] , data::hour_hand_dx , data::hour_hand_dy , 97 , 42 , c[0] ) ;
195 void Gv::DemoImp::drawItem( CaptureBuffer & b ,
const CaptureBufferScale & scale ,
196 const char * image_rle ,
size_t image_dx ,
size_t image_dy ,
int offset_x ,
int offset_y ,
197 triple_t fg ,
bool draw_bg ,
size_t lhs_blank )
199 Out out( b , scale , image_dx , image_dy , offset_x , offset_y , fg , m_bg , draw_bg , lhs_blank ) ;
201 for(
const char * p = image_rle ; p[0] && p[1] ; p += 2 )
203 int n = (hex_value(p[0])<<4) + hex_value(p[1]) ;
204 bool v = !( n & 0x80 ) ;
205 size_t length = n & 0x7f ;
210 int Gv::DemoImp::hex_value(
char c )
212 if( c >=
'0' && c <=
'9' )
214 else if( c >=
'A' && c <=
'F' )
215 return (c -
'A') + 10 ;
223 size_t image_dx ,
size_t image_dy ,
size_t offset_x ,
size_t offset_y ,
224 triple_t fg , triple_t bg ,
bool draw_bg ,
size_t lhs_blank ) :
225 m_linesize(scale.m_linesize) ,
226 m_image_dx(image_dx) ,
227 m_offset_x_3(offset_x*3U) ,
233 G_ASSERT( offset_y < scale.m_dy ) ;
234 m_row = b.
begin() + ( offset_y * m_linesize ) ;
235 m_p = m_row + m_offset_x_3 ;
236 m_lhs = m_p + ( lhs_blank * 3U ) ;
237 m_rhs = m_row + m_linesize ;
242 const unsigned char *
const end = b.
end() ;
243 for(
unsigned char * p = b.
begin() ; p < end ; p += 3 )
251 void Gv::DemoImp::Out::operator()(
bool b ,
size_t n )
255 for(
size_t i = 0U ; i < n && m_p < m_rhs ; i++ , m_p += 3 )
259 m_p[0] = b ? m_fg.r() : m_bg.r() ;
260 m_p[1] = b ? m_fg.g() : m_bg.g() ;
261 m_p[2] = b ? m_fg.b() : m_bg.b() ;
267 for(
size_t i = 0U ; i < n && m_p < m_rhs ; i++ , m_p += 3 )
279 m_p += n ; m_p += n ; m_p += n ;
285 if( m_image_x >= m_image_dx )
288 m_lhs += m_linesize ;
289 m_rhs += m_linesize ;
290 m_row += m_linesize ;
291 m_p = m_row + m_offset_x_3 ;
A subsecond-resolution timestamp based on a time_t.
virtual bool init() override
Override from Gv::ImageGenerator.
virtual ~Demo()
Destructor.
A representation of a timezone.
const unsigned char * begin() const
Returns a pointer to start of the dword-aligned data buffer.
A simple time-of-day (hh/mm/ss) class.
const unsigned char * end() const
Returns a pointer off the end of the raw data buffer.
static EpochTime now()
Returns the current epoch time.
A video-capture buffer class to hold image data, with overloaded constructors for the various V4l i/o...
A pimple-pattern implementation class for Gv::Demo.
Demo(int dx, int dy, const std::string &dev_config, Gv::Timezone)
Constructor.
A structure holding capture buffer dimensions.
virtual void fillBuffer(CaptureBuffer &, const CaptureBufferScale &) override
Override from Gv::ImageGenerator.