1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ConfigManagerUtil.h"
#include <log/log.h>
#include <system/graphics-base-v1.0.h>
#include <linux/videodev2.h>
#include <sstream>
#include <string>
namespace android::hardware::automotive::evs::V1_1::implementation {
using namespace std;
bool ConfigManagerUtil::convertToEvsCameraParam(const string& id, CameraParam& camParam) {
string trimmed = ConfigManagerUtil::trimString(id);
bool success = true;
if (!trimmed.compare("BRIGHTNESS")) {
camParam = CameraParam::BRIGHTNESS;
} else if (!trimmed.compare("CONTRAST")) {
camParam = CameraParam::CONTRAST;
} else if (!trimmed.compare("AUTOGAIN")) {
camParam = CameraParam::AUTOGAIN;
} else if (!trimmed.compare("GAIN")) {
camParam = CameraParam::GAIN;
} else if (!trimmed.compare("AUTO_WHITE_BALANCE")) {
camParam = CameraParam::AUTO_WHITE_BALANCE;
} else if (!trimmed.compare("WHITE_BALANCE_TEMPERATURE")) {
camParam = CameraParam::WHITE_BALANCE_TEMPERATURE;
} else if (!trimmed.compare("SHARPNESS")) {
camParam = CameraParam::SHARPNESS;
} else if (!trimmed.compare("AUTO_EXPOSURE")) {
camParam = CameraParam::AUTO_EXPOSURE;
} else if (!trimmed.compare("ABSOLUTE_EXPOSURE")) {
camParam = CameraParam::ABSOLUTE_EXPOSURE;
} else if (!trimmed.compare("ABSOLUTE_FOCUS")) {
camParam = CameraParam::ABSOLUTE_FOCUS;
} else if (!trimmed.compare("AUTO_FOCUS")) {
camParam = CameraParam::AUTO_FOCUS;
} else if (!trimmed.compare("ABSOLUTE_ZOOM")) {
camParam = CameraParam::ABSOLUTE_ZOOM;
} else {
success = false;
}
return success;
}
bool ConfigManagerUtil::convertToPixelFormat(const string& format, int32_t& pixFormat) {
string trimmed = ConfigManagerUtil::trimString(format);
bool success = true;
if (!trimmed.compare("RGBA_8888")) {
pixFormat = HAL_PIXEL_FORMAT_RGBA_8888;
} else if (!trimmed.compare("YCRCB_420_SP")) {
pixFormat = HAL_PIXEL_FORMAT_YCRCB_420_SP;
} else if (!trimmed.compare("YCBCR_422_I")) {
pixFormat = HAL_PIXEL_FORMAT_YCBCR_422_I;
} else {
success = false;
}
return success;
}
bool ConfigManagerUtil::convertToMetadataTag(const char* name, camera_metadata_tag& aTag) {
if (!strcmp(name, "LENS_DISTORTION")) {
aTag = ANDROID_LENS_DISTORTION;
} else if (!strcmp(name, "LENS_INTRINSIC_CALIBRATION")) {
aTag = ANDROID_LENS_INTRINSIC_CALIBRATION;
} else if (!strcmp(name, "LENS_POSE_ROTATION")) {
aTag = ANDROID_LENS_POSE_ROTATION;
} else if (!strcmp(name, "LENS_POSE_TRANSLATION")) {
aTag = ANDROID_LENS_POSE_TRANSLATION;
} else if (!strcmp(name, "REQUEST_AVAILABLE_CAPABILITIES")) {
aTag = ANDROID_REQUEST_AVAILABLE_CAPABILITIES;
} else if (!strcmp(name, "LOGICAL_MULTI_CAMERA_PHYSICAL_IDS")) {
aTag = ANDROID_LOGICAL_MULTI_CAMERA_PHYSICAL_IDS;
} else {
return false;
}
return true;
}
bool ConfigManagerUtil::convertToCameraCapability(
const char* name, camera_metadata_enum_android_request_available_capabilities_t& cap) {
if (!strcmp(name, "DEPTH_OUTPUT")) {
cap = ANDROID_REQUEST_AVAILABLE_CAPABILITIES_DEPTH_OUTPUT;
} else if (!strcmp(name, "LOGICAL_MULTI_CAMERA")) {
cap = ANDROID_REQUEST_AVAILABLE_CAPABILITIES_LOGICAL_MULTI_CAMERA;
} else if (!strcmp(name, "MONOCHROME")) {
cap = ANDROID_REQUEST_AVAILABLE_CAPABILITIES_MONOCHROME;
} else if (!strcmp(name, "SECURE_IMAGE_DATA")) {
cap = ANDROID_REQUEST_AVAILABLE_CAPABILITIES_SECURE_IMAGE_DATA;
} else {
return false;
}
return true;
}
float* ConfigManagerUtil::convertFloatArray(const char* sz, const char* vals, size_t& count,
const char delimiter) {
string size_string(sz);
string value_string(vals);
count = stoi(size_string);
float* result = new float[count];
stringstream values(value_string);
int32_t idx = 0;
string token;
while (getline(values, token, delimiter)) {
result[idx++] = stof(token);
}
return result;
}
string ConfigManagerUtil::trimString(const string& src, const string& ws) {
const auto s = src.find_first_not_of(ws);
if (s == string::npos) {
return "";
}
const auto e = src.find_last_not_of(ws);
const auto r = e - s + 1;
return src.substr(s, r);
}
} // namespace android::hardware::automotive::evs::V1_1::implementation
|