Lines Matching refs:p

45 void LzmaEncProps_Init(CLzmaEncProps *p)  in LzmaEncProps_Init()  argument
47 p->level = 5; in LzmaEncProps_Init()
48 p->dictSize = p->mc = 0; in LzmaEncProps_Init()
49 p->lc = p->lp = p->pb = p->algo = p->fb = p->btMode = p->numHashBytes = p->numThreads = -1; in LzmaEncProps_Init()
50 p->writeEndMark = 0; in LzmaEncProps_Init()
53 void LzmaEncProps_Normalize(CLzmaEncProps *p) in LzmaEncProps_Normalize() argument
55 int level = p->level; in LzmaEncProps_Normalize()
57 p->level = level; in LzmaEncProps_Normalize()
58 …if (p->dictSize == 0) p->dictSize = (level <= 5 ? (1 << (level * 2 + 14)) : (level == 6 ? (1 << 25… in LzmaEncProps_Normalize()
59 if (p->lc < 0) p->lc = 3; in LzmaEncProps_Normalize()
60 if (p->lp < 0) p->lp = 0; in LzmaEncProps_Normalize()
61 if (p->pb < 0) p->pb = 2; in LzmaEncProps_Normalize()
62 if (p->algo < 0) p->algo = (level < 5 ? 0 : 1); in LzmaEncProps_Normalize()
63 if (p->fb < 0) p->fb = (level < 7 ? 32 : 64); in LzmaEncProps_Normalize()
64 if (p->btMode < 0) p->btMode = (p->algo == 0 ? 0 : 1); in LzmaEncProps_Normalize()
65 if (p->numHashBytes < 0) p->numHashBytes = 4; in LzmaEncProps_Normalize()
66 if (p->mc == 0) p->mc = (16 + (p->fb >> 1)) >> (p->btMode ? 0 : 1); in LzmaEncProps_Normalize()
67 if (p->numThreads < 0) in LzmaEncProps_Normalize()
68 p->numThreads = in LzmaEncProps_Normalize()
70 ((p->btMode && p->algo) ? 2 : 1); in LzmaEncProps_Normalize()
124 res = p->g_FastPos[pos >> i] + (i * 2); }
131 #define GetPosSlot1(pos) p->g_FastPos[pos]
133 #define GetPosSlot(pos, res) { if (pos < kNumFullDistances) res = p->g_FastPos[pos]; else BSR2_RET(…
215 CLenEnc p; member
341 CLzmaEnc *p = (CLzmaEnc *)pp; in LzmaEnc_SaveState() local
342 CSaveState *dest = &p->saveState; in LzmaEnc_SaveState()
344 dest->lenEnc = p->lenEnc; in LzmaEnc_SaveState()
345 dest->repLenEnc = p->repLenEnc; in LzmaEnc_SaveState()
346 dest->state = p->state; in LzmaEnc_SaveState()
350 memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i])); in LzmaEnc_SaveState()
351 memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i])); in LzmaEnc_SaveState()
354 memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i])); in LzmaEnc_SaveState()
355 memcpy(dest->isRep, p->isRep, sizeof(p->isRep)); in LzmaEnc_SaveState()
356 memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0)); in LzmaEnc_SaveState()
357 memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1)); in LzmaEnc_SaveState()
358 memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2)); in LzmaEnc_SaveState()
359 memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders)); in LzmaEnc_SaveState()
360 memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder)); in LzmaEnc_SaveState()
361 memcpy(dest->reps, p->reps, sizeof(p->reps)); in LzmaEnc_SaveState()
362 memcpy(dest->litProbs, p->litProbs, (0x300 << p->lclp) * sizeof(CLzmaProb)); in LzmaEnc_SaveState()
368 const CSaveState *p = &dest->saveState; in LzmaEnc_RestoreState() local
370 dest->lenEnc = p->lenEnc; in LzmaEnc_RestoreState()
371 dest->repLenEnc = p->repLenEnc; in LzmaEnc_RestoreState()
372 dest->state = p->state; in LzmaEnc_RestoreState()
376 memcpy(dest->isMatch[i], p->isMatch[i], sizeof(p->isMatch[i])); in LzmaEnc_RestoreState()
377 memcpy(dest->isRep0Long[i], p->isRep0Long[i], sizeof(p->isRep0Long[i])); in LzmaEnc_RestoreState()
380 memcpy(dest->posSlotEncoder[i], p->posSlotEncoder[i], sizeof(p->posSlotEncoder[i])); in LzmaEnc_RestoreState()
381 memcpy(dest->isRep, p->isRep, sizeof(p->isRep)); in LzmaEnc_RestoreState()
382 memcpy(dest->isRepG0, p->isRepG0, sizeof(p->isRepG0)); in LzmaEnc_RestoreState()
383 memcpy(dest->isRepG1, p->isRepG1, sizeof(p->isRepG1)); in LzmaEnc_RestoreState()
384 memcpy(dest->isRepG2, p->isRepG2, sizeof(p->isRepG2)); in LzmaEnc_RestoreState()
385 memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders)); in LzmaEnc_RestoreState()
386 memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder)); in LzmaEnc_RestoreState()
387 memcpy(dest->reps, p->reps, sizeof(p->reps)); in LzmaEnc_RestoreState()
388 memcpy(dest->litProbs, p->litProbs, (0x300 << dest->lclp) * sizeof(CLzmaProb)); in LzmaEnc_RestoreState()
393 CLzmaEnc *p = (CLzmaEnc *)pp; in LzmaEnc_SetProps() local
400 p->dictSize = props.dictSize; in LzmaEnc_SetProps()
401 p->matchFinderCycles = props.mc; in LzmaEnc_SetProps()
408 p->numFastBytes = fb; in LzmaEnc_SetProps()
410 p->lc = props.lc; in LzmaEnc_SetProps()
411 p->lp = props.lp; in LzmaEnc_SetProps()
412 p->pb = props.pb; in LzmaEnc_SetProps()
413 p->fastMode = (props.algo == 0); in LzmaEnc_SetProps()
414 p->matchFinderBase.btMode = props.btMode; in LzmaEnc_SetProps()
424 p->matchFinderBase.numHashBytes = numHashBytes; in LzmaEnc_SetProps()
427 p->matchFinderBase.cutValue = props.mc; in LzmaEnc_SetProps()
429 p->writeEndMark = props.writeEndMark; in LzmaEnc_SetProps()
439 p->multiThread = (props.numThreads > 1); in LzmaEnc_SetProps()
456 static void RangeEnc_Construct(CRangeEnc *p) in RangeEnc_Construct() argument
458 p->outStream = 0; in RangeEnc_Construct()
459 p->bufBase = 0; in RangeEnc_Construct()
462 #define RangeEnc_GetProcessed(p) ((p)->processed + ((p)->buf - (p)->bufBase) + (p)->cacheSize) argument
465 static int RangeEnc_Alloc(CRangeEnc *p, ISzAlloc *alloc) in RangeEnc_Alloc() argument
467 if (p->bufBase == 0) in RangeEnc_Alloc()
469 p->bufBase = (Byte *)alloc->Alloc(alloc, RC_BUF_SIZE); in RangeEnc_Alloc()
470 if (p->bufBase == 0) in RangeEnc_Alloc()
472 p->bufLim = p->bufBase + RC_BUF_SIZE; in RangeEnc_Alloc()
477 static void RangeEnc_Free(CRangeEnc *p, ISzAlloc *alloc) in RangeEnc_Free() argument
479 alloc->Free(alloc, p->bufBase); in RangeEnc_Free()
480 p->bufBase = 0; in RangeEnc_Free()
483 static void RangeEnc_Init(CRangeEnc *p) in RangeEnc_Init() argument
486 p->low = 0; in RangeEnc_Init()
487 p->range = 0xFFFFFFFF; in RangeEnc_Init()
488 p->cacheSize = 1; in RangeEnc_Init()
489 p->cache = 0; in RangeEnc_Init()
491 p->buf = p->bufBase; in RangeEnc_Init()
493 p->processed = 0; in RangeEnc_Init()
494 p->res = SZ_OK; in RangeEnc_Init()
497 static void RangeEnc_FlushStream(CRangeEnc *p) in RangeEnc_FlushStream() argument
500 if (p->res != SZ_OK) in RangeEnc_FlushStream()
502 num = p->buf - p->bufBase; in RangeEnc_FlushStream()
503 if (num != p->outStream->Write(p->outStream, p->bufBase, num)) in RangeEnc_FlushStream()
504 p->res = SZ_ERROR_WRITE; in RangeEnc_FlushStream()
505 p->processed += num; in RangeEnc_FlushStream()
506 p->buf = p->bufBase; in RangeEnc_FlushStream()
509 static void MY_FAST_CALL RangeEnc_ShiftLow(CRangeEnc *p) in RangeEnc_ShiftLow() argument
511 if ((UInt32)p->low < (UInt32)0xFF000000 || (int)(p->low >> 32) != 0) in RangeEnc_ShiftLow()
513 Byte temp = p->cache; in RangeEnc_ShiftLow()
516 Byte *buf = p->buf; in RangeEnc_ShiftLow()
517 *buf++ = (Byte)(temp + (Byte)(p->low >> 32)); in RangeEnc_ShiftLow()
518 p->buf = buf; in RangeEnc_ShiftLow()
519 if (buf == p->bufLim) in RangeEnc_ShiftLow()
520 RangeEnc_FlushStream(p); in RangeEnc_ShiftLow()
523 while (--p->cacheSize != 0); in RangeEnc_ShiftLow()
524 p->cache = (Byte)((UInt32)p->low >> 24); in RangeEnc_ShiftLow()
526 p->cacheSize++; in RangeEnc_ShiftLow()
527 p->low = (UInt32)p->low << 8; in RangeEnc_ShiftLow()
530 static void RangeEnc_FlushData(CRangeEnc *p) in RangeEnc_FlushData() argument
534 RangeEnc_ShiftLow(p); in RangeEnc_FlushData()
537 static void RangeEnc_EncodeDirectBits(CRangeEnc *p, UInt32 value, int numBits) in RangeEnc_EncodeDirectBits() argument
541 p->range >>= 1; in RangeEnc_EncodeDirectBits()
542 p->low += p->range & (0 - ((value >> --numBits) & 1)); in RangeEnc_EncodeDirectBits()
543 if (p->range < kTopValue) in RangeEnc_EncodeDirectBits()
545 p->range <<= 8; in RangeEnc_EncodeDirectBits()
546 RangeEnc_ShiftLow(p); in RangeEnc_EncodeDirectBits()
552 static void RangeEnc_EncodeBit(CRangeEnc *p, CLzmaProb *prob, UInt32 symbol) in RangeEnc_EncodeBit() argument
555 UInt32 newBound = (p->range >> kNumBitModelTotalBits) * ttt; in RangeEnc_EncodeBit()
558 p->range = newBound; in RangeEnc_EncodeBit()
563 p->low += newBound; in RangeEnc_EncodeBit()
564 p->range -= newBound; in RangeEnc_EncodeBit()
568 if (p->range < kTopValue) in RangeEnc_EncodeBit()
570 p->range <<= 8; in RangeEnc_EncodeBit()
571 RangeEnc_ShiftLow(p); in RangeEnc_EncodeBit()
575 static void LitEnc_Encode(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol) in LitEnc_Encode() argument
580 RangeEnc_EncodeBit(p, probs + (symbol >> 8), (symbol >> 7) & 1); in LitEnc_Encode()
586 static void LitEnc_EncodeMatched(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol, UInt32 matchByte) in LitEnc_EncodeMatched() argument
593 RangeEnc_EncodeBit(p, probs + (offs + (matchByte & offs) + (symbol >> 8)), (symbol >> 7) & 1); in LitEnc_EncodeMatched()
625 p->ProbPrices[((prob) ^ (((-(int)(symbol))) & (kBitModelTotal - 1))) >> kNumMoveReducingBits];
630 #define GET_PRICE_0(prob) p->ProbPrices[(prob) >> kNumMoveReducingBits]
631 #define GET_PRICE_1(prob) p->ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]
721 static void LenEnc_Init(CLenEnc *p) in LenEnc_Init() argument
724 p->choice = p->choice2 = kProbInitValue; in LenEnc_Init()
726 p->low[i] = kProbInitValue; in LenEnc_Init()
728 p->mid[i] = kProbInitValue; in LenEnc_Init()
730 p->high[i] = kProbInitValue; in LenEnc_Init()
733 static void LenEnc_Encode(CLenEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32 posState) in LenEnc_Encode() argument
737 RangeEnc_EncodeBit(rc, &p->choice, 0); in LenEnc_Encode()
738 RcTree_Encode(rc, p->low + (posState << kLenNumLowBits), kLenNumLowBits, symbol); in LenEnc_Encode()
742 RangeEnc_EncodeBit(rc, &p->choice, 1); in LenEnc_Encode()
745 RangeEnc_EncodeBit(rc, &p->choice2, 0); in LenEnc_Encode()
746 …RcTree_Encode(rc, p->mid + (posState << kLenNumMidBits), kLenNumMidBits, symbol - kLenNumLowSymbol… in LenEnc_Encode()
750 RangeEnc_EncodeBit(rc, &p->choice2, 1); in LenEnc_Encode()
751 RcTree_Encode(rc, p->high, kLenNumHighBits, symbol - kLenNumLowSymbols - kLenNumMidSymbols); in LenEnc_Encode()
756 static void LenEnc_SetPrices(CLenEnc *p, UInt32 posState, UInt32 numSymbols, UInt32 *prices, UInt32… in LenEnc_SetPrices() argument
758 UInt32 a0 = GET_PRICE_0a(p->choice); in LenEnc_SetPrices()
759 UInt32 a1 = GET_PRICE_1a(p->choice); in LenEnc_SetPrices()
760 UInt32 b0 = a1 + GET_PRICE_0a(p->choice2); in LenEnc_SetPrices()
761 UInt32 b1 = a1 + GET_PRICE_1a(p->choice2); in LenEnc_SetPrices()
767 …prices[i] = a0 + RcTree_GetPrice(p->low + (posState << kLenNumLowBits), kLenNumLowBits, i, ProbPri… in LenEnc_SetPrices()
773 …prices[i] = b0 + RcTree_GetPrice(p->mid + (posState << kLenNumMidBits), kLenNumMidBits, i - kLenNu… in LenEnc_SetPrices()
776 …prices[i] = b1 + RcTree_GetPrice(p->high, kLenNumHighBits, i - kLenNumLowSymbols - kLenNumMidSymbo… in LenEnc_SetPrices()
779 static void MY_FAST_CALL LenPriceEnc_UpdateTable(CLenPriceEnc *p, UInt32 posState, UInt32 *ProbPric… in LenPriceEnc_UpdateTable() argument
781 LenEnc_SetPrices(&p->p, posState, p->tableSize, p->prices[posState], ProbPrices); in LenPriceEnc_UpdateTable()
782 p->counters[posState] = p->tableSize; in LenPriceEnc_UpdateTable()
785 static void LenPriceEnc_UpdateTables(CLenPriceEnc *p, UInt32 numPosStates, UInt32 *ProbPrices) in LenPriceEnc_UpdateTables() argument
789 LenPriceEnc_UpdateTable(p, posState, ProbPrices); in LenPriceEnc_UpdateTables()
792 static void LenEnc_Encode2(CLenPriceEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32 posState, Bool upd… in LenEnc_Encode2() argument
794 LenEnc_Encode(&p->p, rc, symbol, posState); in LenEnc_Encode2()
796 if (--p->counters[posState] == 0) in LenEnc_Encode2()
797 LenPriceEnc_UpdateTable(p, posState, ProbPrices); in LenEnc_Encode2()
803 static void MovePos(CLzmaEnc *p, UInt32 num) in MovePos() argument
811 p->additionalOffset += num; in MovePos()
812 p->matchFinder.Skip(p->matchFinderObj, num); in MovePos()
816 static UInt32 ReadMatchDistances(CLzmaEnc *p, UInt32 *numDistancePairsRes) in ReadMatchDistances() argument
819 p->numAvail = p->matchFinder.GetNumAvailableBytes(p->matchFinderObj); in ReadMatchDistances()
820 numPairs = p->matchFinder.GetMatches(p->matchFinderObj, p->matches); in ReadMatchDistances()
827 printf("%2d %6d | ", p->matches[i], p->matches[i + 1]); in ReadMatchDistances()
832 lenRes = p->matches[numPairs - 2]; in ReadMatchDistances()
833 if (lenRes == p->numFastBytes) in ReadMatchDistances()
835 const Byte *pby = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1; in ReadMatchDistances()
836 UInt32 distance = p->matches[numPairs - 1] + 1; in ReadMatchDistances()
837 UInt32 numAvail = p->numAvail; in ReadMatchDistances()
846 p->additionalOffset++; in ReadMatchDistances()
852 #define MakeAsChar(p) (p)->backPrev = (UInt32)(-1); (p)->prev1IsChar = False; argument
853 #define MakeAsShortRep(p) (p)->backPrev = 0; (p)->prev1IsChar = False; argument
854 #define IsShortRep(p) ((p)->backPrev == 0) argument
856 static UInt32 GetRepLen1Price(CLzmaEnc *p, UInt32 state, UInt32 posState) in GetRepLen1Price() argument
859 GET_PRICE_0(p->isRepG0[state]) + in GetRepLen1Price()
860 GET_PRICE_0(p->isRep0Long[state][posState]); in GetRepLen1Price()
863 static UInt32 GetPureRepPrice(CLzmaEnc *p, UInt32 repIndex, UInt32 state, UInt32 posState) in GetPureRepPrice() argument
868 price = GET_PRICE_0(p->isRepG0[state]); in GetPureRepPrice()
869 price += GET_PRICE_1(p->isRep0Long[state][posState]); in GetPureRepPrice()
873 price = GET_PRICE_1(p->isRepG0[state]); in GetPureRepPrice()
875 price += GET_PRICE_0(p->isRepG1[state]); in GetPureRepPrice()
878 price += GET_PRICE_1(p->isRepG1[state]); in GetPureRepPrice()
879 price += GET_PRICE(p->isRepG2[state], repIndex - 2); in GetPureRepPrice()
885 static UInt32 GetRepPrice(CLzmaEnc *p, UInt32 repIndex, UInt32 len, UInt32 state, UInt32 posState) in GetRepPrice() argument
887 return p->repLenEnc.prices[posState][len - LZMA_MATCH_LEN_MIN] + in GetRepPrice()
888 GetPureRepPrice(p, repIndex, state, posState); in GetRepPrice()
891 static UInt32 Backward(CLzmaEnc *p, UInt32 *backRes, UInt32 cur) in Backward() argument
893 UInt32 posMem = p->opt[cur].posPrev; in Backward()
894 UInt32 backMem = p->opt[cur].backPrev; in Backward()
895 p->optimumEndIndex = cur; in Backward()
898 if (p->opt[cur].prev1IsChar) in Backward()
900 MakeAsChar(&p->opt[posMem]) in Backward()
901 p->opt[posMem].posPrev = posMem - 1; in Backward()
902 if (p->opt[cur].prev2) in Backward()
904 p->opt[posMem - 1].prev1IsChar = False; in Backward()
905 p->opt[posMem - 1].posPrev = p->opt[cur].posPrev2; in Backward()
906 p->opt[posMem - 1].backPrev = p->opt[cur].backPrev2; in Backward()
913 backMem = p->opt[posPrev].backPrev; in Backward()
914 posMem = p->opt[posPrev].posPrev; in Backward()
916 p->opt[posPrev].backPrev = backCur; in Backward()
917 p->opt[posPrev].posPrev = cur; in Backward()
922 *backRes = p->opt[0].backPrev; in Backward()
923 p->optimumCurrentIndex = p->opt[0].posPrev; in Backward()
924 return p->optimumCurrentIndex; in Backward()
927 #define LIT_PROBS(pos, prevByte) (p->litProbs + ((((pos) & p->lpMask) << p->lc) + ((prevByte) >> (8…
929 static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) in GetOptimum() argument
937 if (p->optimumEndIndex != p->optimumCurrentIndex) in GetOptimum()
939 const COptimal *opt = &p->opt[p->optimumCurrentIndex]; in GetOptimum()
940 UInt32 lenRes = opt->posPrev - p->optimumCurrentIndex; in GetOptimum()
942 p->optimumCurrentIndex = opt->posPrev; in GetOptimum()
945 p->optimumCurrentIndex = p->optimumEndIndex = 0; in GetOptimum()
947 if (p->additionalOffset == 0) in GetOptimum()
948 mainLen = ReadMatchDistances(p, &numPairs); in GetOptimum()
951 mainLen = p->longestMatchLength; in GetOptimum()
952 numPairs = p->numPairs; in GetOptimum()
955 numAvail = p->numAvail; in GetOptimum()
964 data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1; in GetOptimum()
970 reps[i] = p->reps[i]; in GetOptimum()
982 if (repLens[repMaxIndex] >= p->numFastBytes) in GetOptimum()
987 MovePos(p, lenRes - 1); in GetOptimum()
991 matches = p->matches; in GetOptimum()
992 if (mainLen >= p->numFastBytes) in GetOptimum()
995 MovePos(p, mainLen - 1); in GetOptimum()
1007 p->opt[0].state = (CState)p->state; in GetOptimum()
1009 posState = (position & p->pbMask); in GetOptimum()
1013 p->opt[1].price = GET_PRICE_0(p->isMatch[p->state][posState]) + in GetOptimum()
1014 (!IsCharState(p->state) ? in GetOptimum()
1015 LitEnc_GetPriceMatched(probs, curByte, matchByte, p->ProbPrices) : in GetOptimum()
1016 LitEnc_GetPrice(probs, curByte, p->ProbPrices)); in GetOptimum()
1019 MakeAsChar(&p->opt[1]); in GetOptimum()
1021 matchPrice = GET_PRICE_1(p->isMatch[p->state][posState]); in GetOptimum()
1022 repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[p->state]); in GetOptimum()
1026 UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(p, p->state, posState); in GetOptimum()
1027 if (shortRepPrice < p->opt[1].price) in GetOptimum()
1029 p->opt[1].price = shortRepPrice; in GetOptimum()
1030 MakeAsShortRep(&p->opt[1]); in GetOptimum()
1037 *backRes = p->opt[1].backPrev; in GetOptimum()
1041 p->opt[1].posPrev = 0; in GetOptimum()
1043 p->opt[0].backs[i] = reps[i]; in GetOptimum()
1047 p->opt[len--].price = kInfinityPrice; in GetOptimum()
1056 price = repMatchPrice + GetPureRepPrice(p, i, p->state, posState); in GetOptimum()
1059 UInt32 curAndLenPrice = price + p->repLenEnc.prices[posState][repLen - 2]; in GetOptimum()
1060 COptimal *opt = &p->opt[repLen]; in GetOptimum()
1072 normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[p->state]); in GetOptimum()
1085 … UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][len - LZMA_MATCH_LEN_MIN]; in GetOptimum()
1088 curAndLenPrice += p->distancesPrices[lenToPosState][distance]; in GetOptimum()
1093 … curAndLenPrice += p->alignPrices[distance & kAlignMask] + p->posSlotPrices[lenToPosState][slot]; in GetOptimum()
1095 opt = &p->opt[len]; in GetOptimum()
1120 printf("\nprice[%4X] = %d", position - cur + i, p->opt[i].price); in GetOptimum()
1136 return Backward(p, backRes, cur); in GetOptimum()
1138 newLen = ReadMatchDistances(p, &numPairs); in GetOptimum()
1139 if (newLen >= p->numFastBytes) in GetOptimum()
1141 p->numPairs = numPairs; in GetOptimum()
1142 p->longestMatchLength = newLen; in GetOptimum()
1143 return Backward(p, backRes, cur); in GetOptimum()
1146 curOpt = &p->opt[cur]; in GetOptimum()
1153 state = p->opt[curOpt->posPrev2].state; in GetOptimum()
1160 state = p->opt[posPrev].state; in GetOptimum()
1164 state = p->opt[posPrev].state; in GetOptimum()
1190 prevOpt = &p->opt[posPrev]; in GetOptimum()
1217 data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1; in GetOptimum()
1221 posState = (position & p->pbMask); in GetOptimum()
1223 curAnd1Price = curPrice + GET_PRICE_0(p->isMatch[state][posState]); in GetOptimum()
1228 LitEnc_GetPriceMatched(probs, curByte, matchByte, p->ProbPrices) : in GetOptimum()
1229 LitEnc_GetPrice(probs, curByte, p->ProbPrices)); in GetOptimum()
1232 nextOpt = &p->opt[cur + 1]; in GetOptimum()
1242 matchPrice = curPrice + GET_PRICE_1(p->isMatch[state][posState]); in GetOptimum()
1243 repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[state]); in GetOptimum()
1247 UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(p, state, posState); in GetOptimum()
1256 numAvailFull = p->numAvail; in GetOptimum()
1265 numAvail = (numAvailFull <= p->numFastBytes ? numAvailFull : p->numFastBytes); in GetOptimum()
1273 UInt32 limit = p->numFastBytes + 1; in GetOptimum()
1282 UInt32 posStateNext = (position + 1) & p->pbMask; in GetOptimum()
1284 GET_PRICE_1(p->isMatch[state2][posStateNext]) + in GetOptimum()
1285 GET_PRICE_1(p->isRep[state2]); in GetOptimum()
1292 p->opt[++lenEnd].price = kInfinityPrice; in GetOptimum()
1293 curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext); in GetOptimum()
1294 opt = &p->opt[offset]; in GetOptimum()
1320 p->opt[++lenEnd].price = kInfinityPrice; in GetOptimum()
1322 price = repMatchPrice + GetPureRepPrice(p, repIndex, state, posState); in GetOptimum()
1325 UInt32 curAndLenPrice = price + p->repLenEnc.prices[posState][lenTest - 2]; in GetOptimum()
1326 COptimal *opt = &p->opt[cur + lenTest]; in GetOptimum()
1344 UInt32 limit = lenTest2 + p->numFastBytes; in GetOptimum()
1353 UInt32 posStateNext = (position + lenTest) & p->pbMask; in GetOptimum()
1355 price + p->repLenEnc.prices[posState][lenTest - 2] + in GetOptimum()
1356 GET_PRICE_0(p->isMatch[state2][posStateNext]) + in GetOptimum()
1358 data[lenTest], data2[lenTest], p->ProbPrices); in GetOptimum()
1360 posStateNext = (position + lenTest + 1) & p->pbMask; in GetOptimum()
1362 GET_PRICE_1(p->isMatch[state2][posStateNext]) + in GetOptimum()
1363 GET_PRICE_1(p->isRep[state2]); in GetOptimum()
1371 p->opt[++lenEnd].price = kInfinityPrice; in GetOptimum()
1372 … curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext); in GetOptimum()
1373 opt = &p->opt[offset]; in GetOptimum()
1399 UInt32 normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[state]); in GetOptimum()
1403 p->opt[++lenEnd].price = kInfinityPrice; in GetOptimum()
1412 …UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][lenTest - LZMA_MATCH_LEN_MIN… in GetOptimum()
1416 curAndLenPrice += p->distancesPrices[lenToPosState][curBack]; in GetOptimum()
1418 … curAndLenPrice += p->posSlotPrices[lenToPosState][posSlot] + p->alignPrices[curBack & kAlignMask]; in GetOptimum()
1420 opt = &p->opt[cur + lenTest]; in GetOptimum()
1434 UInt32 limit = lenTest2 + p->numFastBytes; in GetOptimum()
1443 UInt32 posStateNext = (position + lenTest) & p->pbMask; in GetOptimum()
1445 GET_PRICE_0(p->isMatch[state2][posStateNext]) + in GetOptimum()
1447 data[lenTest], data2[lenTest], p->ProbPrices); in GetOptimum()
1449 posStateNext = (posStateNext + 1) & p->pbMask; in GetOptimum()
1451 GET_PRICE_1(p->isMatch[state2][posStateNext]) + in GetOptimum()
1452 GET_PRICE_1(p->isRep[state2]); in GetOptimum()
1460 p->opt[++lenEnd].price = kInfinityPrice; in GetOptimum()
1461 … curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext); in GetOptimum()
1462 opt = &p->opt[offset]; in GetOptimum()
1489 static UInt32 GetOptimumFast(CLzmaEnc *p, UInt32 *backRes) in GetOptimumFast() argument
1495 if (p->additionalOffset == 0) in GetOptimumFast()
1496 mainLen = ReadMatchDistances(p, &numPairs); in GetOptimumFast()
1499 mainLen = p->longestMatchLength; in GetOptimumFast()
1500 numPairs = p->numPairs; in GetOptimumFast()
1503 numAvail = p->numAvail; in GetOptimumFast()
1509 data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1; in GetOptimumFast()
1515 const Byte *data2 = data - (p->reps[i] + 1); in GetOptimumFast()
1519 if (len >= p->numFastBytes) in GetOptimumFast()
1522 MovePos(p, len - 1); in GetOptimumFast()
1532 matches = p->matches; in GetOptimumFast()
1533 if (mainLen >= p->numFastBytes) in GetOptimumFast()
1536 MovePos(p, mainLen - 1); in GetOptimumFast()
1562 MovePos(p, repLen - 1); in GetOptimumFast()
1569 p->longestMatchLength = ReadMatchDistances(p, &p->numPairs); in GetOptimumFast()
1570 if (p->longestMatchLength >= 2) in GetOptimumFast()
1572 UInt32 newDistance = matches[p->numPairs - 1]; in GetOptimumFast()
1573 if ((p->longestMatchLength >= mainLen && newDistance < mainDist) || in GetOptimumFast()
1574 (p->longestMatchLength == mainLen + 1 && !ChangePair(mainDist, newDistance)) || in GetOptimumFast()
1575 (p->longestMatchLength > mainLen + 1) || in GetOptimumFast()
1576 (p->longestMatchLength + 1 >= mainLen && mainLen >= 3 && ChangePair(newDistance, mainDist))) in GetOptimumFast()
1580 data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1; in GetOptimumFast()
1584 const Byte *data2 = data - (p->reps[i] + 1); in GetOptimumFast()
1593 MovePos(p, mainLen - 2); in GetOptimumFast()
1597 static void WriteEndMarker(CLzmaEnc *p, UInt32 posState) in WriteEndMarker() argument
1600 RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 1); in WriteEndMarker()
1601 RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0); in WriteEndMarker()
1602 p->state = kMatchNextStates[p->state]; in WriteEndMarker()
1604 …LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices… in WriteEndMarker()
1605 …RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, (1 << kNumPosSlot… in WriteEndMarker()
1606 RangeEnc_EncodeDirectBits(&p->rc, (((UInt32)1 << 30) - 1) >> kNumAlignBits, 30 - kNumAlignBits); in WriteEndMarker()
1607 RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, kAlignMask); in WriteEndMarker()
1610 static SRes CheckErrors(CLzmaEnc *p) in CheckErrors() argument
1612 if (p->result != SZ_OK) in CheckErrors()
1613 return p->result; in CheckErrors()
1614 if (p->rc.res != SZ_OK) in CheckErrors()
1615 p->result = SZ_ERROR_WRITE; in CheckErrors()
1616 if (p->matchFinderBase.result != SZ_OK) in CheckErrors()
1617 p->result = SZ_ERROR_READ; in CheckErrors()
1618 if (p->result != SZ_OK) in CheckErrors()
1619 p->finished = True; in CheckErrors()
1620 return p->result; in CheckErrors()
1623 static SRes Flush(CLzmaEnc *p, UInt32 nowPos) in Flush() argument
1626 p->finished = True; in Flush()
1627 if (p->writeEndMark) in Flush()
1628 WriteEndMarker(p, nowPos & p->pbMask); in Flush()
1629 RangeEnc_FlushData(&p->rc); in Flush()
1630 RangeEnc_FlushStream(&p->rc); in Flush()
1631 return CheckErrors(p); in Flush()
1634 static void FillAlignPrices(CLzmaEnc *p) in FillAlignPrices() argument
1638 p->alignPrices[i] = RcTree_ReverseGetPrice(p->posAlignEncoder, kNumAlignBits, i, p->ProbPrices); in FillAlignPrices()
1639 p->alignPriceCount = 0; in FillAlignPrices()
1642 static void FillDistancesPrices(CLzmaEnc *p) in FillDistancesPrices() argument
1651 …tempPrices[i] = RcTree_ReverseGetPrice(p->posEncoders + base - posSlot - 1, footerBits, i - base, in FillDistancesPrices()
1657 const CLzmaProb *encoder = p->posSlotEncoder[lenToPosState]; in FillDistancesPrices()
1658 UInt32 *posSlotPrices = p->posSlotPrices[lenToPosState]; in FillDistancesPrices()
1659 for (posSlot = 0; posSlot < p->distTableSize; posSlot++) in FillDistancesPrices()
1660 posSlotPrices[posSlot] = RcTree_GetPrice(encoder, kNumPosSlotBits, posSlot, p->ProbPrices); in FillDistancesPrices()
1661 for (posSlot = kEndPosModelIndex; posSlot < p->distTableSize; posSlot++) in FillDistancesPrices()
1665 UInt32 *distancesPrices = p->distancesPrices[lenToPosState]; in FillDistancesPrices()
1673 p->matchPriceCount = 0; in FillDistancesPrices()
1676 void LzmaEnc_Construct(CLzmaEnc *p) in LzmaEnc_Construct() argument
1678 RangeEnc_Construct(&p->rc); in LzmaEnc_Construct()
1679 MatchFinder_Construct(&p->matchFinderBase); in LzmaEnc_Construct()
1681 MatchFinderMt_Construct(&p->matchFinderMt); in LzmaEnc_Construct()
1682 p->matchFinderMt.MatchFinder = &p->matchFinderBase; in LzmaEnc_Construct()
1688 LzmaEnc_SetProps(p, &props); in LzmaEnc_Construct()
1692 LzmaEnc_FastPosInit(p->g_FastPos); in LzmaEnc_Construct()
1695 LzmaEnc_InitPriceTables(p->ProbPrices); in LzmaEnc_Construct()
1696 p->litProbs = 0; in LzmaEnc_Construct()
1697 p->saveState.litProbs = 0; in LzmaEnc_Construct()
1702 void *p; in LzmaEnc_Create() local
1703 p = alloc->Alloc(alloc, sizeof(CLzmaEnc)); in LzmaEnc_Create()
1704 if (p != 0) in LzmaEnc_Create()
1705 LzmaEnc_Construct((CLzmaEnc *)p); in LzmaEnc_Create()
1706 return p; in LzmaEnc_Create()
1709 void LzmaEnc_FreeLits(CLzmaEnc *p, ISzAlloc *alloc) in LzmaEnc_FreeLits() argument
1711 alloc->Free(alloc, p->litProbs); in LzmaEnc_FreeLits()
1712 alloc->Free(alloc, p->saveState.litProbs); in LzmaEnc_FreeLits()
1713 p->litProbs = 0; in LzmaEnc_FreeLits()
1714 p->saveState.litProbs = 0; in LzmaEnc_FreeLits()
1717 void LzmaEnc_Destruct(CLzmaEnc *p, ISzAlloc *alloc, ISzAlloc *allocBig) in LzmaEnc_Destruct() argument
1720 MatchFinderMt_Destruct(&p->matchFinderMt, allocBig); in LzmaEnc_Destruct()
1722 MatchFinder_Free(&p->matchFinderBase, allocBig); in LzmaEnc_Destruct()
1723 LzmaEnc_FreeLits(p, alloc); in LzmaEnc_Destruct()
1724 RangeEnc_Free(&p->rc, alloc); in LzmaEnc_Destruct()
1727 void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig) in LzmaEnc_Destroy() argument
1729 LzmaEnc_Destruct((CLzmaEnc *)p, alloc, allocBig); in LzmaEnc_Destroy()
1730 alloc->Free(alloc, p); in LzmaEnc_Destroy()
1733 static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize, UInt32 maxUnpackS… in LzmaEnc_CodeOneBlock() argument
1736 if (p->needInit) in LzmaEnc_CodeOneBlock()
1738 p->matchFinder.Init(p->matchFinderObj); in LzmaEnc_CodeOneBlock()
1739 p->needInit = 0; in LzmaEnc_CodeOneBlock()
1742 if (p->finished) in LzmaEnc_CodeOneBlock()
1743 return p->result; in LzmaEnc_CodeOneBlock()
1744 RINOK(CheckErrors(p)); in LzmaEnc_CodeOneBlock()
1746 nowPos32 = (UInt32)p->nowPos64; in LzmaEnc_CodeOneBlock()
1749 if (p->nowPos64 == 0) in LzmaEnc_CodeOneBlock()
1753 if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0) in LzmaEnc_CodeOneBlock()
1754 return Flush(p, nowPos32); in LzmaEnc_CodeOneBlock()
1755 ReadMatchDistances(p, &numPairs); in LzmaEnc_CodeOneBlock()
1756 RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][0], 0); in LzmaEnc_CodeOneBlock()
1757 p->state = kLiteralNextStates[p->state]; in LzmaEnc_CodeOneBlock()
1758 curByte = p->matchFinder.GetIndexByte(p->matchFinderObj, 0 - p->additionalOffset); in LzmaEnc_CodeOneBlock()
1759 LitEnc_Encode(&p->rc, p->litProbs, curByte); in LzmaEnc_CodeOneBlock()
1760 p->additionalOffset--; in LzmaEnc_CodeOneBlock()
1764 if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) != 0) in LzmaEnc_CodeOneBlock()
1769 if (p->fastMode) in LzmaEnc_CodeOneBlock()
1770 len = GetOptimumFast(p, &pos); in LzmaEnc_CodeOneBlock()
1772 len = GetOptimum(p, nowPos32, &pos); in LzmaEnc_CodeOneBlock()
1778 posState = nowPos32 & p->pbMask; in LzmaEnc_CodeOneBlock()
1785 RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 0); in LzmaEnc_CodeOneBlock()
1786 data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset; in LzmaEnc_CodeOneBlock()
1789 if (IsCharState(p->state)) in LzmaEnc_CodeOneBlock()
1790 LitEnc_Encode(&p->rc, probs, curByte); in LzmaEnc_CodeOneBlock()
1792 LitEnc_EncodeMatched(&p->rc, probs, curByte, *(data - p->reps[0] - 1)); in LzmaEnc_CodeOneBlock()
1793 p->state = kLiteralNextStates[p->state]; in LzmaEnc_CodeOneBlock()
1797 RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 1); in LzmaEnc_CodeOneBlock()
1800 RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 1); in LzmaEnc_CodeOneBlock()
1803 RangeEnc_EncodeBit(&p->rc, &p->isRepG0[p->state], 0); in LzmaEnc_CodeOneBlock()
1804 RangeEnc_EncodeBit(&p->rc, &p->isRep0Long[p->state][posState], ((len == 1) ? 0 : 1)); in LzmaEnc_CodeOneBlock()
1808 UInt32 distance = p->reps[pos]; in LzmaEnc_CodeOneBlock()
1809 RangeEnc_EncodeBit(&p->rc, &p->isRepG0[p->state], 1); in LzmaEnc_CodeOneBlock()
1811 RangeEnc_EncodeBit(&p->rc, &p->isRepG1[p->state], 0); in LzmaEnc_CodeOneBlock()
1814 RangeEnc_EncodeBit(&p->rc, &p->isRepG1[p->state], 1); in LzmaEnc_CodeOneBlock()
1815 RangeEnc_EncodeBit(&p->rc, &p->isRepG2[p->state], pos - 2); in LzmaEnc_CodeOneBlock()
1817 p->reps[3] = p->reps[2]; in LzmaEnc_CodeOneBlock()
1818 p->reps[2] = p->reps[1]; in LzmaEnc_CodeOneBlock()
1820 p->reps[1] = p->reps[0]; in LzmaEnc_CodeOneBlock()
1821 p->reps[0] = distance; in LzmaEnc_CodeOneBlock()
1824 p->state = kShortRepNextStates[p->state]; in LzmaEnc_CodeOneBlock()
1827 …LenEnc_Encode2(&p->repLenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPri… in LzmaEnc_CodeOneBlock()
1828 p->state = kRepNextStates[p->state]; in LzmaEnc_CodeOneBlock()
1834 RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0); in LzmaEnc_CodeOneBlock()
1835 p->state = kMatchNextStates[p->state]; in LzmaEnc_CodeOneBlock()
1836 …LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices… in LzmaEnc_CodeOneBlock()
1839 RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, posSlot); in LzmaEnc_CodeOneBlock()
1848 … RcTree_ReverseEncode(&p->rc, p->posEncoders + base - posSlot - 1, footerBits, posReduced); in LzmaEnc_CodeOneBlock()
1851 … RangeEnc_EncodeDirectBits(&p->rc, posReduced >> kNumAlignBits, footerBits - kNumAlignBits); in LzmaEnc_CodeOneBlock()
1852 … RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, posReduced & kAlignMask); in LzmaEnc_CodeOneBlock()
1853 p->alignPriceCount++; in LzmaEnc_CodeOneBlock()
1856 p->reps[3] = p->reps[2]; in LzmaEnc_CodeOneBlock()
1857 p->reps[2] = p->reps[1]; in LzmaEnc_CodeOneBlock()
1858 p->reps[1] = p->reps[0]; in LzmaEnc_CodeOneBlock()
1859 p->reps[0] = pos; in LzmaEnc_CodeOneBlock()
1860 p->matchPriceCount++; in LzmaEnc_CodeOneBlock()
1863 p->additionalOffset -= len; in LzmaEnc_CodeOneBlock()
1865 if (p->additionalOffset == 0) in LzmaEnc_CodeOneBlock()
1868 if (!p->fastMode) in LzmaEnc_CodeOneBlock()
1870 if (p->matchPriceCount >= (1 << 7)) in LzmaEnc_CodeOneBlock()
1871 FillDistancesPrices(p); in LzmaEnc_CodeOneBlock()
1872 if (p->alignPriceCount >= kAlignTableSize) in LzmaEnc_CodeOneBlock()
1873 FillAlignPrices(p); in LzmaEnc_CodeOneBlock()
1875 if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0) in LzmaEnc_CodeOneBlock()
1881 RangeEnc_GetProcessed(&p->rc) + kNumOpts * 2 >= maxPackSize) in LzmaEnc_CodeOneBlock()
1886 p->nowPos64 += nowPos32 - startPos32; in LzmaEnc_CodeOneBlock()
1887 return CheckErrors(p); in LzmaEnc_CodeOneBlock()
1891 p->nowPos64 += nowPos32 - startPos32; in LzmaEnc_CodeOneBlock()
1892 return Flush(p, nowPos32); in LzmaEnc_CodeOneBlock()
1897 static SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig) in LzmaEnc_Alloc() argument
1901 if (!RangeEnc_Alloc(&p->rc, alloc)) in LzmaEnc_Alloc()
1903 btMode = (p->matchFinderBase.btMode != 0); in LzmaEnc_Alloc()
1905 p->mtMode = (p->multiThread && !p->fastMode && btMode); in LzmaEnc_Alloc()
1909 unsigned lclp = p->lc + p->lp; in LzmaEnc_Alloc()
1910 if (p->litProbs == 0 || p->saveState.litProbs == 0 || p->lclp != lclp) in LzmaEnc_Alloc()
1912 LzmaEnc_FreeLits(p, alloc); in LzmaEnc_Alloc()
1913 p->litProbs = (CLzmaProb *)alloc->Alloc(alloc, (0x300 << lclp) * sizeof(CLzmaProb)); in LzmaEnc_Alloc()
1914 p->saveState.litProbs = (CLzmaProb *)alloc->Alloc(alloc, (0x300 << lclp) * sizeof(CLzmaProb)); in LzmaEnc_Alloc()
1915 if (p->litProbs == 0 || p->saveState.litProbs == 0) in LzmaEnc_Alloc()
1917 LzmaEnc_FreeLits(p, alloc); in LzmaEnc_Alloc()
1920 p->lclp = lclp; in LzmaEnc_Alloc()
1924 p->matchFinderBase.bigHash = (p->dictSize > kBigHashDicLimit); in LzmaEnc_Alloc()
1926 if (beforeSize + p->dictSize < keepWindowSize) in LzmaEnc_Alloc()
1927 beforeSize = keepWindowSize - p->dictSize; in LzmaEnc_Alloc()
1930 if (p->mtMode) in LzmaEnc_Alloc()
1932 …RINOK(MatchFinderMt_Create(&p->matchFinderMt, p->dictSize, beforeSize, p->numFastBytes, LZMA_MATCH… in LzmaEnc_Alloc()
1933 p->matchFinderObj = &p->matchFinderMt; in LzmaEnc_Alloc()
1934 MatchFinderMt_CreateVTable(&p->matchFinderMt, &p->matchFinder); in LzmaEnc_Alloc()
1939 …if (!MatchFinder_Create(&p->matchFinderBase, p->dictSize, beforeSize, p->numFastBytes, LZMA_MATCH_… in LzmaEnc_Alloc()
1941 p->matchFinderObj = &p->matchFinderBase; in LzmaEnc_Alloc()
1942 MatchFinder_CreateVTable(&p->matchFinderBase, &p->matchFinder); in LzmaEnc_Alloc()
1947 void LzmaEnc_Init(CLzmaEnc *p) in LzmaEnc_Init() argument
1950 p->state = 0; in LzmaEnc_Init()
1952 p->reps[i] = 0; in LzmaEnc_Init()
1954 RangeEnc_Init(&p->rc); in LzmaEnc_Init()
1962 p->isMatch[i][j] = kProbInitValue; in LzmaEnc_Init()
1963 p->isRep0Long[i][j] = kProbInitValue; in LzmaEnc_Init()
1965 p->isRep[i] = kProbInitValue; in LzmaEnc_Init()
1966 p->isRepG0[i] = kProbInitValue; in LzmaEnc_Init()
1967 p->isRepG1[i] = kProbInitValue; in LzmaEnc_Init()
1968 p->isRepG2[i] = kProbInitValue; in LzmaEnc_Init()
1972 UInt32 num = 0x300 << (p->lp + p->lc); in LzmaEnc_Init()
1974 p->litProbs[i] = kProbInitValue; in LzmaEnc_Init()
1980 CLzmaProb *probs = p->posSlotEncoder[i]; in LzmaEnc_Init()
1988 p->posEncoders[i] = kProbInitValue; in LzmaEnc_Init()
1991 LenEnc_Init(&p->lenEnc.p); in LzmaEnc_Init()
1992 LenEnc_Init(&p->repLenEnc.p); in LzmaEnc_Init()
1995 p->posAlignEncoder[i] = kProbInitValue; in LzmaEnc_Init()
1997 p->optimumEndIndex = 0; in LzmaEnc_Init()
1998 p->optimumCurrentIndex = 0; in LzmaEnc_Init()
1999 p->additionalOffset = 0; in LzmaEnc_Init()
2001 p->pbMask = (1 << p->pb) - 1; in LzmaEnc_Init()
2002 p->lpMask = (1 << p->lp) - 1; in LzmaEnc_Init()
2005 void LzmaEnc_InitPrices(CLzmaEnc *p) in LzmaEnc_InitPrices() argument
2007 if (!p->fastMode) in LzmaEnc_InitPrices()
2009 FillDistancesPrices(p); in LzmaEnc_InitPrices()
2010 FillAlignPrices(p); in LzmaEnc_InitPrices()
2013 p->lenEnc.tableSize = in LzmaEnc_InitPrices()
2014 p->repLenEnc.tableSize = in LzmaEnc_InitPrices()
2015 p->numFastBytes + 1 - LZMA_MATCH_LEN_MIN; in LzmaEnc_InitPrices()
2016 LenPriceEnc_UpdateTables(&p->lenEnc, 1 << p->pb, p->ProbPrices); in LzmaEnc_InitPrices()
2017 LenPriceEnc_UpdateTables(&p->repLenEnc, 1 << p->pb, p->ProbPrices); in LzmaEnc_InitPrices()
2020 static SRes LzmaEnc_AllocAndInit(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *all… in LzmaEnc_AllocAndInit() argument
2024 if (p->dictSize <= ((UInt32)1 << i)) in LzmaEnc_AllocAndInit()
2026 p->distTableSize = i * 2; in LzmaEnc_AllocAndInit()
2028 p->finished = False; in LzmaEnc_AllocAndInit()
2029 p->result = SZ_OK; in LzmaEnc_AllocAndInit()
2030 RINOK(LzmaEnc_Alloc(p, keepWindowSize, alloc, allocBig)); in LzmaEnc_AllocAndInit()
2031 LzmaEnc_Init(p); in LzmaEnc_AllocAndInit()
2032 LzmaEnc_InitPrices(p); in LzmaEnc_AllocAndInit()
2033 p->nowPos64 = 0; in LzmaEnc_AllocAndInit()
2040 CLzmaEnc *p = (CLzmaEnc *)pp; in LzmaEnc_Prepare() local
2041 p->matchFinderBase.stream = inStream; in LzmaEnc_Prepare()
2042 p->needInit = 1; in LzmaEnc_Prepare()
2043 p->rc.outStream = outStream; in LzmaEnc_Prepare()
2044 return LzmaEnc_AllocAndInit(p, 0, alloc, allocBig); in LzmaEnc_Prepare()
2051 CLzmaEnc *p = (CLzmaEnc *)pp; in LzmaEnc_PrepareForLzma2() local
2052 p->matchFinderBase.stream = inStream; in LzmaEnc_PrepareForLzma2()
2053 p->needInit = 1; in LzmaEnc_PrepareForLzma2()
2054 return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig); in LzmaEnc_PrepareForLzma2()
2057 static void LzmaEnc_SetInputBuf(CLzmaEnc *p, const Byte *src, SizeT srcLen) in LzmaEnc_SetInputBuf() argument
2059 p->matchFinderBase.directInput = 1; in LzmaEnc_SetInputBuf()
2060 p->matchFinderBase.bufferBase = (Byte *)src; in LzmaEnc_SetInputBuf()
2061 p->matchFinderBase.directInputRem = srcLen; in LzmaEnc_SetInputBuf()
2067 CLzmaEnc *p = (CLzmaEnc *)pp; in LzmaEnc_MemPrepare() local
2068 LzmaEnc_SetInputBuf(p, src, srcLen); in LzmaEnc_MemPrepare()
2069 p->needInit = 1; in LzmaEnc_MemPrepare()
2071 return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig); in LzmaEnc_MemPrepare()
2077 CLzmaEnc *p = (CLzmaEnc *)pp; in LzmaEnc_Finish() local
2078 if (p->mtMode) in LzmaEnc_Finish()
2079 MatchFinderMt_ReleaseStream(&p->matchFinderMt); in LzmaEnc_Finish()
2095 CSeqOutStreamBuf *p = (CSeqOutStreamBuf *)pp; in MyWrite() local
2096 if (p->rem < size) in MyWrite()
2098 size = p->rem; in MyWrite()
2099 p->overflow = True; in MyWrite()
2101 memcpy(p->data, data, size); in MyWrite()
2102 p->rem -= size; in MyWrite()
2103 p->data += size; in MyWrite()
2110 const CLzmaEnc *p = (CLzmaEnc *)pp; in LzmaEnc_GetNumAvailableBytes() local
2111 return p->matchFinder.GetNumAvailableBytes(p->matchFinderObj); in LzmaEnc_GetNumAvailableBytes()
2116 const CLzmaEnc *p = (CLzmaEnc *)pp; in LzmaEnc_GetCurBuf() local
2117 return p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset; in LzmaEnc_GetCurBuf()
2123 CLzmaEnc *p = (CLzmaEnc *)pp; in LzmaEnc_CodeOneMemBlock() local
2133 p->writeEndMark = False; in LzmaEnc_CodeOneMemBlock()
2134 p->finished = False; in LzmaEnc_CodeOneMemBlock()
2135 p->result = SZ_OK; in LzmaEnc_CodeOneMemBlock()
2138 LzmaEnc_Init(p); in LzmaEnc_CodeOneMemBlock()
2139 LzmaEnc_InitPrices(p); in LzmaEnc_CodeOneMemBlock()
2140 nowPos64 = p->nowPos64; in LzmaEnc_CodeOneMemBlock()
2141 RangeEnc_Init(&p->rc); in LzmaEnc_CodeOneMemBlock()
2142 p->rc.outStream = &outStream.funcTable; in LzmaEnc_CodeOneMemBlock()
2144 res = LzmaEnc_CodeOneBlock(p, True, desiredPackSize, *unpackSize); in LzmaEnc_CodeOneMemBlock()
2146 *unpackSize = (UInt32)(p->nowPos64 - nowPos64); in LzmaEnc_CodeOneMemBlock()
2154 static SRes LzmaEnc_Encode2(CLzmaEnc *p, ICompressProgress *progress) in LzmaEnc_Encode2() argument
2167 res = LzmaEnc_CodeOneBlock(p, False, 0, 0); in LzmaEnc_Encode2()
2168 if (res != SZ_OK || p->finished != 0) in LzmaEnc_Encode2()
2172 res = progress->Progress(progress, p->nowPos64, RangeEnc_GetProcessed(&p->rc)); in LzmaEnc_Encode2()
2180 LzmaEnc_Finish(p); in LzmaEnc_Encode2()
2193 CLzmaEnc *p = (CLzmaEnc *)pp; in LzmaEnc_WriteProperties() local
2195 UInt32 dictSize = p->dictSize; in LzmaEnc_WriteProperties()
2199 props[0] = (Byte)((p->pb * 5 + p->lp) * 9 + p->lc); in LzmaEnc_WriteProperties()
2224 CLzmaEnc *p = (CLzmaEnc *)pp; in LzmaEnc_MemEncode() local
2228 LzmaEnc_SetInputBuf(p, src, srcLen); in LzmaEnc_MemEncode()
2235 p->writeEndMark = writeEndMark; in LzmaEnc_MemEncode()
2237 p->rc.outStream = &outStream.funcTable; in LzmaEnc_MemEncode()
2240 res = LzmaEnc_Encode2(p, progress); in LzmaEnc_MemEncode()
2252 CLzmaEnc *p = (CLzmaEnc *)LzmaEnc_Create(alloc); in LzmaEncode() local
2254 if (p == 0) in LzmaEncode()
2257 res = LzmaEnc_SetProps(p, props); in LzmaEncode()
2260 res = LzmaEnc_WriteProperties(p, propsEncoded, propsSize); in LzmaEncode()
2262 res = LzmaEnc_MemEncode(p, dest, destLen, src, srcLen, in LzmaEncode()
2266 LzmaEnc_Destroy(p, alloc, allocBig); in LzmaEncode()