1 /** 2 * Copyright (C) 2022 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 IMS_MEDIA_IMAGE_ROTATE 18 #define IMS_MEDIA_IMAGE_ROTATE 19 20 #include <string.h> 21 22 class ImsMediaImageRotate 23 { 24 public: 25 /** 26 * @brief Rotates YUVImage_420_Planar Image by 90 degrees and flips. 27 * Supports input row stride equal to width. 28 * 29 * Source Image Destination Image 30 * + - - - - + + - - - - + 31 * | 1 2 3 | | 9 6 3 | 32 * | 4 5 6 | | 8 5 2 | 33 * | 7 8 9 | | 7 4 1 | 34 * + - - - - + + - - - - + 35 * 36 * @param pOutBuffer Pointer to output buffer with size nDstWidth*nDstHeight*1.5. 37 * @param pbSrc Source buffer with size nDstWidth*nDstHeight*1.5. 38 * @param nSrcWidth Source Image width. 39 * @param nSrcHeight Source Image height. 40 */ 41 static void YUV420_Planar_Rotate90_Flip( 42 uint8_t* pOutBuffer, uint8_t* pbSrc, uint16_t nSrcWidth, uint16_t nSrcHeight); 43 44 /** 45 * @brief Rotates YUVImage_420_888 Image by 90 degrees. 46 * Supports input row stride equal to width and adds padding when outputStride is not same 47 * as output image width. 48 * 49 * Source Image Destination Image 50 * + - - - - + + - - - - + 51 * | 1 2 3 | | 7 4 1 | 52 * | 4 5 6 | | 8 5 2 | 53 * | 7 8 9 | | 9 6 3 | 54 * + - - - - + + - - - - + 55 * 56 * @param pOutBuffer Pointer to output buffer with size outputStride*nDstHeight*1.5. 57 * @param nOutBufSize size of output buffer. 58 * @param outputStride Stride of the output image >= nDstWidth. 59 * @param pYPlane Y-Plane data of size nDstWidth*nDstHeight. 60 * @param pUVPlane UV-Plane data of size (nDstWidth*nDstHeight)/2. 61 * @param nSrcWidth Source Image width. 62 * @param nSrcHeight Source Image height. 63 * 64 * @return -1 on error and 0 on success. 65 */ 66 static int YUV420_SP_Rotate90(uint8_t* pOutBuffer, size_t nOutBufSize, uint16_t outputStride, 67 uint8_t* pYPlane, uint8_t* pUVPlane, uint16_t nSrcWidth, uint16_t nSrcHeight); 68 69 /** 70 * @brief Rotates YUVImage_420_888 Image by 90 degrees and flip. 71 * Supports input row stride equal to width. 72 * 73 * Source Image Destination Image 74 * + - - - - + + - - - - + 75 * | 1 2 3 | | 9 6 3 | 76 * | 4 5 6 | | 8 5 2 | 77 * | 7 8 9 | | 7 4 1 | 78 * + - - - - + + - - - - + 79 * 80 * @param pOutBuffer Pointer to output buffer with size nDstWidth*nDstHeight*1.5. 81 * @param pYPlane Y-Plane data of size nDstWidth*nDstHeight. 82 * @param pUVPlane UV-Plane data of size (nDstWidth*nDstHeight)/2. 83 * @param nSrcWidth Source Image width. 84 * @param nSrcHeight Source Image height. 85 */ 86 static void YUV420_SP_Rotate90_Flip(uint8_t* pOutBuffer, uint8_t* pYPlane, uint8_t* pUVPlane, 87 uint16_t nSrcWidth, uint16_t nSrcHeight); 88 89 /** 90 * @brief Rotates YUVImage_420_888 Image by 270 degrees. 91 * Supports input row stride equal to width and adds padding when outputStride is not same 92 * as output image width. 93 * 94 * Source Image Destination Image 95 * + - - - - + + - - - - + 96 * | 1 2 3 | | 3 6 9 | 97 * | 4 5 6 | | 2 5 8 | 98 * | 7 8 9 | | 1 4 7 | 99 * + - - - - + + - - - - + 100 * 101 * @param pOutBuffer Pointer to output buffer with size nDstWidth*nDstHeight*1.5. 102 * @param nOutBufSize size of output buffer. 103 * @param outputStride Stride of the output image >= nDstWidth. 104 * @param pYPlane Y-Plane data of size nDstWidth*nDstHeight. 105 * @param pUVPlane UV-Plane data of size (nDstWidth*nDstHeight)/2. 106 * @param nSrcWidth Source Image width. 107 * @param nSrcHeight Source Image height. 108 * 109 * @return -1 on error and 0 on success. 110 */ 111 static int YUV420_SP_Rotate270(uint8_t* pOutBuffer, size_t nOutBufSize, uint16_t outputStride, 112 uint8_t* pYPlane, uint8_t* pUVPlane, uint16_t nSrcWidth, uint16_t nSrcHeight); 113 }; 114 115 #endif // IMS_MEDIA_IMAGE_ROTATE