21 #ifndef KJB_CPP_GR_PLAYER_H
22 #define KJB_CPP_GR_PLAYER_H
24 #ifdef KJB_HAVE_OPENGL
39 void render_video_frame(
const Video& video,
size_t frame,
bool reset_pos =
true)
43 if(num_cols != video.get_width() || num_rows != video.get_height())
return;
45 if(reset_pos) glRasterPos2f(0, 0);
46 glDrawPixels(num_cols, num_rows, GL_RGB, GL_UNSIGNED_BYTE, video.get_buffer(frame));
76 typedef Video_player Self;
80 void operator()(
void const*)
const
89 timer_registered_(false)
92 Video_player(
const std::string& movie_fname) :
96 timer_registered_(false)
101 Video_player(
const std::vector<std::string>& fnames) :
105 timer_registered_(false)
110 const Video& get_video()
const
115 void load(
const std::string& movie_fname)
117 boost::shared_ptr<Video> tmp(
new Video());
120 video_->decode_video(movie_fname);
123 void load(
const std::vector<std::string>& fnames,
float fps)
125 boost::shared_ptr<Video> tmp(
new Video());
127 video_->load_images(fnames, fps);
130 void set(boost::shared_ptr<Video> video)
135 void set(Video* video)
137 video_ = boost::shared_ptr<Video>(video, null_deleter());
141 void attach(kjb::opengl::Glut_window& wnd)
143 using namespace boost;
144 glPixelStorei(GL_PACK_ALIGNMENT, 1);
145 wnd.set_display_callback(bind(&Self::display,
this));
146 wnd.set_special_callback(bind(&Self::special_key,
this, _1, _2, _3));
147 wnd.set_keyboard_callback(bind(&Self::key,
this, _1, _2, _3));
148 wnd.set_size(video_->get_width(), video_->get_height());
153 void render_image(
size_t frame)
const
155 render_video_frame(*video_, frame);
161 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
167 virtual void render()
const
169 render_image(cur_frame_);
172 void special_key(
int k,
int,
int)
178 cur_frame_ = (cur_frame_ + 10) % video_->size();
181 cur_frame_ = (cur_frame_ + video_->size() - 10) % video_->size();
184 cur_frame_ = (cur_frame_ + 1) % video_->size();
187 cur_frame_ = (cur_frame_ + video_->size() - 1) % video_->size();
202 if(timer_registered_ ==
false)
204 float period = 1000.0 / video_->get_frame_rate();
205 kjb::opengl::Glut::add_timer_callback(period, boost::bind(&Self::timer,
this));
206 timer_registered_ =
true;
222 timer_registered_ =
false;
233 cur_frame_ = (cur_frame_ + 1) % video_->size();
242 void key(
unsigned int k,
int,
int)
252 playing_ = !playing_;
263 int current_frame_index()
const
268 boost::shared_ptr<kjb::Video> video_;
273 bool timer_registered_;
size_t get_viewport_height()
Get current GL viewport height.
Definition: gr_opengl.cpp:587
for k
Definition: APPgetLargeConnectedEdges.m:61
size_t get_viewport_width()
Get current GL viewport width.
Definition: gr_opengl.cpp:575
void load(Edge_set &edges, const std::string &fname)
Definition: edge.h:603
void render(const Cuboid &c)
Definition: psi_weighted_box.cpp:56
#define KJB_THROW_2(ex, msg)
Definition: l_exception.h:48
Code for a wrapper class around the C struct KJB_Image.