WebCFace 2.5.2
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;
40 Image child(std::string_view field) const {
41 return this->Field::child(field);
42 }
47 Image child(std::wstring_view field) const {
48 return this->Field::child(field);
49 }
53 Image child(int index) const { return this->Field::child(index); }
58 Image operator[](std::string_view field) const { return child(field); }
63 Image operator[](std::wstring_view field) const { return child(field); }
68 Image operator[](const char *field) const { return child(field); }
72 Image operator[](const wchar_t *field) const { return child(field); }
77 Image operator[](int index) const { return child(index); }
82 Image parent() const { return this->Field::parent(); }
83
90 const Image &
91 onChange(std::function<void WEBCFACE_CALL_FP(Image)> callback) const;
98 template <typename F, typename std::enable_if_t<std::is_invocable_v<F>,
99 std::nullptr_t> = nullptr>
100 const Image &onChange(F callback) const {
101 return onChange(
102 [callback = std::move(callback)](const auto &) { callback(); });
103 }
111 template <typename T>
112 [[deprecated]] void appendListener(T &&callback) const {
113 onChange(std::forward<T>(callback));
114 }
115
120 const Image &set(const ImageFrame &img) const;
125 const Image &operator=(const ImageFrame &img) const {
126 this->set(img);
127 return *this;
128 }
129
130 protected:
131 const Image &tryRequest() const;
132
133 public:
147 [[deprecated("Ambiguous image size")]]
148 const Image &
149 request(std::optional<int> rows, std::optional<int> cols = std::nullopt,
150 std::optional<ImageColorMode> color_mode = std::nullopt,
151 std::optional<double> frame_rate = std::nullopt) const {
152 return request(rows, cols, ImageCompressMode::raw, 0, color_mode,
153 frame_rate);
154 }
166 const Image &
167 request(std::optional<SizeOption> size = std::nullopt,
168 std::optional<ImageColorMode> color_mode = std::nullopt,
169 std::optional<double> frame_rate = std::nullopt) const {
170 return request(size.value_or(SizeOption{}).rows(),
171 size.value_or(SizeOption{}).cols(),
172 ImageCompressMode::raw, 0, color_mode, frame_rate);
173 }
190 [[deprecated("Ambiguous image size")]]
191 const Image &
192 request(std::optional<int> rows, std::optional<int> cols,
193 ImageCompressMode cmp_mode, int quality,
194 std::optional<double> frame_rate = std::nullopt) const {
195 return request(rows, cols, cmp_mode, quality, std::nullopt, frame_rate);
196 }
211 const Image &
212 request(std::optional<SizeOption> size, ImageCompressMode cmp_mode,
213 int quality,
214 std::optional<double> frame_rate = std::nullopt) const {
215 return request(size.value_or(SizeOption{}).rows(),
216 size.value_or(SizeOption{}).cols(), cmp_mode, quality,
217 std::nullopt, frame_rate);
218 }
225 std::optional<ImageFrame> tryGet() const;
232 ImageFrame get() const { return tryGet().value_or(ImageFrame{}); }
233
234 // operator ImageFrame() const { return get(); }
235
244 bool exists() const;
245
251 [[deprecated]] std::chrono::system_clock::time_point time() const;
252
254 const Image &free() const;
255
257 const Image &clear() const;
258
263 template <typename T, typename std::enable_if_t<std::is_same_v<T, Image>,
264 std::nullptr_t> = nullptr>
265 bool operator==(const T &other) const {
266 return static_cast<Field>(*this) == static_cast<Field>(other);
267 }
268 template <typename T, typename std::enable_if_t<std::is_same_v<T, Image>,
269 std::nullptr_t> = nullptr>
270 bool operator!=(const T &other) const {
271 return static_cast<Field>(*this) != static_cast<Field>(other);
272 }
273};
274
(ver1.3から追加) 画像データ
Definition image_frame.h:101
(ver1.3から追加) 画像の送受信データを表すクラス
Definition image.h:20
Image operator[](int index) const
Definition image.h:77
const Image & operator=(const ImageFrame &img) const
画像をセットする
Definition image.h:125
Image()=default
bool operator==(const T &other) const
Imageの参照先を比較
Definition image.h:265
Image child(int index) const
Definition image.h:53
Image operator[](const wchar_t *field) const
Definition image.h:72
Image child(std::wstring_view field) const
「(thisの名前).(追加の名前)」を新しい名前とするField (wstring)
Definition image.h:47
const Image & request(std::optional< SizeOption > size, ImageCompressMode cmp_mode, int quality, std::optional< double > frame_rate=std::nullopt) const
画像を圧縮されたフォーマットでリクエストする
Definition image.h:212
const Image & onChange(F callback) const
値が変化したときに呼び出されるコールバックを設定
Definition image.h:100
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:149
Image operator[](const char *field) const
Definition image.h:68
Image operator[](std::string_view field) const
Definition image.h:58
bool operator!=(const T &other) const
Definition image.h:270
ImageFrame get() const
画像を返す (データがない場合0x0の画像が返る)
Definition image.h:232
void appendListener(T &&callback) const
Definition image.h:112
Image operator[](std::wstring_view field) const
Definition image.h:63
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:192
Image child(std::string_view field) const
「(thisの名前).(追加の名前)」を新しい名前とするField
Definition image.h:40
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:167
Image parent() const
nameの最後のピリオドの前までを新しい名前とするField
Definition image.h:82
Image(const Field &base, const SharedString &field)
Definition image.h:29
u8stringとstringとwstringをshared_ptrで持ち共有する
Definition encoding.h:69
Definition image_frame.h:59
ImageCompressMode
Definition image_frame.h:23
ClientDataの参照とメンバ名とデータ名を持つクラス
Definition field.h:70
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:60
#define WEBCFACE_NS_END
Definition webcface-config.h:104
#define WEBCFACE_NS_BEGIN
Definition webcface-config.h:103
#define WEBCFACE_CALL_FP
Definition webcface-config.h:98