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
19 #include "mp4dec_lib.h"
20
21 #ifdef PV_ANNEX_IJKT_SUPPORT
22 #include "motion_comp.h"
23 #include "mbtype_mode.h"
24 const static int STRENGTH_tab[] = {0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 5, 5, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 12};
25 #endif
26
27
28
29 #ifdef PV_ANNEX_IJKT_SUPPORT
H263_Deblock(uint8 * rec,int width,int height,int16 * QP_store,uint8 * mode,int chr,int annex_T)30 void H263_Deblock(uint8 *rec,
31 int width,
32 int height,
33 int16 *QP_store,
34 uint8 *mode,
35 int chr, int annex_T)
36 {
37 /*----------------------------------------------------------------------------
38 ; Define all local variables
39 ----------------------------------------------------------------------------*/
40 int i, j, k;
41 uint8 *rec_y;
42 int tmpvar;
43 int mbnum, strength, A_D, d1_2, d1, d2, A, B, C, D, b_size;
44 int d, offset, nMBPerRow, nMBPerCol, width2 = (width << 1);
45 /* MAKE SURE I-VOP INTRA MACROBLOCKS ARE SET TO NON-SKIPPED MODE*/
46 mbnum = 0;
47
48 if (chr)
49 {
50 nMBPerRow = width >> 3;
51 nMBPerCol = height >> 3;
52 b_size = 8;
53 }
54 else
55 {
56 nMBPerRow = width >> 4;
57 nMBPerCol = height >> 4;
58 b_size = 16;
59 }
60
61
62 /********************************* VERTICAL FILTERING ****************************/
63 /* vertical filtering of mid sections no need to check neighboring QP's etc */
64 if (!chr)
65 {
66 rec_y = rec + (width << 3);
67 for (i = 0; i < (height >> 4); i++)
68 {
69 for (j = 0; j < (width >> 4); j++)
70 {
71 if (mode[mbnum] != MODE_SKIPPED)
72 {
73 k = 16;
74 strength = STRENGTH_tab[QP_store[mbnum]];
75 while (k--)
76 {
77 A = *(rec_y - width2);
78 D = *(rec_y + width);
79 A_D = A - D;
80 C = *rec_y;
81 B = *(rec_y - width);
82 d = (((C - B) << 2) + A_D);
83
84 if (d < 0)
85 {
86 d1 = -(-d >> 3);
87 if (d1 < -(strength << 1))
88 {
89 d1 = 0;
90 }
91 else if (d1 < -strength)
92 {
93 d1 = -d1 - (strength << 1);
94 }
95 d1_2 = -d1 >> 1;
96 }
97 else
98 {
99 d1 = d >> 3;
100 if (d1 > (strength << 1))
101 {
102 d1 = 0;
103 }
104 else if (d1 > strength)
105 {
106 d1 = (strength << 1) - d1;
107 }
108 d1_2 = d1 >> 1;
109 }
110
111 if (A_D < 0)
112 {
113 d2 = -(-A_D >> 2);
114 if (d2 < -d1_2)
115 {
116 d2 = -d1_2;
117 }
118 }
119 else
120 {
121 d2 = A_D >> 2;
122 if (d2 > d1_2)
123 {
124 d2 = d1_2;
125 }
126 }
127
128 *(rec_y - width2) = A - d2;
129 tmpvar = B + d1;
130 CLIP_RESULT(tmpvar)
131 *(rec_y - width) = tmpvar;
132 tmpvar = C - d1;
133 CLIP_RESULT(tmpvar)
134 *rec_y = tmpvar;
135 *(rec_y + width) = D + d2;
136 rec_y++;
137 }
138 }
139 else
140 {
141 rec_y += b_size;
142 }
143 mbnum++;
144 }
145 rec_y += (15 * width);
146
147 }
148 }
149
150 /* VERTICAL boundary blocks */
151
152
153 rec_y = rec + width * b_size;
154
155 mbnum = nMBPerRow;
156 for (i = 0; i < nMBPerCol - 1; i++)
157 {
158 for (j = 0; j < nMBPerRow; j++)
159 {
160 if (mode[mbnum] != MODE_SKIPPED || mode[mbnum - nMBPerRow] != MODE_SKIPPED)
161 {
162 k = b_size;
163 if (mode[mbnum] != MODE_SKIPPED)
164 {
165 strength = STRENGTH_tab[(annex_T ? MQ_chroma_QP_table[QP_store[mbnum]] : QP_store[mbnum])];
166 }
167 else
168 {
169 strength = STRENGTH_tab[(annex_T ? MQ_chroma_QP_table[QP_store[mbnum - nMBPerRow]] : QP_store[mbnum - nMBPerRow])];
170 }
171
172 while (k--)
173 {
174 A = *(rec_y - width2);
175 D = *(rec_y + width);
176 A_D = A - D;
177 C = *rec_y;
178 B = *(rec_y - width);
179 d = (((C - B) << 2) + A_D);
180
181 if (d < 0)
182 {
183 d1 = -(-d >> 3);
184 if (d1 < -(strength << 1))
185 {
186 d1 = 0;
187 }
188 else if (d1 < -strength)
189 {
190 d1 = -d1 - (strength << 1);
191 }
192 d1_2 = -d1 >> 1;
193 }
194 else
195 {
196 d1 = d >> 3;
197 if (d1 > (strength << 1))
198 {
199 d1 = 0;
200 }
201 else if (d1 > strength)
202 {
203 d1 = (strength << 1) - d1;
204 }
205 d1_2 = d1 >> 1;
206 }
207
208 if (A_D < 0)
209 {
210 d2 = -(-A_D >> 2);
211 if (d2 < -d1_2)
212 {
213 d2 = -d1_2;
214 }
215 }
216 else
217 {
218 d2 = A_D >> 2;
219 if (d2 > d1_2)
220 {
221 d2 = d1_2;
222 }
223 }
224
225 *(rec_y - width2) = A - d2;
226 tmpvar = B + d1;
227 CLIP_RESULT(tmpvar)
228 *(rec_y - width) = tmpvar;
229 tmpvar = C - d1;
230 CLIP_RESULT(tmpvar)
231 *rec_y = tmpvar;
232 *(rec_y + width) = D + d2;
233 rec_y++;
234 }
235 }
236 else
237 {
238 rec_y += b_size;
239 }
240 mbnum++;
241 }
242 rec_y += ((b_size - 1) * width);
243
244 }
245
246
247 /***************************HORIZONTAL FILTERING ********************************************/
248 mbnum = 0;
249 /* HORIZONTAL INNER */
250 if (!chr)
251 {
252 rec_y = rec + 8;
253 offset = width * b_size - b_size;
254
255 for (i = 0; i < nMBPerCol; i++)
256 {
257 for (j = 0; j < nMBPerRow; j++)
258 {
259 if (mode[mbnum] != MODE_SKIPPED)
260 {
261 k = 16;
262 strength = STRENGTH_tab[QP_store[mbnum]];
263 while (k--)
264 {
265 A = *(rec_y - 2);
266 D = *(rec_y + 1);
267 A_D = A - D;
268 C = *rec_y;
269 B = *(rec_y - 1);
270 d = (((C - B) << 2) + A_D);
271
272 if (d < 0)
273 {
274 d1 = -(-d >> 3);
275 if (d1 < -(strength << 1))
276 {
277 d1 = 0;
278 }
279 else if (d1 < -strength)
280 {
281 d1 = -d1 - (strength << 1);
282 }
283 d1_2 = -d1 >> 1;
284 }
285 else
286 {
287 d1 = d >> 3;
288 if (d1 > (strength << 1))
289 {
290 d1 = 0;
291 }
292 else if (d1 > strength)
293 {
294 d1 = (strength << 1) - d1;
295 }
296 d1_2 = d1 >> 1;
297 }
298
299 if (A_D < 0)
300 {
301 d2 = -(-A_D >> 2);
302 if (d2 < -d1_2)
303 {
304 d2 = -d1_2;
305 }
306 }
307 else
308 {
309 d2 = A_D >> 2;
310 if (d2 > d1_2)
311 {
312 d2 = d1_2;
313 }
314 }
315
316 *(rec_y - 2) = A - d2;
317 tmpvar = B + d1;
318 CLIP_RESULT(tmpvar)
319 *(rec_y - 1) = tmpvar;
320 tmpvar = C - d1;
321 CLIP_RESULT(tmpvar)
322 *rec_y = tmpvar;
323 *(rec_y + 1) = D + d2;
324 rec_y += width;
325 }
326 rec_y -= offset;
327 }
328 else
329 {
330 rec_y += b_size;
331 }
332 mbnum++;
333 }
334 rec_y += (15 * width);
335
336 }
337 }
338
339
340
341 /* HORIZONTAL EDGE */
342 rec_y = rec + b_size;
343 offset = width * b_size - b_size;
344 mbnum = 1;
345 for (i = 0; i < nMBPerCol; i++)
346 {
347 for (j = 0; j < nMBPerRow - 1; j++)
348 {
349 if (mode[mbnum] != MODE_SKIPPED || mode[mbnum-1] != MODE_SKIPPED)
350 {
351 k = b_size;
352 if (mode[mbnum] != MODE_SKIPPED)
353 {
354 strength = STRENGTH_tab[(annex_T ? MQ_chroma_QP_table[QP_store[mbnum]] : QP_store[mbnum])];
355 }
356 else
357 {
358 strength = STRENGTH_tab[(annex_T ? MQ_chroma_QP_table[QP_store[mbnum - 1]] : QP_store[mbnum - 1])];
359 }
360
361 while (k--)
362 {
363 A = *(rec_y - 2);
364 D = *(rec_y + 1);
365 A_D = A - D;
366 C = *rec_y;
367 B = *(rec_y - 1);
368 d = (((C - B) << 2) + A_D);
369
370 if (d < 0)
371 {
372 d1 = -(-d >> 3);
373 if (d1 < -(strength << 1))
374 {
375 d1 = 0;
376 }
377 else if (d1 < -strength)
378 {
379 d1 = -d1 - (strength << 1);
380 }
381 d1_2 = -d1 >> 1;
382 }
383 else
384 {
385 d1 = d >> 3;
386 if (d1 > (strength << 1))
387 {
388 d1 = 0;
389 }
390 else if (d1 > strength)
391 {
392 d1 = (strength << 1) - d1;
393 }
394 d1_2 = d1 >> 1;
395 }
396
397 if (A_D < 0)
398 {
399 d2 = -(-A_D >> 2);
400 if (d2 < -d1_2)
401 {
402 d2 = -d1_2;
403 }
404 }
405 else
406 {
407 d2 = A_D >> 2;
408 if (d2 > d1_2)
409 {
410 d2 = d1_2;
411 }
412 }
413
414 *(rec_y - 2) = A - d2;
415 tmpvar = B + d1;
416 CLIP_RESULT(tmpvar)
417 *(rec_y - 1) = tmpvar;
418 tmpvar = C - d1;
419 CLIP_RESULT(tmpvar)
420 *rec_y = tmpvar;
421 *(rec_y + 1) = D + d2;
422 rec_y += width;
423 }
424 rec_y -= offset;
425 }
426 else
427 {
428 rec_y += b_size;
429 }
430 mbnum++;
431 }
432 rec_y += ((width * (b_size - 1)) + b_size);
433 mbnum++;
434 }
435
436 return;
437 }
438 #endif
439
440