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