• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*!
2  * \copy
3  *     Copyright (c)  2013, Cisco Systems
4  *     All rights reserved.
5  *
6  *     Redistribution and use in source and binary forms, with or without
7  *     modification, are permitted provided that the following conditions
8  *     are met:
9  *
10  *        * Redistributions of source code must retain the above copyright
11  *          notice, this list of conditions and the following disclaimer.
12  *
13  *        * Redistributions in binary form must reproduce the above copyright
14  *          notice, this list of conditions and the following disclaimer in
15  *          the documentation and/or other materials provided with the
16  *          distribution.
17  *
18  *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  *     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  *     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  *     FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22  *     COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23  *     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24  *     BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26  *     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  *     LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28  *     ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  *     POSSIBILITY OF SUCH DAMAGE.
30  *
31  */
32 
33 #include "imagerotate.h"
34 
35 WELSVP_NAMESPACE_BEGIN
36 
37 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
38 
CImageRotating(int32_t iCpuFlag)39 CImageRotating::CImageRotating (int32_t iCpuFlag) {
40   m_iCPUFlag = iCpuFlag;
41   m_eMethod   = METHOD_IMAGE_ROTATE;
42   WelsMemset (&m_pfRotateImage, 0, sizeof (m_pfRotateImage));
43   InitImageRotateFuncs (m_pfRotateImage, m_iCPUFlag);
44 }
45 
~CImageRotating()46 CImageRotating::~CImageRotating() {
47 }
48 
InitImageRotateFuncs(SImageRotateFuncs & sImageRotateFuncs,int32_t iCpuFlag)49 void CImageRotating::InitImageRotateFuncs (SImageRotateFuncs& sImageRotateFuncs, int32_t iCpuFlag) {
50   sImageRotateFuncs.pfImageRotate90D = ImageRotate90D_c;
51   sImageRotateFuncs.pfImageRotate180D = ImageRotate180D_c;
52   sImageRotateFuncs.pfImageRotate270D = ImageRotate270D_c;
53 }
ProcessImageRotate(int32_t iType,uint8_t * pSrc,uint32_t uiBytesPerPixel,uint32_t iWidth,uint32_t iHeight,uint8_t * pDst)54 EResult CImageRotating::ProcessImageRotate (int32_t iType, uint8_t* pSrc, uint32_t uiBytesPerPixel, uint32_t iWidth,
55     uint32_t iHeight, uint8_t* pDst) {
56   if (iType == 90) {
57     m_pfRotateImage.pfImageRotate90D (pSrc, uiBytesPerPixel, iWidth, iHeight, pDst);
58   } else if (iType == 180) {
59     m_pfRotateImage.pfImageRotate180D (pSrc, uiBytesPerPixel, iWidth, iHeight, pDst);
60   } else if (iType == 270) {
61     m_pfRotateImage.pfImageRotate270D (pSrc, uiBytesPerPixel, iWidth, iHeight, pDst);
62   } else {
63     return RET_NOTSUPPORTED;
64   }
65   return RET_SUCCESS;
66 }
67 
Process(int32_t iType,SPixMap * pSrc,SPixMap * pDst)68 EResult CImageRotating::Process (int32_t iType, SPixMap* pSrc, SPixMap* pDst) {
69   EResult eReturn = RET_INVALIDPARAM;
70 
71   if ((pSrc->eFormat == VIDEO_FORMAT_RGBA) ||
72       (pSrc->eFormat == VIDEO_FORMAT_BGRA) ||
73       (pSrc->eFormat == VIDEO_FORMAT_ABGR) ||
74       (pSrc->eFormat == VIDEO_FORMAT_ARGB)) {
75     eReturn = ProcessImageRotate (iType, (uint8_t*)pSrc->pPixel[0], pSrc->iSizeInBits * 8, pSrc->sRect.iRectWidth,
76                                   pSrc->sRect.iRectHeight, (uint8_t*)pDst->pPixel[0]);
77   } else if (pSrc->eFormat == VIDEO_FORMAT_I420) {
78     ProcessImageRotate (iType, (uint8_t*)pSrc->pPixel[0], pSrc->iSizeInBits * 8, pSrc->sRect.iRectWidth,
79                         pSrc->sRect.iRectHeight, (uint8_t*)pDst->pPixel[0]);
80     ProcessImageRotate (iType, (uint8_t*)pSrc->pPixel[1], pSrc->iSizeInBits * 8, (pSrc->sRect.iRectWidth >> 1),
81                         (pSrc->sRect.iRectHeight >> 1), (uint8_t*)pDst->pPixel[1]);
82     eReturn = ProcessImageRotate (iType, (uint8_t*)pSrc->pPixel[2], pSrc->iSizeInBits * 8, (pSrc->sRect.iRectWidth >> 1),
83                                   (pSrc->sRect.iRectHeight >> 1), (uint8_t*)pDst->pPixel[2]);
84   } else {
85     eReturn = RET_NOTSUPPORTED;
86   }
87 
88   return eReturn;
89 }
90 
91 
92 WELSVP_NAMESPACE_END
93