• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*!
2  * \copy
3  *     Copyright (c)  2013, Cisco Systems
4  *     All rights reserved.
5  *
6  *     Redistribution and use in source and binary forms, with or without
7  *     modification, are permitted provided that the following conditions
8  *     are met:
9  *
10  *        * Redistributions of source code must retain the above copyright
11  *          notice, this list of conditions and the following disclaimer.
12  *
13  *        * Redistributions in binary form must reproduce the above copyright
14  *          notice, this list of conditions and the following disclaimer in
15  *          the documentation and/or other materials provided with the
16  *          distribution.
17  *
18  *     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  *     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  *     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  *     FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22  *     COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23  *     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24  *     BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  *     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26  *     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  *     LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28  *     ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  *     POSSIBILITY OF SUCH DAMAGE.
30  *
31  */
32 
33 #ifndef WELS_VLC_ENCODER_H__
34 #define WELS_VLC_ENCODER_H__
35 
36 #include "svc_enc_golomb.h"
37 
38 /************************************************************************/
39 /* VLC FOR WELS ENCODER                                                 */
40 /************************************************************************/
41 
42 namespace WelsEnc {
43 
44 //g_kuiVlcCoeffToken[uiNc][total-coeff][trailing-ones][0--value, 1--bit count]
45 extern const uint8_t g_kuiVlcCoeffToken[5][17][4][2];
46 extern const uint8_t g_kuiVlcLevelPrefix[15][2];
47 //g_kuiVlcTotalZeros[tzVlcIndex][uiTotalZeros][0--value, 1--bit count]
48 extern const uint8_t g_kuiVlcTotalZeros[16][16][2];
49 extern const uint8_t g_kuiVlcTotalZerosChromaDc[4][4][2];
50 //add for mgs
51 extern const uint8_t g_kuiVlcTotalZerosChromaDc422[8][8][2];
52 //g_kuiVlcRunBefore[zeros-left][run-before][0--value, 1--bit count]
53 extern const uint8_t g_kuiVlcRunBefore[8][15][2];
54 extern const ALIGNED_DECLARE (uint8_t, g_kuiEncNcMapTable[18], 16);
55 
56 #define    CHROMA_DC_NC_OFFSET       17
57 
WriteTotalCoeffTrailingones(SBitStringAux * pBs,uint8_t uiNc,uint8_t uiTotalCoeff,uint8_t uiTrailingOnes)58 static inline int32_t WriteTotalCoeffTrailingones (SBitStringAux* pBs, uint8_t uiNc, uint8_t uiTotalCoeff,
59     uint8_t uiTrailingOnes) {
60 const uint8_t kuiNcIdx      = g_kuiEncNcMapTable[uiNc];
61 const uint8_t* kpCoeffToken = &g_kuiVlcCoeffToken[kuiNcIdx][uiTotalCoeff][uiTrailingOnes][0];
62 return BsWriteBits (pBs,  kpCoeffToken[1], kpCoeffToken[0]);
63 }
64 
WriteTotalcoeffTrailingonesChroma(SBitStringAux * pBs,uint8_t uiTotalCoeff,uint8_t uiTrailingOnes)65 static inline int32_t WriteTotalcoeffTrailingonesChroma (SBitStringAux* pBs, uint8_t uiTotalCoeff,
66     uint8_t uiTrailingOnes) {
67 const uint8_t* kpCoeffToken = &g_kuiVlcCoeffToken[4][uiTotalCoeff][uiTrailingOnes][0];
68 return BsWriteBits (pBs, kpCoeffToken[1], kpCoeffToken[0]);
69 }
70 
71 //kuiZeroCount = level_prefix;
WriteLevelPrefix(SBitStringAux * pBs,const uint32_t kuiZeroCount)72 static inline int32_t WriteLevelPrefix (SBitStringAux* pBs, const uint32_t kuiZeroCount) {
73 BsWriteBits (pBs, kuiZeroCount + 1, 1);
74 return 0;
75 }
76 
WriteTotalZeros(SBitStringAux * pBs,uint32_t uiTotalCoeff,uint32_t uiTotalZeros)77 static inline int32_t WriteTotalZeros (SBitStringAux* pBs, uint32_t uiTotalCoeff, uint32_t uiTotalZeros) {
78 const uint8_t* kpTotalZeros = &g_kuiVlcTotalZeros[uiTotalCoeff][uiTotalZeros][0];
79 return BsWriteBits (pBs, kpTotalZeros[1], kpTotalZeros[0]);
80 }
81 
WriteTotalZerosChromaDc(SBitStringAux * pBs,uint32_t uiTotalCoeff,uint32_t uiTotalZeros)82 static inline int32_t WriteTotalZerosChromaDc (SBitStringAux* pBs, uint32_t uiTotalCoeff, uint32_t uiTotalZeros) {
83 const uint8_t* kpTotalZerosChromaDc = &g_kuiVlcTotalZerosChromaDc[uiTotalCoeff][uiTotalZeros][0];
84 return BsWriteBits (pBs, kpTotalZerosChromaDc[1], kpTotalZerosChromaDc[0]);
85 }
86 
WriteRunBefore(SBitStringAux * pBs,uint8_t uiZeroLeft,uint8_t uiRunBefore)87 static inline int32_t WriteRunBefore (SBitStringAux* pBs, uint8_t uiZeroLeft, uint8_t uiRunBefore) {
88 const uint8_t* kpRunBefore = &g_kuiVlcRunBefore[uiZeroLeft][uiRunBefore][0];
89 return BsWriteBits (pBs, kpRunBefore[1], kpRunBefore[0]);
90 }
91 }
92 #endif
93