WebCFace 3.2.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::lastNameW;
34 using Field::member;
35 using Field::name;
36 using Field::nameW;
44 return this->Field::child(static_cast<SharedString &>(field));
45 }
50 [[deprecated]]
51 Image child(int index) const {
52 return this->Field::child(std::to_string(index));
53 }
61 Image operator[](StringInitializer field) const { return child(std::move(field)); }
67 [[deprecated]]
68 Image operator[](int index) const {
69 return child(std::to_string(index));
70 }
75 Image parent() const { return this->Field::parent(); }
76
83 const Image &
84 onChange(std::function<void WEBCFACE_CALL_FP(Image)> callback) const;
91 template <typename F, typename std::enable_if_t<std::is_invocable_v<F>,
92 std::nullptr_t> = nullptr>
93 const Image &onChange(F callback) const {
94 return onChange(
95 [callback = std::move(callback)](const auto &) { callback(); });
96 }
97
102 const Image &set(const ImageFrame &img) const;
107 const Image &operator=(const ImageFrame &img) const {
108 this->set(img);
109 return *this;
110 }
111
112 protected:
113 const Image &tryRequest() const;
114
115 public:
127 const Image &
128 request(std::optional<SizeOption> size = std::nullopt,
129 std::optional<ImageColorMode> color_mode = std::nullopt,
130 std::optional<double> frame_rate = std::nullopt) const {
131 return request(size.value_or(SizeOption{}).rows(),
132 size.value_or(SizeOption{}).cols(),
133 ImageCompressMode::raw, 0, color_mode, frame_rate);
134 }
149 const Image &
150 request(std::optional<SizeOption> size, ImageCompressMode cmp_mode,
151 int quality,
152 std::optional<double> frame_rate = std::nullopt) const {
153 return request(size.value_or(SizeOption{}).rows(),
154 size.value_or(SizeOption{}).cols(), cmp_mode, quality,
155 std::nullopt, frame_rate);
156 }
163 std::optional<ImageFrame> tryGet() const;
170 ImageFrame get() const { return tryGet().value_or(ImageFrame{}); }
171
172 // operator ImageFrame() const { return get(); }
173
182 bool exists() const;
183
185 const Image &free() const;
186
188 const Image &clear() const;
189
194 template <typename T, typename std::enable_if_t<std::is_same_v<T, Image>,
195 std::nullptr_t> = nullptr>
196 bool operator==(const T &other) const {
197 return static_cast<Field>(*this) == static_cast<Field>(other);
198 }
199 template <typename T, typename std::enable_if_t<std::is_same_v<T, Image>,
200 std::nullptr_t> = nullptr>
201 bool operator!=(const T &other) const {
202 return static_cast<Field>(*this) != static_cast<Field>(other);
203 }
204};
205
(ver1.3から追加) 画像データ
Definition image_frame.h:101
(ver1.3から追加) 画像の送受信データを表すクラス
Definition image.h:20
Image operator[](int index) const
Definition image.h:68
const Image & operator=(const ImageFrame &img) const
画像をセットする
Definition image.h:107
Image()=default
Image child(StringInitializer field) const
「(thisの名前).(追加の名前)」を新しい名前とするField
Definition image.h:43
bool operator==(const T &other) const
Imageの参照先を比較
Definition image.h:196
Image child(int index) const
Definition image.h:51
const Image & request(std::optional< SizeOption > size, ImageCompressMode cmp_mode, int quality, std::optional< double > frame_rate=std::nullopt) const
画像を圧縮されたフォーマットでリクエストする
Definition image.h:150
const Image & onChange(F callback) const
値が変化したときに呼び出されるコールバックを設定
Definition image.h:93
bool operator!=(const T &other) const
Definition image.h:201
ImageFrame get() const
画像を返す (データがない場合0x0の画像が返る)
Definition image.h:170
Image operator[](StringInitializer field) const
Definition image.h:61
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:128
Image parent() const
nameの最後のピリオドの前までを新しい名前とするField
Definition image.h:75
Image(const Field &base, const SharedString &field)
Definition image.h:29
u8stringとstringとwstringをshared_ptrで持ち共有する
Definition encoding.h:170
Definition image_frame.h:59
SharedString のpublicなコンストラクタインタフェース (入力専用)
Definition encoding.h:235
ImageCompressMode
Definition image_frame.h:23
ClientDataの参照とメンバ名とデータ名を持つクラス
Definition field.h:68
Field parent() const
nameの最後のピリオドの前までを新しい名前とするField
Definition field.cc:39
Field child(const SharedString &field) const
Definition field.cc:48
#define WEBCFACE_DLL
Definition webcface-config.h:69
#define WEBCFACE_NS_END
Definition webcface-config.h:113
#define WEBCFACE_NS_BEGIN
Definition webcface-config.h:112
#define WEBCFACE_CALL_FP
Definition webcface-config.h:107