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:  omxVCCOMM_ComputeTextureErrorBlock_SAD.c
20 * OpenMAX DL: v1.0.2
21 * Revision:   9641
22 * Date:       Thursday, February 7, 2008
23 *
24 *
25 *
26 *
27 * Description:
28 * Contains module computing the error for a MB of size 8x8
29 *
30 */
31#include "omxtypes.h"
32#include "armOMX.h"
33#include "omxVC.h"
34
35#include "armCOMM.h"
36
37
38/**
39 * Function:  omxVCCOMM_ComputeTextureErrorBlock_SAD   (6.1.4.1.1)
40 *
41 * Description:
42 * Computes texture error of the block; also returns SAD.
43 *
44 * Input Arguments:
45 *
46 *   pSrc - pointer to the source plane; must be aligned on an 8-byte
47 *            boundary.
48 *   srcStep - step of the source plane
49 *   pSrcRef - pointer to the reference buffer, an 8x8 block; must be aligned
50 *            on an 8-byte boundary.
51 *
52 * Output Arguments:
53 *
54 *   pDst - pointer to the destination buffer, an 8x8 block; must be aligned
55 *            on an 8-byte boundary.
56 *   pDstSAD - pointer to the Sum of Absolute Differences (SAD) value
57 *
58 * Return Value:
59 *
60 *    OMX_Sts_NoErr - no error
61 *    OMX_Sts_BadArgErr - bad arguments
62 *    -    At least one of the following
63 *         pointers is NULL: pSrc, pSrcRef, pDst and pDstSAD.
64 *    -    pSrc is not 8-byte aligned.
65 *    -    SrcStep <= 0 or srcStep is not a multiple of 8.
66 *    -    pSrcRef is not 8-byte aligned.
67 *    -    pDst is not 8-byte aligned.
68 *
69 */
70
71OMXResult omxVCCOMM_ComputeTextureErrorBlock_SAD(
72     const OMX_U8 *pSrc,
73     OMX_INT srcStep,
74     const OMX_U8 *pSrcRef,
75     OMX_S16 * pDst,
76     OMX_INT *pDstSAD
77)
78{
79
80    OMX_INT     x, y, count;
81
82    /* Argument error checks */
83    armRetArgErrIf(pSrc == NULL, OMX_Sts_BadArgErr);
84    armRetArgErrIf(pSrcRef == NULL, OMX_Sts_BadArgErr);
85    armRetArgErrIf(pDst == NULL, OMX_Sts_BadArgErr);
86    armRetArgErrIf(pDstSAD == NULL, OMX_Sts_BadArgErr);
87    armRetArgErrIf(!armIs8ByteAligned(pSrc), OMX_Sts_BadArgErr);
88    armRetArgErrIf(!armIs8ByteAligned(pSrcRef), OMX_Sts_BadArgErr);
89    armRetArgErrIf(!armIs8ByteAligned(pDst), OMX_Sts_BadArgErr);
90    armRetArgErrIf((srcStep <= 0) || (srcStep & 7), OMX_Sts_BadArgErr);
91
92    /* Calculate the error block */
93    for (y = 0, count = 0, *pDstSAD = 0;
94         y < 8;
95         y++, pSrc += srcStep)
96    {
97        for (x = 0; x < 8; x++, count++)
98        {
99            pDst[count] = pSrc[x] - pSrcRef[count];
100            *pDstSAD += armAbs(pDst[count]);
101        }
102    }
103
104    return OMX_Sts_NoErr;
105
106}
107
108/* End of file */
109