libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
sdlvideowidget.h
Go to the documentation of this file.
1
8#pragma once
9
10#include <promeki/namespace.h>
11#include <promeki/widget.h>
13
14struct SDL_Texture;
15struct SDL_Renderer;
16
17PROMEKI_NAMESPACE_BEGIN
18
64class SDLVideoWidget : public Widget {
65 PROMEKI_OBJECT(SDLVideoWidget, Widget)
66 public:
68 enum ScaleMode {
71 ScaleStretch
72 };
73
78 SDLVideoWidget(ObjectBase *parent = nullptr);
79
82
94 void setPayload(const UncompressedVideoPayload::Ptr &payload);
95
100 void setScaleMode(ScaleMode mode) { _scaleMode = mode; }
101
103 ScaleMode scaleMode() const { return _scaleMode; }
104
134 static uint32_t mapPixelFormat(const PixelFormat &pd);
135
152 static uint32_t mapColorspace(const PixelFormat &pd);
153
165 static bool isDirectlyMappable(const PixelFormat &pd);
166
167 protected:
168 void paintEvent(PaintEvent *e) override;
169
170 private:
171 SDL_Texture *_texture = nullptr;
172 Size2Di32 _textureSize{0, 0};
173 uint32_t _texturePixFmt = 0;
174 uint32_t _textureColorspace = 0;
175 ScaleMode _scaleMode = ScaleFit;
176 UncompressedVideoPayload::Ptr _currentPayload;
177 uint32_t _frameCount = 0;
178 uint32_t _framesFastPath = 0;
179
180 void ensureTexture(int w, int h, uint32_t sdlPixFmt, uint32_t sdlColorspace);
181 void uploadPayload(const UncompressedVideoPayload &payload, uint32_t sdlPixFmt);
182 bool uploadCurrentPayload();
183 SDL_Renderer *findRenderer() const;
184};
185
186PROMEKI_NAMESPACE_END
Widget that displays an UncompressedVideoPayload via SDL texture rendering.
Definition sdlvideowidget.h:64
static bool isDirectlyMappable(const PixelFormat &pd)
Returns whether a format can skip CSC conversion on upload.
static uint32_t mapColorspace(const PixelFormat &pd)
Maps a promeki PixelFormat to an SDL_Colorspace.
ScaleMode scaleMode() const
Returns the current scaling mode.
Definition sdlvideowidget.h:103
static uint32_t mapPixelFormat(const PixelFormat &pd)
Maps a promeki PixelFormat to an SDL pixel format.
void setPayload(const UncompressedVideoPayload::Ptr &payload)
Sets the payload to display.
~SDLVideoWidget()
Destructor. Frees the SDL texture.
SDLVideoWidget(ObjectBase *parent=nullptr)
Constructs an SDLVideoWidget.
void setScaleMode(ScaleMode mode)
Sets the scaling mode.
Definition sdlvideowidget.h:100
ScaleMode
Scaling mode for displayed images.
Definition sdlvideowidget.h:68
@ ScaleNone
No scaling, centered at native size.
Definition sdlvideowidget.h:69
@ ScaleFit
Scale to fit, preserving aspect ratio.
Definition sdlvideowidget.h:70