duvc-ctl 2.0.0
USB Video Class Camera Control Library
Loading...
Searching...
No Matches
string_conversion.cpp
Go to the documentation of this file.
1
7#include <stdexcept>
8#include <string>
9#include <windows.h>
10
11namespace duvc {
12
13const char *to_string(CamProp p) {
14 switch (p) {
15 case CamProp::Pan:
16 return "Pan";
17 case CamProp::Tilt:
18 return "Tilt";
19 case CamProp::Roll:
20 return "Roll";
21 case CamProp::Zoom:
22 return "Zoom";
24 return "Exposure";
25 case CamProp::Iris:
26 return "Iris";
27 case CamProp::Focus:
28 return "Focus";
30 return "ScanMode";
32 return "Privacy";
34 return "PanRelative";
36 return "TiltRelative";
38 return "RollRelative";
40 return "ZoomRelative";
42 return "ExposureRelative";
44 return "IrisRelative";
46 return "FocusRelative";
48 return "PanTilt";
50 return "PanTiltRelative";
52 return "FocusSimple";
54 return "DigitalZoom";
56 return "DigitalZoomRelative";
58 return "BacklightCompensation";
59 case CamProp::Lamp:
60 return "Lamp";
61 default:
62 return "Unknown";
63 }
64}
65
66const char *to_string(VidProp p) {
67 switch (p) {
69 return "Brightness";
71 return "Contrast";
72 case VidProp::Hue:
73 return "Hue";
75 return "Saturation";
77 return "Sharpness";
78 case VidProp::Gamma:
79 return "Gamma";
81 return "ColorEnable";
83 return "WhiteBalance";
85 return "BacklightCompensation";
86 case VidProp::Gain:
87 return "Gain";
88 default:
89 return "Unknown";
90 }
91}
92
93const char *to_string(CamMode m) {
94 return (m == CamMode::Auto) ? "AUTO" : "MANUAL";
95}
96
97const wchar_t *to_wstring(CamProp p) {
98 switch (p) {
99 case CamProp::Pan:
100 return L"Pan";
101 case CamProp::Tilt:
102 return L"Tilt";
103 case CamProp::Roll:
104 return L"Roll";
105 case CamProp::Zoom:
106 return L"Zoom";
108 return L"Exposure";
109 case CamProp::Iris:
110 return L"Iris";
111 case CamProp::Focus:
112 return L"Focus";
114 return L"ScanMode";
115 case CamProp::Privacy:
116 return L"Privacy";
118 return L"PanRelative";
120 return L"TiltRelative";
122 return L"RollRelative";
124 return L"ZoomRelative";
126 return L"ExposureRelative";
128 return L"IrisRelative";
130 return L"FocusRelative";
131 case CamProp::PanTilt:
132 return L"PanTilt";
134 return L"PanTiltRelative";
136 return L"FocusSimple";
138 return L"DigitalZoom";
140 return L"DigitalZoomRelative";
142 return L"BacklightCompensation";
143 case CamProp::Lamp:
144 return L"Lamp";
145 default:
146 return L"Unknown";
147 }
148}
149
150const wchar_t *to_wstring(VidProp p) {
151 switch (p) {
153 return L"Brightness";
155 return L"Contrast";
156 case VidProp::Hue:
157 return L"Hue";
159 return L"Saturation";
161 return L"Sharpness";
162 case VidProp::Gamma:
163 return L"Gamma";
165 return L"ColorEnable";
167 return L"WhiteBalance";
169 return L"BacklightCompensation";
170 case VidProp::Gain:
171 return L"Gain";
172 default:
173 return L"Unknown";
174 }
175}
176
177const wchar_t *to_wstring(CamMode m) {
178 return (m == CamMode::Auto) ? L"AUTO" : L"MANUAL";
179}
180
181std::string to_utf8(const std::wstring &wstr) {
182 if (wstr.empty()) {
183 return std::string();
184 }
185 int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(),
186 NULL, 0, NULL, NULL);
187 if (size_needed == 0) {
188 throw std::runtime_error("WideCharToMultiByte failed.");
189 }
190 std::string str_to(size_needed, 0);
191 WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &str_to[0],
193 return str_to;
194}
195
196std::wstring to_wstring(const std::string &str) {
197#ifdef _WIN32
198 if (str.empty())
199 return std::wstring();
200
201 int size = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, nullptr, 0);
202 if (size <= 0)
203 return std::wstring();
204
205 std::wstring result(size - 1, L'\0');
206 MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, &result[0], size);
207 return result;
208#else
209 std::wstring result;
210 result.reserve(str.size());
211 for (char c : str) {
212 result.push_back(static_cast<wchar_t>(static_cast<unsigned char>(c)));
213 }
214 return result;
215#endif
216}
217
218} // namespace duvc
Result type that can contain either a value or an error.
Definition result.h:75
Definition core.h:13
VidProp
Video processing properties (IAMVideoProcAmp interface)
Definition types.h:50
@ Saturation
Color saturation level.
@ Gain
Sensor gain level.
@ WhiteBalance
White balance adjustment.
@ Brightness
Image brightness level.
@ ColorEnable
Color vs. monochrome mode.
@ Sharpness
Image sharpness level.
@ Contrast
Image contrast level.
@ Gamma
Gamma correction value.
@ BacklightCompensation
Backlight compensation level.
@ Hue
Color hue adjustment.
CamMode
Property control mode.
Definition types.h:66
@ Auto
Automatic control by camera.
const wchar_t * to_wstring(CamProp)
Convert camera property enum to wide string.
Definition core.cpp:707
const char * to_string(CamProp)
Convert camera property enum to string.
Definition core.cpp:678
std::string to_utf8(const std::wstring &wstr)
Converts a wide string (UTF-16 on Windows) to a UTF-8 string.
CamProp
Camera control properties (IAMCameraControl interface)
Definition types.h:18
@ ExposureRelative
Relative exposure adjustment.
@ Roll
Camera roll rotation.
@ FocusSimple
Simple focus control.
@ PanRelative
Relative pan movement.
@ RollRelative
Relative roll movement.
@ Zoom
Optical zoom level.
@ Lamp
Camera lamp/flash control.
@ PanTiltRelative
Relative pan/tilt movement.
@ Tilt
Vertical camera rotation.
@ TiltRelative
Relative tilt movement.
@ ScanMode
Scan mode (progressive/interlaced)
@ ZoomRelative
Relative zoom movement.
@ Privacy
Privacy mode on/off.
@ IrisRelative
Relative iris adjustment.
@ Iris
Aperture/iris setting.
@ Exposure
Exposure time.
@ Focus
Focus position.
@ FocusRelative
Relative focus adjustment.
@ PanTilt
Combined pan/tilt control.
@ DigitalZoomRelative
Relative digital zoom.
@ Pan
Horizontal camera rotation.
@ BacklightCompensation
Backlight compensation.
@ DigitalZoom
Digital zoom level.
String conversion utilities for enums and types.