blob: 38efbfdf28fa1a3f39d8bda422f950a80d4fb1f2 [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#ifndef ANDROID_SERVERS_ZOOMRATIOMAPPER_H
18#define ANDROID_SERVERS_ZOOMRATIOMAPPER_H
19
20#include <utils/Errors.h>
21#include <array>
22#include <mutex>
23
24#include "camera/CameraMetadata.h"
25#include "device3/CoordinateMapper.h"
26
27namespace android {
28
29namespace camera3 {
30
31/**
32 * Utilities to convert between the new zoomRatio and existing cropRegion
33 * metadata tags. Note that this class does conversions in 2 scenarios:
34 * - HAL supports zoomRatio and the application uses cropRegion, or
35 * - HAL doesn't support zoomRatio, but the application uses zoomRatio
36 */
37class ZoomRatioMapper : private CoordinateMapper {
38 public:
39 ZoomRatioMapper();
40 ZoomRatioMapper(const ZoomRatioMapper& other) :
41 mHalSupportsZoomRatio(other.mHalSupportsZoomRatio),
42 mArrayWidth(other.mArrayWidth), mArrayHeight(other.mArrayHeight) {}
43
44 /**
45 * Initialize request template with valid zoomRatio if necessary.
46 */
47 static status_t initZoomRatioInTemplate(CameraMetadata *request);
48
49 /**
50 * Override zoomRatio related tags in the static metadata.
51 */
52 static status_t overrideZoomRatioTags(
53 CameraMetadata* deviceInfo, bool* supportNativeZoomRatio);
54
55 /**
56 * Initialize zoom ratio mapper with static metadata.
57 *
58 * Note:
59 * This function may modify the static metadata with zoomRatio related
60 * tags.
61 */
62 status_t initZoomRatioTags(const CameraMetadata *deviceInfo,
63 bool supportNativeZoomRatio, bool usePrecorrectArray);
64
65 /**
66 * Update capture request to handle both cropRegion and zoomRatio.
67 */
68 status_t updateCaptureRequest(CameraMetadata *request);
69
70 /**
71 * Update capture result to handle both cropRegion and zoomRatio.
72 */
73 status_t updateCaptureResult(CameraMetadata *request, bool requestedZoomRatioIs1);
74
75 public: // Visible for testing. Do not use concurently.
76 enum ClampMode {
77 ClampOff,
78 ClampInclusive,
79 ClampExclusive,
80 };
81
82 void scaleCoordinates(int32_t* coordPairs, int coordCount,
83 float scaleRatio, ClampMode clamp);
84
85 private:
86 bool mHalSupportsZoomRatio;
87
88 // active array / pre-correction array dimension
89 int32_t mArrayWidth, mArrayHeight;
90
91 mutable std::mutex mMutex;
92
93 float deriveZoomRatio(const CameraMetadata* metadata);
94
95 void scaleRects(int32_t* rects, int rectCount, float scaleRatio);
96
97 status_t separateZoomFromCropLocked(CameraMetadata* metadata, bool isResult);
98 status_t combineZoomAndCropLocked(CameraMetadata* metadata, bool isResult);
99};
100
101} // namespace camera3
102
103} // namespace android
104
105#endif