Decode the DHT marker segment (Huffman Tables) In some cases (such as for MotionJPEG), we fake out the DHT tables (when bInject=true) with a standard table as each JPEG frame in the MJPG does not include the DHT. In all other cases (bInject=false), we simply read the DHT table from the file buffer via Buf() ITU-T standard indicates that we can expect up to a maximum of 16-bit huffman code bitstri
| 3399 | // ITU-T standard indicates that we can expect up to a |
| 3400 | // maximum of 16-bit huffman code bitstrings. |
| 3401 | void CjfifDecode::DecodeDHT(bool bInject) |
| 3402 | { |
| 3403 | unsigned nLength; |
| 3404 | unsigned nTmpVal; |
| 3405 | CString strTmp,strFull; |
| 3406 | unsigned nPosEnd; |
| 3407 | unsigned nPosSaved = 0; |
| 3408 | |
| 3409 | bool bRet; |
| 3410 | |
| 3411 | |
| 3412 | if (bInject) { |
| 3413 | // Redirect Buf() to DHT table in MJPGDHTSeg[] |
| 3414 | // ... so change mode that Buf() call uses |
| 3415 | m_bBufFakeDHT = true; |
| 3416 | |
| 3417 | // Preserve the "m_nPos" pointer, at end we undo it |
| 3418 | // And we also start at 2 which is just after FFC4 in array |
| 3419 | nPosSaved = m_nPos; |
| 3420 | m_nPos = 2; |
| 3421 | } |
| 3422 | |
| 3423 | nLength = Buf(m_nPos)*256 + Buf(m_nPos+1); |
| 3424 | nPosEnd = m_nPos+nLength; |
| 3425 | m_nPos+=2; |
| 3426 | strTmp.Format(_T(" Huffman table length = %u"),nLength); |
| 3427 | m_pLog->AddLine(strTmp); |
| 3428 | |
| 3429 | unsigned nDhtClass_Tc; // Range 0..1 |
| 3430 | unsigned nDhtHuffTblId_Th; // Range 0..3 |
| 3431 | |
| 3432 | // In various places, added m_bStateAbort check to allow us |
| 3433 | // to escape in case we get in excessive number of DHT entries |
| 3434 | // See BUG FIX #1003 |
| 3435 | |
| 3436 | while ((!m_bStateAbort)&&(nPosEnd > m_nPos)) |
| 3437 | { |
| 3438 | m_pLog->AddLine(_T(" ----")); |
| 3439 | |
| 3440 | nTmpVal = Buf(m_nPos++); |
| 3441 | nDhtClass_Tc = (nTmpVal & 0xF0) >> 4; // Tc, range 0..1 |
| 3442 | nDhtHuffTblId_Th = nTmpVal & 0x0F; // Th, range 0..3 |
| 3443 | strTmp.Format(_T(" Destination ID = %u"),nDhtHuffTblId_Th); |
| 3444 | m_pLog->AddLine(strTmp); |
| 3445 | strTmp.Format(_T(" Class = %u (%s)"),nDhtClass_Tc,(nDhtClass_Tc?_T("AC Table"):_T("DC / Lossless Table"))); |
| 3446 | m_pLog->AddLine(strTmp); |
| 3447 | |
| 3448 | // Add in some error checking to prevent |
| 3449 | if (nDhtClass_Tc >= MAX_DHT_CLASS) { |
| 3450 | strTmp.Format(_T("ERROR: Invalid DHT Class (%u). Aborting DHT Load."),nDhtClass_Tc); |
| 3451 | m_pLog->AddLineErr(strTmp); |
| 3452 | m_nPos = nPosEnd; |
| 3453 | //m_bStateAbort = true; // Stop decoding |
| 3454 | break; |
| 3455 | } |
| 3456 | if (nDhtHuffTblId_Th >= MAX_DHT_DEST_ID) { |
| 3457 | strTmp.Format(_T("ERROR: Invalid DHT Dest ID (%u). Aborting DHT Load."),nDhtHuffTblId_Th); |
| 3458 | m_pLog->AddLineErr(strTmp); |
nothing calls this directly
no test coverage detected