blob: b7a9e41cea73bed4444028f8a4e129e85382863d [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>
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -080022
23#include "camera/CameraMetadata.h"
24#include "device3/CoordinateMapper.h"
25
26namespace android {
27
28namespace camera3 {
29
30/**
31 * Utilities to convert between the new zoomRatio and existing cropRegion
32 * metadata tags. Note that this class does conversions in 2 scenarios:
33 * - HAL supports zoomRatio and the application uses cropRegion, or
34 * - HAL doesn't support zoomRatio, but the application uses zoomRatio
35 */
Shuzhen Wang8c75a642020-10-29 21:58:53 -070036class ZoomRatioMapper : public CoordinateMapper {
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -080037 public:
Shuzhen Wang1c834da2019-12-18 11:17:03 -080038 ZoomRatioMapper() = default;
39 ZoomRatioMapper(const CameraMetadata *deviceInfo,
40 bool supportNativeZoomRatio, bool usePrecorrectArray);
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -080041 ZoomRatioMapper(const ZoomRatioMapper& other) :
42 mHalSupportsZoomRatio(other.mHalSupportsZoomRatio),
Yin-Chia Yeh87fccca2020-01-28 09:37:18 -080043 mArrayWidth(other.mArrayWidth), mArrayHeight(other.mArrayHeight),
Shuzhen Wang8c75a642020-10-29 21:58:53 -070044 mIsValid(other.mIsValid) { initRemappedKeys(); }
45
46 void initRemappedKeys() override;
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -080047
48 /**
49 * Initialize request template with valid zoomRatio if necessary.
50 */
51 static status_t initZoomRatioInTemplate(CameraMetadata *request);
52
53 /**
54 * Override zoomRatio related tags in the static metadata.
55 */
56 static status_t overrideZoomRatioTags(
57 CameraMetadata* deviceInfo, bool* supportNativeZoomRatio);
58
59 /**
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -080060 * Update capture request to handle both cropRegion and zoomRatio.
61 */
62 status_t updateCaptureRequest(CameraMetadata *request);
63
64 /**
65 * Update capture result to handle both cropRegion and zoomRatio.
66 */
67 status_t updateCaptureResult(CameraMetadata *request, bool requestedZoomRatioIs1);
68
69 public: // Visible for testing. Do not use concurently.
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -080070 void scaleCoordinates(int32_t* coordPairs, int coordCount,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -080071 float scaleRatio, bool clamp, int32_t arrayWidth, int32_t arrayHeight);
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -080072
Shuzhen Wang1c834da2019-12-18 11:17:03 -080073 bool isValid() { return mIsValid; }
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -080074 private:
Shuzhen Wang1c834da2019-12-18 11:17:03 -080075 // const after construction
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -080076 bool mHalSupportsZoomRatio;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -080077
78 // active array / pre-correction array dimension for default and maximum
79 // resolution modes.
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -080080 int32_t mArrayWidth, mArrayHeight;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -080081 int32_t mArrayWidthMaximumResolution, mArrayHeightMaximumResolution;
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -080082
Shuzhen Wang1c834da2019-12-18 11:17:03 -080083 bool mIsValid = false;
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -080084
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -080085 status_t deriveZoomRatio(const CameraMetadata* metadata, float *zoomRatio, int arrayWidth,
86 int arrayHeight);
87 void scaleRects(int32_t* rects, int rectCount, float scaleRatio, int32_t arrayWidth,
88 int32_t arrayHeight);
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -080089
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -080090 status_t separateZoomFromCropLocked(CameraMetadata* metadata, bool isResult, int arrayWidth,
91 int arrayHeight);
92 status_t combineZoomAndCropLocked(CameraMetadata* metadata, bool isResult, int arrayWidth,
93 int arrayHeight);
94 status_t getArrayDimensionsToBeUsed(const CameraMetadata *settings, int32_t *arrayWidth,
95 int32_t *arrayHeight);
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -080096};
97
98} // namespace camera3
99
100} // namespace android
101
102#endif