1/*
2 * Copyright (C) 2007-2008 ARM Limited
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17/**
18 *
19 * File Name:  omxVCM4P2_EncodeVLCZigzag_Inter.c
20 * OpenMAX DL: v1.0.2
21 * Revision:   9641
22 * Date:       Thursday, February 7, 2008
23 *
24 *
25 *
26 *
27 * Description:
28 * Contains modules for zigzag scanning and VLC encoding
29 * for inter block.
30 *
31 */
32
33#include "omxtypes.h"
34#include "armOMX.h"
35#include "omxVC.h"
36
37#include "armVC.h"
38#include "armCOMM_Bitstream.h"
39#include "armCOMM.h"
40#include "armVCM4P2_Huff_Tables_VLC.h"
41#include "armVCM4P2_ZigZag_Tables.h"
42
43
44
45/**
46 * Function:  omxVCM4P2_EncodeVLCZigzag_Inter   (6.2.4.5.3)
47 *
48 * Description:
49 * Performs classical zigzag scanning and VLC encoding for one inter block.
50 *
51 * Input Arguments:
52 *
53 *   ppBitStream - pointer to the pointer to the current byte in the bit
54 *            stream
55 *   pBitOffset - pointer to the bit position in the byte pointed by
56 *            *ppBitStream. Valid within 0 to 7
57 *   pQDctBlkCoef - pointer to the quantized DCT coefficient
58 *   pattern - block pattern which is used to decide whether this block is
59 *            encoded
60 *   shortVideoHeader - binary flag indicating presence of
61 *            short_video_header; escape modes 0-3 are used if
62 *            shortVideoHeader==0, and escape mode 4 is used when
63 *            shortVideoHeader==1.
64 *
65 * Output Arguments:
66 *
67 *   ppBitStream - *ppBitStream is updated after the block is encoded so that
68 *            it points to the current byte in the bit stream buffer.
69 *   pBitOffset - *pBitOffset is updated so that it points to the current bit
70 *            position in the byte pointed by *ppBitStream.
71 *
72 * Return Value:
73 *
74 *    OMX_Sts_NoErr - no error
75 *    OMX_Sts_BadArgErr - Bad arguments
76 *    -    At least one of the pointers: is NULL: ppBitStream, *ppBitStream,
77 *              pBitOffset, pQDctBlkCoef
78 *    -   *pBitOffset < 0, or *pBitOffset >7.
79 *
80 */
81OMXResult omxVCM4P2_EncodeVLCZigzag_Inter(
82     OMX_U8 **ppBitStream,
83     OMX_INT * pBitOffset,
84     const OMX_S16 *pQDctBlkCoef,
85     OMX_U8 pattern,
86	 OMX_INT shortVideoHeader
87)
88{
89    OMX_U8 start = 0;
90    const OMX_U8  *pZigzagTable = armVCM4P2_aClassicalZigzagScan;
91
92    /* Argument error checks */
93    armRetArgErrIf(ppBitStream == NULL, OMX_Sts_BadArgErr);
94    armRetArgErrIf(*ppBitStream == NULL, OMX_Sts_BadArgErr);
95    armRetArgErrIf(pBitOffset == NULL, OMX_Sts_BadArgErr);
96    armRetArgErrIf(pQDctBlkCoef == NULL, OMX_Sts_BadArgErr);
97    armRetArgErrIf((*pBitOffset < 0) || (*pBitOffset >7), OMX_Sts_BadArgErr);
98
99    if (pattern)
100    {
101        armVCM4P2_PutVLCBits (
102              ppBitStream,
103              pBitOffset,
104              pQDctBlkCoef,
105              shortVideoHeader,
106              start,
107              26,
108              40,
109              10,
110              1,
111              armVCM4P2_InterL0RunIdx,
112              armVCM4P2_InterVlcL0,
113			  armVCM4P2_InterL1RunIdx,
114              armVCM4P2_InterVlcL1,
115              armVCM4P2_InterL0LMAX,
116              armVCM4P2_InterL1LMAX,
117              armVCM4P2_InterL0RMAX,
118              armVCM4P2_InterL1RMAX,
119              pZigzagTable
120        );
121    } /* Pattern check ends*/
122
123    return OMX_Sts_NoErr;
124
125}
126
127/* End of file */
128