blob: aa3d9139ace1f504c3400c2ed7e4cdbc5f8f7f63 [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 */
36class ZoomRatioMapper : private CoordinateMapper {
37 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),
44 mIsValid(other.mIsValid) {}
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -080045
46 /**
47 * Initialize request template with valid zoomRatio if necessary.
48 */
49 static status_t initZoomRatioInTemplate(CameraMetadata *request);
50
51 /**
52 * Override zoomRatio related tags in the static metadata.
53 */
54 static status_t overrideZoomRatioTags(
55 CameraMetadata* deviceInfo, bool* supportNativeZoomRatio);
56
57 /**
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -080058 * Update capture request to handle both cropRegion and zoomRatio.
59 */
60 status_t updateCaptureRequest(CameraMetadata *request);
61
62 /**
63 * Update capture result to handle both cropRegion and zoomRatio.
64 */
65 status_t updateCaptureResult(CameraMetadata *request, bool requestedZoomRatioIs1);
66
67 public: // Visible for testing. Do not use concurently.
68 enum ClampMode {
69 ClampOff,
70 ClampInclusive,
71 ClampExclusive,
72 };
73
74 void scaleCoordinates(int32_t* coordPairs, int coordCount,
75 float scaleRatio, ClampMode clamp);
76
Shuzhen Wang1c834da2019-12-18 11:17:03 -080077 bool isValid() { return mIsValid; }
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -080078 private:
Shuzhen Wang1c834da2019-12-18 11:17:03 -080079 // const after construction
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -080080 bool mHalSupportsZoomRatio;
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -080081 // active array / pre-correction array dimension
82 int32_t mArrayWidth, mArrayHeight;
83
Shuzhen Wang1c834da2019-12-18 11:17:03 -080084 bool mIsValid = false;
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -080085
86 float deriveZoomRatio(const CameraMetadata* metadata);
Shuzhen Wangdbdf72b2019-11-13 11:22:12 -080087 void scaleRects(int32_t* rects, int rectCount, float scaleRatio);
88
89 status_t separateZoomFromCropLocked(CameraMetadata* metadata, bool isResult);
90 status_t combineZoomAndCropLocked(CameraMetadata* metadata, bool isResult);
91};
92
93} // namespace camera3
94
95} // namespace android
96
97#endif