Add a byte to the scan buffer from the file - Handle stuff bytes - Handle restart markers PRE: - m_nScanBuffPtr POST: - m_nRestartRead - m_nRestartLastInd
| 1384 | // - m_nRestartLastInd |
| 1385 | // |
| 1386 | unsigned CimgDecode::BuffAddByte() |
| 1387 | { |
| 1388 | unsigned nMarker = 0x00; |
| 1389 | unsigned nBuf0,nBuf1; |
| 1390 | |
| 1391 | // If we have already read in a restart marker but not |
| 1392 | // handled it yet, then simply return without reading any |
| 1393 | // more bytes |
| 1394 | if (m_bRestartRead) { |
| 1395 | return 0; |
| 1396 | } |
| 1397 | |
| 1398 | nBuf0 = m_pWBuf->Buf(m_nScanBuffPtr); |
| 1399 | nBuf1 = m_pWBuf->Buf(m_nScanBuffPtr+1); |
| 1400 | |
| 1401 | // Check for restart marker first. Assume none back-to-back. |
| 1402 | if (nBuf0 == 0xFF) { |
| 1403 | nMarker = nBuf1; |
| 1404 | |
| 1405 | if ((nMarker >= JFIF_RST0) && (nMarker <= JFIF_RST7)) { |
| 1406 | |
| 1407 | if (m_bVerbose) { |
| 1408 | CString strTmp; |
| 1409 | strTmp.Format(_T(" RESTART marker: @ 0x%08X.0 : RST%02u"), |
| 1410 | m_nScanBuffPtr,nMarker-JFIF_RST0); |
| 1411 | m_pLog->AddLine(strTmp); |
| 1412 | } |
| 1413 | |
| 1414 | m_nRestartRead++; |
| 1415 | m_nRestartLastInd = nMarker - JFIF_RST0; |
| 1416 | if (m_nRestartLastInd != m_nRestartExpectInd) { |
| 1417 | if (!m_bScanErrorsDisable) { |
| 1418 | CString strTmp; |
| 1419 | strTmp.Format(_T(" ERROR: Expected RST marker index RST%u got RST%u @ 0x%08X.0"), |
| 1420 | m_nRestartExpectInd,m_nRestartLastInd,m_nScanBuffPtr); |
| 1421 | m_pLog->AddLineErr(strTmp); |
| 1422 | } |
| 1423 | } |
| 1424 | m_nRestartExpectInd = (m_nRestartLastInd+1)%8; |
| 1425 | |
| 1426 | // FIXME: Later on, we should be checking for RST out of sequence |
| 1427 | |
| 1428 | // END BUFFER READ HERE! |
| 1429 | // Indicate that a Restart marker has been seen, which |
| 1430 | // will prevent further reading of scan buffer until it |
| 1431 | // has been handled. |
| 1432 | m_bRestartRead = true; |
| 1433 | |
| 1434 | return 0; |
| 1435 | |
| 1436 | /* |
| 1437 | // Now we need to skip to the next bytes |
| 1438 | m_nScanBuffPtr+=2; |
| 1439 | |
| 1440 | // Update local saved buffer vars |
| 1441 | nBuf0 = m_pWBuf->Buf(m_nScanBuffPtr); |
| 1442 | nBuf1 = m_pWBuf->Buf(m_nScanBuffPtr+1); |
| 1443 |
nothing calls this directly
no test coverage detected