]> git.sesse.net Git - nageru/blob - image_input.h
Search for images in all directories in --theme-dirs, and install bg.jpeg on make...
[nageru] / image_input.h
1 #ifndef _IMAGE_INPUT_H
2 #define _IMAGE_INPUT_H 1
3
4 #include <map>
5 #include <memory>
6 #include <mutex>
7 #include <string>
8 #include <thread>
9
10 #include <time.h>
11
12 #include <movit/flat_input.h>
13
14 // An output that takes its input from a static image, loaded with ffmpeg.
15 // comes from a single 2D array with chunky pixels. The image is refreshed
16 // from disk about every second.
17 class ImageInput : public movit::FlatInput {
18 public:
19         ImageInput(const std::string &pathname);
20
21         std::string effect_type_id() const override { return "ImageInput"; }
22         void set_gl_state(GLuint glsl_program_num, const std::string& prefix, unsigned *sampler_num) override;
23         static void shutdown_updaters();
24         
25 private:
26         struct Image {
27                 std::unique_ptr<uint8_t[]> pixels;
28                 timespec last_modified;
29         };
30
31         std::string pathname;
32         std::shared_ptr<const Image> current_image;
33
34         static std::shared_ptr<const Image> load_image(const std::string &pathname);
35         static std::shared_ptr<const Image> load_image_raw(const std::string &pathname);
36         static void update_thread_func(const std::string &pathname, const timespec &first_modified);
37         static std::mutex all_images_lock;
38         static std::map<std::string, std::shared_ptr<const Image>> all_images;
39         static std::map<std::string, std::thread> update_threads;
40         static volatile bool threads_should_quit;
41 };
42
43 #endif // !defined(_IMAGE_INPUT_H)