source: SHVCSoftware/branches/SHM-dev/source/Lib/TLibCommon/Debug.h @ 1164

Last change on this file since 1164 was 1029, checked in by seregin, 10 years ago

merge with SHM-upgrade branch

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-2014, 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
49#ifdef DEBUG_STRING
50extern const Char *debug_reorder_data_inter_token[MAX_NUM_COMPONENT+1];
51extern const Char *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
64class EnvVar
65{
66private:
67  std::string m_sName;
68  std::string m_sHelp;
69  std::string m_sVal;
70  Double      m_dVal;
71  Int         m_iVal;
72  Bool        m_bSet;
73
74public:
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
97namespace DebugOptionList
98{
99  extern EnvVar DebugSBAC;
100  extern EnvVar DebugRQT;
101  extern EnvVar DebugPred;
102  extern EnvVar ForceLumaMode;
103  extern EnvVar ForceChromaMode;
104
105#ifdef 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
116Void printMacroSettings();
117
118// ---------------------------------------------------------------------------------------------- //
119
120//Debugging
121
122extern Bool g_bFinalEncode;
123extern UInt g_debugCounter;
124extern Bool g_printDebug;
125extern Void* g_debugAddr;
126
127#ifdef DEBUG_ENCODER_SEARCH_BINS
128extern const UInt debugEncoderSearchBinTargetLine;
129extern const UInt debugEncoderSearchBinWindow;
130#endif
131
132#ifdef DEBUG_CABAC_BINS
133extern const UInt debugCabacBinTargetLine;
134extern const UInt debugCabacBinWindow;
135#endif
136
137
138Void printSBACCoeffData(  const UInt          lastX,
139                          const UInt          lastY,
140                          const UInt          width,
141                          const UInt          height,
142                          const UInt          chan,
143                          const UInt          absPart,
144                          const UInt          scanIdx,
145                          const TCoeff *const pCoeff,
146                          const Bool          finalEncode=true
147                        );
148
149
150Void printCbfArray( class TComDataCU* pcCU  );
151
152UInt getDecimalWidth(const Double value);
153UInt getZScanIndex(const UInt x, const UInt y);
154
155//template specialisation for Char types to get it to render as a number
156template <typename ValueType> inline Void writeValueToStream       (const ValueType &value, std::ostream &stream, const UInt outputWidth) { stream << std::setw(outputWidth) <<      value;  }
157template <>                   inline Void writeValueToStream<Char >(const Char      &value, std::ostream &stream, const UInt outputWidth) { stream << std::setw(outputWidth) <<  Int(value); }
158template <>                   inline Void writeValueToStream<UChar>(const UChar     &value, std::ostream &stream, const UInt outputWidth) { stream << std::setw(outputWidth) << UInt(value); }
159
160template <typename ValueType>
161Void printBlock(const ValueType    *const source,
162                const UInt                width,
163                const UInt                height,
164                const UInt                stride,
165                const UInt                outputValueWidth = 0,         //if set to 0, the maximum output width will be calculated and used
166                const Bool                onlyPrintEdges   = false,     //print only the top row and left column for printing prediction reference samples
167                const Bool                printInZScan     = false,     //output values in Z-scan format (useful for values addressed by AbsPartIdxes)
168                const Int                 shiftLeftBy      = 0,         //set a negative value to right-shift instead
169                const Bool                printAverage     = false,     //also print the average of the values in the block
170                      std::ostream      & stream           = std::cout)
171{
172  //find the maximum output width
173  UInt outputWidth = outputValueWidth;
174
175  if (outputWidth == 0)
176  {
177    ValueType minimumValue = leftShift(source[0], shiftLeftBy);
178    ValueType maximumValue = minimumValue;
179
180    for (UInt y = 0; y < height; y++)
181      for (UInt x = 0; x < width; x++)
182      {
183        ValueType value = 0;
184
185        if (!onlyPrintEdges || (x == 0) || (y == 0))
186        {
187          value = leftShift(source[printInZScan ? getZScanIndex(x, y) : ((y * stride) + x)], shiftLeftBy);
188        }
189
190        if      (value < minimumValue) minimumValue = value;
191        else if (value > maximumValue) maximumValue = value;
192      }
193
194    outputWidth = std::max<UInt>(getDecimalWidth(Double(minimumValue)), getDecimalWidth(Double(maximumValue))) + 1; //+1 so the numbers don't run into each other
195  }
196
197  //------------------
198  //print out the block
199
200  ValueType valueSum = 0;
201
202  for (UInt y = 0; y < height; y++)
203  {
204    for (UInt x = 0; x < width; x++)
205    {
206      ValueType value = 0;
207
208      if (!onlyPrintEdges || (x == 0) || (y == 0))
209      {
210        value     = leftShift(source[printInZScan ? getZScanIndex(x, y) : ((y * stride) + x)], shiftLeftBy);
211        valueSum += value;
212      }
213
214      writeValueToStream(value, stream, outputWidth);
215    }
216    stream << "\n";
217  }
218
219  const Int valueCount = onlyPrintEdges ? Int((width + height) - 1) : Int(width * height);
220  if (printAverage) stream << "Average: " << (valueSum / valueCount) << "\n";
221  stream << "\n";
222}
223
224
225template <typename T>
226Void printBlockToStream( std::ostream &ss, const Char *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 )
227{
228  for (UInt y=0; y<height; y++)
229  {
230    if (subBlockHeight!=0 && (y%subBlockHeight)==0 && y!=0)
231      ss << pLinePrefix << '\n';
232
233    ss << pLinePrefix;
234    for (UInt x=0; x<width; x++)
235    {
236      if (subBlockWidth!=0 && (x%subBlockWidth)==0 && x!=0)
237        ss << std::setw(defWidth+2) << "";
238
239      ss << std::setw(defWidth) << blkSrc[y*stride + x] << ' ';
240    }
241    ss << '\n';
242  }
243}
244
245class TComYuv;
246Void printBlockToStream( std::ostream &ss, const Char *pLinePrefix, TComYuv &src, const UInt numSubBlocksAcross=1, const UInt numSubBlocksUp=1, const UInt defWidth=3 );
247
248// ---------------------------------------------------------------------------------------------- //
249
250//String manipulation functions for aligning and wrapping printed text
251
252std::string splitOnSettings(const std::string &input);
253
254std::string lineWrap(const std::string &input, const UInt maximumLineLength);
255
256std::string indentNewLines(const std::string &input, const UInt indentBy);
257
258// ---------------------------------------------------------------------------------------------- //
259
260#ifdef DEBUG_STRING
261  Int DebugStringGetPredModeMask(PredMode mode);
262  Void DebugInterPredResiReco(std::string &sDebug, TComYuv &pred, TComYuv &resi, TComYuv &reco, Int predmode_mask);
263#endif
264
265
266#endif /* __DEBUG__ */
Note: See TracBrowser for help on using the repository browser.