1 | /* The copyright in this software is being made available under the BSD |
---|
2 | * License, included below. This software may be subject to other third party |
---|
3 | * and contributor rights, including patent rights, and no such rights are |
---|
4 | * granted under this license. |
---|
5 | * |
---|
6 | * Copyright (c) 2010-2011, ISO/IEC |
---|
7 | * All rights reserved. |
---|
8 | * |
---|
9 | * Redistribution and use in source and binary forms, with or without |
---|
10 | * modification, are permitted provided that the following conditions are met: |
---|
11 | * |
---|
12 | * * Redistributions of source code must retain the above copyright notice, |
---|
13 | * this list of conditions and the following disclaimer. |
---|
14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
15 | * this list of conditions and the following disclaimer in the documentation |
---|
16 | * and/or other materials provided with the distribution. |
---|
17 | * * Neither the name of the ISO/IEC nor the names of its contributors may |
---|
18 | * be used to endorse or promote products derived from this software without |
---|
19 | * specific prior written permission. |
---|
20 | * |
---|
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
32 | */ |
---|
33 | |
---|
34 | |
---|
35 | |
---|
36 | #ifndef __TCOMWEDGELET__ |
---|
37 | #define __TCOMWEDGELET__ |
---|
38 | |
---|
39 | // Include files |
---|
40 | #include <assert.h> |
---|
41 | #include "CommonDef.h" |
---|
42 | |
---|
43 | #include <vector> |
---|
44 | |
---|
45 | #if H_3D_DIM |
---|
46 | #define DIM_OFFSET (NUM_INTRA_MODE+1) // offset for DMM and RBC mode numbers (PM: not consistent with spec, but non-overlapping with chroma, see DM_CHROMA_IDX) |
---|
47 | #define DIM_MIN_SIZE 4 // min. block size for DMM and RBC modes |
---|
48 | #define DIM_MAX_SIZE 32 // max. block size for DMM and RBC modes |
---|
49 | |
---|
50 | enum DIM_IDX |
---|
51 | { |
---|
52 | #if SEC_DMM2_E0146_HHIFIX |
---|
53 | DMM1_IDX = 0, |
---|
54 | DMM3_IDX = 1, |
---|
55 | DMM4_IDX = 2, |
---|
56 | RBC_IDX = 3 |
---|
57 | #else |
---|
58 | DMM1_IDX = 0, |
---|
59 | DMM2_IDX = 3, |
---|
60 | DMM3_IDX = 1, |
---|
61 | DMM4_IDX = 2, |
---|
62 | RBC_IDX = 4 |
---|
63 | #endif |
---|
64 | }; |
---|
65 | #if SEC_DMM2_E0146_HHIFIX |
---|
66 | #define DMM_NUM_TYPE 3 |
---|
67 | #else |
---|
68 | #define DMM_NUM_TYPE 4 |
---|
69 | #endif |
---|
70 | #define RBC_NUM_TYPE 1 |
---|
71 | #define DIM_NUM_TYPE (DMM_NUM_TYPE+RBC_NUM_TYPE) |
---|
72 | #define DIM_NO_IDX MAX_UINT |
---|
73 | |
---|
74 | __inline UInt getDimType ( Int intraMode ) { Int dimType = (intraMode-DIM_OFFSET)/2; return (dimType >= 0 && dimType < DIM_NUM_TYPE) ? (UInt)dimType : DIM_NO_IDX; } |
---|
75 | __inline Bool isDimMode ( Int intraMode ) { return (getDimType( intraMode ) < DIM_NUM_TYPE); } |
---|
76 | __inline Bool isDimDeltaDC( Int intraMode ) { return (isDimMode( intraMode ) && ((intraMode-DIM_OFFSET)%2) == 1); } |
---|
77 | #endif |
---|
78 | |
---|
79 | #if H_3D_DIM_RBC |
---|
80 | #define RBC_THRESHOLD 20 |
---|
81 | #define RBC_MAX_EDGE_NUM_PER_4x4 8 |
---|
82 | #define RBC_MAX_DISTANCE 255 |
---|
83 | #endif |
---|
84 | |
---|
85 | #if H_3D_DIM_DMM |
---|
86 | #define DMM_NO_WEDGEINDEX MAX_UINT |
---|
87 | #define DMM_NUM_WEDGE_REFINES 8 |
---|
88 | #if !SEC_DMM2_E0146_HHIFIX |
---|
89 | #define DMM2_DELTAEND_MAX 4 |
---|
90 | #endif |
---|
91 | #define DMM3_SIMPLIFY_TR 1 |
---|
92 | |
---|
93 | enum WedgeResolution |
---|
94 | { |
---|
95 | DOUBLE_PEL, |
---|
96 | FULL_PEL, |
---|
97 | HALF_PEL |
---|
98 | }; |
---|
99 | |
---|
100 | |
---|
101 | // ==================================================================================================================== |
---|
102 | // Class definition TComWedgelet |
---|
103 | // ==================================================================================================================== |
---|
104 | class TComWedgelet |
---|
105 | { |
---|
106 | private: |
---|
107 | UChar m_uhXs; // line start X pos |
---|
108 | UChar m_uhYs; // line start Y pos |
---|
109 | UChar m_uhXe; // line end X pos |
---|
110 | UChar m_uhYe; // line end Y pos |
---|
111 | UChar m_uhOri; // orientation index |
---|
112 | WedgeResolution m_eWedgeRes; // start/end pos resolution |
---|
113 | Bool m_bIsCoarse; |
---|
114 | UInt m_uiAng; |
---|
115 | |
---|
116 | UInt m_uiWidth; |
---|
117 | UInt m_uiHeight; |
---|
118 | |
---|
119 | Bool* m_pbPattern; |
---|
120 | |
---|
121 | Void xGenerateWedgePattern(); |
---|
122 | Void xDrawEdgeLine( UChar uhXs, UChar uhYs, UChar uhXe, UChar uhYe, Bool* pbPattern, Int iPatternStride ); |
---|
123 | |
---|
124 | public: |
---|
125 | TComWedgelet( UInt uiWidth, UInt uiHeight ); |
---|
126 | TComWedgelet( const TComWedgelet &rcWedge ); |
---|
127 | virtual ~TComWedgelet(); |
---|
128 | |
---|
129 | Void create ( UInt iWidth, UInt iHeight ); ///< create wedgelet pattern |
---|
130 | Void destroy(); ///< destroy wedgelet pattern |
---|
131 | Void clear (); ///< clear wedgelet pattern |
---|
132 | |
---|
133 | UInt getWidth () { return m_uiWidth; } |
---|
134 | UInt getStride () { return m_uiWidth; } |
---|
135 | UInt getHeight () { return m_uiHeight; } |
---|
136 | WedgeResolution getWedgeRes() { return m_eWedgeRes; } |
---|
137 | Bool* getPattern () { return m_pbPattern; } |
---|
138 | UChar getStartX () { return m_uhXs; } |
---|
139 | UChar getStartY () { return m_uhYs; } |
---|
140 | UChar getEndX () { return m_uhXe; } |
---|
141 | UChar getEndY () { return m_uhYe; } |
---|
142 | UChar getOri () { return m_uhOri; } |
---|
143 | Bool getIsCoarse() { return m_bIsCoarse; } |
---|
144 | UInt getAng () { return m_uiAng; } |
---|
145 | |
---|
146 | Void setWedgelet( UChar uhXs, UChar uhYs, UChar uhXe, UChar uhYe, UChar uhOri, WedgeResolution eWedgeRes, Bool bIsCoarse = false ); |
---|
147 | Void findClosestAngle(); |
---|
148 | |
---|
149 | Bool checkNotPlain(); |
---|
150 | Bool checkIdentical( Bool* pbRefPattern ); |
---|
151 | Bool checkInvIdentical( Bool* pbRefPattern ); |
---|
152 | |
---|
153 | #if !SEC_DMM2_E0146_HHIFIX |
---|
154 | // functions for DMM2 prediction |
---|
155 | Bool checkPredDirAbovePossible( UInt uiPredDirBlockSize, UInt uiPredDirBlockOffsett ); |
---|
156 | Bool checkPredDirLeftPossible ( UInt uiPredDirBlockSize, UInt uiPredDirBlockOffsett ); |
---|
157 | Void getPredDirStartEndAbove( UChar& ruhXs, UChar& ruhYs, UChar& ruhXe, UChar& ruhYe, UInt uiPredDirBlockSize, UInt uiPredDirBlockOffset, Int iDeltaEnd ); |
---|
158 | Void getPredDirStartEndLeft ( UChar& ruhXs, UChar& ruhYs, UChar& ruhXe, UChar& ruhYe, UInt uiPredDirBlockSize, UInt uiPredDirBlockOffset, Int iDeltaEnd ); |
---|
159 | #endif |
---|
160 | }; // END CLASS DEFINITION TComWedgelet |
---|
161 | |
---|
162 | // type definition wedgelet pattern list |
---|
163 | typedef std::vector<TComWedgelet> WedgeList; |
---|
164 | |
---|
165 | // ==================================================================================================================== |
---|
166 | // Class definition TComWedgeRef |
---|
167 | // ==================================================================================================================== |
---|
168 | class TComWedgeRef |
---|
169 | { |
---|
170 | private: |
---|
171 | UChar m_uhXs; // line start X pos |
---|
172 | UChar m_uhYs; // line start Y pos |
---|
173 | UChar m_uhXe; // line end X pos |
---|
174 | UChar m_uhYe; // line end Y pos |
---|
175 | UInt m_uiRefIdx; // index of corresponding pattern of TComWedgelet object in wedge list |
---|
176 | |
---|
177 | public: |
---|
178 | TComWedgeRef() {} |
---|
179 | virtual ~TComWedgeRef() {} |
---|
180 | |
---|
181 | UChar getStartX () { return m_uhXs; } |
---|
182 | UChar getStartY () { return m_uhYs; } |
---|
183 | UChar getEndX () { return m_uhXe; } |
---|
184 | UChar getEndY () { return m_uhYe; } |
---|
185 | UInt getRefIdx () { return m_uiRefIdx; } |
---|
186 | |
---|
187 | Void setWedgeRef( UChar uhXs, UChar uhYs, UChar uhXe, UChar uhYe, UInt uiRefIdx ) { m_uhXs = uhXs; m_uhYs = uhYs; m_uhXe = uhXe; m_uhYe = uhYe; m_uiRefIdx = uiRefIdx; } |
---|
188 | }; // END CLASS DEFINITION TComWedgeRef |
---|
189 | |
---|
190 | // type definition wedgelet reference list |
---|
191 | typedef std::vector<TComWedgeRef> WedgeRefList; |
---|
192 | |
---|
193 | // ==================================================================================================================== |
---|
194 | // Class definition TComWedgeNode |
---|
195 | // ==================================================================================================================== |
---|
196 | class TComWedgeNode |
---|
197 | { |
---|
198 | private: |
---|
199 | UInt m_uiPatternIdx; |
---|
200 | UInt m_uiRefineIdx[DMM_NUM_WEDGE_REFINES]; |
---|
201 | |
---|
202 | public: |
---|
203 | TComWedgeNode(); |
---|
204 | virtual ~TComWedgeNode() {} |
---|
205 | |
---|
206 | UInt getPatternIdx(); |
---|
207 | UInt getRefineIdx ( UInt uiPos ); |
---|
208 | |
---|
209 | Void setPatternIdx( UInt uiIdx ); |
---|
210 | Void setRefineIdx ( UInt uiIdx, UInt uiPos ); |
---|
211 | }; // END CLASS DEFINITION TComWedgeNode |
---|
212 | |
---|
213 | // type definition wedgelet node list |
---|
214 | typedef std::vector<TComWedgeNode> WedgeNodeList; |
---|
215 | #endif //H_3D_DIM_DMM |
---|
216 | |
---|
217 | |
---|
218 | // ==================================================================================================================== |
---|
219 | // Function definition roftoi (mathematically correct rounding of float to int) |
---|
220 | // ==================================================================================================================== |
---|
221 | __inline Int roftoi( Double value ) |
---|
222 | { |
---|
223 | (value < -0.5) ? (value -= 0.5) : (value += 0.5); |
---|
224 | return ( (Int)value ); |
---|
225 | } |
---|
226 | #endif // __TCOMWEDGELET__ |
---|