blob: 459e27f01075bef75f1e0321b346cce0178786ee [file] [log] [blame]
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -08001/*
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
27namespace android {
28
29namespace 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 */
35class RotateAndCropMapper : private CoordinateMapper {
36 public:
37 static bool isNeeded(const CameraMetadata* deviceInfo);
38
39 RotateAndCropMapper(const CameraMetadata* deviceInfo);
40
41 /**
42 * Adjust capture request assuming rotate and crop AUTO is enabled
43 */
44 status_t updateCaptureRequest(CameraMetadata *request);
45
46 /**
47 * Adjust capture result assuming rotate and crop AUTO is enabled
48 */
49 status_t updateCaptureResult(CameraMetadata *result);
50
51 private:
52 // Transform count's worth of x,y points passed in with 2x2 matrix + translate with transform
53 // origin (cx,cy)
54 void transformPoints(int32_t* pts, size_t count, float transformMat[4],
55 float xShift, float yShift, float cx, float cy);
56 // Take two corners of a rect as (x1,y1,x2,y2) and swap x and y components
57 // if needed so that x1 < x2, y1 < y2.
58 void swapRectToMinFirst(int32_t* rect);
59
60 int32_t mArrayWidth, mArrayHeight;
61 float mArrayAspect, mRotateAspect;
62}; // class RotateAndCroMapper
63
64} // namespace camera3
65
66} // namespace android
67
68#endif