source: 3DVCSoftware/branches/HTM-16.2-dev/source/Lib/TLibCommon/Debug.h

Last change on this file was 1412, checked in by tech, 7 years ago
  • Update HM-16.18
  • Cleanups
  • Encoder Extension

-- Representation formats
-- Parameter set sharing
-- GOP configuration

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