WebCFace 2.9.0
Web-based Communication Framework & Dashboard-like UI
Loading...
Searching...
No Matches
image.h
Go to the documentation of this file.
1#pragma once
2#include <functional>
3#include <optional>
4#include <chrono>
5#include "image_frame.h"
6#include "field.h"
7#ifdef WEBCFACE_MESON
8#include "webcface-config.h"
9#else
10#include "webcface/common/webcface-config.h"
11#endif
12
14
20class WEBCFACE_DLL Image : protected Field {
21 const Image &request(std::optional<int> rows, std::optional<int> cols,
22 ImageCompressMode cmp_mode, int quality,
23 std::optional<ImageColorMode> color_mode,
24 std::optional<double> frame_rate) const;
25
26 public:
27 Image() = default;
28 Image(const Field &base);
29 Image(const Field &base, const SharedString &field)
30 : Image(Field{base, field}) {}
31
32 using Field::lastName;
33 using Field::member;
34 using Field::name;
35 using Field::nameW;
43 return this->Field::child(static_cast<SharedString &>(field));
44 }
49 [[deprecated]]
50 Image child(int index) const {
51 return this->Field::child(std::to_string(index));
52 }
60 Image operator[](StringInitializer field) const { return child(std::move(field)); }
66 [[deprecated]]
67 Image operator[](int index) const {
68 return child(std::to_string(index));
69 }
74 Image parent() const { return this->Field::parent(); }
75
82 const Image &
83 onChange(std::function<void WEBCFACE_CALL_FP(Image)> callback) const;
90 template <typename F, typename std::enable_if_t<std::is_invocable_v<F>,
91 std::nullptr_t> = nullptr>
92 const Image &onChange(F callback) const {
93 return onChange(
94 [callback = std::move(callback)](const auto &) { callback(); });
95 }
103 template <typename T>
104 [[deprecated]] void appendListener(T &&callback) const {
105 onChange(std::forward<T>(callback));
106 }
107
112 const Image &set(const ImageFrame &img) const;
117 const Image &operator=(const ImageFrame &img) const {
118 this->set(img);
119 return *this;
120 }
121
122 protected:
123 const Image &tryRequest() const;
124
125 public:
139 [[deprecated("Ambiguous image size")]]
140 const Image &
141 request(std::optional<int> rows, std::optional<int> cols = std::nullopt,
142 std::optional<ImageColorMode> color_mode = std::nullopt,
143 std::optional<double> frame_rate = std::nullopt) const {
144 return request(rows, cols, ImageCompressMode::raw, 0, color_mode,
145 frame_rate);
146 }
158 const Image &
159 request(std::optional<SizeOption> size = std::nullopt,
160 std::optional<ImageColorMode> color_mode = std::nullopt,
161 std::optional<double> frame_rate = std::nullopt) const {
162 return request(size.value_or(SizeOption{}).rows(),
163 size.value_or(SizeOption{}).cols(),
164 ImageCompressMode::raw, 0, color_mode, frame_rate);
165 }
182 [[deprecated("Ambiguous image size")]]
183 const Image &
184 request(std::optional<int> rows, std::optional<int> cols,
185 ImageCompressMode cmp_mode, int quality,
186 std::optional<double> frame_rate = std::nullopt) const {
187 return request(rows, cols, cmp_mode, quality, std::nullopt, frame_rate);
188 }
203 const Image &
204 request(std::optional<SizeOption> size, ImageCompressMode cmp_mode,
205 int quality,
206 std::optional<double> frame_rate = std::nullopt) const {
207 return request(size.value_or(SizeOption{}).rows(),
208 size.value_or(SizeOption{}).cols(), cmp_mode, quality,
209 std::nullopt, frame_rate);
210 }
217 std::optional<ImageFrame> tryGet() const;
224 ImageFrame get() const { return tryGet().value_or(ImageFrame{}); }
225
226 // operator ImageFrame() const { return get(); }
227
236 bool exists() const;
237
243 [[deprecated]] std::chrono::system_clock::time_point time() const;
244
246 const Image &free() const;
247
249 const Image &clear() const;
250
255 template <typename T, typename std::enable_if_t<std::is_same_v<T, Image>,
256 std::nullptr_t> = nullptr>
257 bool operator==(const T &other) const {
258 return static_cast<Field>(*this) == static_cast<Field>(other);
259 }
260 template <typename T, typename std::enable_if_t<std::is_same_v<T, Image>,
261 std::nullptr_t> = nullptr>
262 bool operator!=(const T &other) const {
263 return static_cast<Field>(*this) != static_cast<Field>(other);
264 }
265};
266
(ver1.3から追加) 画像データ
Definition image_frame.h:101
(ver1.3から追加) 画像の送受信データを表すクラス
Definition image.h:20
Image operator[](int index) const
Definition image.h:67
const Image & operator=(const ImageFrame &img) const
画像をセットする
Definition image.h:117
Image()=default
Image child(StringInitializer field) const
「(thisの名前).(追加の名前)」を新しい名前とするField
Definition image.h:42
bool operator==(const T &other) const
Imageの参照先を比較
Definition image.h:257
Image child(int index) const
Definition image.h:50
const Image & request(std::optional< SizeOption > size, ImageCompressMode cmp_mode, int quality, std::optional< double > frame_rate=std::nullopt) const
画像を圧縮されたフォーマットでリクエストする
Definition image.h:204
const Image & onChange(F callback) const
値が変化したときに呼び出されるコールバックを設定
Definition image.h:92
const Image & request(std::optional< int > rows, std::optional< int > cols=std::nullopt, std::optional< ImageColorMode > color_mode=std::nullopt, std::optional< double > frame_rate=std::nullopt) const
画像を生画像のフォーマットでリクエストする
Definition image.h:141
bool operator!=(const T &other) const
Definition image.h:262
ImageFrame get() const
画像を返す (データがない場合0x0の画像が返る)
Definition image.h:224
void appendListener(T &&callback) const
Definition image.h:104
const Image & request(std::optional< int > rows, std::optional< int > cols, ImageCompressMode cmp_mode, int quality, std::optional< double > frame_rate=std::nullopt) const
画像を圧縮されたフォーマットでリクエストする
Definition image.h:184
Image operator[](StringInitializer field) const
Definition image.h:60
const Image & request(std::optional< SizeOption > size=std::nullopt, std::optional< ImageColorMode > color_mode=std::nullopt, std::optional< double > frame_rate=std::nullopt) const
画像を生画像のフォーマットでリクエストする
Definition image.h:159
Image parent() const
nameの最後のピリオドの前までを新しい名前とするField
Definition image.h:74
Image(const Field &base, const SharedString &field)
Definition image.h:29
u8stringとstringとwstringをshared_ptrで持ち共有する
Definition encoding.h:159
Definition image_frame.h:59
SharedString のpublicなコンストラクタインタフェース (入力専用)
Definition encoding.h:215
ImageCompressMode
Definition image_frame.h:23
ClientDataの参照とメンバ名とデータ名を持つクラス
Definition field.h:71
Field parent() const
nameの最後のピリオドの前までを新しい名前とするField
Definition field.cc:33
Field child(const SharedString &field) const
Definition field.cc:42
#define WEBCFACE_DLL
Definition webcface-config.h:69
#define WEBCFACE_NS_END
Definition webcface-config.h:118
#define WEBCFACE_NS_BEGIN
Definition webcface-config.h:117
#define WEBCFACE_CALL_FP
Definition webcface-config.h:107