1 /*
2  * Copyright © 2014 Intel Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sub license, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the
13  * next paragraph) shall be included in all copies or substantial portions
14  * of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  * Authors:
25  *     Zhao Yakui <yakui.zhao@intel.com>
26  *
27  */
28 
29 /*
30  * Copyright (c) 2010, The WebM Project authors. All rights reserved.
31  *
32  * An additional intellectual property rights grant can be found
33  * in the file LIBVPX_PATENTS.  All contributing project authors may
34  * be found in the LIBVPX_AUTHORS file.
35  *
36  * Redistribution and use in source and binary forms, with or without
37  * modification, are permitted provided that the following conditions are met:
38 
39  * Redistributions of source code must retain the above copyright
40  * notice, this list of conditions and the following disclaimer.
41  *
42  * Redistributions in binary form must reproduce the above copyright
43  * notice, this list of conditions and the following disclaimer in
44  * the documentation and/or other materials provided with the distribution.
45 
46  * Neither the name of Google, nor the WebM Project, nor the names
47  * of its contributors may be used to endorse or promote products
48  * derived from this software without specific prior written permission.
49  *
50  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61  *
62  */
63 
64 #ifndef __INTEL_HOSTVLD_VP9_ENGINE_H__
65 #define __INTEL_HOSTVLD_VP9_ENGINE_H__
66 
67 #include "intel_hybrid_hostvld_vp9_internal.h"
68 
69 #define BYTE_BITS               8
70 #define BAC_ENG_MAX_RANGE       255
71 #define BAC_ENG_VALUE_BITS      ( BYTE_BITS * sizeof(INTEL_HOSTVLD_VP9_BAC_VALUE) )
72 #define BAC_ENG_MASSIVE_BITS    0x40000000
73 #define BAC_ENG_VALUE_HEAD_RSRV BYTE_BITS
74 #define BAC_ENG_VALUE_TAIL_RSRV BYTE_BITS
75 #define BAC_ENG_PROB_BITS       8
76 #define BAC_ENG_PROB_RANGE      ( 1 << BAC_ENG_PROB_BITS )
77 #define BAC_ENG_PROB_HALF       ( 1 << (BAC_ENG_PROB_BITS-1) )
78 
79 // Read 16-bit or Read 8-bit for the last even byte to fill BAC engine
80 #define INTEL_HOSTVLD_VP9_BACENGINE_FILL()           \
81 do                                                      \
82 { \
83     if (iCount < BAC_ENG_VALUE_HEAD_RSRV)                                     \
84     {                                                   \
85 	if ((pBacEngine->pBufEnd - pBacEngine->pBuf) >= 2 ) { \
86 		register UINT16 ui16RegOp = *((PUINT16)(pBacEngine->pBuf));                     \
87 		BacValue |= (ui16RegOp & 0xFF) << (BAC_ENG_VALUE_BITS - BYTE_BITS - iCount);    \
88 		BacValue |= (ui16RegOp & 0xFF00) << (BYTE_BITS - iCount);                       \
89 		pBacEngine->pBuf += 2;                          \
90 		iCount += (BYTE_BITS << 1);                     \
91 	} else { \
92 		register UINT8 ui8RegOp = *((PUINT8)(pBacEngine->pBuf));                     \
93 		BacValue |= (ui8RegOp & 0xFF) << (BAC_ENG_VALUE_BITS - BYTE_BITS - iCount);    \
94 		pBacEngine->pBuf += 1;                          \
95 		iCount += BAC_ENG_MASSIVE_BITS;                     \
96 	} \
97     }                                                   \
98 } while (0)
99 
100 extern const UCHAR g_Vp9NormTable[BAC_ENG_MAX_RANGE+1];
101 
102 INT Intel_HostvldVp9_BacEngineInit(
103     PINTEL_HOSTVLD_VP9_BAC_ENGINE pBacEngine,
104     PUCHAR                           pBuf,
105     DWORD                            dwBufSize);
106 
107 INT Intel_HostvldVp9_BacEngineReadBit(
108     PINTEL_HOSTVLD_VP9_BAC_ENGINE pBacEngine,
109     INT                              iProb);
110 
111 INT Intel_HostvldVp9_BacEngineReadSingleBit(
112     PINTEL_HOSTVLD_VP9_BAC_ENGINE pBacEngine);
113 
114 INT Intel_HostvldVp9_BacEngineReadMultiBits(
115     PINTEL_HOSTVLD_VP9_BAC_ENGINE pBacEngine,
116     register INT                     iNumBits);
117 
118 INT Intel_HostvldVp9_BacEngineReadTree(
119     PINTEL_HOSTVLD_VP9_BAC_ENGINE pBacEngine,
120     INTEL_HOSTVLD_VP9_TKN_TREE    TknTree);
121 
122 #endif // __INTEL_HOSTVLD_VP9_ENGINE_H__
123