178e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar/* 278e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * Copyright (C) 2007-2008 ARM Limited 378e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * 478e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * Licensed under the Apache License, Version 2.0 (the "License"); 578e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * you may not use this file except in compliance with the License. 678e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * You may obtain a copy of the License at 778e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * 878e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * http://www.apache.org/licenses/LICENSE-2.0 978e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * 1078e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * Unless required by applicable law or agreed to in writing, software 1178e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * distributed under the License is distributed on an "AS IS" BASIS, 1278e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1378e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * See the License for the specific language governing permissions and 1478e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * limitations under the License. 1578e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar * 1678e52bfac041d71ce53b5b13c2abf78af742b09dLajos Molnar */ 170c1bc742181ded4930842b46e9507372f0b1b963James Dong/* ---------------------------------------------------------------- 180c1bc742181ded4930842b46e9507372f0b1b963James Dong * 190c1bc742181ded4930842b46e9507372f0b1b963James Dong * 200c1bc742181ded4930842b46e9507372f0b1b963James Dong * File Name: armVCM4P10_DeBlockPixel.c 210c1bc742181ded4930842b46e9507372f0b1b963James Dong * OpenMAX DL: v1.0.2 220c1bc742181ded4930842b46e9507372f0b1b963James Dong * Revision: 9641 230c1bc742181ded4930842b46e9507372f0b1b963James Dong * Date: Thursday, February 7, 2008 240c1bc742181ded4930842b46e9507372f0b1b963James Dong * 250c1bc742181ded4930842b46e9507372f0b1b963James Dong * 260c1bc742181ded4930842b46e9507372f0b1b963James Dong * 270c1bc742181ded4930842b46e9507372f0b1b963James Dong * 280c1bc742181ded4930842b46e9507372f0b1b963James Dong * H.264 luma deblock module 290c1bc742181ded4930842b46e9507372f0b1b963James Dong * 300c1bc742181ded4930842b46e9507372f0b1b963James Dong */ 310c1bc742181ded4930842b46e9507372f0b1b963James Dong 320c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifdef DEBUG_ARMVCM4P10_DEBLOCKPIXEL 330c1bc742181ded4930842b46e9507372f0b1b963James Dong#undef DEBUG_ON 340c1bc742181ded4930842b46e9507372f0b1b963James Dong#define DEBUG_ON 350c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif /* DEBUG_ARMVCM4P10_DEBLOCKPIXEL */ 360c1bc742181ded4930842b46e9507372f0b1b963James Dong 370c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "omxtypes.h" 380c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armOMX.h" 390c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "omxVC.h" 400c1bc742181ded4930842b46e9507372f0b1b963James Dong 410c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armCOMM.h" 420c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armVC.h" 430c1bc742181ded4930842b46e9507372f0b1b963James Dong 440c1bc742181ded4930842b46e9507372f0b1b963James Dong/* 450c1bc742181ded4930842b46e9507372f0b1b963James Dong * Description 460c1bc742181ded4930842b46e9507372f0b1b963James Dong * Deblock one boundary pixel 470c1bc742181ded4930842b46e9507372f0b1b963James Dong * 480c1bc742181ded4930842b46e9507372f0b1b963James Dong * Parameters: 490c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] pQ0 Pointer to pixel q0 500c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] Step Step between pixels q0 and q1 510c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] tC0 Edge threshold value 520c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] alpha alpha threshold value 530c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] beta beta threshold value 540c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] bS deblocking strength 550c1bc742181ded4930842b46e9507372f0b1b963James Dong * [in] ChromaFlag True for chroma blocks 560c1bc742181ded4930842b46e9507372f0b1b963James Dong * [out] pQ0 Deblocked pixels 570c1bc742181ded4930842b46e9507372f0b1b963James Dong * 580c1bc742181ded4930842b46e9507372f0b1b963James Dong */ 590c1bc742181ded4930842b46e9507372f0b1b963James Dong 600c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid armVCM4P10_DeBlockPixel( 610c1bc742181ded4930842b46e9507372f0b1b963James Dong OMX_U8 *pQ0, /* pointer to the pixel q0 */ 620c1bc742181ded4930842b46e9507372f0b1b963James Dong int Step, /* step between pixels q0 and q1 */ 630c1bc742181ded4930842b46e9507372f0b1b963James Dong int tC0, /* edge threshold value */ 640c1bc742181ded4930842b46e9507372f0b1b963James Dong int alpha, /* alpha */ 650c1bc742181ded4930842b46e9507372f0b1b963James Dong int beta, /* beta */ 660c1bc742181ded4930842b46e9507372f0b1b963James Dong int bS, /* deblocking strength */ 670c1bc742181ded4930842b46e9507372f0b1b963James Dong int ChromaFlag 680c1bc742181ded4930842b46e9507372f0b1b963James Dong) 690c1bc742181ded4930842b46e9507372f0b1b963James Dong{ 700c1bc742181ded4930842b46e9507372f0b1b963James Dong int p3, p2, p1, p0, q0, q1, q2, q3; 710c1bc742181ded4930842b46e9507372f0b1b963James Dong int ap, aq, delta; 720c1bc742181ded4930842b46e9507372f0b1b963James Dong 730c1bc742181ded4930842b46e9507372f0b1b963James Dong if (bS==0) 740c1bc742181ded4930842b46e9507372f0b1b963James Dong { 750c1bc742181ded4930842b46e9507372f0b1b963James Dong return; 760c1bc742181ded4930842b46e9507372f0b1b963James Dong } 770c1bc742181ded4930842b46e9507372f0b1b963James Dong 780c1bc742181ded4930842b46e9507372f0b1b963James Dong p3 = pQ0[-4*Step]; 790c1bc742181ded4930842b46e9507372f0b1b963James Dong p2 = pQ0[-3*Step]; 800c1bc742181ded4930842b46e9507372f0b1b963James Dong p1 = pQ0[-2*Step]; 810c1bc742181ded4930842b46e9507372f0b1b963James Dong p0 = pQ0[-1*Step]; 820c1bc742181ded4930842b46e9507372f0b1b963James Dong q0 = pQ0[ 0*Step]; 830c1bc742181ded4930842b46e9507372f0b1b963James Dong q1 = pQ0[ 1*Step]; 840c1bc742181ded4930842b46e9507372f0b1b963James Dong q2 = pQ0[ 2*Step]; 850c1bc742181ded4930842b46e9507372f0b1b963James Dong q3 = pQ0[ 3*Step]; 860c1bc742181ded4930842b46e9507372f0b1b963James Dong 870c1bc742181ded4930842b46e9507372f0b1b963James Dong if (armAbs(p0-q0)>=alpha || armAbs(p1-p0)>=beta || armAbs(q1-q0)>=beta) 880c1bc742181ded4930842b46e9507372f0b1b963James Dong { 890c1bc742181ded4930842b46e9507372f0b1b963James Dong DEBUG_PRINTF_10("DeBlockPixel: %02x %02x %02x %02x | %02x %02x %02x %02x alpha=%d beta=%d\n", 900c1bc742181ded4930842b46e9507372f0b1b963James Dong p3, p2, p1, p0, q0, q1, q2, q3, alpha, beta); 910c1bc742181ded4930842b46e9507372f0b1b963James Dong return; 920c1bc742181ded4930842b46e9507372f0b1b963James Dong } 930c1bc742181ded4930842b46e9507372f0b1b963James Dong 940c1bc742181ded4930842b46e9507372f0b1b963James Dong ap = armAbs(p2 - p0); 950c1bc742181ded4930842b46e9507372f0b1b963James Dong aq = armAbs(q2 - q0); 960c1bc742181ded4930842b46e9507372f0b1b963James Dong 970c1bc742181ded4930842b46e9507372f0b1b963James Dong if (bS < 4) 980c1bc742181ded4930842b46e9507372f0b1b963James Dong { 990c1bc742181ded4930842b46e9507372f0b1b963James Dong int tC = tC0; 1000c1bc742181ded4930842b46e9507372f0b1b963James Dong 1010c1bc742181ded4930842b46e9507372f0b1b963James Dong if (ChromaFlag) 1020c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1030c1bc742181ded4930842b46e9507372f0b1b963James Dong tC++; 1040c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1050c1bc742181ded4930842b46e9507372f0b1b963James Dong else 1060c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1070c1bc742181ded4930842b46e9507372f0b1b963James Dong if (ap < beta) 1080c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1090c1bc742181ded4930842b46e9507372f0b1b963James Dong tC++; 1100c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1110c1bc742181ded4930842b46e9507372f0b1b963James Dong if (aq < beta) 1120c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1130c1bc742181ded4930842b46e9507372f0b1b963James Dong tC++; 1140c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1150c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1160c1bc742181ded4930842b46e9507372f0b1b963James Dong 1170c1bc742181ded4930842b46e9507372f0b1b963James Dong delta = (((q0-p0)<<2) + (p1-q1) + 4) >> 3; 1180c1bc742181ded4930842b46e9507372f0b1b963James Dong delta = armClip(-tC, tC, delta); 1190c1bc742181ded4930842b46e9507372f0b1b963James Dong 1200c1bc742181ded4930842b46e9507372f0b1b963James Dong pQ0[-1*Step] = (OMX_U8)armClip(0, 255, p0 + delta); 1210c1bc742181ded4930842b46e9507372f0b1b963James Dong pQ0[ 0*Step] = (OMX_U8)armClip(0, 255, q0 - delta); 1220c1bc742181ded4930842b46e9507372f0b1b963James Dong 1230c1bc742181ded4930842b46e9507372f0b1b963James Dong if (ChromaFlag==0 && ap<beta) 1240c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1250c1bc742181ded4930842b46e9507372f0b1b963James Dong delta = (p2 + ((p0+q0+1)>>1) - (p1<<1))>>1; 1260c1bc742181ded4930842b46e9507372f0b1b963James Dong delta = armClip(-tC0, tC0, delta); 1270c1bc742181ded4930842b46e9507372f0b1b963James Dong pQ0[-2*Step] = (OMX_U8)(p1 + delta); 1280c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1290c1bc742181ded4930842b46e9507372f0b1b963James Dong 1300c1bc742181ded4930842b46e9507372f0b1b963James Dong if (ChromaFlag==0 && aq<beta) 1310c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1320c1bc742181ded4930842b46e9507372f0b1b963James Dong delta = (q2 + ((p0+q0+1)>>1) - (q1<<1))>>1; 1330c1bc742181ded4930842b46e9507372f0b1b963James Dong delta = armClip(-tC0, tC0, delta); 1340c1bc742181ded4930842b46e9507372f0b1b963James Dong pQ0[ 1*Step] = (OMX_U8)(q1 + delta); 1350c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1360c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1370c1bc742181ded4930842b46e9507372f0b1b963James Dong else /* bS==4 */ 1380c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1390c1bc742181ded4930842b46e9507372f0b1b963James Dong if (ChromaFlag==0 && ap<beta && armAbs(p0-q0)<((alpha>>2)+2)) 1400c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1410c1bc742181ded4930842b46e9507372f0b1b963James Dong pQ0[-1*Step] = (OMX_U8)((p2 + 2*p1 + 2*p0 + 2*q0 + q1 + 4)>>3); 1420c1bc742181ded4930842b46e9507372f0b1b963James Dong pQ0[-2*Step] = (OMX_U8)((p2 + p1 + p0 + q0 + 2)>>2); 1430c1bc742181ded4930842b46e9507372f0b1b963James Dong pQ0[-3*Step] = (OMX_U8)((2*p3 + 3*p2 + p1 + p0 + q0 + 4)>>3); 1440c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1450c1bc742181ded4930842b46e9507372f0b1b963James Dong else 1460c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1470c1bc742181ded4930842b46e9507372f0b1b963James Dong pQ0[-1*Step] = (OMX_U8)((2*p1 + p0 + q1 + 2)>>2); 1480c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1490c1bc742181ded4930842b46e9507372f0b1b963James Dong 1500c1bc742181ded4930842b46e9507372f0b1b963James Dong if (ChromaFlag==0 && aq<beta && armAbs(p0-q0)<((alpha>>2)+2)) 1510c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1520c1bc742181ded4930842b46e9507372f0b1b963James Dong pQ0[ 0*Step] = (OMX_U8)((q2 + 2*q1 + 2*q0 + 2*p0 + p1 + 4)>>3); 1530c1bc742181ded4930842b46e9507372f0b1b963James Dong pQ0[ 1*Step] = (OMX_U8)((q2 + q1 + p0 + q0 + 2)>>2); 1540c1bc742181ded4930842b46e9507372f0b1b963James Dong pQ0[ 2*Step] = (OMX_U8)((2*q3 + 3*q2 + q1 + q0 + p0 + 4)>>3); 1550c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1560c1bc742181ded4930842b46e9507372f0b1b963James Dong else 1570c1bc742181ded4930842b46e9507372f0b1b963James Dong { 1580c1bc742181ded4930842b46e9507372f0b1b963James Dong pQ0[ 0*Step] = (OMX_U8)((2*q1 + q0 + p1 + 2)>>2); 1590c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1600c1bc742181ded4930842b46e9507372f0b1b963James Dong } 1610c1bc742181ded4930842b46e9507372f0b1b963James Dong 1620c1bc742181ded4930842b46e9507372f0b1b963James Dong DEBUG_PRINTF_13("DeBlockPixel: %02x %02x %02x %02x | %02x %02x %02x %02x bS=%d -> %02x %02x %02x %02x\n", 1630c1bc742181ded4930842b46e9507372f0b1b963James Dong p3, p2, p1, p0, q0, q1, q2, q3, bS, 1640c1bc742181ded4930842b46e9507372f0b1b963James Dong pQ0[-2*Step], pQ0[-1*Step],pQ0[0*Step],pQ0[1*Step]); 1650c1bc742181ded4930842b46e9507372f0b1b963James Dong 1660c1bc742181ded4930842b46e9507372f0b1b963James Dong} 167