Debian Codegraph @

examples/sdl.hh

raw
1 /*
2 This file is part of dec265, an example application using libde265.
3
4 MIT License
5
6 Copyright (c) 2013-2014 struktur AG, Dirk Farin <[email protected]>
7
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
14
15 The above copyright notice and this permission notice shall be included in all
16 copies or substantial portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 SOFTWARE.
25 */
26
27 #include <SDL2/SDL.h>
28 #include <string>
29 #include <optional>
30
31
32 class SDL_YUV_Display
33 {
34 public:
35
36 enum SDL_Chroma {
37 SDL_CHROMA_MONO=400,
38 SDL_CHROMA_420 =420,
39 SDL_CHROMA_422 =422,
40 SDL_CHROMA_444 =444
41 };
42
43 // Returns error message or nullopt on success.
44 std::optional<std::string> init(int frame_width, int frame_height, enum SDL_Chroma chroma, const char* window_title);
45 void display(const unsigned char *Y, const unsigned char *U, const unsigned char *V,
46 int stride, int chroma_stride);
47 void close();
48
49 bool doQuit() const;
50
51 bool isOpen() const { return mWindowOpen; }
52
53 private:
54 SDL_Window *mWindow = nullptr;
55 SDL_Renderer *mRenderer = nullptr;
56 SDL_Texture *mTexture = nullptr;
57 SDL_Rect rect;
58 bool mWindowOpen;
59 uint8_t *mPixels = nullptr;
60 int mStride = 0;
61
62 SDL_Chroma mChroma;
63
64 void display400(const unsigned char *Y,
65 int stride);
66 void display420(const unsigned char *Y,
67 const unsigned char *U,
68 const unsigned char *V,
69 int stride, int chroma_stride);
70 void display422(const unsigned char *Y,
71 const unsigned char *U,
72 const unsigned char *V,
73 int stride, int chroma_stride);
74 void display444as422(const unsigned char *Y,
75 const unsigned char *U,
76 const unsigned char *V,
77 int stride, int chroma_stride);
78 void display444as420(const unsigned char *Y,
79 const unsigned char *U,
80 const unsigned char *V,
81 int stride, int chroma_stride);
82 };