Home | History | Annotate | Download | only in include
      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 CCZOOMROTATIONBASE_H_INCLUDED
     19 #define CCZOOMROTATIONBASE_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 
     30 #ifndef COLORCONV_CONFIG_H_INCLUDED
     31 #include "colorconv_config.h"
     32 #endif
     33 
     34 /* add capability support */
     35 #define  CCSUPPORT_ROTATION     0x1
     36 #define  CCSUPPORT_SCALING      0x2
     37 
     38 /* rotation orientation, values for nRotation */
     39 #define CCROTATE_NONE            0
     40 #define CCROTATE_CNTRCLKWISE     1
     41 #define CCROTATE_180             2
     42 #define CCROTATE_CLKWISE         3
     43 #define CCFLIP                   4
     44 #define CCBOTTOM_UP              8
     45 
     46 /**
     47 *   Description - This is the base class of color converter classes.
     48 *   Each of the 3 libraries needs to include this class in the project.
     49 *
     50 *   ASSUMPTIONS:
     51 *   1. zoom ratio must be no greater than 3
     52 *   2. cannot do zoom in in one dimenstion and zoom out in another
     53 *   3. caller should take care of the aspect ratio control
     54 *   4. if there are margins, the caller should paint the background to the desired color
     55 *   5. all the starting address MUST be multiple of 4, which is normally the case.
     56 *   4. the dest pitch MUST be multiple of 4
     57 *
     58 */
     59 // Definition of ColorConvertBase class
     60 
     61 class ColorConvertBase
     62 {
     63     public:
     64 
     65         //! Constructor
     66         ColorConvertBase();
     67 
     68         //! Destructor
     69         OSCL_IMPORT_REF virtual ~ColorConvertBase();
     70 
     71         /**
     72         *   @brief  This function returns a value indicate the capability of the library at run-time.
     73         *   @return It returns one of or a union of CCSUPPORT_ROTATION and CCSUPPORT_SCALING
     74         */
     75         virtual int16 GetCapability(void);
     76 
     77         /**
     78         *   @brief The function initializes necessary lookup tables and verify the capability of the library before starting the operation.
     79         *   @param Src_width specifies the width in pixel from the source to be color converted.
     80         *   @param Src_height specifies the height in pixel from the source to be color converted.
     81         *   @param Src_pitch is the actual memory width or stride of the source.
     82         *   @param Dst_width specifies the width in pixel of the output.
     83         *   @param Dst_height specifies the height in pixel of the output.
     84         *   @param Dst_pitch is the stride size of the destination memory.
     85         *   @param nRotation specifies whether rotation is to be applied. The value can be one of the followings
     86         *   CCROTATE_NONE (0), CCROTATE_CNTRCLKWISE (1) or CCROTATE_CLKWISE (3).
     87         *   When rotation is chosen, the Dst_width and Dst_height is still relative to the source coordinate,
     88         *   i.e., to rotate a QCIF image, the output width will be 144 and height will be 176.
     89         *   @return It returns 1 if success, 0 if fail, i.e., rotation or scaling not supported or
     90         *   any of the above parameters is an odd number.
     91         */
     92 
     93         virtual int32 Init(int32 Src_width, int32 Src_height, int32 Src_pitch, int32 Dst_width, int32 Dst_height, int32 Dst_pitch, int32 nRotation = 0);
     94 
     95         /**
     96         *   @brief This function specifies the height of the Y plane which may be larger
     97         *   than the height of the displayed region. For example, the output from PVM4Vdec
     98         *   always has width and height to be multiple of 16 pixels but the actual size may be not.
     99         *   In this case, users will set the src_width and src_height to the actual size,
    100         *   but set the src_pitch and SetMemHeight to the allocated Y plane size.
    101         *   For WMV, the Y plane output from WMV decoder has the exact dimension (no padding
    102         *   for multiple of 16).
    103         */
    104         virtual void SetMemHeight(int32 a_mHeight)
    105         {
    106             _mSrc_mheight = a_mHeight;
    107         };
    108 
    109         /**
    110         *   @brief This function specifies whether the output will use the attribute specified
    111         *   in the Init(.) function or perform regular color conversion without scaling or rotation.
    112         *   @param nMode When set to 0, 1-to-1 color conversion only is done. When NMode is 1,
    113         *   the output is be of the size and orientation specified in Init().
    114         *   @return 0 if fails (capability not supported or not initialized), 1 if success.
    115         */
    116         virtual int32 SetMode(int32 nMode) = 0; //nMode : 0 Off, 1 On
    117 
    118         /**
    119         *   @brief These functions convert the input buffer data into the output format
    120         *   and write the converted data to the output buffer.
    121         *   @param srcBuf is a pointer to the Y plane assuming that the U and V planes are contiguous to the Y plane.
    122         *   @param destBuf is a pointer to an output buffer.
    123         *   @return This function return 1 if success, 0 if fail.in the case of the destBuf
    124         *   and/or srcBuf address are not word-aligned (multiple of 4).
    125         */
    126 
    127         virtual int32 Convert(uint8 *srcBuf, uint8 *destBuf) = 0;
    128 
    129         /**
    130         *   @brief This function returns the size of output buffer that users need
    131         *   to allocate and pass it in as an input argument to Convert() function.
    132         *   Depending on the input argument to SetMode(), the buffer size can change.
    133         *   Furthermore, the color conversion library MAY REQUIRE BUFFER TO BE LARGER
    134         *   THAN what users EXPECT for extra processing space.
    135         *   @return An integer specifying the size of the output buffer.
    136         */
    137         virtual int32 GetOutputBufferSize(void) = 0;
    138 
    139         /**
    140         *   @brief This function allows the destination pitch to be set at run-time,
    141         *   e.g., switching between zoom & nonZoom mode.
    142         *   @return 1.
    143         */
    144         int32 SetDstPitch(int32 iDstPitch)
    145         {
    146             _mDisp.dst_pitch = iDstPitch;
    147             return 1;
    148         };
    149 
    150 
    151         /**
    152         *   @brief This function specifies the range of the YCbCr input such that the
    153         *   conversion to RGB is done accordingly (see ISO/IEC 14496-2:2004/FPDAM 3)..
    154         *   @param range  a boolean, false or zero means the range of the Y is 16-235,
    155         *   true or one means the full range of 0-255 is used. The default range is false.
    156         */
    157 
    158         virtual int32  SetYuvFullRange(bool range) = 0;
    159 
    160     protected:
    161 
    162         /** Internal structure for display property. This structure contains all configuration related
    163         *   parameters thus unifying the interface to variations of color convert functions
    164         */
    165         typedef struct
    166         {
    167             /** @brief Pitch of the input buffer (in pixel) */
    168             int32 src_pitch;
    169             /** @brief Pitch of the output buffer (in pixel) */
    170             int32 dst_pitch;
    171             /** @brief Width of the content of the input (in pixel) */
    172             int32 src_width;
    173             /** @brief Height of the content of the input (in pixel) */
    174             int32 src_height;
    175             /** @brief Width of the desired output (in pixel) */
    176             int32 dst_width;
    177             /** @brief Height of the desired output (in pixel) */
    178             int32 dst_height;
    179         } DisplayProperties ;
    180         DisplayProperties _mDisp;
    181 
    182         uint32 _mSrc_width, _mSrc_height, _mSrc_mheight, _mSrc_pitch, _mDst_width, _mDst_height, _mDst_pitch, _mRotation;
    183         uint8 *_mRowPix, *_mColPix;
    184 
    185         bool _mInitialized; // initialized yet?
    186         bool _mIsZoom;  //Is zoomable?
    187         int32 _mState;  //Zoom? Rotation? etc
    188         bool _mIsFlip;
    189         bool _mYuvRange;
    190 
    191     private:
    192         /**
    193         *   @brief This function calculates the number of repetitions for each input pixel to output
    194         *   pixel such that the total output size is as specified. Users have to call this function
    195         *   twice, one for horizontal scaling and one for vertical scaling.
    196         *   @param  pLinePix is a pointer to an array of number of repetition (zero-order interpolation).
    197         *   @param  iSrcLen is the input size.
    198         *   @param  iDstLen is the output size.
    199         */
    200         void StretchLine(uint8 *pLinePix, int32 iSrcLen, int32 iDstLen);
    201 
    202 };
    203 #endif // CCZOOMROTATIONBASE_H_INCLUDED
    204 
    205