1 /*
2  * Copyright (C) 2020 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 HARDWARE_GOOGLE_CAMERA_HAL_UTILS_ZOOM_RATIO_MAPPER_H_
18 #define HARDWARE_GOOGLE_CAMERA_HAL_UTILS_ZOOM_RATIO_MAPPER_H_
19 
20 #include "hal_types.h"
21 #include "zoom_ratio_mapper_hwl.h"
22 
23 namespace android {
24 namespace google_camera_hal {
25 
26 class ZoomRatioMapper {
27  public:
28   struct InitParams {
29     Dimension active_array_dimension;
30     std::unordered_map<uint32_t, Dimension> physical_cam_active_array_dimension;
31     ZoomRatioRange zoom_ratio_range;
32     std::unique_ptr<ZoomRatioMapperHwl> zoom_ratio_mapper_hwl;
33     uint32_t camera_id;
34   };
35 
36   void Initialize(InitParams* params);
37 
38   // Apply zoom ratio to capture request
39   void UpdateCaptureRequest(CaptureRequest* request);
40 
41   // Apply zoom ratio to capture result
42   void UpdateCaptureResult(CaptureResult* result);
43 
44  private:
45   // Apply zoom ratio to the capture request or result.
46   void ApplyZoomRatio(const Dimension& active_array_dimension,
47                       const bool is_request, HalCameraMetadata* metadata);
48 
49   // Update rect region with respect to zoom ratio and active array
50   // dimension.
51   void UpdateRects(float zoom_ratio, const uint32_t tag_id,
52                    const Dimension& active_array_dimension,
53                    const bool is_request, HalCameraMetadata* metadata);
54 
55   // Update weighted rect regions with respect to zoom ratio and active array
56   // dimension.
57   void UpdateWeightedRects(float zoom_ratio, const uint32_t tag_id,
58                            const Dimension& active_array_dimension,
59                            const bool is_request, HalCameraMetadata* metadata);
60 
61   // Update point position with respect to zoom ratio and active array
62   // dimension.
63   void UpdatePoints(float zoom_ratio, const uint32_t tag_id,
64                     const Dimension& active_array_dimension,
65                     HalCameraMetadata* metadata);
66 
67   // Active array dimension of logical camera.
68   Dimension active_array_dimension_;
69 
70   // Active array dimension of physical camera.
71   std::unordered_map<uint32_t, Dimension> physical_cam_active_array_dimension_;
72 
73   // Zoom ratio range.
74   ZoomRatioRange zoom_ratio_range_;
75 
76   // Indicate whether zoom ratio is supported.
77   bool is_zoom_ratio_supported_ = false;
78 
79   std::unique_ptr<ZoomRatioMapperHwl> zoom_ratio_mapper_hwl_;
80 
81   uint32_t camera_id_;
82 };
83 
84 }  // namespace google_camera_hal
85 }  // namespace android
86 
87 #endif  // HARDWARE_GOOGLE_CAMERA_HAL_UTILS_ZOOM_RATIO_MAPPER_H_
88