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 #ifndef CCRGB12TOYUV420_H_INCLUDED 19 #define CCRGB12TOYUV420_H_INCLUDED 20 21 #ifndef OSCL_BASE_H_INCLUDED 22 #include "oscl_base.h" 23 #endif 24 25 #ifndef OSCL_MEM_H_INCLUDED 26 #include "oscl_mem.h" 27 #endif 28 29 #ifndef CCZOOMROTATIONBASE_H_INCLUDED 30 #include "cczoomrotationbase.h" 31 #endif 32 33 34 class CCRGB12toYUV420 : public ColorConvertBase 35 { 36 37 public: 38 OSCL_IMPORT_REF static ColorConvertBase* New(); 39 OSCL_IMPORT_REF ~CCRGB12toYUV420(); 40 41 42 /** 43 * @brief The function initializes necessary lookup tables and verify the capability of the library before starting the operation. 44 * This function performs some initializations and memory allocations for the Y, Cb, Cr tables. 45 46 * @param Src_width specifies the width in pixel from the source to be color converted. 47 * @param Src_height specifies the height in pixel from the source to be color converted. 48 * @param Src_pitch is the actual memory width or stride of the source. 49 * @param Dst_width specifies the width in pixel of the output. 50 * @param Dst_height specifies the height in pixel of the output. 51 * @param Dst_pitch is the stride size of the destination memory. 52 * @param nRotation specifies whether rotation is to be applied. The value can be one of the followings 53 * CCROTATE_NONE (0), CCROTATE_CNTRCLKWISE (1) or CCROTATE_CLKWISE (3). 54 * When rotation is chosen, the Dst_width and Dst_height is still relative to the source coordinate, 55 * i.e., to rotate a QCIF image, the output width will be 144 and height will be 176. 56 * @return It returns 1 if success, 0 if fail, i.e.any of the above parameters is an odd number. 57 */ 58 int32 Init(int32 Src_width, 59 int32 Src_height, 60 int32 Src_pitch, 61 int32 Dst_width, 62 int32 Dst_height, 63 int32 Dst_pitch, 64 int32 nRotation = 0); 65 66 /** 67 * @brief As opposed to the definition defined in cczoomrotationbase.h, this function 68 sets the memory height of the YUV buffer which is the output instead of the input. 69 */ 70 SetMemHeight(int32 a_mHeight)71 void SetMemHeight(int32 a_mHeight) 72 { 73 _mDst_mheight = a_mHeight; 74 }; 75 76 /** 77 * @brief This function specifies whether the output will use the attribute specified 78 * in the Init(.) function or perform regular color conversion without scaling or rotation. 79 * @param nMode When set to 0, 1-to-1 color conversion only is done. When NMode is 1, 80 * the output is be of the size and orientation specified in Init(). 81 * @return 0 if fails (capability not supported or not initialized), 1 if success. 82 */ 83 int32 SetMode(int32 nMode); 84 85 /** 86 * @brief These functions convert input RGB into corresponding YUV output. 87 * @param rgb12 is a pointer to an input buffer. 88 * @param yuv420 is a pointer to an output buffer of Y plane assuming that the U and V planes are contiguous to the Y plane. 89 * @return This function return 1 if success, 0 if fail. 90 */ 91 int32 Convert(uint8 *rgb12, 92 uint8 *yuv420); 93 94 int32 Convert(uint8 *rgb12, uint8 **yuv420); 95 96 97 /** 98 * @brief This function gives the size of the output YUV420 buffer 99 * @return buffer size in bytes 100 */ 101 int32 GetOutputBufferSize(void); 102 103 /** 104 * @brief Implemenation of a virtual function for range. 105 * @return default to 1. 106 */ 107 int32 SetYuvFullRange(bool range); 108 109 private: 110 111 CCRGB12toYUV420(); 112 113 /** 114 @brief This function frees the memory allocated for the YUV tables 115 */ 116 void freeRGB2YUVTables(); 117 118 /** @brief Tables in color coversion */ 119 uint8 *iY_Table, *iCb_Table, *iCr_Table; 120 uint8 *ipCb_Table, *ipCr_Table; 121 122 /** @brief Memory height of the output YUV420 image, default to mDstHeight. **/ 123 int32 _mDst_mheight; 124 bool iBottomUp; 125 126 }; 127 128 #endif // CCRGB12TOYUV420_H_INCLUDED 129 130