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          h264bsdIntraPrediction
270c1bc742181ded4930842b46e9507372f0b1b963James Dong          h264bsdGetNeighbourPels
280c1bc742181ded4930842b46e9507372f0b1b963James Dong          h264bsdIntra16x16Prediction
290c1bc742181ded4930842b46e9507372f0b1b963James Dong          h264bsdIntra4x4Prediction
300c1bc742181ded4930842b46e9507372f0b1b963James Dong          h264bsdIntraChromaPrediction
310c1bc742181ded4930842b46e9507372f0b1b963James Dong          h264bsdAddResidual
320c1bc742181ded4930842b46e9507372f0b1b963James Dong          Intra16x16VerticalPrediction
330c1bc742181ded4930842b46e9507372f0b1b963James Dong          Intra16x16HorizontalPrediction
340c1bc742181ded4930842b46e9507372f0b1b963James Dong          Intra16x16DcPrediction
350c1bc742181ded4930842b46e9507372f0b1b963James Dong          Intra16x16PlanePrediction
360c1bc742181ded4930842b46e9507372f0b1b963James Dong          IntraChromaDcPrediction
370c1bc742181ded4930842b46e9507372f0b1b963James Dong          IntraChromaHorizontalPrediction
380c1bc742181ded4930842b46e9507372f0b1b963James Dong          IntraChromaVerticalPrediction
390c1bc742181ded4930842b46e9507372f0b1b963James Dong          IntraChromaPlanePrediction
400c1bc742181ded4930842b46e9507372f0b1b963James Dong          Get4x4NeighbourPels
410c1bc742181ded4930842b46e9507372f0b1b963James Dong          Write4x4To16x16
420c1bc742181ded4930842b46e9507372f0b1b963James Dong          Intra4x4VerticalPrediction
430c1bc742181ded4930842b46e9507372f0b1b963James Dong          Intra4x4HorizontalPrediction
440c1bc742181ded4930842b46e9507372f0b1b963James Dong          Intra4x4DcPrediction
450c1bc742181ded4930842b46e9507372f0b1b963James Dong          Intra4x4DiagonalDownLeftPrediction
460c1bc742181ded4930842b46e9507372f0b1b963James Dong          Intra4x4DiagonalDownRightPrediction
470c1bc742181ded4930842b46e9507372f0b1b963James Dong          Intra4x4VerticalRightPrediction
480c1bc742181ded4930842b46e9507372f0b1b963James Dong          Intra4x4HorizontalDownPrediction
490c1bc742181ded4930842b46e9507372f0b1b963James Dong          Intra4x4VerticalLeftPrediction
500c1bc742181ded4930842b46e9507372f0b1b963James Dong          Intra4x4HorizontalUpPrediction
510c1bc742181ded4930842b46e9507372f0b1b963James Dong          DetermineIntra4x4PredMode
520c1bc742181ded4930842b46e9507372f0b1b963James Dong
530c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
540c1bc742181ded4930842b46e9507372f0b1b963James Dong
550c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
560c1bc742181ded4930842b46e9507372f0b1b963James Dong    1. Include headers
570c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
580c1bc742181ded4930842b46e9507372f0b1b963James Dong
590c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_intra_prediction.h"
600c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_util.h"
610c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_macroblock_layer.h"
620c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_neighbour.h"
630c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "h264bsd_image.h"
640c1bc742181ded4930842b46e9507372f0b1b963James Dong
650c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifdef H264DEC_OMXDL
660c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "omxtypes.h"
670c1bc742181ded4930842b46e9507372f0b1b963James Dong#include "omxVC.h"
680c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif /* H264DEC_OMXDL */
690c1bc742181ded4930842b46e9507372f0b1b963James Dong
700c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
710c1bc742181ded4930842b46e9507372f0b1b963James Dong    2. External compiler flags
720c1bc742181ded4930842b46e9507372f0b1b963James Dong--------------------------------------------------------------------------------
730c1bc742181ded4930842b46e9507372f0b1b963James Dong
740c1bc742181ded4930842b46e9507372f0b1b963James Dong--------------------------------------------------------------------------------
750c1bc742181ded4930842b46e9507372f0b1b963James Dong    3. Module defines
760c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
770c1bc742181ded4930842b46e9507372f0b1b963James Dong
780c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Switch off the following Lint messages for this file:
790c1bc742181ded4930842b46e9507372f0b1b963James Dong * Info 702: Shift right of signed quantity (int)
800c1bc742181ded4930842b46e9507372f0b1b963James Dong */
810c1bc742181ded4930842b46e9507372f0b1b963James Dong/*lint -e702 */
820c1bc742181ded4930842b46e9507372f0b1b963James Dong
830c1bc742181ded4930842b46e9507372f0b1b963James Dong
840c1bc742181ded4930842b46e9507372f0b1b963James Dong/* x- and y-coordinates for each block */
850c1bc742181ded4930842b46e9507372f0b1b963James Dongconst u32 h264bsdBlockX[16] =
860c1bc742181ded4930842b46e9507372f0b1b963James Dong    { 0, 4, 0, 4, 8, 12, 8, 12, 0, 4, 0, 4, 8, 12, 8, 12 };
870c1bc742181ded4930842b46e9507372f0b1b963James Dongconst u32 h264bsdBlockY[16] =
880c1bc742181ded4930842b46e9507372f0b1b963James Dong    { 0, 0, 4, 4, 0, 0, 4, 4, 8, 8, 12, 12, 8, 8, 12, 12 };
890c1bc742181ded4930842b46e9507372f0b1b963James Dong
900c1bc742181ded4930842b46e9507372f0b1b963James Dongconst u8 h264bsdClip[1280] =
910c1bc742181ded4930842b46e9507372f0b1b963James Dong{
920c1bc742181ded4930842b46e9507372f0b1b963James Dong    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
930c1bc742181ded4930842b46e9507372f0b1b963James Dong    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
940c1bc742181ded4930842b46e9507372f0b1b963James Dong    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
950c1bc742181ded4930842b46e9507372f0b1b963James Dong    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
960c1bc742181ded4930842b46e9507372f0b1b963James Dong    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
970c1bc742181ded4930842b46e9507372f0b1b963James Dong    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
980c1bc742181ded4930842b46e9507372f0b1b963James Dong    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
990c1bc742181ded4930842b46e9507372f0b1b963James Dong    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1000c1bc742181ded4930842b46e9507372f0b1b963James Dong    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1010c1bc742181ded4930842b46e9507372f0b1b963James Dong    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1020c1bc742181ded4930842b46e9507372f0b1b963James Dong    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1030c1bc742181ded4930842b46e9507372f0b1b963James Dong    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1040c1bc742181ded4930842b46e9507372f0b1b963James Dong    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1050c1bc742181ded4930842b46e9507372f0b1b963James Dong    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1060c1bc742181ded4930842b46e9507372f0b1b963James Dong    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1070c1bc742181ded4930842b46e9507372f0b1b963James Dong    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1080c1bc742181ded4930842b46e9507372f0b1b963James Dong    0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
1090c1bc742181ded4930842b46e9507372f0b1b963James Dong    16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
1100c1bc742181ded4930842b46e9507372f0b1b963James Dong    32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
1110c1bc742181ded4930842b46e9507372f0b1b963James Dong    48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
1120c1bc742181ded4930842b46e9507372f0b1b963James Dong    64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,
1130c1bc742181ded4930842b46e9507372f0b1b963James Dong    80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,
1140c1bc742181ded4930842b46e9507372f0b1b963James Dong    96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,
1150c1bc742181ded4930842b46e9507372f0b1b963James Dong    112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
1160c1bc742181ded4930842b46e9507372f0b1b963James Dong    128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
1170c1bc742181ded4930842b46e9507372f0b1b963James Dong    144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
1180c1bc742181ded4930842b46e9507372f0b1b963James Dong    160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
1190c1bc742181ded4930842b46e9507372f0b1b963James Dong    176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
1200c1bc742181ded4930842b46e9507372f0b1b963James Dong    192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
1210c1bc742181ded4930842b46e9507372f0b1b963James Dong    208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
1220c1bc742181ded4930842b46e9507372f0b1b963James Dong    224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
1230c1bc742181ded4930842b46e9507372f0b1b963James Dong    240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,
1240c1bc742181ded4930842b46e9507372f0b1b963James Dong    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
1250c1bc742181ded4930842b46e9507372f0b1b963James Dong    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
1260c1bc742181ded4930842b46e9507372f0b1b963James Dong    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
1270c1bc742181ded4930842b46e9507372f0b1b963James Dong    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
1280c1bc742181ded4930842b46e9507372f0b1b963James Dong    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
1290c1bc742181ded4930842b46e9507372f0b1b963James Dong    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
1300c1bc742181ded4930842b46e9507372f0b1b963James Dong    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
1310c1bc742181ded4930842b46e9507372f0b1b963James Dong    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
1320c1bc742181ded4930842b46e9507372f0b1b963James Dong    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
1330c1bc742181ded4930842b46e9507372f0b1b963James Dong    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
1340c1bc742181ded4930842b46e9507372f0b1b963James Dong    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
1350c1bc742181ded4930842b46e9507372f0b1b963James Dong    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
1360c1bc742181ded4930842b46e9507372f0b1b963James Dong    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
1370c1bc742181ded4930842b46e9507372f0b1b963James Dong    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
1380c1bc742181ded4930842b46e9507372f0b1b963James Dong    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
1390c1bc742181ded4930842b46e9507372f0b1b963James Dong    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
1400c1bc742181ded4930842b46e9507372f0b1b963James Dong    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
1410c1bc742181ded4930842b46e9507372f0b1b963James Dong    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
1420c1bc742181ded4930842b46e9507372f0b1b963James Dong    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
1430c1bc742181ded4930842b46e9507372f0b1b963James Dong    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
1440c1bc742181ded4930842b46e9507372f0b1b963James Dong    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
1450c1bc742181ded4930842b46e9507372f0b1b963James Dong    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
1460c1bc742181ded4930842b46e9507372f0b1b963James Dong    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
1470c1bc742181ded4930842b46e9507372f0b1b963James Dong    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
1480c1bc742181ded4930842b46e9507372f0b1b963James Dong    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
1490c1bc742181ded4930842b46e9507372f0b1b963James Dong    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
1500c1bc742181ded4930842b46e9507372f0b1b963James Dong    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
1510c1bc742181ded4930842b46e9507372f0b1b963James Dong    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
1520c1bc742181ded4930842b46e9507372f0b1b963James Dong    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
1530c1bc742181ded4930842b46e9507372f0b1b963James Dong    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
1540c1bc742181ded4930842b46e9507372f0b1b963James Dong    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
1550c1bc742181ded4930842b46e9507372f0b1b963James Dong    255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
1560c1bc742181ded4930842b46e9507372f0b1b963James Dong};
1570c1bc742181ded4930842b46e9507372f0b1b963James Dong
1580c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifndef H264DEC_OMXDL
1590c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
1600c1bc742181ded4930842b46e9507372f0b1b963James Dong    4. Local function prototypes
1610c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
1620c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic void Get4x4NeighbourPels(u8 *a, u8 *l, u8 *data, u8 *above, u8 *left,
1630c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 blockNum);
1640c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic void Intra16x16VerticalPrediction(u8 *data, u8 *above);
1650c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic void Intra16x16HorizontalPrediction(u8 *data, u8 *left);
1660c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic void Intra16x16DcPrediction(u8 *data, u8 *above, u8 *left,
1670c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 A, u32 B);
1680c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic void Intra16x16PlanePrediction(u8 *data, u8 *above, u8 *left);
1690c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic void IntraChromaDcPrediction(u8 *data, u8 *above, u8 *left,
1700c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 A, u32 B);
1710c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic void IntraChromaHorizontalPrediction(u8 *data, u8 *left);
1720c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic void IntraChromaVerticalPrediction(u8 *data, u8 *above);
1730c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic void IntraChromaPlanePrediction(u8 *data, u8 *above, u8 *left);
1740c1bc742181ded4930842b46e9507372f0b1b963James Dong
1750c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic void Intra4x4VerticalPrediction(u8 *data, u8 *above);
1760c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic void Intra4x4HorizontalPrediction(u8 *data, u8 *left);
1770c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic void Intra4x4DcPrediction(u8 *data, u8 *above, u8 *left, u32 A, u32 B);
1780c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic void Intra4x4DiagonalDownLeftPrediction(u8 *data, u8 *above);
1790c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic void Intra4x4DiagonalDownRightPrediction(u8 *data, u8 *above, u8 *left);
1800c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic void Intra4x4VerticalRightPrediction(u8 *data, u8 *above, u8 *left);
1810c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic void Intra4x4HorizontalDownPrediction(u8 *data, u8 *above, u8 *left);
1820c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic void Intra4x4VerticalLeftPrediction(u8 *data, u8 *above);
1830c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic void Intra4x4HorizontalUpPrediction(u8 *data, u8 *left);
1840c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid h264bsdAddResidual(u8 *data, i32 *residual, u32 blockNum);
1850c1bc742181ded4930842b46e9507372f0b1b963James Dong
1860c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic void Write4x4To16x16(u8 *data, u8 *data4x4, u32 blockNum);
1870c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif /* H264DEC_OMXDL */
1880c1bc742181ded4930842b46e9507372f0b1b963James Dong
1890c1bc742181ded4930842b46e9507372f0b1b963James Dongstatic u32 DetermineIntra4x4PredMode(macroblockLayer_t *pMbLayer,
1900c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 available, neighbour_t *nA, neighbour_t *nB, u32 index,
1910c1bc742181ded4930842b46e9507372f0b1b963James Dong    mbStorage_t *nMbA, mbStorage_t *nMbB);
1920c1bc742181ded4930842b46e9507372f0b1b963James Dong
1930c1bc742181ded4930842b46e9507372f0b1b963James Dong
1940c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifdef H264DEC_OMXDL
1950c1bc742181ded4930842b46e9507372f0b1b963James Dong
1960c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
1970c1bc742181ded4930842b46e9507372f0b1b963James Dong
1980c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: h264bsdIntra16x16Prediction
1990c1bc742181ded4930842b46e9507372f0b1b963James Dong
2000c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
2010c1bc742181ded4930842b46e9507372f0b1b963James Dong          Perform intra 16x16 prediction mode for luma pixels and add
2020c1bc742181ded4930842b46e9507372f0b1b963James Dong          residual into prediction. The resulting luma pixels are
2030c1bc742181ded4930842b46e9507372f0b1b963James Dong          stored in macroblock array 'data'.
2040c1bc742181ded4930842b46e9507372f0b1b963James Dong
2050c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
2060c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 h264bsdIntra16x16Prediction(mbStorage_t *pMb, u8 *data, u8 *ptr,
2070c1bc742181ded4930842b46e9507372f0b1b963James Dong                                u32 width, u32 constrainedIntraPred)
2080c1bc742181ded4930842b46e9507372f0b1b963James Dong{
2090c1bc742181ded4930842b46e9507372f0b1b963James Dong
2100c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
2110c1bc742181ded4930842b46e9507372f0b1b963James Dong
2120c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 availableA, availableB, availableD;
2130c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMXResult omxRes;
2140c1bc742181ded4930842b46e9507372f0b1b963James Dong
2150c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
2160c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(pMb);
2170c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(data);
2180c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(ptr);
2190c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(h264bsdPredModeIntra16x16(pMb->mbType) < 4);
2200c1bc742181ded4930842b46e9507372f0b1b963James Dong
2210c1bc742181ded4930842b46e9507372f0b1b963James Dong    availableA = h264bsdIsNeighbourAvailable(pMb, pMb->mbA);
2220c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (availableA && constrainedIntraPred &&
2230c1bc742181ded4930842b46e9507372f0b1b963James Dong       (h264bsdMbPartPredMode(pMb->mbA->mbType) == PRED_MODE_INTER))
2240c1bc742181ded4930842b46e9507372f0b1b963James Dong        availableA = HANTRO_FALSE;
2250c1bc742181ded4930842b46e9507372f0b1b963James Dong    availableB = h264bsdIsNeighbourAvailable(pMb, pMb->mbB);
2260c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (availableB && constrainedIntraPred &&
2270c1bc742181ded4930842b46e9507372f0b1b963James Dong       (h264bsdMbPartPredMode(pMb->mbB->mbType) == PRED_MODE_INTER))
2280c1bc742181ded4930842b46e9507372f0b1b963James Dong        availableB = HANTRO_FALSE;
2290c1bc742181ded4930842b46e9507372f0b1b963James Dong    availableD = h264bsdIsNeighbourAvailable(pMb, pMb->mbD);
2300c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (availableD && constrainedIntraPred &&
2310c1bc742181ded4930842b46e9507372f0b1b963James Dong       (h264bsdMbPartPredMode(pMb->mbD->mbType) == PRED_MODE_INTER))
2320c1bc742181ded4930842b46e9507372f0b1b963James Dong        availableD = HANTRO_FALSE;
2330c1bc742181ded4930842b46e9507372f0b1b963James Dong
2340c1bc742181ded4930842b46e9507372f0b1b963James Dong    omxRes = omxVCM4P10_PredictIntra_16x16( (ptr-1),
2350c1bc742181ded4930842b46e9507372f0b1b963James Dong                                    (ptr - width),
2360c1bc742181ded4930842b46e9507372f0b1b963James Dong                                    (ptr - width-1),
2370c1bc742181ded4930842b46e9507372f0b1b963James Dong                                    data,
2380c1bc742181ded4930842b46e9507372f0b1b963James Dong                                    (i32)width,
2390c1bc742181ded4930842b46e9507372f0b1b963James Dong                                    16,
2400c1bc742181ded4930842b46e9507372f0b1b963James Dong                                    (OMXVCM4P10Intra16x16PredMode)
2410c1bc742181ded4930842b46e9507372f0b1b963James Dong                                    h264bsdPredModeIntra16x16(pMb->mbType),
2420c1bc742181ded4930842b46e9507372f0b1b963James Dong                                    (i32)(availableB + (availableA<<1) +
2430c1bc742181ded4930842b46e9507372f0b1b963James Dong                                     (availableD<<5)) );
2440c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (omxRes != OMX_Sts_NoErr)
2450c1bc742181ded4930842b46e9507372f0b1b963James Dong        return HANTRO_NOK;
2460c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
2470c1bc742181ded4930842b46e9507372f0b1b963James Dong        return(HANTRO_OK);
2480c1bc742181ded4930842b46e9507372f0b1b963James Dong}
2490c1bc742181ded4930842b46e9507372f0b1b963James Dong
2500c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
2510c1bc742181ded4930842b46e9507372f0b1b963James Dong
2520c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: h264bsdIntra4x4Prediction
2530c1bc742181ded4930842b46e9507372f0b1b963James Dong
2540c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
2550c1bc742181ded4930842b46e9507372f0b1b963James Dong          Perform intra 4x4 prediction for luma pixels and add residual
2560c1bc742181ded4930842b46e9507372f0b1b963James Dong          into prediction. The resulting luma pixels are stored in
2570c1bc742181ded4930842b46e9507372f0b1b963James Dong          macroblock array 'data'. The intra 4x4 prediction mode for each
2580c1bc742181ded4930842b46e9507372f0b1b963James Dong          block is stored in 'pMb' structure.
2590c1bc742181ded4930842b46e9507372f0b1b963James Dong
2600c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
2610c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 h264bsdIntra4x4Prediction(mbStorage_t *pMb, u8 *data,
2620c1bc742181ded4930842b46e9507372f0b1b963James Dong                              macroblockLayer_t *mbLayer,
2630c1bc742181ded4930842b46e9507372f0b1b963James Dong                              u8 *ptr, u32 width,
2640c1bc742181ded4930842b46e9507372f0b1b963James Dong                              u32 constrainedIntraPred, u32 block)
2650c1bc742181ded4930842b46e9507372f0b1b963James Dong{
2660c1bc742181ded4930842b46e9507372f0b1b963James Dong
2670c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
2680c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 mode;
2690c1bc742181ded4930842b46e9507372f0b1b963James Dong    neighbour_t neighbour, neighbourB;
2700c1bc742181ded4930842b46e9507372f0b1b963James Dong    mbStorage_t *nMb, *nMb2;
2710c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 availableA, availableB, availableC, availableD;
2720c1bc742181ded4930842b46e9507372f0b1b963James Dong
2730c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMXResult omxRes;
2740c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 x, y;
2750c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 *l, *a, *al;
2760c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
2770c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(pMb);
2780c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(data);
2790c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(mbLayer);
2800c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(ptr);
2810c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(pMb->intra4x4PredMode[block] < 9);
2820c1bc742181ded4930842b46e9507372f0b1b963James Dong
2830c1bc742181ded4930842b46e9507372f0b1b963James Dong    neighbour = *h264bsdNeighbour4x4BlockA(block);
2840c1bc742181ded4930842b46e9507372f0b1b963James Dong    nMb = h264bsdGetNeighbourMb(pMb, neighbour.mb);
2850c1bc742181ded4930842b46e9507372f0b1b963James Dong    availableA = h264bsdIsNeighbourAvailable(pMb, nMb);
2860c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (availableA && constrainedIntraPred &&
2870c1bc742181ded4930842b46e9507372f0b1b963James Dong       ( h264bsdMbPartPredMode(nMb->mbType) == PRED_MODE_INTER) )
2880c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
2890c1bc742181ded4930842b46e9507372f0b1b963James Dong        availableA = HANTRO_FALSE;
2900c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
2910c1bc742181ded4930842b46e9507372f0b1b963James Dong
2920c1bc742181ded4930842b46e9507372f0b1b963James Dong    neighbourB = *h264bsdNeighbour4x4BlockB(block);
2930c1bc742181ded4930842b46e9507372f0b1b963James Dong    nMb2 = h264bsdGetNeighbourMb(pMb, neighbourB.mb);
2940c1bc742181ded4930842b46e9507372f0b1b963James Dong    availableB = h264bsdIsNeighbourAvailable(pMb, nMb2);
2950c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (availableB && constrainedIntraPred &&
2960c1bc742181ded4930842b46e9507372f0b1b963James Dong       ( h264bsdMbPartPredMode(nMb2->mbType) == PRED_MODE_INTER) )
2970c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
2980c1bc742181ded4930842b46e9507372f0b1b963James Dong        availableB = HANTRO_FALSE;
2990c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
3000c1bc742181ded4930842b46e9507372f0b1b963James Dong
3010c1bc742181ded4930842b46e9507372f0b1b963James Dong    mode = DetermineIntra4x4PredMode(mbLayer,
3020c1bc742181ded4930842b46e9507372f0b1b963James Dong        (u32)(availableA && availableB),
3030c1bc742181ded4930842b46e9507372f0b1b963James Dong        &neighbour, &neighbourB, block, nMb, nMb2);
3040c1bc742181ded4930842b46e9507372f0b1b963James Dong    pMb->intra4x4PredMode[block] = (u8)mode;
3050c1bc742181ded4930842b46e9507372f0b1b963James Dong
3060c1bc742181ded4930842b46e9507372f0b1b963James Dong    neighbour = *h264bsdNeighbour4x4BlockC(block);
3070c1bc742181ded4930842b46e9507372f0b1b963James Dong    nMb = h264bsdGetNeighbourMb(pMb, neighbour.mb);
3080c1bc742181ded4930842b46e9507372f0b1b963James Dong    availableC = h264bsdIsNeighbourAvailable(pMb, nMb);
3090c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (availableC && constrainedIntraPred &&
3100c1bc742181ded4930842b46e9507372f0b1b963James Dong       ( h264bsdMbPartPredMode(nMb->mbType) == PRED_MODE_INTER) )
3110c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
3120c1bc742181ded4930842b46e9507372f0b1b963James Dong        availableC = HANTRO_FALSE;
3130c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
3140c1bc742181ded4930842b46e9507372f0b1b963James Dong
3150c1bc742181ded4930842b46e9507372f0b1b963James Dong    neighbour = *h264bsdNeighbour4x4BlockD(block);
3160c1bc742181ded4930842b46e9507372f0b1b963James Dong    nMb = h264bsdGetNeighbourMb(pMb, neighbour.mb);
3170c1bc742181ded4930842b46e9507372f0b1b963James Dong    availableD = h264bsdIsNeighbourAvailable(pMb, nMb);
3180c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (availableD && constrainedIntraPred &&
3190c1bc742181ded4930842b46e9507372f0b1b963James Dong       ( h264bsdMbPartPredMode(nMb->mbType) == PRED_MODE_INTER) )
3200c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
3210c1bc742181ded4930842b46e9507372f0b1b963James Dong        availableD = HANTRO_FALSE;
3220c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
3230c1bc742181ded4930842b46e9507372f0b1b963James Dong
3240c1bc742181ded4930842b46e9507372f0b1b963James Dong    x = h264bsdBlockX[block];
3250c1bc742181ded4930842b46e9507372f0b1b963James Dong    y = h264bsdBlockY[block];
3260c1bc742181ded4930842b46e9507372f0b1b963James Dong
3270c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (y == 0)
3280c1bc742181ded4930842b46e9507372f0b1b963James Dong        a = ptr - width + x;
3290c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
3300c1bc742181ded4930842b46e9507372f0b1b963James Dong        a = data-16;
3310c1bc742181ded4930842b46e9507372f0b1b963James Dong
3320c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (x == 0)
3330c1bc742181ded4930842b46e9507372f0b1b963James Dong        l = ptr + y * width -1;
3340c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
3350c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
3360c1bc742181ded4930842b46e9507372f0b1b963James Dong        l = data-1;
3370c1bc742181ded4930842b46e9507372f0b1b963James Dong        width = 16;
3380c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
3390c1bc742181ded4930842b46e9507372f0b1b963James Dong
3400c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (x == 0)
3410c1bc742181ded4930842b46e9507372f0b1b963James Dong        al = l-width;
3420c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
3430c1bc742181ded4930842b46e9507372f0b1b963James Dong        al = a-1;
3440c1bc742181ded4930842b46e9507372f0b1b963James Dong
3450c1bc742181ded4930842b46e9507372f0b1b963James Dong    omxRes = omxVCM4P10_PredictIntra_4x4( l,
3460c1bc742181ded4930842b46e9507372f0b1b963James Dong                                          a,
3470c1bc742181ded4930842b46e9507372f0b1b963James Dong                                          al,
3480c1bc742181ded4930842b46e9507372f0b1b963James Dong                                          data,
3490c1bc742181ded4930842b46e9507372f0b1b963James Dong                                          (i32)width,
3500c1bc742181ded4930842b46e9507372f0b1b963James Dong                                          16,
3510c1bc742181ded4930842b46e9507372f0b1b963James Dong                                          (OMXVCM4P10Intra4x4PredMode)mode,
3520c1bc742181ded4930842b46e9507372f0b1b963James Dong                                          (i32)(availableB +
3530c1bc742181ded4930842b46e9507372f0b1b963James Dong                                          (availableA<<1) +
3540c1bc742181ded4930842b46e9507372f0b1b963James Dong                                          (availableD<<5) +
3550c1bc742181ded4930842b46e9507372f0b1b963James Dong                                          (availableC<<6)) );
3560c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (omxRes != OMX_Sts_NoErr)
3570c1bc742181ded4930842b46e9507372f0b1b963James Dong        return HANTRO_NOK;
3580c1bc742181ded4930842b46e9507372f0b1b963James Dong
3590c1bc742181ded4930842b46e9507372f0b1b963James Dong    return(HANTRO_OK);
3600c1bc742181ded4930842b46e9507372f0b1b963James Dong
3610c1bc742181ded4930842b46e9507372f0b1b963James Dong}
3620c1bc742181ded4930842b46e9507372f0b1b963James Dong
3630c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
3640c1bc742181ded4930842b46e9507372f0b1b963James Dong
3650c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: h264bsdIntraChromaPrediction
3660c1bc742181ded4930842b46e9507372f0b1b963James Dong
3670c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
3680c1bc742181ded4930842b46e9507372f0b1b963James Dong          Perform intra prediction for chroma pixels and add residual
3690c1bc742181ded4930842b46e9507372f0b1b963James Dong          into prediction. The resulting chroma pixels are stored in 'data'.
3700c1bc742181ded4930842b46e9507372f0b1b963James Dong
3710c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
3720c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 h264bsdIntraChromaPrediction(mbStorage_t *pMb, u8 *data, image_t *image,
3730c1bc742181ded4930842b46e9507372f0b1b963James Dong                                        u32 predMode, u32 constrainedIntraPred)
3740c1bc742181ded4930842b46e9507372f0b1b963James Dong{
3750c1bc742181ded4930842b46e9507372f0b1b963James Dong
3760c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
3770c1bc742181ded4930842b46e9507372f0b1b963James Dong
3780c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 availableA, availableB, availableD;
3790c1bc742181ded4930842b46e9507372f0b1b963James Dong    OMXResult omxRes;
3800c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 *ptr;
3810c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 width;
3820c1bc742181ded4930842b46e9507372f0b1b963James Dong
3830c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
3840c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(pMb);
3850c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(data);
3860c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(image);
3870c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(predMode < 4);
3880c1bc742181ded4930842b46e9507372f0b1b963James Dong
3890c1bc742181ded4930842b46e9507372f0b1b963James Dong    availableA = h264bsdIsNeighbourAvailable(pMb, pMb->mbA);
3900c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (availableA && constrainedIntraPred &&
3910c1bc742181ded4930842b46e9507372f0b1b963James Dong       (h264bsdMbPartPredMode(pMb->mbA->mbType) == PRED_MODE_INTER))
3920c1bc742181ded4930842b46e9507372f0b1b963James Dong        availableA = HANTRO_FALSE;
3930c1bc742181ded4930842b46e9507372f0b1b963James Dong    availableB = h264bsdIsNeighbourAvailable(pMb, pMb->mbB);
3940c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (availableB && constrainedIntraPred &&
3950c1bc742181ded4930842b46e9507372f0b1b963James Dong       (h264bsdMbPartPredMode(pMb->mbB->mbType) == PRED_MODE_INTER))
3960c1bc742181ded4930842b46e9507372f0b1b963James Dong        availableB = HANTRO_FALSE;
3970c1bc742181ded4930842b46e9507372f0b1b963James Dong    availableD = h264bsdIsNeighbourAvailable(pMb, pMb->mbD);
3980c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (availableD && constrainedIntraPred &&
3990c1bc742181ded4930842b46e9507372f0b1b963James Dong       (h264bsdMbPartPredMode(pMb->mbD->mbType) == PRED_MODE_INTER))
4000c1bc742181ded4930842b46e9507372f0b1b963James Dong        availableD = HANTRO_FALSE;
4010c1bc742181ded4930842b46e9507372f0b1b963James Dong
4020c1bc742181ded4930842b46e9507372f0b1b963James Dong    ptr = image->cb;
4030c1bc742181ded4930842b46e9507372f0b1b963James Dong    width = image->width*8;
4040c1bc742181ded4930842b46e9507372f0b1b963James Dong
4050c1bc742181ded4930842b46e9507372f0b1b963James Dong    omxRes = omxVCM4P10_PredictIntraChroma_8x8( (ptr-1),
4060c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                (ptr - width),
4070c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                (ptr - width -1),
4080c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                data,
4090c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                (i32)width,
4100c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                8,
4110c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                (OMXVCM4P10IntraChromaPredMode)
4120c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                predMode,
4130c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                (i32)(availableB +
4140c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                 (availableA<<1) +
4150c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                 (availableD<<5)) );
4160c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (omxRes != OMX_Sts_NoErr)
4170c1bc742181ded4930842b46e9507372f0b1b963James Dong        return HANTRO_NOK;
4180c1bc742181ded4930842b46e9507372f0b1b963James Dong
4190c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* advance pointers */
4200c1bc742181ded4930842b46e9507372f0b1b963James Dong    data += 64;
4210c1bc742181ded4930842b46e9507372f0b1b963James Dong    ptr = image->cr;
4220c1bc742181ded4930842b46e9507372f0b1b963James Dong
4230c1bc742181ded4930842b46e9507372f0b1b963James Dong    omxRes = omxVCM4P10_PredictIntraChroma_8x8( (ptr-1),
4240c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                (ptr - width),
4250c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                (ptr - width -1),
4260c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                data,
4270c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                (i32)width,
4280c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                8,
4290c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                (OMXVCM4P10IntraChromaPredMode)
4300c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                predMode,
4310c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                (i32)(availableB +
4320c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                 (availableA<<1) +
4330c1bc742181ded4930842b46e9507372f0b1b963James Dong                                                 (availableD<<5)) );
4340c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (omxRes != OMX_Sts_NoErr)
4350c1bc742181ded4930842b46e9507372f0b1b963James Dong        return HANTRO_NOK;
4360c1bc742181ded4930842b46e9507372f0b1b963James Dong
4370c1bc742181ded4930842b46e9507372f0b1b963James Dong    return(HANTRO_OK);
4380c1bc742181ded4930842b46e9507372f0b1b963James Dong
4390c1bc742181ded4930842b46e9507372f0b1b963James Dong}
4400c1bc742181ded4930842b46e9507372f0b1b963James Dong
4410c1bc742181ded4930842b46e9507372f0b1b963James Dong
4420c1bc742181ded4930842b46e9507372f0b1b963James Dong#else /* H264DEC_OMXDL */
4430c1bc742181ded4930842b46e9507372f0b1b963James Dong
4440c1bc742181ded4930842b46e9507372f0b1b963James Dong
4450c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
4460c1bc742181ded4930842b46e9507372f0b1b963James Dong
4470c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: h264bsdIntraPrediction
4480c1bc742181ded4930842b46e9507372f0b1b963James Dong
4490c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
4500c1bc742181ded4930842b46e9507372f0b1b963James Dong          Processes one intra macroblock. Performs intra prediction using
4510c1bc742181ded4930842b46e9507372f0b1b963James Dong          specified prediction mode. Writes the final macroblock
4520c1bc742181ded4930842b46e9507372f0b1b963James Dong          (prediction + residual) into the output image (image)
4530c1bc742181ded4930842b46e9507372f0b1b963James Dong
4540c1bc742181ded4930842b46e9507372f0b1b963James Dong        Inputs:
4550c1bc742181ded4930842b46e9507372f0b1b963James Dong          pMb           pointer to macroblock specific information
4560c1bc742181ded4930842b46e9507372f0b1b963James Dong          mbLayer       pointer to current macroblock data from stream
4570c1bc742181ded4930842b46e9507372f0b1b963James Dong          image         pointer to output image
4580c1bc742181ded4930842b46e9507372f0b1b963James Dong          mbNum         current macroblock number
4590c1bc742181ded4930842b46e9507372f0b1b963James Dong          constrainedIntraPred  flag specifying if neighbouring inter
4600c1bc742181ded4930842b46e9507372f0b1b963James Dong                                macroblocks are used in intra prediction
4610c1bc742181ded4930842b46e9507372f0b1b963James Dong          data          pointer where output macroblock will be stored
4620c1bc742181ded4930842b46e9507372f0b1b963James Dong
4630c1bc742181ded4930842b46e9507372f0b1b963James Dong        Outputs:
4640c1bc742181ded4930842b46e9507372f0b1b963James Dong          pMb           structure is updated with current macroblock
4650c1bc742181ded4930842b46e9507372f0b1b963James Dong          image         current macroblock is written into image
4660c1bc742181ded4930842b46e9507372f0b1b963James Dong          data          current macroblock is stored here
4670c1bc742181ded4930842b46e9507372f0b1b963James Dong
4680c1bc742181ded4930842b46e9507372f0b1b963James Dong        Returns:
4690c1bc742181ded4930842b46e9507372f0b1b963James Dong          HANTRO_OK     success
4700c1bc742181ded4930842b46e9507372f0b1b963James Dong          HANTRO_NOK    error in intra prediction
4710c1bc742181ded4930842b46e9507372f0b1b963James Dong
4720c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
4730c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 h264bsdIntraPrediction(mbStorage_t *pMb, macroblockLayer_t *mbLayer,
4740c1bc742181ded4930842b46e9507372f0b1b963James Dong    image_t *image, u32 mbNum, u32 constrainedIntraPred, u8 *data)
4750c1bc742181ded4930842b46e9507372f0b1b963James Dong{
4760c1bc742181ded4930842b46e9507372f0b1b963James Dong
4770c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
4780c1bc742181ded4930842b46e9507372f0b1b963James Dong
4790c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* pelAbove and pelLeft contain samples above and left to the current
4800c1bc742181ded4930842b46e9507372f0b1b963James Dong     * macroblock. Above array contains also sample above-left to the current
4810c1bc742181ded4930842b46e9507372f0b1b963James Dong     * mb as well as 4 samples above-right to the current mb (latter only for
4820c1bc742181ded4930842b46e9507372f0b1b963James Dong     * luma) */
4830c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* lumD + lumB + lumC + cbD + cbB + crD + crB */
4840c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 pelAbove[1 + 16 + 4 + 1 + 8 + 1 + 8];
4850c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* lumA + cbA + crA */
4860c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 pelLeft[16 + 8 + 8];
4870c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 tmp;
4880c1bc742181ded4930842b46e9507372f0b1b963James Dong
4890c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
4900c1bc742181ded4930842b46e9507372f0b1b963James Dong
4910c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(pMb);
4920c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(image);
4930c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(mbNum < image->width * image->height);
4940c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(h264bsdMbPartPredMode(pMb->mbType) != PRED_MODE_INTER);
4950c1bc742181ded4930842b46e9507372f0b1b963James Dong
4960c1bc742181ded4930842b46e9507372f0b1b963James Dong    h264bsdGetNeighbourPels(image, pelAbove, pelLeft, mbNum);
4970c1bc742181ded4930842b46e9507372f0b1b963James Dong
4980c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (h264bsdMbPartPredMode(pMb->mbType) == PRED_MODE_INTRA16x16)
4990c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
5000c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp = h264bsdIntra16x16Prediction(pMb, data, mbLayer->residual.level,
5010c1bc742181ded4930842b46e9507372f0b1b963James Dong            pelAbove, pelLeft, constrainedIntraPred);
5020c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (tmp != HANTRO_OK)
5030c1bc742181ded4930842b46e9507372f0b1b963James Dong            return(tmp);
5040c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
5050c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
5060c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
5070c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp = h264bsdIntra4x4Prediction(pMb, data, mbLayer,
5080c1bc742181ded4930842b46e9507372f0b1b963James Dong            pelAbove, pelLeft, constrainedIntraPred);
5090c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (tmp != HANTRO_OK)
5100c1bc742181ded4930842b46e9507372f0b1b963James Dong            return(tmp);
5110c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
5120c1bc742181ded4930842b46e9507372f0b1b963James Dong
5130c1bc742181ded4930842b46e9507372f0b1b963James Dong    tmp = h264bsdIntraChromaPrediction(pMb, data + 256,
5140c1bc742181ded4930842b46e9507372f0b1b963James Dong            mbLayer->residual.level+16, pelAbove + 21, pelLeft + 16,
5150c1bc742181ded4930842b46e9507372f0b1b963James Dong            mbLayer->mbPred.intraChromaPredMode, constrainedIntraPred);
5160c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (tmp != HANTRO_OK)
5170c1bc742181ded4930842b46e9507372f0b1b963James Dong        return(tmp);
5180c1bc742181ded4930842b46e9507372f0b1b963James Dong
5190c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* if decoded flag > 1 -> mb has already been successfully decoded and
5200c1bc742181ded4930842b46e9507372f0b1b963James Dong     * written to output -> do not write again */
5210c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (pMb->decoded > 1)
5220c1bc742181ded4930842b46e9507372f0b1b963James Dong        return HANTRO_OK;
5230c1bc742181ded4930842b46e9507372f0b1b963James Dong
5240c1bc742181ded4930842b46e9507372f0b1b963James Dong    h264bsdWriteMacroblock(image, data);
5250c1bc742181ded4930842b46e9507372f0b1b963James Dong
5260c1bc742181ded4930842b46e9507372f0b1b963James Dong    return(HANTRO_OK);
5270c1bc742181ded4930842b46e9507372f0b1b963James Dong
5280c1bc742181ded4930842b46e9507372f0b1b963James Dong}
5290c1bc742181ded4930842b46e9507372f0b1b963James Dong
5300c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
5310c1bc742181ded4930842b46e9507372f0b1b963James Dong
5320c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: h264bsdGetNeighbourPels
5330c1bc742181ded4930842b46e9507372f0b1b963James Dong
5340c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
5350c1bc742181ded4930842b46e9507372f0b1b963James Dong          Get pixel values from neighbouring macroblocks into 'above'
5360c1bc742181ded4930842b46e9507372f0b1b963James Dong          and 'left' arrays.
5370c1bc742181ded4930842b46e9507372f0b1b963James Dong
5380c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
5390c1bc742181ded4930842b46e9507372f0b1b963James Dong
5400c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid h264bsdGetNeighbourPels(image_t *image, u8 *above, u8 *left, u32 mbNum)
5410c1bc742181ded4930842b46e9507372f0b1b963James Dong{
5420c1bc742181ded4930842b46e9507372f0b1b963James Dong
5430c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
5440c1bc742181ded4930842b46e9507372f0b1b963James Dong
5450c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 i;
5460c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 width, picSize;
5470c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 *ptr, *tmp;
5480c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 row, col;
5490c1bc742181ded4930842b46e9507372f0b1b963James Dong
5500c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
5510c1bc742181ded4930842b46e9507372f0b1b963James Dong
5520c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(image);
5530c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(above);
5540c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(left);
5550c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(mbNum < image->width * image->height);
5560c1bc742181ded4930842b46e9507372f0b1b963James Dong
5570c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (!mbNum)
5580c1bc742181ded4930842b46e9507372f0b1b963James Dong        return;
5590c1bc742181ded4930842b46e9507372f0b1b963James Dong
5600c1bc742181ded4930842b46e9507372f0b1b963James Dong    width = image->width;
5610c1bc742181ded4930842b46e9507372f0b1b963James Dong    picSize = width * image->height;
5620c1bc742181ded4930842b46e9507372f0b1b963James Dong    row = mbNum / width;
5630c1bc742181ded4930842b46e9507372f0b1b963James Dong    col = mbNum - row * width;
5640c1bc742181ded4930842b46e9507372f0b1b963James Dong
5650c1bc742181ded4930842b46e9507372f0b1b963James Dong    width *= 16;
5660c1bc742181ded4930842b46e9507372f0b1b963James Dong    ptr = image->data + row * 16 * width  + col * 16;
5670c1bc742181ded4930842b46e9507372f0b1b963James Dong
5680c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* note that luma samples above-right to current macroblock do not make
5690c1bc742181ded4930842b46e9507372f0b1b963James Dong     * sense when current mb is the right-most mb in a row. Same applies to
5700c1bc742181ded4930842b46e9507372f0b1b963James Dong     * sample above-left if col is zero. However, usage of pels in prediction
5710c1bc742181ded4930842b46e9507372f0b1b963James Dong     * is controlled by neighbour availability information in actual prediction
5720c1bc742181ded4930842b46e9507372f0b1b963James Dong     * process */
5730c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (row)
5740c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
5750c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp = ptr - (width + 1);
5760c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (i = 21; i--;)
5770c1bc742181ded4930842b46e9507372f0b1b963James Dong            *above++ = *tmp++;
5780c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
5790c1bc742181ded4930842b46e9507372f0b1b963James Dong
5800c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (col)
5810c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
5820c1bc742181ded4930842b46e9507372f0b1b963James Dong        ptr--;
5830c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (i = 16; i--; ptr+=width)
5840c1bc742181ded4930842b46e9507372f0b1b963James Dong            *left++ = *ptr;
5850c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
5860c1bc742181ded4930842b46e9507372f0b1b963James Dong
5870c1bc742181ded4930842b46e9507372f0b1b963James Dong    width >>= 1;
5880c1bc742181ded4930842b46e9507372f0b1b963James Dong    ptr = image->data + picSize * 256 + row * 8 * width  + col * 8;
5890c1bc742181ded4930842b46e9507372f0b1b963James Dong
5900c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (row)
5910c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
5920c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp = ptr - (width + 1);
5930c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (i = 9; i--;)
5940c1bc742181ded4930842b46e9507372f0b1b963James Dong            *above++ = *tmp++;
5950c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp += (picSize * 64) - 9;
5960c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (i = 9; i--;)
5970c1bc742181ded4930842b46e9507372f0b1b963James Dong            *above++ = *tmp++;
5980c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
5990c1bc742181ded4930842b46e9507372f0b1b963James Dong
6000c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (col)
6010c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
6020c1bc742181ded4930842b46e9507372f0b1b963James Dong        ptr--;
6030c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (i = 8; i--; ptr+=width)
6040c1bc742181ded4930842b46e9507372f0b1b963James Dong            *left++ = *ptr;
6050c1bc742181ded4930842b46e9507372f0b1b963James Dong        ptr += (picSize * 64) - 8 * width;
6060c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (i = 8; i--; ptr+=width)
6070c1bc742181ded4930842b46e9507372f0b1b963James Dong            *left++ = *ptr;
6080c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
6090c1bc742181ded4930842b46e9507372f0b1b963James Dong}
6100c1bc742181ded4930842b46e9507372f0b1b963James Dong
6110c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
6120c1bc742181ded4930842b46e9507372f0b1b963James Dong
6130c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: Intra16x16Prediction
6140c1bc742181ded4930842b46e9507372f0b1b963James Dong
6150c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
6160c1bc742181ded4930842b46e9507372f0b1b963James Dong          Perform intra 16x16 prediction mode for luma pixels and add
6170c1bc742181ded4930842b46e9507372f0b1b963James Dong          residual into prediction. The resulting luma pixels are
6180c1bc742181ded4930842b46e9507372f0b1b963James Dong          stored in macroblock array 'data'.
6190c1bc742181ded4930842b46e9507372f0b1b963James Dong
6200c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
6210c1bc742181ded4930842b46e9507372f0b1b963James Dong
6220c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 h264bsdIntra16x16Prediction(mbStorage_t *pMb, u8 *data, i32 residual[][16],
6230c1bc742181ded4930842b46e9507372f0b1b963James Dong                                u8 *above, u8 *left, u32 constrainedIntraPred)
6240c1bc742181ded4930842b46e9507372f0b1b963James Dong{
6250c1bc742181ded4930842b46e9507372f0b1b963James Dong
6260c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
6270c1bc742181ded4930842b46e9507372f0b1b963James Dong
6280c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 i;
6290c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 availableA, availableB, availableD;
6300c1bc742181ded4930842b46e9507372f0b1b963James Dong
6310c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
6320c1bc742181ded4930842b46e9507372f0b1b963James Dong
6330c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(data);
6340c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(residual);
6350c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(above);
6360c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(left);
6370c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(h264bsdPredModeIntra16x16(pMb->mbType) < 4);
6380c1bc742181ded4930842b46e9507372f0b1b963James Dong
6390c1bc742181ded4930842b46e9507372f0b1b963James Dong    availableA = h264bsdIsNeighbourAvailable(pMb, pMb->mbA);
6400c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (availableA && constrainedIntraPred &&
6410c1bc742181ded4930842b46e9507372f0b1b963James Dong       (h264bsdMbPartPredMode(pMb->mbA->mbType) == PRED_MODE_INTER))
6420c1bc742181ded4930842b46e9507372f0b1b963James Dong        availableA = HANTRO_FALSE;
6430c1bc742181ded4930842b46e9507372f0b1b963James Dong    availableB = h264bsdIsNeighbourAvailable(pMb, pMb->mbB);
6440c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (availableB && constrainedIntraPred &&
6450c1bc742181ded4930842b46e9507372f0b1b963James Dong       (h264bsdMbPartPredMode(pMb->mbB->mbType) == PRED_MODE_INTER))
6460c1bc742181ded4930842b46e9507372f0b1b963James Dong        availableB = HANTRO_FALSE;
6470c1bc742181ded4930842b46e9507372f0b1b963James Dong    availableD = h264bsdIsNeighbourAvailable(pMb, pMb->mbD);
6480c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (availableD && constrainedIntraPred &&
6490c1bc742181ded4930842b46e9507372f0b1b963James Dong       (h264bsdMbPartPredMode(pMb->mbD->mbType) == PRED_MODE_INTER))
6500c1bc742181ded4930842b46e9507372f0b1b963James Dong        availableD = HANTRO_FALSE;
6510c1bc742181ded4930842b46e9507372f0b1b963James Dong
6520c1bc742181ded4930842b46e9507372f0b1b963James Dong    switch(h264bsdPredModeIntra16x16(pMb->mbType))
6530c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
6540c1bc742181ded4930842b46e9507372f0b1b963James Dong        case 0: /* Intra_16x16_Vertical */
6550c1bc742181ded4930842b46e9507372f0b1b963James Dong            if (!availableB)
6560c1bc742181ded4930842b46e9507372f0b1b963James Dong                return(HANTRO_NOK);
6570c1bc742181ded4930842b46e9507372f0b1b963James Dong            Intra16x16VerticalPrediction(data, above+1);
6580c1bc742181ded4930842b46e9507372f0b1b963James Dong            break;
6590c1bc742181ded4930842b46e9507372f0b1b963James Dong
6600c1bc742181ded4930842b46e9507372f0b1b963James Dong        case 1: /* Intra_16x16_Horizontal */
6610c1bc742181ded4930842b46e9507372f0b1b963James Dong            if (!availableA)
6620c1bc742181ded4930842b46e9507372f0b1b963James Dong                return(HANTRO_NOK);
6630c1bc742181ded4930842b46e9507372f0b1b963James Dong            Intra16x16HorizontalPrediction(data, left);
6640c1bc742181ded4930842b46e9507372f0b1b963James Dong            break;
6650c1bc742181ded4930842b46e9507372f0b1b963James Dong
6660c1bc742181ded4930842b46e9507372f0b1b963James Dong        case 2: /* Intra_16x16_DC */
6670c1bc742181ded4930842b46e9507372f0b1b963James Dong            Intra16x16DcPrediction(data, above+1, left, availableA, availableB);
6680c1bc742181ded4930842b46e9507372f0b1b963James Dong            break;
6690c1bc742181ded4930842b46e9507372f0b1b963James Dong
6700c1bc742181ded4930842b46e9507372f0b1b963James Dong        default: /* case 3: Intra_16x16_Plane */
6710c1bc742181ded4930842b46e9507372f0b1b963James Dong            if (!availableA || !availableB || !availableD)
6720c1bc742181ded4930842b46e9507372f0b1b963James Dong                return(HANTRO_NOK);
6730c1bc742181ded4930842b46e9507372f0b1b963James Dong            Intra16x16PlanePrediction(data, above+1, left);
6740c1bc742181ded4930842b46e9507372f0b1b963James Dong            break;
6750c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
6760c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* add residual */
6770c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (i = 0; i < 16; i++)
6780c1bc742181ded4930842b46e9507372f0b1b963James Dong        h264bsdAddResidual(data, residual[i], i);
6790c1bc742181ded4930842b46e9507372f0b1b963James Dong
6800c1bc742181ded4930842b46e9507372f0b1b963James Dong    return(HANTRO_OK);
6810c1bc742181ded4930842b46e9507372f0b1b963James Dong
6820c1bc742181ded4930842b46e9507372f0b1b963James Dong}
6830c1bc742181ded4930842b46e9507372f0b1b963James Dong
6840c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
6850c1bc742181ded4930842b46e9507372f0b1b963James Dong
6860c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: Intra4x4Prediction
6870c1bc742181ded4930842b46e9507372f0b1b963James Dong
6880c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
6890c1bc742181ded4930842b46e9507372f0b1b963James Dong          Perform intra 4x4 prediction for luma pixels and add residual
6900c1bc742181ded4930842b46e9507372f0b1b963James Dong          into prediction. The resulting luma pixels are stored in
6910c1bc742181ded4930842b46e9507372f0b1b963James Dong          macroblock array 'data'. The intra 4x4 prediction mode for each
6920c1bc742181ded4930842b46e9507372f0b1b963James Dong          block is stored in 'pMb' structure.
6930c1bc742181ded4930842b46e9507372f0b1b963James Dong
6940c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
6950c1bc742181ded4930842b46e9507372f0b1b963James Dong
6960c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 h264bsdIntra4x4Prediction(mbStorage_t *pMb, u8 *data,
6970c1bc742181ded4930842b46e9507372f0b1b963James Dong                              macroblockLayer_t *mbLayer, u8 *above,
6980c1bc742181ded4930842b46e9507372f0b1b963James Dong                              u8 *left, u32 constrainedIntraPred)
6990c1bc742181ded4930842b46e9507372f0b1b963James Dong{
7000c1bc742181ded4930842b46e9507372f0b1b963James Dong
7010c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
7020c1bc742181ded4930842b46e9507372f0b1b963James Dong
7030c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 block;
7040c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 mode;
7050c1bc742181ded4930842b46e9507372f0b1b963James Dong    neighbour_t neighbour, neighbourB;
7060c1bc742181ded4930842b46e9507372f0b1b963James Dong    mbStorage_t *nMb, *nMb2;
7070c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 a[1 + 4 + 4], l[1 + 4];
7080c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 data4x4[4];
7090c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 availableA, availableB, availableC, availableD;
7100c1bc742181ded4930842b46e9507372f0b1b963James Dong
7110c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
7120c1bc742181ded4930842b46e9507372f0b1b963James Dong
7130c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(data);
7140c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(mbLayer);
7150c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(above);
7160c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(left);
7170c1bc742181ded4930842b46e9507372f0b1b963James Dong
7180c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (block = 0; block < 16; block++)
7190c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
7200c1bc742181ded4930842b46e9507372f0b1b963James Dong
7210c1bc742181ded4930842b46e9507372f0b1b963James Dong        ASSERT(pMb->intra4x4PredMode[block] < 9);
7220c1bc742181ded4930842b46e9507372f0b1b963James Dong
7230c1bc742181ded4930842b46e9507372f0b1b963James Dong        neighbour = *h264bsdNeighbour4x4BlockA(block);
7240c1bc742181ded4930842b46e9507372f0b1b963James Dong        nMb = h264bsdGetNeighbourMb(pMb, neighbour.mb);
7250c1bc742181ded4930842b46e9507372f0b1b963James Dong        availableA = h264bsdIsNeighbourAvailable(pMb, nMb);
7260c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (availableA && constrainedIntraPred &&
7270c1bc742181ded4930842b46e9507372f0b1b963James Dong           ( h264bsdMbPartPredMode(nMb->mbType) == PRED_MODE_INTER) )
7280c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
7290c1bc742181ded4930842b46e9507372f0b1b963James Dong            availableA = HANTRO_FALSE;
7300c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
7310c1bc742181ded4930842b46e9507372f0b1b963James Dong
7320c1bc742181ded4930842b46e9507372f0b1b963James Dong        neighbourB = *h264bsdNeighbour4x4BlockB(block);
7330c1bc742181ded4930842b46e9507372f0b1b963James Dong        nMb2 = h264bsdGetNeighbourMb(pMb, neighbourB.mb);
7340c1bc742181ded4930842b46e9507372f0b1b963James Dong        availableB = h264bsdIsNeighbourAvailable(pMb, nMb2);
7350c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (availableB && constrainedIntraPred &&
7360c1bc742181ded4930842b46e9507372f0b1b963James Dong           ( h264bsdMbPartPredMode(nMb2->mbType) == PRED_MODE_INTER) )
7370c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
7380c1bc742181ded4930842b46e9507372f0b1b963James Dong            availableB = HANTRO_FALSE;
7390c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
7400c1bc742181ded4930842b46e9507372f0b1b963James Dong
7410c1bc742181ded4930842b46e9507372f0b1b963James Dong        mode = DetermineIntra4x4PredMode(mbLayer,
7420c1bc742181ded4930842b46e9507372f0b1b963James Dong            (u32)(availableA && availableB),
7430c1bc742181ded4930842b46e9507372f0b1b963James Dong            &neighbour, &neighbourB, block, nMb, nMb2);
7440c1bc742181ded4930842b46e9507372f0b1b963James Dong        pMb->intra4x4PredMode[block] = (u8)mode;
7450c1bc742181ded4930842b46e9507372f0b1b963James Dong
7460c1bc742181ded4930842b46e9507372f0b1b963James Dong        neighbour = *h264bsdNeighbour4x4BlockC(block);
7470c1bc742181ded4930842b46e9507372f0b1b963James Dong        nMb = h264bsdGetNeighbourMb(pMb, neighbour.mb);
7480c1bc742181ded4930842b46e9507372f0b1b963James Dong        availableC = h264bsdIsNeighbourAvailable(pMb, nMb);
7490c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (availableC && constrainedIntraPred &&
7500c1bc742181ded4930842b46e9507372f0b1b963James Dong           ( h264bsdMbPartPredMode(nMb->mbType) == PRED_MODE_INTER) )
7510c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
7520c1bc742181ded4930842b46e9507372f0b1b963James Dong            availableC = HANTRO_FALSE;
7530c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
7540c1bc742181ded4930842b46e9507372f0b1b963James Dong
7550c1bc742181ded4930842b46e9507372f0b1b963James Dong        neighbour = *h264bsdNeighbour4x4BlockD(block);
7560c1bc742181ded4930842b46e9507372f0b1b963James Dong        nMb = h264bsdGetNeighbourMb(pMb, neighbour.mb);
7570c1bc742181ded4930842b46e9507372f0b1b963James Dong        availableD = h264bsdIsNeighbourAvailable(pMb, nMb);
7580c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (availableD && constrainedIntraPred &&
7590c1bc742181ded4930842b46e9507372f0b1b963James Dong           ( h264bsdMbPartPredMode(nMb->mbType) == PRED_MODE_INTER) )
7600c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
7610c1bc742181ded4930842b46e9507372f0b1b963James Dong            availableD = HANTRO_FALSE;
7620c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
7630c1bc742181ded4930842b46e9507372f0b1b963James Dong
7640c1bc742181ded4930842b46e9507372f0b1b963James Dong        Get4x4NeighbourPels(a, l, data, above, left, block);
7650c1bc742181ded4930842b46e9507372f0b1b963James Dong
7660c1bc742181ded4930842b46e9507372f0b1b963James Dong        switch(mode)
7670c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
7680c1bc742181ded4930842b46e9507372f0b1b963James Dong            case 0: /* Intra_4x4_Vertical */
7690c1bc742181ded4930842b46e9507372f0b1b963James Dong                if (!availableB)
7700c1bc742181ded4930842b46e9507372f0b1b963James Dong                    return(HANTRO_NOK);
7710c1bc742181ded4930842b46e9507372f0b1b963James Dong                Intra4x4VerticalPrediction((u8*)data4x4, a + 1);
7720c1bc742181ded4930842b46e9507372f0b1b963James Dong                break;
7730c1bc742181ded4930842b46e9507372f0b1b963James Dong            case 1: /* Intra_4x4_Horizontal */
7740c1bc742181ded4930842b46e9507372f0b1b963James Dong                if (!availableA)
7750c1bc742181ded4930842b46e9507372f0b1b963James Dong                    return(HANTRO_NOK);
7760c1bc742181ded4930842b46e9507372f0b1b963James Dong                Intra4x4HorizontalPrediction((u8*)data4x4, l + 1);
7770c1bc742181ded4930842b46e9507372f0b1b963James Dong                break;
7780c1bc742181ded4930842b46e9507372f0b1b963James Dong            case 2: /* Intra_4x4_DC */
7790c1bc742181ded4930842b46e9507372f0b1b963James Dong                Intra4x4DcPrediction((u8*)data4x4, a + 1, l + 1,
7800c1bc742181ded4930842b46e9507372f0b1b963James Dong                    availableA, availableB);
7810c1bc742181ded4930842b46e9507372f0b1b963James Dong                break;
7820c1bc742181ded4930842b46e9507372f0b1b963James Dong            case 3: /* Intra_4x4_Diagonal_Down_Left */
7830c1bc742181ded4930842b46e9507372f0b1b963James Dong                if (!availableB)
7840c1bc742181ded4930842b46e9507372f0b1b963James Dong                    return(HANTRO_NOK);
7850c1bc742181ded4930842b46e9507372f0b1b963James Dong                if (!availableC)
7860c1bc742181ded4930842b46e9507372f0b1b963James Dong                {
7870c1bc742181ded4930842b46e9507372f0b1b963James Dong                    a[5] = a[6] = a[7] = a[8] = a[4];
7880c1bc742181ded4930842b46e9507372f0b1b963James Dong                }
7890c1bc742181ded4930842b46e9507372f0b1b963James Dong                Intra4x4DiagonalDownLeftPrediction((u8*)data4x4, a + 1);
7900c1bc742181ded4930842b46e9507372f0b1b963James Dong                break;
7910c1bc742181ded4930842b46e9507372f0b1b963James Dong            case 4: /* Intra_4x4_Diagonal_Down_Right */
7920c1bc742181ded4930842b46e9507372f0b1b963James Dong                if (!availableA || !availableB || !availableD)
7930c1bc742181ded4930842b46e9507372f0b1b963James Dong                    return(HANTRO_NOK);
7940c1bc742181ded4930842b46e9507372f0b1b963James Dong                Intra4x4DiagonalDownRightPrediction((u8*)data4x4, a + 1, l + 1);
7950c1bc742181ded4930842b46e9507372f0b1b963James Dong                break;
7960c1bc742181ded4930842b46e9507372f0b1b963James Dong            case 5: /* Intra_4x4_Vertical_Right */
7970c1bc742181ded4930842b46e9507372f0b1b963James Dong                if (!availableA || !availableB || !availableD)
7980c1bc742181ded4930842b46e9507372f0b1b963James Dong                    return(HANTRO_NOK);
7990c1bc742181ded4930842b46e9507372f0b1b963James Dong                Intra4x4VerticalRightPrediction((u8*)data4x4, a + 1, l + 1);
8000c1bc742181ded4930842b46e9507372f0b1b963James Dong                break;
8010c1bc742181ded4930842b46e9507372f0b1b963James Dong            case 6: /* Intra_4x4_Horizontal_Down */
8020c1bc742181ded4930842b46e9507372f0b1b963James Dong                if (!availableA || !availableB || !availableD)
8030c1bc742181ded4930842b46e9507372f0b1b963James Dong                    return(HANTRO_NOK);
8040c1bc742181ded4930842b46e9507372f0b1b963James Dong                Intra4x4HorizontalDownPrediction((u8*)data4x4, a + 1, l + 1);
8050c1bc742181ded4930842b46e9507372f0b1b963James Dong                break;
8060c1bc742181ded4930842b46e9507372f0b1b963James Dong            case 7: /* Intra_4x4_Vertical_Left */
8070c1bc742181ded4930842b46e9507372f0b1b963James Dong                if (!availableB)
8080c1bc742181ded4930842b46e9507372f0b1b963James Dong                    return(HANTRO_NOK);
8090c1bc742181ded4930842b46e9507372f0b1b963James Dong                if (!availableC)
8100c1bc742181ded4930842b46e9507372f0b1b963James Dong                {
8110c1bc742181ded4930842b46e9507372f0b1b963James Dong                    a[5] = a[6] = a[7] = a[8] = a[4];
8120c1bc742181ded4930842b46e9507372f0b1b963James Dong                }
8130c1bc742181ded4930842b46e9507372f0b1b963James Dong                Intra4x4VerticalLeftPrediction((u8*)data4x4, a + 1);
8140c1bc742181ded4930842b46e9507372f0b1b963James Dong                break;
8150c1bc742181ded4930842b46e9507372f0b1b963James Dong            default: /* case 8 Intra_4x4_Horizontal_Up */
8160c1bc742181ded4930842b46e9507372f0b1b963James Dong                if (!availableA)
8170c1bc742181ded4930842b46e9507372f0b1b963James Dong                    return(HANTRO_NOK);
8180c1bc742181ded4930842b46e9507372f0b1b963James Dong                Intra4x4HorizontalUpPrediction((u8*)data4x4, l + 1);
8190c1bc742181ded4930842b46e9507372f0b1b963James Dong                break;
8200c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
8210c1bc742181ded4930842b46e9507372f0b1b963James Dong
8220c1bc742181ded4930842b46e9507372f0b1b963James Dong        Write4x4To16x16(data, (u8*)data4x4, block);
8230c1bc742181ded4930842b46e9507372f0b1b963James Dong        h264bsdAddResidual(data, mbLayer->residual.level[block], block);
8240c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
8250c1bc742181ded4930842b46e9507372f0b1b963James Dong
8260c1bc742181ded4930842b46e9507372f0b1b963James Dong    return(HANTRO_OK);
8270c1bc742181ded4930842b46e9507372f0b1b963James Dong
8280c1bc742181ded4930842b46e9507372f0b1b963James Dong}
8290c1bc742181ded4930842b46e9507372f0b1b963James Dong
8300c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
8310c1bc742181ded4930842b46e9507372f0b1b963James Dong
8320c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: IntraChromaPrediction
8330c1bc742181ded4930842b46e9507372f0b1b963James Dong
8340c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
8350c1bc742181ded4930842b46e9507372f0b1b963James Dong          Perform intra prediction for chroma pixels and add residual
8360c1bc742181ded4930842b46e9507372f0b1b963James Dong          into prediction. The resulting chroma pixels are stored in 'data'.
8370c1bc742181ded4930842b46e9507372f0b1b963James Dong
8380c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
8390c1bc742181ded4930842b46e9507372f0b1b963James Dong
8400c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 h264bsdIntraChromaPrediction(mbStorage_t *pMb, u8 *data, i32 residual[][16],
8410c1bc742181ded4930842b46e9507372f0b1b963James Dong                    u8 *above, u8 *left, u32 predMode, u32 constrainedIntraPred)
8420c1bc742181ded4930842b46e9507372f0b1b963James Dong{
8430c1bc742181ded4930842b46e9507372f0b1b963James Dong
8440c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
8450c1bc742181ded4930842b46e9507372f0b1b963James Dong
8460c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 i, comp, block;
8470c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 availableA, availableB, availableD;
8480c1bc742181ded4930842b46e9507372f0b1b963James Dong
8490c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
8500c1bc742181ded4930842b46e9507372f0b1b963James Dong
8510c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(data);
8520c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(residual);
8530c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(above);
8540c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(left);
8550c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(predMode < 4);
8560c1bc742181ded4930842b46e9507372f0b1b963James Dong
8570c1bc742181ded4930842b46e9507372f0b1b963James Dong    availableA = h264bsdIsNeighbourAvailable(pMb, pMb->mbA);
8580c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (availableA && constrainedIntraPred &&
8590c1bc742181ded4930842b46e9507372f0b1b963James Dong       (h264bsdMbPartPredMode(pMb->mbA->mbType) == PRED_MODE_INTER))
8600c1bc742181ded4930842b46e9507372f0b1b963James Dong        availableA = HANTRO_FALSE;
8610c1bc742181ded4930842b46e9507372f0b1b963James Dong    availableB = h264bsdIsNeighbourAvailable(pMb, pMb->mbB);
8620c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (availableB && constrainedIntraPred &&
8630c1bc742181ded4930842b46e9507372f0b1b963James Dong       (h264bsdMbPartPredMode(pMb->mbB->mbType) == PRED_MODE_INTER))
8640c1bc742181ded4930842b46e9507372f0b1b963James Dong        availableB = HANTRO_FALSE;
8650c1bc742181ded4930842b46e9507372f0b1b963James Dong    availableD = h264bsdIsNeighbourAvailable(pMb, pMb->mbD);
8660c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (availableD && constrainedIntraPred &&
8670c1bc742181ded4930842b46e9507372f0b1b963James Dong       (h264bsdMbPartPredMode(pMb->mbD->mbType) == PRED_MODE_INTER))
8680c1bc742181ded4930842b46e9507372f0b1b963James Dong        availableD = HANTRO_FALSE;
8690c1bc742181ded4930842b46e9507372f0b1b963James Dong
8700c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (comp = 0, block = 16; comp < 2; comp++)
8710c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
8720c1bc742181ded4930842b46e9507372f0b1b963James Dong        switch(predMode)
8730c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
8740c1bc742181ded4930842b46e9507372f0b1b963James Dong            case 0: /* Intra_Chroma_DC */
8750c1bc742181ded4930842b46e9507372f0b1b963James Dong                IntraChromaDcPrediction(data, above+1, left, availableA,
8760c1bc742181ded4930842b46e9507372f0b1b963James Dong                    availableB);
8770c1bc742181ded4930842b46e9507372f0b1b963James Dong                break;
8780c1bc742181ded4930842b46e9507372f0b1b963James Dong
8790c1bc742181ded4930842b46e9507372f0b1b963James Dong            case 1: /* Intra_Chroma_Horizontal */
8800c1bc742181ded4930842b46e9507372f0b1b963James Dong                if (!availableA)
8810c1bc742181ded4930842b46e9507372f0b1b963James Dong                    return(HANTRO_NOK);
8820c1bc742181ded4930842b46e9507372f0b1b963James Dong                IntraChromaHorizontalPrediction(data, left);
8830c1bc742181ded4930842b46e9507372f0b1b963James Dong                break;
8840c1bc742181ded4930842b46e9507372f0b1b963James Dong
8850c1bc742181ded4930842b46e9507372f0b1b963James Dong            case 2: /* Intra_Chroma_Vertical */
8860c1bc742181ded4930842b46e9507372f0b1b963James Dong                if (!availableB)
8870c1bc742181ded4930842b46e9507372f0b1b963James Dong                    return(HANTRO_NOK);
8880c1bc742181ded4930842b46e9507372f0b1b963James Dong                IntraChromaVerticalPrediction(data, above+1);
8890c1bc742181ded4930842b46e9507372f0b1b963James Dong
8900c1bc742181ded4930842b46e9507372f0b1b963James Dong                break;
8910c1bc742181ded4930842b46e9507372f0b1b963James Dong
8920c1bc742181ded4930842b46e9507372f0b1b963James Dong            default: /* case 3: Intra_Chroma_Plane */
8930c1bc742181ded4930842b46e9507372f0b1b963James Dong                if (!availableA || !availableB || !availableD)
8940c1bc742181ded4930842b46e9507372f0b1b963James Dong                    return(HANTRO_NOK);
8950c1bc742181ded4930842b46e9507372f0b1b963James Dong                IntraChromaPlanePrediction(data, above+1, left);
8960c1bc742181ded4930842b46e9507372f0b1b963James Dong                break;
8970c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
8980c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (i = 0; i < 4; i++, block++)
8990c1bc742181ded4930842b46e9507372f0b1b963James Dong            h264bsdAddResidual(data, residual[i], block);
9000c1bc742181ded4930842b46e9507372f0b1b963James Dong
9010c1bc742181ded4930842b46e9507372f0b1b963James Dong        /* advance pointers */
9020c1bc742181ded4930842b46e9507372f0b1b963James Dong        data += 64;
9030c1bc742181ded4930842b46e9507372f0b1b963James Dong        above += 9;
9040c1bc742181ded4930842b46e9507372f0b1b963James Dong        left += 8;
9050c1bc742181ded4930842b46e9507372f0b1b963James Dong        residual += 4;
9060c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
9070c1bc742181ded4930842b46e9507372f0b1b963James Dong
9080c1bc742181ded4930842b46e9507372f0b1b963James Dong    return(HANTRO_OK);
9090c1bc742181ded4930842b46e9507372f0b1b963James Dong
9100c1bc742181ded4930842b46e9507372f0b1b963James Dong}
9110c1bc742181ded4930842b46e9507372f0b1b963James Dong
9120c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
9130c1bc742181ded4930842b46e9507372f0b1b963James Dong
9140c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: h264bsdAddResidual
9150c1bc742181ded4930842b46e9507372f0b1b963James Dong
9160c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
9170c1bc742181ded4930842b46e9507372f0b1b963James Dong          Add residual of a block into prediction in macroblock array 'data'.
9180c1bc742181ded4930842b46e9507372f0b1b963James Dong          The result (residual + prediction) is stored in 'data'.
9190c1bc742181ded4930842b46e9507372f0b1b963James Dong
9200c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
9210c1bc742181ded4930842b46e9507372f0b1b963James Dong#ifndef H264DEC_OMXDL
9220c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid h264bsdAddResidual(u8 *data, i32 *residual, u32 blockNum)
9230c1bc742181ded4930842b46e9507372f0b1b963James Dong{
9240c1bc742181ded4930842b46e9507372f0b1b963James Dong
9250c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
9260c1bc742181ded4930842b46e9507372f0b1b963James Dong
9270c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 i;
9280c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 x, y;
9290c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 width;
9300c1bc742181ded4930842b46e9507372f0b1b963James Dong    i32 tmp1, tmp2, tmp3, tmp4;
9310c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 *tmp;
9320c1bc742181ded4930842b46e9507372f0b1b963James Dong    const u8 *clp = h264bsdClip + 512;
9330c1bc742181ded4930842b46e9507372f0b1b963James Dong
9340c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
9350c1bc742181ded4930842b46e9507372f0b1b963James Dong
9360c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(data);
9370c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(residual);
9380c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(blockNum < 16 + 4 + 4);
9390c1bc742181ded4930842b46e9507372f0b1b963James Dong
9400c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (IS_RESIDUAL_EMPTY(residual))
9410c1bc742181ded4930842b46e9507372f0b1b963James Dong        return;
9420c1bc742181ded4930842b46e9507372f0b1b963James Dong
9430c1bc742181ded4930842b46e9507372f0b1b963James Dong    RANGE_CHECK_ARRAY(residual, -512, 511, 16);
9440c1bc742181ded4930842b46e9507372f0b1b963James Dong
9450c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (blockNum < 16)
9460c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
9470c1bc742181ded4930842b46e9507372f0b1b963James Dong        width = 16;
9480c1bc742181ded4930842b46e9507372f0b1b963James Dong        x = h264bsdBlockX[blockNum];
9490c1bc742181ded4930842b46e9507372f0b1b963James Dong        y = h264bsdBlockY[blockNum];
9500c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
9510c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
9520c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
9530c1bc742181ded4930842b46e9507372f0b1b963James Dong        width = 8;
9540c1bc742181ded4930842b46e9507372f0b1b963James Dong        x = h264bsdBlockX[blockNum & 0x3];
9550c1bc742181ded4930842b46e9507372f0b1b963James Dong        y = h264bsdBlockY[blockNum & 0x3];
9560c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
9570c1bc742181ded4930842b46e9507372f0b1b963James Dong
9580c1bc742181ded4930842b46e9507372f0b1b963James Dong    tmp = data + y*width + x;
9590c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (i = 4; i; i--)
9600c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
9610c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp1 = *residual++;
9620c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp2 = tmp[0];
9630c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp3 = *residual++;
9640c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp4 = tmp[1];
9650c1bc742181ded4930842b46e9507372f0b1b963James Dong
9660c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp[0] = clp[tmp1 + tmp2];
9670c1bc742181ded4930842b46e9507372f0b1b963James Dong
9680c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp1 = *residual++;
9690c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp2 = tmp[2];
9700c1bc742181ded4930842b46e9507372f0b1b963James Dong
9710c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp[1] = clp[tmp3 + tmp4];
9720c1bc742181ded4930842b46e9507372f0b1b963James Dong
9730c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp3 = *residual++;
9740c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp4 = tmp[3];
9750c1bc742181ded4930842b46e9507372f0b1b963James Dong
9760c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp1 = clp[tmp1 + tmp2];
9770c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp3 = clp[tmp3 + tmp4];
9780c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp[2] = (u8)tmp1;
9790c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp[3] = (u8)tmp3;
9800c1bc742181ded4930842b46e9507372f0b1b963James Dong
9810c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp += width;
9820c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
9830c1bc742181ded4930842b46e9507372f0b1b963James Dong
9840c1bc742181ded4930842b46e9507372f0b1b963James Dong}
9850c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif
9860c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
9870c1bc742181ded4930842b46e9507372f0b1b963James Dong
9880c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: Intra16x16VerticalPrediction
9890c1bc742181ded4930842b46e9507372f0b1b963James Dong
9900c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
9910c1bc742181ded4930842b46e9507372f0b1b963James Dong          Perform intra 16x16 vertical prediction mode.
9920c1bc742181ded4930842b46e9507372f0b1b963James Dong
9930c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
9940c1bc742181ded4930842b46e9507372f0b1b963James Dong
9950c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid Intra16x16VerticalPrediction(u8 *data, u8 *above)
9960c1bc742181ded4930842b46e9507372f0b1b963James Dong{
9970c1bc742181ded4930842b46e9507372f0b1b963James Dong
9980c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
9990c1bc742181ded4930842b46e9507372f0b1b963James Dong
10000c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 i, j;
10010c1bc742181ded4930842b46e9507372f0b1b963James Dong
10020c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
10030c1bc742181ded4930842b46e9507372f0b1b963James Dong
10040c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(data);
10050c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(above);
10060c1bc742181ded4930842b46e9507372f0b1b963James Dong
10070c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (i = 0; i < 16; i++)
10080c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
10090c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (j = 0; j < 16; j++)
10100c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
10110c1bc742181ded4930842b46e9507372f0b1b963James Dong            *data++ = above[j];
10120c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
10130c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
10140c1bc742181ded4930842b46e9507372f0b1b963James Dong
10150c1bc742181ded4930842b46e9507372f0b1b963James Dong}
10160c1bc742181ded4930842b46e9507372f0b1b963James Dong
10170c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
10180c1bc742181ded4930842b46e9507372f0b1b963James Dong
10190c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: Intra16x16HorizontalPrediction
10200c1bc742181ded4930842b46e9507372f0b1b963James Dong
10210c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
10220c1bc742181ded4930842b46e9507372f0b1b963James Dong          Perform intra 16x16 horizontal prediction mode.
10230c1bc742181ded4930842b46e9507372f0b1b963James Dong
10240c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
10250c1bc742181ded4930842b46e9507372f0b1b963James Dong
10260c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid Intra16x16HorizontalPrediction(u8 *data, u8 *left)
10270c1bc742181ded4930842b46e9507372f0b1b963James Dong{
10280c1bc742181ded4930842b46e9507372f0b1b963James Dong
10290c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
10300c1bc742181ded4930842b46e9507372f0b1b963James Dong
10310c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 i, j;
10320c1bc742181ded4930842b46e9507372f0b1b963James Dong
10330c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
10340c1bc742181ded4930842b46e9507372f0b1b963James Dong
10350c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(data);
10360c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(left);
10370c1bc742181ded4930842b46e9507372f0b1b963James Dong
10380c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (i = 0; i < 16; i++)
10390c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
10400c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (j = 0; j < 16; j++)
10410c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
10420c1bc742181ded4930842b46e9507372f0b1b963James Dong            *data++ = left[i];
10430c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
10440c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
10450c1bc742181ded4930842b46e9507372f0b1b963James Dong
10460c1bc742181ded4930842b46e9507372f0b1b963James Dong}
10470c1bc742181ded4930842b46e9507372f0b1b963James Dong
10480c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
10490c1bc742181ded4930842b46e9507372f0b1b963James Dong
10500c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: Intra16x16DcPrediction
10510c1bc742181ded4930842b46e9507372f0b1b963James Dong
10520c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
10530c1bc742181ded4930842b46e9507372f0b1b963James Dong          Perform intra 16x16 DC prediction mode.
10540c1bc742181ded4930842b46e9507372f0b1b963James Dong
10550c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
10560c1bc742181ded4930842b46e9507372f0b1b963James Dong
10570c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid Intra16x16DcPrediction(u8 *data, u8 *above, u8 *left, u32 availableA,
10580c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 availableB)
10590c1bc742181ded4930842b46e9507372f0b1b963James Dong{
10600c1bc742181ded4930842b46e9507372f0b1b963James Dong
10610c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
10620c1bc742181ded4930842b46e9507372f0b1b963James Dong
10630c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 i, tmp;
10640c1bc742181ded4930842b46e9507372f0b1b963James Dong
10650c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
10660c1bc742181ded4930842b46e9507372f0b1b963James Dong
10670c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(data);
10680c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(above);
10690c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(left);
10700c1bc742181ded4930842b46e9507372f0b1b963James Dong
10710c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (availableA && availableB)
10720c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
10730c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (i = 0, tmp = 0; i < 16; i++)
10740c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp += above[i] + left[i];
10750c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp = (tmp + 16) >> 5;
10760c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
10770c1bc742181ded4930842b46e9507372f0b1b963James Dong    else if (availableA)
10780c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
10790c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (i = 0, tmp = 0; i < 16; i++)
10800c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp += left[i];
10810c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp = (tmp + 8) >> 4;
10820c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
10830c1bc742181ded4930842b46e9507372f0b1b963James Dong    else if (availableB)
10840c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
10850c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (i = 0, tmp = 0; i < 16; i++)
10860c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp += above[i];
10870c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp = (tmp + 8) >> 4;
10880c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
10890c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* neither A nor B available */
10900c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
10910c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
10920c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp = 128;
10930c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
10940c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (i = 0; i < 256; i++)
10950c1bc742181ded4930842b46e9507372f0b1b963James Dong        data[i] = (u8)tmp;
10960c1bc742181ded4930842b46e9507372f0b1b963James Dong
10970c1bc742181ded4930842b46e9507372f0b1b963James Dong}
10980c1bc742181ded4930842b46e9507372f0b1b963James Dong
10990c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
11000c1bc742181ded4930842b46e9507372f0b1b963James Dong
11010c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: Intra16x16PlanePrediction
11020c1bc742181ded4930842b46e9507372f0b1b963James Dong
11030c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
11040c1bc742181ded4930842b46e9507372f0b1b963James Dong          Perform intra 16x16 plane prediction mode.
11050c1bc742181ded4930842b46e9507372f0b1b963James Dong
11060c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
11070c1bc742181ded4930842b46e9507372f0b1b963James Dong
11080c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid Intra16x16PlanePrediction(u8 *data, u8 *above, u8 *left)
11090c1bc742181ded4930842b46e9507372f0b1b963James Dong{
11100c1bc742181ded4930842b46e9507372f0b1b963James Dong
11110c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
11120c1bc742181ded4930842b46e9507372f0b1b963James Dong
11131f797f960412b5a50bf8e92a0c8b460f30e947d7Marcus Oakland    i32 i, j;
11140c1bc742181ded4930842b46e9507372f0b1b963James Dong    i32 a, b, c;
11150c1bc742181ded4930842b46e9507372f0b1b963James Dong    i32 tmp;
11160c1bc742181ded4930842b46e9507372f0b1b963James Dong
11170c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
11180c1bc742181ded4930842b46e9507372f0b1b963James Dong
11190c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(data);
11200c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(above);
11210c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(left);
11220c1bc742181ded4930842b46e9507372f0b1b963James Dong
11230c1bc742181ded4930842b46e9507372f0b1b963James Dong    a = 16 * (above[15] + left[15]);
11240c1bc742181ded4930842b46e9507372f0b1b963James Dong
11250c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (i = 0, b = 0; i < 8; i++)
11261f797f960412b5a50bf8e92a0c8b460f30e947d7Marcus Oakland        b += (i + 1) * (above[8+i] - above[6-i]);
11270c1bc742181ded4930842b46e9507372f0b1b963James Dong    b = (5 * b + 32) >> 6;
11280c1bc742181ded4930842b46e9507372f0b1b963James Dong
11290c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (i = 0, c = 0; i < 7; i++)
11301f797f960412b5a50bf8e92a0c8b460f30e947d7Marcus Oakland        c += (i + 1) * (left[8+i] - left[6-i]);
11310c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* p[-1,-1] has to be accessed through above pointer */
11321f797f960412b5a50bf8e92a0c8b460f30e947d7Marcus Oakland    c += (i + 1) * (left[8+i] - above[-1]);
11330c1bc742181ded4930842b46e9507372f0b1b963James Dong    c = (5 * c + 32) >> 6;
11340c1bc742181ded4930842b46e9507372f0b1b963James Dong
11350c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (i = 0; i < 16; i++)
11360c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
11370c1bc742181ded4930842b46e9507372f0b1b963James Dong        for (j = 0; j < 16; j++)
11380c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
11391f797f960412b5a50bf8e92a0c8b460f30e947d7Marcus Oakland            tmp = (a + b * (j - 7) + c * (i - 7) + 16) >> 5;
11400c1bc742181ded4930842b46e9507372f0b1b963James Dong            data[i*16+j] = (u8)CLIP1(tmp);
11410c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
11420c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
11430c1bc742181ded4930842b46e9507372f0b1b963James Dong
11440c1bc742181ded4930842b46e9507372f0b1b963James Dong}
11450c1bc742181ded4930842b46e9507372f0b1b963James Dong
11460c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
11470c1bc742181ded4930842b46e9507372f0b1b963James Dong
11480c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: IntraChromaDcPrediction
11490c1bc742181ded4930842b46e9507372f0b1b963James Dong
11500c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
11510c1bc742181ded4930842b46e9507372f0b1b963James Dong          Perform intra chroma DC prediction mode.
11520c1bc742181ded4930842b46e9507372f0b1b963James Dong
11530c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
11540c1bc742181ded4930842b46e9507372f0b1b963James Dong
11550c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid IntraChromaDcPrediction(u8 *data, u8 *above, u8 *left, u32 availableA,
11560c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 availableB)
11570c1bc742181ded4930842b46e9507372f0b1b963James Dong{
11580c1bc742181ded4930842b46e9507372f0b1b963James Dong
11590c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
11600c1bc742181ded4930842b46e9507372f0b1b963James Dong
11610c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 i;
11620c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 tmp1, tmp2;
11630c1bc742181ded4930842b46e9507372f0b1b963James Dong
11640c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
11650c1bc742181ded4930842b46e9507372f0b1b963James Dong
11660c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(data);
11670c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(above);
11680c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(left);
11690c1bc742181ded4930842b46e9507372f0b1b963James Dong
11700c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* y = 0..3 */
11710c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (availableA && availableB)
11720c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
11730c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp1 = above[0] + above[1] + above[2] + above[3] +
11740c1bc742181ded4930842b46e9507372f0b1b963James Dong              left[0] + left[1] + left[2] + left[3];
11750c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp1 = (tmp1 + 4) >> 3;
11760c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp2 = (above[4] + above[5] + above[6] + above[7] + 2) >> 2;
11770c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
11780c1bc742181ded4930842b46e9507372f0b1b963James Dong    else if (availableB)
11790c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
11800c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp1 = (above[0] + above[1] + above[2] + above[3] + 2) >> 2;
11810c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp2 = (above[4] + above[5] + above[6] + above[7] + 2) >> 2;
11820c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
11830c1bc742181ded4930842b46e9507372f0b1b963James Dong    else if (availableA)
11840c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
11850c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp1 = (left[0] + left[1] + left[2] + left[3] + 2) >> 2;
11860c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp2 = tmp1;
11870c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
11880c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* neither A nor B available */
11890c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
11900c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
11910c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp1 = tmp2 = 128;
11920c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
11930c1bc742181ded4930842b46e9507372f0b1b963James Dong
11940c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(tmp1 < 256 && tmp2 < 256);
11950c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (i = 4; i--;)
11960c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
11970c1bc742181ded4930842b46e9507372f0b1b963James Dong        *data++ = (u8)tmp1;
11980c1bc742181ded4930842b46e9507372f0b1b963James Dong        *data++ = (u8)tmp1;
11990c1bc742181ded4930842b46e9507372f0b1b963James Dong        *data++ = (u8)tmp1;
12000c1bc742181ded4930842b46e9507372f0b1b963James Dong        *data++ = (u8)tmp1;
12010c1bc742181ded4930842b46e9507372f0b1b963James Dong        *data++ = (u8)tmp2;
12020c1bc742181ded4930842b46e9507372f0b1b963James Dong        *data++ = (u8)tmp2;
12030c1bc742181ded4930842b46e9507372f0b1b963James Dong        *data++ = (u8)tmp2;
12040c1bc742181ded4930842b46e9507372f0b1b963James Dong        *data++ = (u8)tmp2;
12050c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
12060c1bc742181ded4930842b46e9507372f0b1b963James Dong
12070c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* y = 4...7 */
12080c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (availableA)
12090c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
12100c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp1 = (left[4] + left[5] + left[6] + left[7] + 2) >> 2;
12110c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (availableB)
12120c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
12130c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 = above[4] + above[5] + above[6] + above[7] +
12140c1bc742181ded4930842b46e9507372f0b1b963James Dong                   left[4] + left[5] + left[6] + left[7];
12150c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 = (tmp2 + 4) >> 3;
12160c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
12170c1bc742181ded4930842b46e9507372f0b1b963James Dong        else
12180c1bc742181ded4930842b46e9507372f0b1b963James Dong            tmp2 = tmp1;
12190c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
12200c1bc742181ded4930842b46e9507372f0b1b963James Dong    else if (availableB)
12210c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
12220c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp1 = (above[0] + above[1] + above[2] + above[3] + 2) >> 2;
12230c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp2 = (above[4] + above[5] + above[6] + above[7] + 2) >> 2;
12240c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
12250c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
12260c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
12270c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp1 = tmp2 = 128;
12280c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
12290c1bc742181ded4930842b46e9507372f0b1b963James Dong
12300c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(tmp1 < 256 && tmp2 < 256);
12310c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (i = 4; i--;)
12320c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
12330c1bc742181ded4930842b46e9507372f0b1b963James Dong        *data++ = (u8)tmp1;
12340c1bc742181ded4930842b46e9507372f0b1b963James Dong        *data++ = (u8)tmp1;
12350c1bc742181ded4930842b46e9507372f0b1b963James Dong        *data++ = (u8)tmp1;
12360c1bc742181ded4930842b46e9507372f0b1b963James Dong        *data++ = (u8)tmp1;
12370c1bc742181ded4930842b46e9507372f0b1b963James Dong        *data++ = (u8)tmp2;
12380c1bc742181ded4930842b46e9507372f0b1b963James Dong        *data++ = (u8)tmp2;
12390c1bc742181ded4930842b46e9507372f0b1b963James Dong        *data++ = (u8)tmp2;
12400c1bc742181ded4930842b46e9507372f0b1b963James Dong        *data++ = (u8)tmp2;
12410c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
12420c1bc742181ded4930842b46e9507372f0b1b963James Dong}
12430c1bc742181ded4930842b46e9507372f0b1b963James Dong
12440c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
12450c1bc742181ded4930842b46e9507372f0b1b963James Dong
12460c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: IntraChromaHorizontalPrediction
12470c1bc742181ded4930842b46e9507372f0b1b963James Dong
12480c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
12490c1bc742181ded4930842b46e9507372f0b1b963James Dong          Perform intra chroma horizontal prediction mode.
12500c1bc742181ded4930842b46e9507372f0b1b963James Dong
12510c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
12520c1bc742181ded4930842b46e9507372f0b1b963James Dong
12530c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid IntraChromaHorizontalPrediction(u8 *data, u8 *left)
12540c1bc742181ded4930842b46e9507372f0b1b963James Dong{
12550c1bc742181ded4930842b46e9507372f0b1b963James Dong
12560c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
12570c1bc742181ded4930842b46e9507372f0b1b963James Dong
12580c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 i;
12590c1bc742181ded4930842b46e9507372f0b1b963James Dong
12600c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
12610c1bc742181ded4930842b46e9507372f0b1b963James Dong
12620c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(data);
12630c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(left);
12640c1bc742181ded4930842b46e9507372f0b1b963James Dong
12650c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (i = 8; i--;)
12660c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
12670c1bc742181ded4930842b46e9507372f0b1b963James Dong        *data++ = *left;
12680c1bc742181ded4930842b46e9507372f0b1b963James Dong        *data++ = *left;
12690c1bc742181ded4930842b46e9507372f0b1b963James Dong        *data++ = *left;
12700c1bc742181ded4930842b46e9507372f0b1b963James Dong        *data++ = *left;
12710c1bc742181ded4930842b46e9507372f0b1b963James Dong        *data++ = *left;
12720c1bc742181ded4930842b46e9507372f0b1b963James Dong        *data++ = *left;
12730c1bc742181ded4930842b46e9507372f0b1b963James Dong        *data++ = *left;
12740c1bc742181ded4930842b46e9507372f0b1b963James Dong        *data++ = *left++;
12750c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
12760c1bc742181ded4930842b46e9507372f0b1b963James Dong
12770c1bc742181ded4930842b46e9507372f0b1b963James Dong}
12780c1bc742181ded4930842b46e9507372f0b1b963James Dong
12790c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
12800c1bc742181ded4930842b46e9507372f0b1b963James Dong
12810c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: IntraChromaVerticalPrediction
12820c1bc742181ded4930842b46e9507372f0b1b963James Dong
12830c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
12840c1bc742181ded4930842b46e9507372f0b1b963James Dong          Perform intra chroma vertical prediction mode.
12850c1bc742181ded4930842b46e9507372f0b1b963James Dong
12860c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
12870c1bc742181ded4930842b46e9507372f0b1b963James Dong
12880c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid IntraChromaVerticalPrediction(u8 *data, u8 *above)
12890c1bc742181ded4930842b46e9507372f0b1b963James Dong{
12900c1bc742181ded4930842b46e9507372f0b1b963James Dong
12910c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
12920c1bc742181ded4930842b46e9507372f0b1b963James Dong
12930c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 i;
12940c1bc742181ded4930842b46e9507372f0b1b963James Dong
12950c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
12960c1bc742181ded4930842b46e9507372f0b1b963James Dong
12970c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(data);
12980c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(above);
12990c1bc742181ded4930842b46e9507372f0b1b963James Dong
13000c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (i = 8; i--;data++/*above-=8*/)
13010c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
13020c1bc742181ded4930842b46e9507372f0b1b963James Dong        data[0] = *above;
13030c1bc742181ded4930842b46e9507372f0b1b963James Dong        data[8] = *above;
13040c1bc742181ded4930842b46e9507372f0b1b963James Dong        data[16] = *above;
13050c1bc742181ded4930842b46e9507372f0b1b963James Dong        data[24] = *above;
13060c1bc742181ded4930842b46e9507372f0b1b963James Dong        data[32] = *above;
13070c1bc742181ded4930842b46e9507372f0b1b963James Dong        data[40] = *above;
13080c1bc742181ded4930842b46e9507372f0b1b963James Dong        data[48] = *above;
13090c1bc742181ded4930842b46e9507372f0b1b963James Dong        data[56] = *above++;
13100c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
13110c1bc742181ded4930842b46e9507372f0b1b963James Dong
13120c1bc742181ded4930842b46e9507372f0b1b963James Dong}
13130c1bc742181ded4930842b46e9507372f0b1b963James Dong
13140c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
13150c1bc742181ded4930842b46e9507372f0b1b963James Dong
13160c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: IntraChromaPlanePrediction
13170c1bc742181ded4930842b46e9507372f0b1b963James Dong
13180c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
13190c1bc742181ded4930842b46e9507372f0b1b963James Dong          Perform intra chroma plane prediction mode.
13200c1bc742181ded4930842b46e9507372f0b1b963James Dong
13210c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
13220c1bc742181ded4930842b46e9507372f0b1b963James Dong
13230c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid IntraChromaPlanePrediction(u8 *data, u8 *above, u8 *left)
13240c1bc742181ded4930842b46e9507372f0b1b963James Dong{
13250c1bc742181ded4930842b46e9507372f0b1b963James Dong
13260c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
13270c1bc742181ded4930842b46e9507372f0b1b963James Dong
13280c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 i;
13290c1bc742181ded4930842b46e9507372f0b1b963James Dong    i32 a, b, c;
13300c1bc742181ded4930842b46e9507372f0b1b963James Dong    i32 tmp;
13310c1bc742181ded4930842b46e9507372f0b1b963James Dong    const u8 *clp = h264bsdClip + 512;
13320c1bc742181ded4930842b46e9507372f0b1b963James Dong
13330c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
13340c1bc742181ded4930842b46e9507372f0b1b963James Dong
13350c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(data);
13360c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(above);
13370c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(left);
13380c1bc742181ded4930842b46e9507372f0b1b963James Dong
13390c1bc742181ded4930842b46e9507372f0b1b963James Dong    a = 16 * (above[7] + left[7]);
13400c1bc742181ded4930842b46e9507372f0b1b963James Dong
13410c1bc742181ded4930842b46e9507372f0b1b963James Dong    b = (above[4] - above[2]) + 2 * (above[5] - above[1])
13420c1bc742181ded4930842b46e9507372f0b1b963James Dong        + 3 * (above[6] - above[0]) + 4 * (above[7] - above[-1]);
13430c1bc742181ded4930842b46e9507372f0b1b963James Dong    b = (17 * b + 16) >> 5;
13440c1bc742181ded4930842b46e9507372f0b1b963James Dong
13450c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* p[-1,-1] has to be accessed through above pointer */
13460c1bc742181ded4930842b46e9507372f0b1b963James Dong    c = (left[4] - left[2]) + 2 * (left[5] - left[1])
13470c1bc742181ded4930842b46e9507372f0b1b963James Dong        + 3 * (left[6] - left[0]) + 4 * (left[7] - above[-1]);
13480c1bc742181ded4930842b46e9507372f0b1b963James Dong    c = (17 * c + 16) >> 5;
13490c1bc742181ded4930842b46e9507372f0b1b963James Dong
13500c1bc742181ded4930842b46e9507372f0b1b963James Dong    /*a += 16;*/
13510c1bc742181ded4930842b46e9507372f0b1b963James Dong    a = a - 3 * c + 16;
13520c1bc742181ded4930842b46e9507372f0b1b963James Dong    for (i = 8; i--; a += c)
13530c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
13540c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp = (a - 3 * b);
13550c1bc742181ded4930842b46e9507372f0b1b963James Dong        *data++ = clp[tmp>>5];
13560c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp += b;
13570c1bc742181ded4930842b46e9507372f0b1b963James Dong        *data++ = clp[tmp>>5];
13580c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp += b;
13590c1bc742181ded4930842b46e9507372f0b1b963James Dong        *data++ = clp[tmp>>5];
13600c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp += b;
13610c1bc742181ded4930842b46e9507372f0b1b963James Dong        *data++ = clp[tmp>>5];
13620c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp += b;
13630c1bc742181ded4930842b46e9507372f0b1b963James Dong        *data++ = clp[tmp>>5];
13640c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp += b;
13650c1bc742181ded4930842b46e9507372f0b1b963James Dong        *data++ = clp[tmp>>5];
13660c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp += b;
13670c1bc742181ded4930842b46e9507372f0b1b963James Dong        *data++ = clp[tmp>>5];
13680c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp += b;
13690c1bc742181ded4930842b46e9507372f0b1b963James Dong        *data++ = clp[tmp>>5];
13700c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
13710c1bc742181ded4930842b46e9507372f0b1b963James Dong
13720c1bc742181ded4930842b46e9507372f0b1b963James Dong}
13730c1bc742181ded4930842b46e9507372f0b1b963James Dong
13740c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
13750c1bc742181ded4930842b46e9507372f0b1b963James Dong
13760c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: Get4x4NeighbourPels
13770c1bc742181ded4930842b46e9507372f0b1b963James Dong
13780c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
13790c1bc742181ded4930842b46e9507372f0b1b963James Dong          Get neighbouring pixels of a 4x4 block into 'a' and 'l'.
13800c1bc742181ded4930842b46e9507372f0b1b963James Dong
13810c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
13820c1bc742181ded4930842b46e9507372f0b1b963James Dong
13830c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid Get4x4NeighbourPels(u8 *a, u8 *l, u8 *data, u8 *above, u8 *left,
13840c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 blockNum)
13850c1bc742181ded4930842b46e9507372f0b1b963James Dong{
13860c1bc742181ded4930842b46e9507372f0b1b963James Dong
13870c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
13880c1bc742181ded4930842b46e9507372f0b1b963James Dong
13890c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 x, y;
13900c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 t1, t2;
13910c1bc742181ded4930842b46e9507372f0b1b963James Dong
13920c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
13930c1bc742181ded4930842b46e9507372f0b1b963James Dong
13940c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(a);
13950c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(l);
13960c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(data);
13970c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(above);
13980c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(left);
13990c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(blockNum < 16);
14000c1bc742181ded4930842b46e9507372f0b1b963James Dong
14010c1bc742181ded4930842b46e9507372f0b1b963James Dong    x = h264bsdBlockX[blockNum];
14020c1bc742181ded4930842b46e9507372f0b1b963James Dong    y = h264bsdBlockY[blockNum];
14030c1bc742181ded4930842b46e9507372f0b1b963James Dong
14040c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* A and D */
14050c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (x == 0)
14060c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
14070c1bc742181ded4930842b46e9507372f0b1b963James Dong        t1 = left[y    ];
14080c1bc742181ded4930842b46e9507372f0b1b963James Dong        t2 = left[y + 1];
14090c1bc742181ded4930842b46e9507372f0b1b963James Dong        l[1] = t1;
14100c1bc742181ded4930842b46e9507372f0b1b963James Dong        l[2] = t2;
14110c1bc742181ded4930842b46e9507372f0b1b963James Dong        t1 = left[y + 2];
14120c1bc742181ded4930842b46e9507372f0b1b963James Dong        t2 = left[y + 3];
14130c1bc742181ded4930842b46e9507372f0b1b963James Dong        l[3] = t1;
14140c1bc742181ded4930842b46e9507372f0b1b963James Dong        l[4] = t2;
14150c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
14160c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
14170c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
14180c1bc742181ded4930842b46e9507372f0b1b963James Dong        t1 = data[y * 16 + x - 1     ];
14190c1bc742181ded4930842b46e9507372f0b1b963James Dong        t2 = data[y * 16 + x - 1 + 16];
14200c1bc742181ded4930842b46e9507372f0b1b963James Dong        l[1] = t1;
14210c1bc742181ded4930842b46e9507372f0b1b963James Dong        l[2] = t2;
14220c1bc742181ded4930842b46e9507372f0b1b963James Dong        t1 = data[y * 16 + x - 1 + 32];
14230c1bc742181ded4930842b46e9507372f0b1b963James Dong        t2 = data[y * 16 + x - 1 + 48];
14240c1bc742181ded4930842b46e9507372f0b1b963James Dong        l[3] = t1;
14250c1bc742181ded4930842b46e9507372f0b1b963James Dong        l[4] = t2;
14260c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
14270c1bc742181ded4930842b46e9507372f0b1b963James Dong
14280c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* B, C and D */
14290c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (y == 0)
14300c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
14310c1bc742181ded4930842b46e9507372f0b1b963James Dong        t1 = above[x    ];
14320c1bc742181ded4930842b46e9507372f0b1b963James Dong        t2 = above[x    ];
14330c1bc742181ded4930842b46e9507372f0b1b963James Dong        l[0] = t1;
14340c1bc742181ded4930842b46e9507372f0b1b963James Dong        a[0] = t2;
14350c1bc742181ded4930842b46e9507372f0b1b963James Dong        t1 = above[x + 1];
14360c1bc742181ded4930842b46e9507372f0b1b963James Dong        t2 = above[x + 2];
14370c1bc742181ded4930842b46e9507372f0b1b963James Dong        a[1] = t1;
14380c1bc742181ded4930842b46e9507372f0b1b963James Dong        a[2] = t2;
14390c1bc742181ded4930842b46e9507372f0b1b963James Dong        t1 = above[x + 3];
14400c1bc742181ded4930842b46e9507372f0b1b963James Dong        t2 = above[x + 4];
14410c1bc742181ded4930842b46e9507372f0b1b963James Dong        a[3] = t1;
14420c1bc742181ded4930842b46e9507372f0b1b963James Dong        a[4] = t2;
14430c1bc742181ded4930842b46e9507372f0b1b963James Dong        t1 = above[x + 5];
14440c1bc742181ded4930842b46e9507372f0b1b963James Dong        t2 = above[x + 6];
14450c1bc742181ded4930842b46e9507372f0b1b963James Dong        a[5] = t1;
14460c1bc742181ded4930842b46e9507372f0b1b963James Dong        a[6] = t2;
14470c1bc742181ded4930842b46e9507372f0b1b963James Dong        t1 = above[x + 7];
14480c1bc742181ded4930842b46e9507372f0b1b963James Dong        t2 = above[x + 8];
14490c1bc742181ded4930842b46e9507372f0b1b963James Dong        a[7] = t1;
14500c1bc742181ded4930842b46e9507372f0b1b963James Dong        a[8] = t2;
14510c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
14520c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
14530c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
14540c1bc742181ded4930842b46e9507372f0b1b963James Dong        t1 = data[(y - 1) * 16 + x    ];
14550c1bc742181ded4930842b46e9507372f0b1b963James Dong        t2 = data[(y - 1) * 16 + x + 1];
14560c1bc742181ded4930842b46e9507372f0b1b963James Dong        a[1] = t1;
14570c1bc742181ded4930842b46e9507372f0b1b963James Dong        a[2] = t2;
14580c1bc742181ded4930842b46e9507372f0b1b963James Dong        t1 = data[(y - 1) * 16 + x + 2];
14590c1bc742181ded4930842b46e9507372f0b1b963James Dong        t2 = data[(y - 1) * 16 + x + 3];
14600c1bc742181ded4930842b46e9507372f0b1b963James Dong        a[3] = t1;
14610c1bc742181ded4930842b46e9507372f0b1b963James Dong        a[4] = t2;
14620c1bc742181ded4930842b46e9507372f0b1b963James Dong        t1 = data[(y - 1) * 16 + x + 4];
14630c1bc742181ded4930842b46e9507372f0b1b963James Dong        t2 = data[(y - 1) * 16 + x + 5];
14640c1bc742181ded4930842b46e9507372f0b1b963James Dong        a[5] = t1;
14650c1bc742181ded4930842b46e9507372f0b1b963James Dong        a[6] = t2;
14660c1bc742181ded4930842b46e9507372f0b1b963James Dong        t1 = data[(y - 1) * 16 + x + 6];
14670c1bc742181ded4930842b46e9507372f0b1b963James Dong        t2 = data[(y - 1) * 16 + x + 7];
14680c1bc742181ded4930842b46e9507372f0b1b963James Dong        a[7] = t1;
14690c1bc742181ded4930842b46e9507372f0b1b963James Dong        a[8] = t2;
14700c1bc742181ded4930842b46e9507372f0b1b963James Dong
14710c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (x == 0)
14720c1bc742181ded4930842b46e9507372f0b1b963James Dong            l[0] = a[0] = left[y-1];
14730c1bc742181ded4930842b46e9507372f0b1b963James Dong        else
14740c1bc742181ded4930842b46e9507372f0b1b963James Dong            l[0] = a[0] = data[(y - 1) * 16 + x - 1];
14750c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
14760c1bc742181ded4930842b46e9507372f0b1b963James Dong}
14770c1bc742181ded4930842b46e9507372f0b1b963James Dong
14780c1bc742181ded4930842b46e9507372f0b1b963James Dong
14790c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
14800c1bc742181ded4930842b46e9507372f0b1b963James Dong
14810c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: Intra4x4VerticalPrediction
14820c1bc742181ded4930842b46e9507372f0b1b963James Dong
14830c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
14840c1bc742181ded4930842b46e9507372f0b1b963James Dong          Perform intra 4x4 vertical prediction mode.
14850c1bc742181ded4930842b46e9507372f0b1b963James Dong
14860c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
14870c1bc742181ded4930842b46e9507372f0b1b963James Dong
14880c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid Intra4x4VerticalPrediction(u8 *data, u8 *above)
14890c1bc742181ded4930842b46e9507372f0b1b963James Dong{
14900c1bc742181ded4930842b46e9507372f0b1b963James Dong
14910c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
14920c1bc742181ded4930842b46e9507372f0b1b963James Dong
14930c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 t1, t2;
14940c1bc742181ded4930842b46e9507372f0b1b963James Dong
14950c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
14960c1bc742181ded4930842b46e9507372f0b1b963James Dong
14970c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(data);
14980c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(above);
14990c1bc742181ded4930842b46e9507372f0b1b963James Dong
15000c1bc742181ded4930842b46e9507372f0b1b963James Dong    t1 = above[0];
15010c1bc742181ded4930842b46e9507372f0b1b963James Dong    t2 = above[1];
15020c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[0] = data[4] = data[8] = data[12] = t1;
15030c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[1] = data[5] = data[9] = data[13] = t2;
15040c1bc742181ded4930842b46e9507372f0b1b963James Dong    t1 = above[2];
15050c1bc742181ded4930842b46e9507372f0b1b963James Dong    t2 = above[3];
15060c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[2] = data[6] = data[10] = data[14] = t1;
15070c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[3] = data[7] = data[11] = data[15] = t2;
15080c1bc742181ded4930842b46e9507372f0b1b963James Dong
15090c1bc742181ded4930842b46e9507372f0b1b963James Dong}
15100c1bc742181ded4930842b46e9507372f0b1b963James Dong
15110c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
15120c1bc742181ded4930842b46e9507372f0b1b963James Dong
15130c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: Intra4x4HorizontalPrediction
15140c1bc742181ded4930842b46e9507372f0b1b963James Dong
15150c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
15160c1bc742181ded4930842b46e9507372f0b1b963James Dong          Perform intra 4x4 horizontal prediction mode.
15170c1bc742181ded4930842b46e9507372f0b1b963James Dong
15180c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
15190c1bc742181ded4930842b46e9507372f0b1b963James Dong
15200c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid Intra4x4HorizontalPrediction(u8 *data, u8 *left)
15210c1bc742181ded4930842b46e9507372f0b1b963James Dong{
15220c1bc742181ded4930842b46e9507372f0b1b963James Dong
15230c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
15240c1bc742181ded4930842b46e9507372f0b1b963James Dong
15250c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 t1, t2;
15260c1bc742181ded4930842b46e9507372f0b1b963James Dong
15270c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
15280c1bc742181ded4930842b46e9507372f0b1b963James Dong
15290c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(data);
15300c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(left);
15310c1bc742181ded4930842b46e9507372f0b1b963James Dong
15320c1bc742181ded4930842b46e9507372f0b1b963James Dong    t1 = left[0];
15330c1bc742181ded4930842b46e9507372f0b1b963James Dong    t2 = left[1];
15340c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[0] = data[1] = data[2] = data[3] = t1;
15350c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[4] = data[5] = data[6] = data[7] = t2;
15360c1bc742181ded4930842b46e9507372f0b1b963James Dong    t1 = left[2];
15370c1bc742181ded4930842b46e9507372f0b1b963James Dong    t2 = left[3];
15380c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[8] = data[9] = data[10] = data[11] = t1;
15390c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[12] = data[13] = data[14] = data[15] = t2;
15400c1bc742181ded4930842b46e9507372f0b1b963James Dong
15410c1bc742181ded4930842b46e9507372f0b1b963James Dong}
15420c1bc742181ded4930842b46e9507372f0b1b963James Dong
15430c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
15440c1bc742181ded4930842b46e9507372f0b1b963James Dong
15450c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: Intra4x4DcPrediction
15460c1bc742181ded4930842b46e9507372f0b1b963James Dong
15470c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
15480c1bc742181ded4930842b46e9507372f0b1b963James Dong          Perform intra 4x4 DC prediction mode.
15490c1bc742181ded4930842b46e9507372f0b1b963James Dong
15500c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
15510c1bc742181ded4930842b46e9507372f0b1b963James Dong
15520c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid Intra4x4DcPrediction(u8 *data, u8 *above, u8 *left, u32 availableA,
15530c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 availableB)
15540c1bc742181ded4930842b46e9507372f0b1b963James Dong{
15550c1bc742181ded4930842b46e9507372f0b1b963James Dong
15560c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
15570c1bc742181ded4930842b46e9507372f0b1b963James Dong
15580c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 tmp;
15590c1bc742181ded4930842b46e9507372f0b1b963James Dong    u8 t1, t2, t3, t4;
15600c1bc742181ded4930842b46e9507372f0b1b963James Dong
15610c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
15620c1bc742181ded4930842b46e9507372f0b1b963James Dong
15630c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(data);
15640c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(above);
15650c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(left);
15660c1bc742181ded4930842b46e9507372f0b1b963James Dong
15670c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (availableA && availableB)
15680c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
15690c1bc742181ded4930842b46e9507372f0b1b963James Dong        t1 = above[0]; t2 = above[1]; t3 = above[2]; t4 = above[3];
15700c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp = t1 + t2 + t3 + t4;
15710c1bc742181ded4930842b46e9507372f0b1b963James Dong        t1 = left[0]; t2 = left[1]; t3 = left[2]; t4 = left[3];
15720c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp += t1 + t2 + t3 + t4;
15730c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp = (tmp + 4) >> 3;
15740c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
15750c1bc742181ded4930842b46e9507372f0b1b963James Dong    else if (availableA)
15760c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
15770c1bc742181ded4930842b46e9507372f0b1b963James Dong        t1 = left[0]; t2 = left[1]; t3 = left[2]; t4 = left[3];
15780c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp = (t1 + t2 + t3 + t4 + 2) >> 2;
15790c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
15800c1bc742181ded4930842b46e9507372f0b1b963James Dong    else if (availableB)
15810c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
15820c1bc742181ded4930842b46e9507372f0b1b963James Dong        t1 = above[0]; t2 = above[1]; t3 = above[2]; t4 = above[3];
15830c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp = (t1 + t2 + t3 + t4 + 2) >> 2;
15840c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
15850c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
15860c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
15870c1bc742181ded4930842b46e9507372f0b1b963James Dong        tmp = 128;
15880c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
15890c1bc742181ded4930842b46e9507372f0b1b963James Dong
15900c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(tmp < 256);
15910c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[0] = data[1] = data[2] = data[3] =
15920c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[4] = data[5] = data[6] = data[7] =
15930c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[8] = data[9] = data[10] = data[11] =
15940c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[12] = data[13] = data[14] = data[15] = (u8)tmp;
15950c1bc742181ded4930842b46e9507372f0b1b963James Dong
15960c1bc742181ded4930842b46e9507372f0b1b963James Dong}
15970c1bc742181ded4930842b46e9507372f0b1b963James Dong
15980c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
15990c1bc742181ded4930842b46e9507372f0b1b963James Dong
16000c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: Intra4x4DiagonalDownLeftPrediction
16010c1bc742181ded4930842b46e9507372f0b1b963James Dong
16020c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
16030c1bc742181ded4930842b46e9507372f0b1b963James Dong          Perform intra 4x4 diagonal down-left prediction mode.
16040c1bc742181ded4930842b46e9507372f0b1b963James Dong
16050c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
16060c1bc742181ded4930842b46e9507372f0b1b963James Dong
16070c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid Intra4x4DiagonalDownLeftPrediction(u8 *data, u8 *above)
16080c1bc742181ded4930842b46e9507372f0b1b963James Dong{
16090c1bc742181ded4930842b46e9507372f0b1b963James Dong
16100c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
16110c1bc742181ded4930842b46e9507372f0b1b963James Dong
16120c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
16130c1bc742181ded4930842b46e9507372f0b1b963James Dong
16140c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(data);
16150c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(above);
16160c1bc742181ded4930842b46e9507372f0b1b963James Dong
16170c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 0] = (above[0] + 2 * above[1] + above[2] + 2) >> 2;
16180c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 1] = (above[1] + 2 * above[2] + above[3] + 2) >> 2;
16190c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 4] = (above[1] + 2 * above[2] + above[3] + 2) >> 2;
16200c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 2] = (above[2] + 2 * above[3] + above[4] + 2) >> 2;
16210c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 5] = (above[2] + 2 * above[3] + above[4] + 2) >> 2;
16220c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 8] = (above[2] + 2 * above[3] + above[4] + 2) >> 2;
16230c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 3] = (above[3] + 2 * above[4] + above[5] + 2) >> 2;
16240c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 6] = (above[3] + 2 * above[4] + above[5] + 2) >> 2;
16250c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 9] = (above[3] + 2 * above[4] + above[5] + 2) >> 2;
16260c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[12] = (above[3] + 2 * above[4] + above[5] + 2) >> 2;
16270c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 7] = (above[4] + 2 * above[5] + above[6] + 2) >> 2;
16280c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[10] = (above[4] + 2 * above[5] + above[6] + 2) >> 2;
16290c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[13] = (above[4] + 2 * above[5] + above[6] + 2) >> 2;
16300c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[11] = (above[5] + 2 * above[6] + above[7] + 2) >> 2;
16310c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[14] = (above[5] + 2 * above[6] + above[7] + 2) >> 2;
16320c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[15] = (above[6] + 3 * above[7] + 2) >> 2;
16330c1bc742181ded4930842b46e9507372f0b1b963James Dong
16340c1bc742181ded4930842b46e9507372f0b1b963James Dong}
16350c1bc742181ded4930842b46e9507372f0b1b963James Dong
16360c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
16370c1bc742181ded4930842b46e9507372f0b1b963James Dong
16380c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: Intra4x4DiagonalDownRightPrediction
16390c1bc742181ded4930842b46e9507372f0b1b963James Dong
16400c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
16410c1bc742181ded4930842b46e9507372f0b1b963James Dong          Perform intra 4x4 diagonal down-right prediction mode.
16420c1bc742181ded4930842b46e9507372f0b1b963James Dong
16430c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
16440c1bc742181ded4930842b46e9507372f0b1b963James Dong
16450c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid Intra4x4DiagonalDownRightPrediction(u8 *data, u8 *above, u8 *left)
16460c1bc742181ded4930842b46e9507372f0b1b963James Dong{
16470c1bc742181ded4930842b46e9507372f0b1b963James Dong
16480c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
16490c1bc742181ded4930842b46e9507372f0b1b963James Dong
16500c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
16510c1bc742181ded4930842b46e9507372f0b1b963James Dong
16520c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(data);
16530c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(above);
16540c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(left);
16550c1bc742181ded4930842b46e9507372f0b1b963James Dong
16560c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 0] = (above[0] + 2 * above[-1] + left[0] + 2) >> 2;
16570c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 5] = (above[0] + 2 * above[-1] + left[0] + 2) >> 2;
16580c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[10] = (above[0] + 2 * above[-1] + left[0] + 2) >> 2;
16590c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[15] = (above[0] + 2 * above[-1] + left[0] + 2) >> 2;
16600c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 1] = (above[-1] + 2 * above[0] + above[1] + 2) >> 2;
16610c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 6] = (above[-1] + 2 * above[0] + above[1] + 2) >> 2;
16620c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[11] = (above[-1] + 2 * above[0] + above[1] + 2) >> 2;
16630c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 2] = (above[0] + 2 * above[1] + above[2] + 2) >> 2;
16640c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 7] = (above[0] + 2 * above[1] + above[2] + 2) >> 2;
16650c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 3] = (above[1] + 2 * above[2] + above[3] + 2) >> 2;
16660c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 4] = (left[-1] + 2 * left[0] + left[1] + 2) >> 2;
16670c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 9] = (left[-1] + 2 * left[0] + left[1] + 2) >> 2;
16680c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[14] = (left[-1] + 2 * left[0] + left[1] + 2) >> 2;
16690c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 8] = (left[0] + 2 * left[1] + left[2] + 2) >> 2;
16700c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[13] = (left[0] + 2 * left[1] + left[2] + 2) >> 2;
16710c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[12] = (left[1] + 2 * left[2] + left[3] + 2) >> 2;
16720c1bc742181ded4930842b46e9507372f0b1b963James Dong}
16730c1bc742181ded4930842b46e9507372f0b1b963James Dong
16740c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
16750c1bc742181ded4930842b46e9507372f0b1b963James Dong
16760c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: Intra4x4VerticalRightPrediction
16770c1bc742181ded4930842b46e9507372f0b1b963James Dong
16780c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
16790c1bc742181ded4930842b46e9507372f0b1b963James Dong          Perform intra 4x4 vertical right prediction mode.
16800c1bc742181ded4930842b46e9507372f0b1b963James Dong
16810c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
16820c1bc742181ded4930842b46e9507372f0b1b963James Dong
16830c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid Intra4x4VerticalRightPrediction(u8 *data, u8 *above, u8 *left)
16840c1bc742181ded4930842b46e9507372f0b1b963James Dong{
16850c1bc742181ded4930842b46e9507372f0b1b963James Dong
16860c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
16870c1bc742181ded4930842b46e9507372f0b1b963James Dong
16880c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
16890c1bc742181ded4930842b46e9507372f0b1b963James Dong
16900c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(data);
16910c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(above);
16920c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(left);
16930c1bc742181ded4930842b46e9507372f0b1b963James Dong
16940c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 0] = (above[-1] + above[0] + 1) >> 1;
16950c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 9] = (above[-1] + above[0] + 1) >> 1;
16960c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 5] = (above[-1] + 2 * above[0] + above[1] + 2) >> 2;
16970c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[14] = (above[-1] + 2 * above[0] + above[1] + 2) >> 2;
16980c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 4] = (above[0] + 2 * above[-1] + left[0] + 2) >> 2;
16990c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[13] = (above[0] + 2 * above[-1] + left[0] + 2) >> 2;
17000c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 1] = (above[0] + above[1] + 1) >> 1;
17010c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[10] = (above[0] + above[1] + 1) >> 1;
17020c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 6] = (above[0] + 2 * above[1] + above[2] + 2) >> 2;
17030c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[15] = (above[0] + 2 * above[1] + above[2] + 2) >> 2;
17040c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 2] = (above[1] + above[2] + 1) >> 1;
17050c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[11] = (above[1] + above[2] + 1) >> 1;
17060c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 7] = (above[1] + 2 * above[2] + above[3] + 2) >> 2;
17070c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 3] = (above[2] + above[3] + 1) >> 1;
17080c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 8] = (left[1] + 2 * left[0] + left[-1] + 2) >> 2;
17090c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[12] = (left[2] + 2 * left[1] + left[0] + 2) >> 2;
17100c1bc742181ded4930842b46e9507372f0b1b963James Dong
17110c1bc742181ded4930842b46e9507372f0b1b963James Dong}
17120c1bc742181ded4930842b46e9507372f0b1b963James Dong
17130c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
17140c1bc742181ded4930842b46e9507372f0b1b963James Dong
17150c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: Intra4x4HorizontalDownPrediction
17160c1bc742181ded4930842b46e9507372f0b1b963James Dong
17170c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
17180c1bc742181ded4930842b46e9507372f0b1b963James Dong          Perform intra 4x4 horizontal down prediction mode.
17190c1bc742181ded4930842b46e9507372f0b1b963James Dong
17200c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
17210c1bc742181ded4930842b46e9507372f0b1b963James Dong
17220c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid Intra4x4HorizontalDownPrediction(u8 *data, u8 *above, u8 *left)
17230c1bc742181ded4930842b46e9507372f0b1b963James Dong{
17240c1bc742181ded4930842b46e9507372f0b1b963James Dong
17250c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
17260c1bc742181ded4930842b46e9507372f0b1b963James Dong
17270c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
17280c1bc742181ded4930842b46e9507372f0b1b963James Dong
17290c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(data);
17300c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(above);
17310c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(left);
17320c1bc742181ded4930842b46e9507372f0b1b963James Dong
17330c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 0] = (left[-1] + left[0] + 1) >> 1;
17340c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 6] = (left[-1] + left[0] + 1) >> 1;
17350c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 5] = (left[-1] + 2 * left[0] + left[1] + 2) >> 2;
17360c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[11] = (left[-1] + 2 * left[0] + left[1] + 2) >> 2;
17370c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 4] = (left[0] + left[1] + 1) >> 1;
17380c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[10] = (left[0] + left[1] + 1) >> 1;
17390c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 9] = (left[0] + 2 * left[1] + left[2] + 2) >> 2;
17400c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[15] = (left[0] + 2 * left[1] + left[2] + 2) >> 2;
17410c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 8] = (left[1] + left[2] + 1) >> 1;
17420c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[14] = (left[1] + left[2] + 1) >> 1;
17430c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[13] = (left[1] + 2 * left[2] + left[3] + 2) >> 2;
17440c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[12] = (left[2] + left[3] + 1) >> 1;
17450c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 1] = (above[0] + 2 * above[-1] + left[0] + 2) >> 2;
17460c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 7] = (above[0] + 2 * above[-1] + left[0] + 2) >> 2;
17470c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 2] = (above[1] + 2 * above[0] + above[-1] + 2) >> 2;
17480c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 3] = (above[2] + 2 * above[1] + above[0] + 2) >> 2;
17490c1bc742181ded4930842b46e9507372f0b1b963James Dong}
17500c1bc742181ded4930842b46e9507372f0b1b963James Dong
17510c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
17520c1bc742181ded4930842b46e9507372f0b1b963James Dong
17530c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: Intra4x4VerticalLeftPrediction
17540c1bc742181ded4930842b46e9507372f0b1b963James Dong
17550c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
17560c1bc742181ded4930842b46e9507372f0b1b963James Dong          Perform intra 4x4 vertical left prediction mode.
17570c1bc742181ded4930842b46e9507372f0b1b963James Dong
17580c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
17590c1bc742181ded4930842b46e9507372f0b1b963James Dong
17600c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid Intra4x4VerticalLeftPrediction(u8 *data, u8 *above)
17610c1bc742181ded4930842b46e9507372f0b1b963James Dong{
17620c1bc742181ded4930842b46e9507372f0b1b963James Dong
17630c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
17640c1bc742181ded4930842b46e9507372f0b1b963James Dong
17650c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
17660c1bc742181ded4930842b46e9507372f0b1b963James Dong
17670c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(data);
17680c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(above);
17690c1bc742181ded4930842b46e9507372f0b1b963James Dong
17700c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 0] = (above[0] + above[1] + 1) >> 1;
17710c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 1] = (above[1] + above[2] + 1) >> 1;
17720c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 2] = (above[2] + above[3] + 1) >> 1;
17730c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 3] = (above[3] + above[4] + 1) >> 1;
17740c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 4] = (above[0] + 2 * above[1] + above[2] + 2) >> 2;
17750c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 5] = (above[1] + 2 * above[2] + above[3] + 2) >> 2;
17760c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 6] = (above[2] + 2 * above[3] + above[4] + 2) >> 2;
17770c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 7] = (above[3] + 2 * above[4] + above[5] + 2) >> 2;
17780c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 8] = (above[1] + above[2] + 1) >> 1;
17790c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 9] = (above[2] + above[3] + 1) >> 1;
17800c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[10] = (above[3] + above[4] + 1) >> 1;
17810c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[11] = (above[4] + above[5] + 1) >> 1;
17820c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[12] = (above[1] + 2 * above[2] + above[3] + 2) >> 2;
17830c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[13] = (above[2] + 2 * above[3] + above[4] + 2) >> 2;
17840c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[14] = (above[3] + 2 * above[4] + above[5] + 2) >> 2;
17850c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[15] = (above[4] + 2 * above[5] + above[6] + 2) >> 2;
17860c1bc742181ded4930842b46e9507372f0b1b963James Dong
17870c1bc742181ded4930842b46e9507372f0b1b963James Dong}
17880c1bc742181ded4930842b46e9507372f0b1b963James Dong
17890c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
17900c1bc742181ded4930842b46e9507372f0b1b963James Dong
17910c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: Intra4x4HorizontalUpPrediction
17920c1bc742181ded4930842b46e9507372f0b1b963James Dong
17930c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
17940c1bc742181ded4930842b46e9507372f0b1b963James Dong          Perform intra 4x4 horizontal up prediction mode.
17950c1bc742181ded4930842b46e9507372f0b1b963James Dong
17960c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
17970c1bc742181ded4930842b46e9507372f0b1b963James Dong
17980c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid Intra4x4HorizontalUpPrediction(u8 *data, u8 *left)
17990c1bc742181ded4930842b46e9507372f0b1b963James Dong{
18000c1bc742181ded4930842b46e9507372f0b1b963James Dong
18010c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
18020c1bc742181ded4930842b46e9507372f0b1b963James Dong
18030c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
18040c1bc742181ded4930842b46e9507372f0b1b963James Dong
18050c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(data);
18060c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(left);
18070c1bc742181ded4930842b46e9507372f0b1b963James Dong
18080c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 0] = (left[0] + left[1] + 1) >> 1;
18090c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 1] = (left[0] + 2 * left[1] + left[2] + 2) >> 2;
18100c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 2] = (left[1] + left[2] + 1) >> 1;
18110c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 3] = (left[1] + 2 * left[2] + left[3] + 2) >> 2;
18120c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 4] = (left[1] + left[2] + 1) >> 1;
18130c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 5] = (left[1] + 2 * left[2] + left[3] + 2) >> 2;
18140c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 6] = (left[2] + left[3] + 1) >> 1;
18150c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 7] = (left[2] + 3 * left[3] + 2) >> 2;
18160c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 8] = (left[2] + left[3] + 1) >> 1;
18170c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[ 9] = (left[2] + 3 * left[3] + 2) >> 2;
18180c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[10] = left[3];
18190c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[11] = left[3];
18200c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[12] = left[3];
18210c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[13] = left[3];
18220c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[14] = left[3];
18230c1bc742181ded4930842b46e9507372f0b1b963James Dong    data[15] = left[3];
18240c1bc742181ded4930842b46e9507372f0b1b963James Dong
18250c1bc742181ded4930842b46e9507372f0b1b963James Dong}
18260c1bc742181ded4930842b46e9507372f0b1b963James Dong
18270c1bc742181ded4930842b46e9507372f0b1b963James Dong#endif /* H264DEC_OMXDL */
18280c1bc742181ded4930842b46e9507372f0b1b963James Dong
18290c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
18300c1bc742181ded4930842b46e9507372f0b1b963James Dong
18310c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: Write4x4To16x16
18320c1bc742181ded4930842b46e9507372f0b1b963James Dong
18330c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
18340c1bc742181ded4930842b46e9507372f0b1b963James Dong          Write a 4x4 block (data4x4) into correct position
18350c1bc742181ded4930842b46e9507372f0b1b963James Dong          in 16x16 macroblock (data).
18360c1bc742181ded4930842b46e9507372f0b1b963James Dong
18370c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
18380c1bc742181ded4930842b46e9507372f0b1b963James Dong
18390c1bc742181ded4930842b46e9507372f0b1b963James Dongvoid Write4x4To16x16(u8 *data, u8 *data4x4, u32 blockNum)
18400c1bc742181ded4930842b46e9507372f0b1b963James Dong{
18410c1bc742181ded4930842b46e9507372f0b1b963James Dong
18420c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
18430c1bc742181ded4930842b46e9507372f0b1b963James Dong
18440c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 x, y;
18450c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 *in32, *out32;
18460c1bc742181ded4930842b46e9507372f0b1b963James Dong
18470c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
18480c1bc742181ded4930842b46e9507372f0b1b963James Dong
18490c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(data);
18500c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(data4x4);
18510c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(blockNum < 16);
18520c1bc742181ded4930842b46e9507372f0b1b963James Dong
18530c1bc742181ded4930842b46e9507372f0b1b963James Dong    x = h264bsdBlockX[blockNum];
18540c1bc742181ded4930842b46e9507372f0b1b963James Dong    y = h264bsdBlockY[blockNum];
18550c1bc742181ded4930842b46e9507372f0b1b963James Dong
18560c1bc742181ded4930842b46e9507372f0b1b963James Dong    data += y*16+x;
18570c1bc742181ded4930842b46e9507372f0b1b963James Dong
18580c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(((u32)data&0x3) == 0);
18590c1bc742181ded4930842b46e9507372f0b1b963James Dong
18600c1bc742181ded4930842b46e9507372f0b1b963James Dong    /*lint --e(826) */
18610c1bc742181ded4930842b46e9507372f0b1b963James Dong    out32 = (u32 *)data;
18620c1bc742181ded4930842b46e9507372f0b1b963James Dong    /*lint --e(826) */
18630c1bc742181ded4930842b46e9507372f0b1b963James Dong    in32 = (u32 *)data4x4;
18640c1bc742181ded4930842b46e9507372f0b1b963James Dong
18650c1bc742181ded4930842b46e9507372f0b1b963James Dong    out32[0] = *in32++;
18660c1bc742181ded4930842b46e9507372f0b1b963James Dong    out32[4] = *in32++;
18670c1bc742181ded4930842b46e9507372f0b1b963James Dong    out32[8] = *in32++;
18680c1bc742181ded4930842b46e9507372f0b1b963James Dong    out32[12] = *in32++;
18690c1bc742181ded4930842b46e9507372f0b1b963James Dong}
18700c1bc742181ded4930842b46e9507372f0b1b963James Dong
18710c1bc742181ded4930842b46e9507372f0b1b963James Dong/*------------------------------------------------------------------------------
18720c1bc742181ded4930842b46e9507372f0b1b963James Dong
18730c1bc742181ded4930842b46e9507372f0b1b963James Dong    Function: DetermineIntra4x4PredMode
18740c1bc742181ded4930842b46e9507372f0b1b963James Dong
18750c1bc742181ded4930842b46e9507372f0b1b963James Dong        Functional description:
18760c1bc742181ded4930842b46e9507372f0b1b963James Dong          Returns the intra 4x4 prediction mode of a block based on the
18770c1bc742181ded4930842b46e9507372f0b1b963James Dong          neighbouring macroblocks and information parsed from stream.
18780c1bc742181ded4930842b46e9507372f0b1b963James Dong
18790c1bc742181ded4930842b46e9507372f0b1b963James Dong------------------------------------------------------------------------------*/
18800c1bc742181ded4930842b46e9507372f0b1b963James Dong
18810c1bc742181ded4930842b46e9507372f0b1b963James Dongu32 DetermineIntra4x4PredMode(macroblockLayer_t *pMbLayer,
18820c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 available, neighbour_t *nA, neighbour_t *nB, u32 index,
18830c1bc742181ded4930842b46e9507372f0b1b963James Dong    mbStorage_t *nMbA, mbStorage_t *nMbB)
18840c1bc742181ded4930842b46e9507372f0b1b963James Dong{
18850c1bc742181ded4930842b46e9507372f0b1b963James Dong
18860c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Variables */
18870c1bc742181ded4930842b46e9507372f0b1b963James Dong
18880c1bc742181ded4930842b46e9507372f0b1b963James Dong    u32 mode1, mode2;
18890c1bc742181ded4930842b46e9507372f0b1b963James Dong    mbStorage_t *pMb;
18900c1bc742181ded4930842b46e9507372f0b1b963James Dong
18910c1bc742181ded4930842b46e9507372f0b1b963James Dong/* Code */
18920c1bc742181ded4930842b46e9507372f0b1b963James Dong
18930c1bc742181ded4930842b46e9507372f0b1b963James Dong    ASSERT(pMbLayer);
18940c1bc742181ded4930842b46e9507372f0b1b963James Dong
18950c1bc742181ded4930842b46e9507372f0b1b963James Dong    /* dc only prediction? */
18960c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (!available)
18970c1bc742181ded4930842b46e9507372f0b1b963James Dong        mode1 = 2;
18980c1bc742181ded4930842b46e9507372f0b1b963James Dong    else
18990c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
19000c1bc742181ded4930842b46e9507372f0b1b963James Dong        pMb = nMbA;
19010c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (h264bsdMbPartPredMode(pMb->mbType) == PRED_MODE_INTRA4x4)
19020c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
19030c1bc742181ded4930842b46e9507372f0b1b963James Dong            mode1 = pMb->intra4x4PredMode[nA->index];
19040c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
19050c1bc742181ded4930842b46e9507372f0b1b963James Dong        else
19060c1bc742181ded4930842b46e9507372f0b1b963James Dong            mode1 = 2;
19070c1bc742181ded4930842b46e9507372f0b1b963James Dong
19080c1bc742181ded4930842b46e9507372f0b1b963James Dong        pMb = nMbB;
19090c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (h264bsdMbPartPredMode(pMb->mbType) == PRED_MODE_INTRA4x4)
19100c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
19110c1bc742181ded4930842b46e9507372f0b1b963James Dong            mode2 = pMb->intra4x4PredMode[nB->index];
19120c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
19130c1bc742181ded4930842b46e9507372f0b1b963James Dong        else
19140c1bc742181ded4930842b46e9507372f0b1b963James Dong            mode2 = 2;
19150c1bc742181ded4930842b46e9507372f0b1b963James Dong
19160c1bc742181ded4930842b46e9507372f0b1b963James Dong        mode1 = MIN(mode1, mode2);
19170c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
19180c1bc742181ded4930842b46e9507372f0b1b963James Dong
19190c1bc742181ded4930842b46e9507372f0b1b963James Dong    if (!pMbLayer->mbPred.prevIntra4x4PredModeFlag[index])
19200c1bc742181ded4930842b46e9507372f0b1b963James Dong    {
19210c1bc742181ded4930842b46e9507372f0b1b963James Dong        if (pMbLayer->mbPred.remIntra4x4PredMode[index] < mode1)
19220c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
19230c1bc742181ded4930842b46e9507372f0b1b963James Dong            mode1 = pMbLayer->mbPred.remIntra4x4PredMode[index];
19240c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
19250c1bc742181ded4930842b46e9507372f0b1b963James Dong        else
19260c1bc742181ded4930842b46e9507372f0b1b963James Dong        {
19270c1bc742181ded4930842b46e9507372f0b1b963James Dong            mode1 = pMbLayer->mbPred.remIntra4x4PredMode[index] + 1;
19280c1bc742181ded4930842b46e9507372f0b1b963James Dong        }
19290c1bc742181ded4930842b46e9507372f0b1b963James Dong    }
19300c1bc742181ded4930842b46e9507372f0b1b963James Dong
19310c1bc742181ded4930842b46e9507372f0b1b963James Dong    return(mode1);
19320c1bc742181ded4930842b46e9507372f0b1b963James Dong}
19330c1bc742181ded4930842b46e9507372f0b1b963James Dong
19340c1bc742181ded4930842b46e9507372f0b1b963James Dong
19350c1bc742181ded4930842b46e9507372f0b1b963James Dong/*lint +e702 */
19360c1bc742181ded4930842b46e9507372f0b1b963James Dong
19370c1bc742181ded4930842b46e9507372f0b1b963James Dong
1938