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 #include "mp4dec_lib.h"
19 #include "post_proc.h"
20
21 #ifdef PV_POSTPROC_ON
22
Deringing_Luma(uint8 * Rec_Y,int width,int height,int16 * QP_store,int Combined,uint8 * pp_mod)23 void Deringing_Luma(
24 uint8 *Rec_Y,
25 int width,
26 int height,
27 int16 *QP_store,
28 int Combined,
29 uint8 *pp_mod)
30 {
31 OSCL_UNUSED_ARG(Combined);
32 /*----------------------------------------------------------------------------
33 ; Define all local variables
34 ----------------------------------------------------------------------------*/
35 int thres[4], range[4], max_range_blk, max_thres_blk;
36 int MB_V, MB_H, BLK_V, BLK_H;
37 int v_blk, h_blk;
38 int max_diff;
39 int max_blk, min_blk;
40 int v0, h0;
41 uint8 *ptr;
42 int thr, blks, incr;
43 int mb_indx, blk_indx;
44
45 /*----------------------------------------------------------------------------
46 ; Function body here
47 ----------------------------------------------------------------------------*/
48 incr = width - BLKSIZE;
49
50 /* Dering the first line of macro blocks */
51 for (MB_H = 0; MB_H < width; MB_H += MBSIZE)
52 {
53 max_diff = (QP_store[(MB_H)>>4] >> 2) + 4;
54
55 /* threshold determination */
56 max_range_blk = max_thres_blk = 0;
57 blks = 0;
58
59 for (BLK_V = 0; BLK_V < MBSIZE; BLK_V += BLKSIZE)
60 {
61 for (BLK_H = 0; BLK_H < MBSIZE; BLK_H += BLKSIZE)
62 {
63 ptr = &Rec_Y[(int32)(BLK_V) * width + MB_H + BLK_H];
64 FindMaxMin(ptr, &min_blk, &max_blk, incr);
65
66 thres[blks] = (max_blk + min_blk + 1) >> 1;
67 range[blks] = max_blk - min_blk;
68
69 if (range[blks] >= max_range_blk)
70 {
71 max_range_blk = range[blks];
72 max_thres_blk = thres[blks];
73 }
74 blks++;
75 }
76 }
77
78 blks = 0;
79 for (v_blk = 0; v_blk < MBSIZE; v_blk += BLKSIZE)
80 {
81 v0 = ((v_blk - 1) >= 1) ? (v_blk - 1) : 1;
82 for (h_blk = MB_H; h_blk < MB_H + MBSIZE; h_blk += BLKSIZE)
83 {
84 h0 = ((h_blk - 1) >= 1) ? (h_blk - 1) : 1;
85
86 /* threshold rearrangement for flat region adjacent to non-flat region */
87 if (range[blks]<32 && max_range_blk >= 64)
88 thres[blks] = max_thres_blk;
89
90 /* threshold rearrangement for deblocking
91 (blockiness annoying at DC dominant region) */
92 if (max_range_blk >= 16)
93 {
94 /* adaptive smoothing */
95 thr = thres[blks];
96
97 AdaptiveSmooth_NoMMX(Rec_Y, v0, h0, v_blk, h_blk,
98 thr, width, max_diff);
99 }
100 blks++;
101 } /* block level (Luminance) */
102 }
103 } /* macroblock level */
104
105
106 /* Do the rest of the macro-block-lines */
107 for (MB_V = MBSIZE; MB_V < height; MB_V += MBSIZE)
108 {
109 /* First macro-block */
110 max_diff = (QP_store[((((int32)MB_V*width)>>4))>>4] >> 2) + 4;
111 /* threshold determination */
112 max_range_blk = max_thres_blk = 0;
113 blks = 0;
114 for (BLK_V = 0; BLK_V < MBSIZE; BLK_V += BLKSIZE)
115 {
116 for (BLK_H = 0; BLK_H < MBSIZE; BLK_H += BLKSIZE)
117 {
118 ptr = &Rec_Y[(int32)(MB_V + BLK_V) * width + BLK_H];
119 FindMaxMin(ptr, &min_blk, &max_blk, incr);
120 thres[blks] = (max_blk + min_blk + 1) >> 1;
121 range[blks] = max_blk - min_blk;
122
123 if (range[blks] >= max_range_blk)
124 {
125 max_range_blk = range[blks];
126 max_thres_blk = thres[blks];
127 }
128 blks++;
129 }
130 }
131
132 blks = 0;
133 for (v_blk = MB_V; v_blk < MB_V + MBSIZE; v_blk += BLKSIZE)
134 {
135 v0 = v_blk - 1;
136 for (h_blk = 0; h_blk < MBSIZE; h_blk += BLKSIZE)
137 {
138 h0 = ((h_blk - 1) >= 1) ? (h_blk - 1) : 1;
139
140 /* threshold rearrangement for flat region adjacent to non-flat region */
141 if (range[blks]<32 && max_range_blk >= 64)
142 thres[blks] = max_thres_blk;
143
144 /* threshold rearrangement for deblocking
145 (blockiness annoying at DC dominant region) */
146 if (max_range_blk >= 16)
147 {
148 /* adaptive smoothing */
149 thr = thres[blks];
150
151 AdaptiveSmooth_NoMMX(Rec_Y, v0, h0, v_blk, h_blk,
152 thr, width, max_diff);
153 }
154 blks++;
155 }
156 } /* block level (Luminance) */
157
158 /* Rest of the macro-blocks */
159 for (MB_H = MBSIZE; MB_H < width; MB_H += MBSIZE)
160 {
161 max_diff = (QP_store[((((int32)MB_V*width)>>4)+MB_H)>>4] >> 2) + 4;
162
163 /* threshold determination */
164 max_range_blk = max_thres_blk = 0;
165 blks = 0;
166
167 mb_indx = (MB_V / 8) * (width / 8) + MB_H / 8;
168 for (BLK_V = 0; BLK_V < MBSIZE; BLK_V += BLKSIZE)
169 {
170 for (BLK_H = 0; BLK_H < MBSIZE; BLK_H += BLKSIZE)
171 {
172 blk_indx = mb_indx + (BLK_V / 8) * width / 8 + BLK_H / 8;
173 /* Update based on pp_mod only */
174 if ((pp_mod[blk_indx]&0x4) != 0)
175 {
176 ptr = &Rec_Y[(int32)(MB_V + BLK_V) * width + MB_H + BLK_H];
177 FindMaxMin(ptr, &min_blk, &max_blk, incr);
178 thres[blks] = (max_blk + min_blk + 1) >> 1;
179 range[blks] = max_blk - min_blk;
180
181 if (range[blks] >= max_range_blk)
182 {
183 max_range_blk = range[blks];
184 max_thres_blk = thres[blks];
185 }
186 }
187 blks++;
188 }
189 }
190
191 blks = 0;
192 for (v_blk = MB_V; v_blk < MB_V + MBSIZE; v_blk += BLKSIZE)
193 {
194 v0 = v_blk - 1;
195 mb_indx = (v_blk / 8) * (width / 8);
196 for (h_blk = MB_H; h_blk < MB_H + MBSIZE; h_blk += BLKSIZE)
197 {
198 h0 = h_blk - 1;
199 blk_indx = mb_indx + h_blk / 8;
200 if ((pp_mod[blk_indx]&0x4) != 0)
201 {
202 /* threshold rearrangement for flat region adjacent to non-flat region */
203 if (range[blks]<32 && max_range_blk >= 64)
204 thres[blks] = max_thres_blk;
205
206 /* threshold rearrangement for deblocking
207 (blockiness annoying at DC dominant region) */
208 if (max_range_blk >= 16)
209 {
210 /* adaptive smoothing */
211 thr = thres[blks];
212 #ifdef NoMMX
213 AdaptiveSmooth_NoMMX(Rec_Y, v0, h0, v_blk, h_blk,
214 thr, width, max_diff);
215 #else
216 DeringAdaptiveSmoothMMX(&Rec_Y[v0*width+h0],
217 width, thr, max_diff);
218 #endif
219 }
220 }
221 blks++;
222 }
223 } /* block level (Luminance) */
224 } /* macroblock level */
225 } /* macroblock level */
226
227 /*----------------------------------------------------------------------------
228 ; Return nothing or data or data pointer
229 ----------------------------------------------------------------------------*/
230 return;
231 }
232 #endif
233