10c1bc742181ded4930842b46e9507372f0b1b963James Dong/*
20c1bc742181ded4930842b46e9507372f0b1b963James Dong * Copyright (C) 2009 The Android Open Source Project
30c1bc742181ded4930842b46e9507372f0b1b963James Dong *
40c1bc742181ded4930842b46e9507372f0b1b963James Dong * Licensed under the Apache License, Version 2.0 (the "License");
50c1bc742181ded4930842b46e9507372f0b1b963James Dong * you may not use this file except in compliance with the License.
60c1bc742181ded4930842b46e9507372f0b1b963James Dong * You may obtain a copy of the License at
70c1bc742181ded4930842b46e9507372f0b1b963James Dong *
80c1bc742181ded4930842b46e9507372f0b1b963James Dong *      http://www.apache.org/licenses/LICENSE-2.0
90c1bc742181ded4930842b46e9507372f0b1b963James Dong *
100c1bc742181ded4930842b46e9507372f0b1b963James Dong * Unless required by applicable law or agreed to in writing, software
110c1bc742181ded4930842b46e9507372f0b1b963James Dong * distributed under the License is distributed on an "AS IS" BASIS,
120c1bc742181ded4930842b46e9507372f0b1b963James Dong * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
130c1bc742181ded4930842b46e9507372f0b1b963James Dong * See the License for the specific language governing permissions and
140c1bc742181ded4930842b46e9507372f0b1b963James Dong * limitations under the License.
150c1bc742181ded4930842b46e9507372f0b1b963James Dong */
160c1bc742181ded4930842b46e9507372f0b1b963James Dong
170c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
180c1bc742181ded4930842b46e9507372f0b1b963James Dong
190c1bc742181ded4930842b46e9507372f0b1b963James Dong    Table of contents
200c1bc742181ded4930842b46e9507372f0b1b963James Dong
210c1bc742181ded4930842b46e9507372f0b1b963James Dong     1. Include headers
220c1bc742181ded4930842b46e9507372f0b1b963James Dong     2. External compiler flags
230c1bc742181ded4930842b46e9507372f0b1b963James Dong     3. Module defines
240c1bc742181ded4930842b46e9507372f0b1b963James Dong     4. Local function prototypes
250c1bc742181ded4930842b46e9507372f0b1b963James Dong     5. Functions
260c1bc742181ded4930842b46e9507372f0b1b963James Dong
270c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
280c1bc742181ded4930842b46e9507372f0b1b963James Dong
290c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
300c1bc742181ded4930842b46e9507372f0b1b963James Dong    1. Include headers
310c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
320c1bc742181ded4930842b46e9507372f0b1b963James Dong
330c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "basetype.h"
340c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_reconstruct.h"
350c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_macroblock_layer.h"
360c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_image.h"
370c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_util.h"
380c1bc742181ded4930842b46e9507372f0b1b963James Dong
390c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifdef H264DEC_OMXDL
400c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "omxtypes.h"
410c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "omxVC.h"
420c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "armVC.h"
430c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif /* H264DEC_OMXDL */
440c1bc742181ded4930842b46e9507372f0b1b963James Dong
4584333e0475bc911adc16417f4ca327c975cf6c36Andreas Huber#define UNUSED(x) (void)(x)
4684333e0475bc911adc16417f4ca327c975cf6c36Andreas Huber
470c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
480c1bc742181ded4930842b46e9507372f0b1b963James Dong    2. External compiler flags
490c1bc742181ded4930842b46e9507372f0b1b963James Dong--------------------------------------------------------------------------------
500c1bc742181ded4930842b46e9507372f0b1b963James Dong
510c1bc742181ded4930842b46e9507372f0b1b963James Dong--------------------------------------------------------------------------------
520c1bc742181ded4930842b46e9507372f0b1b963James Dong    3. Module defines
530c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
540c1bc742181ded4930842b46e9507372f0b1b963James Dong
550c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Switch off the following Lint messages for this file:
560c1bc742181ded4930842b46e9507372f0b1b963James Dong * Info 701: Shift left of signed quantity (int)
570c1bc742181ded4930842b46e9507372f0b1b963James Dong * Info 702: Shift right of signed quantity (int)
580c1bc742181ded4930842b46e9507372f0b1b963James Dong */
590c1bc742181ded4930842b46e9507372f0b1b963James Dong/*lint -e701 -e702 */
600c1bc742181ded4930842b46e9507372f0b1b963James Dong
610c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Luma fractional-sample positions
620c1bc742181ded4930842b46e9507372f0b1b963James Dong *
630c1bc742181ded4930842b46e9507372f0b1b963James Dong *  G a b c H
640c1bc742181ded4930842b46e9507372f0b1b963James Dong *  d e f g
650c1bc742181ded4930842b46e9507372f0b1b963James Dong *  h i j k m
660c1bc742181ded4930842b46e9507372f0b1b963James Dong *  n p q r
670c1bc742181ded4930842b46e9507372f0b1b963James Dong *  M   s   N
680c1bc742181ded4930842b46e9507372f0b1b963James Dong *
690c1bc742181ded4930842b46e9507372f0b1b963James Dong *  G, H, M and N are integer sample positions
700c1bc742181ded4930842b46e9507372f0b1b963James Dong *  a-s are fractional samples that need to be interpolated.
710c1bc742181ded4930842b46e9507372f0b1b963James Dong */
720c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifndef H264DEC_OMXDL
730c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic const u32 lumaFracPos[4][4] = {
740c1bc742181ded4930842b46e9507372f0b1b963James Dong  /* G  d  h  n    a  e  i  p    b  f  j   q     c   g   k   r */
750c1bc742181ded4930842b46e9507372f0b1b963James Dong    {0, 1, 2, 3}, {4, 5, 6, 7}, {8, 9, 10, 11}, {12, 13, 14, 15}};
760c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif /* H264DEC_OMXDL */
770c1bc742181ded4930842b46e9507372f0b1b963James Dong
780c1bc742181ded4930842b46e9507372f0b1b963James Dong/* clipping table, defined in h264bsd_intra_prediction.c */
790c1bc742181ded4930842b46e9507372f0b1b963James Dongextern const u8 h264bsdClip[];
800c1bc742181ded4930842b46e9507372f0b1b963James Dong
810c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
820c1bc742181ded4930842b46e9507372f0b1b963James Dong    4. Local function prototypes
830c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
840c1bc742181ded4930842b46e9507372f0b1b963James Dong
850c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifndef H264DEC_OMXDL
860c1bc742181ded4930842b46e9507372f0b1b963James Dong
870c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
880c1bc742181ded4930842b46e9507372f0b1b963James Dong
890c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: h264bsdInterpolateChromaHor
900c1bc742181ded4930842b46e9507372f0b1b963James Dong
910c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
920c1bc742181ded4930842b46e9507372f0b1b963James Dong          This function performs chroma interpolation in horizontal direction.
930c1bc742181ded4930842b46e9507372f0b1b963James Dong          Overfilling is done only if needed. Reference image (pRef) is
940c1bc742181ded4930842b46e9507372f0b1b963James Dong          read at correct position and the predicted part is written to
950c1bc742181ded4930842b46e9507372f0b1b963James Dong          macroblock's chrominance (predPartChroma)
960c1bc742181ded4930842b46e9507372f0b1b963James Dong        Inputs:
970c1bc742181ded4930842b46e9507372f0b1b963James Dong          pRef              pointer to reference frame Cb top-left corner
980c1bc742181ded4930842b46e9507372f0b1b963James Dong          x0                integer x-coordinate for prediction
990c1bc742181ded4930842b46e9507372f0b1b963James Dong          y0                integer y-coordinate for prediction
1000c1bc742181ded4930842b46e9507372f0b1b963James Dong          width             width of the reference frame chrominance in pixels
1010c1bc742181ded4930842b46e9507372f0b1b963James Dong          height            height of the reference frame chrominance in pixels
1020c1bc742181ded4930842b46e9507372f0b1b963James Dong          xFrac             horizontal fraction for prediction in 1/8 pixels
1030c1bc742181ded4930842b46e9507372f0b1b963James Dong          chromaPartWidth   width of the predicted part in pixels
1040c1bc742181ded4930842b46e9507372f0b1b963James Dong          chromaPartHeight  height of the predicted part in pixels
1050c1bc742181ded4930842b46e9507372f0b1b963James Dong        Outputs:
1060c1bc742181ded4930842b46e9507372f0b1b963James Dong          predPartChroma    pointer where predicted part is written
1070c1bc742181ded4930842b46e9507372f0b1b963James Dong
1080c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
1090c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifndef H264DEC_ARM11
1100c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid h264bsdInterpolateChromaHor(
1110c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *pRef,
1120c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *predPartChroma,
1130c1bc742181ded4930842b46e9507372f0b1b963James Dong  i32 x0,
1140c1bc742181ded4930842b46e9507372f0b1b963James Dong  i32 y0,
1150c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 width,
1160c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 height,
1170c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 xFrac,
1180c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 chromaPartWidth,
1190c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 chromaPartHeight)
1200c1bc742181ded4930842b46e9507372f0b1b963James Dong{
1210c1bc742181ded4930842b46e9507372f0b1b963James Dong
1220c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
1230c1bc742181ded4930842b46e9507372f0b1b963James Dong
1240c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 x, y, tmp1, tmp2, tmp3, tmp4, c, val;
1250c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 *ptrA, *cbr;
1260c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 comp;
1270c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 block[9*8*2];
1280c1bc742181ded4930842b46e9507372f0b1b963James Dong
1290c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
1300c1bc742181ded4930842b46e9507372f0b1b963James Dong
1310c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(predPartChroma);
1320c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(chromaPartWidth);
1330c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(chromaPartHeight);
1340c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(xFrac < 8);
1350c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(pRef);
1360c1bc742181ded4930842b46e9507372f0b1b963James Dong
1370c1bc742181ded4930842b46e9507372f0b1b963James Dong    if ((x0 < 0) || ((u32)x0+chromaPartWidth+1 > width) ||
1380c1bc742181ded4930842b46e9507372f0b1b963James Dong        (y0 < 0) || ((u32)y0+chromaPartHeight > height))
1390c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
1400c1bc742181ded4930842b46e9507372f0b1b963James Dong        h264bsdFillBlock(pRef, block, x0, y0, width, height,
1410c1bc742181ded4930842b46e9507372f0b1b963James Dong            chromaPartWidth + 1, chromaPartHeight, chromaPartWidth + 1);
1420c1bc742181ded4930842b46e9507372f0b1b963James Dong        pRef += width * height;
1430c1bc742181ded4930842b46e9507372f0b1b963James Dong        h264bsdFillBlock(pRef, block + (chromaPartWidth+1)*chromaPartHeight,
1440c1bc742181ded4930842b46e9507372f0b1b963James Dong            x0, y0, width, height, chromaPartWidth + 1,
1450c1bc742181ded4930842b46e9507372f0b1b963James Dong            chromaPartHeight, chromaPartWidth + 1);
1460c1bc742181ded4930842b46e9507372f0b1b963James Dong
1470c1bc742181ded4930842b46e9507372f0b1b963James Dong        pRef = block;
1480c1bc742181ded4930842b46e9507372f0b1b963James Dong        x0 = 0;
1490c1bc742181ded4930842b46e9507372f0b1b963James Dong        y0 = 0;
1500c1bc742181ded4930842b46e9507372f0b1b963James Dong        width = chromaPartWidth+1;
1510c1bc742181ded4930842b46e9507372f0b1b963James Dong        height = chromaPartHeight;
1520c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1530c1bc742181ded4930842b46e9507372f0b1b963James Dong
1540c1bc742181ded4930842b46e9507372f0b1b963James Dong    val = 8 - xFrac;
1550c1bc742181ded4930842b46e9507372f0b1b963James Dong
1560c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (comp = 0; comp <= 1; comp++)
1570c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
1580c1bc742181ded4930842b46e9507372f0b1b963James Dong
1590c1bc742181ded4930842b46e9507372f0b1b963James Dong        ptrA = pRef + (comp * height + (u32)y0) * width + x0;
1600c1bc742181ded4930842b46e9507372f0b1b963James Dong        cbr = predPartChroma + comp * 8 * 8;
1610c1bc742181ded4930842b46e9507372f0b1b963James Dong
1620c1bc742181ded4930842b46e9507372f0b1b963James Dong        /* 2x2 pels per iteration
1630c1bc742181ded4930842b46e9507372f0b1b963James Dong         * bilinear horizontal interpolation */
1640c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (y = (chromaPartHeight >> 1); y; y--)
1650c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
1660c1bc742181ded4930842b46e9507372f0b1b963James Dong            for (x = (chromaPartWidth >> 1); x; x--)
1670c1bc742181ded4930842b46e9507372f0b1b963James Dong            {
1680c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp1 = ptrA[width];
1690c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp2 = *ptrA++;
1700c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp3 = ptrA[width];
1710c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp4 = *ptrA++;
1720c1bc742181ded4930842b46e9507372f0b1b963James Dong                c = ((val * tmp1 + xFrac * tmp3) << 3) + 32;
1730c1bc742181ded4930842b46e9507372f0b1b963James Dong                c >>= 6;
1740c1bc742181ded4930842b46e9507372f0b1b963James Dong                cbr[8] = (u8)c;
1750c1bc742181ded4930842b46e9507372f0b1b963James Dong                c = ((val * tmp2 + xFrac * tmp4) << 3) + 32;
1760c1bc742181ded4930842b46e9507372f0b1b963James Dong                c >>= 6;
1770c1bc742181ded4930842b46e9507372f0b1b963James Dong                *cbr++ = (u8)c;
1780c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp1 = ptrA[width];
1790c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp2 = *ptrA;
1800c1bc742181ded4930842b46e9507372f0b1b963James Dong                c = ((val * tmp3 + xFrac * tmp1) << 3) + 32;
1810c1bc742181ded4930842b46e9507372f0b1b963James Dong                c >>= 6;
1820c1bc742181ded4930842b46e9507372f0b1b963James Dong                cbr[8] = (u8)c;
1830c1bc742181ded4930842b46e9507372f0b1b963James Dong                c = ((val * tmp4 + xFrac * tmp2) << 3) + 32;
1840c1bc742181ded4930842b46e9507372f0b1b963James Dong                c >>= 6;
1850c1bc742181ded4930842b46e9507372f0b1b963James Dong                *cbr++ = (u8)c;
1860c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
1870c1bc742181ded4930842b46e9507372f0b1b963James Dong            cbr += 2*8 - chromaPartWidth;
1880c1bc742181ded4930842b46e9507372f0b1b963James Dong            ptrA += 2*width - chromaPartWidth;
1890c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
1900c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
1910c1bc742181ded4930842b46e9507372f0b1b963James Dong
1920c1bc742181ded4930842b46e9507372f0b1b963James Dong}
1930c1bc742181ded4930842b46e9507372f0b1b963James Dong
1940c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
1950c1bc742181ded4930842b46e9507372f0b1b963James Dong
1960c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: h264bsdInterpolateChromaVer
1970c1bc742181ded4930842b46e9507372f0b1b963James Dong
1980c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
1990c1bc742181ded4930842b46e9507372f0b1b963James Dong          This function performs chroma interpolation in vertical direction.
2000c1bc742181ded4930842b46e9507372f0b1b963James Dong          Overfilling is done only if needed. Reference image (pRef) is
2010c1bc742181ded4930842b46e9507372f0b1b963James Dong          read at correct position and the predicted part is written to
2020c1bc742181ded4930842b46e9507372f0b1b963James Dong          macroblock's chrominance (predPartChroma)
2030c1bc742181ded4930842b46e9507372f0b1b963James Dong
2040c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
2050c1bc742181ded4930842b46e9507372f0b1b963James Dong
2060c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid h264bsdInterpolateChromaVer(
2070c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *pRef,
2080c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *predPartChroma,
2090c1bc742181ded4930842b46e9507372f0b1b963James Dong  i32 x0,
2100c1bc742181ded4930842b46e9507372f0b1b963James Dong  i32 y0,
2110c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 width,
2120c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 height,
2130c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 yFrac,
2140c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 chromaPartWidth,
2150c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 chromaPartHeight)
2160c1bc742181ded4930842b46e9507372f0b1b963James Dong{
2170c1bc742181ded4930842b46e9507372f0b1b963James Dong
2180c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
2190c1bc742181ded4930842b46e9507372f0b1b963James Dong
2200c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 x, y, tmp1, tmp2, tmp3, c, val;
2210c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 *ptrA, *cbr;
2220c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 comp;
2230c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 block[9*8*2];
2240c1bc742181ded4930842b46e9507372f0b1b963James Dong
2250c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
2260c1bc742181ded4930842b46e9507372f0b1b963James Dong
2270c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(predPartChroma);
2280c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(chromaPartWidth);
2290c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(chromaPartHeight);
2300c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(yFrac < 8);
2310c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(pRef);
2320c1bc742181ded4930842b46e9507372f0b1b963James Dong
2330c1bc742181ded4930842b46e9507372f0b1b963James Dong    if ((x0 < 0) || ((u32)x0+chromaPartWidth > width) ||
2340c1bc742181ded4930842b46e9507372f0b1b963James Dong        (y0 < 0) || ((u32)y0+chromaPartHeight+1 > height))
2350c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
2360c1bc742181ded4930842b46e9507372f0b1b963James Dong        h264bsdFillBlock(pRef, block, x0, y0, width, height, chromaPartWidth,
2370c1bc742181ded4930842b46e9507372f0b1b963James Dong            chromaPartHeight + 1, chromaPartWidth);
2380c1bc742181ded4930842b46e9507372f0b1b963James Dong        pRef += width * height;
2390c1bc742181ded4930842b46e9507372f0b1b963James Dong        h264bsdFillBlock(pRef, block + chromaPartWidth*(chromaPartHeight+1),
2400c1bc742181ded4930842b46e9507372f0b1b963James Dong            x0, y0, width, height, chromaPartWidth,
2410c1bc742181ded4930842b46e9507372f0b1b963James Dong            chromaPartHeight + 1, chromaPartWidth);
2420c1bc742181ded4930842b46e9507372f0b1b963James Dong
2430c1bc742181ded4930842b46e9507372f0b1b963James Dong        pRef = block;
2440c1bc742181ded4930842b46e9507372f0b1b963James Dong        x0 = 0;
2450c1bc742181ded4930842b46e9507372f0b1b963James Dong        y0 = 0;
2460c1bc742181ded4930842b46e9507372f0b1b963James Dong        width = chromaPartWidth;
2470c1bc742181ded4930842b46e9507372f0b1b963James Dong        height = chromaPartHeight+1;
2480c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
2490c1bc742181ded4930842b46e9507372f0b1b963James Dong
2500c1bc742181ded4930842b46e9507372f0b1b963James Dong    val = 8 - yFrac;
2510c1bc742181ded4930842b46e9507372f0b1b963James Dong
2520c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (comp = 0; comp <= 1; comp++)
2530c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
2540c1bc742181ded4930842b46e9507372f0b1b963James Dong
2550c1bc742181ded4930842b46e9507372f0b1b963James Dong        ptrA = pRef + (comp * height + (u32)y0) * width + x0;
2560c1bc742181ded4930842b46e9507372f0b1b963James Dong        cbr = predPartChroma + comp * 8 * 8;
2570c1bc742181ded4930842b46e9507372f0b1b963James Dong
2580c1bc742181ded4930842b46e9507372f0b1b963James Dong        /* 2x2 pels per iteration
2590c1bc742181ded4930842b46e9507372f0b1b963James Dong         * bilinear vertical interpolation */
2600c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (y = (chromaPartHeight >> 1); y; y--)
2610c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
2620c1bc742181ded4930842b46e9507372f0b1b963James Dong            for (x = (chromaPartWidth >> 1); x; x--)
2630c1bc742181ded4930842b46e9507372f0b1b963James Dong            {
2640c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp3 = ptrA[width*2];
2650c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp2 = ptrA[width];
2660c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp1 = *ptrA++;
2670c1bc742181ded4930842b46e9507372f0b1b963James Dong                c = ((val * tmp2 + yFrac * tmp3) << 3) + 32;
2680c1bc742181ded4930842b46e9507372f0b1b963James Dong                c >>= 6;
2690c1bc742181ded4930842b46e9507372f0b1b963James Dong                cbr[8] = (u8)c;
2700c1bc742181ded4930842b46e9507372f0b1b963James Dong                c = ((val * tmp1 + yFrac * tmp2) << 3) + 32;
2710c1bc742181ded4930842b46e9507372f0b1b963James Dong                c >>= 6;
2720c1bc742181ded4930842b46e9507372f0b1b963James Dong                *cbr++ = (u8)c;
2730c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp3 = ptrA[width*2];
2740c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp2 = ptrA[width];
2750c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp1 = *ptrA++;
2760c1bc742181ded4930842b46e9507372f0b1b963James Dong                c = ((val * tmp2 + yFrac * tmp3) << 3) + 32;
2770c1bc742181ded4930842b46e9507372f0b1b963James Dong                c >>= 6;
2780c1bc742181ded4930842b46e9507372f0b1b963James Dong                cbr[8] = (u8)c;
2790c1bc742181ded4930842b46e9507372f0b1b963James Dong                c = ((val * tmp1 + yFrac * tmp2) << 3) + 32;
2800c1bc742181ded4930842b46e9507372f0b1b963James Dong                c >>= 6;
2810c1bc742181ded4930842b46e9507372f0b1b963James Dong                *cbr++ = (u8)c;
2820c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
2830c1bc742181ded4930842b46e9507372f0b1b963James Dong            cbr += 2*8 - chromaPartWidth;
2840c1bc742181ded4930842b46e9507372f0b1b963James Dong            ptrA += 2*width - chromaPartWidth;
2850c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
2860c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
2870c1bc742181ded4930842b46e9507372f0b1b963James Dong
2880c1bc742181ded4930842b46e9507372f0b1b963James Dong}
2890c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif
2900c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
2910c1bc742181ded4930842b46e9507372f0b1b963James Dong
2920c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: h264bsdInterpolateChromaHorVer
2930c1bc742181ded4930842b46e9507372f0b1b963James Dong
2940c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
2950c1bc742181ded4930842b46e9507372f0b1b963James Dong          This function performs chroma interpolation in horizontal and
2960c1bc742181ded4930842b46e9507372f0b1b963James Dong          vertical direction. Overfilling is done only if needed. Reference
2970c1bc742181ded4930842b46e9507372f0b1b963James Dong          image (ref) is read at correct position and the predicted part
2980c1bc742181ded4930842b46e9507372f0b1b963James Dong          is written to macroblock's chrominance (predPartChroma)
2990c1bc742181ded4930842b46e9507372f0b1b963James Dong
3000c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
3010c1bc742181ded4930842b46e9507372f0b1b963James Dong
3020c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid h264bsdInterpolateChromaHorVer(
3030c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *ref,
3040c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *predPartChroma,
3050c1bc742181ded4930842b46e9507372f0b1b963James Dong  i32 x0,
3060c1bc742181ded4930842b46e9507372f0b1b963James Dong  i32 y0,
3070c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 width,
3080c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 height,
3090c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 xFrac,
3100c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 yFrac,
3110c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 chromaPartWidth,
3120c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 chromaPartHeight)
3130c1bc742181ded4930842b46e9507372f0b1b963James Dong{
3140c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 block[9*9*2];
3150c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 x, y, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, valX, valY, plus32 = 32;
3160c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 comp;
3170c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 *ptrA, *cbr;
3180c1bc742181ded4930842b46e9507372f0b1b963James Dong
3190c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
3200c1bc742181ded4930842b46e9507372f0b1b963James Dong
3210c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(predPartChroma);
3220c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(chromaPartWidth);
3230c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(chromaPartHeight);
3240c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(xFrac < 8);
3250c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(yFrac < 8);
3260c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(ref);
3270c1bc742181ded4930842b46e9507372f0b1b963James Dong
3280c1bc742181ded4930842b46e9507372f0b1b963James Dong    if ((x0 < 0) || ((u32)x0+chromaPartWidth+1 > width) ||
3290c1bc742181ded4930842b46e9507372f0b1b963James Dong        (y0 < 0) || ((u32)y0+chromaPartHeight+1 > height))
3300c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
3310c1bc742181ded4930842b46e9507372f0b1b963James Dong        h264bsdFillBlock(ref, block, x0, y0, width, height,
3320c1bc742181ded4930842b46e9507372f0b1b963James Dong            chromaPartWidth + 1, chromaPartHeight + 1, chromaPartWidth + 1);
3330c1bc742181ded4930842b46e9507372f0b1b963James Dong        ref += width * height;
3340c1bc742181ded4930842b46e9507372f0b1b963James Dong        h264bsdFillBlock(ref, block + (chromaPartWidth+1)*(chromaPartHeight+1),
3350c1bc742181ded4930842b46e9507372f0b1b963James Dong            x0, y0, width, height, chromaPartWidth + 1,
3360c1bc742181ded4930842b46e9507372f0b1b963James Dong            chromaPartHeight + 1, chromaPartWidth + 1);
3370c1bc742181ded4930842b46e9507372f0b1b963James Dong
3380c1bc742181ded4930842b46e9507372f0b1b963James Dong        ref = block;
3390c1bc742181ded4930842b46e9507372f0b1b963James Dong        x0 = 0;
3400c1bc742181ded4930842b46e9507372f0b1b963James Dong        y0 = 0;
3410c1bc742181ded4930842b46e9507372f0b1b963James Dong        width = chromaPartWidth+1;
3420c1bc742181ded4930842b46e9507372f0b1b963James Dong        height = chromaPartHeight+1;
3430c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
3440c1bc742181ded4930842b46e9507372f0b1b963James Dong
3450c1bc742181ded4930842b46e9507372f0b1b963James Dong    valX = 8 - xFrac;
3460c1bc742181ded4930842b46e9507372f0b1b963James Dong    valY = 8 - yFrac;
3470c1bc742181ded4930842b46e9507372f0b1b963James Dong
3480c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (comp = 0; comp <= 1; comp++)
3490c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
3500c1bc742181ded4930842b46e9507372f0b1b963James Dong
3510c1bc742181ded4930842b46e9507372f0b1b963James Dong        ptrA = ref + (comp * height + (u32)y0) * width + x0;
3520c1bc742181ded4930842b46e9507372f0b1b963James Dong        cbr = predPartChroma + comp * 8 * 8;
3530c1bc742181ded4930842b46e9507372f0b1b963James Dong
3540c1bc742181ded4930842b46e9507372f0b1b963James Dong        /* 2x2 pels per iteration
3550c1bc742181ded4930842b46e9507372f0b1b963James Dong         * bilinear vertical and horizontal interpolation */
3560c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (y = (chromaPartHeight >> 1); y; y--)
3570c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
3580c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = *ptrA;
3590c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 = ptrA[width];
3600c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 = ptrA[width*2];
3610c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 *= valY;
3620c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 += tmp3 * yFrac;
3630c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 *= valY;
3640c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 += tmp5 * yFrac;
3650c1bc742181ded4930842b46e9507372f0b1b963James Dong            for (x = (chromaPartWidth >> 1); x; x--)
3660c1bc742181ded4930842b46e9507372f0b1b963James Dong            {
3670c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp2 = *++ptrA;
3680c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp4 = ptrA[width];
3690c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp6 = ptrA[width*2];
3700c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp2 *= valY;
3710c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp2 += tmp4 * yFrac;
3720c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp4 *= valY;
3730c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp4 += tmp6 * yFrac;
3740c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp1 = tmp1 * valX + plus32;
3750c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp3 = tmp3 * valX + plus32;
3760c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp1 += tmp2 * xFrac;
3770c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp1 >>= 6;
3780c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp3 += tmp4 * xFrac;
3790c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp3 >>= 6;
3800c1bc742181ded4930842b46e9507372f0b1b963James Dong                cbr[8] = (u8)tmp3;
3810c1bc742181ded4930842b46e9507372f0b1b963James Dong                *cbr++ = (u8)tmp1;
3820c1bc742181ded4930842b46e9507372f0b1b963James Dong
3830c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp1 = *++ptrA;
3840c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp3 = ptrA[width];
3850c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp5 = ptrA[width*2];
3860c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp1 *= valY;
3870c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp1 += tmp3 * yFrac;
3880c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp3 *= valY;
3890c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp3 += tmp5 * yFrac;
3900c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp2 = tmp2 * valX + plus32;
3910c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp4 = tmp4 * valX + plus32;
3920c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp2 += tmp1 * xFrac;
3930c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp2 >>= 6;
3940c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp4 += tmp3 * xFrac;
3950c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp4 >>= 6;
3960c1bc742181ded4930842b46e9507372f0b1b963James Dong                cbr[8] = (u8)tmp4;
3970c1bc742181ded4930842b46e9507372f0b1b963James Dong                *cbr++ = (u8)tmp2;
3980c1bc742181ded4930842b46e9507372f0b1b963James Dong            }
3990c1bc742181ded4930842b46e9507372f0b1b963James Dong            cbr += 2*8 - chromaPartWidth;
4000c1bc742181ded4930842b46e9507372f0b1b963James Dong            ptrA += 2*width - chromaPartWidth;
4010c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
4020c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
4030c1bc742181ded4930842b46e9507372f0b1b963James Dong
4040c1bc742181ded4930842b46e9507372f0b1b963James Dong}
4050c1bc742181ded4930842b46e9507372f0b1b963James Dong
4060c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
4070c1bc742181ded4930842b46e9507372f0b1b963James Dong
4080c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: PredictChroma
4090c1bc742181ded4930842b46e9507372f0b1b963James Dong
4100c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
4110c1bc742181ded4930842b46e9507372f0b1b963James Dong          Top level chroma prediction function that calls the appropriate
4120c1bc742181ded4930842b46e9507372f0b1b963James Dong          interpolation function. The output is written to macroblock array.
4130c1bc742181ded4930842b46e9507372f0b1b963James Dong
4140c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
4150c1bc742181ded4930842b46e9507372f0b1b963James Dong
4160c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic void PredictChroma(
4170c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *mbPartChroma,
4180c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 xAL,
4190c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 yAL,
4200c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 partWidth,
4210c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 partHeight,
4220c1bc742181ded4930842b46e9507372f0b1b963James Dong  mv_t *mv,
4230c1bc742181ded4930842b46e9507372f0b1b963James Dong  image_t *refPic)
4240c1bc742181ded4930842b46e9507372f0b1b963James Dong{
4250c1bc742181ded4930842b46e9507372f0b1b963James Dong
4260c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
4270c1bc742181ded4930842b46e9507372f0b1b963James Dong
4280c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 xFrac, yFrac, width, height, chromaPartWidth, chromaPartHeight;
4290c1bc742181ded4930842b46e9507372f0b1b963James Dong    i32 xInt, yInt;
4300c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 *ref;
4310c1bc742181ded4930842b46e9507372f0b1b963James Dong
4320c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
4330c1bc742181ded4930842b46e9507372f0b1b963James Dong
4340c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(mv);
4350c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(refPic);
4360c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(refPic->data);
4370c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(refPic->width);
4380c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(refPic->height);
4390c1bc742181ded4930842b46e9507372f0b1b963James Dong
4400c1bc742181ded4930842b46e9507372f0b1b963James Dong    width  = 8 * refPic->width;
4410c1bc742181ded4930842b46e9507372f0b1b963James Dong    height = 8 * refPic->height;
4420c1bc742181ded4930842b46e9507372f0b1b963James Dong
4430c1bc742181ded4930842b46e9507372f0b1b963James Dong    xInt = (xAL >> 1) + (mv->hor >> 3);
4440c1bc742181ded4930842b46e9507372f0b1b963James Dong    yInt = (yAL >> 1) + (mv->ver >> 3);
4450c1bc742181ded4930842b46e9507372f0b1b963James Dong    xFrac = mv->hor & 0x7;
4460c1bc742181ded4930842b46e9507372f0b1b963James Dong    yFrac = mv->ver & 0x7;
4470c1bc742181ded4930842b46e9507372f0b1b963James Dong
4480c1bc742181ded4930842b46e9507372f0b1b963James Dong    chromaPartWidth  = partWidth >> 1;
4490c1bc742181ded4930842b46e9507372f0b1b963James Dong    chromaPartHeight = partHeight >> 1;
4500c1bc742181ded4930842b46e9507372f0b1b963James Dong    ref = refPic->data + 256 * refPic->width * refPic->height;
4510c1bc742181ded4930842b46e9507372f0b1b963James Dong
4520c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (xFrac && yFrac)
4530c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
4540c1bc742181ded4930842b46e9507372f0b1b963James Dong        h264bsdInterpolateChromaHorVer(ref, mbPartChroma, xInt, yInt, width,
4550c1bc742181ded4930842b46e9507372f0b1b963James Dong                height, xFrac, yFrac, chromaPartWidth, chromaPartHeight);
4560c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
4570c1bc742181ded4930842b46e9507372f0b1b963James Dong    else if (xFrac)
4580c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
4590c1bc742181ded4930842b46e9507372f0b1b963James Dong        h264bsdInterpolateChromaHor(ref, mbPartChroma, xInt, yInt, width,
4600c1bc742181ded4930842b46e9507372f0b1b963James Dong                height, xFrac, chromaPartWidth, chromaPartHeight);
4610c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
4620c1bc742181ded4930842b46e9507372f0b1b963James Dong    else if (yFrac)
4630c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
4640c1bc742181ded4930842b46e9507372f0b1b963James Dong        h264bsdInterpolateChromaVer(ref, mbPartChroma, xInt, yInt, width,
4650c1bc742181ded4930842b46e9507372f0b1b963James Dong                height, yFrac, chromaPartWidth, chromaPartHeight);
4660c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
4670c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
4680c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
4690c1bc742181ded4930842b46e9507372f0b1b963James Dong        h264bsdFillBlock(ref, mbPartChroma, xInt, yInt, width, height,
4700c1bc742181ded4930842b46e9507372f0b1b963James Dong            chromaPartWidth, chromaPartHeight, 8);
4710c1bc742181ded4930842b46e9507372f0b1b963James Dong        ref += width * height;
4720c1bc742181ded4930842b46e9507372f0b1b963James Dong        h264bsdFillBlock(ref, mbPartChroma + 8*8, xInt, yInt, width, height,
4730c1bc742181ded4930842b46e9507372f0b1b963James Dong            chromaPartWidth, chromaPartHeight, 8);
4740c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
4750c1bc742181ded4930842b46e9507372f0b1b963James Dong
4760c1bc742181ded4930842b46e9507372f0b1b963James Dong}
4770c1bc742181ded4930842b46e9507372f0b1b963James Dong
4780c1bc742181ded4930842b46e9507372f0b1b963James Dong
4790c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
4800c1bc742181ded4930842b46e9507372f0b1b963James Dong
4810c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: h264bsdInterpolateVerHalf
4820c1bc742181ded4930842b46e9507372f0b1b963James Dong
4830c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
4840c1bc742181ded4930842b46e9507372f0b1b963James Dong          Function to perform vertical interpolation of pixel position 'h'
4850c1bc742181ded4930842b46e9507372f0b1b963James Dong          for a block. Overfilling is done only if needed. Reference
4860c1bc742181ded4930842b46e9507372f0b1b963James Dong          image (ref) is read at correct position and the predicted part
4870c1bc742181ded4930842b46e9507372f0b1b963James Dong          is written to macroblock array (mb)
4880c1bc742181ded4930842b46e9507372f0b1b963James Dong
4890c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
4900c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifndef H264DEC_ARM11
4910c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid h264bsdInterpolateVerHalf(
4920c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *ref,
4930c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *mb,
4940c1bc742181ded4930842b46e9507372f0b1b963James Dong  i32 x0,
4950c1bc742181ded4930842b46e9507372f0b1b963James Dong  i32 y0,
4960c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 width,
4970c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 height,
4980c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 partWidth,
4990c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 partHeight)
5000c1bc742181ded4930842b46e9507372f0b1b963James Dong{
5010c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 p1[21*21/4+1];
5020c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 i, j;
5030c1bc742181ded4930842b46e9507372f0b1b963James Dong    i32 tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
5040c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 *ptrC, *ptrV;
5050c1bc742181ded4930842b46e9507372f0b1b963James Dong    const u8 *clp = h264bsdClip + 512;
5060c1bc742181ded4930842b46e9507372f0b1b963James Dong
5070c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* Code */
5080c1bc742181ded4930842b46e9507372f0b1b963James Dong
5090c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(ref);
5100c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(mb);
5110c1bc742181ded4930842b46e9507372f0b1b963James Dong
5120c1bc742181ded4930842b46e9507372f0b1b963James Dong    if ((x0 < 0) || ((u32)x0+partWidth > width) ||
5130c1bc742181ded4930842b46e9507372f0b1b963James Dong        (y0 < 0) || ((u32)y0+partHeight+5 > height))
5140c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
5150c1bc742181ded4930842b46e9507372f0b1b963James Dong        h264bsdFillBlock(ref, (u8*)p1, x0, y0, width, height,
5160c1bc742181ded4930842b46e9507372f0b1b963James Dong                partWidth, partHeight+5, partWidth);
5170c1bc742181ded4930842b46e9507372f0b1b963James Dong
5180c1bc742181ded4930842b46e9507372f0b1b963James Dong        x0 = 0;
5190c1bc742181ded4930842b46e9507372f0b1b963James Dong        y0 = 0;
5200c1bc742181ded4930842b46e9507372f0b1b963James Dong        ref = (u8*)p1;
5210c1bc742181ded4930842b46e9507372f0b1b963James Dong        width = partWidth;
5220c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
5230c1bc742181ded4930842b46e9507372f0b1b963James Dong
5240c1bc742181ded4930842b46e9507372f0b1b963James Dong    ref += (u32)y0 * width + (u32)x0;
5250c1bc742181ded4930842b46e9507372f0b1b963James Dong
5260c1bc742181ded4930842b46e9507372f0b1b963James Dong    ptrC = ref + width;
5270c1bc742181ded4930842b46e9507372f0b1b963James Dong    ptrV = ptrC + 5*width;
5280c1bc742181ded4930842b46e9507372f0b1b963James Dong
5290c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* 4 pixels per iteration, interpolate using 5 vertical samples */
5300c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (i = (partHeight >> 2); i; i--)
5310c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
5320c1bc742181ded4930842b46e9507372f0b1b963James Dong        /* h1 = (16 + A + 16(G+M) + 4(G+M) - 4(C+R) - (C+R) + T) >> 5 */
5330c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (j = partWidth; j; j--)
5340c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
5350c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 = ptrV[-(i32)width*2];
5360c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 = ptrV[-(i32)width];
5370c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = ptrV[width];
5380c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 = ptrV[width*2];
5390c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 = *ptrV++;
5400c1bc742181ded4930842b46e9507372f0b1b963James Dong
5410c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp4 + tmp1;
5420c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 -= (tmp7 << 2);
5430c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 -= tmp7;
5440c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 += 16;
5450c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp5 + tmp6;
5460c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 = ptrC[width*2];
5470c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 += (tmp7 << 4);
5480c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 += (tmp7 << 2);
5490c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 += tmp3;
5500c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 = clp[tmp2>>5];
5510c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 += 16;
5520c1bc742181ded4930842b46e9507372f0b1b963James Dong            mb[48] = (u8)tmp2;
5530c1bc742181ded4930842b46e9507372f0b1b963James Dong
5540c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp3 + tmp6;
5550c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 -= (tmp7 << 2);
5560c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 -= tmp7;
5570c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp4 + tmp5;
5580c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 = ptrC[width];
5590c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 += (tmp7 << 4);
5600c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 += (tmp7 << 2);
5610c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 += tmp2;
5620c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = clp[tmp1>>5];
5630c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += 16;
5640c1bc742181ded4930842b46e9507372f0b1b963James Dong            mb[32] = (u8)tmp1;
5650c1bc742181ded4930842b46e9507372f0b1b963James Dong
5660c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp2 + tmp5;
5670c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 -= (tmp7 << 2);
5680c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 -= tmp7;
5690c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp4 + tmp3;
5700c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = *ptrC;
5710c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += (tmp7 << 4);
5720c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += (tmp7 << 2);
5730c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += tmp1;
5740c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 = clp[tmp6>>5];
5750c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += 16;
5760c1bc742181ded4930842b46e9507372f0b1b963James Dong            mb[16] = (u8)tmp6;
5770c1bc742181ded4930842b46e9507372f0b1b963James Dong
5780c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 += tmp4;
5790c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 -= (tmp1 << 2);
5800c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 -= tmp1;
5810c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 += tmp2;
5820c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 = ptrC[-(i32)width];
5830c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += (tmp3 << 4);
5840c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += (tmp3 << 2);
5850c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += tmp6;
5860c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 = clp[tmp5>>5];
5870c1bc742181ded4930842b46e9507372f0b1b963James Dong            *mb++ = (u8)tmp5;
5880c1bc742181ded4930842b46e9507372f0b1b963James Dong            ptrC++;
5890c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
5900c1bc742181ded4930842b46e9507372f0b1b963James Dong        ptrC += 4*width - partWidth;
5910c1bc742181ded4930842b46e9507372f0b1b963James Dong        ptrV += 4*width - partWidth;
5920c1bc742181ded4930842b46e9507372f0b1b963James Dong        mb += 4*16 - partWidth;
5930c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
5940c1bc742181ded4930842b46e9507372f0b1b963James Dong
5950c1bc742181ded4930842b46e9507372f0b1b963James Dong}
5960c1bc742181ded4930842b46e9507372f0b1b963James Dong
5970c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
5980c1bc742181ded4930842b46e9507372f0b1b963James Dong
5990c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: h264bsdInterpolateVerQuarter
6000c1bc742181ded4930842b46e9507372f0b1b963James Dong
6010c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
6020c1bc742181ded4930842b46e9507372f0b1b963James Dong          Function to perform vertical interpolation of pixel position 'd'
6030c1bc742181ded4930842b46e9507372f0b1b963James Dong          or 'n' for a block. Overfilling is done only if needed. Reference
6040c1bc742181ded4930842b46e9507372f0b1b963James Dong          image (ref) is read at correct position and the predicted part
6050c1bc742181ded4930842b46e9507372f0b1b963James Dong          is written to macroblock array (mb)
6060c1bc742181ded4930842b46e9507372f0b1b963James Dong
6070c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
6080c1bc742181ded4930842b46e9507372f0b1b963James Dong
6090c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid h264bsdInterpolateVerQuarter(
6100c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *ref,
6110c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *mb,
6120c1bc742181ded4930842b46e9507372f0b1b963James Dong  i32 x0,
6130c1bc742181ded4930842b46e9507372f0b1b963James Dong  i32 y0,
6140c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 width,
6150c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 height,
6160c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 partWidth,
6170c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 partHeight,
6180c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 verOffset)    /* 0 for pixel d, 1 for pixel n */
6190c1bc742181ded4930842b46e9507372f0b1b963James Dong{
6200c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 p1[21*21/4+1];
6210c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 i, j;
6220c1bc742181ded4930842b46e9507372f0b1b963James Dong    i32 tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
6230c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 *ptrC, *ptrV, *ptrInt;
6240c1bc742181ded4930842b46e9507372f0b1b963James Dong    const u8 *clp = h264bsdClip + 512;
6250c1bc742181ded4930842b46e9507372f0b1b963James Dong
6260c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* Code */
6270c1bc742181ded4930842b46e9507372f0b1b963James Dong
6280c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(ref);
6290c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(mb);
6300c1bc742181ded4930842b46e9507372f0b1b963James Dong
6310c1bc742181ded4930842b46e9507372f0b1b963James Dong    if ((x0 < 0) || ((u32)x0+partWidth > width) ||
6320c1bc742181ded4930842b46e9507372f0b1b963James Dong        (y0 < 0) || ((u32)y0+partHeight+5 > height))
6330c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
6340c1bc742181ded4930842b46e9507372f0b1b963James Dong        h264bsdFillBlock(ref, (u8*)p1, x0, y0, width, height,
6350c1bc742181ded4930842b46e9507372f0b1b963James Dong                partWidth, partHeight+5, partWidth);
6360c1bc742181ded4930842b46e9507372f0b1b963James Dong
6370c1bc742181ded4930842b46e9507372f0b1b963James Dong        x0 = 0;
6380c1bc742181ded4930842b46e9507372f0b1b963James Dong        y0 = 0;
6390c1bc742181ded4930842b46e9507372f0b1b963James Dong        ref = (u8*)p1;
6400c1bc742181ded4930842b46e9507372f0b1b963James Dong        width = partWidth;
6410c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
6420c1bc742181ded4930842b46e9507372f0b1b963James Dong
6430c1bc742181ded4930842b46e9507372f0b1b963James Dong    ref += (u32)y0 * width + (u32)x0;
6440c1bc742181ded4930842b46e9507372f0b1b963James Dong
6450c1bc742181ded4930842b46e9507372f0b1b963James Dong    ptrC = ref + width;
6460c1bc742181ded4930842b46e9507372f0b1b963James Dong    ptrV = ptrC + 5*width;
6470c1bc742181ded4930842b46e9507372f0b1b963James Dong
6480c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* Pointer to integer sample position, either M or R */
6490c1bc742181ded4930842b46e9507372f0b1b963James Dong    ptrInt = ptrC + (2+verOffset)*width;
6500c1bc742181ded4930842b46e9507372f0b1b963James Dong
6510c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* 4 pixels per iteration
6520c1bc742181ded4930842b46e9507372f0b1b963James Dong     * interpolate using 5 vertical samples and average between
6530c1bc742181ded4930842b46e9507372f0b1b963James Dong     * interpolated value and integer sample value */
6540c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (i = (partHeight >> 2); i; i--)
6550c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
6560c1bc742181ded4930842b46e9507372f0b1b963James Dong        /* h1 = (16 + A + 16(G+M) + 4(G+M) - 4(C+R) - (C+R) + T) >> 5 */
6570c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (j = partWidth; j; j--)
6580c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
6590c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 = ptrV[-(i32)width*2];
6600c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 = ptrV[-(i32)width];
6610c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = ptrV[width];
6620c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 = ptrV[width*2];
6630c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 = *ptrV++;
6640c1bc742181ded4930842b46e9507372f0b1b963James Dong
6650c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp4 + tmp1;
6660c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 -= (tmp7 << 2);
6670c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 -= tmp7;
6680c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 += 16;
6690c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp5 + tmp6;
6700c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 = ptrC[width*2];
6710c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 += (tmp7 << 4);
6720c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 += (tmp7 << 2);
6730c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 += tmp3;
6740c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 = clp[tmp2>>5];
6750c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = ptrInt[width*2];
6760c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 += 16;
6770c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2++;
6780c1bc742181ded4930842b46e9507372f0b1b963James Dong            mb[48] = (u8)((tmp2 + tmp7) >> 1);
6790c1bc742181ded4930842b46e9507372f0b1b963James Dong
6800c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp3 + tmp6;
6810c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 -= (tmp7 << 2);
6820c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 -= tmp7;
6830c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp4 + tmp5;
6840c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 = ptrC[width];
6850c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 += (tmp7 << 4);
6860c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 += (tmp7 << 2);
6870c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 += tmp2;
6880c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = clp[tmp1>>5];
6890c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = ptrInt[width];
6900c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += 16;
6910c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1++;
6920c1bc742181ded4930842b46e9507372f0b1b963James Dong            mb[32] = (u8)((tmp1 + tmp7) >> 1);
6930c1bc742181ded4930842b46e9507372f0b1b963James Dong
6940c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp2 + tmp5;
6950c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 -= (tmp7 << 2);
6960c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 -= tmp7;
6970c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp4 + tmp3;
6980c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = *ptrC;
6990c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += (tmp7 << 4);
7000c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += (tmp7 << 2);
7010c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += tmp1;
7020c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 = clp[tmp6>>5];
7030c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = *ptrInt;
7040c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += 16;
7050c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6++;
7060c1bc742181ded4930842b46e9507372f0b1b963James Dong            mb[16] = (u8)((tmp6 + tmp7) >> 1);
7070c1bc742181ded4930842b46e9507372f0b1b963James Dong
7080c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 += tmp4;
7090c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 -= (tmp1 << 2);
7100c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 -= tmp1;
7110c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 += tmp2;
7120c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 = ptrC[-(i32)width];
7130c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += (tmp3 << 4);
7140c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += (tmp3 << 2);
7150c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += tmp6;
7160c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 = clp[tmp5>>5];
7170c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = ptrInt[-(i32)width];
7180c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5++;
7190c1bc742181ded4930842b46e9507372f0b1b963James Dong            *mb++ = (u8)((tmp5 + tmp7) >> 1);
7200c1bc742181ded4930842b46e9507372f0b1b963James Dong            ptrC++;
7210c1bc742181ded4930842b46e9507372f0b1b963James Dong            ptrInt++;
7220c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
7230c1bc742181ded4930842b46e9507372f0b1b963James Dong        ptrC += 4*width - partWidth;
7240c1bc742181ded4930842b46e9507372f0b1b963James Dong        ptrV += 4*width - partWidth;
7250c1bc742181ded4930842b46e9507372f0b1b963James Dong        ptrInt += 4*width - partWidth;
7260c1bc742181ded4930842b46e9507372f0b1b963James Dong        mb += 4*16 - partWidth;
7270c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
7280c1bc742181ded4930842b46e9507372f0b1b963James Dong
7290c1bc742181ded4930842b46e9507372f0b1b963James Dong}
7300c1bc742181ded4930842b46e9507372f0b1b963James Dong
7310c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
7320c1bc742181ded4930842b46e9507372f0b1b963James Dong
7330c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: h264bsdInterpolateHorHalf
7340c1bc742181ded4930842b46e9507372f0b1b963James Dong
7350c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
7360c1bc742181ded4930842b46e9507372f0b1b963James Dong          Function to perform horizontal interpolation of pixel position 'b'
7370c1bc742181ded4930842b46e9507372f0b1b963James Dong          for a block. Overfilling is done only if needed. Reference
7380c1bc742181ded4930842b46e9507372f0b1b963James Dong          image (ref) is read at correct position and the predicted part
7390c1bc742181ded4930842b46e9507372f0b1b963James Dong          is written to macroblock array (mb)
7400c1bc742181ded4930842b46e9507372f0b1b963James Dong
7410c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
7420c1bc742181ded4930842b46e9507372f0b1b963James Dong
7430c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid h264bsdInterpolateHorHalf(
7440c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *ref,
7450c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *mb,
7460c1bc742181ded4930842b46e9507372f0b1b963James Dong  i32 x0,
7470c1bc742181ded4930842b46e9507372f0b1b963James Dong  i32 y0,
7480c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 width,
7490c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 height,
7500c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 partWidth,
7510c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 partHeight)
7520c1bc742181ded4930842b46e9507372f0b1b963James Dong{
7530c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 p1[21*21/4+1];
7540c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 *ptrJ;
7550c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 x, y;
7560c1bc742181ded4930842b46e9507372f0b1b963James Dong    i32 tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
7570c1bc742181ded4930842b46e9507372f0b1b963James Dong    const u8 *clp = h264bsdClip + 512;
7580c1bc742181ded4930842b46e9507372f0b1b963James Dong
7590c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* Code */
7600c1bc742181ded4930842b46e9507372f0b1b963James Dong
7610c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(ref);
7620c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(mb);
7630c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT((partWidth&0x3) == 0);
7640c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT((partHeight&0x3) == 0);
7650c1bc742181ded4930842b46e9507372f0b1b963James Dong
7660c1bc742181ded4930842b46e9507372f0b1b963James Dong    if ((x0 < 0) || ((u32)x0+partWidth+5 > width) ||
7670c1bc742181ded4930842b46e9507372f0b1b963James Dong        (y0 < 0) || ((u32)y0+partHeight > height))
7680c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
7690c1bc742181ded4930842b46e9507372f0b1b963James Dong        h264bsdFillBlock(ref, (u8*)p1, x0, y0, width, height,
7700c1bc742181ded4930842b46e9507372f0b1b963James Dong                partWidth+5, partHeight, partWidth+5);
7710c1bc742181ded4930842b46e9507372f0b1b963James Dong
7720c1bc742181ded4930842b46e9507372f0b1b963James Dong        x0 = 0;
7730c1bc742181ded4930842b46e9507372f0b1b963James Dong        y0 = 0;
7740c1bc742181ded4930842b46e9507372f0b1b963James Dong        ref = (u8*)p1;
7750c1bc742181ded4930842b46e9507372f0b1b963James Dong        width = partWidth + 5;
7760c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
7770c1bc742181ded4930842b46e9507372f0b1b963James Dong
7780c1bc742181ded4930842b46e9507372f0b1b963James Dong    ref += (u32)y0 * width + (u32)x0;
7790c1bc742181ded4930842b46e9507372f0b1b963James Dong
7800c1bc742181ded4930842b46e9507372f0b1b963James Dong    ptrJ = ref + 5;
7810c1bc742181ded4930842b46e9507372f0b1b963James Dong
7820c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (y = partHeight; y; y--)
7830c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
7840c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp6 = *(ptrJ - 5);
7850c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp5 = *(ptrJ - 4);
7860c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp4 = *(ptrJ - 3);
7870c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp3 = *(ptrJ - 2);
7880c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp2 = *(ptrJ - 1);
7890c1bc742181ded4930842b46e9507372f0b1b963James Dong
7900c1bc742181ded4930842b46e9507372f0b1b963James Dong        /* calculate 4 pels per iteration */
7910c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (x = (partWidth >> 2); x; x--)
7920c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
7930c1bc742181ded4930842b46e9507372f0b1b963James Dong            /* First pixel */
7940c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += 16;
7950c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp3 + tmp4;
7960c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += (tmp7 << 4);
7970c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += (tmp7 << 2);
7980c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp2 + tmp5;
7990c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = *ptrJ++;
8000c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 -= (tmp7 << 2);
8010c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 -= tmp7;
8020c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += tmp1;
8030c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 = clp[tmp6>>5];
8040c1bc742181ded4930842b46e9507372f0b1b963James Dong            /* Second pixel */
8050c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += 16;
8060c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp2 + tmp3;
8070c1bc742181ded4930842b46e9507372f0b1b963James Dong            *mb++ = (u8)tmp6;
8080c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += (tmp7 << 4);
8090c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += (tmp7 << 2);
8100c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp1 + tmp4;
8110c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 = *ptrJ++;
8120c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 -= (tmp7 << 2);
8130c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 -= tmp7;
8140c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += tmp6;
8150c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 = clp[tmp5>>5];
8160c1bc742181ded4930842b46e9507372f0b1b963James Dong            /* Third pixel */
8170c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 += 16;
8180c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp1 + tmp2;
8190c1bc742181ded4930842b46e9507372f0b1b963James Dong            *mb++ = (u8)tmp5;
8200c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 += (tmp7 << 4);
8210c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 += (tmp7 << 2);
8220c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp6 + tmp3;
8230c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 = *ptrJ++;
8240c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 -= (tmp7 << 2);
8250c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 -= tmp7;
8260c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 += tmp5;
8270c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 = clp[tmp4>>5];
8280c1bc742181ded4930842b46e9507372f0b1b963James Dong            /* Fourth pixel */
8290c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 += 16;
8300c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp6 + tmp1;
8310c1bc742181ded4930842b46e9507372f0b1b963James Dong            *mb++ = (u8)tmp4;
8320c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 += (tmp7 << 4);
8330c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 += (tmp7 << 2);
8340c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp5 + tmp2;
8350c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 = *ptrJ++;
8360c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 -= (tmp7 << 2);
8370c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 -= tmp7;
8380c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 += tmp4;
8390c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 = clp[tmp3>>5];
8400c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp4;
8410c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 = tmp6;
8420c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 = tmp2;
8430c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 = tmp7;
8440c1bc742181ded4930842b46e9507372f0b1b963James Dong            *mb++ = (u8)tmp3;
8450c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 = tmp5;
8460c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 = tmp1;
8470c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
8480c1bc742181ded4930842b46e9507372f0b1b963James Dong        ptrJ += width - partWidth;
8490c1bc742181ded4930842b46e9507372f0b1b963James Dong        mb += 16 - partWidth;
8500c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
8510c1bc742181ded4930842b46e9507372f0b1b963James Dong
8520c1bc742181ded4930842b46e9507372f0b1b963James Dong}
8530c1bc742181ded4930842b46e9507372f0b1b963James Dong
8540c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
8550c1bc742181ded4930842b46e9507372f0b1b963James Dong
8560c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: h264bsdInterpolateHorQuarter
8570c1bc742181ded4930842b46e9507372f0b1b963James Dong
8580c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
8590c1bc742181ded4930842b46e9507372f0b1b963James Dong          Function to perform horizontal interpolation of pixel position 'a'
8600c1bc742181ded4930842b46e9507372f0b1b963James Dong          or 'c' for a block. Overfilling is done only if needed. Reference
8610c1bc742181ded4930842b46e9507372f0b1b963James Dong          image (ref) is read at correct position and the predicted part
8620c1bc742181ded4930842b46e9507372f0b1b963James Dong          is written to macroblock array (mb)
8630c1bc742181ded4930842b46e9507372f0b1b963James Dong
8640c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
8650c1bc742181ded4930842b46e9507372f0b1b963James Dong
8660c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid h264bsdInterpolateHorQuarter(
8670c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *ref,
8680c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *mb,
8690c1bc742181ded4930842b46e9507372f0b1b963James Dong  i32 x0,
8700c1bc742181ded4930842b46e9507372f0b1b963James Dong  i32 y0,
8710c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 width,
8720c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 height,
8730c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 partWidth,
8740c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 partHeight,
8750c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 horOffset) /* 0 for pixel a, 1 for pixel c */
8760c1bc742181ded4930842b46e9507372f0b1b963James Dong{
8770c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 p1[21*21/4+1];
8780c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 *ptrJ;
8790c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 x, y;
8800c1bc742181ded4930842b46e9507372f0b1b963James Dong    i32 tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
8810c1bc742181ded4930842b46e9507372f0b1b963James Dong    const u8 *clp = h264bsdClip + 512;
8820c1bc742181ded4930842b46e9507372f0b1b963James Dong
8830c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* Code */
8840c1bc742181ded4930842b46e9507372f0b1b963James Dong
8850c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(ref);
8860c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(mb);
8870c1bc742181ded4930842b46e9507372f0b1b963James Dong
8880c1bc742181ded4930842b46e9507372f0b1b963James Dong    if ((x0 < 0) || ((u32)x0+partWidth+5 > width) ||
8890c1bc742181ded4930842b46e9507372f0b1b963James Dong        (y0 < 0) || ((u32)y0+partHeight > height))
8900c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
8910c1bc742181ded4930842b46e9507372f0b1b963James Dong        h264bsdFillBlock(ref, (u8*)p1, x0, y0, width, height,
8920c1bc742181ded4930842b46e9507372f0b1b963James Dong                partWidth+5, partHeight, partWidth+5);
8930c1bc742181ded4930842b46e9507372f0b1b963James Dong
8940c1bc742181ded4930842b46e9507372f0b1b963James Dong        x0 = 0;
8950c1bc742181ded4930842b46e9507372f0b1b963James Dong        y0 = 0;
8960c1bc742181ded4930842b46e9507372f0b1b963James Dong        ref = (u8*)p1;
8970c1bc742181ded4930842b46e9507372f0b1b963James Dong        width = partWidth + 5;
8980c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
8990c1bc742181ded4930842b46e9507372f0b1b963James Dong
9000c1bc742181ded4930842b46e9507372f0b1b963James Dong    ref += (u32)y0 * width + (u32)x0;
9010c1bc742181ded4930842b46e9507372f0b1b963James Dong
9020c1bc742181ded4930842b46e9507372f0b1b963James Dong    ptrJ = ref + 5;
9030c1bc742181ded4930842b46e9507372f0b1b963James Dong
9040c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (y = partHeight; y; y--)
9050c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
9060c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp6 = *(ptrJ - 5);
9070c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp5 = *(ptrJ - 4);
9080c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp4 = *(ptrJ - 3);
9090c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp3 = *(ptrJ - 2);
9100c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp2 = *(ptrJ - 1);
9110c1bc742181ded4930842b46e9507372f0b1b963James Dong
9120c1bc742181ded4930842b46e9507372f0b1b963James Dong        /* calculate 4 pels per iteration */
9130c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (x = (partWidth >> 2); x; x--)
9140c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
9150c1bc742181ded4930842b46e9507372f0b1b963James Dong            /* First pixel */
9160c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += 16;
9170c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp3 + tmp4;
9180c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += (tmp7 << 4);
9190c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += (tmp7 << 2);
9200c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp2 + tmp5;
9210c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = *ptrJ++;
9220c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 -= (tmp7 << 2);
9230c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 -= tmp7;
9240c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += tmp1;
9250c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 = clp[tmp6>>5];
9260c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += 16;
9270c1bc742181ded4930842b46e9507372f0b1b963James Dong            if (!horOffset)
9280c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp6 += tmp4;
9290c1bc742181ded4930842b46e9507372f0b1b963James Dong            else
9300c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp6 += tmp3;
9310c1bc742181ded4930842b46e9507372f0b1b963James Dong            *mb++ = (u8)((tmp6 + 1) >> 1);
9320c1bc742181ded4930842b46e9507372f0b1b963James Dong            /* Second pixel */
9330c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp2 + tmp3;
9340c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += (tmp7 << 4);
9350c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += (tmp7 << 2);
9360c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp1 + tmp4;
9370c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 = *ptrJ++;
9380c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 -= (tmp7 << 2);
9390c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 -= tmp7;
9400c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += tmp6;
9410c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 = clp[tmp5>>5];
9420c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 += 16;
9430c1bc742181ded4930842b46e9507372f0b1b963James Dong            if (!horOffset)
9440c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp5 += tmp3;
9450c1bc742181ded4930842b46e9507372f0b1b963James Dong            else
9460c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp5 += tmp2;
9470c1bc742181ded4930842b46e9507372f0b1b963James Dong            *mb++ = (u8)((tmp5 + 1) >> 1);
9480c1bc742181ded4930842b46e9507372f0b1b963James Dong            /* Third pixel */
9490c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp1 + tmp2;
9500c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 += (tmp7 << 4);
9510c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 += (tmp7 << 2);
9520c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp6 + tmp3;
9530c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 = *ptrJ++;
9540c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 -= (tmp7 << 2);
9550c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 -= tmp7;
9560c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 += tmp5;
9570c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 = clp[tmp4>>5];
9580c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 += 16;
9590c1bc742181ded4930842b46e9507372f0b1b963James Dong            if (!horOffset)
9600c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp4 += tmp2;
9610c1bc742181ded4930842b46e9507372f0b1b963James Dong            else
9620c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp4 += tmp1;
9630c1bc742181ded4930842b46e9507372f0b1b963James Dong            *mb++ = (u8)((tmp4 + 1) >> 1);
9640c1bc742181ded4930842b46e9507372f0b1b963James Dong            /* Fourth pixel */
9650c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp6 + tmp1;
9660c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 += (tmp7 << 4);
9670c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 += (tmp7 << 2);
9680c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp5 + tmp2;
9690c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 = *ptrJ++;
9700c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 -= (tmp7 << 2);
9710c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 -= tmp7;
9720c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 += tmp4;
9730c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 = clp[tmp3>>5];
9740c1bc742181ded4930842b46e9507372f0b1b963James Dong            if (!horOffset)
9750c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp3 += tmp1;
9760c1bc742181ded4930842b46e9507372f0b1b963James Dong            else
9770c1bc742181ded4930842b46e9507372f0b1b963James Dong                tmp3 += tmp6;
9780c1bc742181ded4930842b46e9507372f0b1b963James Dong            *mb++ = (u8)((tmp3 + 1) >> 1);
9790c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 = tmp5;
9800c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 = tmp1;
9810c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp4;
9820c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 = tmp6;
9830c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 = tmp2;
9840c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 = tmp7;
9850c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
9860c1bc742181ded4930842b46e9507372f0b1b963James Dong        ptrJ += width - partWidth;
9870c1bc742181ded4930842b46e9507372f0b1b963James Dong        mb += 16 - partWidth;
9880c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
9890c1bc742181ded4930842b46e9507372f0b1b963James Dong
9900c1bc742181ded4930842b46e9507372f0b1b963James Dong}
9910c1bc742181ded4930842b46e9507372f0b1b963James Dong
9920c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
9930c1bc742181ded4930842b46e9507372f0b1b963James Dong
9940c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: h264bsdInterpolateHorVerQuarter
9950c1bc742181ded4930842b46e9507372f0b1b963James Dong
9960c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
9970c1bc742181ded4930842b46e9507372f0b1b963James Dong          Function to perform horizontal and vertical interpolation of pixel
9980c1bc742181ded4930842b46e9507372f0b1b963James Dong          position 'e', 'g', 'p' or 'r' for a block. Overfilling is done only
9990c1bc742181ded4930842b46e9507372f0b1b963James Dong          if needed. Reference image (ref) is read at correct position and
10000c1bc742181ded4930842b46e9507372f0b1b963James Dong          the predicted part is written to macroblock array (mb)
10010c1bc742181ded4930842b46e9507372f0b1b963James Dong
10020c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
10030c1bc742181ded4930842b46e9507372f0b1b963James Dong
10040c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid h264bsdInterpolateHorVerQuarter(
10050c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *ref,
10060c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *mb,
10070c1bc742181ded4930842b46e9507372f0b1b963James Dong  i32 x0,
10080c1bc742181ded4930842b46e9507372f0b1b963James Dong  i32 y0,
10090c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 width,
10100c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 height,
10110c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 partWidth,
10120c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 partHeight,
10130c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 horVerOffset) /* 0 for pixel e, 1 for pixel g,
10140c1bc742181ded4930842b46e9507372f0b1b963James Dong                       2 for pixel p, 3 for pixel r */
10150c1bc742181ded4930842b46e9507372f0b1b963James Dong{
10160c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 p1[21*21/4+1];
10170c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 *ptrC, *ptrJ, *ptrV;
10180c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 x, y;
10190c1bc742181ded4930842b46e9507372f0b1b963James Dong    i32 tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
10200c1bc742181ded4930842b46e9507372f0b1b963James Dong    const u8 *clp = h264bsdClip + 512;
10210c1bc742181ded4930842b46e9507372f0b1b963James Dong
10220c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* Code */
10230c1bc742181ded4930842b46e9507372f0b1b963James Dong
10240c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(ref);
10250c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(mb);
10260c1bc742181ded4930842b46e9507372f0b1b963James Dong
10270c1bc742181ded4930842b46e9507372f0b1b963James Dong    if ((x0 < 0) || ((u32)x0+partWidth+5 > width) ||
10280c1bc742181ded4930842b46e9507372f0b1b963James Dong        (y0 < 0) || ((u32)y0+partHeight+5 > height))
10290c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
10300c1bc742181ded4930842b46e9507372f0b1b963James Dong        h264bsdFillBlock(ref, (u8*)p1, x0, y0, width, height,
10310c1bc742181ded4930842b46e9507372f0b1b963James Dong                partWidth+5, partHeight+5, partWidth+5);
10320c1bc742181ded4930842b46e9507372f0b1b963James Dong
10330c1bc742181ded4930842b46e9507372f0b1b963James Dong        x0 = 0;
10340c1bc742181ded4930842b46e9507372f0b1b963James Dong        y0 = 0;
10350c1bc742181ded4930842b46e9507372f0b1b963James Dong        ref = (u8*)p1;
10360c1bc742181ded4930842b46e9507372f0b1b963James Dong        width = partWidth+5;
10370c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
10380c1bc742181ded4930842b46e9507372f0b1b963James Dong
10390c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* Ref points to G + (-2, -2) */
10400c1bc742181ded4930842b46e9507372f0b1b963James Dong    ref += (u32)y0 * width + (u32)x0;
10410c1bc742181ded4930842b46e9507372f0b1b963James Dong
10420c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* ptrJ points to either J or Q, depending on vertical offset */
10430c1bc742181ded4930842b46e9507372f0b1b963James Dong    ptrJ = ref + (((horVerOffset & 0x2) >> 1) + 2) * width + 5;
10440c1bc742181ded4930842b46e9507372f0b1b963James Dong
10450c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* ptrC points to either C or D, depending on horizontal offset */
10460c1bc742181ded4930842b46e9507372f0b1b963James Dong    ptrC = ref + width + 2 + (horVerOffset & 0x1);
10470c1bc742181ded4930842b46e9507372f0b1b963James Dong
10480c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (y = partHeight; y; y--)
10490c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
10500c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp6 = *(ptrJ - 5);
10510c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp5 = *(ptrJ - 4);
10520c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp4 = *(ptrJ - 3);
10530c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp3 = *(ptrJ - 2);
10540c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp2 = *(ptrJ - 1);
10550c1bc742181ded4930842b46e9507372f0b1b963James Dong
10560c1bc742181ded4930842b46e9507372f0b1b963James Dong        /* Horizontal interpolation, calculate 4 pels per iteration */
10570c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (x = (partWidth >> 2); x; x--)
10580c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
10590c1bc742181ded4930842b46e9507372f0b1b963James Dong            /* First pixel */
10600c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += 16;
10610c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp3 + tmp4;
10620c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += (tmp7 << 4);
10630c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += (tmp7 << 2);
10640c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp2 + tmp5;
10650c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = *ptrJ++;
10660c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 -= (tmp7 << 2);
10670c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 -= tmp7;
10680c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += tmp1;
10690c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 = clp[tmp6>>5];
10700c1bc742181ded4930842b46e9507372f0b1b963James Dong            /* Second pixel */
10710c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += 16;
10720c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp2 + tmp3;
10730c1bc742181ded4930842b46e9507372f0b1b963James Dong            *mb++ = (u8)tmp6;
10740c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += (tmp7 << 4);
10750c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += (tmp7 << 2);
10760c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp1 + tmp4;
10770c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 = *ptrJ++;
10780c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 -= (tmp7 << 2);
10790c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 -= tmp7;
10800c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += tmp6;
10810c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 = clp[tmp5>>5];
10820c1bc742181ded4930842b46e9507372f0b1b963James Dong            /* Third pixel */
10830c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 += 16;
10840c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp1 + tmp2;
10850c1bc742181ded4930842b46e9507372f0b1b963James Dong            *mb++ = (u8)tmp5;
10860c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 += (tmp7 << 4);
10870c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 += (tmp7 << 2);
10880c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp6 + tmp3;
10890c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 = *ptrJ++;
10900c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 -= (tmp7 << 2);
10910c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 -= tmp7;
10920c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 += tmp5;
10930c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 = clp[tmp4>>5];
10940c1bc742181ded4930842b46e9507372f0b1b963James Dong            /* Fourth pixel */
10950c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 += 16;
10960c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp6 + tmp1;
10970c1bc742181ded4930842b46e9507372f0b1b963James Dong            *mb++ = (u8)tmp4;
10980c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 += (tmp7 << 4);
10990c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 += (tmp7 << 2);
11000c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp5 + tmp2;
11010c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 = *ptrJ++;
11020c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 -= (tmp7 << 2);
11030c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 -= tmp7;
11040c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 += tmp4;
11050c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 = clp[tmp3>>5];
11060c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp4;
11070c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 = tmp6;
11080c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 = tmp2;
11090c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 = tmp7;
11100c1bc742181ded4930842b46e9507372f0b1b963James Dong            *mb++ = (u8)tmp3;
11110c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 = tmp5;
11120c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 = tmp1;
11130c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
11140c1bc742181ded4930842b46e9507372f0b1b963James Dong        ptrJ += width - partWidth;
11150c1bc742181ded4930842b46e9507372f0b1b963James Dong        mb += 16 - partWidth;
11160c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
11170c1bc742181ded4930842b46e9507372f0b1b963James Dong
11180c1bc742181ded4930842b46e9507372f0b1b963James Dong    mb -= 16*partHeight;
11190c1bc742181ded4930842b46e9507372f0b1b963James Dong    ptrV = ptrC + 5*width;
11200c1bc742181ded4930842b46e9507372f0b1b963James Dong
11210c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (y = (partHeight >> 2); y; y--)
11220c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
11230c1bc742181ded4930842b46e9507372f0b1b963James Dong        /* Vertical interpolation and averaging, 4 pels per iteration */
11240c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (x = partWidth; x; x--)
11250c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
11260c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 = ptrV[-(i32)width*2];
11270c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 = ptrV[-(i32)width];
11280c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = ptrV[width];
11290c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 = ptrV[width*2];
11300c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 = *ptrV++;
11310c1bc742181ded4930842b46e9507372f0b1b963James Dong
11320c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp4 + tmp1;
11330c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 -= (tmp7 << 2);
11340c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 -= tmp7;
11350c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 += 16;
11360c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp5 + tmp6;
11370c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 = ptrC[width*2];
11380c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 += (tmp7 << 4);
11390c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 += (tmp7 << 2);
11400c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 += tmp3;
11410c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = clp[tmp2>>5];
11420c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 = mb[48];
11430c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 += 16;
11440c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7++;
11450c1bc742181ded4930842b46e9507372f0b1b963James Dong            mb[48] = (u8)((tmp2 + tmp7) >> 1);
11460c1bc742181ded4930842b46e9507372f0b1b963James Dong
11470c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp3 + tmp6;
11480c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 -= (tmp7 << 2);
11490c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 -= tmp7;
11500c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp4 + tmp5;
11510c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 = ptrC[width];
11520c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 += (tmp7 << 4);
11530c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 += (tmp7 << 2);
11540c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 += tmp2;
11550c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = clp[tmp1>>5];
11560c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = mb[32];
11570c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += 16;
11580c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7++;
11590c1bc742181ded4930842b46e9507372f0b1b963James Dong            mb[32] = (u8)((tmp1 + tmp7) >> 1);
11600c1bc742181ded4930842b46e9507372f0b1b963James Dong
11610c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = *ptrC;
11620c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp2 + tmp5;
11630c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 -= (tmp7 << 2);
11640c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 -= tmp7;
11650c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp4 + tmp3;
11660c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += (tmp7 << 4);
11670c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += (tmp7 << 2);
11680c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += tmp1;
11690c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = clp[tmp6>>5];
11700c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 = mb[16];
11710c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += 16;
11720c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7++;
11730c1bc742181ded4930842b46e9507372f0b1b963James Dong            mb[16] = (u8)((tmp6 + tmp7) >> 1);
11740c1bc742181ded4930842b46e9507372f0b1b963James Dong
11750c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 = ptrC[-(i32)width];
11760c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 += tmp4;
11770c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 -= (tmp1 << 2);
11780c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 -= tmp1;
11790c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 += tmp2;
11800c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += (tmp3 << 4);
11810c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += (tmp3 << 2);
11820c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += tmp6;
11830c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = clp[tmp5>>5];
11840c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 = *mb;
11850c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7++;
11860c1bc742181ded4930842b46e9507372f0b1b963James Dong            *mb++ = (u8)((tmp5 + tmp7) >> 1);
11870c1bc742181ded4930842b46e9507372f0b1b963James Dong            ptrC++;
11880c1bc742181ded4930842b46e9507372f0b1b963James Dong
11890c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
11900c1bc742181ded4930842b46e9507372f0b1b963James Dong        ptrC += 4*width - partWidth;
11910c1bc742181ded4930842b46e9507372f0b1b963James Dong        ptrV += 4*width - partWidth;
11920c1bc742181ded4930842b46e9507372f0b1b963James Dong        mb += 4*16 - partWidth;
11930c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
11940c1bc742181ded4930842b46e9507372f0b1b963James Dong
11950c1bc742181ded4930842b46e9507372f0b1b963James Dong}
11960c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif
11970c1bc742181ded4930842b46e9507372f0b1b963James Dong
11980c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
11990c1bc742181ded4930842b46e9507372f0b1b963James Dong
12000c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: h264bsdInterpolateMidHalf
12010c1bc742181ded4930842b46e9507372f0b1b963James Dong
12020c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
12030c1bc742181ded4930842b46e9507372f0b1b963James Dong          Function to perform horizontal and vertical interpolation of pixel
12040c1bc742181ded4930842b46e9507372f0b1b963James Dong          position 'j' for a block. Overfilling is done only if needed.
12050c1bc742181ded4930842b46e9507372f0b1b963James Dong          Reference image (ref) is read at correct position and the predicted
12060c1bc742181ded4930842b46e9507372f0b1b963James Dong          part is written to macroblock array (mb)
12070c1bc742181ded4930842b46e9507372f0b1b963James Dong
12080c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
12090c1bc742181ded4930842b46e9507372f0b1b963James Dong
12100c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid h264bsdInterpolateMidHalf(
12110c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *ref,
12120c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *mb,
12130c1bc742181ded4930842b46e9507372f0b1b963James Dong  i32 x0,
12140c1bc742181ded4930842b46e9507372f0b1b963James Dong  i32 y0,
12150c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 width,
12160c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 height,
12170c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 partWidth,
12180c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 partHeight)
12190c1bc742181ded4930842b46e9507372f0b1b963James Dong{
12200c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 p1[21*21/4+1];
12210c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 x, y;
12220c1bc742181ded4930842b46e9507372f0b1b963James Dong    i32 tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
12230c1bc742181ded4930842b46e9507372f0b1b963James Dong    i32 *ptrC, *ptrV, *b1;
12240c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8  *ptrJ;
12250c1bc742181ded4930842b46e9507372f0b1b963James Dong    i32 table[21*16];
12260c1bc742181ded4930842b46e9507372f0b1b963James Dong    const u8 *clp = h264bsdClip + 512;
12270c1bc742181ded4930842b46e9507372f0b1b963James Dong
12280c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* Code */
12290c1bc742181ded4930842b46e9507372f0b1b963James Dong
12300c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(ref);
12310c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(mb);
12320c1bc742181ded4930842b46e9507372f0b1b963James Dong
12330c1bc742181ded4930842b46e9507372f0b1b963James Dong    if ((x0 < 0) || ((u32)x0+partWidth+5 > width) ||
12340c1bc742181ded4930842b46e9507372f0b1b963James Dong        (y0 < 0) || ((u32)y0+partHeight+5 > height))
12350c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
12360c1bc742181ded4930842b46e9507372f0b1b963James Dong        h264bsdFillBlock(ref, (u8*)p1, x0, y0, width, height,
12370c1bc742181ded4930842b46e9507372f0b1b963James Dong                partWidth+5, partHeight+5, partWidth+5);
12380c1bc742181ded4930842b46e9507372f0b1b963James Dong
12390c1bc742181ded4930842b46e9507372f0b1b963James Dong        x0 = 0;
12400c1bc742181ded4930842b46e9507372f0b1b963James Dong        y0 = 0;
12410c1bc742181ded4930842b46e9507372f0b1b963James Dong        ref = (u8*)p1;
12420c1bc742181ded4930842b46e9507372f0b1b963James Dong        width = partWidth+5;
12430c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
12440c1bc742181ded4930842b46e9507372f0b1b963James Dong
12450c1bc742181ded4930842b46e9507372f0b1b963James Dong    ref += (u32)y0 * width + (u32)x0;
12460c1bc742181ded4930842b46e9507372f0b1b963James Dong
12470c1bc742181ded4930842b46e9507372f0b1b963James Dong    b1 = table;
12480c1bc742181ded4930842b46e9507372f0b1b963James Dong    ptrJ = ref + 5;
12490c1bc742181ded4930842b46e9507372f0b1b963James Dong
12500c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* First step: calculate intermediate values for
12510c1bc742181ded4930842b46e9507372f0b1b963James Dong     * horizontal interpolation */
12520c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (y = partHeight + 5; y; y--)
12530c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
12540c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp6 = *(ptrJ - 5);
12550c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp5 = *(ptrJ - 4);
12560c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp4 = *(ptrJ - 3);
12570c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp3 = *(ptrJ - 2);
12580c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp2 = *(ptrJ - 1);
12590c1bc742181ded4930842b46e9507372f0b1b963James Dong
12600c1bc742181ded4930842b46e9507372f0b1b963James Dong        /* 4 pels per iteration */
12610c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (x = (partWidth >> 2); x; x--)
12620c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
12630c1bc742181ded4930842b46e9507372f0b1b963James Dong            /* First pixel */
12640c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp3 + tmp4;
12650c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += (tmp7 << 4);
12660c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += (tmp7 << 2);
12670c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp2 + tmp5;
12680c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = *ptrJ++;
12690c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 -= (tmp7 << 2);
12700c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 -= tmp7;
12710c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += tmp1;
12720c1bc742181ded4930842b46e9507372f0b1b963James Dong            *b1++ = tmp6;
12730c1bc742181ded4930842b46e9507372f0b1b963James Dong            /* Second pixel */
12740c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp2 + tmp3;
12750c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += (tmp7 << 4);
12760c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += (tmp7 << 2);
12770c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp1 + tmp4;
12780c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 = *ptrJ++;
12790c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 -= (tmp7 << 2);
12800c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 -= tmp7;
12810c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += tmp6;
12820c1bc742181ded4930842b46e9507372f0b1b963James Dong            *b1++ = tmp5;
12830c1bc742181ded4930842b46e9507372f0b1b963James Dong            /* Third pixel */
12840c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp1 + tmp2;
12850c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 += (tmp7 << 4);
12860c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 += (tmp7 << 2);
12870c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp6 + tmp3;
12880c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 = *ptrJ++;
12890c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 -= (tmp7 << 2);
12900c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 -= tmp7;
12910c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 += tmp5;
12920c1bc742181ded4930842b46e9507372f0b1b963James Dong            *b1++ = tmp4;
12930c1bc742181ded4930842b46e9507372f0b1b963James Dong            /* Fourth pixel */
12940c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp6 + tmp1;
12950c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 += (tmp7 << 4);
12960c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 += (tmp7 << 2);
12970c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp5 + tmp2;
12980c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 = *ptrJ++;
12990c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 -= (tmp7 << 2);
13000c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 -= tmp7;
13010c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 += tmp4;
13020c1bc742181ded4930842b46e9507372f0b1b963James Dong            *b1++ = tmp3;
13030c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp4;
13040c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 = tmp6;
13050c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 = tmp2;
13060c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 = tmp7;
13070c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 = tmp5;
13080c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 = tmp1;
13090c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
13100c1bc742181ded4930842b46e9507372f0b1b963James Dong        ptrJ += width - partWidth;
13110c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
13120c1bc742181ded4930842b46e9507372f0b1b963James Dong
13130c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* Second step: calculate vertical interpolation */
13140c1bc742181ded4930842b46e9507372f0b1b963James Dong    ptrC = table + partWidth;
13150c1bc742181ded4930842b46e9507372f0b1b963James Dong    ptrV = ptrC + 5*partWidth;
13160c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (y = (partHeight >> 2); y; y--)
13170c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
13180c1bc742181ded4930842b46e9507372f0b1b963James Dong        /* 4 pels per iteration */
13190c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (x = partWidth; x; x--)
13200c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
13210c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 = ptrV[-(i32)partWidth*2];
13220c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 = ptrV[-(i32)partWidth];
13230c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = ptrV[partWidth];
13240c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 = ptrV[partWidth*2];
13250c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 = *ptrV++;
13260c1bc742181ded4930842b46e9507372f0b1b963James Dong
13270c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp4 + tmp1;
13280c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 -= (tmp7 << 2);
13290c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 -= tmp7;
13300c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 += 512;
13310c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp5 + tmp6;
13320c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 = ptrC[partWidth*2];
13330c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 += (tmp7 << 4);
13340c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 += (tmp7 << 2);
13350c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 += tmp3;
13360c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = clp[tmp2>>10];
13370c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 += 512;
13380c1bc742181ded4930842b46e9507372f0b1b963James Dong            mb[48] = (u8)tmp7;
13390c1bc742181ded4930842b46e9507372f0b1b963James Dong
13400c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp3 + tmp6;
13410c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 -= (tmp7 << 2);
13420c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 -= tmp7;
13430c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp4 + tmp5;
13440c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 = ptrC[partWidth];
13450c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 += (tmp7 << 4);
13460c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 += (tmp7 << 2);
13470c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 += tmp2;
13480c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = clp[tmp1>>10];
13490c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += 512;
13500c1bc742181ded4930842b46e9507372f0b1b963James Dong            mb[32] = (u8)tmp7;
13510c1bc742181ded4930842b46e9507372f0b1b963James Dong
13520c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = *ptrC;
13530c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp2 + tmp5;
13540c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 -= (tmp7 << 2);
13550c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 -= tmp7;
13560c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp4 + tmp3;
13570c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += (tmp7 << 4);
13580c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += (tmp7 << 2);
13590c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += tmp1;
13600c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = clp[tmp6>>10];
13610c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += 512;
13620c1bc742181ded4930842b46e9507372f0b1b963James Dong            mb[16] = (u8)tmp7;
13630c1bc742181ded4930842b46e9507372f0b1b963James Dong
13640c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 = ptrC[-(i32)partWidth];
13650c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 += tmp4;
13660c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 -= (tmp1 << 2);
13670c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 -= tmp1;
13680c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 += tmp2;
13690c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += (tmp3 << 4);
13700c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += (tmp3 << 2);
13710c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += tmp6;
13720c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = clp[tmp5>>10];
13730c1bc742181ded4930842b46e9507372f0b1b963James Dong            *mb++ = (u8)tmp7;
13740c1bc742181ded4930842b46e9507372f0b1b963James Dong            ptrC++;
13750c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
13760c1bc742181ded4930842b46e9507372f0b1b963James Dong        mb += 4*16 - partWidth;
13770c1bc742181ded4930842b46e9507372f0b1b963James Dong        ptrC += 3*partWidth;
13780c1bc742181ded4930842b46e9507372f0b1b963James Dong        ptrV += 3*partWidth;
13790c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
13800c1bc742181ded4930842b46e9507372f0b1b963James Dong
13810c1bc742181ded4930842b46e9507372f0b1b963James Dong}
13820c1bc742181ded4930842b46e9507372f0b1b963James Dong
13830c1bc742181ded4930842b46e9507372f0b1b963James Dong
13840c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
13850c1bc742181ded4930842b46e9507372f0b1b963James Dong
13860c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: h264bsdInterpolateMidVerQuarter
13870c1bc742181ded4930842b46e9507372f0b1b963James Dong
13880c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
13890c1bc742181ded4930842b46e9507372f0b1b963James Dong          Function to perform horizontal and vertical interpolation of pixel
13900c1bc742181ded4930842b46e9507372f0b1b963James Dong          position 'f' or 'q' for a block. Overfilling is done only if needed.
13910c1bc742181ded4930842b46e9507372f0b1b963James Dong          Reference image (ref) is read at correct position and the predicted
13920c1bc742181ded4930842b46e9507372f0b1b963James Dong          part is written to macroblock array (mb)
13930c1bc742181ded4930842b46e9507372f0b1b963James Dong
13940c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
13950c1bc742181ded4930842b46e9507372f0b1b963James Dong
13960c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid h264bsdInterpolateMidVerQuarter(
13970c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *ref,
13980c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *mb,
13990c1bc742181ded4930842b46e9507372f0b1b963James Dong  i32 x0,
14000c1bc742181ded4930842b46e9507372f0b1b963James Dong  i32 y0,
14010c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 width,
14020c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 height,
14030c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 partWidth,
14040c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 partHeight,
14050c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 verOffset)    /* 0 for pixel f, 1 for pixel q */
14060c1bc742181ded4930842b46e9507372f0b1b963James Dong{
14070c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 p1[21*21/4+1];
14080c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 x, y;
14090c1bc742181ded4930842b46e9507372f0b1b963James Dong    i32 tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
14100c1bc742181ded4930842b46e9507372f0b1b963James Dong    i32 *ptrC, *ptrV, *ptrInt, *b1;
14110c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8  *ptrJ;
14120c1bc742181ded4930842b46e9507372f0b1b963James Dong    i32 table[21*16];
14130c1bc742181ded4930842b46e9507372f0b1b963James Dong    const u8 *clp = h264bsdClip + 512;
14140c1bc742181ded4930842b46e9507372f0b1b963James Dong
14150c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* Code */
14160c1bc742181ded4930842b46e9507372f0b1b963James Dong
14170c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(ref);
14180c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(mb);
14190c1bc742181ded4930842b46e9507372f0b1b963James Dong
14200c1bc742181ded4930842b46e9507372f0b1b963James Dong    if ((x0 < 0) || ((u32)x0+partWidth+5 > width) ||
14210c1bc742181ded4930842b46e9507372f0b1b963James Dong        (y0 < 0) || ((u32)y0+partHeight+5 > height))
14220c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
14230c1bc742181ded4930842b46e9507372f0b1b963James Dong        h264bsdFillBlock(ref, (u8*)p1, x0, y0, width, height,
14240c1bc742181ded4930842b46e9507372f0b1b963James Dong                partWidth+5, partHeight+5, partWidth+5);
14250c1bc742181ded4930842b46e9507372f0b1b963James Dong
14260c1bc742181ded4930842b46e9507372f0b1b963James Dong        x0 = 0;
14270c1bc742181ded4930842b46e9507372f0b1b963James Dong        y0 = 0;
14280c1bc742181ded4930842b46e9507372f0b1b963James Dong        ref = (u8*)p1;
14290c1bc742181ded4930842b46e9507372f0b1b963James Dong        width = partWidth+5;
14300c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
14310c1bc742181ded4930842b46e9507372f0b1b963James Dong
14320c1bc742181ded4930842b46e9507372f0b1b963James Dong    ref += (u32)y0 * width + (u32)x0;
14330c1bc742181ded4930842b46e9507372f0b1b963James Dong
14340c1bc742181ded4930842b46e9507372f0b1b963James Dong    b1 = table;
14350c1bc742181ded4930842b46e9507372f0b1b963James Dong    ptrJ = ref + 5;
14360c1bc742181ded4930842b46e9507372f0b1b963James Dong
14370c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* First step: calculate intermediate values for
14380c1bc742181ded4930842b46e9507372f0b1b963James Dong     * horizontal interpolation */
14390c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (y = partHeight + 5; y; y--)
14400c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
14410c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp6 = *(ptrJ - 5);
14420c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp5 = *(ptrJ - 4);
14430c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp4 = *(ptrJ - 3);
14440c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp3 = *(ptrJ - 2);
14450c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp2 = *(ptrJ - 1);
14460c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (x = (partWidth >> 2); x; x--)
14470c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
14480c1bc742181ded4930842b46e9507372f0b1b963James Dong            /* First pixel */
14490c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp3 + tmp4;
14500c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += (tmp7 << 4);
14510c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += (tmp7 << 2);
14520c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp2 + tmp5;
14530c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = *ptrJ++;
14540c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 -= (tmp7 << 2);
14550c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 -= tmp7;
14560c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += tmp1;
14570c1bc742181ded4930842b46e9507372f0b1b963James Dong            *b1++ = tmp6;
14580c1bc742181ded4930842b46e9507372f0b1b963James Dong            /* Second pixel */
14590c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp2 + tmp3;
14600c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += (tmp7 << 4);
14610c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += (tmp7 << 2);
14620c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp1 + tmp4;
14630c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 = *ptrJ++;
14640c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 -= (tmp7 << 2);
14650c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 -= tmp7;
14660c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += tmp6;
14670c1bc742181ded4930842b46e9507372f0b1b963James Dong            *b1++ = tmp5;
14680c1bc742181ded4930842b46e9507372f0b1b963James Dong            /* Third pixel */
14690c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp1 + tmp2;
14700c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 += (tmp7 << 4);
14710c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 += (tmp7 << 2);
14720c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp6 + tmp3;
14730c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 = *ptrJ++;
14740c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 -= (tmp7 << 2);
14750c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 -= tmp7;
14760c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 += tmp5;
14770c1bc742181ded4930842b46e9507372f0b1b963James Dong            *b1++ = tmp4;
14780c1bc742181ded4930842b46e9507372f0b1b963James Dong            /* Fourth pixel */
14790c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp6 + tmp1;
14800c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 += (tmp7 << 4);
14810c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 += (tmp7 << 2);
14820c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp5 + tmp2;
14830c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 = *ptrJ++;
14840c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 -= (tmp7 << 2);
14850c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 -= tmp7;
14860c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 += tmp4;
14870c1bc742181ded4930842b46e9507372f0b1b963James Dong            *b1++ = tmp3;
14880c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp4;
14890c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 = tmp6;
14900c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 = tmp2;
14910c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 = tmp7;
14920c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 = tmp5;
14930c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 = tmp1;
14940c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
14950c1bc742181ded4930842b46e9507372f0b1b963James Dong        ptrJ += width - partWidth;
14960c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
14970c1bc742181ded4930842b46e9507372f0b1b963James Dong
14980c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* Second step: calculate vertical interpolation and average */
14990c1bc742181ded4930842b46e9507372f0b1b963James Dong    ptrC = table + partWidth;
15000c1bc742181ded4930842b46e9507372f0b1b963James Dong    ptrV = ptrC + 5*partWidth;
15010c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* Pointer to integer sample position, either M or R */
15020c1bc742181ded4930842b46e9507372f0b1b963James Dong    ptrInt = ptrC + (2+verOffset)*partWidth;
15030c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (y = (partHeight >> 2); y; y--)
15040c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
15050c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (x = partWidth; x; x--)
15060c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
15070c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 = ptrV[-(i32)partWidth*2];
15080c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 = ptrV[-(i32)partWidth];
15090c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = ptrV[partWidth];
15100c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 = ptrV[partWidth*2];
15110c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 = *ptrV++;
15120c1bc742181ded4930842b46e9507372f0b1b963James Dong
15130c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp4 + tmp1;
15140c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 -= (tmp7 << 2);
15150c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 -= tmp7;
15160c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 += 512;
15170c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp5 + tmp6;
15180c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 = ptrC[partWidth*2];
15190c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 += (tmp7 << 4);
15200c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 += (tmp7 << 2);
15210c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = ptrInt[partWidth*2];
15220c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 += tmp3;
15230c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 = clp[tmp2>>10];
15240c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 += 16;
15250c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = clp[tmp7>>5];
15260c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 += 512;
15270c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2++;
15280c1bc742181ded4930842b46e9507372f0b1b963James Dong            mb[48] = (u8)((tmp7 + tmp2) >> 1);
15290c1bc742181ded4930842b46e9507372f0b1b963James Dong
15300c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp3 + tmp6;
15310c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 -= (tmp7 << 2);
15320c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 -= tmp7;
15330c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp4 + tmp5;
15340c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 = ptrC[partWidth];
15350c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 += (tmp7 << 4);
15360c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 += (tmp7 << 2);
15370c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = ptrInt[partWidth];
15380c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 += tmp2;
15390c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = clp[tmp1>>10];
15400c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 += 16;
15410c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = clp[tmp7>>5];
15420c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += 512;
15430c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1++;
15440c1bc742181ded4930842b46e9507372f0b1b963James Dong            mb[32] = (u8)((tmp7 + tmp1) >> 1);
15450c1bc742181ded4930842b46e9507372f0b1b963James Dong
15460c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = *ptrC;
15470c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp2 + tmp5;
15480c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 -= (tmp7 << 2);
15490c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 -= tmp7;
15500c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp4 + tmp3;
15510c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += (tmp7 << 4);
15520c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += (tmp7 << 2);
15530c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = *ptrInt;
15540c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += tmp1;
15550c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 = clp[tmp6>>10];
15560c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 += 16;
15570c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = clp[tmp7>>5];
15580c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += 512;
15590c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6++;
15600c1bc742181ded4930842b46e9507372f0b1b963James Dong            mb[16] = (u8)((tmp7 + tmp6) >> 1);
15610c1bc742181ded4930842b46e9507372f0b1b963James Dong
15620c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 = ptrC[-(i32)partWidth];
15630c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 += tmp4;
15640c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 -= (tmp1 << 2);
15650c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 -= tmp1;
15660c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 += tmp2;
15670c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += (tmp3 << 4);
15680c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += (tmp3 << 2);
15690c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = ptrInt[-(i32)partWidth];
15700c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += tmp6;
15710c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 = clp[tmp5>>10];
15720c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 += 16;
15730c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = clp[tmp7>>5];
15740c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5++;
15750c1bc742181ded4930842b46e9507372f0b1b963James Dong            *mb++ = (u8)((tmp7 + tmp5) >> 1);
15760c1bc742181ded4930842b46e9507372f0b1b963James Dong            ptrC++;
15770c1bc742181ded4930842b46e9507372f0b1b963James Dong            ptrInt++;
15780c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
15790c1bc742181ded4930842b46e9507372f0b1b963James Dong        mb += 4*16 - partWidth;
15800c1bc742181ded4930842b46e9507372f0b1b963James Dong        ptrC += 3*partWidth;
15810c1bc742181ded4930842b46e9507372f0b1b963James Dong        ptrV += 3*partWidth;
15820c1bc742181ded4930842b46e9507372f0b1b963James Dong        ptrInt += 3*partWidth;
15830c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
15840c1bc742181ded4930842b46e9507372f0b1b963James Dong
15850c1bc742181ded4930842b46e9507372f0b1b963James Dong}
15860c1bc742181ded4930842b46e9507372f0b1b963James Dong
15870c1bc742181ded4930842b46e9507372f0b1b963James Dong
15880c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
15890c1bc742181ded4930842b46e9507372f0b1b963James Dong
15900c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: h264bsdInterpolateMidHorQuarter
15910c1bc742181ded4930842b46e9507372f0b1b963James Dong
15920c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
15930c1bc742181ded4930842b46e9507372f0b1b963James Dong          Function to perform horizontal and vertical interpolation of pixel
15940c1bc742181ded4930842b46e9507372f0b1b963James Dong          position 'i' or 'k' for a block. Overfilling is done only if needed.
15950c1bc742181ded4930842b46e9507372f0b1b963James Dong          Reference image (ref) is read at correct position and the predicted
15960c1bc742181ded4930842b46e9507372f0b1b963James Dong          part is written to macroblock array (mb)
15970c1bc742181ded4930842b46e9507372f0b1b963James Dong
15980c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
15990c1bc742181ded4930842b46e9507372f0b1b963James Dong
16000c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid h264bsdInterpolateMidHorQuarter(
16010c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *ref,
16020c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *mb,
16030c1bc742181ded4930842b46e9507372f0b1b963James Dong  i32 x0,
16040c1bc742181ded4930842b46e9507372f0b1b963James Dong  i32 y0,
16050c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 width,
16060c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 height,
16070c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 partWidth,
16080c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 partHeight,
16090c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 horOffset)    /* 0 for pixel i, 1 for pixel k */
16100c1bc742181ded4930842b46e9507372f0b1b963James Dong{
16110c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 p1[21*21/4+1];
16120c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 x, y;
16130c1bc742181ded4930842b46e9507372f0b1b963James Dong    i32 tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
16140c1bc742181ded4930842b46e9507372f0b1b963James Dong    i32 *ptrJ, *ptrInt, *h1;
16150c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8  *ptrC, *ptrV;
16160c1bc742181ded4930842b46e9507372f0b1b963James Dong    i32 table[21*16];
16170c1bc742181ded4930842b46e9507372f0b1b963James Dong    i32 tableWidth = (i32)partWidth+5;
16180c1bc742181ded4930842b46e9507372f0b1b963James Dong    const u8 *clp = h264bsdClip + 512;
16190c1bc742181ded4930842b46e9507372f0b1b963James Dong
16200c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* Code */
16210c1bc742181ded4930842b46e9507372f0b1b963James Dong
16220c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(ref);
16230c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(mb);
16240c1bc742181ded4930842b46e9507372f0b1b963James Dong
16250c1bc742181ded4930842b46e9507372f0b1b963James Dong    if ((x0 < 0) || ((u32)x0+partWidth+5 > width) ||
16260c1bc742181ded4930842b46e9507372f0b1b963James Dong        (y0 < 0) || ((u32)y0+partHeight+5 > height))
16270c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
16280c1bc742181ded4930842b46e9507372f0b1b963James Dong        h264bsdFillBlock(ref, (u8*)p1, x0, y0, width, height,
16290c1bc742181ded4930842b46e9507372f0b1b963James Dong                partWidth+5, partHeight+5, partWidth+5);
16300c1bc742181ded4930842b46e9507372f0b1b963James Dong
16310c1bc742181ded4930842b46e9507372f0b1b963James Dong        x0 = 0;
16320c1bc742181ded4930842b46e9507372f0b1b963James Dong        y0 = 0;
16330c1bc742181ded4930842b46e9507372f0b1b963James Dong        ref = (u8*)p1;
16340c1bc742181ded4930842b46e9507372f0b1b963James Dong        width = partWidth+5;
16350c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
16360c1bc742181ded4930842b46e9507372f0b1b963James Dong
16370c1bc742181ded4930842b46e9507372f0b1b963James Dong    ref += (u32)y0 * width + (u32)x0;
16380c1bc742181ded4930842b46e9507372f0b1b963James Dong
16390c1bc742181ded4930842b46e9507372f0b1b963James Dong    h1 = table + tableWidth;
16400c1bc742181ded4930842b46e9507372f0b1b963James Dong    ptrC = ref + width;
16410c1bc742181ded4930842b46e9507372f0b1b963James Dong    ptrV = ptrC + 5*width;
16420c1bc742181ded4930842b46e9507372f0b1b963James Dong
16430c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* First step: calculate intermediate values for
16440c1bc742181ded4930842b46e9507372f0b1b963James Dong     * vertical interpolation */
16450c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (y = (partHeight >> 2); y; y--)
16460c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
16470c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (x = (u32)tableWidth; x; x--)
16480c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
16490c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 = ptrV[-(i32)width*2];
16500c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 = ptrV[-(i32)width];
16510c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = ptrV[width];
16520c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 = ptrV[width*2];
16530c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 = *ptrV++;
16540c1bc742181ded4930842b46e9507372f0b1b963James Dong
16550c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp4 + tmp1;
16560c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 -= (tmp7 << 2);
16570c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 -= tmp7;
16580c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp5 + tmp6;
16590c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 = ptrC[width*2];
16600c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 += (tmp7 << 4);
16610c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 += (tmp7 << 2);
16620c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 += tmp3;
16630c1bc742181ded4930842b46e9507372f0b1b963James Dong            h1[tableWidth*2] = tmp2;
16640c1bc742181ded4930842b46e9507372f0b1b963James Dong
16650c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp3 + tmp6;
16660c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 -= (tmp7 << 2);
16670c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 -= tmp7;
16680c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp4 + tmp5;
16690c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 = ptrC[width];
16700c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 += (tmp7 << 4);
16710c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 += (tmp7 << 2);
16720c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 += tmp2;
16730c1bc742181ded4930842b46e9507372f0b1b963James Dong            h1[tableWidth] = tmp1;
16740c1bc742181ded4930842b46e9507372f0b1b963James Dong
16750c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = *ptrC;
16760c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp2 + tmp5;
16770c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 -= (tmp7 << 2);
16780c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 -= tmp7;
16790c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp4 + tmp3;
16800c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += (tmp7 << 4);
16810c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += (tmp7 << 2);
16820c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += tmp1;
16830c1bc742181ded4930842b46e9507372f0b1b963James Dong            *h1 = tmp6;
16840c1bc742181ded4930842b46e9507372f0b1b963James Dong
16850c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 = ptrC[-(i32)width];
16860c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 += tmp4;
16870c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 -= (tmp1 << 2);
16880c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 -= tmp1;
16890c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 += tmp2;
16900c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += (tmp3 << 4);
16910c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += (tmp3 << 2);
16920c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += tmp6;
16930c1bc742181ded4930842b46e9507372f0b1b963James Dong            h1[-tableWidth] = tmp5;
16940c1bc742181ded4930842b46e9507372f0b1b963James Dong            h1++;
16950c1bc742181ded4930842b46e9507372f0b1b963James Dong            ptrC++;
16960c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
16970c1bc742181ded4930842b46e9507372f0b1b963James Dong        ptrC += 4*width - partWidth - 5;
16980c1bc742181ded4930842b46e9507372f0b1b963James Dong        ptrV += 4*width - partWidth - 5;
16990c1bc742181ded4930842b46e9507372f0b1b963James Dong        h1 += 3*tableWidth;
17000c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
17010c1bc742181ded4930842b46e9507372f0b1b963James Dong
17020c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* Second step: calculate horizontal interpolation and average */
17030c1bc742181ded4930842b46e9507372f0b1b963James Dong    ptrJ = table + 5;
17040c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* Pointer to integer sample position, either G or H */
17050c1bc742181ded4930842b46e9507372f0b1b963James Dong    ptrInt = table + 2 + horOffset;
17060c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (y = partHeight; y; y--)
17070c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
17080c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp6 = *(ptrJ - 5);
17090c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp5 = *(ptrJ - 4);
17100c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp4 = *(ptrJ - 3);
17110c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp3 = *(ptrJ - 2);
17120c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp2 = *(ptrJ - 1);
17130c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (x = (partWidth>>2); x; x--)
17140c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
17150c1bc742181ded4930842b46e9507372f0b1b963James Dong            /* First pixel */
17160c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += 512;
17170c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp3 + tmp4;
17180c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += (tmp7 << 4);
17190c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += (tmp7 << 2);
17200c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp2 + tmp5;
17210c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp1 = *ptrJ++;
17220c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 -= (tmp7 << 2);
17230c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 -= tmp7;
17240c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = *ptrInt++;
17250c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 += tmp1;
17260c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 = clp[tmp6 >> 10];
17270c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 += 16;
17280c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = clp[tmp7 >> 5];
17290c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += 512;
17300c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6++;
17310c1bc742181ded4930842b46e9507372f0b1b963James Dong            *mb++ = (u8)((tmp6 + tmp7) >> 1);
17320c1bc742181ded4930842b46e9507372f0b1b963James Dong            /* Second pixel */
17330c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp2 + tmp3;
17340c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += (tmp7 << 4);
17350c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += (tmp7 << 2);
17360c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp1 + tmp4;
17370c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 = *ptrJ++;
17380c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 -= (tmp7 << 2);
17390c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 -= tmp7;
17400c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = *ptrInt++;
17410c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 += tmp6;
17420c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 = clp[tmp5 >> 10];
17430c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 += 16;
17440c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = clp[tmp7 >> 5];
17450c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 += 512;
17460c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5++;
17470c1bc742181ded4930842b46e9507372f0b1b963James Dong            *mb++ = (u8)((tmp5 + tmp7) >> 1);
17480c1bc742181ded4930842b46e9507372f0b1b963James Dong            /* Third pixel */
17490c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp1 + tmp2;
17500c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 += (tmp7 << 4);
17510c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 += (tmp7 << 2);
17520c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp6 + tmp3;
17530c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 = *ptrJ++;
17540c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 -= (tmp7 << 2);
17550c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 -= tmp7;
17560c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = *ptrInt++;
17570c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 += tmp5;
17580c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 = clp[tmp4 >> 10];
17590c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 += 16;
17600c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = clp[tmp7 >> 5];
17610c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 += 512;
17620c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4++;
17630c1bc742181ded4930842b46e9507372f0b1b963James Dong            *mb++ = (u8)((tmp4 + tmp7) >> 1);
17640c1bc742181ded4930842b46e9507372f0b1b963James Dong            /* Fourth pixel */
17650c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp6 + tmp1;
17660c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 += (tmp7 << 4);
17670c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 += (tmp7 << 2);
17680c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp5 + tmp2;
17690c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 = *ptrJ++;
17700c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 -= (tmp7 << 2);
17710c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 -= tmp7;
17720c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = *ptrInt++;
17730c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 += tmp4;
17740c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 = clp[tmp3 >> 10];
17750c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 += 16;
17760c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = clp[tmp7 >> 5];
17770c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3++;
17780c1bc742181ded4930842b46e9507372f0b1b963James Dong            *mb++ = (u8)((tmp3 + tmp7) >> 1);
17790c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp3 = tmp5;
17800c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp5 = tmp1;
17810c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp7 = tmp4;
17820c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp4 = tmp6;
17830c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp6 = tmp2;
17840c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 = tmp7;
17850c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
17860c1bc742181ded4930842b46e9507372f0b1b963James Dong        ptrJ += 5;
17870c1bc742181ded4930842b46e9507372f0b1b963James Dong        ptrInt += 5;
17880c1bc742181ded4930842b46e9507372f0b1b963James Dong        mb += 16 - partWidth;
17890c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
17900c1bc742181ded4930842b46e9507372f0b1b963James Dong
17910c1bc742181ded4930842b46e9507372f0b1b963James Dong}
17920c1bc742181ded4930842b46e9507372f0b1b963James Dong
17930c1bc742181ded4930842b46e9507372f0b1b963James Dong
17940c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
17950c1bc742181ded4930842b46e9507372f0b1b963James Dong
17960c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: h264bsdPredictSamples
17970c1bc742181ded4930842b46e9507372f0b1b963James Dong
17980c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
17990c1bc742181ded4930842b46e9507372f0b1b963James Dong          This function reconstructs a prediction for a macroblock partition.
18000c1bc742181ded4930842b46e9507372f0b1b963James Dong          The prediction is either copied or interpolated using the reference
18010c1bc742181ded4930842b46e9507372f0b1b963James Dong          frame and the motion vector. Both luminance and chrominance parts are
18020c1bc742181ded4930842b46e9507372f0b1b963James Dong          predicted. The prediction is stored in given macroblock array (data).
18030c1bc742181ded4930842b46e9507372f0b1b963James Dong        Inputs:
18040c1bc742181ded4930842b46e9507372f0b1b963James Dong          data          pointer to macroblock array (384 bytes) for output
18050c1bc742181ded4930842b46e9507372f0b1b963James Dong          mv            pointer to motion vector used for prediction
18060c1bc742181ded4930842b46e9507372f0b1b963James Dong          refPic        pointer to reference picture structure
18070c1bc742181ded4930842b46e9507372f0b1b963James Dong          xA            x-coordinate for current macroblock
18080c1bc742181ded4930842b46e9507372f0b1b963James Dong          yA            y-coordinate for current macroblock
18090c1bc742181ded4930842b46e9507372f0b1b963James Dong          partX         x-offset for partition in macroblock
18100c1bc742181ded4930842b46e9507372f0b1b963James Dong          partY         y-offset for partition in macroblock
18110c1bc742181ded4930842b46e9507372f0b1b963James Dong          partWidth     width of partition
18120c1bc742181ded4930842b46e9507372f0b1b963James Dong          partHeight    height of partition
18130c1bc742181ded4930842b46e9507372f0b1b963James Dong        Outputs:
18140c1bc742181ded4930842b46e9507372f0b1b963James Dong          data          macroblock array (16x16+8x8+8x8) where predicted
18150c1bc742181ded4930842b46e9507372f0b1b963James Dong                        partition is stored at correct position
18160c1bc742181ded4930842b46e9507372f0b1b963James Dong
18170c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
18180c1bc742181ded4930842b46e9507372f0b1b963James Dong
18190c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid h264bsdPredictSamples(
18200c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *data,
18210c1bc742181ded4930842b46e9507372f0b1b963James Dong  mv_t *mv,
18220c1bc742181ded4930842b46e9507372f0b1b963James Dong  image_t *refPic,
18230c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 xA,
18240c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 yA,
18250c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 partX,
18260c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 partY,
18270c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 partWidth,
18280c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 partHeight)
18290c1bc742181ded4930842b46e9507372f0b1b963James Dong
18300c1bc742181ded4930842b46e9507372f0b1b963James Dong{
18310c1bc742181ded4930842b46e9507372f0b1b963James Dong
18320c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
18330c1bc742181ded4930842b46e9507372f0b1b963James Dong
18340c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 xFrac, yFrac, width, height;
18350c1bc742181ded4930842b46e9507372f0b1b963James Dong    i32 xInt, yInt;
18360c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 *lumaPartData;
18370c1bc742181ded4930842b46e9507372f0b1b963James Dong
18380c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
18390c1bc742181ded4930842b46e9507372f0b1b963James Dong
18400c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(data);
18410c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(mv);
18420c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(partWidth);
18430c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(partHeight);
18440c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(refPic);
18450c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(refPic->data);
18460c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(refPic->width);
18470c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(refPic->height);
18480c1bc742181ded4930842b46e9507372f0b1b963James Dong
18490c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* luma */
18500c1bc742181ded4930842b46e9507372f0b1b963James Dong    lumaPartData = data + 16*partY + partX;
18510c1bc742181ded4930842b46e9507372f0b1b963James Dong
18520c1bc742181ded4930842b46e9507372f0b1b963James Dong    xFrac = mv->hor & 0x3;
18530c1bc742181ded4930842b46e9507372f0b1b963James Dong    yFrac = mv->ver & 0x3;
18540c1bc742181ded4930842b46e9507372f0b1b963James Dong
18550c1bc742181ded4930842b46e9507372f0b1b963James Dong    width = 16 * refPic->width;
18560c1bc742181ded4930842b46e9507372f0b1b963James Dong    height = 16 * refPic->height;
18570c1bc742181ded4930842b46e9507372f0b1b963James Dong
18580c1bc742181ded4930842b46e9507372f0b1b963James Dong    xInt = (i32)xA + (i32)partX + (mv->hor >> 2);
18590c1bc742181ded4930842b46e9507372f0b1b963James Dong    yInt = (i32)yA + (i32)partY + (mv->ver >> 2);
18600c1bc742181ded4930842b46e9507372f0b1b963James Dong
18610c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(lumaFracPos[xFrac][yFrac] < 16);
18620c1bc742181ded4930842b46e9507372f0b1b963James Dong
18630c1bc742181ded4930842b46e9507372f0b1b963James Dong    switch (lumaFracPos[xFrac][yFrac])
18640c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
18650c1bc742181ded4930842b46e9507372f0b1b963James Dong        case 0: /* G */
18660c1bc742181ded4930842b46e9507372f0b1b963James Dong            h264bsdFillBlock(refPic->data, lumaPartData,
18670c1bc742181ded4930842b46e9507372f0b1b963James Dong                    xInt,yInt,width,height,partWidth,partHeight,16);
18680c1bc742181ded4930842b46e9507372f0b1b963James Dong            break;
18690c1bc742181ded4930842b46e9507372f0b1b963James Dong        case 1: /* d */
18700c1bc742181ded4930842b46e9507372f0b1b963James Dong            h264bsdInterpolateVerQuarter(refPic->data, lumaPartData,
18710c1bc742181ded4930842b46e9507372f0b1b963James Dong                    xInt, yInt-2, width, height, partWidth, partHeight, 0);
18720c1bc742181ded4930842b46e9507372f0b1b963James Dong            break;
18730c1bc742181ded4930842b46e9507372f0b1b963James Dong        case 2: /* h */
18740c1bc742181ded4930842b46e9507372f0b1b963James Dong            h264bsdInterpolateVerHalf(refPic->data, lumaPartData,
18750c1bc742181ded4930842b46e9507372f0b1b963James Dong                    xInt, yInt-2, width, height, partWidth, partHeight);
18760c1bc742181ded4930842b46e9507372f0b1b963James Dong            break;
18770c1bc742181ded4930842b46e9507372f0b1b963James Dong        case 3: /* n */
18780c1bc742181ded4930842b46e9507372f0b1b963James Dong            h264bsdInterpolateVerQuarter(refPic->data, lumaPartData,
18790c1bc742181ded4930842b46e9507372f0b1b963James Dong                    xInt, yInt-2, width, height, partWidth, partHeight, 1);
18800c1bc742181ded4930842b46e9507372f0b1b963James Dong            break;
18810c1bc742181ded4930842b46e9507372f0b1b963James Dong        case 4: /* a */
18820c1bc742181ded4930842b46e9507372f0b1b963James Dong            h264bsdInterpolateHorQuarter(refPic->data, lumaPartData,
18830c1bc742181ded4930842b46e9507372f0b1b963James Dong                    xInt-2, yInt, width, height, partWidth, partHeight, 0);
18840c1bc742181ded4930842b46e9507372f0b1b963James Dong            break;
18850c1bc742181ded4930842b46e9507372f0b1b963James Dong        case 5: /* e */
18860c1bc742181ded4930842b46e9507372f0b1b963James Dong            h264bsdInterpolateHorVerQuarter(refPic->data, lumaPartData,
18870c1bc742181ded4930842b46e9507372f0b1b963James Dong                    xInt-2, yInt-2, width, height, partWidth, partHeight, 0);
18880c1bc742181ded4930842b46e9507372f0b1b963James Dong            break;
18890c1bc742181ded4930842b46e9507372f0b1b963James Dong        case 6: /* i */
18900c1bc742181ded4930842b46e9507372f0b1b963James Dong            h264bsdInterpolateMidHorQuarter(refPic->data, lumaPartData,
18910c1bc742181ded4930842b46e9507372f0b1b963James Dong                    xInt-2, yInt-2, width, height, partWidth, partHeight, 0);
18920c1bc742181ded4930842b46e9507372f0b1b963James Dong            break;
18930c1bc742181ded4930842b46e9507372f0b1b963James Dong        case 7: /* p */
18940c1bc742181ded4930842b46e9507372f0b1b963James Dong            h264bsdInterpolateHorVerQuarter(refPic->data, lumaPartData,
18950c1bc742181ded4930842b46e9507372f0b1b963James Dong                    xInt-2, yInt-2, width, height, partWidth, partHeight, 2);
18960c1bc742181ded4930842b46e9507372f0b1b963James Dong            break;
18970c1bc742181ded4930842b46e9507372f0b1b963James Dong        case 8: /* b */
18980c1bc742181ded4930842b46e9507372f0b1b963James Dong            h264bsdInterpolateHorHalf(refPic->data, lumaPartData,
18990c1bc742181ded4930842b46e9507372f0b1b963James Dong                    xInt-2, yInt, width, height, partWidth, partHeight);
19000c1bc742181ded4930842b46e9507372f0b1b963James Dong            break;
19010c1bc742181ded4930842b46e9507372f0b1b963James Dong        case 9: /* f */
19020c1bc742181ded4930842b46e9507372f0b1b963James Dong            h264bsdInterpolateMidVerQuarter(refPic->data, lumaPartData,
19030c1bc742181ded4930842b46e9507372f0b1b963James Dong                    xInt-2, yInt-2, width, height, partWidth, partHeight, 0);
19040c1bc742181ded4930842b46e9507372f0b1b963James Dong            break;
19050c1bc742181ded4930842b46e9507372f0b1b963James Dong        case 10: /* j */
19060c1bc742181ded4930842b46e9507372f0b1b963James Dong            h264bsdInterpolateMidHalf(refPic->data, lumaPartData,
19070c1bc742181ded4930842b46e9507372f0b1b963James Dong                    xInt-2, yInt-2, width, height, partWidth, partHeight);
19080c1bc742181ded4930842b46e9507372f0b1b963James Dong            break;
19090c1bc742181ded4930842b46e9507372f0b1b963James Dong        case 11: /* q */
19100c1bc742181ded4930842b46e9507372f0b1b963James Dong            h264bsdInterpolateMidVerQuarter(refPic->data, lumaPartData,
19110c1bc742181ded4930842b46e9507372f0b1b963James Dong                    xInt-2, yInt-2, width, height, partWidth, partHeight, 1);
19120c1bc742181ded4930842b46e9507372f0b1b963James Dong            break;
19130c1bc742181ded4930842b46e9507372f0b1b963James Dong        case 12: /* c */
19140c1bc742181ded4930842b46e9507372f0b1b963James Dong            h264bsdInterpolateHorQuarter(refPic->data, lumaPartData,
19150c1bc742181ded4930842b46e9507372f0b1b963James Dong                    xInt-2, yInt, width, height, partWidth, partHeight, 1);
19160c1bc742181ded4930842b46e9507372f0b1b963James Dong            break;
19170c1bc742181ded4930842b46e9507372f0b1b963James Dong        case 13: /* g */
19180c1bc742181ded4930842b46e9507372f0b1b963James Dong            h264bsdInterpolateHorVerQuarter(refPic->data, lumaPartData,
19190c1bc742181ded4930842b46e9507372f0b1b963James Dong                    xInt-2, yInt-2, width, height, partWidth, partHeight, 1);
19200c1bc742181ded4930842b46e9507372f0b1b963James Dong            break;
19210c1bc742181ded4930842b46e9507372f0b1b963James Dong        case 14: /* k */
19220c1bc742181ded4930842b46e9507372f0b1b963James Dong            h264bsdInterpolateMidHorQuarter(refPic->data, lumaPartData,
19230c1bc742181ded4930842b46e9507372f0b1b963James Dong                    xInt-2, yInt-2, width, height, partWidth, partHeight, 1);
19240c1bc742181ded4930842b46e9507372f0b1b963James Dong            break;
19250c1bc742181ded4930842b46e9507372f0b1b963James Dong        default: /* case 15, r */
19260c1bc742181ded4930842b46e9507372f0b1b963James Dong            h264bsdInterpolateHorVerQuarter(refPic->data, lumaPartData,
19270c1bc742181ded4930842b46e9507372f0b1b963James Dong                    xInt-2, yInt-2, width, height, partWidth, partHeight, 3);
19280c1bc742181ded4930842b46e9507372f0b1b963James Dong            break;
19290c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
19300c1bc742181ded4930842b46e9507372f0b1b963James Dong
19310c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* chroma */
19320c1bc742181ded4930842b46e9507372f0b1b963James Dong    PredictChroma(
19330c1bc742181ded4930842b46e9507372f0b1b963James Dong      data + 16*16 + (partY>>1)*8 + (partX>>1),
19340c1bc742181ded4930842b46e9507372f0b1b963James Dong      xA + partX,
19350c1bc742181ded4930842b46e9507372f0b1b963James Dong      yA + partY,
19360c1bc742181ded4930842b46e9507372f0b1b963James Dong      partWidth,
19370c1bc742181ded4930842b46e9507372f0b1b963James Dong      partHeight,
19380c1bc742181ded4930842b46e9507372f0b1b963James Dong      mv,
19390c1bc742181ded4930842b46e9507372f0b1b963James Dong      refPic);
19400c1bc742181ded4930842b46e9507372f0b1b963James Dong
19410c1bc742181ded4930842b46e9507372f0b1b963James Dong}
19420c1bc742181ded4930842b46e9507372f0b1b963James Dong
19430c1bc742181ded4930842b46e9507372f0b1b963James Dong#else /* H264DEC_OMXDL */
19440c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
19450c1bc742181ded4930842b46e9507372f0b1b963James Dong
19460c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: h264bsdPredictSamples
19470c1bc742181ded4930842b46e9507372f0b1b963James Dong
19480c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
19490c1bc742181ded4930842b46e9507372f0b1b963James Dong          This function reconstructs a prediction for a macroblock partition.
19500c1bc742181ded4930842b46e9507372f0b1b963James Dong          The prediction is either copied or interpolated using the reference
19510c1bc742181ded4930842b46e9507372f0b1b963James Dong          frame and the motion vector. Both luminance and chrominance parts are
19520c1bc742181ded4930842b46e9507372f0b1b963James Dong          predicted. The prediction is stored in given macroblock array (data).
19530c1bc742181ded4930842b46e9507372f0b1b963James Dong        Inputs:
19540c1bc742181ded4930842b46e9507372f0b1b963James Dong          data          pointer to macroblock array (384 bytes) for output
19550c1bc742181ded4930842b46e9507372f0b1b963James Dong          mv            pointer to motion vector used for prediction
19560c1bc742181ded4930842b46e9507372f0b1b963James Dong          refPic        pointer to reference picture structure
19570c1bc742181ded4930842b46e9507372f0b1b963James Dong          xA            x-coordinate for current macroblock
19580c1bc742181ded4930842b46e9507372f0b1b963James Dong          yA            y-coordinate for current macroblock
19590c1bc742181ded4930842b46e9507372f0b1b963James Dong          partX         x-offset for partition in macroblock
19600c1bc742181ded4930842b46e9507372f0b1b963James Dong          partY         y-offset for partition in macroblock
19610c1bc742181ded4930842b46e9507372f0b1b963James Dong          partWidth     width of partition
19620c1bc742181ded4930842b46e9507372f0b1b963James Dong          partHeight    height of partition
19630c1bc742181ded4930842b46e9507372f0b1b963James Dong        Outputs:
19640c1bc742181ded4930842b46e9507372f0b1b963James Dong          data          macroblock array (16x16+8x8+8x8) where predicted
19650c1bc742181ded4930842b46e9507372f0b1b963James Dong                        partition is stored at correct position
19660c1bc742181ded4930842b46e9507372f0b1b963James Dong
19670c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
19680c1bc742181ded4930842b46e9507372f0b1b963James Dong
19690c1bc742181ded4930842b46e9507372f0b1b963James Dong/*lint -e{550} Symbol 'res' not accessed */
19700c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid h264bsdPredictSamples(
19710c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *data,
19720c1bc742181ded4930842b46e9507372f0b1b963James Dong  mv_t *mv,
19730c1bc742181ded4930842b46e9507372f0b1b963James Dong  image_t *refPic,
19740c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 colAndRow,
19750c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 part,
19760c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *pFill)
19770c1bc742181ded4930842b46e9507372f0b1b963James Dong
19780c1bc742181ded4930842b46e9507372f0b1b963James Dong{
19790c1bc742181ded4930842b46e9507372f0b1b963James Dong
19800c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
19810c1bc742181ded4930842b46e9507372f0b1b963James Dong
19820c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 xFrac, yFrac;
19830c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 width, height;
19840c1bc742181ded4930842b46e9507372f0b1b963James Dong    i32 xInt, yInt, x0, y0;
19850c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 *partData, *ref;
19860c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMXSize roi;
19870c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 fillWidth;
19880c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 fillHeight;
19890c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMXResult res;
19900c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 xA, yA;
19910c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 partX, partY;
19920c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 partWidth, partHeight;
19930c1bc742181ded4930842b46e9507372f0b1b963James Dong
19940c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
19950c1bc742181ded4930842b46e9507372f0b1b963James Dong
19960c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(data);
19970c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(mv);
19980c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(refPic);
19990c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(refPic->data);
20000c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(refPic->width);
20010c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(refPic->height);
20020c1bc742181ded4930842b46e9507372f0b1b963James Dong
20030c1bc742181ded4930842b46e9507372f0b1b963James Dong    xA = (colAndRow & 0xFFFF0000) >> 16;
20040c1bc742181ded4930842b46e9507372f0b1b963James Dong    yA = (colAndRow & 0x0000FFFF);
20050c1bc742181ded4930842b46e9507372f0b1b963James Dong
20060c1bc742181ded4930842b46e9507372f0b1b963James Dong    partX = (part & 0xFF000000) >> 24;
20070c1bc742181ded4930842b46e9507372f0b1b963James Dong    partY = (part & 0x00FF0000) >> 16;
20080c1bc742181ded4930842b46e9507372f0b1b963James Dong    partWidth = (part & 0x0000FF00) >> 8;
20090c1bc742181ded4930842b46e9507372f0b1b963James Dong    partHeight = (part & 0x000000FF);
20100c1bc742181ded4930842b46e9507372f0b1b963James Dong
20110c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(partWidth);
20120c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(partHeight);
20130c1bc742181ded4930842b46e9507372f0b1b963James Dong
20140c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* luma */
20150c1bc742181ded4930842b46e9507372f0b1b963James Dong    partData = data + 16*partY + partX;
20160c1bc742181ded4930842b46e9507372f0b1b963James Dong
20170c1bc742181ded4930842b46e9507372f0b1b963James Dong    xFrac = mv->hor & 0x3;
20180c1bc742181ded4930842b46e9507372f0b1b963James Dong    yFrac = mv->ver & 0x3;
20190c1bc742181ded4930842b46e9507372f0b1b963James Dong
20200c1bc742181ded4930842b46e9507372f0b1b963James Dong    width = 16 * refPic->width;
20210c1bc742181ded4930842b46e9507372f0b1b963James Dong    height = 16 * refPic->height;
20220c1bc742181ded4930842b46e9507372f0b1b963James Dong
20230c1bc742181ded4930842b46e9507372f0b1b963James Dong    xInt = (i32)xA + (i32)partX + (mv->hor >> 2);
20240c1bc742181ded4930842b46e9507372f0b1b963James Dong    yInt = (i32)yA + (i32)partY + (mv->ver >> 2);
20250c1bc742181ded4930842b46e9507372f0b1b963James Dong
20260c1bc742181ded4930842b46e9507372f0b1b963James Dong    x0 = (xFrac) ? xInt-2 : xInt;
20270c1bc742181ded4930842b46e9507372f0b1b963James Dong    y0 = (yFrac) ? yInt-2 : yInt;
20280c1bc742181ded4930842b46e9507372f0b1b963James Dong
20290c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (xFrac)
20300c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
20310c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (partWidth == 16)
20320c1bc742181ded4930842b46e9507372f0b1b963James Dong            fillWidth = 32;
20330c1bc742181ded4930842b46e9507372f0b1b963James Dong        else
20340c1bc742181ded4930842b46e9507372f0b1b963James Dong            fillWidth = 16;
20350c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
20360c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
20370c1bc742181ded4930842b46e9507372f0b1b963James Dong        fillWidth = (partWidth*2);
20380c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (yFrac)
20390c1bc742181ded4930842b46e9507372f0b1b963James Dong        fillHeight = partHeight+5;
20400c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
20410c1bc742181ded4930842b46e9507372f0b1b963James Dong        fillHeight = partHeight;
20420c1bc742181ded4930842b46e9507372f0b1b963James Dong
20430c1bc742181ded4930842b46e9507372f0b1b963James Dong
20440c1bc742181ded4930842b46e9507372f0b1b963James Dong    if ((x0 < 0) || ((u32)x0+fillWidth > width) ||
20450c1bc742181ded4930842b46e9507372f0b1b963James Dong        (y0 < 0) || ((u32)y0+fillHeight > height))
20460c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
20470c1bc742181ded4930842b46e9507372f0b1b963James Dong        h264bsdFillBlock(refPic->data, (u8*)pFill, x0, y0, width, height,
20480c1bc742181ded4930842b46e9507372f0b1b963James Dong                fillWidth, fillHeight, fillWidth);
20490c1bc742181ded4930842b46e9507372f0b1b963James Dong
20500c1bc742181ded4930842b46e9507372f0b1b963James Dong        x0 = 0;
20510c1bc742181ded4930842b46e9507372f0b1b963James Dong        y0 = 0;
20520c1bc742181ded4930842b46e9507372f0b1b963James Dong        ref = pFill;
20530c1bc742181ded4930842b46e9507372f0b1b963James Dong        width = fillWidth;
20540c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (yFrac)
20550c1bc742181ded4930842b46e9507372f0b1b963James Dong            ref += 2*width;
20560c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (xFrac)
20570c1bc742181ded4930842b46e9507372f0b1b963James Dong            ref += 2;
20580c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
20590c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
20600c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
20610c1bc742181ded4930842b46e9507372f0b1b963James Dong        /*lint --e(737) Loss of sign */
20620c1bc742181ded4930842b46e9507372f0b1b963James Dong        ref = refPic->data + yInt*width + xInt;
20630c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
20640c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* Luma interpolation */
20650c1bc742181ded4930842b46e9507372f0b1b963James Dong    roi.width = (i32)partWidth;
20660c1bc742181ded4930842b46e9507372f0b1b963James Dong    roi.height = (i32)partHeight;
20670c1bc742181ded4930842b46e9507372f0b1b963James Dong
20680c1bc742181ded4930842b46e9507372f0b1b963James Dong    res = omxVCM4P10_InterpolateLuma(ref, (i32)width, partData, 16,
20690c1bc742181ded4930842b46e9507372f0b1b963James Dong                                        (i32)xFrac, (i32)yFrac, roi);
20700c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(res == 0);
20710c1bc742181ded4930842b46e9507372f0b1b963James Dong
20720c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* Chroma */
20730c1bc742181ded4930842b46e9507372f0b1b963James Dong    width  = 8 * refPic->width;
20740c1bc742181ded4930842b46e9507372f0b1b963James Dong    height = 8 * refPic->height;
20750c1bc742181ded4930842b46e9507372f0b1b963James Dong
20760c1bc742181ded4930842b46e9507372f0b1b963James Dong    x0 = ((xA + partX) >> 1) + (mv->hor >> 3);
20770c1bc742181ded4930842b46e9507372f0b1b963James Dong    y0 = ((yA + partY) >> 1) + (mv->ver >> 3);
20780c1bc742181ded4930842b46e9507372f0b1b963James Dong    xFrac = mv->hor & 0x7;
20790c1bc742181ded4930842b46e9507372f0b1b963James Dong    yFrac = mv->ver & 0x7;
20800c1bc742181ded4930842b46e9507372f0b1b963James Dong
20810c1bc742181ded4930842b46e9507372f0b1b963James Dong    ref = refPic->data + 256 * refPic->width * refPic->height;
20820c1bc742181ded4930842b46e9507372f0b1b963James Dong
20830c1bc742181ded4930842b46e9507372f0b1b963James Dong    roi.width = (i32)(partWidth >> 1);
20840c1bc742181ded4930842b46e9507372f0b1b963James Dong    fillWidth = ((partWidth >> 1) + 8) & ~0x7;
20850c1bc742181ded4930842b46e9507372f0b1b963James Dong    roi.height = (i32)(partHeight >> 1);
20860c1bc742181ded4930842b46e9507372f0b1b963James Dong    fillHeight = (partHeight >> 1) + 1;
20870c1bc742181ded4930842b46e9507372f0b1b963James Dong
20880c1bc742181ded4930842b46e9507372f0b1b963James Dong    if ((x0 < 0) || ((u32)x0+fillWidth > width) ||
20890c1bc742181ded4930842b46e9507372f0b1b963James Dong        (y0 < 0) || ((u32)y0+fillHeight > height))
20900c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
20910c1bc742181ded4930842b46e9507372f0b1b963James Dong        h264bsdFillBlock(ref, pFill, x0, y0, width, height,
20920c1bc742181ded4930842b46e9507372f0b1b963James Dong            fillWidth, fillHeight, fillWidth);
20930c1bc742181ded4930842b46e9507372f0b1b963James Dong        ref += width * height;
20940c1bc742181ded4930842b46e9507372f0b1b963James Dong        h264bsdFillBlock(ref, pFill + fillWidth*fillHeight,
20950c1bc742181ded4930842b46e9507372f0b1b963James Dong            x0, y0, width, height, fillWidth,
20960c1bc742181ded4930842b46e9507372f0b1b963James Dong            fillHeight, fillWidth);
20970c1bc742181ded4930842b46e9507372f0b1b963James Dong
20980c1bc742181ded4930842b46e9507372f0b1b963James Dong        ref = pFill;
20990c1bc742181ded4930842b46e9507372f0b1b963James Dong        x0 = 0;
21000c1bc742181ded4930842b46e9507372f0b1b963James Dong        y0 = 0;
21010c1bc742181ded4930842b46e9507372f0b1b963James Dong        width = fillWidth;
21020c1bc742181ded4930842b46e9507372f0b1b963James Dong        height = fillHeight;
21030c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
21040c1bc742181ded4930842b46e9507372f0b1b963James Dong
21050c1bc742181ded4930842b46e9507372f0b1b963James Dong    partData = data + 16*16 + (partY>>1)*8 + (partX>>1);
21060c1bc742181ded4930842b46e9507372f0b1b963James Dong
21070c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* Chroma interpolation */
21080c1bc742181ded4930842b46e9507372f0b1b963James Dong    /*lint --e(737) Loss of sign */
21090c1bc742181ded4930842b46e9507372f0b1b963James Dong    ref += y0 * width + x0;
21100c1bc742181ded4930842b46e9507372f0b1b963James Dong    res = armVCM4P10_Interpolate_Chroma(ref, width, partData, 8,
21110c1bc742181ded4930842b46e9507372f0b1b963James Dong                            (u32)roi.width, (u32)roi.height, xFrac, yFrac);
21120c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(res == 0);
21130c1bc742181ded4930842b46e9507372f0b1b963James Dong    partData += 8 * 8;
21140c1bc742181ded4930842b46e9507372f0b1b963James Dong    ref += height * width;
21150c1bc742181ded4930842b46e9507372f0b1b963James Dong    res = armVCM4P10_Interpolate_Chroma(ref, width, partData, 8,
21160c1bc742181ded4930842b46e9507372f0b1b963James Dong                            (u32)roi.width, (u32)roi.height, xFrac, yFrac);
21170c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(res == 0);
21180c1bc742181ded4930842b46e9507372f0b1b963James Dong
21190c1bc742181ded4930842b46e9507372f0b1b963James Dong}
21200c1bc742181ded4930842b46e9507372f0b1b963James Dong
21210c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif /* H264DEC_OMXDL */
21220c1bc742181ded4930842b46e9507372f0b1b963James Dong
21230c1bc742181ded4930842b46e9507372f0b1b963James Dong
21240c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
21250c1bc742181ded4930842b46e9507372f0b1b963James Dong
21260c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: FillRow1
21270c1bc742181ded4930842b46e9507372f0b1b963James Dong
21280c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
21290c1bc742181ded4930842b46e9507372f0b1b963James Dong          This function gets a row of reference pels in a 'normal' case when no
21300c1bc742181ded4930842b46e9507372f0b1b963James Dong          overfilling is necessary.
21310c1bc742181ded4930842b46e9507372f0b1b963James Dong
21320c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
21330c1bc742181ded4930842b46e9507372f0b1b963James Dong
21340c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic void FillRow1(
21350c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *ref,
21360c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *fill,
21370c1bc742181ded4930842b46e9507372f0b1b963James Dong  i32 left,
21380c1bc742181ded4930842b46e9507372f0b1b963James Dong  i32 center,
21390c1bc742181ded4930842b46e9507372f0b1b963James Dong  i32 right)
21400c1bc742181ded4930842b46e9507372f0b1b963James Dong{
214184333e0475bc911adc16417f4ca327c975cf6c36Andreas Huber    UNUSED(left);
214284333e0475bc911adc16417f4ca327c975cf6c36Andreas Huber    UNUSED(right);
21430c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(ref);
21440c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(fill);
21450c1bc742181ded4930842b46e9507372f0b1b963James Dong
21460c1bc742181ded4930842b46e9507372f0b1b963James Dong    H264SwDecMemcpy(fill, ref, (u32)center);
21470c1bc742181ded4930842b46e9507372f0b1b963James Dong
21480c1bc742181ded4930842b46e9507372f0b1b963James Dong    /*lint -e(715) */
21490c1bc742181ded4930842b46e9507372f0b1b963James Dong}
21500c1bc742181ded4930842b46e9507372f0b1b963James Dong
21510c1bc742181ded4930842b46e9507372f0b1b963James Dong
21520c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
21530c1bc742181ded4930842b46e9507372f0b1b963James Dong
21540c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: h264bsdFillRow7
21550c1bc742181ded4930842b46e9507372f0b1b963James Dong
21560c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
21570c1bc742181ded4930842b46e9507372f0b1b963James Dong          This function gets a row of reference pels when horizontal coordinate
21580c1bc742181ded4930842b46e9507372f0b1b963James Dong          is partly negative or partly greater than reference picture width
21590c1bc742181ded4930842b46e9507372f0b1b963James Dong          (overfilling some pels on left and/or right edge).
21600c1bc742181ded4930842b46e9507372f0b1b963James Dong        Inputs:
21610c1bc742181ded4930842b46e9507372f0b1b963James Dong          ref       pointer to reference samples
21620c1bc742181ded4930842b46e9507372f0b1b963James Dong          left      amount of pixels to overfill on left-edge
21630c1bc742181ded4930842b46e9507372f0b1b963James Dong          center    amount of pixels to copy
21640c1bc742181ded4930842b46e9507372f0b1b963James Dong          right     amount of pixels to overfill on right-edge
21650c1bc742181ded4930842b46e9507372f0b1b963James Dong        Outputs:
21660c1bc742181ded4930842b46e9507372f0b1b963James Dong          fill      pointer where samples are stored
21670c1bc742181ded4930842b46e9507372f0b1b963James Dong
21680c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
21690c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifndef H264DEC_NEON
21700c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid h264bsdFillRow7(
21710c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *ref,
21720c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *fill,
21730c1bc742181ded4930842b46e9507372f0b1b963James Dong  i32 left,
21740c1bc742181ded4930842b46e9507372f0b1b963James Dong  i32 center,
21750c1bc742181ded4930842b46e9507372f0b1b963James Dong  i32 right)
21760c1bc742181ded4930842b46e9507372f0b1b963James Dong{
21770c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 tmp;
21780c1bc742181ded4930842b46e9507372f0b1b963James Dong
21790c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(ref);
21800c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(fill);
21810c1bc742181ded4930842b46e9507372f0b1b963James Dong
21820c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (left)
21830c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp = *ref;
21840c1bc742181ded4930842b46e9507372f0b1b963James Dong
21850c1bc742181ded4930842b46e9507372f0b1b963James Dong    for ( ; left; left--)
21860c1bc742181ded4930842b46e9507372f0b1b963James Dong        /*lint -esym(644,tmp)  tmp is initialized if used */
21870c1bc742181ded4930842b46e9507372f0b1b963James Dong        *fill++ = tmp;
21880c1bc742181ded4930842b46e9507372f0b1b963James Dong
21890c1bc742181ded4930842b46e9507372f0b1b963James Dong    for ( ; center; center--)
21900c1bc742181ded4930842b46e9507372f0b1b963James Dong        *fill++ = *ref++;
21910c1bc742181ded4930842b46e9507372f0b1b963James Dong
21920c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (right)
21930c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp = ref[-1];
21940c1bc742181ded4930842b46e9507372f0b1b963James Dong
21950c1bc742181ded4930842b46e9507372f0b1b963James Dong    for ( ; right; right--)
21960c1bc742181ded4930842b46e9507372f0b1b963James Dong        /*lint -esym(644,tmp)  tmp is initialized if used */
21970c1bc742181ded4930842b46e9507372f0b1b963James Dong        *fill++ = tmp;
21980c1bc742181ded4930842b46e9507372f0b1b963James Dong}
21990c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif
22000c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
22010c1bc742181ded4930842b46e9507372f0b1b963James Dong
22020c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: h264bsdFillBlock
22030c1bc742181ded4930842b46e9507372f0b1b963James Dong
22040c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
22050c1bc742181ded4930842b46e9507372f0b1b963James Dong          This function gets a block of reference pels. It determines whether
22060c1bc742181ded4930842b46e9507372f0b1b963James Dong          overfilling is needed or not and repeatedly calls an appropriate
22070c1bc742181ded4930842b46e9507372f0b1b963James Dong          function (by using a function pointer) that fills one row the block.
22080c1bc742181ded4930842b46e9507372f0b1b963James Dong        Inputs:
22090c1bc742181ded4930842b46e9507372f0b1b963James Dong          ref               pointer to reference frame
22100c1bc742181ded4930842b46e9507372f0b1b963James Dong          x0                x-coordinate for block
22110c1bc742181ded4930842b46e9507372f0b1b963James Dong          y0                y-coordinate for block
22120c1bc742181ded4930842b46e9507372f0b1b963James Dong          width             width of reference frame
22130c1bc742181ded4930842b46e9507372f0b1b963James Dong          height            height of reference frame
22140c1bc742181ded4930842b46e9507372f0b1b963James Dong          blockWidth        width of block
22150c1bc742181ded4930842b46e9507372f0b1b963James Dong          blockHeight       height of block
22160c1bc742181ded4930842b46e9507372f0b1b963James Dong          fillScanLength    length of a line in output array (pixels)
22170c1bc742181ded4930842b46e9507372f0b1b963James Dong        Outputs:
22180c1bc742181ded4930842b46e9507372f0b1b963James Dong          fill              pointer to array where output block is written
22190c1bc742181ded4930842b46e9507372f0b1b963James Dong
22200c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
22210c1bc742181ded4930842b46e9507372f0b1b963James Dong
22220c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid h264bsdFillBlock(
22230c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *ref,
22240c1bc742181ded4930842b46e9507372f0b1b963James Dong  u8 *fill,
22250c1bc742181ded4930842b46e9507372f0b1b963James Dong  i32 x0,
22260c1bc742181ded4930842b46e9507372f0b1b963James Dong  i32 y0,
22270c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 width,
22280c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 height,
22290c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 blockWidth,
22300c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 blockHeight,
22310c1bc742181ded4930842b46e9507372f0b1b963James Dong  u32 fillScanLength)
22320c1bc742181ded4930842b46e9507372f0b1b963James Dong
22330c1bc742181ded4930842b46e9507372f0b1b963James Dong{
22340c1bc742181ded4930842b46e9507372f0b1b963James Dong
22350c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
22360c1bc742181ded4930842b46e9507372f0b1b963James Dong
22370c1bc742181ded4930842b46e9507372f0b1b963James Dong    i32 xstop, ystop;
22380c1bc742181ded4930842b46e9507372f0b1b963James Dong    void (*fp)(u8*, u8*, i32, i32, i32);
22390c1bc742181ded4930842b46e9507372f0b1b963James Dong    i32 left, x, right;
22400c1bc742181ded4930842b46e9507372f0b1b963James Dong    i32 top, y, bottom;
22410c1bc742181ded4930842b46e9507372f0b1b963James Dong
22420c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
22430c1bc742181ded4930842b46e9507372f0b1b963James Dong
22440c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(ref);
22450c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(fill);
22460c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(width);
22470c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(height);
22480c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(fill);
22490c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(blockWidth);
22500c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(blockHeight);
22510c1bc742181ded4930842b46e9507372f0b1b963James Dong
22520c1bc742181ded4930842b46e9507372f0b1b963James Dong    xstop = x0 + (i32)blockWidth;
22530c1bc742181ded4930842b46e9507372f0b1b963James Dong    ystop = y0 + (i32)blockHeight;
22540c1bc742181ded4930842b46e9507372f0b1b963James Dong
22550c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* Choose correct function whether overfilling on left-edge or right-edge
22560c1bc742181ded4930842b46e9507372f0b1b963James Dong     * is needed or not */
22570c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (x0 >= 0 && xstop <= (i32)width)
22580c1bc742181ded4930842b46e9507372f0b1b963James Dong        fp = FillRow1;
22590c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
22600c1bc742181ded4930842b46e9507372f0b1b963James Dong        fp = h264bsdFillRow7;
22610c1bc742181ded4930842b46e9507372f0b1b963James Dong
22620c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (ystop < 0)
22630c1bc742181ded4930842b46e9507372f0b1b963James Dong        y0 = -(i32)blockHeight;
22640c1bc742181ded4930842b46e9507372f0b1b963James Dong
22650c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (xstop < 0)
22660c1bc742181ded4930842b46e9507372f0b1b963James Dong        x0 = -(i32)blockWidth;
22670c1bc742181ded4930842b46e9507372f0b1b963James Dong
22680c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (y0 > (i32)height)
22690c1bc742181ded4930842b46e9507372f0b1b963James Dong        y0 = (i32)height;
22700c1bc742181ded4930842b46e9507372f0b1b963James Dong
22710c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (x0 > (i32)width)
22720c1bc742181ded4930842b46e9507372f0b1b963James Dong        x0 = (i32)width;
22730c1bc742181ded4930842b46e9507372f0b1b963James Dong
22740c1bc742181ded4930842b46e9507372f0b1b963James Dong    xstop = x0 + (i32)blockWidth;
22750c1bc742181ded4930842b46e9507372f0b1b963James Dong    ystop = y0 + (i32)blockHeight;
22760c1bc742181ded4930842b46e9507372f0b1b963James Dong
22770c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (x0 > 0)
22780c1bc742181ded4930842b46e9507372f0b1b963James Dong        ref += x0;
22790c1bc742181ded4930842b46e9507372f0b1b963James Dong
22800c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (y0 > 0)
22810c1bc742181ded4930842b46e9507372f0b1b963James Dong        ref += y0 * (i32)width;
22820c1bc742181ded4930842b46e9507372f0b1b963James Dong
22830c1bc742181ded4930842b46e9507372f0b1b963James Dong    left = x0 < 0 ? -x0 : 0;
22840c1bc742181ded4930842b46e9507372f0b1b963James Dong    right = xstop > (i32)width ? xstop - (i32)width : 0;
22850c1bc742181ded4930842b46e9507372f0b1b963James Dong    x = (i32)blockWidth - left - right;
22860c1bc742181ded4930842b46e9507372f0b1b963James Dong
22870c1bc742181ded4930842b46e9507372f0b1b963James Dong    top = y0 < 0 ? -y0 : 0;
22880c1bc742181ded4930842b46e9507372f0b1b963James Dong    bottom = ystop > (i32)height ? ystop - (i32)height : 0;
22890c1bc742181ded4930842b46e9507372f0b1b963James Dong    y = (i32)blockHeight - top - bottom;
22900c1bc742181ded4930842b46e9507372f0b1b963James Dong
22910c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* Top-overfilling */
22920c1bc742181ded4930842b46e9507372f0b1b963James Dong    for ( ; top; top-- )
22930c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
22940c1bc742181ded4930842b46e9507372f0b1b963James Dong        (*fp)(ref, fill, left, x, right);
22950c1bc742181ded4930842b46e9507372f0b1b963James Dong        fill += fillScanLength;
22960c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
22970c1bc742181ded4930842b46e9507372f0b1b963James Dong
22980c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* Lines inside reference image */
22990c1bc742181ded4930842b46e9507372f0b1b963James Dong    for ( ; y; y-- )
23000c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
23010c1bc742181ded4930842b46e9507372f0b1b963James Dong        (*fp)(ref, fill, left, x, right);
23020c1bc742181ded4930842b46e9507372f0b1b963James Dong        ref += width;
23030c1bc742181ded4930842b46e9507372f0b1b963James Dong        fill += fillScanLength;
23040c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
23050c1bc742181ded4930842b46e9507372f0b1b963James Dong
23060c1bc742181ded4930842b46e9507372f0b1b963James Dong    ref -= width;
23070c1bc742181ded4930842b46e9507372f0b1b963James Dong
23080c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* Bottom-overfilling */
23090c1bc742181ded4930842b46e9507372f0b1b963James Dong    for ( ; bottom; bottom-- )
23100c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
23110c1bc742181ded4930842b46e9507372f0b1b963James Dong        (*fp)(ref, fill, left, x, right);
23120c1bc742181ded4930842b46e9507372f0b1b963James Dong        fill += fillScanLength;
23130c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
23140c1bc742181ded4930842b46e9507372f0b1b963James Dong}
23150c1bc742181ded4930842b46e9507372f0b1b963James Dong
23160c1bc742181ded4930842b46e9507372f0b1b963James Dong/*lint +e701 +e702 */
23170c1bc742181ded4930842b46e9507372f0b1b963James Dong
23180c1bc742181ded4930842b46e9507372f0b1b963James Dong
2319