WebCFace 2.5.2
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
140 [[deprecated("Ambiguous image size")]] ImageFrame(
141 int rows, int cols, const void *data,
142 ImageColorMode color_mode = ImageColorMode::bgr)
143 : ImageFrame(sizeHW(rows, cols), data, color_mode) {}
156 ImageFrame(const Size &size, const void *data, ImageColorMode color_mode);
169 ImageFrame(const Size &size, ImageColorMode color_mode);
170
177 bool empty() const { return data_->size() == 0; }
182 const Size &size() const { return size_; }
187 int width() const { return size_.width(); }
192 int height() const { return size_.height(); }
197 int rows() const { return size_.rows(); }
202 int cols() const { return size_.cols(); }
209 int channels() const;
213 ImageColorMode color_mode() const { return color_mode_; }
220 ImageColorMode colorMode() const { return color_mode_; }
224 ImageCompressMode compress_mode() const { return cmp_mode_; }
229 ImageCompressMode compressMode() const { return cmp_mode_; }
230
231 std::shared_ptr<std::vector<unsigned char>> dataPtr() const {
232 return data_;
233 }
242 const std::vector<unsigned char> &data() const { return *data_; }
250 std::vector<unsigned char> &data() { return *data_; }
257 const unsigned char &at(int row, int col, int ch = 0) const {
258 return dataPtr()->at((row * cols() + col) * channels() + ch);
259 }
267 unsigned char &at(int row, int col, int ch = 0) {
268 return dataPtr()->at((row * cols() + col) * channels() + ch);
269 }
270};
271
272using ImageBase [[deprecated]] = ImageFrame;
273
(ver1.3から追加) 画像データ
Definition image_frame.h:101
unsigned char & at(int row, int col, int ch=0)
画像の要素にアクセス
Definition image_frame.h:267
const std::vector< unsigned char > & data() const
画像データ
Definition image_frame.h:242
ImageColorMode colorMode() const
色の並び順 (生画像データの場合)
Definition image_frame.h:220
ImageCompressMode compress_mode() const
Definition image_frame.h:224
ImageColorMode color_mode() const
Definition image_frame.h:213
bool empty() const
画像が空かどうかを返す
Definition image_frame.h:177
const unsigned char & at(int row, int col, int ch=0) const
画像の要素にアクセス
Definition image_frame.h:257
std::vector< unsigned char > & data()
画像データ (非const)
Definition image_frame.h:250
ImageCompressMode compressMode() const
画像の圧縮モード
Definition image_frame.h:229
int cols() const
画像の幅
Definition image_frame.h:202
const Size & size() const
画像のサイズ
Definition image_frame.h:182
std::shared_ptr< std::vector< unsigned char > > data_
Definition image_frame.h:104
int rows() const
画像の高さ
Definition image_frame.h:197
int height() const
画像の高さ
Definition image_frame.h:192
int width() const
画像の幅
Definition image_frame.h:187
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:231
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:60
#define WEBCFACE_CALL
Definition webcface-config.h:97
#define WEBCFACE_NS_END
Definition webcface-config.h:104
#define WEBCFACE_NS_BEGIN
Definition webcface-config.h:103