Showing the changes to codec/processing/src/downsample (3 of 124 files). Show all
Unified · Split
| @@ -0,0 +1,135 @@ | |||
| 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 "downsample.h" | ||
| 34 | #include "../common/cpu.h" | ||
| 35 | |||
| 36 | WELSVP_NAMESPACE_BEGIN | ||
| 37 | |||
| 38 | |||
| 39 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 40 | |||
| 41 | CDownsampling::CDownsampling (int32_t iCpuFlag) { | ||
| 42 | m_iCPUFlag = iCpuFlag; | ||
| 43 | m_eMethod = METHOD_DOWNSAMPLE; | ||
| 44 | WelsMemset (&m_pfDownsample, 0, sizeof (m_pfDownsample)); | ||
| 45 | InitDownsampleFuncs (m_pfDownsample, m_iCPUFlag); | ||
| 46 | } | ||
| 47 | |||
| 48 | CDownsampling::~CDownsampling() { | ||
| 49 | } | ||
| 50 | |||
| 51 | void CDownsampling::InitDownsampleFuncs (SDownsampleFuncs& sDownsampleFunc, int32_t iCpuFlag) { | ||
| 52 | sDownsampleFunc.pfHalfAverage[0] = DyadicBilinearDownsampler_c; | ||
| 53 | sDownsampleFunc.pfHalfAverage[1] = DyadicBilinearDownsampler_c; | ||
| 54 | sDownsampleFunc.pfHalfAverage[2] = DyadicBilinearDownsampler_c; | ||
| 55 | sDownsampleFunc.pfHalfAverage[3] = DyadicBilinearDownsampler_c; | ||
| 56 | sDownsampleFunc.pfGeneralRatioChroma = GeneralBilinearAccurateDownsampler_c; | ||
| 57 | sDownsampleFunc.pfGeneralRatioLuma = GeneralBilinearFastDownsampler_c; | ||
| 58 | #if defined(X86_ASM) | ||
| 59 | if (iCpuFlag & WELS_CPU_SSE) { | ||
| 60 | /* sDownsampleFunc.pfHalfAverage[0] = DyadicBilinearDownsamplerWidthx32_sse; | ||
| 61 | sDownsampleFunc.pfHalfAverage[1] = DyadicBilinearDownsamplerWidthx16_sse; | ||
| 62 | sDownsampleFunc.pfHalfAverage[2] = DyadicBilinearDownsamplerWidthx8_sse;*/ | ||
| 63 | } | ||
| 64 | if (iCpuFlag & WELS_CPU_SSE2) { | ||
| 65 | // sDownsampleFunc.pfGeneralRatioChroma = GeneralBilinearAccurateDownsamplerWrap_sse2; | ||
| 66 | // sDownsampleFunc.pfGeneralRatioLuma = GeneralBilinearFastDownsamplerWrap_sse2; | ||
| 67 | } | ||
| 68 | if (iCpuFlag & WELS_CPU_SSSE3) { | ||
| 69 | // sDownsampleFunc.pfHalfAverage[0] = DyadicBilinearDownsamplerWidthx32_ssse3; | ||
| 70 | // sDownsampleFunc.pfHalfAverage[1] = DyadicBilinearDownsamplerWidthx16_ssse3; | ||
| 71 | } | ||
| 72 | if (iCpuFlag & WELS_CPU_SSE41) { | ||
| 73 | // sDownsampleFunc.pfHalfAverage[0] = DyadicBilinearDownsamplerWidthx32_sse4; | ||
| 74 | // sDownsampleFunc.pfHalfAverage[1] = DyadicBilinearDownsamplerWidthx16_sse4; | ||
| 75 | } | ||
| 76 | #endif//X86_ASM | ||
| 77 | |||
| 78 | } | ||
| 79 | |||
| 80 | EResult CDownsampling::Process (int32_t iType, SPixMap* pSrcPixMap, SPixMap* pDstPixMap) { | ||
| 81 | int32_t iSrcWidthY = pSrcPixMap->sRect.iRectWidth; | ||
| 82 | int32_t iSrcHeightY = pSrcPixMap->sRect.iRectHeight; | ||
| 83 | int32_t iDstWidthY = pDstPixMap->sRect.iRectWidth; | ||
| 84 | int32_t iDstHeightY = pDstPixMap->sRect.iRectHeight; | ||
| 85 | |||
| 86 | int32_t iSrcWidthUV = iSrcWidthY >> 1; | ||
| 87 | int32_t iSrcHeightUV = iSrcHeightY >> 1; | ||
| 88 | int32_t iDstWidthUV = iDstWidthY >> 1; | ||
| 89 | int32_t iDstHeightUV = iDstHeightY >> 1; | ||
| 90 | |||
| 91 | if (iSrcWidthY <= iDstWidthY || iSrcHeightY <= iDstHeightY) { | ||
| 92 | return RET_INVALIDPARAM; | ||
| 93 | } | ||
| 94 | |||
| 95 | if ((iSrcWidthY >> 1) == iDstWidthY && (iSrcHeightY >> 1) == iDstHeightY) { | ||
| 96 | // use half average functions | ||
| 97 | uint8_t iAlignIndex = 3; | ||
| 98 | |||
| 99 | iAlignIndex = GetAlignedIndex (iSrcWidthY); | ||
| 100 | m_pfDownsample.pfHalfAverage[iAlignIndex] ((uint8_t*)pDstPixMap->pPixel[0], pDstPixMap->iStride[0], | ||
| 101 | (uint8_t*)pSrcPixMap->pPixel[0], pSrcPixMap->iStride[0], iSrcWidthY, iSrcHeightY); | ||
| 102 | |||
| 103 | iAlignIndex = GetAlignedIndex (iSrcWidthUV); | ||
| 104 | m_pfDownsample.pfHalfAverage[iAlignIndex] ((uint8_t*)pDstPixMap->pPixel[1], pDstPixMap->iStride[1], | ||
| 105 | (uint8_t*)pSrcPixMap->pPixel[1], pSrcPixMap->iStride[1], iSrcWidthUV, iSrcHeightUV); | ||
| 106 | m_pfDownsample.pfHalfAverage[iAlignIndex] ((uint8_t*)pDstPixMap->pPixel[2], pDstPixMap->iStride[2], | ||
| 107 | (uint8_t*)pSrcPixMap->pPixel[2], pSrcPixMap->iStride[2], iSrcWidthUV, iSrcHeightUV); | ||
| 108 | } else { | ||
| 109 | m_pfDownsample.pfGeneralRatioLuma ((uint8_t*)pDstPixMap->pPixel[0], pDstPixMap->iStride[0], iDstWidthY, iDstHeightY, | ||
| 110 | (uint8_t*)pSrcPixMap->pPixel[0], pSrcPixMap->iStride[0], iSrcWidthY, iSrcHeightY); | ||
| 111 | |||
| 112 | m_pfDownsample.pfGeneralRatioChroma ((uint8_t*)pDstPixMap->pPixel[1], pDstPixMap->iStride[1], iDstWidthUV, iDstHeightUV, | ||
| 113 | (uint8_t*)pSrcPixMap->pPixel[1], pSrcPixMap->iStride[1], iSrcWidthUV, iSrcHeightUV); | ||
| 114 | |||
| 115 | m_pfDownsample.pfGeneralRatioChroma ((uint8_t*)pDstPixMap->pPixel[2], pDstPixMap->iStride[2], iDstWidthUV, iDstHeightUV, | ||
| 116 | (uint8_t*)pSrcPixMap->pPixel[2], pSrcPixMap->iStride[2], iSrcWidthUV, iSrcHeightUV); | ||
| 117 | } | ||
| 118 | return RET_SUCCESS; | ||
| 119 | } | ||
| 120 | |||
| 121 | int32_t CDownsampling::GetAlignedIndex (const int32_t kiSrcWidth) { | ||
| 122 | int32_t iAlignIndex = 3; | ||
| 123 | if ((kiSrcWidth & 0x1f) == 0) // x32 | ||
| 124 | iAlignIndex = 0; | ||
| 125 | else if ((kiSrcWidth & 0x0f) == 0) // x16 | ||
| 126 | iAlignIndex = 1; | ||
| 127 | else if ((kiSrcWidth & 0x07) == 0) // x8 | ||
| 128 | iAlignIndex = 2; | ||
| 129 | else | ||
| 130 | iAlignIndex = 3; | ||
| 131 | return iAlignIndex; | ||
| 132 | } | ||
| 133 | |||
| 134 | |||
| 135 | WELSVP_NAMESPACE_END | ||
| @@ -0,0 +1,128 @@ | |||
| 1 | /*! | ||
| 2 | * \copy | ||
| 3 | * Copyright (c) 2011-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 | * \file : downsample.h | ||
| 32 | * | ||
| 33 | * \brief : downsample class of wels video processor class | ||
| 34 | * | ||
| 35 | * \date : 2011/03/33 | ||
| 36 | * | ||
| 37 | * \description : 1. rewrite the package code of downsample class | ||
| 38 | * | ||
| 39 | ************************************************************************************* | ||
| 40 | */ | ||
| 41 | |||
| 42 | #ifndef WELSVP_DOWNSAMPLE_H | ||
| 43 | #define WELSVP_DOWNSAMPLE_H | ||
| 44 | |||
| 45 | #include "../common/util.h" | ||
| 46 | #include "../common/WelsFrameWork.h" | ||
| 47 | #include "../../interface/IWelsVP.h" | ||
| 48 | |||
| 49 | WELSVP_NAMESPACE_BEGIN | ||
| 50 | |||
| 51 | |||
| 52 | typedef void (HalveDownsampleFunc) (uint8_t* pDst, const int32_t kiDstStride, | ||
| 53 | uint8_t* pSrc, const int32_t kiSrcStride, | ||
| 54 | const int32_t kiSrcWidth, const int32_t kiSrcHeight); | ||
| 55 | |||
| 56 | typedef void (GeneralDownsampleFunc) (uint8_t* pDst, const int32_t kiDstStride, const int32_t kiDstWidth, | ||
| 57 | const int32_t kiDstHeight, | ||
| 58 | uint8_t* pSrc, const int32_t kiSrcStride, const int32_t kiSrcWidth, const int32_t kiSrcHeight); | ||
| 59 | |||
| 60 | typedef HalveDownsampleFunc* PHalveDownsampleFunc; | ||
| 61 | typedef GeneralDownsampleFunc* PGeneralDownsampleFunc; | ||
| 62 | |||
| 63 | HalveDownsampleFunc DyadicBilinearDownsampler_c; | ||
| 64 | GeneralDownsampleFunc GeneralBilinearFastDownsampler_c; | ||
| 65 | GeneralDownsampleFunc GeneralBilinearAccurateDownsampler_c; | ||
| 66 | |||
| 67 | typedef struct { | ||
| 68 | // align_index: 0 = x32; 1 = x16; 2 = x8; 3 = common case left; | ||
| 69 | PHalveDownsampleFunc pfHalfAverage[4]; | ||
| 70 | PGeneralDownsampleFunc pfGeneralRatioLuma; | ||
| 71 | PGeneralDownsampleFunc pfGeneralRatioChroma; | ||
| 72 | } SDownsampleFuncs; | ||
| 73 | |||
| 74 | |||
| 75 | #ifdef X86_ASM | ||
| 76 | WELSVP_EXTERN_C_BEGIN | ||
| 77 | // used for scr width is multipler of 8 pixels | ||
| 78 | HalveDownsampleFunc DyadicBilinearDownsamplerWidthx8_sse; | ||
| 79 | // iSrcWidth= x16 pixels | ||
| 80 | HalveDownsampleFunc DyadicBilinearDownsamplerWidthx16_sse; | ||
| 81 | // iSrcWidth= x32 pixels | ||
| 82 | HalveDownsampleFunc DyadicBilinearDownsamplerWidthx32_sse; | ||
| 83 | // used for scr width is multipler of 16 pixels | ||
| 84 | HalveDownsampleFunc DyadicBilinearDownsamplerWidthx16_ssse3; | ||
| 85 | // iSrcWidth= x32 pixels | ||
| 86 | HalveDownsampleFunc DyadicBilinearDownsamplerWidthx32_ssse3; | ||
| 87 | // iSrcWidth= x16 pixels | ||
| 88 | HalveDownsampleFunc DyadicBilinearDownsamplerWidthx16_sse4; | ||
| 89 | // iSrcWidth= x32 pixels | ||
| 90 | HalveDownsampleFunc DyadicBilinearDownsamplerWidthx32_sse4; | ||
| 91 | |||
| 92 | GeneralDownsampleFunc GeneralBilinearFastDownsamplerWrap_sse2; | ||
| 93 | GeneralDownsampleFunc GeneralBilinearAccurateDownsamplerWrap_sse2; | ||
| 94 | |||
| 95 | void GeneralBilinearFastDownsampler_sse2 (uint8_t* pDst, const int32_t kiDstStride, const int32_t kiDstWidth, | ||
| 96 | const int32_t kiDstHeight, | ||
| 97 | uint8_t* pSrc, const int32_t kiSrcStride, const int32_t kiSrcWidth, const int32_t kiSrcHeight, | ||
| 98 | const uint32_t kuiScaleX, const uint32_t kuiScaleY); | ||
| 99 | void GeneralBilinearAccurateDownsampler_sse2 (uint8_t* pDst, const int32_t kiDstStride, const int32_t kiDstWidth, | ||
| 100 | const int32_t kiDstHeight, | ||
| 101 | uint8_t* pSrc, const int32_t kiSrcStride, const int32_t kiSrcWidth, const int32_t kiSrcHeight, | ||
| 102 | const uint32_t kuiScaleX, const uint32_t kuiScaleY); | ||
| 103 | WELSVP_EXTERN_C_END | ||
| 104 | #endif | ||
| 105 | |||
| 106 | |||
| 107 | |||
| 108 | |||
| 109 | class CDownsampling : public IStrategy { | ||
| 110 | public: | ||
| 111 | CDownsampling (int32_t iCpuFlag); | ||
| 112 | ~CDownsampling(); | ||
| 113 | |||
| 114 | EResult Process (int32_t iType, SPixMap* pSrc, SPixMap* pDst); | ||
| 115 | |||
| 116 | private: | ||
| 117 | void InitDownsampleFuncs (SDownsampleFuncs& sDownsampleFunc, int32_t iCpuFlag); | ||
| 118 | |||
| 119 | int32_t GetAlignedIndex (const int32_t kiSrcWidth); | ||
| 120 | |||
| 121 | private: | ||
| 122 | SDownsampleFuncs m_pfDownsample; | ||
| 123 | int32_t m_iCPUFlag; | ||
| 124 | }; | ||
| 125 | |||
| 126 | WELSVP_NAMESPACE_END | ||
| 127 | |||
| 128 | #endif | ||
| @@ -0,0 +1,234 @@ | |||
| 1 | /*! | ||
| 2 | * \copy | ||
| 3 | * Copyright (c) 2008-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 | * downsample_yuv.c | ||
| 32 | * | ||
| 33 | * Abstract | ||
| 34 | * Implementation for source yuv data downsampling used before spatial encoding. | ||
| 35 | * | ||
| 36 | * History | ||
| 37 | * 10/24/2008 Created | ||
| 38 | * | ||
| 39 | *****************************************************************************/ | ||
| 40 | |||
| 41 | #include "../common/typedef.h" | ||
| 42 | #include "../common/util.h" | ||
| 43 | #include "downsample.h" | ||
| 44 | |||
| 45 | |||
| 46 | WELSVP_NAMESPACE_BEGIN | ||
| 47 | |||
| 48 | |||
| 49 | void DyadicBilinearDownsampler_c (uint8_t* pDst, const int32_t kiDstStride, | ||
| 50 | uint8_t* pSrc, const int32_t kiSrcStride, | ||
| 51 | const int32_t kiSrcWidth, const int32_t kiSrcHeight) | ||
| 52 | |||
| 53 | { | ||
| 54 | uint8_t* pDstLine = pDst; | ||
| 55 | uint8_t* pSrcLine = pSrc; | ||
| 56 | const int32_t kiSrcStridex2 = kiSrcStride << 1; | ||
| 57 | const int32_t kiDstWidth = kiSrcWidth >> 1; | ||
| 58 | const int32_t kiDstHeight = kiSrcHeight >> 1; | ||
| 59 | |||
| 60 | for (int32_t j = 0; j < kiDstHeight; j ++) { | ||
| 61 | for (int32_t i = 0; i < kiDstWidth; i ++) { | ||
| 62 | const int32_t kiSrcX = i << 1; | ||
| 63 | const int32_t kiTempRow1 = (pSrcLine[kiSrcX] + pSrcLine[kiSrcX + 1] + 1) >> 1; | ||
| 64 | const int32_t kiTempRow2 = (pSrcLine[kiSrcX + kiSrcStride] + pSrcLine[kiSrcX + kiSrcStride + 1] + 1) >> 1; | ||
| 65 | |||
| 66 | pDstLine[i] = (uint8_t) ((kiTempRow1 + kiTempRow2 + 1) >> 1); | ||
| 67 | } | ||
| 68 | pDstLine += kiDstStride; | ||
| 69 | pSrcLine += kiSrcStridex2; | ||
| 70 | } | ||
| 71 | } | ||
| 72 | |||
| 73 | void GeneralBilinearFastDownsampler_c (uint8_t* pDst, const int32_t kiDstStride, const int32_t kiDstWidth, | ||
| 74 | const int32_t kiDstHeight, | ||
| 75 | uint8_t* pSrc, const int32_t kiSrcStride, const int32_t kiSrcWidth, const int32_t kiSrcHeight) { | ||
| 76 | const uint32_t kuiScaleBitWidth = 16, kuiScaleBitHeight = 15; | ||
| 77 | const uint32_t kuiScaleWidth = (1 << kuiScaleBitWidth), kuiScaleHeight = (1 << kuiScaleBitHeight); | ||
| 78 | int32_t fScalex = (int32_t) ((float_t)kiSrcWidth / (float_t)kiDstWidth * kuiScaleWidth); | ||
| 79 | int32_t fScaley = (int32_t) ((float_t)kiSrcHeight / (float_t)kiDstHeight * kuiScaleHeight); | ||
| 80 | uint32_t x; | ||
| 81 | int32_t iYInverse, iXInverse; | ||
| 82 | |||
| 83 | uint8_t* pByDst = pDst; | ||
| 84 | uint8_t* pByLineDst = pDst; | ||
| 85 | |||
| 86 | iYInverse = 1 << (kuiScaleBitHeight - 1); | ||
| 87 | for (int32_t i = 0; i < kiDstHeight - 1; i++) { | ||
| 88 | int32_t iYy = iYInverse >> kuiScaleBitHeight; | ||
| 89 | int32_t fv = iYInverse & (kuiScaleHeight - 1); | ||
| 90 | |||
| 91 | uint8_t* pBySrc = pSrc + iYy * kiSrcStride; | ||
| 92 | |||
| 93 | pByDst = pByLineDst; | ||
| 94 | iXInverse = 1 << (kuiScaleBitWidth - 1); | ||
| 95 | for (int32_t j = 0; j < kiDstWidth - 1; j++) { | ||
| 96 | int32_t iXx = iXInverse >> kuiScaleBitWidth; | ||
| 97 | int32_t iFu = iXInverse & (kuiScaleWidth - 1); | ||
| 98 | |||
| 99 | uint8_t* pByCurrent = pBySrc + iXx; | ||
| 100 | uint8_t a, b, c, d; | ||
| 101 | |||
| 102 | a = *pByCurrent; | ||
| 103 | b = * (pByCurrent + 1); | ||
| 104 | c = * (pByCurrent + kiSrcStride); | ||
| 105 | d = * (pByCurrent + kiSrcStride + 1); | ||
| 106 | |||
| 107 | x = (((uint32_t) (kuiScaleWidth - 1 - iFu)) * (kuiScaleHeight - 1 - fv) >> kuiScaleBitWidth) * a; | ||
| 108 | x += (((uint32_t) (iFu)) * (kuiScaleHeight - 1 - fv) >> kuiScaleBitWidth) * b; | ||
| 109 | x += (((uint32_t) (kuiScaleWidth - 1 - iFu)) * (fv) >> kuiScaleBitWidth) * c; | ||
| 110 | x += (((uint32_t) (iFu)) * (fv) >> kuiScaleBitWidth) * d; | ||
| 111 | x >>= (kuiScaleBitHeight - 1); | ||
| 112 | x += 1; | ||
| 113 | x >>= 1; | ||
| 114 | //x = (((__int64)(SCALE_BIG - 1 - iFu))*(SCALE_BIG - 1 - fv)*a + ((__int64)iFu)*(SCALE_BIG - 1 -fv)*b + ((__int64)(SCALE_BIG - 1 -iFu))*fv*c + | ||
| 115 | // ((__int64)iFu)*fv*d + (1 << (2*SCALE_BIT_BIG-1)) ) >> (2*SCALE_BIT_BIG); | ||
| 116 | x = WELS_CLAMP (x, 0, 255); | ||
| 117 | *pByDst++ = (uint8_t)x; | ||
| 118 | |||
| 119 | iXInverse += fScalex; | ||
| 120 | } | ||
| 121 | *pByDst = * (pBySrc + (iXInverse >> kuiScaleBitWidth)); | ||
| 122 | pByLineDst += kiDstStride; | ||
| 123 | iYInverse += fScaley; | ||
| 124 | } | ||
| 125 | |||
| 126 | // last row special | ||
| 127 | { | ||
| 128 | int32_t iYy = iYInverse >> kuiScaleBitHeight; | ||
| 129 | uint8_t* pBySrc = pSrc + iYy * kiSrcStride; | ||
| 130 | |||
| 131 | pByDst = pByLineDst; | ||
| 132 | iXInverse = 1 << (kuiScaleBitWidth - 1); | ||
| 133 | for (int32_t j = 0; j < kiDstWidth; j++) { | ||
| 134 | int32_t iXx = iXInverse >> kuiScaleBitWidth; | ||
| 135 | *pByDst++ = * (pBySrc + iXx); | ||
| 136 | |||
| 137 | iXInverse += fScalex; | ||
| 138 | } | ||
| 139 | } | ||
| 140 | } | ||
| 141 | |||
| 142 | void GeneralBilinearAccurateDownsampler_c (uint8_t* pDst, const int32_t kiDstStride, const int32_t kiDstWidth, | ||
| 143 | const int32_t kiDstHeight, | ||
| 144 | uint8_t* pSrc, const int32_t kiSrcStride, const int32_t kiSrcWidth, const int32_t kiSrcHeight) { | ||
| 145 | const int32_t kiScaleBit = 15; | ||
| 146 | const int32_t kiScale = (1 << kiScaleBit); | ||
| 147 | int32_t iScalex = (int32_t) ((float_t)kiSrcWidth / (float_t)kiDstWidth * kiScale); | ||
| 148 | int32_t iScaley = (int32_t) ((float_t)kiSrcHeight / (float_t)kiDstHeight * kiScale); | ||
| 149 | int64_t x; | ||
| 150 | int32_t iYInverse, iXInverse; | ||
| 151 | |||
| 152 | uint8_t* pByDst = pDst; | ||
| 153 | uint8_t* pByLineDst = pDst; | ||
| 154 | |||
| 155 | iYInverse = 1 << (kiScaleBit - 1); | ||
| 156 | for (int32_t i = 0; i < kiDstHeight - 1; i++) { | ||
| 157 | int32_t iYy = iYInverse >> kiScaleBit; | ||
| 158 | int32_t iFv = iYInverse & (kiScale - 1); | ||
| 159 | |||
| 160 | uint8_t* pBySrc = pSrc + iYy * kiSrcStride; | ||
| 161 | |||
| 162 | pByDst = pByLineDst; | ||
| 163 | iXInverse = 1 << (kiScaleBit - 1); | ||
| 164 | for (int32_t j = 0; j < kiDstWidth - 1; j++) { | ||
| 165 | int32_t iXx = iXInverse >> kiScaleBit; | ||
| 166 | int32_t iFu = iXInverse & (kiScale - 1); | ||
| 167 | |||
| 168 | uint8_t* pByCurrent = pBySrc + iXx; | ||
| 169 | uint8_t a, b, c, d; | ||
| 170 | |||
| 171 | a = *pByCurrent; | ||
| 172 | b = * (pByCurrent + 1); | ||
| 173 | c = * (pByCurrent + kiSrcStride); | ||
| 174 | d = * (pByCurrent + kiSrcStride + 1); | ||
| 175 | |||
| 176 | x = (((int64_t) (kiScale - 1 - iFu)) * (kiScale - 1 - iFv) * a + ((int64_t)iFu) * (kiScale - 1 - iFv) * b + ((int64_t) ( | ||
| 177 | kiScale - 1 - iFu)) * iFv * c + | ||
| 178 | ((int64_t)iFu) * iFv * d + (int64_t) (1 << (2 * kiScaleBit - 1))) >> (2 * kiScaleBit); | ||
| 179 | x = WELS_CLAMP (x, 0, 255); | ||
| 180 | *pByDst++ = (uint8_t)x; | ||
| 181 | |||
| 182 | iXInverse += iScalex; | ||
| 183 | } | ||
| 184 | *pByDst = * (pBySrc + (iXInverse >> kiScaleBit)); | ||
| 185 | pByLineDst += kiDstStride; | ||
| 186 | iYInverse += iScaley; | ||
| 187 | } | ||
| 188 | |||
| 189 | // last row special | ||
| 190 | { | ||
| 191 | int32_t iYy = iYInverse >> kiScaleBit; | ||
| 192 | uint8_t* pBySrc = pSrc + iYy * kiSrcStride; | ||
| 193 | |||
| 194 | pByDst = pByLineDst; | ||
| 195 | iXInverse = 1 << (kiScaleBit - 1); | ||
| 196 | for (int32_t j = 0; j < kiDstWidth; j++) { | ||
| 197 | int32_t iXx = iXInverse >> kiScaleBit; | ||
| 198 | *pByDst++ = * (pBySrc + iXx); | ||
| 199 | |||
| 200 | iXInverse += iScalex; | ||
| 201 | } | ||
| 202 | } | ||
| 203 | } | ||
| 204 | |||
| 205 | |||
| 206 | #ifdef X86_ASM | ||
| 207 | //void GeneralBilinearFastDownsamplerWrap_sse2 (uint8_t* pDst, const int32_t kiDstStride, const int32_t kiDstWidth, | ||
| 208 | // const int32_t kiDstHeight, | ||
| 209 | // uint8_t* pSrc, const int32_t kiSrcStride, const int32_t kiSrcWidth, const int32_t kiSrcHeight) { | ||
| 210 | // const int32_t kiScaleBitWidth = 16, kiScaleBitHeight = 15; | ||
| 211 | // const uint32_t kuiScaleWidth = (1 << kiScaleBitWidth), kuiScaleHeight = (1 << kiScaleBitHeight); | ||
| 212 | // | ||
| 213 | // uint32_t uiScalex = (uint32_t) ((float_t)kiSrcWidth / (float_t)kiDstWidth * kuiScaleWidth); | ||
| 214 | // uint32_t uiScaley = (uint32_t) ((float_t)kiSrcHeight / (float_t)kiDstHeight * kuiScaleHeight); | ||
| 215 | // | ||
| 216 | // GeneralBilinearFastDownsampler_sse2 (pDst, kiDstStride, kiDstWidth, kiDstHeight, | ||
| 217 | // pSrc, kiSrcStride, kiSrcWidth, kiSrcHeight, uiScalex, uiScaley); | ||
| 218 | //} | ||
| 219 | // | ||
| 220 | //void GeneralBilinearAccurateDownsamplerWrap_sse2 (uint8_t* pDst, const int32_t kiDstStride, const int32_t kiDstWidth, | ||
| 221 | // const int32_t kiDstHeight, | ||
| 222 | // uint8_t* pSrc, const int32_t kiSrcStride, const int32_t kiSrcWidth, const int32_t kiSrcHeight) { | ||
| 223 | // const int32_t kiScaleBit = 15; | ||
| 224 | // const uint32_t kuiScale = (1 << kiScaleBit); | ||
| 225 | // | ||
| 226 | // uint32_t uiScalex = (uint32_t) ((float_t)kiSrcWidth / (float_t)kiDstWidth * kuiScale); | ||
| 227 | // uint32_t uiScaley = (uint32_t) ((float_t)kiSrcHeight / (float_t)kiDstHeight * kuiScale); | ||
| 228 | // | ||
| 229 | // GeneralBilinearAccurateDownsampler_sse2 (pDst, kiDstStride, kiDstWidth, kiDstHeight, | ||
| 230 | // pSrc, kiSrcStride, kiSrcWidth, kiSrcHeight, uiScalex, uiScaley); | ||
| 231 | //} | ||
| 232 | #endif //X86_ASM | ||
| 233 | |||
| 234 | WELSVP_NAMESPACE_END | ||