Changeset 1313 in 3DVCSoftware for trunk/source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp
- Timestamp:
- 13 Aug 2015, 17:38:13 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp
r1179 r1313 2 2 * License, included below. This software may be subject to other third party 3 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/IEC4 * granted under this license. 5 * 6 * Copyright (c) 2010-2015, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 38 38 #include "TEncBinCoderCABAC.h" 39 39 #include "TLibCommon/TComRom.h" 40 40 #include "TLibCommon/Debug.h" 41 41 42 42 //! \ingroup TLibEncoder … … 74 74 m_numBufferedBytes = 0; 75 75 m_bufferedByte = 0xff; 76 #if FAST_BIT_EST 77 m_fracBits = 0; 78 #endif 76 79 } 77 80 … … 100 103 m_pcTComBitIf->write( 0xff, 8 ); 101 104 m_numBufferedBytes--; 102 } 105 } 103 106 } 104 107 m_pcTComBitIf->write( m_uiLow >> 8, 24 - m_bitsLeft ); … … 143 146 } 144 147 145 Void TEncBinCABAC::copyState( TEncBinIf* pcTEncBinIf )146 { 147 TEncBinCABAC* pcTEncBinCABAC = pcTEncBinIf->getTEncBinCABAC();148 Void TEncBinCABAC::copyState( const TEncBinIf* pcTEncBinIf ) 149 { 150 const TEncBinCABAC* pcTEncBinCABAC = pcTEncBinIf->getTEncBinCABAC(); 148 151 m_uiLow = pcTEncBinCABAC->m_uiLow; 149 152 m_uiRange = pcTEncBinCABAC->m_uiRange; … … 153 156 #if FAST_BIT_EST 154 157 m_fracBits = pcTEncBinCABAC->m_fracBits; 158 D_PRINT_INDENT(g_traceEncFracBits, "CopyState " + n2s(m_fracBits) ); 155 159 #endif 156 160 } … … 167 171 } 168 172 #if FAST_BIT_EST 173 D_PRINT_INDENT( g_traceEncFracBits, "Reset Bits Before" + n2s(m_fracBits) ); 169 174 m_fracBits &= 32767; 175 D_PRINT_INDENT( g_traceEncFracBits, "Reset Bits " + n2s(m_fracBits) ); 170 176 #endif 171 177 } … … 184 190 Void TEncBinCABAC::encodeBin( UInt binValue, ContextModel &rcCtxModel ) 185 191 { 186 { 187 #if !H_MV 188 DTRACE_CABAC_VL( g_nSymbolCounter++ ) 189 DTRACE_CABAC_T( "\tstate=" ) 190 DTRACE_CABAC_V( ( rcCtxModel.getState() << 1 ) + rcCtxModel.getMps() ) 191 DTRACE_CABAC_T( "\tsymbol=" ) 192 DTRACE_CABAC_V( binValue ) 193 DTRACE_CABAC_T( "\n" ) 194 #endif 195 } 192 #if !NH_MV 193 //{ 194 // DTRACE_CABAC_VL( g_nSymbolCounter++ ) 195 // DTRACE_CABAC_T( "\tstate=" ) 196 // DTRACE_CABAC_V( ( rcCtxModel.getState() << 1 ) + rcCtxModel.getMps() ) 197 // DTRACE_CABAC_T( "\tsymbol=" ) 198 // DTRACE_CABAC_V( binValue ) 199 // DTRACE_CABAC_T( "\n" ) 200 //} 201 #endif 202 #if DEBUG_CABAC_BINS 203 const UInt startingRange = m_uiRange; 204 #endif 205 196 206 m_uiBinsCoded += m_binCountIncrement; 197 207 rcCtxModel.setBinsCoded( 1 ); 198 208 199 209 UInt uiLPS = TComCABACTables::sm_aucLPSTable[ rcCtxModel.getState() ][ ( m_uiRange >> 6 ) & 3 ]; 200 210 m_uiRange -= uiLPS; 201 211 202 212 if( binValue != rcCtxModel.getMps() ) 203 213 { … … 206 216 m_uiRange = uiLPS << numBits; 207 217 rcCtxModel.updateLPS(); 208 209 218 m_bitsLeft -= numBits; 219 testAndWriteOut(); 210 220 } 211 221 else 212 222 { 213 223 rcCtxModel.updateMPS(); 214 if ( m_uiRange >= 256 ) 215 { 216 return; 217 } 218 219 m_uiLow <<= 1; 220 m_uiRange <<= 1; 221 m_bitsLeft--; 222 } 223 224 testAndWriteOut(); 224 225 if ( m_uiRange < 256 ) 226 { 227 m_uiLow <<= 1; 228 m_uiRange <<= 1; 229 m_bitsLeft--; 230 testAndWriteOut(); 231 } 232 } 233 234 #if DEBUG_CABAC_BINS 235 if ((g_debugCounter + debugCabacBinWindow) >= debugCabacBinTargetLine) 236 { 237 std::cout << g_debugCounter << ": coding bin value " << binValue << ", range = [" << startingRange << "->" << m_uiRange << "]\n"; 238 } 239 240 if (g_debugCounter >= debugCabacBinTargetLine) 241 { 242 Char breakPointThis; 243 breakPointThis = 7; 244 } 245 if (g_debugCounter >= (debugCabacBinTargetLine + debugCabacBinWindow)) 246 { 247 exit(0); 248 } 249 250 g_debugCounter++; 251 #endif 225 252 } 226 253 … … 232 259 Void TEncBinCABAC::encodeBinEP( UInt binValue ) 233 260 { 234 { 235 #if !H_MV 261 if (false) 262 { 263 #if !NH_MV 236 264 DTRACE_CABAC_VL( g_nSymbolCounter++ ) 237 265 DTRACE_CABAC_T( "\tEPsymbol=" ) … … 240 268 #endif 241 269 } 270 242 271 m_uiBinsCoded += m_binCountIncrement; 272 273 if (m_uiRange == 256) 274 { 275 encodeAlignedBinsEP(binValue, 1); 276 return; 277 } 278 243 279 m_uiLow <<= 1; 244 280 if( binValue ) … … 247 283 } 248 284 m_bitsLeft--; 249 285 250 286 testAndWriteOut(); 251 287 } … … 260 296 { 261 297 m_uiBinsCoded += numBins & -m_binCountIncrement; 262 263 for ( Int i = 0; i < numBins; i++ ) 264 { 265 #if !H_MV 266 DTRACE_CABAC_VL( g_nSymbolCounter++ ) 267 DTRACE_CABAC_T( "\tEPsymbol=" ) 268 DTRACE_CABAC_V( ( binValues >> ( numBins - 1 - i ) ) & 1 ) 269 DTRACE_CABAC_T( "\n" ) 270 #endif 271 } 272 298 299 if (false) 300 { 301 for ( Int i = 0; i < numBins; i++ ) 302 { 303 #if !NH_MV 304 DTRACE_CABAC_VL( g_nSymbolCounter++ ) 305 DTRACE_CABAC_T( "\tEPsymbol=" ) 306 DTRACE_CABAC_V( ( binValues >> ( numBins - 1 - i ) ) & 1 ) 307 DTRACE_CABAC_T( "\n" ) 308 #endif 309 } 310 } 311 312 if (m_uiRange == 256) 313 { 314 encodeAlignedBinsEP(binValues, numBins); 315 return; 316 } 317 273 318 while ( numBins > 8 ) 274 319 { 275 320 numBins -= 8; 276 UInt pattern = binValues >> numBins; 321 UInt pattern = binValues >> numBins; 277 322 m_uiLow <<= 8; 278 323 m_uiLow += m_uiRange * pattern; 279 324 binValues -= pattern << numBins; 280 325 m_bitsLeft -= 8; 281 326 282 327 testAndWriteOut(); 283 328 } 284 329 285 330 m_uiLow <<= numBins; 286 331 m_uiLow += m_uiRange * binValues; 287 332 m_bitsLeft -= numBins; 288 333 289 334 testAndWriteOut(); 335 } 336 337 Void TEncBinCABAC::align() 338 { 339 m_uiRange = 256; 340 } 341 342 Void TEncBinCABAC::encodeAlignedBinsEP( UInt binValues, Int numBins ) 343 { 344 Int binsRemaining = numBins; 345 346 assert(m_uiRange == 256); //aligned encode only works when range = 256 347 348 while (binsRemaining > 0) 349 { 350 const UInt binsToCode = std::min<UInt>(binsRemaining, 8); //code bytes if able to take advantage of the system's byte-write function 351 const UInt binMask = (1 << binsToCode) - 1; 352 353 const UInt newBins = (binValues >> (binsRemaining - binsToCode)) & binMask; 354 355 //The process of encoding an EP bin is the same as that of coding a normal 356 //bin where the symbol ranges for 1 and 0 are both half the range: 357 // 358 // low = (low + range/2) << 1 (to encode a 1) 359 // low = low << 1 (to encode a 0) 360 // 361 // i.e. 362 // low = (low + (bin * range/2)) << 1 363 // 364 // which is equivalent to: 365 // 366 // low = (low << 1) + (bin * range) 367 // 368 // this can be generalised for multiple bins, producing the following expression: 369 // 370 m_uiLow = (m_uiLow << binsToCode) + (newBins << 8); //range is known to be 256 371 372 binsRemaining -= binsToCode; 373 m_bitsLeft -= binsToCode; 374 375 testAndWriteOut(); 376 } 290 377 } 291 378 … … 314 401 m_uiLow <<= 1; 315 402 m_uiRange <<= 1; 316 m_bitsLeft--; 317 } 318 403 m_bitsLeft--; 404 } 405 319 406 testAndWriteOut(); 320 407 } … … 336 423 m_bitsLeft += 8; 337 424 m_uiLow &= 0xffffffffu >> m_bitsLeft; 338 425 339 426 if ( leadByte == 0xff ) 340 427 { … … 349 436 m_bufferedByte = leadByte & 0xff; 350 437 m_pcTComBitIf->write( byte, 8 ); 351 438 352 439 byte = ( 0xff + carry ) & 0xff; 353 440 while ( m_numBufferedBytes > 1 ) … … 361 448 m_numBufferedBytes = 1; 362 449 m_bufferedByte = leadByte; 363 } 364 } 450 } 451 } 365 452 } 366 453
Note: See TracChangeset for help on using the changeset viewer.