]> git.sesse.net Git - nageru/blob - nageru/image_input.h
Fix a comment typo.
[nageru] / nageru / image_input.h
1 #ifndef _IMAGE_INPUT_H
2 #define _IMAGE_INPUT_H 1
3
4 #include <epoxy/gl.h>
5 #include <movit/flat_input.h>
6 #include <stdbool.h>
7 #include <time.h>
8 #include <condition_variable>
9 #include <cstdint>
10 #include <map>
11 #include <memory>
12 #include <mutex>
13 #include <string>
14 #include <thread>
15
16 #include "ref_counted_texture.h"
17 #include "tweaked_inputs.h"
18
19 class QSurface;
20
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 {
25 public:
26         // For loading images.
27         // NOTE: You will need to call start_update_thread() yourself, once per program.
28         struct Image {
29                 unsigned width, height;
30                 RefCountedTexture tex;
31                 timespec last_modified;
32         };
33         static std::shared_ptr<const Image> load_image(const std::string &filename, const std::string &pathname);
34
35         // Actual members.
36
37         ImageInput();  // Construct an empty input, which can't be used until you call switch_image().
38         ImageInput(const std::string &filename);
39
40         std::string effect_type_id() const override { return "ImageInput"; }
41         void set_gl_state(GLuint glsl_program_num, const std::string& prefix, unsigned *sampler_num) override;
42
43         // Switch to a different image. The image must be previously loaded using load_image().
44         void switch_image(const std::string &pathname);
45
46         std::string get_pathname() const { return pathname; }
47
48         static void start_update_thread(QSurface *surface);
49         static void end_update_thread();
50         
51 private:
52         std::string pathname;
53         std::shared_ptr<const Image> current_image;
54
55         static std::shared_ptr<const Image> load_image_raw(const std::string &pathname);
56         static void update_thread_func(QSurface *surface);
57         static std::mutex all_images_lock;
58         static std::map<std::string, std::shared_ptr<const Image>> all_images;  // Under all_images_lock.
59
60         static std::thread update_thread;
61         static std::mutex update_thread_should_quit_mu;
62         static bool update_thread_should_quit;  // Under thread_should_quit_mu.
63         static std::condition_variable update_thread_should_quit_modified;  // Signals when threads_should_quit is set.
64 };
65
66 #endif // !defined(_IMAGE_INPUT_H)