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