Changeset 1200 in 3DVCSoftware for branches/HTM-14.1-update-dev0/source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp
- Timestamp:
- 4 May 2015, 18:38:08 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HTM-14.1-update-dev0/source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp
r1179 r1200 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; … … 184 187 Void TEncBinCABAC::encodeBin( UInt binValue, ContextModel &rcCtxModel ) 185 188 { 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 } 189 #if !NH_MV 190 //{ 191 // DTRACE_CABAC_VL( g_nSymbolCounter++ ) 192 // DTRACE_CABAC_T( "\tstate=" ) 193 // DTRACE_CABAC_V( ( rcCtxModel.getState() << 1 ) + rcCtxModel.getMps() ) 194 // DTRACE_CABAC_T( "\tsymbol=" ) 195 // DTRACE_CABAC_V( binValue ) 196 // DTRACE_CABAC_T( "\n" ) 197 //} 198 #endif 199 #if DEBUG_CABAC_BINS 200 const UInt startingRange = m_uiRange; 201 #endif 202 196 203 m_uiBinsCoded += m_binCountIncrement; 197 204 rcCtxModel.setBinsCoded( 1 ); 198 205 199 206 UInt uiLPS = TComCABACTables::sm_aucLPSTable[ rcCtxModel.getState() ][ ( m_uiRange >> 6 ) & 3 ]; 200 207 m_uiRange -= uiLPS; 201 208 202 209 if( binValue != rcCtxModel.getMps() ) 203 210 { … … 206 213 m_uiRange = uiLPS << numBits; 207 214 rcCtxModel.updateLPS(); 208 209 215 m_bitsLeft -= numBits; 216 testAndWriteOut(); 210 217 } 211 218 else 212 219 { 213 220 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(); 221 222 if ( m_uiRange < 256 ) 223 { 224 m_uiLow <<= 1; 225 m_uiRange <<= 1; 226 m_bitsLeft--; 227 testAndWriteOut(); 228 } 229 } 230 231 #if DEBUG_CABAC_BINS 232 if ((g_debugCounter + debugCabacBinWindow) >= debugCabacBinTargetLine) 233 { 234 std::cout << g_debugCounter << ": coding bin value " << binValue << ", range = [" << startingRange << "->" << m_uiRange << "]\n"; 235 } 236 237 if (g_debugCounter >= debugCabacBinTargetLine) 238 { 239 Char breakPointThis; 240 breakPointThis = 7; 241 } 242 if (g_debugCounter >= (debugCabacBinTargetLine + debugCabacBinWindow)) 243 { 244 exit(0); 245 } 246 247 g_debugCounter++; 248 #endif 225 249 } 226 250 … … 232 256 Void TEncBinCABAC::encodeBinEP( UInt binValue ) 233 257 { 234 { 235 #if !H_MV 258 if (false) 259 { 260 #if !NH_MV 236 261 DTRACE_CABAC_VL( g_nSymbolCounter++ ) 237 262 DTRACE_CABAC_T( "\tEPsymbol=" ) … … 240 265 #endif 241 266 } 267 242 268 m_uiBinsCoded += m_binCountIncrement; 269 270 if (m_uiRange == 256) 271 { 272 encodeAlignedBinsEP(binValue, 1); 273 return; 274 } 275 243 276 m_uiLow <<= 1; 244 277 if( binValue ) … … 247 280 } 248 281 m_bitsLeft--; 249 282 250 283 testAndWriteOut(); 251 284 } … … 260 293 { 261 294 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 295 296 if (false) 297 { 298 for ( Int i = 0; i < numBins; i++ ) 299 { 300 #if !NH_MV 301 DTRACE_CABAC_VL( g_nSymbolCounter++ ) 302 DTRACE_CABAC_T( "\tEPsymbol=" ) 303 DTRACE_CABAC_V( ( binValues >> ( numBins - 1 - i ) ) & 1 ) 304 DTRACE_CABAC_T( "\n" ) 305 #endif 306 } 307 } 308 309 if (m_uiRange == 256) 310 { 311 encodeAlignedBinsEP(binValues, numBins); 312 return; 313 } 314 273 315 while ( numBins > 8 ) 274 316 { 275 317 numBins -= 8; 276 UInt pattern = binValues >> numBins; 318 UInt pattern = binValues >> numBins; 277 319 m_uiLow <<= 8; 278 320 m_uiLow += m_uiRange * pattern; 279 321 binValues -= pattern << numBins; 280 322 m_bitsLeft -= 8; 281 323 282 324 testAndWriteOut(); 283 325 } 284 326 285 327 m_uiLow <<= numBins; 286 328 m_uiLow += m_uiRange * binValues; 287 329 m_bitsLeft -= numBins; 288 330 289 331 testAndWriteOut(); 332 } 333 334 Void TEncBinCABAC::align() 335 { 336 m_uiRange = 256; 337 } 338 339 Void TEncBinCABAC::encodeAlignedBinsEP( UInt binValues, Int numBins ) 340 { 341 Int binsRemaining = numBins; 342 343 assert(m_uiRange == 256); //aligned encode only works when range = 256 344 345 while (binsRemaining > 0) 346 { 347 const UInt binsToCode = std::min<UInt>(binsRemaining, 8); //code bytes if able to take advantage of the system's byte-write function 348 const UInt binMask = (1 << binsToCode) - 1; 349 350 const UInt newBins = (binValues >> (binsRemaining - binsToCode)) & binMask; 351 352 //The process of encoding an EP bin is the same as that of coding a normal 353 //bin where the symbol ranges for 1 and 0 are both half the range: 354 // 355 // low = (low + range/2) << 1 (to encode a 1) 356 // low = low << 1 (to encode a 0) 357 // 358 // i.e. 359 // low = (low + (bin * range/2)) << 1 360 // 361 // which is equivalent to: 362 // 363 // low = (low << 1) + (bin * range) 364 // 365 // this can be generalised for multiple bins, producing the following expression: 366 // 367 m_uiLow = (m_uiLow << binsToCode) + (newBins << 8); //range is known to be 256 368 369 binsRemaining -= binsToCode; 370 m_bitsLeft -= binsToCode; 371 372 testAndWriteOut(); 373 } 290 374 } 291 375 … … 314 398 m_uiLow <<= 1; 315 399 m_uiRange <<= 1; 316 m_bitsLeft--; 317 } 318 400 m_bitsLeft--; 401 } 402 319 403 testAndWriteOut(); 320 404 } … … 336 420 m_bitsLeft += 8; 337 421 m_uiLow &= 0xffffffffu >> m_bitsLeft; 338 422 339 423 if ( leadByte == 0xff ) 340 424 { … … 349 433 m_bufferedByte = leadByte & 0xff; 350 434 m_pcTComBitIf->write( byte, 8 ); 351 435 352 436 byte = ( 0xff + carry ) & 0xff; 353 437 while ( m_numBufferedBytes > 1 ) … … 361 445 m_numBufferedBytes = 1; 362 446 m_bufferedByte = leadByte; 363 } 364 } 447 } 448 } 365 449 } 366 450
Note: See TracChangeset for help on using the changeset viewer.