CVB++ 15.0
jpeg_converter.hpp
1#pragma once
2
3#include "../_cexports/c_webstreaming.h"
4#include "converter.hpp"
5
6namespace Cvb
7{
8
9 CVB_BEGIN_INLINE_NS
10
11 namespace WebStreaming
12 {
13
20 class JPEGConverter : public Converter
21 {
22 private:
23 struct PrivateTag
24 {
25 };
26
27 public:
29
34 {
35 return Internal::DoResCallShareOut<JPEGConverter>(
36 [&](void *&handle) { return CVB_CALL_CAPI(CVWSCreateConverter(CExports::CVWSCT_Jpeg, handle)); });
37 }
38
39 template <class T>
40 static JPEGConverterPtr FromHandle(HandleGuard<Converter> &&guard)
41 {
42 static_assert(std::is_same<JPEGConverter, T>::value, "CVB: T must be JPEGConverter");
43 if (!guard.Handle())
44 throw std::runtime_error("converter handle invalid");
45 return std::make_shared<T>(std::move(guard), PrivateTag{});
46 }
47
48 JPEGConverter(HandleGuard<Converter> &&guard, PrivateTag) noexcept
49 : Converter(std::move(guard))
50 {
51 }
52
54
58 int Scale() const
59 {
60 CExports::cvbint64_t value = 0;
61 CVB_CALL_CAPI_CHECKED(CVWSGetPropertyAsInteger(Handle(), CExports::CVWSCP_JPEGScale, value));
62 return static_cast<int>(value);
63 }
64
66
72 void SetScale(int scale)
73 {
74 CVB_CALL_CAPI_CHECKED(
75 CVWSSetPropertyAsInteger(Handle(), CExports::CVWSCP_JPEGScale, static_cast<CExports::cvbint64_t>(scale)));
76 }
77
79
83 int Quality() const
84 {
85 CExports::cvbint64_t value = 0;
86 CVB_CALL_CAPI_CHECKED(CVWSGetPropertyAsInteger(Handle(), CExports::CVWSCP_JPEGQualityLevel, value));
87 return static_cast<int>(value);
88 }
89
91
97 void SetQuality(int quality)
98 {
99 CVB_CALL_CAPI_CHECKED(CVWSSetPropertyAsInteger(Handle(), CExports::CVWSCP_JPEGQualityLevel,
100 static_cast<CExports::cvbint64_t>(quality)));
101 }
102 };
103
104 } // namespace WebStreaming
105
106 CVB_END_INLINE_NS
107
108} // namespace Cvb
void * Handle() const noexcept
Returns C-API style handle to Converter Object.
Definition converter.hpp:44
void SetQuality(int quality)
Set the quality of the JPEG conversion.
Definition jpeg_converter.hpp:97
void SetScale(int scale)
Set the scale of the JPEG conversion.
Definition jpeg_converter.hpp:72
int Scale() const
Get the scale of the JPEG conversion.
Definition jpeg_converter.hpp:58
static JPEGConverterPtr Create()
Creates a new JPEG converter.
Definition jpeg_converter.hpp:33
int Quality() const
Get the quality of the JPEG conversion.
Definition jpeg_converter.hpp:83
T make_shared(T... args)
T move(T... args)
Namespace for streaming images via web sockets.
Definition converter.hpp:20
std::shared_ptr< JPEGConverter > JPEGConverterPtr
Convenience shared pointer for JPEGConverter.
Definition webstreaming.hpp:31
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17