📄 lzma.diff
字号:
} len = 0; }@@ -246,15 +455,16 @@ else previousByte = dictionary[dictionaryPos - 1]; + #ifdef _LZMA_IN_CB+ rd.Result = LZMA_RESULT_OK;+ #endif+ rd.ExtraBytes = 0;+ #else /* if !_LZMA_OUT_READ */ int state = 0; UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1; int len = 0;- const Byte *Buffer;- const Byte *BufferLim;- UInt32 Range;- UInt32 Code; #ifndef _LZMA_IN_CB *inSizeProcessed = 0;@@ -269,17 +479,26 @@ } #ifdef _LZMA_IN_CB- RC_INIT;- #else- RC_INIT(inStream, inSize);+ rd.InCallback = InCallback; #endif+ RangeDecoderInit(&rd+ #ifndef _LZMA_IN_CB+ , inStream, inSize+ #endif+ ); + #ifdef _LZMA_IN_CB+ if (rd.Result != LZMA_RESULT_OK)+ return rd.Result;+ #endif+ if (rd.ExtraBytes != 0)+ return LZMA_RESULT_DATA_ERROR;+ #endif /* _LZMA_OUT_READ */ + while(nowPos < outSize) {- CProb *prob;- UInt32 bound; int posState = (int)( (nowPos #ifdef _LZMA_OUT_READ@@ -287,13 +506,15 @@ #endif ) & posStateMask);-- prob = p + IsMatch + (state << kNumPosBitsMax) + posState;- IfBit0(prob)+ #ifdef _LZMA_IN_CB+ if (rd.Result != LZMA_RESULT_OK)+ return rd.Result;+ #endif+ if (rd.ExtraBytes != 0)+ return LZMA_RESULT_DATA_ERROR;+ if (RangeDecoderBitDecode(p + IsMatch + (state << kNumPosBitsMax) + posState, &rd) == 0) {- int symbol = 1;- UpdateBit0(prob)- prob = p + Literal + (LZMA_LIT_SIZE * + CProb *probs = p + Literal + (LZMA_LIT_SIZE * ((( (nowPos #ifdef _LZMA_OUT_READ@@ -304,7 +525,7 @@ if (state >= kNumLitStates) {- int matchByte;+ Byte matchByte; #ifdef _LZMA_OUT_READ UInt32 pos = dictionaryPos - rep0; if (pos >= dictionarySize)@@ -313,24 +534,10 @@ #else matchByte = outStream[nowPos - rep0]; #endif- do- {- int bit;- CProb *probLit;- matchByte <<= 1;- bit = (matchByte & 0x100);- probLit = prob + 0x100 + bit + symbol;- RC_GET_BIT2(probLit, symbol, if (bit != 0) break, if (bit == 0) break)- }- while (symbol < 0x100);+ previousByte = LzmaLiteralDecodeMatch(probs, &rd, matchByte); }- while (symbol < 0x100)- {- CProb *probLit = prob + symbol;- RC_GET_BIT(probLit, symbol)- }- previousByte = (Byte)symbol;-+ else+ previousByte = LzmaLiteralDecode(probs, &rd); outStream[nowPos++] = previousByte; #ifdef _LZMA_OUT_READ if (distanceLimit < dictionarySize)@@ -346,40 +553,24 @@ } else {- UpdateBit1(prob);- prob = p + IsRep + state;- IfBit0(prob)+ if (RangeDecoderBitDecode(p + IsRep + state, &rd) == 1) {- UpdateBit0(prob);- rep3 = rep2;- rep2 = rep1;- rep1 = rep0;- state = state < kNumLitStates ? 0 : 3;- prob = p + LenCoder;- }- else- {- UpdateBit1(prob);- prob = p + IsRepG0 + state;- IfBit0(prob)+ if (RangeDecoderBitDecode(p + IsRepG0 + state, &rd) == 0) {- UpdateBit0(prob);- prob = p + IsRep0Long + (state << kNumPosBitsMax) + posState;- IfBit0(prob)+ if (RangeDecoderBitDecode(p + IsRep0Long + (state << kNumPosBitsMax) + posState, &rd) == 0) { #ifdef _LZMA_OUT_READ UInt32 pos; #endif- UpdateBit0(prob);- + #ifdef _LZMA_OUT_READ if (distanceLimit == 0) #else if (nowPos == 0) #endif return LZMA_RESULT_DATA_ERROR;- - state = state < kNumLitStates ? 9 : 11;++ state = state < 7 ? 9 : 11; #ifdef _LZMA_OUT_READ pos = dictionaryPos - rep0; if (pos >= dictionarySize)@@ -392,40 +583,25 @@ previousByte = outStream[nowPos - rep0]; #endif outStream[nowPos++] = previousByte;+ #ifdef _LZMA_OUT_READ if (distanceLimit < dictionarySize) distanceLimit++; #endif- continue; }- else- {- UpdateBit1(prob);- } } else { UInt32 distance;- UpdateBit1(prob);- prob = p + IsRepG1 + state;- IfBit0(prob)- {- UpdateBit0(prob);+ if(RangeDecoderBitDecode(p + IsRepG1 + state, &rd) == 0) distance = rep1;- } else {- UpdateBit1(prob);- prob = p + IsRepG2 + state;- IfBit0(prob)- {- UpdateBit0(prob);+ if(RangeDecoderBitDecode(p + IsRepG2 + state, &rd) == 0) distance = rep2;- } else {- UpdateBit1(prob); distance = rep3; rep3 = rep2; }@@ -434,89 +610,35 @@ rep1 = rep0; rep0 = distance; }- state = state < kNumLitStates ? 8 : 11;- prob = p + RepLenCoder;+ len = LzmaLenDecode(p + RepLenCoder, &rd, posState);+ state = state < 7 ? 8 : 11; }+ else {- int numBits, offset;- CProb *probLen = prob + LenChoice;- IfBit0(probLen)- {- UpdateBit0(probLen);- probLen = prob + LenLow + (posState << kLenNumLowBits);- offset = 0;- numBits = kLenNumLowBits;- }- else- {- UpdateBit1(probLen);- probLen = prob + LenChoice2;- IfBit0(probLen)- {- UpdateBit0(probLen);- probLen = prob + LenMid + (posState << kLenNumMidBits);- offset = kLenNumLowSymbols;- numBits = kLenNumMidBits;- }- else- {- UpdateBit1(probLen);- probLen = prob + LenHigh;- offset = kLenNumLowSymbols + kLenNumMidSymbols;- numBits = kLenNumHighBits;- }- }- RangeDecoderBitTreeDecode(probLen, numBits, len);- len += offset;- }-- if (state < 4)- { int posSlot;- state += kNumLitStates;- prob = p + PosSlot ++ rep3 = rep2;+ rep2 = rep1;+ rep1 = rep0;+ state = state < 7 ? 7 : 10;+ len = LzmaLenDecode(p + LenCoder, &rd, posState);+ posSlot = RangeDecoderBitTreeDecode(p + PosSlot + ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << - kNumPosSlotBits);- RangeDecoderBitTreeDecode(prob, kNumPosSlotBits, posSlot);+ kNumPosSlotBits), kNumPosSlotBits, &rd); if (posSlot >= kStartPosModelIndex) { int numDirectBits = ((posSlot >> 1) - 1);- rep0 = (2 | ((UInt32)posSlot & 1));+ rep0 = ((2 | ((UInt32)posSlot & 1)) << numDirectBits); if (posSlot < kEndPosModelIndex) {- rep0 <<= numDirectBits;- prob = p + SpecPos + rep0 - posSlot - 1;+ rep0 += RangeDecoderReverseBitTreeDecode(+ p + SpecPos + rep0 - posSlot - 1, numDirectBits, &rd); } else {- numDirectBits -= kNumAlignBits;- do- {- RC_NORMALIZE- Range >>= 1;- rep0 <<= 1;- if (Code >= Range)- {- Code -= Range;- rep0 |= 1;- }- }- while (--numDirectBits != 0);- prob = p + Align;- rep0 <<= kNumAlignBits;- numDirectBits = kNumAlignBits;+ rep0 += RangeDecoderDecodeDirectBits(&rd, + numDirectBits - kNumAlignBits) << kNumAlignBits;+ rep0 += RangeDecoderReverseBitTreeDecode(p + Align, kNumAlignBits, &rd); }- {- int i = 1;- int mi = 1;- do- {- CProb *prob3 = prob + mi;- RC_GET_BIT2(prob3, mi, ; , rep0 |= i);- i <<= 1;- }- while(--numDirectBits != 0);- } } else rep0 = posSlot;@@ -562,11 +684,11 @@ while(len != 0 && nowPos < outSize); } }- RC_NORMALIZE; + #ifdef _LZMA_OUT_READ- vs->Range = Range;- vs->Code = Code;+ vs->Range = rd.Range;+ vs->Code = rd.Code; vs->DictionaryPos = dictionaryPos; vs->GlobalPos = globalPos + (UInt32)nowPos; vs->DistanceLimit = distanceLimit;@@ -580,10 +702,10 @@ #endif #ifdef _LZMA_IN_CB- vs->Buffer = Buffer;- vs->BufferLim = BufferLim;+ vs->Buffer = rd.Buffer;+ vs->BufferLim = rd.BufferLim; #else- *inSizeProcessed = (SizeT)(Buffer - inStream);+ *inSizeProcessed = (SizeT)(rd.Buffer - inStream); #endif *outSizeProcessed = nowPos; return LZMA_RESULT_OK;Index: LzmaDecode.h===================================================================--- LzmaDecode.h (revision 8777)+++ LzmaDecode.h (working copy)@@ -2,7 +2,7 @@ LzmaDecode.h LZMA Decoder interface - LZMA SDK 4.21 Copyright (c) 1999-2005 Igor Pavlov (2005-06-08)+ LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01) http://www.7-zip.org/ LZMA SDK is licensed under two licenses:@@ -22,6 +22,8 @@ #ifndef __LZMADECODE_H #define __LZMADECODE_H +#include "LzmaTypes.h"+ /* #define _LZMA_IN_CB */ /* Use callback for input data */ @@ -35,30 +37,10 @@ /* #define _LZMA_LOC_OPT */ /* Enable local speed optimizations inside code */ -/* #define _LZMA_SYSTEM_SIZE_T */-/* Use system's size_t. You can use it to enable 64-bit sizes supporting*/--#ifndef UInt32-#ifdef _LZMA_UINT32_IS_ULONG-#define UInt32 unsigned long-#else-#define UInt32 unsigned int-#endif-#endif--#ifndef SizeT-#ifdef _LZMA_SYSTEM_SIZE_T-#include <stddef.h>-#define SizeT size_t-#else-#define SizeT UInt32-#endif-#endif- #ifdef _LZMA_PROB32 #define CProb UInt32 #else-#define CProb unsigned short+#define CProb UInt16 #endif #define LZMA_RESULT_OK 0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -