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:  armVCM4P10_Interpolate_Chroma.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 interpolation for chroma components
28 *
29 */
30
31#include "omxtypes.h"
32#include "armOMX.h"
33
34#include "armCOMM.h"
35
36/**
37 * Function: armVCM4P10_Interpolate_Chroma
38 *
39 * Description:
40 * This function performs interpolation for chroma components.
41 *
42 * Remarks:
43 *
44 *  [in]    pSrc            Pointer to top-left corner of block used to
45 *                                              interpolate in the reconstructed frame plane
46 *  [in]    iSrcStep    Step of the source buffer.
47 *  [in]    iDstStep    Step of the destination(interpolation) buffer.
48 *  [in]    iWidth      Width of the current block
49 *  [in]    iHeight     Height of the current block
50 *  [in]    dx              Fractional part of horizontal motion vector
51 *                                              component in 1/8 pixel unit (0~7)
52 *  [in]    dy              Fractional part of vertical motion vector
53 *                                              component in 1/8 pixel unit (0~7)
54 *  [out]   pDst            Pointer to the interpolation buffer
55 *
56 * Return Value:
57 * Standard OMXResult value.
58 *
59 */
60 OMXResult armVCM4P10_Interpolate_Chroma(
61        OMX_U8      *pSrc,
62        OMX_U32     iSrcStep,
63        OMX_U8      *pDst,
64        OMX_U32     iDstStep,
65        OMX_U32     iWidth,
66        OMX_U32     iHeight,
67        OMX_U32     dx,
68        OMX_U32     dy
69)
70{
71    OMX_U32     EightMinusdx = 8 - dx;
72    OMX_U32     EightMinusdy = 8 - dy;
73    OMX_U32     ACoeff, BCoeff, CCoeff, DCoeff;
74    OMX_U32     x, y;
75
76    /* check for argument error */
77    armRetArgErrIf(pSrc == NULL, OMX_Sts_BadArgErr)
78    armRetArgErrIf(pDst == NULL, OMX_Sts_BadArgErr)
79    armRetArgErrIf(dx > 7, OMX_Sts_BadArgErr)
80    armRetArgErrIf(dy > 7, OMX_Sts_BadArgErr)
81    armRetArgErrIf(iSrcStep == 0, OMX_Sts_BadArgErr)
82    armRetArgErrIf(iDstStep == 0, OMX_Sts_BadArgErr)
83    armRetArgErrIf(iWidth == 0, OMX_Sts_BadArgErr)
84    armRetArgErrIf(iHeight == 0, OMX_Sts_BadArgErr)
85
86    /* if fractionl mv is not (0, 0) */
87    if (dx != 0 || dy != 0)
88    {
89        ACoeff = EightMinusdx * EightMinusdy;
90        BCoeff = dx * EightMinusdy;
91        CCoeff = EightMinusdx * dy;
92        DCoeff = dx * dy;
93
94        for (y = 0; y < iHeight; y++)
95        {
96            for (x = 0; x < iWidth; x++)
97            {
98                pDst [y * iDstStep + x] = (
99                    ACoeff * pSrc [y * iSrcStep + x] +
100                    BCoeff * pSrc [y * iSrcStep + x + 1] +
101                    CCoeff * pSrc [(y + 1) * iSrcStep + x] +
102                    DCoeff * pSrc [(y + 1) * iSrcStep + x + 1] +
103                    32) >> 6;
104            }
105        }
106    }
107    else
108    {
109        for (y = 0; y < iHeight; y++)
110        {
111            for (x = 0; x < iWidth; x++)
112            {
113                pDst [y * iDstStep + x] = pSrc [y * iSrcStep + x];
114            }
115        }
116    }
117
118    return OMX_Sts_NoErr;
119}
120
121/*****************************************************************************
122 *                              END OF FILE
123 *****************************************************************************/
124
125