• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 ANDROID_SERVERS_ROTATEANDCROPMAPPER_H
18 #define ANDROID_SERVERS_ROTATEANDCROPMAPPER_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 
27 namespace android {
28 
29 namespace camera3 {
30 
31 /**
32  * Utilities to transform between unrotated and rotated-and-cropped coordinate systems
33  * for cameras that support SCALER_ROTATE_AND_CROP controls in AUTO mode.
34  */
35 class RotateAndCropMapper : public CoordinateMapper {
36   public:
37     static bool isNeeded(const CameraMetadata* deviceInfo);
38 
39     RotateAndCropMapper(const CameraMetadata* deviceInfo);
40 
41     void initRemappedKeys() override;
42 
43     /**
44      * Adjust capture request assuming rotate and crop AUTO is enabled
45      */
46     status_t updateCaptureRequest(CameraMetadata *request);
47 
48     /**
49      * Adjust capture result assuming rotate and crop AUTO is enabled
50      */
51     status_t updateCaptureResult(CameraMetadata *result);
52 
53   private:
54     // Transform count's worth of x,y points passed in with 2x2 matrix + translate with transform
55     // origin (cx,cy)
56     void transformPoints(int32_t* pts, size_t count, float transformMat[4],
57             float xShift, float yShift, float cx, float cy);
58     // Take two corners of a rect as (x1,y1,x2,y2) and swap x and y components
59     // if needed so that x1 < x2, y1 < y2.
60     void swapRectToMinFirst(int32_t* rect);
61 
62     int32_t mArrayWidth, mArrayHeight;
63     float mArrayAspect, mRotateAspect;
64 }; // class RotateAndCroMapper
65 
66 } // namespace camera3
67 
68 } // namespace android
69 
70 #endif
71