1 /* ------------------------------------------------------------------ 2 * Copyright (C) 1998-2009 PacketVideo 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 13 * express or implied. 14 * See the License for the specific language governing permissions 15 * and limitations under the License. 16 * ------------------------------------------------------------------- 17 */ 18 /*! \file pvvideoblend.h 19 * \brief This file contains APIs for video blending functions. 20 */ 21 22 23 #ifndef PVVIDEOBLEND_H_INCLUDED 24 #define PVVIDEOBLEND_H_INCLUDED 25 26 #ifndef OSCL_TYPES_H_INCLUDED 27 #include "oscl_types.h" 28 #include "oscl_mem.h" 29 #endif 30 #ifndef CCZOOMROTATION16_H_INCLUDED 31 #include "cczoomrotation16.h" 32 #endif 33 #ifndef CCRGB16TOYUV420_H_INCLUDED 34 #include "ccrgb16toyuv420.h" 35 #endif 36 #ifndef CCYUV422TOYUV420_H_INCLUDED 37 #include "ccyuv422toyuv420.h" 38 #endif 39 40 /** 41 The type of YUV format. All are separate planar Y, U, and V. 42 **/ 43 typedef enum 44 { 45 YUV420 = 0, 46 YUV422 = 1 47 } PVYUVFormat; 48 49 50 /** 51 This enumeration is for the clockwise rotation angle. 52 **/ 53 typedef enum 54 { 55 Rotation0 = 0, 56 Rotation90 = 1, 57 Rotation180 = 2, 58 Rotation270 = 3, 59 } PVRotationCLKWise; 60 61 /** 62 This is for the mirror effect. */ 63 #define MirrorDisable 0 64 #define MirrorEnable 4 65 66 /** 67 This structure contains the YUV data and related information. 68 **/ 69 typedef struct 70 { 71 uint8 *pBuffer; /*!< contain the YUV data in contiguous manner */ 72 uint32 bufSize; /*!< size of the allocated pBuffer, can be larger than needed. */ 73 int32 width; /*!< in pixels for Y component */ 74 int32 height; /*!< in lines for Y component */ 75 PVYUVFormat format; /*!< indicates the specific YUV format for pBuffer */ 76 } PVBlendFrame; 77 78 79 /** 80 This structure contains the bitmap data and related information. The bitmap memory is to be allocated by users. 81 **/ 82 typedef struct 83 { 84 uint8 *pBuffer; /*!< RGB565 data */ 85 uint32 bufSize; /*!< size of the allocated pBuffer, can be larger than needed. */ 86 int32 width; /*!< in pixels */ 87 int32 height; /*!< in lines */ 88 int16 color_key; /*!< the color key for pBuffer data, to be ignored by the blend function */ 89 } PVBitmap; 90 91 92 /** 93 This structure contains the dimension of a frame. 94 **/ 95 typedef struct 96 { 97 int32 width; /*!< width in pixels */ 98 int32 height; /*!< height in lines */ 99 100 } PVDimension; 101 102 /** 103 This structure contains the top-left coordinate of a rectangle window. 104 **/ 105 typedef struct 106 { 107 int32 x; /*!< horizontal */ 108 int32 y; /*!< vertical */ 109 110 } PVCoordinate; 111 112 113 class CPVVideoBlend 114 { 115 public: 116 117 OSCL_IMPORT_REF static CPVVideoBlend* New(); 118 OSCL_IMPORT_REF ~CPVVideoBlend(); 119 120 /** 121 This function performs initialization to the input blend functionality, especially, for the RGB16 to YUV 122 conversion part. Look at BlendInput function for detailed operation. 123 @param frameSize Pointer to the size of the camera input frame, assuming the bitmap (if present) 124 has the same frame size as the camera input frame. 125 @param rotation Angle of rotation, for the input from camera. 126 @return 1 for success and 0 for fail. 127 **/ 128 OSCL_IMPORT_REF int32 InitInputBlend(PVDimension *frameSize, PVRotationCLKWise rotation); 129 130 /** 131 This function performs YUV422 to YUV420 conversion and rotation on the input from the camera 132 and output to a separate YUV buffer. It performs the RGB-to-YUV420 conversion on a bitmap 133 input (no scaling involved), if present, and overwrite the pixel output onto the output from the first operation 134 if the pixel value is different from the colorkey. 135 136 No additional persistent memory is allocated by the function. 137 138 Note on YUV422 format, the data in pCameraInput->pBuffer is of following: 139 Y2 Cr1 Y1 Cb1 Y4 Cr2 Y3 Cb2..... going from low to high address where Y2 140 represents pixel to the right of Y1 (notice the swapping of position in the buffer). 141 142 @param pCameraInput Pointer to the structure of the input frame from camera. 143 @param pBitmap Pointer to the bitmap structure, set to NULL if not present. 144 @param pToEncode Pointer to the output frame structure. 145 @return 1 for success and 0 for fail. 146 **/ 147 OSCL_IMPORT_REF int32 BlendInput(PVBlendFrame *pCameraInput, PVBitmap *pBitmap, PVBlendFrame *pToEncode); 148 149 150 /** 151 This function performs some initializations according to parameters for output blending function. 152 The input arguments represent parameters that do not change from frame to frame. 153 For clarity, we make the following association. 154 Input #1 is the frame coming out from the decoder. 155 Input #2 is the frame going into the encoder. 156 157 @param srcDecodeFrm The original dimension of Input #1. The top_left element is ignored. 158 @param dstDecodeFrm The output dimension after the scaling of Input #1. 159 @param srcEncodeFrm The original dimension of Input #2. The top_left element is ignored. 160 @param dstEncodeFrm The output dimension after the scaling of Input #2. 161 @param rotateMirrorEncFrm A flag to signify whether the Input#2 is to be rotated and/or mirror, for 162 example, it can be set to Rotation90|MirrorEnable. 163 @param pitch The pitch of the bitmap memory to be input as pDisplayOutput in FrameBlendOutput API. 164 @return 1 for success and 0 for fail. 165 */ 166 167 OSCL_IMPORT_REF int32 InitOutputBlend(PVDimension *srcDecodeFrm, 168 PVDimension *dstDecodeFrm, 169 PVDimension *srcEncodeFrm, 170 PVDimension *dstEncodeFrm, 171 int32 rotateMirrorForEncFrm, 172 int32 pitch); 173 174 /** 175 This function takes 3 inputs, pFromDecode, pToEncode, and pDropDownMenu and performs one or more of the 176 following operations on them: 177 - color conversion into RGB565 178 - scaling 179 - mirroring 180 - copying 181 according to the initialized parameters specified in InitOutputBlend. 182 pDisplayOutput is an I/O parameter. 183 184 Each input is sequentially written 185 onto the display bitmap (pDisplayOutput) according to this order: 186 pFromDecode, pToEncode and pDromDownMenu. If there are overlapped regions 187 among them, the previous outputs will be overwritten by the later outputs. 188 However, when changeOutputOrder flag is set to 1, the output order becomes 189 pToEncode, pFromDecode and pDropDownMenu. 190 191 192 No additional persistent memory is allocated by the function. 193 194 When any of the input frames (pFromDecode, pToEncode or pDropDownMenu) is NULL, 195 no operations are performed regarding the NULL input. pDisplayOutput is required to be present, 196 otherwise there will be no operations on any of the inputs. 197 198 @param pFromDecode Pointer to the decoded frame from the incoming call, to be color converted and scaled. 199 @param pos1 The location of the output associated with pFromDecode relative to the display output memory. 200 @param pToEncode Pointer to the frame to outgoing call, to be color converted, scaled, rotated, and/or mirrored. 201 @param pos2 The location of the output associated with pToEncode relative to the display output memory. 202 @param pDropDownMenu Pointer to the drop-down menu bitmap, to be copied, set to NULL if not present. 203 @param pos3 The location of the output associated with pDropDownMenu relative to the display output memory. 204 @param changeOutputOrder A flag to specify an alternative output order (see function description). 205 @param pDisplayOutput Pointer to the final bitmap output. This is also an input bitmap as the background 206 (canvas) for all the blending to be done over it. 207 @return 1 for success and 0 for fail. 208 **/ 209 OSCL_IMPORT_REF int32 BlendOutput(PVBlendFrame *pFromDecode, PVCoordinate *pos1, 210 PVBlendFrame *pToEncode, PVCoordinate *pos2, 211 PVBitmap *pDropDownMenu, PVCoordinate *pos3, 212 uint32 changeOutputOrder, 213 PVBitmap *pDisplayOutput); 214 215 216 private: 217 CPVVideoBlend(); 218 219 CCYUV422toYUV420 *CameraInput; 220 CCRGB16toYUV420 *BitmapInput; 221 ColorConvert16 *DecoderOutput; 222 ColorConvert16 *EncoderInput; 223 224 int32 Src_width, Src_height, Src_pitch, Dst_width, Dst_height, Dst_pitch, Rotation; 225 bool mInitInputBlend; 226 bool mInitOutputBlend; 227 }; 228 229 #endif // PVVIDEOBLEND_H_INCLUDED 230