HEVC Test Model (HM)  HM-16.3
TComChromaFormat.h
Go to the documentation of this file.
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-2015, ITU/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 ITU/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 #ifndef __TCOMCHROMAFORMAT__
35 #define __TCOMCHROMAFORMAT__
36 
37 #include "CommonDef.h"
38 #include "TComRectangle.h"
39 #include "ContextTables.h"
40 #include "TComRom.h"
41 #include <iostream>
42 #include <vector>
43 #include <assert.h>
44 #include "Debug.h"
45 
46 //======================================================================================================================
47 //Chroma format utility functions =====================================================================================
48 //======================================================================================================================
49 
50 class TComDataCU;
51 
52 
54 static inline Bool isLuma (const ComponentID id) { return (id==COMPONENT_Y); }
55 static inline Bool isLuma (const ChannelType id) { return (id==CHANNEL_TYPE_LUMA); }
56 static inline Bool isChroma (const ComponentID id) { return (id!=COMPONENT_Y); }
57 static inline Bool isChroma (const ChannelType id) { return (id!=CHANNEL_TYPE_LUMA); }
58 static inline UInt getChannelTypeScaleX (const ChannelType id, const ChromaFormat fmt) { return (isLuma(id) || (fmt==CHROMA_444)) ? 0 : 1; }
59 static inline UInt getChannelTypeScaleY (const ChannelType id, const ChromaFormat fmt) { return (isLuma(id) || (fmt!=CHROMA_420)) ? 0 : 1; }
60 static inline UInt getComponentScaleX (const ComponentID id, const ChromaFormat fmt) { return getChannelTypeScaleX(toChannelType(id), fmt); }
61 static inline UInt getComponentScaleY (const ComponentID id, const ChromaFormat fmt) { return getChannelTypeScaleY(toChannelType(id), fmt); }
62 static inline UInt getNumberValidChannelTypes(const ChromaFormat fmt) { return (fmt==CHROMA_400) ? 1 : MAX_NUM_CHANNEL_TYPE; }
63 static inline UInt getNumberValidComponents (const ChromaFormat fmt) { return (fmt==CHROMA_400) ? 1 : MAX_NUM_COMPONENT; }
64 static inline Bool isChromaEnabled (const ChromaFormat fmt) { return fmt!=CHROMA_400; }
66 
67 InputColourSpaceConversion stringToInputColourSpaceConvert(const std::string &value, const Bool bIsForward);
68 std::string getListOfColourSpaceConverts(const Bool bIsForward);
69 
70 //------------------------------------------------
71 
72 static inline UInt getTotalSamples(const UInt width, const UInt height, const ChromaFormat format)
73 {
74  const UInt samplesPerChannel = width * height;
75 
76  switch (format)
77  {
78  case CHROMA_400: return samplesPerChannel; break;
79  case CHROMA_420: return (samplesPerChannel * 3) >> 1; break;
80  case CHROMA_422: return samplesPerChannel * 2; break;
81  case CHROMA_444: return samplesPerChannel * 3; break;
82  default:
83  std::cerr << "ERROR: Unrecognised chroma format in getTotalSamples()" << std::endl;
84  exit(1);
85  break;
86  }
87 
88  return MAX_UINT;
89 }
90 
91 //------------------------------------------------
92 
93 static inline UInt getTotalBits(const UInt width, const UInt height, const ChromaFormat format, const Int bitDepths[MAX_NUM_CHANNEL_TYPE])
94 {
95  const UInt samplesPerChannel = width * height;
96 
97  switch (format)
98  {
99  case CHROMA_400: return samplesPerChannel * bitDepths[CHANNEL_TYPE_LUMA]; break;
100  case CHROMA_420: return (samplesPerChannel * (bitDepths[CHANNEL_TYPE_LUMA]*2 + bitDepths[CHANNEL_TYPE_CHROMA]) ) >> 1; break;
101  case CHROMA_422: return samplesPerChannel * (bitDepths[CHANNEL_TYPE_LUMA] + bitDepths[CHANNEL_TYPE_CHROMA]); break;
102  case CHROMA_444: return samplesPerChannel * (bitDepths[CHANNEL_TYPE_LUMA] + 2*bitDepths[CHANNEL_TYPE_CHROMA]); break;
103  default:
104  std::cerr << "ERROR: Unrecognised chroma format in getTotalSamples()" << std::endl;
105  exit(1);
106  break;
107  }
108 
109  return MAX_UINT;
110 }
111 
112 
113 //------------------------------------------------
114 
115 // In HM, a CU only has one chroma intra prediction direction, that corresponds to the top left luma intra prediction
116 // even if the NxN PU split occurs when 4 sub-TUs exist for chroma.
117 // Use this function to allow NxN PU splitting for chroma.
118 
120 {
121  return (chFmt == CHROMA_444);
122 }
123 
124 
125 //------------------------------------------------
126 
127 //returns the part index of the luma region that is co-located with the specified chroma region
128 
129 static inline UInt getChromasCorrespondingPULumaIdx(const UInt lumaZOrderIdxInCtu, const ChromaFormat chFmt)
130 {
131  return enable4ChromaPUsInIntraNxNCU(chFmt) ? lumaZOrderIdxInCtu : lumaZOrderIdxInCtu & (~((1<<(2*g_uiAddCUDepth))-1)); //(lumaZOrderIdxInCtu/numParts)*numParts;
132 }
133 
134 //------------------------------------------------
135 
136 // If chroma format is 4:2:2 and a chroma-square-sub-tu is possible for the smallest TU, then increase the depth by 1 to allow for more parts.
137 
138 static inline UInt getMaxCUDepthOffset(const ChromaFormat chFmt, const UInt quadtreeTULog2MinSize)
139 {
140  return (chFmt==CHROMA_422 && quadtreeTULog2MinSize>2) ? 1 : 0;
141 }
142 
143 //======================================================================================================================
144 //Intra prediction ====================================================================================================
145 //======================================================================================================================
146 
147 static inline Bool filterIntraReferenceSamples (const ChannelType chType, const ChromaFormat chFmt, const Bool intraReferenceSmoothingDisabled)
148 {
149  return (!intraReferenceSmoothingDisabled) && (isLuma(chType) || (chFmt == CHROMA_444));
150 }
151 
152 
153 //======================================================================================================================
154 //Transform and Quantisation ==========================================================================================
155 //======================================================================================================================
156 
157 static inline Bool TUCompRectHasAssociatedTransformSkipFlag(const TComRectangle &rectSamples, const UInt transformSkipLog2MaxSize)
158 {
159  return (rectSamples.width <= (1<<transformSkipLog2MaxSize));
160 }
161 
162 
163 //------------------------------------------------
164 
165 static inline Int getTransformShift(const ChannelType type, const UInt uiLog2TrSize)
166 {
167 #if O0043_BEST_EFFORT_DECODING
168  return g_maxTrDynamicRange[type] - g_bitDepthInStream[type] - uiLog2TrSize;
169 #else
170  return g_maxTrDynamicRange[type] - g_bitDepth[type] - uiLog2TrSize;
171 #endif
172 }
173 
174 
175 //------------------------------------------------
176 
177 static inline Int getScaledChromaQP(Int unscaledChromaQP, const ChromaFormat chFmt)
178 {
179  return g_aucChromaScale[chFmt][Clip3(0, (chromaQPMappingTableSize - 1), unscaledChromaQP)];
180 }
181 
182 
183 //======================================================================================================================
184 //Scaling lists =======================================================================================================
185 //======================================================================================================================
186 
187 static inline Int getScalingListType(const PredMode predMode, const ComponentID compID)
188 {
189  return ((predMode != MODE_INTER) ? 0 : MAX_NUM_COMPONENT) + compID;
190 }
191 
192 
193 //------------------------------------------------
194 
195 
196 //======================================================================================================================
197 //Context variable selection ==========================================================================================
198 //======================================================================================================================
199 
200 //context variable source tables
201 
205 
206 
207 //------------------------------------------------
208 
209 //Function for last-significant-coefficient context selection parameters
210 
211 static inline Void getLastSignificantContextParameters (const ComponentID component,
212  const Int width,
213  const Int height,
214  Int &result_offsetX,
215  Int &result_offsetY,
216  Int &result_shiftX,
217  Int &result_shiftY)
218 {
219  const UInt convertedWidth = g_aucConvertToBit[width];
220  const UInt convertedHeight = g_aucConvertToBit[height];
221 
222  result_offsetX = (isChroma(component)) ? 0 : ((convertedWidth * 3) + ((convertedWidth + 1) >> 2));
223  result_offsetY = (isChroma(component)) ? 0 : ((convertedHeight * 3) + ((convertedHeight + 1) >> 2));
224  result_shiftX = (isChroma(component)) ? convertedWidth : ((convertedWidth + 3) >> 2);
225  result_shiftY = (isChroma(component)) ? convertedHeight : ((convertedHeight + 3) >> 2);
226 }
227 
228 
229 //------------------------------------------------
230 
231 //Function for significance map context index offset selection
232 
233 static inline UInt getSignificanceMapContextOffset (const ComponentID component)
234 {
236 }
237 
238 
239 //------------------------------------------------
240 
241 // Function for greater-than-one map/greater-than-two map context set selection
242 
243 static inline UInt getContextSetIndex (const ComponentID component,
244  const UInt subsetIndex,
245  const Bool foundACoefficientGreaterThan1)
246 {
247  const UInt notFirstSubsetOffset = (isLuma(component) && (subsetIndex > 0)) ? 2 : 0;
248  const UInt foundAGreaterThan1Offset = foundACoefficientGreaterThan1 ? 1 : 0;
249 
250  return contextSetStartTable[toChannelType(component)] + notFirstSubsetOffset + foundAGreaterThan1Offset;
251 }
252 
253 
254 //------------------------------------------------
255 
256 //Function for CBF context index offset
257 
258 static inline UInt getCBFContextOffset (const ComponentID component)
259 {
260  return CBFContextStartTable[toChannelType(component)];
261 }
262 
263 
264 //======================================================================================================================
265 //Entropy coding parameters ============================================================================================
266 //======================================================================================================================
267 
269  class TComTU &rTu,
270  const ComponentID component);
271 
272 
273 //======================================================================================================================
274 //End =================================================================================================================
275 //======================================================================================================================
276 
277 #endif
static Bool isChromaEnabled(const ChromaFormat fmt)
static const UInt significanceMapContextStartTable[MAX_NUM_CHANNEL_TYPE]
#define FIRST_SIG_FLAG_CTX_CHROMA
Definition: ContextTables.h:98
static Int getScalingListType(const PredMode predMode, const ComponentID compID)
static Int getScaledChromaQP(Int unscaledChromaQP, const ChromaFormat chFmt)
CU data structure class.
Definition: TComDataCU.h:64
ChannelType
Definition: TypeDef.h:361
static const UInt CBFContextStartTable[MAX_NUM_CHANNEL_TYPE]
Defines constants, macros and tool parameters.
void Void
Definition: TypeDef.h:285
static UInt getNumberValidChannelTypes(const ChromaFormat fmt)
static ComponentID getFirstComponentOfChannel(const ChannelType id)
global variables & functions (header)
static UInt getComponentScaleY(const ComponentID id, const ChromaFormat fmt)
Char g_aucConvertToBit[(1<<(6))+1]
Definition: TComRom.cpp:558
unsigned int UInt
Definition: TypeDef.h:297
static UInt getComponentScaleX(const ComponentID id, const ChromaFormat fmt)
static UInt getChromasCorrespondingPULumaIdx(const UInt lumaZOrderIdxInCtu, const ChromaFormat chFmt)
static const Int chromaQPMappingTableSize
Definition: TComRom.h:128
UInt g_uiAddCUDepth
Definition: TComRom.cpp:254
Void getTUEntropyCodingParameters(TUEntropyCodingParameters &result, class TComTU &rTu, const ComponentID component)
static Bool enable4ChromaPUsInIntraNxNCU(const ChromaFormat chFmt)
#define MAX_UINT
max. value of unsigned 32-bit integer
Definition: CommonDef.h:115
static UInt getCBFContextOffset(const ComponentID component)
bool Bool
Definition: TypeDef.h:286
Int g_maxTrDynamicRange[MAX_NUM_CHANNEL_TYPE]
Definition: TComRom.cpp:325
static ChannelType toChannelType(const ComponentID id)
T Clip3(const T minVal, const T maxVal, const T a)
general min/max clip
Definition: CommonDef.h:137
Defines constants and tables for SBAC.
static UInt getChannelTypeScaleY(const ChannelType id, const ChromaFormat fmt)
#define FIRST_CBF_CTX_LUMA
index of first luminance CBF context
ChromaFormat
chroma formats (according to semantics of chroma_format_idc)
Definition: TypeDef.h:352
#define FIRST_CTX_SET_LUMA
index of first luminance context set
static UInt getTotalSamples(const UInt width, const UInt height, const ChromaFormat format)
static UInt getTotalBits(const UInt width, const UInt height, const ChromaFormat format, const Int bitDepths[MAX_NUM_CHANNEL_TYPE])
#define FIRST_CBF_CTX_CHROMA
index of first chrominance CBF context
#define FIRST_SIG_FLAG_CTX_LUMA
Definition: ContextTables.h:97
#define FIRST_CTX_SET_CHROMA
index of first chrominance context set
InputColourSpaceConversion
Definition: TypeDef.h:376
static Bool TUCompRectHasAssociatedTransformSkipFlag(const TComRectangle &rectSamples, const UInt transformSkipLog2MaxSize)
static const UInt contextSetStartTable[MAX_NUM_CHANNEL_TYPE]
Int g_bitDepth[MAX_NUM_CHANNEL_TYPE]
Definition: TComRom.cpp:548
Definition: TComTU.h:48
static Bool filterIntraReferenceSamples(const ChannelType chType, const ChromaFormat chFmt, const Bool intraReferenceSmoothingDisabled)
static Int getTransformShift(const ChannelType type, const UInt uiLog2TrSize)
static UInt getSignificanceMapContextOffset(const ComponentID component)
static Void getLastSignificantContextParameters(const ComponentID component, const Int width, const Int height, Int &result_offsetX, Int &result_offsetY, Int &result_shiftX, Int &result_shiftY)
int Int
Definition: TypeDef.h:296
static Bool isChroma(const ComponentID id)
static UInt getMaxCUDepthOffset(const ChromaFormat chFmt, const UInt quadtreeTULog2MinSize)
ComponentID
Definition: TypeDef.h:368
PredMode
supported prediction type
Definition: TypeDef.h:407
inter-prediction mode
Definition: TypeDef.h:409
const UChar g_aucChromaScale[NUM_CHROMA_FORMAT][chromaQPMappingTableSize]
Definition: TComRom.cpp:505
static UInt getContextSetIndex(const ComponentID component, const UInt subsetIndex, const Bool foundACoefficientGreaterThan1)
static UInt getNumberValidComponents(const ChromaFormat fmt)
InputColourSpaceConversion stringToInputColourSpaceConvert(const std::string &value, const Bool bIsForward)
static UInt getChannelTypeScaleX(const ChannelType id, const ChromaFormat fmt)
std::string getListOfColourSpaceConverts(const Bool bIsForward)
Defines types and objects for environment-variable-based debugging and feature control.
static Bool isLuma(const ComponentID id)