]> git.sesse.net Git - nageru/blob - jpeg_frame_view.h
Make it possible to switch camera angles by clicking on the preview displays.
[nageru] / jpeg_frame_view.h
1 #ifndef _JPEG_FRAME_VIEW_H
2 #define _JPEG_FRAME_VIEW_H 1
3
4 #include <epoxy/gl.h>
5 #include <QGLWidget>
6
7 #include <stdint.h>
8
9 #include <movit/effect_chain.h>
10 #include <movit/ycbcr_input.h>
11
12 #include <memory>
13
14 struct JPEGID {
15         unsigned stream_idx;
16         int64_t pts;
17 };
18 struct Frame {
19         std::unique_ptr<uint8_t[]> y, cb, cr;
20         unsigned width, height;
21         unsigned chroma_subsampling_x, chroma_subsampling_y;
22         unsigned pitch_y, pitch_chroma;
23 };
24 enum CacheMissBehavior {
25         DECODE_IF_NOT_IN_CACHE,
26         RETURN_NULLPTR_IF_NOT_IN_CACHE
27 };
28
29 std::string filename_for_frame(unsigned stream_idx, int64_t pts);
30 std::shared_ptr<Frame> decode_jpeg(const std::string &filename);
31 std::shared_ptr<Frame> decode_jpeg_with_cache(JPEGID id, CacheMissBehavior cache_miss_behavior, bool *did_decode);
32
33 class JPEGFrameView : public QGLWidget {
34         Q_OBJECT
35
36 public:
37         JPEGFrameView(QWidget *parent);
38
39         void setFrame(unsigned stream_idx, int64_t pts)
40         {
41                 this->stream_idx = stream_idx;
42                 this->pts = pts;
43                 update_frame();
44         }
45
46         void mousePressEvent(QMouseEvent *event) override;
47
48         unsigned get_stream_idx() const { return stream_idx; }
49
50         void setDecodedFrame(std::shared_ptr<Frame> frame);
51
52 signals:
53         void clicked();
54
55 protected:
56         void initializeGL() override;
57         void resizeGL(int width, int height) override;
58         void paintGL() override;
59
60 private:
61         void update_frame();
62
63         unsigned stream_idx;
64         int64_t pts;
65
66         std::unique_ptr<movit::EffectChain> chain;
67         std::shared_ptr<Frame> current_frame;  // So that we hold on to the pixels.
68         movit::YCbCrInput *ycbcr_input;
69         movit::YCbCrFormat ycbcr_format;
70 };
71
72 #endif  // !defined(_JPEG_FRAME_VIEW_H)