HEVC Test Model (HM)  HM-16.18
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Debug.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-2017, 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 
38 #ifndef __DEBUG__
39 #define __DEBUG__
40 
41 #include <iostream>
42 #include <iomanip>
43 #include <string>
44 #include <list>
45 #include <stdlib.h>
46 #include <sstream>
47 #include <TLibCommon/CommonDef.h>
48 
49 #if DEBUG_STRING
50 extern const TChar *debug_reorder_data_inter_token[MAX_NUM_COMPONENT+1];
51 extern const TChar *partSizeToString[NUMBER_OF_PART_SIZES];
52 #endif
53 
54 // ---------------------------------------------------------------------------------------------- //
55 
56 //constant print-out macro
57 
58 #define PRINT_CONSTANT(NAME, NAME_WIDTH, VALUE_WIDTH) std::cout << std::setw(NAME_WIDTH) << #NAME << " = " << std::setw(VALUE_WIDTH) << NAME << std::endl;
59 
60 // ---------------------------------------------------------------------------------------------- //
61 
62 // ---- Environment variables for test/debug ---- //
63 
64 class EnvVar
65 {
66 private:
67  std::string m_sName;
68  std::string m_sHelp;
69  std::string m_sVal;
73 
74 public:
75 
76  static std::list< std::pair<std::string, std::string> > &getEnvVarList();
77  static std::list<EnvVar*> &getEnvVarInUse();
78  static Void printEnvVar();
79  static Void printEnvVarInUse();
80 
81  EnvVar(const std::string &sName, const std::string &sDefault, const std::string &sHelp);
82 
83  Double getDouble() const { return m_dVal; }
84  Int getInt() const { return m_iVal; }
85  const std::string &getString() const { return m_sVal; }
86  Bool isSet() const { return m_bSet; }
87  Bool isTrue() const { return m_iVal!=0; }
88  const std::string &getName() const { return m_sName; }
89 
90 };
91 
92 
93 // ---------------------------------------------------------------------------------------------- //
94 
95 // ---- Control switches for debugging and feature control ---- //
96 
97 namespace DebugOptionList
98 {
99  extern EnvVar DebugSBAC;
100  extern EnvVar DebugRQT;
101  extern EnvVar DebugPred;
102  extern EnvVar ForceLumaMode;
103  extern EnvVar ForceChromaMode;
104 
105 #if DEBUG_STRING
106  extern EnvVar DebugString_Structure;
107  extern EnvVar DebugString_Pred;
108  extern EnvVar DebugString_Resi;
109  extern EnvVar DebugString_Reco;
110  extern EnvVar DebugString_InvTran;
111 #endif
112 }
113 
114 // ---------------------------------------------------------------------------------------------- //
115 
117 
118 // ---------------------------------------------------------------------------------------------- //
119 
120 //Debugging
121 
122 extern UInt g_debugCounter;
123 
124 #if DEBUG_ENCODER_SEARCH_BINS
125 extern const UInt debugEncoderSearchBinTargetLine;
126 extern const UInt debugEncoderSearchBinWindow;
127 #endif
128 
129 #if DEBUG_CABAC_BINS
130 extern const UInt debugCabacBinTargetLine;
131 extern const UInt debugCabacBinWindow;
132 #endif
133 
134 
135 Void printSBACCoeffData( const UInt lastX,
136  const UInt lastY,
137  const UInt width,
138  const UInt height,
139  const UInt chan,
140  const UInt absPart,
141  const UInt scanIdx,
142  const TCoeff *const pCoeff,
143  const Bool finalEncode=true
144  );
145 
146 
147 Void printCbfArray( class TComDataCU* pcCU );
148 
149 UInt getDecimalWidth(const Double value);
150 UInt getZScanIndex(const UInt x, const UInt y);
151 
152 //template specialisation for SChar/UChar types to get it to render as a number
153 template <typename ValueType> inline Void writeValueToStream (const ValueType &value, std::ostream &stream, const UInt outputWidth) { stream << std::setw(outputWidth) << value; }
154 template <> inline Void writeValueToStream<SChar>(const SChar &value, std::ostream &stream, const UInt outputWidth) { stream << std::setw(outputWidth) << Int(value); }
155 template <> inline Void writeValueToStream<UChar>(const UChar &value, std::ostream &stream, const UInt outputWidth) { stream << std::setw(outputWidth) << UInt(value); }
156 
157 template <typename ValueType>
158 Void printBlock(const ValueType *const source,
159  const UInt width,
160  const UInt height,
161  const UInt stride,
162  const UInt outputValueWidth = 0, //if set to 0, the maximum output width will be calculated and used
163  const Bool onlyPrintEdges = false, //print only the top row and left column for printing prediction reference samples
164  const Bool printInZScan = false, //output values in Z-scan format (useful for values addressed by AbsPartIdxes)
165  const Int shiftLeftBy = 0, //set a negative value to right-shift instead
166  const Bool printAverage = false, //also print the average of the values in the block
167  std::ostream & stream = std::cout)
168 {
169  //find the maximum output width
170  UInt outputWidth = outputValueWidth;
171 
172  if (outputWidth == 0)
173  {
174  ValueType minimumValue = leftShift(source[0], shiftLeftBy);
175  ValueType maximumValue = minimumValue;
176 
177  for (UInt y = 0; y < height; y++)
178  {
179  for (UInt x = 0; x < width; x++)
180  {
181  ValueType value = 0;
182 
183  if (!onlyPrintEdges || (x == 0) || (y == 0))
184  {
185  value = leftShift(source[printInZScan ? getZScanIndex(x, y) : ((y * stride) + x)], shiftLeftBy);
186  }
187 
188  if (value < minimumValue)
189  {
190  minimumValue = value;
191  }
192  else if (value > maximumValue)
193  {
194  maximumValue = value;
195  }
196  }
197  }
198 
199  outputWidth = std::max<UInt>(getDecimalWidth(Double(minimumValue)), getDecimalWidth(Double(maximumValue))) + 1; //+1 so the numbers don't run into each other
200  }
201 
202  //------------------
203  //print out the block
204 
205  ValueType valueSum = 0;
206 
207  for (UInt y = 0; y < height; y++)
208  {
209  for (UInt x = 0; x < width; x++)
210  {
211  ValueType value = 0;
212 
213  if (!onlyPrintEdges || (x == 0) || (y == 0))
214  {
215  value = leftShift(source[printInZScan ? getZScanIndex(x, y) : ((y * stride) + x)], shiftLeftBy);
216  valueSum += value;
217  }
218 
219  writeValueToStream(value, stream, outputWidth);
220  }
221  stream << "\n";
222  }
223 
224  const Int valueCount = onlyPrintEdges ? Int((width + height) - 1) : Int(width * height);
225  if (printAverage)
226  {
227  stream << "Average: " << (valueSum / valueCount) << "\n";
228  }
229  stream << "\n";
230 }
231 
232 
233 template <typename T>
234 Void printBlockToStream( std::ostream &ss, const TChar *pLinePrefix, const T * blkSrc, const UInt width, const UInt height, const UInt stride, const UInt subBlockWidth=0, const UInt subBlockHeight=0, const UInt defWidth=3 )
235 {
236  for (UInt y=0; y<height; y++)
237  {
238  if (subBlockHeight!=0 && (y%subBlockHeight)==0 && y!=0)
239  {
240  ss << pLinePrefix << '\n';
241  }
242 
243  ss << pLinePrefix;
244  for (UInt x=0; x<width; x++)
245  {
246  if (subBlockWidth!=0 && (x%subBlockWidth)==0 && x!=0)
247  {
248  ss << std::setw(defWidth+2) << "";
249  }
250 
251  ss << std::setw(defWidth) << blkSrc[y*stride + x] << ' ';
252  }
253  ss << '\n';
254  }
255 }
256 
257 class TComYuv;
258 Void printBlockToStream( std::ostream &ss, const TChar *pLinePrefix, TComYuv &src, const UInt numSubBlocksAcross=1, const UInt numSubBlocksUp=1, const UInt defWidth=3 );
259 
260 // ---------------------------------------------------------------------------------------------- //
261 
262 //String manipulation functions for aligning and wrapping printed text
263 
264 std::string splitOnSettings(const std::string &input);
265 
266 std::string lineWrap(const std::string &input, const UInt maximumLineLength);
267 
268 std::string indentNewLines(const std::string &input, const UInt indentBy);
269 
270 // ---------------------------------------------------------------------------------------------- //
271 
272 #if DEBUG_STRING
273  Int DebugStringGetPredModeMask(PredMode mode);
274  Void DebugInterPredResiReco(std::string &sDebug, TComYuv &pred, TComYuv &resi, TComYuv &reco, Int predmode_mask);
275 #endif
276 
277 
278 #endif /* __DEBUG__ */
ValueType leftShift(const ValueType value, const Int shift)
Definition: CommonDef.h:280
static std::list< std::pair< std::string, std::string > > & getEnvVarList()
Definition: Debug.cpp:60
CU data structure class.
Definition: TComDataCU.h:64
Void printMacroSettings()
Definition: Debug.cpp:167
Int getInt() const
Definition: Debug.h:84
Defines version information, constants and small in-line functions.
void Void
Definition: TypeDef.h:203
UInt getDecimalWidth(const Double value)
Definition: Debug.cpp:253
std::string lineWrap(const std::string &input, const UInt maximumLineLength)
Definition: Debug.cpp:323
std::string m_sHelp
Definition: Debug.h:68
unsigned int UInt
Definition: TypeDef.h:212
static Void printEnvVar()
Definition: Debug.cpp:96
char TChar
Definition: TypeDef.h:206
Void writeValueToStream(const ValueType &value, std::ostream &stream, const UInt outputWidth)
Definition: Debug.h:153
std::string splitOnSettings(const std::string &input)
Definition: Debug.cpp:284
Void writeValueToStream< UChar >(const UChar &value, std::ostream &stream, const UInt outputWidth)
Definition: Debug.h:155
const std::string & getString() const
Definition: Debug.h:85
general YUV buffer class
Definition: TComYuv.h:54
Double getDouble() const
Definition: Debug.h:83
signed char SChar
Definition: TypeDef.h:207
bool Bool
Definition: TypeDef.h:204
UInt getZScanIndex(const UInt x, const UInt y)
Definition: Debug.cpp:259
EnvVar(const std::string &sName, const std::string &sDefault, const std::string &sHelp)
Definition: Debug.cpp:117
Bool isTrue() const
Definition: Debug.h:87
Definition: Debug.h:64
EnvVar ForceLumaMode
Int TCoeff
transform coefficient
Definition: TypeDef.h:250
Double m_dVal
Definition: Debug.h:70
unsigned char UChar
Definition: TypeDef.h:208
static Void printEnvVarInUse()
Definition: Debug.cpp:107
Int m_iVal
Definition: Debug.h:71
std::string m_sName
Definition: Debug.h:67
Void writeValueToStream< SChar >(const SChar &value, std::ostream &stream, const UInt outputWidth)
Definition: Debug.h:154
Void printCbfArray(TComDataCU *pcCU)
Definition: Debug.cpp:235
Bool m_bSet
Definition: Debug.h:72
std::string indentNewLines(const std::string &input, const UInt indentBy)
Definition: Debug.cpp:399
UInt g_debugCounter
Definition: Debug.cpp:193
int Int
Definition: TypeDef.h:211
Bool isSet() const
Definition: Debug.h:86
PredMode
supported prediction type
Definition: TypeDef.h:362
Void printSBACCoeffData(const UInt lastX, const UInt lastY, const UInt width, const UInt height, const UInt chan, const UInt absPart, const UInt scanIdx, const TCoeff *const pCoeff, const Bool finalEncode)
Definition: Debug.cpp:205
std::string m_sVal
Definition: Debug.h:69
Void printBlock(const ValueType *const source, const UInt width, const UInt height, const UInt stride, const UInt outputValueWidth=0, const Bool onlyPrintEdges=false, const Bool printInZScan=false, const Int shiftLeftBy=0, const Bool printAverage=false, std::ostream &stream=std::cout)
Definition: Debug.h:158
double Double
Definition: TypeDef.h:213
const std::string & getName() const
Definition: Debug.h:88
Void printBlockToStream(std::ostream &ss, const TChar *pLinePrefix, TComYuv &src, const UInt numSubBlocksAcross, const UInt numSubBlocksUp, const UInt defWidth)
Definition: Debug.cpp:422
static std::list< EnvVar * > & getEnvVarInUse()
Definition: Debug.cpp:66
EnvVar ForceChromaMode