summaryrefslogtreecommitdiff
path: root/service/src/com/android/telephony/imsmedia/lib/libimsmedia/core/include/utils/ImsMediaImageRotate.h
blob: a0d46ddfcbcdd3a080f2ca707a3ec4fe7dd6c9e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/**
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef IMS_MEDIA_IMAGE_ROTATE
#define IMS_MEDIA_IMAGE_ROTATE

#include <string.h>

class ImsMediaImageRotate
{
public:
    /**
     * @brief Rotates YUVImage_420_Planar Image by 90 degrees and flips.
     * Supports input row stride equal to width.
     *
     *  Source Image    Destination Image
     *  + - - - - +     + - - - - +
     *  | 1  2  3 |     | 9  6  3 |
     *  | 4  5  6 |     | 8  5  2 |
     *  | 7  8  9 |     | 7  4  1 |
     *  + - - - - +     + - - - - +
     *
     * @param pOutBuffer Pointer to output buffer with size nDstWidth*nDstHeight*1.5.
     * @param pbSrc Source buffer with size nDstWidth*nDstHeight*1.5.
     * @param nSrcWidth Source Image width.
     * @param nSrcHeight Source Image height.
     */
    static void YUV420_Planar_Rotate90_Flip(
            uint8_t* pOutBuffer, uint8_t* pbSrc, uint16_t nSrcWidth, uint16_t nSrcHeight);

    /**
     * @brief Rotates YUVImage_420_888 Image by 90 degrees.
     * Supports input row stride equal to width and adds padding when outputStride is not same
     * as output image width.
     *
     *  Source Image    Destination Image
     *  + - - - - +     + - - - - +
     *  | 1  2  3 |     | 7  4  1 |
     *  | 4  5  6 |     | 8  5  2 |
     *  | 7  8  9 |     | 9  6  3 |
     *  + - - - - +     + - - - - +
     *
     * @param pOutBuffer Pointer to output buffer with size outputStride*nDstHeight*1.5.
     * @param nOutBufSize size of output buffer.
     * @param outputStride Stride of the output image >= nDstWidth.
     * @param pYPlane Y-Plane data of size nDstWidth*nDstHeight.
     * @param pUVPlane UV-Plane data of size (nDstWidth*nDstHeight)/2.
     * @param nSrcWidth Source Image width.
     * @param nSrcHeight Source Image height.
     *
     * @return -1 on error and 0 on success.
     */
    static int YUV420_SP_Rotate90(uint8_t* pOutBuffer, size_t nOutBufSize, uint16_t outputStride,
            uint8_t* pYPlane, uint8_t* pUVPlane, uint16_t nSrcWidth, uint16_t nSrcHeight);

    /**
     * @brief Rotates YUVImage_420_888 Image by 90 degrees and flip.
     * Supports input row stride equal to width.
     *
     *  Source Image    Destination Image
     *  + - - - - +     + - - - - +
     *  | 1  2  3 |     | 9  6  3 |
     *  | 4  5  6 |     | 8  5  2 |
     *  | 7  8  9 |     | 7  4  1 |
     *  + - - - - +     + - - - - +
     *
     * @param pOutBuffer Pointer to output buffer with size nDstWidth*nDstHeight*1.5.
     * @param pYPlane Y-Plane data of size nDstWidth*nDstHeight.
     * @param pUVPlane UV-Plane data of size (nDstWidth*nDstHeight)/2.
     * @param nSrcWidth Source Image width.
     * @param nSrcHeight Source Image height.
     */
    static void YUV420_SP_Rotate90_Flip(uint8_t* pOutBuffer, uint8_t* pYPlane, uint8_t* pUVPlane,
            uint16_t nSrcWidth, uint16_t nSrcHeight);

    /**
     * @brief Rotates YUVImage_420_888 Image by 270 degrees.
     * Supports input row stride equal to width and adds padding when outputStride is not same
     * as output image width.
     *
     *  Source Image    Destination Image
     *  + - - - - +     + - - - - +
     *  | 1  2  3 |     | 3  6  9 |
     *  | 4  5  6 |     | 2  5  8 |
     *  | 7  8  9 |     | 1  4  7 |
     *  + - - - - +     + - - - - +
     *
     * @param pOutBuffer Pointer to output buffer with size nDstWidth*nDstHeight*1.5.
     * @param nOutBufSize size of output buffer.
     * @param outputStride Stride of the output image >= nDstWidth.
     * @param pYPlane Y-Plane data of size nDstWidth*nDstHeight.
     * @param pUVPlane UV-Plane data of size (nDstWidth*nDstHeight)/2.
     * @param nSrcWidth Source Image width.
     * @param nSrcHeight Source Image height.
     *
     * @return -1 on error and 0 on success.
     */
    static int YUV420_SP_Rotate270(uint8_t* pOutBuffer, size_t nOutBufSize, uint16_t outputStride,
            uint8_t* pYPlane, uint8_t* pUVPlane, uint16_t nSrcWidth, uint16_t nSrcHeight);
};

#endif  // IMS_MEDIA_IMAGE_ROTATE