2 #define _IMAGE_INPUT_H 1
5 #include <movit/flat_input.h>
8 #include <condition_variable>
16 #include "ref_counted_texture.h"
17 #include "tweaked_inputs.h"
21 // An output that takes its input from a static image, loaded with ffmpeg.
22 // comes from a single 2D array with chunky pixels. The image is refreshed
23 // from disk about every second.
24 class ImageInput : public sRGBSwitchingFlatInput {
26 // NOTE: You will need to call start_update_thread() yourself, once per program.
27 ImageInput(const std::string &filename);
29 std::string effect_type_id() const override { return "ImageInput"; }
30 void set_gl_state(GLuint glsl_program_num, const std::string& prefix, unsigned *sampler_num) override;
32 static void start_update_thread(QSurface *surface);
33 static void end_update_thread();
37 unsigned width, height;
38 RefCountedTexture tex;
39 timespec last_modified;
43 std::shared_ptr<const Image> current_image;
45 static std::shared_ptr<const Image> load_image(const std::string &filename, const std::string &pathname);
46 static std::shared_ptr<const Image> load_image_raw(const std::string &pathname);
47 static void update_thread_func(QSurface *surface);
48 static std::mutex all_images_lock;
49 static std::map<std::string, std::shared_ptr<const Image>> all_images; // Under all_images_lock.
51 static std::thread update_thread;
52 static std::mutex update_thread_should_quit_mu;
53 static bool update_thread_should_quit; // Under thread_should_quit_mu.
54 static std::condition_variable update_thread_should_quit_modified; // Signals when threads_should_quit is set.
57 #endif // !defined(_IMAGE_INPUT_H)