13306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/* ------------------------------------------------------------------
23306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong * Copyright (C) 1998-2009 PacketVideo
33306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong *
43306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong * Licensed under the Apache License, Version 2.0 (the "License");
53306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong * you may not use this file except in compliance with the License.
63306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong * You may obtain a copy of the License at
73306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong *
83306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong *      http://www.apache.org/licenses/LICENSE-2.0
93306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong *
103306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong * Unless required by applicable law or agreed to in writing, software
113306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong * distributed under the License is distributed on an "AS IS" BASIS,
123306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
133306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong * express or implied.
143306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong * See the License for the specific language governing permissions
153306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong * and limitations under the License.
163306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong * -------------------------------------------------------------------
173306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong */
183306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*
193306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*     -------------------------------------------------------------------       *
203306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*                    MPEG-4 Simple Profile Video Decoder                        *
213306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*     -------------------------------------------------------------------       *
223306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*
233306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong* This software module was originally developed by
243306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*
253306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*   Paulo Nunes (IST / ACTS-MoMuSyS)
263306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*   Robert Danielsen (Telenor / ACTS-MoMuSyS)
273306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*
283306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong* in the course of development of the MPEG-4 Video (ISO/IEC 14496-2) standard.
293306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong* This software module is an implementation of a part of one or more MPEG-4
303306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong* Video (ISO/IEC 14496-2) tools as specified by the MPEG-4 Video (ISO/IEC
313306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong* 14496-2) standard.
323306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*
333306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong* ISO/IEC gives users of the MPEG-4 Video (ISO/IEC 14496-2) standard free
343306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong* license to this software module or modifications thereof for use in hardware
353306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong* or software products claiming conformance to the MPEG-4 Video (ISO/IEC
363306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong* 14496-2) standard.
373306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*
383306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong* Those intending to use this software module in hardware or software products
393306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong* are advised that its use may infringe existing patents. The original
403306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong* developer of this software module and his/her company, the subsequent
413306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong* editors and their companies, and ISO/IEC have no liability for use of this
423306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong* software module or modifications thereof in an implementation. Copyright is
433306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong* not released for non MPEG-4 Video (ISO/IEC 14496-2) Standard conforming
443306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong* products.
453306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*
463306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong* ACTS-MoMuSys partners retain full right to use the code for his/her own
473306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong* purpose, assign or donate the code to a third party and to inhibit third
483306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong* parties from using the code for non MPEG-4 Video (ISO/IEC 14496-2) Standard
493306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong* conforming products. This copyright notice must be included in all copies or
503306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong* derivative works.
513306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*
523306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong* Copyright (c) 1996
533306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*
543306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*****************************************************************************/
553306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
563306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/***********************************************************HeaderBegin*******
573306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*
583306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong* File: vlc_dec.c
593306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*
603306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong* Author:   Paulo Nunes (IST) - Paulo.Nunes@lx.it.pt
613306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong* Created:  1-Mar-96
623306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*
633306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong* Description: This file contains the VLC functions needed to decode a
643306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*       bitstream.
653306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*
663306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong* Notes:
673306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*       The functions contained in this file were adapted from
683306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*       tmndecode
693306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*       Written by Karl Olav Lillevold <kol@nta.no>,
703306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*       1995 Telenor R&D.
713306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*       Donated to the Momusys-project as background code by
723306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*       Telenor.
733306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*
743306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*       based on mpeg2decode, (C) 1994, MPEG Software Simulation Group
753306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*       and mpeg2play, (C) 1994 Stefan Eckart
763306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*                   <stefan@lis.e-technik.tu-muenchen.de>
773306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*
783306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*
793306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong* Modified: 9-May-96 Paulo Nunes: Reformatted. New headers.
803306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*              17-Jan-97 Jan De Lameillieure (HHI) : corrected in
813306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*              01.05.97 Luis Ducla-Soares: added RvlcDecTCOEF() to allow decoding
823306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*                                          of Reversible VLCs.
833306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*       09.03.98 Paulo Nunes: Cleaning.
843306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*
853306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong***********************************************************HeaderEnd*********/
863306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
873306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#include "mp4dec_lib.h"
883306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#include "vlc_dec_tab.h"
893306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#include "vlc_decode.h"
903306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#include "bitstream.h"
913306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#include "max_level.h"
923306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
933306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
943306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/* ====================================================================== /
953306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    Function : DecodeUserData()
963306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    Date     : 04/10/2000
973306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    History  :
983306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    Modified : 04/16/2001 : removed status checking of PV_BitstreamFlushBits
993306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
1003306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        This is simply a realization of the user_data() function
1013306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        in the ISO/IEC 14496-2 manual.
1023306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/ ====================================================================== */
1033306cfee3bf38ab207a0504e49c2d492bb73ffbfJames DongPV_STATUS DecodeUserData(BitstreamDecVideo *stream)
1043306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong{
1053306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    PV_STATUS status;
1063306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    uint32 code;
1073306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
1083306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    BitstreamReadBits32HC(stream);
1093306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    BitstreamShowBits32(stream, 24, &code);
1103306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
1113306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    while (code != 1)
1123306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
1133306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        /* Discard user data for now.   04/05/2000 */
1143306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        BitstreamReadBits16(stream, 8);
1153306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        BitstreamShowBits32(stream, 24, &code);
1163306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        status = BitstreamCheckEndBuffer(stream);
1173306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (status == PV_END_OF_VOP) return status;    /*  03/19/2002 */
1183306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
1193306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    return PV_SUCCESS;
1203306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong}
1213306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
1223306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
1233306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
1243306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/***********************************************************CommentBegin******
1253306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*
1263306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*       3/10/00  : initial modification to the
1273306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*                new PV-Decoder Lib format.
1283306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*       3/29/00  : added return code check to some functions and
1293306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*                optimize the code.
1303306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*
1313306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong***********************************************************CommentEnd********/
1323306cfee3bf38ab207a0504e49c2d492bb73ffbfJames DongPV_STATUS PV_GetMBvectors(VideoDecData *video, uint mode)
1333306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong{
1343306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    PV_STATUS status;
1353306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    BitstreamDecVideo *stream = video->bitstream;
1363306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int  f_code_f = video->currVop->fcodeForward;
1373306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int  vlc_code_mag;
1383306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
1393306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
1403306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    MOT *mot_x = video->motX;
1413306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    MOT *mot_y = video->motY;
1423306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
1433306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int k, offset;
1443306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int x_pos = video->mbnum_col;
1453306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int y_pos = video->mbnum_row;
1463306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int doubleWidth = video->nMBPerRow << 1;
1473306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int pos = (x_pos + y_pos * doubleWidth) << 1;
1483306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    MOT mvx = 0, mvy = 0;
1493306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
1503306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
1513306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (f_code_f == 1)
1523306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
1533306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#ifdef PV_ANNEX_IJKT_SUPPORT
1543306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (mode == MODE_INTER4V || mode == MODE_INTER4V_Q)
1553306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#else
1563306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (mode == MODE_INTER4V)
1573306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#endif
1583306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
1593306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            for (k = 0; k < 4; k++)
1603306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
1613306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                offset = (k & 1) + (k >> 1) * doubleWidth;
1623306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                mv_prediction(video, k, &mvx, &mvy);
1633306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                /* decode component x */
1643306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                status = PV_VlcDecMV(stream, &vlc_code_mag);
1653306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                if (status != PV_SUCCESS)
1663306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                {
1673306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    return status;
1683306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                }
1693306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
1703306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                mvx += (MOT)vlc_code_mag;
1713306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                mvx = (MOT)(((mvx + 32) & 0x3F) - 32);
1723306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
1733306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
1743306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                status = PV_VlcDecMV(stream, &vlc_code_mag);
1753306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                if (status != PV_SUCCESS)
1763306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                {
1773306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    return status;
1783306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                }
1793306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
1803306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                mvy += (MOT)vlc_code_mag;
1813306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                mvy = (MOT)(((mvy + 32) & 0x3F) - 32);
1823306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
1833306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                mot_x[pos+offset] = (MOT) mvx;
1843306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                mot_y[pos+offset] = (MOT) mvy;
1853306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
1863306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
1873306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        else
1883306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
1893306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            mv_prediction(video, 0, &mvx, &mvy);
1903306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            /* For PVOPs, field  appears only in MODE_INTER & MODE_INTER_Q */
1913306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            status = PV_VlcDecMV(stream, &vlc_code_mag);
1923306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            if (status != PV_SUCCESS)
1933306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
1943306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                return status;
1953306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
1963306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
1973306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            mvx += (MOT)vlc_code_mag;
1983306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            mvx = (MOT)(((mvx + 32) & 0x3F) - 32);
1993306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
2003306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
2013306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            status = PV_VlcDecMV(stream, &vlc_code_mag);
2023306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            if (status != PV_SUCCESS)
2033306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
2043306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                return status;
2053306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
2063306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
2073306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
2083306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            mvy += (MOT)vlc_code_mag;
2093306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            mvy = (MOT)(((mvy + 32) & 0x3F) - 32);
2103306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
2113306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
2123306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            mot_x[pos] = mot_x[pos+1] = (MOT) mvx;
2133306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            mot_y[pos] = mot_y[pos+1] = (MOT) mvy;
2143306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            pos += doubleWidth;
2153306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            mot_x[pos] = mot_x[pos+1] = (MOT) mvx;
2163306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            mot_y[pos] = mot_y[pos+1] = (MOT) mvy;
2173306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
2183306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
2193306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    else
2203306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
2213306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#ifdef PV_ANNEX_IJKT_SUPPORT
2223306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (mode == MODE_INTER4V || mode == MODE_INTER4V_Q)
2233306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#else
2243306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (mode == MODE_INTER4V)
2253306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#endif
2263306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
2273306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            for (k = 0; k < 4; k++)
2283306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
2293306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                offset = (k & 1) + (k >> 1) * doubleWidth;
2303306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                mv_prediction(video, k, &mvx, &mvy);
2313306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                status = PV_DecodeMBVec(stream, &mvx, &mvy, f_code_f);
2323306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                mot_x[pos+offset] = (MOT) mvx;
2333306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                mot_y[pos+offset] = (MOT) mvy;
2343306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                if (status != PV_SUCCESS)
2353306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                {
2363306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    return status;
2373306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                }
2383306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
2393306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
2403306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        else
2413306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
2423306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            mv_prediction(video, 0, &mvx, &mvy);
2433306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            /* For PVOPs, field  appears only in MODE_INTER & MODE_INTER_Q */
2443306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            status = PV_DecodeMBVec(stream, &mvx, &mvy, f_code_f);
2453306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            mot_x[pos] = mot_x[pos+1] = (MOT) mvx;
2463306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            mot_y[pos] = mot_y[pos+1] = (MOT) mvy;
2473306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            pos += doubleWidth;
2483306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            mot_x[pos] = mot_x[pos+1] = (MOT) mvx;
2493306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            mot_y[pos] = mot_y[pos+1] = (MOT) mvy;
2503306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            if (status != PV_SUCCESS)
2513306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
2523306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                return status;
2533306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
2543306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
2553306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
2563306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    return PV_SUCCESS;
2573306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong}
2583306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
2593306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
2603306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/***********************************************************CommentBegin******
2613306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*       3/10/00  : initial modification to the
2623306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*                new PV-Decoder Lib format.
2633306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*       3/29/00  : added return code check to some functions
2643306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*       5/10/00  : check whether the decoded vector is legal.
2653306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*       4/17/01  : use MOT type
2663306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong***********************************************************CommentEnd********/
2673306cfee3bf38ab207a0504e49c2d492bb73ffbfJames DongPV_STATUS PV_DecodeMBVec(BitstreamDecVideo *stream, MOT *mv_x, MOT *mv_y, int f_code_f)
2683306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong{
2693306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    PV_STATUS status;
2703306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int  vlc_code_magx, vlc_code_magy;
2713306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int  residualx = 0, residualy = 0;
2723306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
2733306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    /* decode component x */
2743306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    status = PV_VlcDecMV(stream, &vlc_code_magx);
2753306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (status != PV_SUCCESS)
2763306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
2773306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        return status;
2783306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
2793306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
2803306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (vlc_code_magx)
2813306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
2823306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        residualx = (int) BitstreamReadBits16_INLINE(stream, (int)(f_code_f - 1));
2833306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
2843306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
2853306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
2863306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    /* decode component y */
2873306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    status = PV_VlcDecMV(stream, &vlc_code_magy);
2883306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (status != PV_SUCCESS)
2893306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
2903306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        return status;
2913306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
2923306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
2933306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (vlc_code_magy)
2943306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
2953306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        residualy = (int) BitstreamReadBits16_INLINE(stream, (int)(f_code_f - 1));
2963306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
2973306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
2983306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
2993306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (PV_DeScaleMVD(f_code_f, residualx, vlc_code_magx, mv_x) != PV_SUCCESS)
3003306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
3013306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        return PV_FAIL;
3023306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
3033306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
3043306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (PV_DeScaleMVD(f_code_f, residualy, vlc_code_magy, mv_y) != PV_SUCCESS)
3053306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
3063306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        return PV_FAIL;
3073306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
3083306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
3093306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    return PV_SUCCESS;
3103306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong}
3113306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
3123306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
3133306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/***********************************************************CommentBegin******
3143306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*       3/31/2000 : initial modification to the new PV-Decoder Lib format.
3153306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*       5/10/2000 : check to see if the decoded vector falls within
3163306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*                           the legal fcode range.
3173306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*
3183306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong***********************************************************CommentEnd********/
3193306cfee3bf38ab207a0504e49c2d492bb73ffbfJames DongPV_STATUS PV_DeScaleMVD(
3203306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int  f_code,       /* <-- MV range in 1/2 units: 1=32,2=64,...,7=2048     */
3213306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int  residual,     /* <-- part of the MV Diff. FLC coded                  */
3223306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int  vlc_code_mag, /* <-- part of the MV Diff. VLC coded                  */
3233306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    MOT  *vector       /* --> Obtained MV component in 1/2 units              */
3243306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong)
3253306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong{
3263306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int   half_range = (1 << (f_code + 4));
3273306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int   mask = (half_range << 1) - 1;
3283306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int   diff_vector;
3293306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
3303306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
3313306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (vlc_code_mag == 0)
3323306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
3333306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        diff_vector = vlc_code_mag;
3343306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
3353306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    else
3363306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
3373306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        diff_vector = ((PV_ABS(vlc_code_mag) - 1) << (f_code - 1)) + residual + 1;
3383306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (vlc_code_mag < 0)
3393306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
3403306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            diff_vector = -diff_vector;
3413306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
3423306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
3433306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
3443306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    *vector += (MOT)(diff_vector);
3453306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
3463306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    *vector = (MOT)((*vector + half_range) & mask) - half_range;
3473306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
3483306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    return PV_SUCCESS;
3493306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong}
3503306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
3513306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
3523306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
3533306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dongvoid mv_prediction(
3543306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    VideoDecData *video,
3553306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int block,
3563306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    MOT *mvx,
3573306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    MOT *mvy
3583306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong)
3593306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong{
3603306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    /*----------------------------------------------------------------------------
3613306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    ; Define all local variables
3623306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    ----------------------------------------------------------------------------*/
3633306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    MOT *motxdata = video->motX;
3643306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    MOT *motydata = video->motY;
3653306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int mbnum_col = video->mbnum_col;
3663306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int mbnum_row = video->mbnum_row;
3673306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    uint8 *slice_nb = video->sliceNo;
3683306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int nMBPerRow = video->nMBPerRow;
3693306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int nMVPerRow = nMBPerRow << 1;
3703306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int mbnum = video->mbnum;
3713306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int p1x = 0, p2x = 0, p3x = 0;
3723306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int p1y = 0, p2y = 0, p3y = 0;
3733306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int rule1 = 0, rule2 = 0, rule3 = 0;
3743306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int     indx;
3753306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
3763306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    indx = ((mbnum_col << 1) + (block & 1)) + ((mbnum_row << 1)  + (block >> 1)) * nMVPerRow - 1; /* left block */
3773306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
3783306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (block & 1)           /* block 1, 3 */
3793306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
3803306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        p1x = motxdata[indx];
3813306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        p1y = motydata[indx];
3823306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        rule1 = 1;
3833306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
3843306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    else                    /* block 0, 2 */
3853306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
3863306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (mbnum_col > 0 && slice_nb[mbnum] == slice_nb[mbnum-1])
3873306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
3883306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            p1x = motxdata[indx];
3893306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            p1y = motydata[indx];
3903306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            rule1 = 1;
3913306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
3923306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
3933306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
3943306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    indx = indx + 1 - nMVPerRow; /* upper_block */
3953306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (block >> 1)
3963306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
3973306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        indx -= (block & 1);
3983306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        p2x = motxdata[indx];
3993306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        p2y = motydata[indx];
4003306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        p3x = motxdata[indx + 1];
4013306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        p3y = motydata[indx + 1];
4023306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        rule2 = rule3 = 1;
4033306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
4043306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    else
4053306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {                           /* block 0,1 */
4063306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (mbnum_row)
4073306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
4083306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            if (slice_nb[mbnum] == slice_nb[mbnum-nMBPerRow])
4093306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
4103306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                p2x = motxdata[indx];
4113306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                p2y = motydata[indx];
4123306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                rule2 = 1;
4133306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
4143306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            if (mbnum_col < nMBPerRow - 1 && slice_nb[mbnum] == slice_nb[mbnum-nMBPerRow+1])
4153306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
4163306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                indx = indx + 2 - (block & 1);
4173306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                p3x = motxdata[indx];
4183306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                p3y = motydata[indx];
4193306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                rule3 = 1;
4203306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
4213306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
4223306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
4233306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
4243306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (rule1 + rule2 + rule3 > 1)
4253306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
4263306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        *mvx = (MOT)PV_MEDIAN(p1x, p2x, p3x);
4273306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        *mvy = (MOT)PV_MEDIAN(p1y, p2y, p3y);
4283306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
4293306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    else if (rule1 + rule2 + rule3 == 1)
4303306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
4313306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        /* two of three are zero */
4323306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        *mvx = (MOT)(p1x + p2x + p3x);
4333306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        *mvy = (MOT)(p1y + p2y + p3y);
4343306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
4353306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    else
4363306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
4373306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        /* all MBs are outside the VOP */
4383306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        *mvx = *mvy = 0;
4393306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
4403306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    /*----------------------------------------------------------------------------
4413306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    ; Return nothing or data or data pointer
4423306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    ----------------------------------------------------------------------------*/
4433306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    return;
4443306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong}
4453306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
4463306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/***********************************************************CommentBegin******
4473306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*
4483306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*       3/30/2000 : initial modification to the new PV-Decoder Lib format.
4493306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*       4/16/2001 : removed checking of status for PV_BitstreamFlushBits
4503306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong***********************************************************CommentEnd********/
4513306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
4523306cfee3bf38ab207a0504e49c2d492bb73ffbfJames DongPV_STATUS PV_VlcDecMV(BitstreamDecVideo *stream, int *mv)
4533306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong{
4543306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    PV_STATUS status = PV_SUCCESS;
4553306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    uint code;
4563306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
4573306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    BitstreamShow13Bits(stream, &code);
4583306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
4593306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (code >> 12)
4603306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
4613306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        *mv = 0; /* Vector difference = 0 */
4623306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        PV_BitstreamFlushBits(stream, 1);
4633306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        return PV_SUCCESS;
4643306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
4653306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
4663306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (code >= 512)
4673306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
4683306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        code = (code >> 8) - 2;
4693306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        PV_BitstreamFlushBits(stream, PV_TMNMVtab0[code].len + 1);
4703306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        *mv = PV_TMNMVtab0[code].val;
4713306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        return status;
4723306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
4733306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
4743306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (code >= 128)
4753306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
4763306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        code = (code >> 2) - 32;
4773306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        PV_BitstreamFlushBits(stream, PV_TMNMVtab1[code].len + 1);
4783306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        *mv = PV_TMNMVtab1[code].val;
4793306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        return status;
4803306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
4813306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
4823306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (code < 4)
4833306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
4843306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        *mv = -1;
4853306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        return PV_FAIL;
4863306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
4873306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
4883306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    code -= 4;
4893306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
4903306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    PV_BitstreamFlushBits(stream, PV_TMNMVtab2[code].len + 1);
4913306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
4923306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    *mv = PV_TMNMVtab2[code].val;
4933306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    return status;
4943306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong}
4953306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
4963306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
4973306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/***********************************************************CommentBegin******
4983306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*       3/30/2000 : initial modification to the new PV-Decoder Lib
4993306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*                           format and the change of error-handling method.
5003306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*       4/16/01   : removed status checking of PV_BitstreamFlushBits
5013306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong***********************************************************CommentEnd********/
5023306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
5033306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dongint PV_VlcDecMCBPC_com_intra(BitstreamDecVideo *stream)
5043306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong{
5053306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    uint code;
5063306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
5073306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    BitstreamShowBits16(stream, 9, &code);
5083306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
5093306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
5103306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (code < 8)
5113306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
5123306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        return VLC_CODE_ERROR;
5133306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
5143306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
5153306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    code >>= 3;
5163306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
5173306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (code >= 32)
5183306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
5193306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        PV_BitstreamFlushBits(stream, 1);
5203306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        return 3;
5213306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
5223306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
5233306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    PV_BitstreamFlushBits(stream, PV_MCBPCtabintra[code].len);
5243306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
5253306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    return PV_MCBPCtabintra[code].val;
5263306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong}
5273306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
5283306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
5293306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/***********************************************************CommentBegin******
5303306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*
5313306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*       3/30/2000 : initial modification to the new PV-Decoder Lib
5323306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*                           format and the change of error-handling method.
5333306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*       4/16/2001 : removed checking of return status of PV_BitstreamFlushBits
5343306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong***********************************************************CommentEnd********/
5353306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
5363306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dongint PV_VlcDecMCBPC_com_inter(BitstreamDecVideo *stream)
5373306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong{
5383306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    uint code;
5393306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
5403306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    BitstreamShowBits16(stream, 9, &code);
5413306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
5423306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (code == 0)
5433306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
5443306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        return VLC_CODE_ERROR;
5453306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
5463306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    else if (code >= 256)
5473306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
5483306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        PV_BitstreamFlushBits(stream, 1);
5493306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        return 0;
5503306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
5513306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
5523306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    PV_BitstreamFlushBits(stream, PV_MCBPCtab[code].len);
5533306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    return PV_MCBPCtab[code].val;
5543306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong}
5553306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
5563306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#ifdef PV_ANNEX_IJKT_SUPPORT
5573306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dongint PV_VlcDecMCBPC_com_inter_H263(BitstreamDecVideo *stream)
5583306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong{
5593306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    uint code;
5603306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
5613306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    BitstreamShow13Bits(stream, &code);
5623306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
5633306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (code == 0)
5643306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
5653306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        return VLC_CODE_ERROR;
5663306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
5673306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    else if (code >= 4096)
5683306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
5693306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        PV_BitstreamFlushBits(stream, 1);
5703306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        return 0;
5713306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
5723306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (code >= 16)
5733306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
5743306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        PV_BitstreamFlushBits(stream, PV_MCBPCtab[code >> 4].len);
5753306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        return PV_MCBPCtab[code >> 4].val;
5763306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
5773306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    else
5783306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
5793306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        PV_BitstreamFlushBits(stream, PV_MCBPCtab1[code - 8].len);
5803306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        return PV_MCBPCtab1[code - 8].val;
5813306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
5823306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong}
5833306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#endif
5843306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/***********************************************************CommentBegin******
5853306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*       3/30/2000 : initial modification to the new PV-Decoder Lib
5863306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*                           format and the change of error-handling method.
5873306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*       4/16/2001 : removed status checking for PV_BitstreamFlushBits
5883306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong***********************************************************CommentEnd********/
5893306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
5903306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dongint PV_VlcDecCBPY(BitstreamDecVideo *stream, int intra)
5913306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong{
5923306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    int CBPY = 0;
5933306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    uint code;
5943306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
5953306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    BitstreamShowBits16(stream, 6, &code);
5963306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
5973306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
5983306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (code < 2)
5993306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
6003306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        return -1;
6013306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
6023306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    else if (code >= 48)
6033306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
6043306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        PV_BitstreamFlushBits(stream, 2);
6053306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        CBPY = 15;
6063306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
6073306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    else
6083306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
6093306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        PV_BitstreamFlushBits(stream, PV_CBPYtab[code].len);
6103306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        CBPY = PV_CBPYtab[code].val;
6113306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
6123306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
6133306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (intra == 0) CBPY = 15 - CBPY;
6143306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    CBPY = CBPY & 15;
6153306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    return CBPY;
6163306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong}
6173306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
6183306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
6193306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/***********************************************************CommentBegin******
6203306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*       3/31/2000 : initial modification to the new PV-Decoder Lib format.
6213306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*
6223306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*       8/23/2000 : optimize the function by removing unnecessary BitstreamShowBits()
6233306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*                       function calls.
6243306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*
6253306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*       9/6/2000 : change the API to check for end-of-buffer for proper
6263306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*                           termination of decoding process.
6273306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong***********************************************************CommentEnd********/
6283306cfee3bf38ab207a0504e49c2d492bb73ffbfJames DongPV_STATUS PV_VlcDecIntraDCPredSize(BitstreamDecVideo *stream, int compnum, uint *DC_size)
6293306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong{
6303306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    PV_STATUS status = PV_FAIL;      /*  07/09/01 */
6313306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    uint  code;
6323306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
6333306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    *DC_size = 0;
6343306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (compnum < 4)  /* luminance block */
6353306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
6363306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
6373306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        BitstreamShowBits16(stream, 11, &code);
6383306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
6393306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (code == 1)
6403306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
6413306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            *DC_size = 12;
6423306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            PV_BitstreamFlushBits(stream, 11);
6433306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            return PV_SUCCESS;
6443306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
6453306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        code >>= 1;
6463306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (code == 1)
6473306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
6483306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            *DC_size = 11;
6493306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            PV_BitstreamFlushBits(stream, 10);
6503306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            return PV_SUCCESS;
6513306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
6523306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        code >>= 1;
6533306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (code == 1)
6543306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
6553306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            *DC_size = 10;
6563306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            PV_BitstreamFlushBits(stream, 9);
6573306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            return PV_SUCCESS;
6583306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
6593306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
6603306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        code >>= 1;
6613306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (code == 1)
6623306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
6633306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            *DC_size = 9;
6643306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            PV_BitstreamFlushBits(stream, 8);
6653306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            return PV_SUCCESS;
6663306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
6673306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
6683306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        code >>= 1;
6693306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (code == 1)
6703306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
6713306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            *DC_size = 8;
6723306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            PV_BitstreamFlushBits(stream, 7);
6733306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            return PV_SUCCESS;
6743306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
6753306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
6763306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        code >>= 1;
6773306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (code == 1)
6783306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
6793306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            *DC_size = 7;
6803306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            PV_BitstreamFlushBits(stream, 6);
6813306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            return PV_SUCCESS;
6823306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
6833306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
6843306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        code >>= 1;
6853306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (code == 1)
6863306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
6873306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            *DC_size = 6;
6883306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            PV_BitstreamFlushBits(stream, 5);
6893306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            return PV_SUCCESS;
6903306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
6913306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
6923306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        code >>= 1;
6933306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (code == 1)
6943306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
6953306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            *DC_size = 5;
6963306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            PV_BitstreamFlushBits(stream, 4);
6973306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            return PV_SUCCESS;
6983306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
6993306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
7003306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        code >>= 1;
7013306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (code == 1)
7023306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
7033306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            *DC_size = 4;
7043306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            PV_BitstreamFlushBits(stream, 3);
7053306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            return PV_SUCCESS;
7063306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
7073306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        else if (code == 2)
7083306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
7093306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            *DC_size = 3;
7103306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            PV_BitstreamFlushBits(stream, 3);
7113306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            return PV_SUCCESS;
7123306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
7133306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        else if (code == 3)
7143306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
7153306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            *DC_size = 0;
7163306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            PV_BitstreamFlushBits(stream, 3);
7173306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            return PV_SUCCESS;
7183306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
7193306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
7203306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        code >>= 1;
7213306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (code == 2)
7223306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
7233306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            *DC_size = 2;
7243306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            PV_BitstreamFlushBits(stream, 2);
7253306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            return PV_SUCCESS;
7263306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
7273306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        else if (code == 3)
7283306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
7293306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            *DC_size = 1;
7303306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            PV_BitstreamFlushBits(stream, 2);
7313306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            return PV_SUCCESS;
7323306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
7333306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
7343306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    else /* chrominance block */
7353306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
7363306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
7373306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        BitstreamShow13Bits(stream, &code);
7383306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        code >>= 1;
7393306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (code == 1)
7403306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
7413306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            *DC_size = 12;
7423306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            PV_BitstreamFlushBits(stream, 12);
7433306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            return PV_SUCCESS;
7443306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
7453306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
7463306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        code >>= 1;
7473306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (code == 1)
7483306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
7493306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            *DC_size = 11;
7503306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            PV_BitstreamFlushBits(stream, 11);
7513306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            return PV_SUCCESS;
7523306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
7533306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
7543306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        code >>= 1;
7553306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (code == 1)
7563306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
7573306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            *DC_size = 10;
7583306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            PV_BitstreamFlushBits(stream, 10);
7593306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            return PV_SUCCESS;
7603306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
7613306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
7623306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        code >>= 1;
7633306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (code == 1)
7643306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
7653306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            *DC_size = 9;
7663306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            PV_BitstreamFlushBits(stream, 9);
7673306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            return PV_SUCCESS;
7683306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
7693306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
7703306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        code >>= 1;
7713306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (code == 1)
7723306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
7733306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            *DC_size = 8;
7743306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            PV_BitstreamFlushBits(stream, 8);
7753306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            return PV_SUCCESS;
7763306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
7773306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
7783306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        code >>= 1;
7793306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (code == 1)
7803306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
7813306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            *DC_size = 7;
7823306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            PV_BitstreamFlushBits(stream, 7);
7833306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            return PV_SUCCESS;
7843306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
7853306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
7863306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        code >>= 1;
7873306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (code == 1)
7883306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
7893306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            *DC_size = 6;
7903306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            PV_BitstreamFlushBits(stream, 6);
7913306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            return PV_SUCCESS;
7923306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
7933306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
7943306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        code >>= 1;
7953306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (code == 1)
7963306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
7973306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            *DC_size = 5;
7983306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            PV_BitstreamFlushBits(stream, 5);
7993306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            return PV_SUCCESS;
8003306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
8013306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
8023306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        code >>= 1;
8033306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (code == 1)
8043306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
8053306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            *DC_size = 4;
8063306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            PV_BitstreamFlushBits(stream, 4);
8073306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            return PV_SUCCESS;
8083306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
8093306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
8103306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        code >>= 1;
8113306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (code == 1)
8123306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
8133306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            *DC_size = 3;
8143306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            PV_BitstreamFlushBits(stream, 3);
8153306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            return PV_SUCCESS;
8163306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
8173306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
8183306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        code >>= 1;
8193306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
8203306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            *DC_size = (int)(3 - code);
8213306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            PV_BitstreamFlushBits(stream, 2);
8223306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            return PV_SUCCESS;
8233306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
8243306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
8253306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
8263306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    return status;
8273306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong}
8283306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
8293306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/***********************************************************CommentBegin******
8303306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*
8313306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*
8323306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*       3/30/2000 : initial modification to the new PV-Decoder Lib
8333306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*                           format and the change of error-handling method.
8343306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong*
8353306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong***********************************************************CommentEnd********/
8363306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
8373306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
8383306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
8393306cfee3bf38ab207a0504e49c2d492bb73ffbfJames DongPV_STATUS VlcDecTCOEFIntra(BitstreamDecVideo *stream, Tcoef *pTcoef)
8403306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong{
8413306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    uint code;
8423306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    const VLCtab2 *tab;
8433306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
8443306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    BitstreamShow13Bits(stream, &code);
8453306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
8463306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    /* 10/17/2000, perform a little bit better on ARM by putting the whole function in VlcDecTCOEFFIntra */
8473306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    /*  if(GetTcoeffIntra(code,pTcoef,&tab,stream)!=PV_SUCCESS) return status;*/
8483306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (code >= 1024)
8493306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
8503306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        tab = &PV_DCT3Dtab3[(code >> 6) - 16];
8513306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
8523306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    else
8533306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
8543306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (code >= 256)
8553306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
8563306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            tab = &PV_DCT3Dtab4[(code >> 3) - 32];
8573306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
8583306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        else
8593306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
8603306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            if (code >= 16)
8613306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
8623306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                tab = &PV_DCT3Dtab5[(code>>1) - 8];
8633306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
8643306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            else
8653306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
8663306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                return PV_FAIL;
8673306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
8683306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
8693306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
8703306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
8713306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    PV_BitstreamFlushBits(stream, tab->len + 1);
8723306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    pTcoef->sign = (code >> (12 - tab->len)) & 1;
8733306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    pTcoef->run = (uint) tab->run; //(tab->val >> 8) & 255;
8743306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    pTcoef->level = (int) tab->level; //tab->val & 255;
8753306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    pTcoef->last = (uint) tab->last; //(tab->val >> 16) & 1;
8763306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
8773306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
8783306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    /* the following is modified for 3-mode escape -- boon */
8793306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (tab->level != 0xFF)
8803306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
8813306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        return PV_SUCCESS;
8823306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
8833306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
8843306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    //if (((tab->run<<8)|(tab->level)|(tab->last<<16)) == VLC_ESCAPE_CODE)
8853306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
8863306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (!pTcoef->sign)
8873306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
8883306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        /* first escape mode. level is offset */
8893306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        BitstreamShow13Bits(stream, &code);
8903306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
8913306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        /* 10/17/2000, perform a little bit better on ARM by putting the whole function in VlcDecTCOEFFIntra */
8923306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        /*          if(GetTcoeffIntra(code,pTcoef,&tab,stream)!=PV_SUCCESS) return status;*/
8933306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (code >= 1024)
8943306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
8953306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            tab = &PV_DCT3Dtab3[(code >> 6) - 16];
8963306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
8973306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        else
8983306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
8993306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            if (code >= 256)
9003306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
9013306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                tab = &PV_DCT3Dtab4[(code >> 3) - 32];
9023306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
9033306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            else
9043306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
9053306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                if (code >= 16)
9063306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                {
9073306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    tab = &PV_DCT3Dtab5[(code>>1) - 8];
9083306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                }
9093306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                else
9103306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                {
9113306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    return PV_FAIL;
9123306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                }
9133306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
9143306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
9153306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
9163306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        PV_BitstreamFlushBits(stream, tab->len + 1);
9173306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
9183306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        /* sign bit */
9193306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        pTcoef->sign = (code >> (12 - tab->len)) & 1;
9203306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        pTcoef->run = (uint)tab->run; //(tab->val >> 8) & 255;
9213306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        pTcoef->level = (int)tab->level; //tab->val & 255;
9223306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        pTcoef->last = (uint)tab->last; //(tab->val >> 16) & 1;
9233306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
9243306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
9253306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        /* need to add back the max level */
9263306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if ((pTcoef->last == 0 && pTcoef->run > 14) || (pTcoef->last == 1 && pTcoef->run > 20))
9273306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
9283306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            return PV_FAIL;
9293306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
9303306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        pTcoef->level = pTcoef->level + intra_max_level[pTcoef->last][pTcoef->run];
9313306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
9323306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
9333306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
9343306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    else
9353306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
9363306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        uint run_offset;
9373306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        run_offset = BitstreamRead1Bits_INLINE(stream);
9383306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
9393306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (!run_offset)
9403306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
9413306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            /* second escape mode. run is offset */
9423306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            BitstreamShow13Bits(stream, &code);
9433306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
9443306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            /* 10/17/2000, perform a little bit better on ARM by putting the whole function in VlcDecTCOEFFIntra */
9453306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            /*              if(GetTcoeffIntra(code,pTcoef,&tab,stream)!=PV_SUCCESS) return status;*/
9463306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            if (code >= 1024)
9473306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
9483306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                tab = &PV_DCT3Dtab3[(code >> 6) - 16];
9493306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
9503306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            else
9513306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
9523306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                if (code >= 256)
9533306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                {
9543306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    tab = &PV_DCT3Dtab4[(code >> 3) - 32];
9553306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                }
9563306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                else
9573306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                {
9583306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    if (code >= 16)
9593306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    {
9603306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        tab = &PV_DCT3Dtab5[(code>>1) - 8];
9613306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    }
9623306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    else
9633306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    {
9643306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        return PV_FAIL;
9653306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    }
9663306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                }
9673306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
9683306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
9693306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            PV_BitstreamFlushBits(stream, tab->len + 1);
9703306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            /* sign bit */
9713306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            pTcoef->sign = (code >> (12 - tab->len)) & 1;
9723306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            pTcoef->run = (uint)tab->run; //(tab->val >> 8) & 255;
9733306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            pTcoef->level = (int)tab->level; //tab->val & 255;
9743306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            pTcoef->last = (uint)tab->last; //(tab->val >> 16) & 1;
9753306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
9763306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
9773306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
9783306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            /* need to add back the max run */
9793306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            if (pTcoef->last)
9803306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
9813306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                if (pTcoef->level > 8)
9823306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                {
9833306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    return PV_FAIL;
9843306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                }
9853306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                pTcoef->run = pTcoef->run + intra_max_run1[pTcoef->level] + 1;
9863306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
9873306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            else
9883306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
9893306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                if (pTcoef->level > 27)
9903306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                {
9913306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    return PV_FAIL;
9923306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                }
9933306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                pTcoef->run = pTcoef->run + intra_max_run0[pTcoef->level] + 1;
9943306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
9953306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
9963306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
9973306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
9983306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        else
9993306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
10003306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
10013306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            code = BitstreamReadBits16_INLINE(stream, 8);
10023306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            pTcoef->last = code >> 7;
10033306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            pTcoef->run = (code >> 1) & 0x3F;
10043306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            pTcoef->level = (int)(BitstreamReadBits16_INLINE(stream, 13) >> 1);
10053306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
10063306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            if (pTcoef->level >= 2048)
10073306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
10083306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                pTcoef->sign = 1;
10093306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                pTcoef->level = 4096 - pTcoef->level;
10103306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
10113306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            else
10123306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
10133306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                pTcoef->sign = 0;
10143306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
10153306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        } /* flc */
10163306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
10173306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
10183306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    return PV_SUCCESS;
10193306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
10203306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong} /* VlcDecTCOEFIntra */
10213306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
10223306cfee3bf38ab207a0504e49c2d492bb73ffbfJames DongPV_STATUS VlcDecTCOEFInter(BitstreamDecVideo *stream, Tcoef *pTcoef)
10233306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong{
10243306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    uint code;
10253306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    const VLCtab2 *tab;
10263306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
10273306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    BitstreamShow13Bits(stream, &code);
10283306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
10293306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    /* 10/17/2000, perform a little bit better on ARM by putting the whole function in VlcDecTCOEFFInter */
10303306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    /*  if(GetTcoeffInter(code,pTcoef,&tab,stream)!=PV_SUCCESS) return status;*/
10313306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (code >= 1024)
10323306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
10333306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        tab = &PV_DCT3Dtab0[(code >> 6) - 16];
10343306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
10353306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    else
10363306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
10373306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (code >= 256)
10383306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
10393306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            tab = &PV_DCT3Dtab1[(code >> 3) - 32];
10403306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
10413306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        else
10423306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
10433306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            if (code >= 16)
10443306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
10453306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                tab = &PV_DCT3Dtab2[(code>>1) - 8];
10463306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
10473306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            else
10483306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
10493306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                return PV_FAIL;
10503306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
10513306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
10523306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
10533306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    PV_BitstreamFlushBits(stream, tab->len + 1);
10543306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    pTcoef->sign = (code >> (12 - tab->len)) & 1;
10553306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    pTcoef->run = (uint)tab->run;     //(tab->val >> 4) & 255;
10563306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    pTcoef->level = (int)tab->level; //tab->val & 15;
10573306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    pTcoef->last = (uint)tab->last;   //(tab->val >> 12) & 1;
10583306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
10593306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    /* the following is modified for 3-mode escape -- boon */
10603306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (tab->run != 0xBF)
10613306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
10623306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        return PV_SUCCESS;
10633306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
10643306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    //if (((tab->run<<4)|(tab->level)|(tab->last<<12)) == VLC_ESCAPE_CODE)
10653306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
10663306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
10673306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (!pTcoef->sign)
10683306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
10693306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        /* first escape mode. level is offset */
10703306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        BitstreamShow13Bits(stream, &code);
10713306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
10723306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        /* 10/17/2000, perform a little bit better on ARM by putting the whole function in VlcDecTCOEFFInter */
10733306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        /*          if(GetTcoeffInter(code,pTcoef,&tab,stream)!=PV_SUCCESS) return status;*/
10743306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (code >= 1024)
10753306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
10763306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            tab = &PV_DCT3Dtab0[(code >> 6) - 16];
10773306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
10783306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        else
10793306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
10803306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            if (code >= 256)
10813306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
10823306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                tab = &PV_DCT3Dtab1[(code >> 3) - 32];
10833306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
10843306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            else
10853306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
10863306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                if (code >= 16)
10873306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                {
10883306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    tab = &PV_DCT3Dtab2[(code>>1) - 8];
10893306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                }
10903306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                else
10913306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                {
10923306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    return PV_FAIL;
10933306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                }
10943306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
10953306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
10963306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        PV_BitstreamFlushBits(stream, tab->len + 1);
10973306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        pTcoef->sign = (code >> (12 - tab->len)) & 1;
10983306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        pTcoef->run = (uint)tab->run;     //(tab->val >> 4) & 255;
10993306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        pTcoef->level = (int)tab->level; //tab->val & 15;
11003306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        pTcoef->last = (uint)tab->last;   //(tab->val >> 12) & 1;
11013306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
11023306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        /* need to add back the max level */
11033306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if ((pTcoef->last == 0 && pTcoef->run > 26) || (pTcoef->last == 1 && pTcoef->run > 40))
11043306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
11053306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            return PV_FAIL;
11063306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
11073306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        pTcoef->level = pTcoef->level + inter_max_level[pTcoef->last][pTcoef->run];
11083306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
11093306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    else
11103306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
11113306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        uint run_offset;
11123306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        run_offset = BitstreamRead1Bits_INLINE(stream);
11133306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
11143306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (!run_offset)
11153306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
11163306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            /* second escape mode. run is offset */
11173306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            BitstreamShow13Bits(stream, &code);
11183306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
11193306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            /* 10/17/2000, perform a little bit better on ARM by putting the whole function in VlcDecTCOEFFInter */
11203306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            /*if(GetTcoeffInter(code,pTcoef,&tab,stream)!=PV_SUCCESS) return status;*/
11213306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            if (code >= 1024)
11223306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
11233306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                tab = &PV_DCT3Dtab0[(code >> 6) - 16];
11243306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
11253306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            else
11263306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
11273306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                if (code >= 256)
11283306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                {
11293306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    tab = &PV_DCT3Dtab1[(code >> 3) - 32];
11303306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                }
11313306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                else
11323306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                {
11333306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    if (code >= 16)
11343306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    {
11353306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        tab = &PV_DCT3Dtab2[(code>>1) - 8];
11363306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    }
11373306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    else
11383306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    {
11393306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                        return PV_FAIL;
11403306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    }
11413306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                }
11423306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
11433306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            PV_BitstreamFlushBits(stream, tab->len + 1);
11443306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            pTcoef->sign = (code >> (12 - tab->len)) & 1;
11453306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            pTcoef->run = (uint)tab->run;     //(tab->val >> 4) & 255;
11463306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            pTcoef->level = (int)tab->level; //tab->val & 15;
11473306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            pTcoef->last = (uint)tab->last;   //(tab->val >> 12) & 1;
11483306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
11493306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            /* need to add back the max run */
11503306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            if (pTcoef->last)
11513306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
11523306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                if (pTcoef->level > 3)
11533306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                {
11543306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    return PV_FAIL;
11553306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                }
11563306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                pTcoef->run = pTcoef->run + inter_max_run1[pTcoef->level] + 1;
11573306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
11583306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            else
11593306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
11603306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                if (pTcoef->level > 12)
11613306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                {
11623306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                    return PV_FAIL;
11633306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                }
11643306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                pTcoef->run = pTcoef->run + inter_max_run0[pTcoef->level] + 1;
11653306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
11663306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
11673306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        else
11683306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
11693306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
11703306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            code = BitstreamReadBits16_INLINE(stream, 8);
11713306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            pTcoef->last = code >> 7;
11723306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            pTcoef->run = (code >> 1) & 0x3F;
11733306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            pTcoef->level = (int)(BitstreamReadBits16_INLINE(stream, 13) >> 1);
11743306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
11753306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
11763306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
11773306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            if (pTcoef->level >= 2048)
11783306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
11793306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                pTcoef->sign = 1;
11803306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                pTcoef->level = 4096 - pTcoef->level;
11813306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
11823306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            else
11833306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            {
11843306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                pTcoef->sign = 0;
11853306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            }
11863306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        } /* flc */
11873306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
11883306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
11893306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    return PV_SUCCESS;
11903306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
11913306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong} /* VlcDecTCOEFInter */
11923306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
11933306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong/*=======================================================
11943306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    Function:   VlcDecTCOEFShortHeader()
11953306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    Date    :   04/27/99
11963306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    Purpose :   New function used in decoding of video planes
11973306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                with short header
11983306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    Modified:   05/23/2000
11993306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong                for new decoder structure.
12003306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong=========================================================*/
12013306cfee3bf38ab207a0504e49c2d492bb73ffbfJames DongPV_STATUS VlcDecTCOEFShortHeader(BitstreamDecVideo *stream, Tcoef *pTcoef/*, int intra*/)
12023306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong{
12033306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    uint code;
12043306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    const VLCtab2 *tab;
12053306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
12063306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    BitstreamShow13Bits(stream, &code);
12073306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
12083306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    /*intra = 0;*/
12093306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
12103306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (code >= 1024) tab = &PV_DCT3Dtab0[(code >> 6) - 16];
12113306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    else
12123306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
12133306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (code >= 256) tab = &PV_DCT3Dtab1[(code >> 3) - 32];
12143306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        else
12153306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
12163306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            if (code >= 16) tab = &PV_DCT3Dtab2[(code>>1) - 8];
12173306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            else return PV_FAIL;
12183306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
12193306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
12203306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
12213306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    PV_BitstreamFlushBits(stream, tab->len + 1);
12223306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    pTcoef->sign = (code >> (12 - tab->len)) & 1;
12233306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    pTcoef->run = (uint)tab->run;//(tab->val >> 4) & 255;
12243306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    pTcoef->level = (int)tab->level;//tab->val & 15;
12253306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    pTcoef->last = (uint)tab->last;//(tab->val >> 12) & 1;
12263306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
12273306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    /* the following is modified for 3-mode escape -- boon */
12283306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (((tab->run << 4) | (tab->level) | (tab->last << 12)) != VLC_ESCAPE_CODE)    /* ESCAPE */
12293306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
12303306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        return PV_SUCCESS;
12313306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
12323306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
12333306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
12343306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    /* escape mode 4 - H.263 type */
12353306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    pTcoef->last = pTcoef->sign; /* Last */
12363306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    pTcoef->run = BitstreamReadBits16_INLINE(stream, 6); /* Run */
12373306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    pTcoef->level = (int) BitstreamReadBits16_INLINE(stream, 8); /* Level */
12383306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
12393306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (pTcoef->level == 0 || pTcoef->level == 128)
12403306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
12413306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        return PV_FAIL;
12423306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
12433306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
12443306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (pTcoef->level > 128)
12453306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
12463306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        pTcoef->sign = 1;
12473306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        pTcoef->level = 256 - pTcoef->level;
12483306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
12493306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    else
12503306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
12513306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        pTcoef->sign = 0;
12523306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
12533306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
12543306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
12553306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
12563306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    return PV_SUCCESS;
12573306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
12583306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong}   /* VlcDecTCOEFShortHeader */
12593306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
12603306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong#ifdef PV_ANNEX_IJKT_SUPPORT
12613306cfee3bf38ab207a0504e49c2d492bb73ffbfJames DongPV_STATUS VlcDecTCOEFShortHeader_AnnexI(BitstreamDecVideo *stream, Tcoef *pTcoef/*, int intra*/)
12623306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong{
12633306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    uint code;
12643306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    const VLCtab2 *tab;
12653306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
12663306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    BitstreamShow13Bits(stream, &code);
12673306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
12683306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    /*intra = 0;*/
12693306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
12703306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (code >= 1024) tab = &PV_DCT3Dtab6[(code >> 6) - 16];
12713306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    else
12723306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
12733306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (code >= 256) tab = &PV_DCT3Dtab7[(code >> 3) - 32];
12743306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        else
12753306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
12763306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            if (code >= 16) tab = &PV_DCT3Dtab8[(code>>1) - 8];
12773306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            else return PV_FAIL;
12783306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
12793306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
12803306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
12813306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    PV_BitstreamFlushBits(stream, tab->len + 1);
12823306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    pTcoef->sign = (code >> (12 - tab->len)) & 1;
12833306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    pTcoef->run = (uint)tab->run;//(tab->val >> 4) & 255;
12843306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    pTcoef->level = (int)tab->level;//tab->val & 15;
12853306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    pTcoef->last = (uint)tab->last;//(tab->val >> 12) & 1;
12863306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
12873306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    /* the following is modified for 3-mode escape -- boon */
12883306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (((tab->run << 6) | (tab->level) | (tab->last << 12)) != VLC_ESCAPE_CODE)    /* ESCAPE */
12893306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
12903306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        return PV_SUCCESS;
12913306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
12923306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    /* escape mode 4 - H.263 type */
12933306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    pTcoef->last = pTcoef->sign; /* Last */
12943306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    pTcoef->run = BitstreamReadBits16(stream, 6); /* Run */
12953306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    pTcoef->level = (int) BitstreamReadBits16(stream, 8); /* Level */
12963306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
12973306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (pTcoef->level == 0 || pTcoef->level == 128)
12983306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
12993306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        return PV_FAIL;
13003306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
13013306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
13023306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
13033306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (pTcoef->level > 128)
13043306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
13053306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        pTcoef->sign = 1;
13063306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        pTcoef->level = 256 - pTcoef->level;
13073306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
13083306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    else pTcoef->sign = 0;
13093306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
13103306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
13113306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
13123306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    return PV_SUCCESS;
13133306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
13143306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong}   /* VlcDecTCOEFShortHeader_AnnexI */
13153306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
13163306cfee3bf38ab207a0504e49c2d492bb73ffbfJames DongPV_STATUS VlcDecTCOEFShortHeader_AnnexT(BitstreamDecVideo *stream, Tcoef *pTcoef/*, int intra*/)
13173306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong{
13183306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    uint code;
13193306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    const VLCtab2 *tab;
13203306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
13213306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    BitstreamShow13Bits(stream, &code);
13223306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
13233306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    /*intra = 0;*/
13243306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
13253306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (code >= 1024) tab = &PV_DCT3Dtab0[(code >> 6) - 16];
13263306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    else
13273306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
13283306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (code >= 256) tab = &PV_DCT3Dtab1[(code >> 3) - 32];
13293306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        else
13303306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        {
13313306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            if (code >= 16) tab = &PV_DCT3Dtab2[(code>>1) - 8];
13323306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong            else return PV_FAIL;
13333306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        }
13343306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
13353306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
13363306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    PV_BitstreamFlushBits(stream, tab->len + 1);
13373306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    pTcoef->sign = (code >> (12 - tab->len)) & 1;
13383306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    pTcoef->run = (uint)tab->run;//(tab->val >> 4) & 255;
13393306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    pTcoef->level = (int)tab->level;//tab->val & 15;
13403306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    pTcoef->last = (uint)tab->last;//(tab->val >> 12) & 1;
13413306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
13423306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    /* the following is modified for 3-mode escape --  */
13433306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (((tab->run << 4) | (tab->level) | (tab->last << 12)) != VLC_ESCAPE_CODE)    /* ESCAPE */
13443306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
13453306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        return PV_SUCCESS;
13463306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
13473306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    /* escape mode 4 - H.263 type */
13483306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    pTcoef->last = pTcoef->sign; /* Last */
13493306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    pTcoef->run = BitstreamReadBits16(stream, 6); /* Run */
13503306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    pTcoef->level = (int) BitstreamReadBits16(stream, 8); /* Level */
13513306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
13523306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (pTcoef->level == 0)
13533306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
13543306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        return PV_FAIL;
13553306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
13563306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
13573306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (pTcoef->level >= 128)
13583306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
13593306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        pTcoef->sign = 1;
13603306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        pTcoef->level = 256 - pTcoef->level;
13613306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
13623306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    else
13633306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
13643306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        pTcoef->sign = 0;
13653306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    }
13663306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
13673306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    if (pTcoef->level == 128)
13683306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong    {
13693306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        code = BitstreamReadBits16(stream, 11);        /* ANNEX_T */
13703306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong
13713306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        code = (code >> 6 & 0x1F) | (code << 5 & 0x7ff);
13723306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong        if (code > 1024)
13733306cfee3bf38ab207a0504e49c2d492bb73ffbfJames Dong<