armVCM4P10_Interpolate_Luma.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:  armVCM4P10_Interpolate_Luma.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 luma components
28 *
29 */
30
31#include "omxtypes.h"
32#include "armOMX.h"
33#include "omxVC.h"
34
35#include "armCOMM.h"
36#include "armVC.h"
37
38/**
39 * Function: armM4P10_Copy
40 *
41 * Description:
42 * This function performs copy a block of data from source to destination
43 *
44 * Remarks:
45 *
46 *  [in]    pSrc            Pointer to top-left corner of block
47 *  [in]    iSrcStep    Step of the source buffer.
48 *  [in]    iDstStep    Step of the destination  buffer.
49 *  [in]    iWidth      Width of the current block
50 *  [in]    iHeight     Height of the current block
51 *  [out]   pDst            Pointer to the interpolation buffer
52 *
53 * Return Value:
54 * Standard OMXResult value.
55 *
56 */
57static OMXResult armM4P10_Copy(
58    const OMX_U8*     pSrc,
59    OMX_U32     iSrcStep,
60    OMX_U8*     pDst,
61    OMX_U32     iDstStep,
62    OMX_U32     iWidth,
63    OMX_U32     iHeight
64)
65{
66    OMX_U32     x, y;
67
68    for (y = 0; y < iHeight; y++)
69    {
70        for (x = 0; x < iWidth; x++)
71        {
72            pDst [y * iDstStep + x] = pSrc [y * iSrcStep + x];
73        }
74    }
75
76    return OMX_Sts_NoErr;
77}
78
79/**
80 * Function: armVCM4P10_Interpolate_Luma
81 *
82 * Description:
83 * This function performs interpolation for luma components.
84 *
85 * Remarks:
86 *
87 *  [in]    pSrc            Pointer to top-left corner of block used to
88 *                                              interpolate in the reconstructed frame plane
89 *  [in]    iSrcStep    Step of the source buffer.
90 *  [in]    iDstStep    Step of the destination(interpolation) buffer.
91 *  [in]    iWidth      Width of the current block
92 *  [in]    iHeight     Height of the current block
93 *  [in]    dx              Fractional part of horizontal motion vector
94 *                                              component in 1/4 pixel unit (0~3)
95 *  [in]    dy              Fractional part of vertical motion vector
96 *                                              component in 1/4 pixel unit (0~3)
97 *  [out]   pDst            Pointer to the interpolation buffer
98 *
99 * Return Value:
100 * Standard OMXResult value.
101 *
102 */
103
104 OMXResult armVCM4P10_Interpolate_Luma(
105     const OMX_U8     *pSrc,
106     OMX_U32    iSrcStep,
107     OMX_U8     *pDst,
108     OMX_U32    iDstStep,
109     OMX_U32    iWidth,
110     OMX_U32    iHeight,
111     OMX_U32    dx,
112     OMX_U32    dy
113)
114{
115    OMX_U8      pBuf1 [16*16];
116    const OMX_U8      *pSrcHalfHor = pSrc;
117    const OMX_U8      *pSrcHalfVer = pSrc;
118
119    /* check for argument error */
120    armRetArgErrIf(pSrc == NULL, OMX_Sts_BadArgErr)
121    armRetArgErrIf(pDst == NULL, OMX_Sts_BadArgErr)
122    armRetArgErrIf(dx > 3, OMX_Sts_BadArgErr)
123    armRetArgErrIf(dy > 3, OMX_Sts_BadArgErr)
124
125    /* Work out positions for half pixel interpolation */
126    if (dx == 3)
127    {
128        pSrcHalfVer += 1;
129    }
130    if (dy == 3)
131    {
132        pSrcHalfHor += iSrcStep;
133    }
134
135    /* Switch on type of pixel
136     * Pixels are named 'a' to 's' as in the H.264 standard
137     */
138    if (dx == 0 && dy == 0)
139    {
140        /* G */
141        armM4P10_Copy(pSrc, iSrcStep, pDst, iDstStep, iWidth, iHeight);
142    }
143    else if (dy == 0)
144    {
145        /* a, b, c */
146        armVCM4P10_InterpolateHalfHor_Luma
147            (pSrcHalfHor, iSrcStep, pDst, iDstStep, iWidth, iHeight);
148
149        if (dx == 1 || dx == 3)
150        {
151            armVCCOMM_Average
152                (pDst, pSrcHalfVer, iDstStep, iSrcStep, pDst, iDstStep, iWidth, iHeight);
153        }
154    }
155    else if (dx == 0)
156    {
157        /* d, h, n */
158        armVCM4P10_InterpolateHalfVer_Luma
159            (pSrcHalfVer, iSrcStep, pDst, iDstStep, iWidth, iHeight);
160
161        if (dy == 1 || dy == 3)
162        {
163            armVCCOMM_Average
164                (pDst, pSrcHalfHor, iDstStep, iSrcStep, pDst, iDstStep, iWidth, iHeight);
165        }
166    }
167    else if (dx == 2 || dy == 2)
168    {
169        /* j */
170        armVCM4P10_InterpolateHalfDiag_Luma
171            (pSrc, iSrcStep, pDst, iDstStep, iWidth, iHeight);
172
173        if (dx == 1 || dx == 3)
174        {
175            /* i, k */
176            armVCM4P10_InterpolateHalfVer_Luma
177                (pSrcHalfVer, iSrcStep, pBuf1, iWidth, iWidth, iHeight);
178
179            armVCCOMM_Average
180                (pDst, pBuf1, iDstStep, iWidth, pDst, iDstStep, iWidth, iHeight);
181        }
182        if (dy == 1 || dy == 3)
183        {
184            /* f,q */
185            armVCM4P10_InterpolateHalfHor_Luma
186                (pSrcHalfHor, iSrcStep, pBuf1, iWidth, iWidth, iHeight);
187
188            armVCCOMM_Average
189                (pDst, pBuf1, iDstStep, iWidth, pDst, iDstStep, iWidth, iHeight);
190        }
191    }
192    else /* dx=1,3 and dy=1,3 */
193    {
194        /* e, g, p, r */
195        armVCM4P10_InterpolateHalfHor_Luma
196            (pSrcHalfHor, iSrcStep, pBuf1, iWidth, iWidth, iHeight);
197
198        armVCM4P10_InterpolateHalfVer_Luma
199            (pSrcHalfVer, iSrcStep, pDst, iDstStep, iWidth, iHeight);
200
201        armVCCOMM_Average
202            (pBuf1, pDst, iWidth, iDstStep, pDst, iDstStep, iWidth, iHeight);
203    }
204
205    return OMX_Sts_NoErr;
206}
207
208/*****************************************************************************
209 *                              END OF FILE
210 *****************************************************************************/
211