duvc-ctl 2.1.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";
89 return "DigitalMultiplier";
91 return "DigitalMultiplierLimit";
93 return "WhiteBalanceComponent";
95 return "PowerLineFrequency";
96 default:
97 return "Unknown";
98 }
99}
100
101const char *to_string(CamMode m) {
102 return (m == CamMode::Auto) ? "AUTO" : "MANUAL";
103}
104
105const wchar_t *to_wstring(CamProp p) {
106 switch (p) {
107 case CamProp::Pan:
108 return L"Pan";
109 case CamProp::Tilt:
110 return L"Tilt";
111 case CamProp::Roll:
112 return L"Roll";
113 case CamProp::Zoom:
114 return L"Zoom";
116 return L"Exposure";
117 case CamProp::Iris:
118 return L"Iris";
119 case CamProp::Focus:
120 return L"Focus";
122 return L"ScanMode";
123 case CamProp::Privacy:
124 return L"Privacy";
126 return L"PanRelative";
128 return L"TiltRelative";
130 return L"RollRelative";
132 return L"ZoomRelative";
134 return L"ExposureRelative";
136 return L"IrisRelative";
138 return L"FocusRelative";
139 case CamProp::PanTilt:
140 return L"PanTilt";
142 return L"PanTiltRelative";
144 return L"FocusSimple";
146 return L"DigitalZoom";
148 return L"DigitalZoomRelative";
150 return L"BacklightCompensation";
151 case CamProp::Lamp:
152 return L"Lamp";
153 default:
154 return L"Unknown";
155 }
156}
157
158const wchar_t *to_wstring(VidProp p) {
159 switch (p) {
161 return L"Brightness";
163 return L"Contrast";
164 case VidProp::Hue:
165 return L"Hue";
167 return L"Saturation";
169 return L"Sharpness";
170 case VidProp::Gamma:
171 return L"Gamma";
173 return L"ColorEnable";
175 return L"WhiteBalance";
177 return L"BacklightCompensation";
178 case VidProp::Gain:
179 return L"Gain";
181 return L"DigitalMultiplier";
183 return L"DigitalMultiplierLimit";
185 return L"WhiteBalanceComponent";
187 return L"PowerLineFrequency";
188 default:
189 return L"Unknown";
190 }
191}
192
193const wchar_t *to_wstring(CamMode m) {
194 return (m == CamMode::Auto) ? L"AUTO" : L"MANUAL";
195}
196
197std::string to_utf8(const std::wstring &wstr) {
198 if (wstr.empty()) {
199 return std::string();
200 }
201 int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(),
202 NULL, 0, NULL, NULL);
203 if (size_needed == 0) {
204 throw std::runtime_error("WideCharToMultiByte failed.");
205 }
206 std::string str_to(size_needed, 0);
207 WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), &str_to[0],
209 return str_to;
210}
211
212std::wstring to_wstring(const std::string &str) {
213#ifdef _WIN32
214 if (str.empty())
215 return std::wstring();
216
217 int size = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, nullptr, 0);
218 if (size <= 0)
219 return std::wstring();
220
221 std::wstring result(size - 1, L'\0');
222 MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, &result[0], size);
223 return result;
224#else
225 std::wstring result;
226 result.reserve(str.size());
227 for (char c : str) {
228 result.push_back(static_cast<wchar_t>(static_cast<unsigned char>(c)));
229 }
230 return result;
231#endif
232}
233
234} // 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
@ PowerLineFrequency
Power line frequency (anti-flicker setting)
@ DigitalMultiplier
Digital multiplier level.
@ Saturation
Color saturation level.
@ Gain
Sensor gain level.
@ WhiteBalanceComponent
White balance component adjustment.
@ WhiteBalance
White balance adjustment.
@ DigitalMultiplierLimit
Maximum digital multiplier level.
@ 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:70
@ Auto
Automatic control by camera.
const wchar_t * to_wstring(CamProp)
Convert camera property enum to wide string.
Definition core.cpp:715
const char * to_string(CamProp)
Convert camera property enum to string.
Definition core.cpp:686
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.