History

resolve conflict

volvet committed 12 years ago

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

Showing the changes to codec/processing/src/denoise (3 of 124 files). Show all

Unified · Split

3 files
  1. codec/processing/src/denoise/denoise.cpp +124 −0
  2. codec/processing/src/denoise/denoise.h +111 −0
  3. codec/processing/src/denoise/denoise_filter.cpp +127 −0
codec/processing/src/denoise/denoise.cpp+124−0
@@ -0,0 +1,124 @@
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 "denoise.h"
34+#include "../common/cpu.h"
35+
36+WELSVP_NAMESPACE_BEGIN
37+
38+#define CALC_BI_STRIDE(iWidth, iBitcount) ((((iWidth) * (iBitcount) + 31) & ~31) >> 3)
39+
40+///////////////////////////////////////////////////////////////////////////////////////////////////////////////
41+
42+CDenoiser::CDenoiser (int32_t iCpuFlag) {
43+ m_CPUFlag = iCpuFlag;
44+ m_eMethod = METHOD_DENOISE;
45+ WelsMemset (&m_pfDenoise, 0, sizeof (m_pfDenoise));
46+
47+ m_uiSpaceRadius = DENOISE_GRAY_RADIUS;
48+ m_fSigmaGrey = DENOISE_GRAY_SIGMA;
49+ m_uiType = DENOISE_ALL_COMPONENT;
50+ InitDenoiseFunc (m_pfDenoise, m_CPUFlag);
51+}
52+
53+CDenoiser::~CDenoiser() {
54+}
55+
56+void CDenoiser::InitDenoiseFunc (SDenoiseFuncs& denoiser, int32_t iCpuFlag) {
57+ denoiser.pfBilateralLumaFilter8 = BilateralLumaFilter8_c;
58+ denoiser.pfWaverageChromaFilter8 = WaverageChromaFilter8_c;
59+#if defined(X86_ASM)
60+ if (iCpuFlag & WELS_CPU_SSE2) {
61+ denoiser.pfBilateralLumaFilter8 = BilateralLumaFilter8_sse2;
62+ denoiser.pfWaverageChromaFilter8 = WaverageChromaFilter8_sse2;
63+ }
64+#endif
65+}
66+
67+EResult CDenoiser::Process (int32_t iType, SPixMap* pSrc, SPixMap* dst) {
68+ uint8_t* pSrcY = (uint8_t*)pSrc->pPixel[0];
69+ uint8_t* pSrcU = (uint8_t*)pSrc->pPixel[1];
70+ uint8_t* pSrcV = (uint8_t*)pSrc->pPixel[2];
71+ if (pSrcY == NULL || pSrcU == NULL || pSrcV == NULL) {
72+ return RET_INVALIDPARAM;
73+ }
74+
75+ int32_t iWidthY = pSrc->sRect.iRectWidth;
76+ int32_t iHeightY = pSrc->sRect.iRectHeight;
77+ int32_t iWidthUV = iWidthY >> 1;
78+ int32_t iHeightUV = iHeightY >> 1;
79+
80+ if (m_uiType & DENOISE_Y_COMPONENT)
81+ BilateralDenoiseLuma (pSrcY, iWidthY, iHeightY, pSrc->iStride[0]);
82+
83+ if (m_uiType & DENOISE_U_COMPONENT)
84+ WaverageDenoiseChroma (pSrcU, iWidthUV, iHeightUV, pSrc->iStride[1]);
85+
86+ if (m_uiType & DENOISE_V_COMPONENT)
87+ WaverageDenoiseChroma (pSrcV, iWidthUV, iHeightUV, pSrc->iStride[2]);
88+
89+ return RET_SUCCESS;
90+}
91+
92+void CDenoiser::BilateralDenoiseLuma (uint8_t* pSrcY, int32_t iWidth, int32_t iHeight, int32_t iStride) {
93+ int32_t w;
94+
95+ pSrcY = pSrcY + m_uiSpaceRadius * iStride;
96+ for (int32_t h = m_uiSpaceRadius; h < iHeight - m_uiSpaceRadius; h++) {
97+ for (w = m_uiSpaceRadius; w < iWidth - m_uiSpaceRadius - TAIL_OF_LINE8; w += 8) {
98+ m_pfDenoise.pfBilateralLumaFilter8 (pSrcY + w, iStride);
99+ }
100+ for (w = w + TAIL_OF_LINE8; w < iWidth - m_uiSpaceRadius; w++) {
101+ Gauss3x3Filter (pSrcY + w, iStride);
102+ }
103+ pSrcY += iStride;
104+ }
105+}
106+
107+void CDenoiser::WaverageDenoiseChroma (uint8_t* pSrcUV, int32_t iWidth, int32_t iHeight, int32_t iStride) {
108+ int32_t w;
109+
110+ pSrcUV = pSrcUV + UV_WINDOWS_RADIUS * iStride;
111+ for (int32_t h = UV_WINDOWS_RADIUS; h < iHeight - UV_WINDOWS_RADIUS; h++) {
112+ for (w = UV_WINDOWS_RADIUS; w < iWidth - UV_WINDOWS_RADIUS - TAIL_OF_LINE8; w += 8) {
113+ m_pfDenoise.pfWaverageChromaFilter8 (pSrcUV + w, iStride);
114+ }
115+
116+ for (w = w + TAIL_OF_LINE8; w < iWidth - UV_WINDOWS_RADIUS; w++) {
117+ Gauss3x3Filter (pSrcUV + w, iStride);
118+ }
119+ pSrcUV += iStride;
120+ }
121+}
122+
123+
124+WELSVP_NAMESPACE_END
codec/processing/src/denoise/denoise.h+111−0
@@ -0,0 +1,111 @@
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 : denoise.h
32+ *
33+ * \brief : denoise class of wels video processor class
34+ *
35+ * \date : 2011/03/15
36+ *
37+ * \description : 1. rewrite the package code of denoise class
38+ *
39+ *************************************************************************************
40+ */
41+
42+#ifndef WELSVP_DENOISE_H
43+#define WELSVP_DENOISE_H
44+
45+#include "../common/util.h"
46+#include "../common/memory.h"
47+#include "../common/WelsFrameWork.h"
48+#include "../../interface/IWelsVP.h"
49+
50+
51+#define DENOISE_GRAY_RADIUS (1)
52+#define DENOISE_GRAY_SIGMA (2)
53+
54+#define UV_WINDOWS_RADIUS (2)
55+#define TAIL_OF_LINE8 (7)
56+
57+#define DENOISE_Y_COMPONENT (1)
58+#define DENOISE_U_COMPONENT (2)
59+#define DENOISE_V_COMPONENT (4)
60+#define DENOISE_ALL_COMPONENT (7)
61+
62+
63+WELSVP_NAMESPACE_BEGIN
64+
65+void Gauss3x3Filter (uint8_t* pixels, int32_t stride);
66+
67+typedef void (DenoiseFilterFunc) (uint8_t* pixels, int32_t stride);
68+
69+typedef DenoiseFilterFunc* DenoiseFilterFuncPtr;
70+
71+DenoiseFilterFunc BilateralLumaFilter8_c;
72+DenoiseFilterFunc WaverageChromaFilter8_c;
73+
74+#ifdef X86_ASM
75+WELSVP_EXTERN_C_BEGIN
76+DenoiseFilterFunc BilateralLumaFilter8_sse2 ;
77+DenoiseFilterFunc WaverageChromaFilter8_sse2 ;
78+WELSVP_EXTERN_C_END
79+#endif
80+
81+typedef struct TagDenoiseFuncs {
82+ DenoiseFilterFuncPtr pfBilateralLumaFilter8;//on 8 samples
83+ DenoiseFilterFuncPtr pfWaverageChromaFilter8;//on 8 samples
84+} SDenoiseFuncs;
85+
86+class CDenoiser : public IStrategy {
87+ public:
88+ CDenoiser (int32_t iCpuFlag);
89+ ~CDenoiser();
90+
91+ EResult Process (int32_t iType, SPixMap* pSrc, SPixMap* dst);
92+
93+ private:
94+ void InitDenoiseFunc (SDenoiseFuncs& pf, int32_t cpu);
95+ void BilateralDenoiseLuma (uint8_t* p_y_data, int32_t width, int32_t height, int32_t stride);
96+ void WaverageDenoiseChroma (uint8_t* pSrcUV, int32_t width, int32_t height, int32_t stride);
97+
98+ private:
99+ float_t m_fSigmaGrey; //sigma for grey scale similarity, suggestion 2.5-3
100+ uint32_t m_uiFilterWindow; //filter window diameter
101+ uint16_t m_uiSpaceRadius; //filter windows radius: 1-3x3, 2-5x5,3-7x7. Larger size, slower speed
102+ uint16_t m_uiType; //do denoising on which component 1-Y, 2-U, 4-V; 7-YUV, 3-YU, 5-YV, 6-UV
103+ uint32_t* m_pGreyWeightTable; //weight table for grey scale
104+
105+ SDenoiseFuncs m_pfDenoise;
106+ int32_t m_CPUFlag;
107+};
108+
109+WELSVP_NAMESPACE_END
110+
111+#endif
codec/processing/src/denoise/denoise_filter.cpp+127−0
@@ -0,0 +1,127 @@
1+/*!
2+ * \copy
3+ * Copyright (c) 2010-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 svc_preprocess.h
32+ *
33+ * \brief svc denoising
34+ *
35+ * \date 4/1/2010 Created
36+ *
37+ */
38+
39+#include "denoise.h"
40+#include "../common/typedef.h"
41+
42+WELSVP_NAMESPACE_BEGIN
43+
44+void BilateralLumaFilter8_c (uint8_t* pSample, int32_t iStride) {
45+ int32_t nSum = 0, nTotWeight = 0;
46+ int32_t iCenterSample = *pSample;
47+ uint8_t* pCurLine = pSample - iStride - DENOISE_GRAY_RADIUS;
48+ int32_t x, y;
49+ int32_t iCurSample, iCurWeight, iGreyDiff;
50+ uint8_t aSample[8];
51+
52+ for (int32_t i = 0; i < 8; i++) {
53+ nSum = 0;
54+ nTotWeight = 0;
55+ iCenterSample = *pSample;
56+ pCurLine = pSample - iStride - DENOISE_GRAY_RADIUS;
57+ for (y = 0; y < 3; y++) {
58+ for (x = 0; x < 3; x++) {
59+ if (x == 1 && y == 1) continue; // except center point
60+ iCurSample = pCurLine[x];
61+ iCurWeight = WELS_ABS (iCurSample - iCenterSample);
62+ iGreyDiff = 32 - iCurWeight;
63+ if (iGreyDiff < 0) continue;
64+ else iCurWeight = (iGreyDiff * iGreyDiff) >> 5;
65+ nSum += iCurSample * iCurWeight;
66+ nTotWeight += iCurWeight;
67+ }
68+ pCurLine += iStride;
69+ }
70+ nTotWeight = 256 - nTotWeight;
71+ nSum += iCenterSample * nTotWeight;
72+ aSample[i] = nSum >> 8;
73+ pSample++;
74+ }
75+ WelsMemcpy (pSample - 8, aSample, 8);
76+}
77+
78+
79+/***************************************************************************
80+5x5 filter:
81+1 1 2 1 1
82+1 2 4 2 1
83+2 4 20 4 2
84+1 2 4 2 1
85+1 1 2 1 1
86+***************************************************************************/
87+#define SUM_LINE1(pSample) (pSample[0] +(pSample[1]) +(pSample[2]<<1) + pSample[3] + pSample[4])
88+#define SUM_LINE2(pSample) (pSample[0] +(pSample[1]<<1) +(pSample[2]<<2) +(pSample[3]<<1) +pSample[4])
89+#define SUM_LINE3(pSample) ((pSample[0]<<1) +(pSample[1]<<2) +(pSample[2]*20) +(pSample[3]<<2) +(pSample[4]<<1))
90+void WaverageChromaFilter8_c (uint8_t* pSample, int32_t iStride) {
91+ int32_t sum;
92+ uint8_t* pStartPixels = pSample - UV_WINDOWS_RADIUS * iStride - UV_WINDOWS_RADIUS;
93+ uint8_t* pCurLine1 = pStartPixels;
94+ uint8_t* pCurLine2 = pCurLine1 + iStride;
95+ uint8_t* pCurLine3 = pCurLine2 + iStride;
96+ uint8_t* pCurLine4 = pCurLine3 + iStride;
97+ uint8_t* pCurLine5 = pCurLine4 + iStride;
98+ uint8_t aSample[8];
99+
100+ for (int32_t i = 0; i < 8; i++) {
101+ sum = SUM_LINE1 ((pCurLine1 + i)) + SUM_LINE2 ((pCurLine2 + i)) + SUM_LINE3 ((pCurLine3 + i))
102+ + SUM_LINE2 ((pCurLine4 + i)) + SUM_LINE1 ((pCurLine5 + i));
103+ aSample[i] = (sum >> 6);
104+ pSample++;
105+ }
106+ WelsMemcpy (pSample - 8, aSample, 8);
107+}
108+
109+/***************************************************************************
110+edge of y/uv use a 3x3 Gauss filter, radius = 1:
111+1 2 1
112+2 4 2
113+1 2 1
114+***************************************************************************/
115+void Gauss3x3Filter (uint8_t* pSrc, int32_t iStride) {
116+ int32_t nSum = 0;
117+ uint8_t* pCurLine1 = pSrc - iStride - 1;
118+ uint8_t* pCurLine2 = pCurLine1 + iStride;
119+ uint8_t* pCurLine3 = pCurLine2 + iStride;
120+
121+ nSum = pCurLine1[0] + (pCurLine1[1] << 1) + pCurLine1[2] +
122+ (pCurLine2[0] << 1) + (pCurLine2[1] << 2) + (pCurLine2[2] << 1) +
123+ pCurLine3[0] + (pCurLine3[1] << 1) + pCurLine3[2];
124+ *pSrc = nSum >> 4;
125+}
126+
127+WELSVP_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