omxVCM4P10_SATD_4x4.c revision 0c1bc742181ded4930842b46e9507372f0b1b963
1/**
2 *
3 * File Name:  omxVCM4P10_SATD_4x4.c
4 * OpenMAX DL: v1.0.2
5 * Revision:   9641
6 * Date:       Thursday, February 7, 2008
7 *
8 * (c) Copyright 2007-2008 ARM Limited. All Rights Reserved.
9 *
10 *
11 * Description:
12 * This function will calculate SAD for 4x4 blocks
13 *
14 */
15#include "omxtypes.h"
16#include "armOMX.h"
17#include "omxVC.h"
18
19#include "armCOMM.h"
20
21/**
22 * Function:  omxVCM4P10_SATD_4x4   (6.3.5.4.5)
23 *
24 * Description:
25 * This function calculates the sum of absolute transform differences (SATD)
26 * for a 4x4 block by applying a Hadamard transform to the difference block
27 * and then calculating the sum of absolute coefficient values.
28 *
29 * Input Arguments:
30 *
31 *   pSrcOrg - Pointer to the original block; must be aligned on a 4-byte
32 *            boundary
33 *   iStepOrg - Step of the original block buffer; must be a multiple of 4
34 *   pSrcRef - Pointer to the reference block; must be aligned on a 4-byte
35 *            boundary
36 *   iStepRef - Step of the reference block buffer; must be a multiple of 4
37 *
38 * Output Arguments:
39 *
40 *   pDstSAD - pointer to the resulting SAD
41 *
42 * Return Value:
43 *
44 *    OMX_Sts_NoErr - no error
45 *    OMX_Sts_BadArgErr - bad arguments; returned if any of the following
46 *              conditions are true:
47 *    -    at least one of the following pointers is NULL:
48 *         pSrcOrg, pSrcRef, or pDstSAD either pSrcOrg
49 *    -    pSrcRef is not aligned on a 4-byte boundary
50 *    -    iStepOrg <= 0 or iStepOrg is not a multiple of 4
51 *    -    iStepRef <= 0 or iStepRef is not a multiple of 4
52 *
53 */
54OMXResult omxVCM4P10_SATD_4x4(
55	const OMX_U8*		pSrcOrg,
56	OMX_U32     iStepOrg,
57	const OMX_U8*		pSrcRef,
58	OMX_U32		iStepRef,
59	OMX_U32*    pDstSAD
60)
61{
62    OMX_INT     i, j;
63    OMX_S32     SATD = 0;
64    OMX_S32     d [4][4], m1[4][4], m2[4][4];
65
66    /* check for argument error */
67    armRetArgErrIf(pSrcOrg == NULL, OMX_Sts_BadArgErr)
68    armRetArgErrIf(pSrcRef == NULL, OMX_Sts_BadArgErr)
69    armRetArgErrIf(pDstSAD == NULL, OMX_Sts_BadArgErr)
70    armRetArgErrIf((iStepOrg == 0) || (iStepOrg & 3), OMX_Sts_BadArgErr)
71    armRetArgErrIf((iStepRef == 0) || (iStepRef & 3), OMX_Sts_BadArgErr)
72    armRetArgErrIf(armNot4ByteAligned(pSrcOrg), OMX_Sts_BadArgErr)
73    armRetArgErrIf(armNot4ByteAligned(pSrcRef), OMX_Sts_BadArgErr)
74
75    /* Calculate the difference */
76    for (j = 0; j < 4; j++)
77    {
78        for (i = 0; i < 4; i++)
79        {
80            d [j][i] = pSrcOrg [j * iStepOrg + i] - pSrcRef [j * iStepRef + i];
81        }
82    }
83
84    /* Hadamard Transfor for 4x4 block */
85
86    /* Horizontal */
87    for (i = 0; i < 4; i++)
88    {
89        m1[i][0] = d[i][0] + d[i][2]; /* a+c */
90        m1[i][1] = d[i][1] + d[i][3]; /* b+d */
91        m1[i][2] = d[i][0] - d[i][2]; /* a-c */
92        m1[i][3] = d[i][1] - d[i][3]; /* b-d */
93
94        m2[i][0] = m1[i][0] + m1[i][1]; /* a+b+c+d */
95        m2[i][1] = m1[i][2] + m1[i][3]; /* a+b-c-d */
96        m2[i][2] = m1[i][2] - m1[i][3]; /* a-b-c+d */
97        m2[i][3] = m1[i][0] - m1[i][1]; /* a-b+c-d */
98
99    }
100
101    /* Vertical */
102    for (i = 0; i < 4; i++)
103    {
104        m1[0][i] = m2[0][i] + m2[2][i];
105        m1[1][i] = m2[1][i] + m2[3][i];
106        m1[2][i] = m2[0][i] - m2[2][i];
107        m1[3][i] = m2[1][i] - m2[3][i];
108
109        m2[0][i] = m1[0][i] + m1[1][i];
110        m2[1][i] = m1[2][i] + m1[3][i];
111        m2[2][i] = m1[2][i] - m1[3][i];
112        m2[3][i] = m1[0][i] - m1[1][i];
113    }
114
115    /* calculate SAD for Transformed coefficients */
116    for (j = 0; j < 4; j++)
117    {
118        for (i = 0; i < 4; i++)
119        {
120            SATD += armAbs(m2 [j][i]);
121        }
122    }
123
124    *pDstSAD = (SATD + 1) / 2;
125
126    return OMX_Sts_NoErr;
127}
128
129/*****************************************************************************
130 *                              END OF FILE
131 *****************************************************************************/
132
133