WebCFace 3.1.1
Web-based Communication Framework & Dashboard-like UI
Loading...
Searching...
No Matches
image_frame.h
Go to the documentation of this file.
1#pragma once
2#include <optional>
3#include <vector>
4#include <memory>
5#ifdef WEBCFACE_MESON
6#include "webcface-config.h"
7#else
8#include "webcface/common/webcface-config.h"
9#endif
10
12namespace message {
13struct ImageFrame;
14} // namespace message
15
16enum class ImageColorMode {
17 gray = 0,
18 bgr = 1,
19 bgra = 2,
20 rgb = 3,
21 rgba = 4,
22};
24 raw = 0,
25 jpeg = 1,
26 webp = 2,
27 png = 3,
28};
29
30class Size {
31 int w_ = 0, h_ = 0;
32 Size(int width, int height) : w_(width), h_(height) {}
33
34 public:
35 Size() = default;
36 friend Size WEBCFACE_CALL sizeWH(int width, int height);
37 friend Size WEBCFACE_CALL sizeHW(int height, int width);
38 int width() const { return w_; }
39 int height() const { return h_; }
40 int rows() const { return h_; }
41 int cols() const { return w_; }
42};
43
48inline Size WEBCFACE_CALL sizeWH(int width, int height) {
49 return Size{width, height};
50}
55inline Size WEBCFACE_CALL sizeHW(int height, int width) {
56 return Size{width, height};
57}
58
60 std::optional<int> w_, h_;
61 SizeOption(std::optional<int> width, std::optional<int> height)
62 : w_(width), h_(height) {}
63
64 public:
65 SizeOption() = default;
66 SizeOption(const Size &s) : w_(s.width()), h_(s.height()) {}
67 friend SizeOption WEBCFACE_CALL sizeWH(std::optional<int> width,
68 std::optional<int> height);
69 friend SizeOption WEBCFACE_CALL sizeHW(std::optional<int> height,
70 std::optional<int> width);
71 std::optional<int> rows() const { return h_; }
72 std::optional<int> cols() const { return w_; }
73};
74
79inline SizeOption WEBCFACE_CALL sizeWH(std::optional<int> width,
80 std::optional<int> height) {
81 return SizeOption{width, height};
82}
87inline SizeOption WEBCFACE_CALL sizeHW(std::optional<int> height,
88 std::optional<int> width) {
89 return SizeOption{width, height};
90}
91
102 protected:
104 std::shared_ptr<std::vector<unsigned char>> data_;
107
108 public:
113 ImageFrame();
114 ImageFrame(const Size &size,
115 const std::shared_ptr<std::vector<unsigned char>> &data,
116 ImageColorMode color_mode = ImageColorMode::bgr,
117 ImageCompressMode cmp_mode = ImageCompressMode::raw);
119 message::ImageFrame toMessage() const;
120
121 ImageFrame(const ImageFrame &);
122 ImageFrame &operator=(const ImageFrame &);
123 ImageFrame(ImageFrame &&) noexcept;
124 ImageFrame &operator=(ImageFrame &&) noexcept;
125
138 ImageFrame(const Size &size, const void *data, ImageColorMode color_mode);
151 ImageFrame(const Size &size, ImageColorMode color_mode);
152
159 bool empty() const { return data_->size() == 0; }
164 const Size &size() const { return size_; }
169 int width() const { return size_.width(); }
174 int height() const { return size_.height(); }
179 int rows() const { return size_.rows(); }
184 int cols() const { return size_.cols(); }
191 int channels() const;
195 ImageColorMode color_mode() const { return color_mode_; }
202 ImageColorMode colorMode() const { return color_mode_; }
206 ImageCompressMode compress_mode() const { return cmp_mode_; }
211 ImageCompressMode compressMode() const { return cmp_mode_; }
212
213 std::shared_ptr<std::vector<unsigned char>> dataPtr() const {
214 return data_;
215 }
224 const std::vector<unsigned char> &data() const { return *data_; }
232 std::vector<unsigned char> &data() { return *data_; }
239 const unsigned char &at(int row, int col, int ch = 0) const {
240 return dataPtr()->at((row * cols() + col) * channels() + ch);
241 }
249 unsigned char &at(int row, int col, int ch = 0) {
250 return dataPtr()->at((row * cols() + col) * channels() + ch);
251 }
252};
253
254using ImageBase [[deprecated]] = ImageFrame;
255
(ver1.3から追加) 画像データ
Definition image_frame.h:101
unsigned char & at(int row, int col, int ch=0)
画像の要素にアクセス
Definition image_frame.h:249
const std::vector< unsigned char > & data() const
画像データ
Definition image_frame.h:224
ImageColorMode colorMode() const
色の並び順 (生画像データの場合)
Definition image_frame.h:202
ImageCompressMode compress_mode() const
Definition image_frame.h:206
ImageColorMode color_mode() const
Definition image_frame.h:195
const unsigned char & at(int row, int col, int ch=0) const
画像の要素にアクセス
Definition image_frame.h:239
std::vector< unsigned char > & data()
画像データ (非const)
Definition image_frame.h:232
ImageCompressMode compressMode() const
画像の圧縮モード
Definition image_frame.h:211
int cols() const
画像の幅
Definition image_frame.h:184
const Size & size() const
画像のサイズ
Definition image_frame.h:164
std::shared_ptr< std::vector< unsigned char > > data_
Definition image_frame.h:104
int rows() const
画像の高さ
Definition image_frame.h:179
int height() const
画像の高さ
Definition image_frame.h:174
int width() const
画像の幅
Definition image_frame.h:169
ImageColorMode color_mode_
Definition image_frame.h:105
Size size_
Definition image_frame.h:103
ImageCompressMode cmp_mode_
Definition image_frame.h:106
std::shared_ptr< std::vector< unsigned char > > dataPtr() const
Definition image_frame.h:213
Definition image_frame.h:59
std::optional< int > rows() const
Definition image_frame.h:71
std::optional< int > cols() const
Definition image_frame.h:72
SizeOption(const Size &s)
Definition image_frame.h:66
Definition image_frame.h:30
int cols() const
Definition image_frame.h:41
int rows() const
Definition image_frame.h:40
int height() const
Definition image_frame.h:39
int width() const
Definition image_frame.h:38
Size()=default
Size sizeHW(int height, int width)
高さ × 幅 でサイズを指定
Definition image_frame.h:55
Size sizeWH(int width, int height)
幅 × 高さ でサイズを指定
Definition image_frame.h:48
ImageCompressMode
Definition image_frame.h:23
ImageColorMode
Definition image_frame.h:16
Definition image.h:39
#define WEBCFACE_DLL
Definition webcface-config.h:69
#define WEBCFACE_CALL
Definition webcface-config.h:106
#define WEBCFACE_NS_END
Definition webcface-config.h:113
#define WEBCFACE_NS_BEGIN
Definition webcface-config.h:112