[919] | 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 | * |
---|
[1259] | 6 | * Copyright (c) 2010-2015, ITU/ISO/IEC |
---|
[919] | 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 |
---|
| 50 | extern const Char *debug_reorder_data_inter_token[MAX_NUM_COMPONENT+1]; |
---|
| 51 | extern 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 | |
---|
| 64 | class EnvVar |
---|
| 65 | { |
---|
| 66 | private: |
---|
| 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 | |
---|
| 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 | #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 | |
---|
| 116 | Void printMacroSettings(); |
---|
| 117 | |
---|
| 118 | // ---------------------------------------------------------------------------------------------- // |
---|
| 119 | |
---|
| 120 | //Debugging |
---|
| 121 | |
---|
| 122 | extern Bool g_bFinalEncode; |
---|
| 123 | extern UInt g_debugCounter; |
---|
| 124 | extern Bool g_printDebug; |
---|
| 125 | extern Void* g_debugAddr; |
---|
| 126 | |
---|
| 127 | #ifdef DEBUG_ENCODER_SEARCH_BINS |
---|
| 128 | extern const UInt debugEncoderSearchBinTargetLine; |
---|
| 129 | extern const UInt debugEncoderSearchBinWindow; |
---|
| 130 | #endif |
---|
| 131 | |
---|
| 132 | #ifdef DEBUG_CABAC_BINS |
---|
| 133 | extern const UInt debugCabacBinTargetLine; |
---|
| 134 | extern const UInt debugCabacBinWindow; |
---|
| 135 | #endif |
---|
| 136 | |
---|
| 137 | |
---|
| 138 | Void 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 | |
---|
| 150 | Void printCbfArray( class TComDataCU* pcCU ); |
---|
| 151 | |
---|
| 152 | UInt getDecimalWidth(const Double value); |
---|
| 153 | UInt getZScanIndex(const UInt x, const UInt y); |
---|
| 154 | |
---|
| 155 | //template specialisation for Char types to get it to render as a number |
---|
| 156 | template <typename ValueType> inline Void writeValueToStream (const ValueType &value, std::ostream &stream, const UInt outputWidth) { stream << std::setw(outputWidth) << value; } |
---|
| 157 | template <> inline Void writeValueToStream<Char >(const Char &value, std::ostream &stream, const UInt outputWidth) { stream << std::setw(outputWidth) << Int(value); } |
---|
| 158 | template <> inline Void writeValueToStream<UChar>(const UChar &value, std::ostream &stream, const UInt outputWidth) { stream << std::setw(outputWidth) << UInt(value); } |
---|
| 159 | |
---|
| 160 | template <typename ValueType> |
---|
| 161 | Void 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++) |
---|
[1246] | 181 | { |
---|
[919] | 182 | for (UInt x = 0; x < width; x++) |
---|
| 183 | { |
---|
| 184 | ValueType value = 0; |
---|
| 185 | |
---|
| 186 | if (!onlyPrintEdges || (x == 0) || (y == 0)) |
---|
| 187 | { |
---|
| 188 | value = leftShift(source[printInZScan ? getZScanIndex(x, y) : ((y * stride) + x)], shiftLeftBy); |
---|
| 189 | } |
---|
| 190 | |
---|
[1246] | 191 | if (value < minimumValue) |
---|
| 192 | { |
---|
| 193 | minimumValue = value; |
---|
| 194 | } |
---|
| 195 | else if (value > maximumValue) |
---|
| 196 | { |
---|
| 197 | maximumValue = value; |
---|
| 198 | } |
---|
[919] | 199 | } |
---|
[1246] | 200 | } |
---|
[919] | 201 | |
---|
| 202 | outputWidth = std::max<UInt>(getDecimalWidth(Double(minimumValue)), getDecimalWidth(Double(maximumValue))) + 1; //+1 so the numbers don't run into each other |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | //------------------ |
---|
| 206 | //print out the block |
---|
| 207 | |
---|
| 208 | ValueType valueSum = 0; |
---|
| 209 | |
---|
| 210 | for (UInt y = 0; y < height; y++) |
---|
| 211 | { |
---|
| 212 | for (UInt x = 0; x < width; x++) |
---|
| 213 | { |
---|
| 214 | ValueType value = 0; |
---|
| 215 | |
---|
| 216 | if (!onlyPrintEdges || (x == 0) || (y == 0)) |
---|
| 217 | { |
---|
| 218 | value = leftShift(source[printInZScan ? getZScanIndex(x, y) : ((y * stride) + x)], shiftLeftBy); |
---|
| 219 | valueSum += value; |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | writeValueToStream(value, stream, outputWidth); |
---|
| 223 | } |
---|
| 224 | stream << "\n"; |
---|
| 225 | } |
---|
| 226 | |
---|
| 227 | const Int valueCount = onlyPrintEdges ? Int((width + height) - 1) : Int(width * height); |
---|
[1246] | 228 | if (printAverage) |
---|
| 229 | { |
---|
| 230 | stream << "Average: " << (valueSum / valueCount) << "\n"; |
---|
| 231 | } |
---|
[919] | 232 | stream << "\n"; |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | |
---|
| 236 | template <typename T> |
---|
| 237 | Void 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 ) |
---|
| 238 | { |
---|
| 239 | for (UInt y=0; y<height; y++) |
---|
| 240 | { |
---|
| 241 | if (subBlockHeight!=0 && (y%subBlockHeight)==0 && y!=0) |
---|
[1246] | 242 | { |
---|
[919] | 243 | ss << pLinePrefix << '\n'; |
---|
[1246] | 244 | } |
---|
[919] | 245 | |
---|
| 246 | ss << pLinePrefix; |
---|
| 247 | for (UInt x=0; x<width; x++) |
---|
| 248 | { |
---|
| 249 | if (subBlockWidth!=0 && (x%subBlockWidth)==0 && x!=0) |
---|
[1246] | 250 | { |
---|
[919] | 251 | ss << std::setw(defWidth+2) << ""; |
---|
[1246] | 252 | } |
---|
[919] | 253 | |
---|
| 254 | ss << std::setw(defWidth) << blkSrc[y*stride + x] << ' '; |
---|
| 255 | } |
---|
| 256 | ss << '\n'; |
---|
| 257 | } |
---|
| 258 | } |
---|
| 259 | |
---|
| 260 | class TComYuv; |
---|
| 261 | Void printBlockToStream( std::ostream &ss, const Char *pLinePrefix, TComYuv &src, const UInt numSubBlocksAcross=1, const UInt numSubBlocksUp=1, const UInt defWidth=3 ); |
---|
| 262 | |
---|
| 263 | // ---------------------------------------------------------------------------------------------- // |
---|
| 264 | |
---|
| 265 | //String manipulation functions for aligning and wrapping printed text |
---|
| 266 | |
---|
| 267 | std::string splitOnSettings(const std::string &input); |
---|
| 268 | |
---|
| 269 | std::string lineWrap(const std::string &input, const UInt maximumLineLength); |
---|
| 270 | |
---|
| 271 | std::string indentNewLines(const std::string &input, const UInt indentBy); |
---|
| 272 | |
---|
| 273 | // ---------------------------------------------------------------------------------------------- // |
---|
| 274 | |
---|
| 275 | #ifdef DEBUG_STRING |
---|
| 276 | Int DebugStringGetPredModeMask(PredMode mode); |
---|
| 277 | Void DebugInterPredResiReco(std::string &sDebug, TComYuv &pred, TComYuv &resi, TComYuv &reco, Int predmode_mask); |
---|
| 278 | #endif |
---|
| 279 | |
---|
| 280 | |
---|
| 281 | #endif /* __DEBUG__ */ |
---|