blob: b3a1d18ae0555ab62cf82c70408bdf36ec4b8516 [file] [log] [blame]
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -08001/*
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#define LOG_NDEBUG 0
18#define LOG_TAG "ZoomRatioMapperTest"
19
20#include <gtest/gtest.h>
21#include <utils/Errors.h>
22
23#include "../device3/ZoomRatioMapper.h"
24
25using namespace std;
26using namespace android;
27using namespace android::camera3;
28
29constexpr int kMaxAllowedPixelError = 1;
30constexpr float kMaxAllowedRatioError = 0.1;
31
32constexpr int32_t testActiveArraySize[] = {100, 100, 1024, 768};
33constexpr int32_t testPreCorrActiveArraySize[] = {90, 90, 1044, 788};
34
35constexpr int32_t testDefaultCropSize[][4] = {
36 {0, 0, 1024, 768}, // active array default crop
37 {0, 0, 1044, 788}, // preCorrection active array default crop
38};
39
40constexpr int32_t test2xCropRegion[][4] = {
41 {256, 192, 512, 384}, // active array 2x zoom crop
42 {261, 197, 522, 394}, // preCorrection active array default crop
43};
44
45constexpr int32_t testLetterBoxSize[][4] = {
46 {0, 96, 1024, 576}, // active array 2x zoom crop
47 {0, 106, 1024, 576}, // preCorrection active array default crop
48};
49
50status_t setupTestMapper(ZoomRatioMapper *m, float maxDigitalZoom,
51 const int32_t activeArray[4], const int32_t preCorrectArray[4],
52 bool hasZoomRatioRange, float zoomRatioRange[2],
53 bool usePreCorrectArray) {
54 CameraMetadata deviceInfo;
55
56 deviceInfo.update(ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE, activeArray, 4);
57 deviceInfo.update(ANDROID_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE, preCorrectArray, 4);
58 deviceInfo.update(ANDROID_SCALER_AVAILABLE_MAX_DIGITAL_ZOOM, &maxDigitalZoom, 1);
59 if (hasZoomRatioRange) {
60 deviceInfo.update(ANDROID_CONTROL_ZOOM_RATIO_RANGE, zoomRatioRange, 2);
61 }
62
63 bool supportNativeZoomRatio;
64 status_t res = ZoomRatioMapper::overrideZoomRatioTags(&deviceInfo, &supportNativeZoomRatio);
65 if (res != OK) {
66 return res;
67 }
68
Shuzhen Wang1c834da2019-12-18 11:17:03 -080069 *m = ZoomRatioMapper(&deviceInfo, hasZoomRatioRange, usePreCorrectArray);
70 return OK;
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -080071}
72
73TEST(ZoomRatioTest, Initialization) {
74 CameraMetadata deviceInfo;
75 status_t res;
76 camera_metadata_entry_t entry;
77
78 deviceInfo.update(ANDROID_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE,
79 testPreCorrActiveArraySize, 4);
80 deviceInfo.update(ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE, testActiveArraySize, 4);
81
82 // Test initialization from devices not supporting zoomRange
83 float maxDigitalZoom = 4.0f;
84 ZoomRatioMapper mapperNoZoomRange;
85 deviceInfo.update(ANDROID_SCALER_AVAILABLE_MAX_DIGITAL_ZOOM, &maxDigitalZoom, 1);
86 bool supportNativeZoomRatio;
87 res = ZoomRatioMapper::overrideZoomRatioTags(&deviceInfo, &supportNativeZoomRatio);
88 ASSERT_EQ(res, OK);
89 ASSERT_EQ(supportNativeZoomRatio, false);
Shuzhen Wang1c834da2019-12-18 11:17:03 -080090 mapperNoZoomRange = ZoomRatioMapper(&deviceInfo,
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -080091 supportNativeZoomRatio, true/*usePreCorrectArray*/);
Shuzhen Wang1c834da2019-12-18 11:17:03 -080092 ASSERT_TRUE(mapperNoZoomRange.isValid());
93 mapperNoZoomRange = ZoomRatioMapper(&deviceInfo,
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -080094 supportNativeZoomRatio, false/*usePreCorrectArray*/);
Shuzhen Wang1c834da2019-12-18 11:17:03 -080095 ASSERT_TRUE(mapperNoZoomRange.isValid());
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -080096
97 entry = deviceInfo.find(ANDROID_CONTROL_ZOOM_RATIO_RANGE);
98 ASSERT_EQ(entry.count, 2U);
99 ASSERT_EQ(entry.data.f[0], 1.0);
100 ASSERT_EQ(entry.data.f[1], maxDigitalZoom);
101
102 entry = deviceInfo.find(ANDROID_REQUEST_AVAILABLE_CHARACTERISTICS_KEYS);
103 ASSERT_GT(entry.count, 0U);
104 ASSERT_NE(std::find(entry.data.i32, entry.data.i32 + entry.count,
105 ANDROID_CONTROL_ZOOM_RATIO_RANGE), entry.data.i32 + entry.count);
106
107 entry = deviceInfo.find(ANDROID_REQUEST_AVAILABLE_REQUEST_KEYS);
108 ASSERT_GT(entry.count, 0U);
109 ASSERT_NE(std::find(entry.data.i32, entry.data.i32 + entry.count,
110 ANDROID_CONTROL_ZOOM_RATIO), entry.data.i32 + entry.count);
111
112 entry = deviceInfo.find(ANDROID_REQUEST_AVAILABLE_RESULT_KEYS);
113 ASSERT_GT(entry.count, 0U);
114 ASSERT_NE(std::find(entry.data.i32, entry.data.i32 + entry.count,
115 ANDROID_CONTROL_ZOOM_RATIO), entry.data.i32 + entry.count);
116
117 // Test initialization from devices supporting zoomRange
118 float ratioRange[2] = {0.2f, maxDigitalZoom};
119 deviceInfo.update(ANDROID_CONTROL_ZOOM_RATIO_RANGE, ratioRange, 2);
120 res = ZoomRatioMapper::overrideZoomRatioTags(&deviceInfo, &supportNativeZoomRatio);
121 ASSERT_EQ(res, OK);
122 ASSERT_EQ(supportNativeZoomRatio, true);
123 ZoomRatioMapper mapperWithZoomRange;
Shuzhen Wang1c834da2019-12-18 11:17:03 -0800124 mapperWithZoomRange = ZoomRatioMapper(&deviceInfo,
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800125 supportNativeZoomRatio, true/*usePreCorrectArray*/);
Shuzhen Wang1c834da2019-12-18 11:17:03 -0800126 ASSERT_TRUE(mapperWithZoomRange.isValid());
127 mapperWithZoomRange = ZoomRatioMapper(&deviceInfo,
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800128 supportNativeZoomRatio, false/*usePreCorrectArray*/);
Shuzhen Wang1c834da2019-12-18 11:17:03 -0800129 ASSERT_TRUE(mapperWithZoomRange.isValid());
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800130
131 entry = deviceInfo.find(ANDROID_CONTROL_ZOOM_RATIO_RANGE);
132 ASSERT_EQ(entry.count, 2U);
133 ASSERT_EQ(entry.data.f[0], ratioRange[0]);
134 ASSERT_EQ(entry.data.f[1], ratioRange[1]);
135
136 // Test default zoom ratio in template
137 CameraMetadata requestTemplate;
138 res = ZoomRatioMapper::initZoomRatioInTemplate(&requestTemplate);
139 ASSERT_EQ(res, OK);
140 entry = requestTemplate.find(ANDROID_CONTROL_ZOOM_RATIO);
141 ASSERT_EQ(entry.count, 1U);
142 ASSERT_EQ(entry.data.f[0], 1.0f);
143
144 float customRatio = 0.5f;
145 res = requestTemplate.update(ANDROID_CONTROL_ZOOM_RATIO, &customRatio, 1);
146 ASSERT_EQ(res, OK);
147 res = ZoomRatioMapper::initZoomRatioInTemplate(&requestTemplate);
148 ASSERT_EQ(res, OK);
149 entry = requestTemplate.find(ANDROID_CONTROL_ZOOM_RATIO);
150 ASSERT_EQ(entry.count, 1U);
151 ASSERT_EQ(entry.data.f[0], customRatio);
152}
153
154void subScaleCoordinatesTest(bool usePreCorrectArray) {
155 ZoomRatioMapper mapper;
156 float maxDigitalZoom = 4.0f;
157 float zoomRatioRange[2];
158 ASSERT_EQ(OK, setupTestMapper(&mapper, maxDigitalZoom,
159 testActiveArraySize, testPreCorrActiveArraySize,
160 false/*hasZoomRatioRange*/, zoomRatioRange,
161 usePreCorrectArray));
162
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800163 int32_t width = testActiveArraySize[2];
164 int32_t height = testActiveArraySize[3];
165 if (usePreCorrectArray) {
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800166 width = testPreCorrActiveArraySize[2];
167 height = testPreCorrActiveArraySize[3];
168 }
169
170 std::array<int32_t, 16> originalCoords = {
171 0, 0, // top-left
Shuzhen Wang9b0d9532020-04-14 17:14:20 -0700172 width - 1, 0, // top-right
173 0, height - 1, // bottom-left
174 width - 1, height - 1, // bottom-right
175 (width - 1) / 2, (height - 1) / 2, // center
176 (width - 1) / 4, (height - 1) / 4, // top-left after 2x
177 (width - 1) / 3, (height - 1) * 2 / 3, // bottom-left after 3x zoom
178 (width - 1) * 7 / 8, (height - 1) / 2, // middle-right after 1.33x zoom
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800179 };
180
181 // Verify 1.0x zoom doesn't change the coordinates
182 auto coords = originalCoords;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800183 mapper.scaleCoordinates(coords.data(), coords.size()/2, 1.0f, false /*clamp*/, width, height);
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800184 for (size_t i = 0; i < coords.size(); i++) {
185 EXPECT_EQ(coords[i], originalCoords[i]);
186 }
187
188 // Verify 2.0x zoom work as expected (no clamping)
189 std::array<float, 16> expected2xCoords = {
Shuzhen Wang9b0d9532020-04-14 17:14:20 -0700190 - (width - 1) / 2.0f, - (height - 1) / 2.0f,// top-left
191 (width - 1) * 3 / 2.0f, - (height - 1) / 2.0f, // top-right
192 - (width - 1) / 2.0f, (height - 1) * 3 / 2.0f, // bottom-left
193 (width - 1) * 3 / 2.0f, (height - 1) * 3 / 2.0f, // bottom-right
194 (width - 1) / 2.0f, (height - 1) / 2.0f, // center
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800195 0, 0, // top-left after 2x
Shuzhen Wang9b0d9532020-04-14 17:14:20 -0700196 (width - 1) / 6.0f, (height - 1) * 5.0f / 6.0f, // bottom-left after 3x zoom
197 (width - 1) * 5.0f / 4.0f, (height - 1) / 2.0f, // middle-right after 1.33x zoom
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800198 };
199 coords = originalCoords;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800200 mapper.scaleCoordinates(coords.data(), coords.size()/2, 2.0f, false /*clamp*/, width, height);
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800201 for (size_t i = 0; i < coords.size(); i++) {
202 EXPECT_LE(std::abs(coords[i] - expected2xCoords[i]), kMaxAllowedPixelError);
203 }
204
205 // Verify 2.0x zoom work as expected (with inclusive clamping)
206 std::array<float, 16> expected2xCoordsClampedInc = {
207 0, 0, // top-left
Shuzhen Wang9b0d9532020-04-14 17:14:20 -0700208 width - 1.0f, 0, // top-right
209 0, height - 1.0f, // bottom-left
210 width - 1.0f, height - 1.0f, // bottom-right
211 (width - 1) / 2.0f, (height - 1) / 2.0f, // center
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800212 0, 0, // top-left after 2x
Shuzhen Wang9b0d9532020-04-14 17:14:20 -0700213 (width - 1) / 6.0f, (height - 1) * 5.0f / 6.0f , // bottom-left after 3x zoom
214 width - 1.0f, (height - 1) / 2.0f, // middle-right after 1.33x zoom
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800215 };
216 coords = originalCoords;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800217 mapper.scaleCoordinates(coords.data(), coords.size()/2, 2.0f, true /*clamp*/, width, height);
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800218 for (size_t i = 0; i < coords.size(); i++) {
219 EXPECT_LE(std::abs(coords[i] - expected2xCoordsClampedInc[i]), kMaxAllowedPixelError);
220 }
221
222 // Verify 2.0x zoom work as expected (with exclusive clamping)
223 std::array<float, 16> expected2xCoordsClampedExc = {
224 0, 0, // top-left
Shuzhen Wang9b0d9532020-04-14 17:14:20 -0700225 width - 1.0f, 0, // top-right
226 0, height - 1.0f, // bottom-left
227 width - 1.0f, height - 1.0f, // bottom-right
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800228 width / 2.0f, height / 2.0f, // center
229 0, 0, // top-left after 2x
Shuzhen Wang9b0d9532020-04-14 17:14:20 -0700230 (width - 1) / 6.0f, (height - 1) * 5.0f / 6.0f , // bottom-left after 3x zoom
231 width - 1.0f, height / 2.0f, // middle-right after 1.33x zoom
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800232 };
233 coords = originalCoords;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800234 mapper.scaleCoordinates(coords.data(), coords.size()/2, 2.0f, true /*clamp*/, width, height);
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800235 for (size_t i = 0; i < coords.size(); i++) {
236 EXPECT_LE(std::abs(coords[i] - expected2xCoordsClampedExc[i]), kMaxAllowedPixelError);
237 }
238
239 // Verify 0.33x zoom work as expected
240 std::array<float, 16> expectedZoomOutCoords = {
Shuzhen Wang9b0d9532020-04-14 17:14:20 -0700241 (width - 1) / 3.0f, (height - 1) / 3.0f, // top-left
242 (width - 1) * 2 / 3.0f, (height - 1) / 3.0f, // top-right
243 (width - 1) / 3.0f, (height - 1) * 2 / 3.0f, // bottom-left
244 (width - 1) * 2 / 3.0f, (height - 1) * 2 / 3.0f, // bottom-right
245 (width - 1) / 2.0f, (height - 1) / 2.0f, // center
246 (width - 1) * 5 / 12.0f, (height - 1) * 5 / 12.0f, // top-left after 2x
247 (width - 1) * 4 / 9.0f, (height - 1) * 5 / 9.0f, // bottom-left after 3x zoom-in
248 (width - 1) * 5 / 8.0f, (height - 1) / 2.0f, // middle-right after 1.33x zoom-in
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800249 };
250 coords = originalCoords;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800251 mapper.scaleCoordinates(coords.data(), coords.size()/2, 1.0f/3, false /*clamp*/, width, height);
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800252 for (size_t i = 0; i < coords.size(); i++) {
253 EXPECT_LE(std::abs(coords[i] - expectedZoomOutCoords[i]), kMaxAllowedPixelError);
254 }
255}
256
257TEST(ZoomRatioTest, scaleCoordinatesTest) {
258 subScaleCoordinatesTest(false/*usePreCorrectArray*/);
259 subScaleCoordinatesTest(true/*usePreCorrectArray*/);
260}
261
262void subCropOverMaxDigitalZoomTest(bool usePreCorrectArray) {
263 status_t res;
264 ZoomRatioMapper mapper;
265 float noZoomRatioRange[2];
266 res = setupTestMapper(&mapper, 4.0/*maxDigitalZoom*/,
267 testActiveArraySize, testPreCorrActiveArraySize,
268 false/*hasZoomRatioRange*/, noZoomRatioRange,
269 usePreCorrectArray);
270 ASSERT_EQ(res, OK);
271
272 CameraMetadata metadata;
273 camera_metadata_entry_t entry;
274
275 size_t index = usePreCorrectArray ? 1 : 0;
276 metadata.update(ANDROID_SCALER_CROP_REGION, testDefaultCropSize[index], 4);
277 res = mapper.updateCaptureRequest(&metadata);
278 ASSERT_EQ(res, OK);
279 entry = metadata.find(ANDROID_SCALER_CROP_REGION);
280 ASSERT_EQ(entry.count, 4U);
281 for (int i = 0; i < 4; i ++) {
282 EXPECT_EQ(entry.data.i32[i], testDefaultCropSize[index][i]);
283 }
284
285 metadata.update(ANDROID_SCALER_CROP_REGION, test2xCropRegion[index], 4);
286 res = mapper.updateCaptureResult(&metadata, true/*requestedZoomRatioIs1*/);
287 ASSERT_EQ(res, OK);
288 entry = metadata.find(ANDROID_SCALER_CROP_REGION);
289 ASSERT_EQ(entry.count, 4U);
290 for (int i = 0; i < 4; i ++) {
291 EXPECT_EQ(entry.data.i32[i], test2xCropRegion[index][i]);
292 }
293 entry = metadata.find(ANDROID_CONTROL_ZOOM_RATIO);
294 ASSERT_TRUE(entry.count == 0 || (entry.count == 1 && entry.data.f[0] == 1.0f));
295}
296
297TEST(ZoomRatioTest, CropOverMaxDigitalZoomTest) {
298 subCropOverMaxDigitalZoomTest(false/*usePreCorrectArray*/);
299 subCropOverMaxDigitalZoomTest(true/*usePreCorrectArray*/);
300}
301
302void subCropOverZoomRangeTest(bool usePreCorrectArray) {
303 status_t res;
304 ZoomRatioMapper mapper;
305 float zoomRatioRange[2] = {0.5f, 4.0f};
306 res = setupTestMapper(&mapper, 4.0/*maxDigitalZoom*/,
307 testActiveArraySize, testPreCorrActiveArraySize,
308 true/*hasZoomRatioRange*/, zoomRatioRange,
309 usePreCorrectArray);
310 ASSERT_EQ(res, OK);
311
312 CameraMetadata metadata;
313 camera_metadata_entry_t entry;
314
315 size_t index = usePreCorrectArray ? 1 : 0;
316
317 // 2x zoom crop region, zoomRatio is 1.0f
318 metadata.update(ANDROID_SCALER_CROP_REGION, test2xCropRegion[index], 4);
319 res = mapper.updateCaptureRequest(&metadata);
320 ASSERT_EQ(res, OK);
321 entry = metadata.find(ANDROID_SCALER_CROP_REGION);
322 ASSERT_EQ(entry.count, 4U);
323 for (int i = 0; i < 4; i++) {
Shuzhen Wang9b0d9532020-04-14 17:14:20 -0700324 EXPECT_LE(std::abs(entry.data.i32[i] - testDefaultCropSize[index][i]),
325 kMaxAllowedPixelError);
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800326 }
327 entry = metadata.find(ANDROID_CONTROL_ZOOM_RATIO);
328 EXPECT_NEAR(entry.data.f[0], 2.0f, kMaxAllowedRatioError);
329
330 res = mapper.updateCaptureResult(&metadata, true/*requestedZoomRatioIs1*/);
331 ASSERT_EQ(res, OK);
332 entry = metadata.find(ANDROID_CONTROL_ZOOM_RATIO);
333 EXPECT_NEAR(entry.data.f[0], 1.0f, kMaxAllowedRatioError);
334 entry = metadata.find(ANDROID_SCALER_CROP_REGION);
335 ASSERT_EQ(entry.count, 4U);
336 for (int i = 0; i < 4; i++) {
Shuzhen Wang9b0d9532020-04-14 17:14:20 -0700337 EXPECT_LE(std::abs(entry.data.i32[i] - test2xCropRegion[index][i]), kMaxAllowedPixelError);
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -0800338 }
339
340 // Letter boxing crop region, zoomRatio is 1.0
341 float zoomRatio = 1.0f;
342 metadata.update(ANDROID_CONTROL_ZOOM_RATIO, &zoomRatio, 1);
343 metadata.update(ANDROID_SCALER_CROP_REGION, testLetterBoxSize[index], 4);
344 res = mapper.updateCaptureRequest(&metadata);
345 ASSERT_EQ(res, OK);
346 entry = metadata.find(ANDROID_SCALER_CROP_REGION);
347 ASSERT_EQ(entry.count, 4U);
348 for (int i = 0; i < 4; i++) {
349 EXPECT_EQ(entry.data.i32[i], testLetterBoxSize[index][i]);
350 }
351 entry = metadata.find(ANDROID_CONTROL_ZOOM_RATIO);
352 EXPECT_NEAR(entry.data.f[0], 1.0f, kMaxAllowedRatioError);
353
354 res = mapper.updateCaptureResult(&metadata, true/*requestedZoomRatioIs1*/);
355 ASSERT_EQ(res, OK);
356 entry = metadata.find(ANDROID_SCALER_CROP_REGION);
357 ASSERT_EQ(entry.count, 4U);
358 for (int i = 0; i < 4; i++) {
359 EXPECT_EQ(entry.data.i32[i], testLetterBoxSize[index][i]);
360 }
361 entry = metadata.find(ANDROID_CONTROL_ZOOM_RATIO);
362 EXPECT_NEAR(entry.data.f[0], 1.0f, kMaxAllowedRatioError);
363}
364
365TEST(ZoomRatioTest, CropOverZoomRangeTest) {
366 subCropOverZoomRangeTest(false/*usePreCorrectArray*/);
367 subCropOverZoomRangeTest(true/*usePreCorrectArray*/);
368}
369
370void subZoomOverMaxDigitalZoomTest(bool usePreCorrectArray) {
371 status_t res;
372 ZoomRatioMapper mapper;
373 float noZoomRatioRange[2];
374 res = setupTestMapper(&mapper, 4.0/*maxDigitalZoom*/,
375 testActiveArraySize, testPreCorrActiveArraySize,
376 false/*hasZoomRatioRange*/, noZoomRatioRange,
377 usePreCorrectArray);
378 ASSERT_EQ(res, OK);
379
380 CameraMetadata metadata;
381 float zoomRatio = 3.0f;
382 camera_metadata_entry_t entry;
383
384 size_t index = usePreCorrectArray ? 1 : 0;
385
386 // Full active array crop, zoomRatio is 3.0f
387 metadata.update(ANDROID_SCALER_CROP_REGION, testDefaultCropSize[index], 4);
388 metadata.update(ANDROID_CONTROL_ZOOM_RATIO, &zoomRatio, 1);
389 res = mapper.updateCaptureRequest(&metadata);
390 ASSERT_EQ(res, OK);
391 entry = metadata.find(ANDROID_SCALER_CROP_REGION);
392 ASSERT_EQ(entry.count, 4U);
393 std::array<float, 4> expectedCrop = {
394 testDefaultCropSize[index][2] / 3.0f, /*x*/
395 testDefaultCropSize[index][3] / 3.0f, /*y*/
396 testDefaultCropSize[index][2] / 3.0f, /*width*/
397 testDefaultCropSize[index][3] / 3.0f, /*height*/
398 };
399 for (int i = 0; i < 4; i++) {
400 EXPECT_LE(std::abs(entry.data.i32[i] - expectedCrop[i]), kMaxAllowedPixelError);
401 }
402
403 entry = metadata.find(ANDROID_CONTROL_ZOOM_RATIO);
404 if (entry.count == 1) {
405 EXPECT_NEAR(entry.data.f[0], 1.0f, kMaxAllowedRatioError);
406 }
407}
408
409TEST(ZoomRatioTest, ZoomOverMaxDigitalZoomTest) {
410 subZoomOverMaxDigitalZoomTest(false/*usePreCorrectArray*/);
411 subZoomOverMaxDigitalZoomTest(true/*usePreCorrectArray*/);
412}
413
414void subZoomOverZoomRangeTest(bool usePreCorrectArray) {
415 status_t res;
416 ZoomRatioMapper mapper;
417 float zoomRatioRange[2] = {1.0f, 4.0f};
418 res = setupTestMapper(&mapper, 4.0/*maxDigitalZoom*/,
419 testActiveArraySize, testPreCorrActiveArraySize,
420 true/*hasZoomRatioRange*/, zoomRatioRange,
421 usePreCorrectArray);
422 ASSERT_EQ(res, OK);
423
424 CameraMetadata metadata;
425 float zoomRatio = 3.0f;
426 camera_metadata_entry_t entry;
427 size_t index = usePreCorrectArray ? 1 : 0;
428
429 // Full active array crop, zoomRatio is 3.0f
430 metadata.update(ANDROID_SCALER_CROP_REGION, testDefaultCropSize[index], 4);
431 metadata.update(ANDROID_CONTROL_ZOOM_RATIO, &zoomRatio, 1);
432 res = mapper.updateCaptureRequest(&metadata);
433 ASSERT_EQ(res, OK);
434 entry = metadata.find(ANDROID_SCALER_CROP_REGION);
435 ASSERT_EQ(entry.count, 4U);
436 for (int i = 0; i < 4; i ++) {
437 EXPECT_EQ(entry.data.i32[i], testDefaultCropSize[index][i]);
438 }
439 entry = metadata.find(ANDROID_CONTROL_ZOOM_RATIO);
440 ASSERT_EQ(entry.data.f[0], zoomRatio);
441
442 res = mapper.updateCaptureResult(&metadata, false/*requestedZoomRatioIs1*/);
443 ASSERT_EQ(res, OK);
444 entry = metadata.find(ANDROID_SCALER_CROP_REGION);
445 ASSERT_EQ(entry.count, 4U);
446 for (int i = 0; i < 4; i ++) {
447 EXPECT_EQ(entry.data.i32[i], testDefaultCropSize[index][i]);
448 }
449 entry = metadata.find(ANDROID_CONTROL_ZOOM_RATIO);
450 ASSERT_EQ(entry.data.f[0], zoomRatio);
451}
452
453TEST(ZoomRatioTest, ZoomOverZoomRangeTest) {
454 subZoomOverZoomRangeTest(false/*usePreCorrectArray*/);
455 subZoomOverZoomRangeTest(true/*usePreCorrectArray*/);
456}