History

resolve conflict

volvet committed 12 years ago

Commit ec84f4b1 parent 3958118124 files · +15352 −15696Browse files

Showing the changes to codec/processing/src/downsample/downsample.cpp (1 of 124 files). Show all

Unified · Split

codec/processing/src/downsample/downsample.cpp+135−0
@@ -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
36WELSVP_NAMESPACE_BEGIN
37
38
39///////////////////////////////////////////////////////////////////////////////////////////////////////////////
40
41CDownsampling::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
48CDownsampling::~CDownsampling() {
49}
50
51void 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
80EResult 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
121int32_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
135WELSVP_NAMESPACE_END

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t