Lines Matching refs:p

47 void LzmaEncProps_Init(CLzmaEncProps *p)  in LzmaEncProps_Init()  argument
49 p->level = 5; in LzmaEncProps_Init()
50 p->dictSize = p->mc = 0; in LzmaEncProps_Init()
51 p->reduceSize = (UInt64)(Int64)-1; in LzmaEncProps_Init()
52 p->lc = p->lp = p->pb = p->algo = p->fb = p->btMode = p->numHashBytes = p->numThreads = -1; in LzmaEncProps_Init()
53 p->writeEndMark = 0; in LzmaEncProps_Init()
56 void LzmaEncProps_Normalize(CLzmaEncProps *p) in LzmaEncProps_Normalize() argument
58 int level = p->level; in LzmaEncProps_Normalize()
60 p->level = level; in LzmaEncProps_Normalize()
61 …if (p->dictSize == 0) p->dictSize = (level <= 5 ? (1 << (level * 2 + 14)) : (level == 6 ? (1 << 25… in LzmaEncProps_Normalize()
62 if (p->dictSize > p->reduceSize) in LzmaEncProps_Normalize()
67 if ((UInt32)p->reduceSize <= ((UInt32)2 << i)) { p->dictSize = ((UInt32)2 << i); break; } in LzmaEncProps_Normalize()
68 if ((UInt32)p->reduceSize <= ((UInt32)3 << i)) { p->dictSize = ((UInt32)3 << i); break; } in LzmaEncProps_Normalize()
71 if (p->lc < 0) p->lc = 3; in LzmaEncProps_Normalize()
72 if (p->lp < 0) p->lp = 0; in LzmaEncProps_Normalize()
73 if (p->pb < 0) p->pb = 2; in LzmaEncProps_Normalize()
74 if (p->algo < 0) p->algo = (level < 5 ? 0 : 1); in LzmaEncProps_Normalize()
75 if (p->fb < 0) p->fb = (level < 7 ? 32 : 64); in LzmaEncProps_Normalize()
76 if (p->btMode < 0) p->btMode = (p->algo == 0 ? 0 : 1); in LzmaEncProps_Normalize()
77 if (p->numHashBytes < 0) p->numHashBytes = 4; in LzmaEncProps_Normalize()
78 if (p->mc == 0) p->mc = (16 + (p->fb >> 1)) >> (p->btMode ? 0 : 1); in LzmaEncProps_Normalize()
79 if (p->numThreads < 0) in LzmaEncProps_Normalize()
80 p->numThreads = in LzmaEncProps_Normalize()
82 ((p->btMode && p->algo) ? 2 : 1); in LzmaEncProps_Normalize()
136 res = p->g_FastPos[pos >> i] + (i * 2); }
143 #define GetPosSlot1(pos) p->g_FastPos[pos]
145 #define GetPosSlot(pos, res) { if (pos < kNumFullDistances) res = p->g_FastPos[pos]; else BSR2_RET(…
227 CLenEnc p; member
352 CLzmaEnc *p = (CLzmaEnc *)pp; in LzmaEnc_SaveState() local
353 CSaveState *dest = &p->saveState; in LzmaEnc_SaveState()
355 dest->lenEnc = p->lenEnc; in LzmaEnc_SaveState()
356 dest->repLenEnc = p->repLenEnc; in LzmaEnc_SaveState()
357 dest->state = p->state; in LzmaEnc_SaveState()
361 memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i])); in LzmaEnc_SaveState()
362 memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i])); in LzmaEnc_SaveState()
365 memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i])); in LzmaEnc_SaveState()
366 memcpy(dest->isRep, p->isRep, sizeof(p->isRep)); in LzmaEnc_SaveState()
367 memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0)); in LzmaEnc_SaveState()
368 memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1)); in LzmaEnc_SaveState()
369 memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2)); in LzmaEnc_SaveState()
370 memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders)); in LzmaEnc_SaveState()
371 memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder)); in LzmaEnc_SaveState()
372 memcpy(dest->reps, p->reps, sizeof(p->reps)); in LzmaEnc_SaveState()
373 memcpy(dest->litProbs, p->litProbs, (0x300 << p->lclp) * sizeof(CLzmaProb)); in LzmaEnc_SaveState()
379 const CSaveState *p = &dest->saveState; in LzmaEnc_RestoreState() local
381 dest->lenEnc = p->lenEnc; in LzmaEnc_RestoreState()
382 dest->repLenEnc = p->repLenEnc; in LzmaEnc_RestoreState()
383 dest->state = p->state; in LzmaEnc_RestoreState()
387 memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i])); in LzmaEnc_RestoreState()
388 memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i])); in LzmaEnc_RestoreState()
391 memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i])); in LzmaEnc_RestoreState()
392 memcpy(dest->isRep, p->isRep, sizeof(p->isRep)); in LzmaEnc_RestoreState()
393 memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0)); in LzmaEnc_RestoreState()
394 memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1)); in LzmaEnc_RestoreState()
395 memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2)); in LzmaEnc_RestoreState()
396 memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders)); in LzmaEnc_RestoreState()
397 memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder)); in LzmaEnc_RestoreState()
398 memcpy(dest->reps, p->reps, sizeof(p->reps)); in LzmaEnc_RestoreState()
399 memcpy(dest->litProbs, p->litProbs, (0x300 << dest->lclp) * sizeof(CLzmaProb)); in LzmaEnc_RestoreState()
404 CLzmaEnc *p = (CLzmaEnc *)pp; in LzmaEnc_SetProps() local
411 p->dictSize = props.dictSize; in LzmaEnc_SetProps()
418 p->numFastBytes = fb; in LzmaEnc_SetProps()
420 p->lc = props.lc; in LzmaEnc_SetProps()
421 p->lp = props.lp; in LzmaEnc_SetProps()
422 p->pb = props.pb; in LzmaEnc_SetProps()
423 p->fastMode = (props.algo == 0); in LzmaEnc_SetProps()
424 p->matchFinderBase.btMode = props.btMode; in LzmaEnc_SetProps()
434 p->matchFinderBase.numHashBytes = numHashBytes; in LzmaEnc_SetProps()
437 p->matchFinderBase.cutValue = props.mc; in LzmaEnc_SetProps()
439 p->writeEndMark = props.writeEndMark; in LzmaEnc_SetProps()
449 p->multiThread = (props.numThreads > 1); in LzmaEnc_SetProps()
466 static void RangeEnc_Construct(CRangeEnc *p) in RangeEnc_Construct() argument
468 p->outStream = 0; in RangeEnc_Construct()
469 p->bufBase = 0; in RangeEnc_Construct()
472 #define RangeEnc_GetProcessed(p) ((p)->processed + ((p)->buf - (p)->bufBase) + (p)->cacheSize) argument
475 static int RangeEnc_Alloc(CRangeEnc *p, ISzAlloc *alloc) in RangeEnc_Alloc() argument
477 if (p->bufBase == 0) in RangeEnc_Alloc()
479 p->bufBase = (Byte *)alloc->Alloc(alloc, RC_BUF_SIZE); in RangeEnc_Alloc()
480 if (p->bufBase == 0) in RangeEnc_Alloc()
482 p->bufLim = p->bufBase + RC_BUF_SIZE; in RangeEnc_Alloc()
487 static void RangeEnc_Free(CRangeEnc *p, ISzAlloc *alloc) in RangeEnc_Free() argument
489 alloc->Free(alloc, p->bufBase); in RangeEnc_Free()
490 p->bufBase = 0; in RangeEnc_Free()
493 static void RangeEnc_Init(CRangeEnc *p) in RangeEnc_Init() argument
496 p->low = 0; in RangeEnc_Init()
497 p->range = 0xFFFFFFFF; in RangeEnc_Init()
498 p->cacheSize = 1; in RangeEnc_Init()
499 p->cache = 0; in RangeEnc_Init()
501 p->buf = p->bufBase; in RangeEnc_Init()
503 p->processed = 0; in RangeEnc_Init()
504 p->res = SZ_OK; in RangeEnc_Init()
507 static void RangeEnc_FlushStream(CRangeEnc *p) in RangeEnc_FlushStream() argument
510 if (p->res != SZ_OK) in RangeEnc_FlushStream()
512 num = p->buf - p->bufBase; in RangeEnc_FlushStream()
513 if (num != p->outStream->Write(p->outStream, p->bufBase, num)) in RangeEnc_FlushStream()
514 p->res = SZ_ERROR_WRITE; in RangeEnc_FlushStream()
515 p->processed += num; in RangeEnc_FlushStream()
516 p->buf = p->bufBase; in RangeEnc_FlushStream()
519 static void MY_FAST_CALL RangeEnc_ShiftLow(CRangeEnc *p) in RangeEnc_ShiftLow() argument
521 if ((UInt32)p->low < (UInt32)0xFF000000 || (unsigned)(p->low >> 32) != 0) in RangeEnc_ShiftLow()
523 Byte temp = p->cache; in RangeEnc_ShiftLow()
526 Byte *buf = p->buf; in RangeEnc_ShiftLow()
527 *buf++ = (Byte)(temp + (Byte)(p->low >> 32)); in RangeEnc_ShiftLow()
528 p->buf = buf; in RangeEnc_ShiftLow()
529 if (buf == p->bufLim) in RangeEnc_ShiftLow()
530 RangeEnc_FlushStream(p); in RangeEnc_ShiftLow()
533 while (--p->cacheSize != 0); in RangeEnc_ShiftLow()
534 p->cache = (Byte)((UInt32)p->low >> 24); in RangeEnc_ShiftLow()
536 p->cacheSize++; in RangeEnc_ShiftLow()
537 p->low = (UInt32)p->low << 8; in RangeEnc_ShiftLow()
540 static void RangeEnc_FlushData(CRangeEnc *p) in RangeEnc_FlushData() argument
544 RangeEnc_ShiftLow(p); in RangeEnc_FlushData()
547 static void RangeEnc_EncodeDirectBits(CRangeEnc *p, UInt32 value, unsigned numBits) in RangeEnc_EncodeDirectBits() argument
551 p->range >>= 1; in RangeEnc_EncodeDirectBits()
552 p->low += p->range & (0 - ((value >> --numBits) & 1)); in RangeEnc_EncodeDirectBits()
553 if (p->range < kTopValue) in RangeEnc_EncodeDirectBits()
555 p->range <<= 8; in RangeEnc_EncodeDirectBits()
556 RangeEnc_ShiftLow(p); in RangeEnc_EncodeDirectBits()
562 static void RangeEnc_EncodeBit(CRangeEnc *p, CLzmaProb *prob, UInt32 symbol) in RangeEnc_EncodeBit() argument
565 UInt32 newBound = (p->range >> kNumBitModelTotalBits) * ttt; in RangeEnc_EncodeBit()
568 p->range = newBound; in RangeEnc_EncodeBit()
573 p->low += newBound; in RangeEnc_EncodeBit()
574 p->range -= newBound; in RangeEnc_EncodeBit()
578 if (p->range < kTopValue) in RangeEnc_EncodeBit()
580 p->range <<= 8; in RangeEnc_EncodeBit()
581 RangeEnc_ShiftLow(p); in RangeEnc_EncodeBit()
585 static void LitEnc_Encode(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol) in LitEnc_Encode() argument
590 RangeEnc_EncodeBit(p, probs + (symbol >> 8), (symbol >> 7) & 1); in LitEnc_Encode()
596 static void LitEnc_EncodeMatched(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol, UInt32 matchByte) in LitEnc_EncodeMatched() argument
603 RangeEnc_EncodeBit(p, probs + (offs + (matchByte & offs) + (symbol >> 8)), (symbol >> 7) & 1); in LitEnc_EncodeMatched()
635 p->ProbPrices[((prob) ^ (((-(int)(symbol))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];
640 #define GET_PRICE_0(prob) p->ProbPrices[(prob) >> kNumMoveReducingBits]
641 #define GET_PRICE_1(prob) p->ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]
731 static void LenEnc_Init(CLenEnc *p) in LenEnc_Init() argument
734 p->choice = p->choice2 = kProbInitValue; in LenEnc_Init()
736 p->low[i] = kProbInitValue; in LenEnc_Init()
738 p->mid[i] = kProbInitValue; in LenEnc_Init()
740 p->high[i] = kProbInitValue; in LenEnc_Init()
743 static void LenEnc_Encode(CLenEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32 posState) in LenEnc_Encode() argument
747 RangeEnc_EncodeBit(rc, &p->choice, 0); in LenEnc_Encode()
748 RcTree_Encode(rc, p->low + (posState << kLenNumLowBits), kLenNumLowBits, symbol); in LenEnc_Encode()
752 RangeEnc_EncodeBit(rc, &p->choice, 1); in LenEnc_Encode()
755 RangeEnc_EncodeBit(rc, &p->choice2, 0); in LenEnc_Encode()
756 …RcTree_Encode(rc, p->mid + (posState << kLenNumMidBits), kLenNumMidBits, symbol - kLenNumLowSymbol… in LenEnc_Encode()
760 RangeEnc_EncodeBit(rc, &p->choice2, 1); in LenEnc_Encode()
761 RcTree_Encode(rc, p->high, kLenNumHighBits, symbol - kLenNumLowSymbols - kLenNumMidSymbols); in LenEnc_Encode()
766 static void LenEnc_SetPrices(CLenEnc *p, UInt32 posState, UInt32 numSymbols, UInt32 *prices, UInt32… in LenEnc_SetPrices() argument
768 UInt32 a0 = GET_PRICE_0a(p->choice); in LenEnc_SetPrices()
769 UInt32 a1 = GET_PRICE_1a(p->choice); in LenEnc_SetPrices()
770 UInt32 b0 = a1 + GET_PRICE_0a(p->choice2); in LenEnc_SetPrices()
771 UInt32 b1 = a1 + GET_PRICE_1a(p->choice2); in LenEnc_SetPrices()
777 …prices[i] = a0 + RcTree_GetPrice(p->low + (posState << kLenNumLowBits), kLenNumLowBits, i, ProbPri… in LenEnc_SetPrices()
783 …prices[i] = b0 + RcTree_GetPrice(p->mid + (posState << kLenNumMidBits), kLenNumMidBits, i - kLenNu… in LenEnc_SetPrices()
786 …prices[i] = b1 + RcTree_GetPrice(p->high, kLenNumHighBits, i - kLenNumLowSymbols - kLenNumMidSymbo… in LenEnc_SetPrices()
789 static void MY_FAST_CALL LenPriceEnc_UpdateTable(CLenPriceEnc *p, UInt32 posState, UInt32 *ProbPric… in LenPriceEnc_UpdateTable() argument
791 LenEnc_SetPrices(&p->p, posState, p->tableSize, p->prices[posState], ProbPrices); in LenPriceEnc_UpdateTable()
792 p->counters[posState] = p->tableSize; in LenPriceEnc_UpdateTable()
795 static void LenPriceEnc_UpdateTables(CLenPriceEnc *p, UInt32 numPosStates, UInt32 *ProbPrices) in LenPriceEnc_UpdateTables() argument
799 LenPriceEnc_UpdateTable(p, posState, ProbPrices); in LenPriceEnc_UpdateTables()
802 static void LenEnc_Encode2(CLenPriceEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32 posState, Bool upd… in LenEnc_Encode2() argument
804 LenEnc_Encode(&p->p, rc, symbol, posState); in LenEnc_Encode2()
806 if (--p->counters[posState] == 0) in LenEnc_Encode2()
807 LenPriceEnc_UpdateTable(p, posState, ProbPrices); in LenEnc_Encode2()
813 static void MovePos(CLzmaEnc *p, UInt32 num) in MovePos() argument
822 p->additionalOffset += num; in MovePos()
823 p->matchFinder.Skip(p->matchFinderObj, num); in MovePos()
827 static UInt32 ReadMatchDistances(CLzmaEnc *p, UInt32 *numDistancePairsRes) in ReadMatchDistances() argument
830 p->numAvail = p->matchFinder.GetNumAvailableBytes(p->matchFinderObj); in ReadMatchDistances()
831 numPairs = p->matchFinder.GetMatches(p->matchFinderObj, p->matches); in ReadMatchDistances()
839 printf("%2d %6d | ", p->matches[i], p->matches[i + 1]); in ReadMatchDistances()
845 lenRes = p->matches[numPairs - 2]; in ReadMatchDistances()
846 if (lenRes == p->numFastBytes) in ReadMatchDistances()
848 const Byte *pby = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1; in ReadMatchDistances()
849 UInt32 distance = p->matches[numPairs - 1] + 1; in ReadMatchDistances()
850 UInt32 numAvail = p->numAvail; in ReadMatchDistances()
859 p->additionalOffset++; in ReadMatchDistances()
865 #define MakeAsChar(p) (p)->backPrev = (UInt32)(-1); (p)->prev1IsChar = False; argument
866 #define MakeAsShortRep(p) (p)->backPrev = 0; (p)->prev1IsChar = False; argument
867 #define IsShortRep(p) ((p)->backPrev == 0) argument
869 static UInt32 GetRepLen1Price(CLzmaEnc *p, UInt32 state, UInt32 posState) in GetRepLen1Price() argument
872 GET_PRICE_0(p->isRepG0[state]) + in GetRepLen1Price()
873 GET_PRICE_0(p->isRep0Long[state][posState]); in GetRepLen1Price()
876 static UInt32 GetPureRepPrice(CLzmaEnc *p, UInt32 repIndex, UInt32 state, UInt32 posState) in GetPureRepPrice() argument
881 price = GET_PRICE_0(p->isRepG0[state]); in GetPureRepPrice()
882 price += GET_PRICE_1(p->isRep0Long[state][posState]); in GetPureRepPrice()
886 price = GET_PRICE_1(p->isRepG0[state]); in GetPureRepPrice()
888 price += GET_PRICE_0(p->isRepG1[state]); in GetPureRepPrice()
891 price += GET_PRICE_1(p->isRepG1[state]); in GetPureRepPrice()
892 price += GET_PRICE(p->isRepG2[state], repIndex - 2); in GetPureRepPrice()
898 static UInt32 GetRepPrice(CLzmaEnc *p, UInt32 repIndex, UInt32 len, UInt32 state, UInt32 posState) in GetRepPrice() argument
900 return p->repLenEnc.prices[posState][len - LZMA_MATCH_LEN_MIN] + in GetRepPrice()
901 GetPureRepPrice(p, repIndex, state, posState); in GetRepPrice()
904 static UInt32 Backward(CLzmaEnc *p, UInt32 *backRes, UInt32 cur) in Backward() argument
906 UInt32 posMem = p->opt[cur].posPrev; in Backward()
907 UInt32 backMem = p->opt[cur].backPrev; in Backward()
908 p->optimumEndIndex = cur; in Backward()
911 if (p->opt[cur].prev1IsChar) in Backward()
913 MakeAsChar(&p->opt[posMem]) in Backward()
914 p->opt[posMem].posPrev = posMem - 1; in Backward()
915 if (p->opt[cur].prev2) in Backward()
917 p->opt[posMem - 1].prev1IsChar = False; in Backward()
918 p->opt[posMem - 1].posPrev = p->opt[cur].posPrev2; in Backward()
919 p->opt[posMem - 1].backPrev = p->opt[cur].backPrev2; in Backward()
926 backMem = p->opt[posPrev].backPrev; in Backward()
927 posMem = p->opt[posPrev].posPrev; in Backward()
929 p->opt[posPrev].backPrev = backCur; in Backward()
930 p->opt[posPrev].posPrev = cur; in Backward()
935 *backRes = p->opt[0].backPrev; in Backward()
936 p->optimumCurrentIndex = p->opt[0].posPrev; in Backward()
937 return p->optimumCurrentIndex; in Backward()
940 #define LIT_PROBS(pos, prevByte) (p->litProbs + ((((pos) & p->lpMask) << p->lc) + ((prevByte) >> (8…
942 static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) in GetOptimum() argument
950 if (p->optimumEndIndex != p->optimumCurrentIndex) in GetOptimum()
952 const COptimal *opt = &p->opt[p->optimumCurrentIndex]; in GetOptimum()
953 UInt32 lenRes = opt->posPrev - p->optimumCurrentIndex; in GetOptimum()
955 p->optimumCurrentIndex = opt->posPrev; in GetOptimum()
958 p->optimumCurrentIndex = p->optimumEndIndex = 0; in GetOptimum()
960 if (p->additionalOffset == 0) in GetOptimum()
961 mainLen = ReadMatchDistances(p, &numPairs); in GetOptimum()
964 mainLen = p->longestMatchLength; in GetOptimum()
965 numPairs = p->numPairs; in GetOptimum()
968 numAvail = p->numAvail; in GetOptimum()
977 data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1; in GetOptimum()
983 reps[i] = p->reps[i]; in GetOptimum()
995 if (repLens[repMaxIndex] >= p->numFastBytes) in GetOptimum()
1000 MovePos(p, lenRes - 1); in GetOptimum()
1004 matches = p->matches; in GetOptimum()
1005 if (mainLen >= p->numFastBytes) in GetOptimum()
1008 MovePos(p, mainLen - 1); in GetOptimum()
1020 p->opt[0].state = (CState)p->state; in GetOptimum()
1022 posState = (position & p->pbMask); in GetOptimum()
1026 p->opt[1].price = GET_PRICE_0(p->isMatch[p->state][posState]) + in GetOptimum()
1027 (!IsCharState(p->state) ? in GetOptimum()
1028 LitEnc_GetPriceMatched(probs, curByte, matchByte, p->ProbPrices) : in GetOptimum()
1029 LitEnc_GetPrice(probs, curByte, p->ProbPrices)); in GetOptimum()
1032 MakeAsChar(&p->opt[1]); in GetOptimum()
1034 matchPrice = GET_PRICE_1(p->isMatch[p->state][posState]); in GetOptimum()
1035 repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[p->state]); in GetOptimum()
1039 UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(p, p->state, posState); in GetOptimum()
1040 if (shortRepPrice < p->opt[1].price) in GetOptimum()
1042 p->opt[1].price = shortRepPrice; in GetOptimum()
1043 MakeAsShortRep(&p->opt[1]); in GetOptimum()
1050 *backRes = p->opt[1].backPrev; in GetOptimum()
1054 p->opt[1].posPrev = 0; in GetOptimum()
1056 p->opt[0].backs[i] = reps[i]; in GetOptimum()
1060 p->opt[len--].price = kInfinityPrice; in GetOptimum()
1069 price = repMatchPrice + GetPureRepPrice(p, i, p->state, posState); in GetOptimum()
1072 UInt32 curAndLenPrice = price + p->repLenEnc.prices[posState][repLen - 2]; in GetOptimum()
1073 COptimal *opt = &p->opt[repLen]; in GetOptimum()
1085 normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[p->state]); in GetOptimum()
1098 … UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][len - LZMA_MATCH_LEN_MIN]; in GetOptimum()
1101 curAndLenPrice += p->distancesPrices[lenToPosState][distance]; in GetOptimum()
1106 … curAndLenPrice += p->alignPrices[distance & kAlignMask] + p->posSlotPrices[lenToPosState][slot]; in GetOptimum()
1108 opt = &p->opt[len]; in GetOptimum()
1133 printf("\nprice[%4X] = %d", position - cur + i, p->opt[i].price); in GetOptimum()
1149 return Backward(p, backRes, cur); in GetOptimum()
1151 newLen = ReadMatchDistances(p, &numPairs); in GetOptimum()
1152 if (newLen >= p->numFastBytes) in GetOptimum()
1154 p->numPairs = numPairs; in GetOptimum()
1155 p->longestMatchLength = newLen; in GetOptimum()
1156 return Backward(p, backRes, cur); in GetOptimum()
1159 curOpt = &p->opt[cur]; in GetOptimum()
1166 state = p->opt[curOpt->posPrev2].state; in GetOptimum()
1173 state = p->opt[posPrev].state; in GetOptimum()
1177 state = p->opt[posPrev].state; in GetOptimum()
1203 prevOpt = &p->opt[posPrev]; in GetOptimum()
1230 data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1; in GetOptimum()
1234 posState = (position & p->pbMask); in GetOptimum()
1236 curAnd1Price = curPrice + GET_PRICE_0(p->isMatch[state][posState]); in GetOptimum()
1241 LitEnc_GetPriceMatched(probs, curByte, matchByte, p->ProbPrices) : in GetOptimum()
1242 LitEnc_GetPrice(probs, curByte, p->ProbPrices)); in GetOptimum()
1245 nextOpt = &p->opt[cur + 1]; in GetOptimum()
1255 matchPrice = curPrice + GET_PRICE_1(p->isMatch[state][posState]); in GetOptimum()
1256 repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[state]); in GetOptimum()
1260 UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(p, state, posState); in GetOptimum()
1269 numAvailFull = p->numAvail; in GetOptimum()
1278 numAvail = (numAvailFull <= p->numFastBytes ? numAvailFull : p->numFastBytes); in GetOptimum()
1286 UInt32 limit = p->numFastBytes + 1; in GetOptimum()
1295 UInt32 posStateNext = (position + 1) & p->pbMask; in GetOptimum()
1297 GET_PRICE_1(p->isMatch[state2][posStateNext]) + in GetOptimum()
1298 GET_PRICE_1(p->isRep[state2]); in GetOptimum()
1305 p->opt[++lenEnd].price = kInfinityPrice; in GetOptimum()
1306 curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext); in GetOptimum()
1307 opt = &p->opt[offset]; in GetOptimum()
1333 p->opt[++lenEnd].price = kInfinityPrice; in GetOptimum()
1335 price = repMatchPrice + GetPureRepPrice(p, repIndex, state, posState); in GetOptimum()
1338 UInt32 curAndLenPrice = price + p->repLenEnc.prices[posState][lenTest - 2]; in GetOptimum()
1339 COptimal *opt = &p->opt[cur + lenTest]; in GetOptimum()
1357 UInt32 limit = lenTest2 + p->numFastBytes; in GetOptimum()
1366 UInt32 posStateNext = (position + lenTest) & p->pbMask; in GetOptimum()
1368 price + p->repLenEnc.prices[posState][lenTest - 2] + in GetOptimum()
1369 GET_PRICE_0(p->isMatch[state2][posStateNext]) + in GetOptimum()
1371 data[lenTest], data2[lenTest], p->ProbPrices); in GetOptimum()
1373 posStateNext = (position + lenTest + 1) & p->pbMask; in GetOptimum()
1375 GET_PRICE_1(p->isMatch[state2][posStateNext]) + in GetOptimum()
1376 GET_PRICE_1(p->isRep[state2]); in GetOptimum()
1384 p->opt[++lenEnd].price = kInfinityPrice; in GetOptimum()
1385 … curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext); in GetOptimum()
1386 opt = &p->opt[offset]; in GetOptimum()
1412 UInt32 normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[state]); in GetOptimum()
1416 p->opt[++lenEnd].price = kInfinityPrice; in GetOptimum()
1425 …UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][lenTest - LZMA_MATCH_LEN_MIN… in GetOptimum()
1429 curAndLenPrice += p->distancesPrices[lenToPosState][curBack]; in GetOptimum()
1431 … curAndLenPrice += p->posSlotPrices[lenToPosState][posSlot] + p->alignPrices[curBack & kAlignMask]; in GetOptimum()
1433 opt = &p->opt[cur + lenTest]; in GetOptimum()
1447 UInt32 limit = lenTest2 + p->numFastBytes; in GetOptimum()
1456 UInt32 posStateNext = (position + lenTest) & p->pbMask; in GetOptimum()
1458 GET_PRICE_0(p->isMatch[state2][posStateNext]) + in GetOptimum()
1460 data[lenTest], data2[lenTest], p->ProbPrices); in GetOptimum()
1462 posStateNext = (posStateNext + 1) & p->pbMask; in GetOptimum()
1464 GET_PRICE_1(p->isMatch[state2][posStateNext]) + in GetOptimum()
1465 GET_PRICE_1(p->isRep[state2]); in GetOptimum()
1473 p->opt[++lenEnd].price = kInfinityPrice; in GetOptimum()
1474 … curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext); in GetOptimum()
1475 opt = &p->opt[offset]; in GetOptimum()
1502 static UInt32 GetOptimumFast(CLzmaEnc *p, UInt32 *backRes) in GetOptimumFast() argument
1508 if (p->additionalOffset == 0) in GetOptimumFast()
1509 mainLen = ReadMatchDistances(p, &numPairs); in GetOptimumFast()
1512 mainLen = p->longestMatchLength; in GetOptimumFast()
1513 numPairs = p->numPairs; in GetOptimumFast()
1516 numAvail = p->numAvail; in GetOptimumFast()
1522 data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1; in GetOptimumFast()
1528 const Byte *data2 = data - (p->reps[i] + 1); in GetOptimumFast()
1532 if (len >= p->numFastBytes) in GetOptimumFast()
1535 MovePos(p, len - 1); in GetOptimumFast()
1545 matches = p->matches; in GetOptimumFast()
1546 if (mainLen >= p->numFastBytes) in GetOptimumFast()
1549 MovePos(p, mainLen - 1); in GetOptimumFast()
1575 MovePos(p, repLen - 1); in GetOptimumFast()
1582 p->longestMatchLength = ReadMatchDistances(p, &p->numPairs); in GetOptimumFast()
1583 if (p->longestMatchLength >= 2) in GetOptimumFast()
1585 UInt32 newDistance = matches[p->numPairs - 1]; in GetOptimumFast()
1586 if ((p->longestMatchLength >= mainLen && newDistance < mainDist) || in GetOptimumFast()
1587 (p->longestMatchLength == mainLen + 1 && !ChangePair(mainDist, newDistance)) || in GetOptimumFast()
1588 (p->longestMatchLength > mainLen + 1) || in GetOptimumFast()
1589 (p->longestMatchLength + 1 >= mainLen && mainLen >= 3 && ChangePair(newDistance, mainDist))) in GetOptimumFast()
1593 data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1; in GetOptimumFast()
1597 const Byte *data2 = data - (p->reps[i] + 1); in GetOptimumFast()
1606 MovePos(p, mainLen - 2); in GetOptimumFast()
1610 static void WriteEndMarker(CLzmaEnc *p, UInt32 posState) in WriteEndMarker() argument
1613 RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 1); in WriteEndMarker()
1614 RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0); in WriteEndMarker()
1615 p->state = kMatchNextStates[p->state]; in WriteEndMarker()
1617 …LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices… in WriteEndMarker()
1618 …RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, (1 << kNumPosSlot… in WriteEndMarker()
1619 RangeEnc_EncodeDirectBits(&p->rc, (((UInt32)1 << 30) - 1) >> kNumAlignBits, 30 - kNumAlignBits); in WriteEndMarker()
1620 RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, kAlignMask); in WriteEndMarker()
1623 static SRes CheckErrors(CLzmaEnc *p) in CheckErrors() argument
1625 if (p->result != SZ_OK) in CheckErrors()
1626 return p->result; in CheckErrors()
1627 if (p->rc.res != SZ_OK) in CheckErrors()
1628 p->result = SZ_ERROR_WRITE; in CheckErrors()
1629 if (p->matchFinderBase.result != SZ_OK) in CheckErrors()
1630 p->result = SZ_ERROR_READ; in CheckErrors()
1631 if (p->result != SZ_OK) in CheckErrors()
1632 p->finished = True; in CheckErrors()
1633 return p->result; in CheckErrors()
1636 static SRes Flush(CLzmaEnc *p, UInt32 nowPos) in Flush() argument
1639 p->finished = True; in Flush()
1640 if (p->writeEndMark) in Flush()
1641 WriteEndMarker(p, nowPos & p->pbMask); in Flush()
1642 RangeEnc_FlushData(&p->rc); in Flush()
1643 RangeEnc_FlushStream(&p->rc); in Flush()
1644 return CheckErrors(p); in Flush()
1647 static void FillAlignPrices(CLzmaEnc *p) in FillAlignPrices() argument
1651 p->alignPrices[i] = RcTree_ReverseGetPrice(p->posAlignEncoder, kNumAlignBits, i, p->ProbPrices); in FillAlignPrices()
1652 p->alignPriceCount = 0; in FillAlignPrices()
1655 static void FillDistancesPrices(CLzmaEnc *p) in FillDistancesPrices() argument
1664 …tempPrices[i] = RcTree_ReverseGetPrice(p->posEncoders + base - posSlot - 1, footerBits, i - base, in FillDistancesPrices()
1670 const CLzmaProb *encoder = p->posSlotEncoder[lenToPosState]; in FillDistancesPrices()
1671 UInt32 *posSlotPrices = p->posSlotPrices[lenToPosState]; in FillDistancesPrices()
1672 for (posSlot = 0; posSlot < p->distTableSize; posSlot++) in FillDistancesPrices()
1673 posSlotPrices[posSlot] = RcTree_GetPrice(encoder, kNumPosSlotBits, posSlot, p->ProbPrices); in FillDistancesPrices()
1674 for (posSlot = kEndPosModelIndex; posSlot < p->distTableSize; posSlot++) in FillDistancesPrices()
1678 UInt32 *distancesPrices = p->distancesPrices[lenToPosState]; in FillDistancesPrices()
1686 p->matchPriceCount = 0; in FillDistancesPrices()
1689 void LzmaEnc_Construct(CLzmaEnc *p) in LzmaEnc_Construct() argument
1691 RangeEnc_Construct(&p->rc); in LzmaEnc_Construct()
1692 MatchFinder_Construct(&p->matchFinderBase); in LzmaEnc_Construct()
1694 MatchFinderMt_Construct(&p->matchFinderMt); in LzmaEnc_Construct()
1695 p->matchFinderMt.MatchFinder = &p->matchFinderBase; in LzmaEnc_Construct()
1701 LzmaEnc_SetProps(p, &props); in LzmaEnc_Construct()
1705 LzmaEnc_FastPosInit(p->g_FastPos); in LzmaEnc_Construct()
1708 LzmaEnc_InitPriceTables(p->ProbPrices); in LzmaEnc_Construct()
1709 p->litProbs = 0; in LzmaEnc_Construct()
1710 p->saveState.litProbs = 0; in LzmaEnc_Construct()
1715 void *p; in LzmaEnc_Create() local
1716 p = alloc->Alloc(alloc, sizeof(CLzmaEnc)); in LzmaEnc_Create()
1717 if (p != 0) in LzmaEnc_Create()
1718 LzmaEnc_Construct((CLzmaEnc *)p); in LzmaEnc_Create()
1719 return p; in LzmaEnc_Create()
1722 void LzmaEnc_FreeLits(CLzmaEnc *p, ISzAlloc *alloc) in LzmaEnc_FreeLits() argument
1724 alloc->Free(alloc, p->litProbs); in LzmaEnc_FreeLits()
1725 alloc->Free(alloc, p->saveState.litProbs); in LzmaEnc_FreeLits()
1726 p->litProbs = 0; in LzmaEnc_FreeLits()
1727 p->saveState.litProbs = 0; in LzmaEnc_FreeLits()
1730 void LzmaEnc_Destruct(CLzmaEnc *p, ISzAlloc *alloc, ISzAlloc *allocBig) in LzmaEnc_Destruct() argument
1733 MatchFinderMt_Destruct(&p->matchFinderMt, allocBig); in LzmaEnc_Destruct()
1735 MatchFinder_Free(&p->matchFinderBase, allocBig); in LzmaEnc_Destruct()
1736 LzmaEnc_FreeLits(p, alloc); in LzmaEnc_Destruct()
1737 RangeEnc_Free(&p->rc, alloc); in LzmaEnc_Destruct()
1740 void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig) in LzmaEnc_Destroy() argument
1742 LzmaEnc_Destruct((CLzmaEnc *)p, alloc, allocBig); in LzmaEnc_Destroy()
1743 alloc->Free(alloc, p); in LzmaEnc_Destroy()
1746 static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize, UInt32 maxUnpackS… in LzmaEnc_CodeOneBlock() argument
1749 if (p->needInit) in LzmaEnc_CodeOneBlock()
1751 p->matchFinder.Init(p->matchFinderObj); in LzmaEnc_CodeOneBlock()
1752 p->needInit = 0; in LzmaEnc_CodeOneBlock()
1755 if (p->finished) in LzmaEnc_CodeOneBlock()
1756 return p->result; in LzmaEnc_CodeOneBlock()
1757 RINOK(CheckErrors(p)); in LzmaEnc_CodeOneBlock()
1759 nowPos32 = (UInt32)p->nowPos64; in LzmaEnc_CodeOneBlock()
1762 if (p->nowPos64 == 0) in LzmaEnc_CodeOneBlock()
1766 if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0) in LzmaEnc_CodeOneBlock()
1767 return Flush(p, nowPos32); in LzmaEnc_CodeOneBlock()
1768 ReadMatchDistances(p, &numPairs); in LzmaEnc_CodeOneBlock()
1769 RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][0], 0); in LzmaEnc_CodeOneBlock()
1770 p->state = kLiteralNextStates[p->state]; in LzmaEnc_CodeOneBlock()
1771 curByte = p->matchFinder.GetIndexByte(p->matchFinderObj, 0 - p->additionalOffset); in LzmaEnc_CodeOneBlock()
1772 LitEnc_Encode(&p->rc, p->litProbs, curByte); in LzmaEnc_CodeOneBlock()
1773 p->additionalOffset--; in LzmaEnc_CodeOneBlock()
1777 if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) != 0) in LzmaEnc_CodeOneBlock()
1782 if (p->fastMode) in LzmaEnc_CodeOneBlock()
1783 len = GetOptimumFast(p, &pos); in LzmaEnc_CodeOneBlock()
1785 len = GetOptimum(p, nowPos32, &pos); in LzmaEnc_CodeOneBlock()
1791 posState = nowPos32 & p->pbMask; in LzmaEnc_CodeOneBlock()
1798 RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 0); in LzmaEnc_CodeOneBlock()
1799 data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset; in LzmaEnc_CodeOneBlock()
1802 if (IsCharState(p->state)) in LzmaEnc_CodeOneBlock()
1803 LitEnc_Encode(&p->rc, probs, curByte); in LzmaEnc_CodeOneBlock()
1805 LitEnc_EncodeMatched(&p->rc, probs, curByte, *(data - p->reps[0] - 1)); in LzmaEnc_CodeOneBlock()
1806 p->state = kLiteralNextStates[p->state]; in LzmaEnc_CodeOneBlock()
1810 RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 1); in LzmaEnc_CodeOneBlock()
1813 RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 1); in LzmaEnc_CodeOneBlock()
1816 RangeEnc_EncodeBit(&p->rc, &p->isRepG0[p->state], 0); in LzmaEnc_CodeOneBlock()
1817 RangeEnc_EncodeBit(&p->rc, &p->isRep0Long[p->state][posState], ((len == 1) ? 0 : 1)); in LzmaEnc_CodeOneBlock()
1821 UInt32 distance = p->reps[pos]; in LzmaEnc_CodeOneBlock()
1822 RangeEnc_EncodeBit(&p->rc, &p->isRepG0[p->state], 1); in LzmaEnc_CodeOneBlock()
1824 RangeEnc_EncodeBit(&p->rc, &p->isRepG1[p->state], 0); in LzmaEnc_CodeOneBlock()
1827 RangeEnc_EncodeBit(&p->rc, &p->isRepG1[p->state], 1); in LzmaEnc_CodeOneBlock()
1828 RangeEnc_EncodeBit(&p->rc, &p->isRepG2[p->state], pos - 2); in LzmaEnc_CodeOneBlock()
1830 p->reps[3] = p->reps[2]; in LzmaEnc_CodeOneBlock()
1831 p->reps[2] = p->reps[1]; in LzmaEnc_CodeOneBlock()
1833 p->reps[1] = p->reps[0]; in LzmaEnc_CodeOneBlock()
1834 p->reps[0] = distance; in LzmaEnc_CodeOneBlock()
1837 p->state = kShortRepNextStates[p->state]; in LzmaEnc_CodeOneBlock()
1840 …LenEnc_Encode2(&p->repLenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPri… in LzmaEnc_CodeOneBlock()
1841 p->state = kRepNextStates[p->state]; in LzmaEnc_CodeOneBlock()
1847 RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0); in LzmaEnc_CodeOneBlock()
1848 p->state = kMatchNextStates[p->state]; in LzmaEnc_CodeOneBlock()
1849 …LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices… in LzmaEnc_CodeOneBlock()
1852 RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, posSlot); in LzmaEnc_CodeOneBlock()
1861 … RcTree_ReverseEncode(&p->rc, p->posEncoders + base - posSlot - 1, footerBits, posReduced); in LzmaEnc_CodeOneBlock()
1864 … RangeEnc_EncodeDirectBits(&p->rc, posReduced >> kNumAlignBits, footerBits - kNumAlignBits); in LzmaEnc_CodeOneBlock()
1865 … RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, posReduced & kAlignMask); in LzmaEnc_CodeOneBlock()
1866 p->alignPriceCount++; in LzmaEnc_CodeOneBlock()
1869 p->reps[3] = p->reps[2]; in LzmaEnc_CodeOneBlock()
1870 p->reps[2] = p->reps[1]; in LzmaEnc_CodeOneBlock()
1871 p->reps[1] = p->reps[0]; in LzmaEnc_CodeOneBlock()
1872 p->reps[0] = pos; in LzmaEnc_CodeOneBlock()
1873 p->matchPriceCount++; in LzmaEnc_CodeOneBlock()
1876 p->additionalOffset -= len; in LzmaEnc_CodeOneBlock()
1878 if (p->additionalOffset == 0) in LzmaEnc_CodeOneBlock()
1881 if (!p->fastMode) in LzmaEnc_CodeOneBlock()
1883 if (p->matchPriceCount >= (1 << 7)) in LzmaEnc_CodeOneBlock()
1884 FillDistancesPrices(p); in LzmaEnc_CodeOneBlock()
1885 if (p->alignPriceCount >= kAlignTableSize) in LzmaEnc_CodeOneBlock()
1886 FillAlignPrices(p); in LzmaEnc_CodeOneBlock()
1888 if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0) in LzmaEnc_CodeOneBlock()
1894 RangeEnc_GetProcessed(&p->rc) + kNumOpts * 2 >= maxPackSize) in LzmaEnc_CodeOneBlock()
1899 p->nowPos64 += nowPos32 - startPos32; in LzmaEnc_CodeOneBlock()
1900 return CheckErrors(p); in LzmaEnc_CodeOneBlock()
1904 p->nowPos64 += nowPos32 - startPos32; in LzmaEnc_CodeOneBlock()
1905 return Flush(p, nowPos32); in LzmaEnc_CodeOneBlock()
1910 static SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig) in LzmaEnc_Alloc() argument
1913 if (!RangeEnc_Alloc(&p->rc, alloc)) in LzmaEnc_Alloc()
1916 p->mtMode = (p->multiThread && !p->fastMode && (p->matchFinderBase.btMode != 0)); in LzmaEnc_Alloc()
1920 unsigned lclp = p->lc + p->lp; in LzmaEnc_Alloc()
1921 if (p->litProbs == 0 || p->saveState.litProbs == 0 || p->lclp != lclp) in LzmaEnc_Alloc()
1923 LzmaEnc_FreeLits(p, alloc); in LzmaEnc_Alloc()
1924 p->litProbs = (CLzmaProb *)alloc->Alloc(alloc, (0x300 << lclp) * sizeof(CLzmaProb)); in LzmaEnc_Alloc()
1925 p->saveState.litProbs = (CLzmaProb *)alloc->Alloc(alloc, (0x300 << lclp) * sizeof(CLzmaProb)); in LzmaEnc_Alloc()
1926 if (p->litProbs == 0 || p->saveState.litProbs == 0) in LzmaEnc_Alloc()
1928 LzmaEnc_FreeLits(p, alloc); in LzmaEnc_Alloc()
1931 p->lclp = lclp; in LzmaEnc_Alloc()
1935 p->matchFinderBase.bigHash = (p->dictSize > kBigHashDicLimit); in LzmaEnc_Alloc()
1937 if (beforeSize + p->dictSize < keepWindowSize) in LzmaEnc_Alloc()
1938 beforeSize = keepWindowSize - p->dictSize; in LzmaEnc_Alloc()
1941 if (p->mtMode) in LzmaEnc_Alloc()
1943 …RINOK(MatchFinderMt_Create(&p->matchFinderMt, p->dictSize, beforeSize, p->numFastBytes, LZMA_MATCH… in LzmaEnc_Alloc()
1944 p->matchFinderObj = &p->matchFinderMt; in LzmaEnc_Alloc()
1945 MatchFinderMt_CreateVTable(&p->matchFinderMt, &p->matchFinder); in LzmaEnc_Alloc()
1950 …if (!MatchFinder_Create(&p->matchFinderBase, p->dictSize, beforeSize, p->numFastBytes, LZMA_MATCH_… in LzmaEnc_Alloc()
1952 p->matchFinderObj = &p->matchFinderBase; in LzmaEnc_Alloc()
1953 MatchFinder_CreateVTable(&p->matchFinderBase, &p->matchFinder); in LzmaEnc_Alloc()
1958 void LzmaEnc_Init(CLzmaEnc *p) in LzmaEnc_Init() argument
1961 p->state = 0; in LzmaEnc_Init()
1963 p->reps[i] = 0; in LzmaEnc_Init()
1965 RangeEnc_Init(&p->rc); in LzmaEnc_Init()
1973 p->isMatch[i][j] = kProbInitValue; in LzmaEnc_Init()
1974 p->isRep0Long[i][j] = kProbInitValue; in LzmaEnc_Init()
1976 p->isRep[i] = kProbInitValue; in LzmaEnc_Init()
1977 p->isRepG0[i] = kProbInitValue; in LzmaEnc_Init()
1978 p->isRepG1[i] = kProbInitValue; in LzmaEnc_Init()
1979 p->isRepG2[i] = kProbInitValue; in LzmaEnc_Init()
1983 UInt32 num = 0x300 << (p->lp + p->lc); in LzmaEnc_Init()
1985 p->litProbs[i] = kProbInitValue; in LzmaEnc_Init()
1991 CLzmaProb *probs = p->posSlotEncoder[i]; in LzmaEnc_Init()
1999 p->posEncoders[i] = kProbInitValue; in LzmaEnc_Init()
2002 LenEnc_Init(&p->lenEnc.p); in LzmaEnc_Init()
2003 LenEnc_Init(&p->repLenEnc.p); in LzmaEnc_Init()
2006 p->posAlignEncoder[i] = kProbInitValue; in LzmaEnc_Init()
2008 p->optimumEndIndex = 0; in LzmaEnc_Init()
2009 p->optimumCurrentIndex = 0; in LzmaEnc_Init()
2010 p->additionalOffset = 0; in LzmaEnc_Init()
2012 p->pbMask = (1 << p->pb) - 1; in LzmaEnc_Init()
2013 p->lpMask = (1 << p->lp) - 1; in LzmaEnc_Init()
2016 void LzmaEnc_InitPrices(CLzmaEnc *p) in LzmaEnc_InitPrices() argument
2018 if (!p->fastMode) in LzmaEnc_InitPrices()
2020 FillDistancesPrices(p); in LzmaEnc_InitPrices()
2021 FillAlignPrices(p); in LzmaEnc_InitPrices()
2024 p->lenEnc.tableSize = in LzmaEnc_InitPrices()
2025 p->repLenEnc.tableSize = in LzmaEnc_InitPrices()
2026 p->numFastBytes + 1 - LZMA_MATCH_LEN_MIN; in LzmaEnc_InitPrices()
2027 LenPriceEnc_UpdateTables(&p->lenEnc, 1 << p->pb, p->ProbPrices); in LzmaEnc_InitPrices()
2028 LenPriceEnc_UpdateTables(&p->repLenEnc, 1 << p->pb, p->ProbPrices); in LzmaEnc_InitPrices()
2031 static SRes LzmaEnc_AllocAndInit(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *all… in LzmaEnc_AllocAndInit() argument
2035 if (p->dictSize <= ((UInt32)1 << i)) in LzmaEnc_AllocAndInit()
2037 p->distTableSize = i * 2; in LzmaEnc_AllocAndInit()
2039 p->finished = False; in LzmaEnc_AllocAndInit()
2040 p->result = SZ_OK; in LzmaEnc_AllocAndInit()
2041 RINOK(LzmaEnc_Alloc(p, keepWindowSize, alloc, allocBig)); in LzmaEnc_AllocAndInit()
2042 LzmaEnc_Init(p); in LzmaEnc_AllocAndInit()
2043 LzmaEnc_InitPrices(p); in LzmaEnc_AllocAndInit()
2044 p->nowPos64 = 0; in LzmaEnc_AllocAndInit()
2051 CLzmaEnc *p = (CLzmaEnc *)pp; in LzmaEnc_Prepare() local
2052 p->matchFinderBase.stream = inStream; in LzmaEnc_Prepare()
2053 p->needInit = 1; in LzmaEnc_Prepare()
2054 p->rc.outStream = outStream; in LzmaEnc_Prepare()
2055 return LzmaEnc_AllocAndInit(p, 0, alloc, allocBig); in LzmaEnc_Prepare()
2062 CLzmaEnc *p = (CLzmaEnc *)pp; in LzmaEnc_PrepareForLzma2() local
2063 p->matchFinderBase.stream = inStream; in LzmaEnc_PrepareForLzma2()
2064 p->needInit = 1; in LzmaEnc_PrepareForLzma2()
2065 return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig); in LzmaEnc_PrepareForLzma2()
2068 static void LzmaEnc_SetInputBuf(CLzmaEnc *p, const Byte *src, SizeT srcLen) in LzmaEnc_SetInputBuf() argument
2070 p->matchFinderBase.directInput = 1; in LzmaEnc_SetInputBuf()
2071 p->matchFinderBase.bufferBase = (Byte *)src; in LzmaEnc_SetInputBuf()
2072 p->matchFinderBase.directInputRem = srcLen; in LzmaEnc_SetInputBuf()
2078 CLzmaEnc *p = (CLzmaEnc *)pp; in LzmaEnc_MemPrepare() local
2079 LzmaEnc_SetInputBuf(p, src, srcLen); in LzmaEnc_MemPrepare()
2080 p->needInit = 1; in LzmaEnc_MemPrepare()
2082 return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig); in LzmaEnc_MemPrepare()
2088 CLzmaEnc *p = (CLzmaEnc *)pp; in LzmaEnc_Finish() local
2089 if (p->mtMode) in LzmaEnc_Finish()
2090 MatchFinderMt_ReleaseStream(&p->matchFinderMt); in LzmaEnc_Finish()
2106 CSeqOutStreamBuf *p = (CSeqOutStreamBuf *)pp; in MyWrite() local
2107 if (p->rem < size) in MyWrite()
2109 size = p->rem; in MyWrite()
2110 p->overflow = True; in MyWrite()
2112 memcpy(p->data, data, size); in MyWrite()
2113 p->rem -= size; in MyWrite()
2114 p->data += size; in MyWrite()
2121 const CLzmaEnc *p = (CLzmaEnc *)pp; in LzmaEnc_GetNumAvailableBytes() local
2122 return p->matchFinder.GetNumAvailableBytes(p->matchFinderObj); in LzmaEnc_GetNumAvailableBytes()
2127 const CLzmaEnc *p = (CLzmaEnc *)pp; in LzmaEnc_GetCurBuf() local
2128 return p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset; in LzmaEnc_GetCurBuf()
2134 CLzmaEnc *p = (CLzmaEnc *)pp; in LzmaEnc_CodeOneMemBlock() local
2144 p->writeEndMark = False; in LzmaEnc_CodeOneMemBlock()
2145 p->finished = False; in LzmaEnc_CodeOneMemBlock()
2146 p->result = SZ_OK; in LzmaEnc_CodeOneMemBlock()
2149 LzmaEnc_Init(p); in LzmaEnc_CodeOneMemBlock()
2150 LzmaEnc_InitPrices(p); in LzmaEnc_CodeOneMemBlock()
2151 nowPos64 = p->nowPos64; in LzmaEnc_CodeOneMemBlock()
2152 RangeEnc_Init(&p->rc); in LzmaEnc_CodeOneMemBlock()
2153 p->rc.outStream = &outStream.funcTable; in LzmaEnc_CodeOneMemBlock()
2155 res = LzmaEnc_CodeOneBlock(p, True, desiredPackSize, *unpackSize); in LzmaEnc_CodeOneMemBlock()
2157 *unpackSize = (UInt32)(p->nowPos64 - nowPos64); in LzmaEnc_CodeOneMemBlock()
2165 static SRes LzmaEnc_Encode2(CLzmaEnc *p, ICompressProgress *progress) in LzmaEnc_Encode2() argument
2177 res = LzmaEnc_CodeOneBlock(p, False, 0, 0); in LzmaEnc_Encode2()
2178 if (res != SZ_OK || p->finished != 0) in LzmaEnc_Encode2()
2182 res = progress->Progress(progress, p->nowPos64, RangeEnc_GetProcessed(&p->rc)); in LzmaEnc_Encode2()
2190 LzmaEnc_Finish(p); in LzmaEnc_Encode2()
2203 CLzmaEnc *p = (CLzmaEnc *)pp; in LzmaEnc_WriteProperties() local
2205 UInt32 dictSize = p->dictSize; in LzmaEnc_WriteProperties()
2209 props[0] = (Byte)((p->pb * 5 + p->lp) * 9 + p->lc); in LzmaEnc_WriteProperties()
2234 CLzmaEnc *p = (CLzmaEnc *)pp; in LzmaEnc_MemEncode() local
2238 LzmaEnc_SetInputBuf(p, src, srcLen); in LzmaEnc_MemEncode()
2245 p->writeEndMark = writeEndMark; in LzmaEnc_MemEncode()
2247 p->rc.outStream = &outStream.funcTable; in LzmaEnc_MemEncode()
2250 res = LzmaEnc_Encode2(p, progress); in LzmaEnc_MemEncode()
2262 CLzmaEnc *p = (CLzmaEnc *)LzmaEnc_Create(alloc); in LzmaEncode() local
2264 if (p == 0) in LzmaEncode()
2267 res = LzmaEnc_SetProps(p, props); in LzmaEncode()
2270 res = LzmaEnc_WriteProperties(p, propsEncoded, propsSize); in LzmaEncode()
2272 res = LzmaEnc_MemEncode(p, dest, destLen, src, srcLen, in LzmaEncode()
2276 LzmaEnc_Destroy(p, alloc, allocBig); in LzmaEncode()