CMS 3D CMS Logo

Classes | Macros | Typedefs | Enumerations | Functions
LzmaDec.h File Reference
#include "Types.h"

Go to the source code of this file.

Classes

struct  _CLzmaProps
 
struct  CLzmaDec
 

Macros

#define CLzmaProb   UInt16
 
#define LZMA_PROPS_SIZE   5
 
#define LZMA_REQUIRED_INPUT_MAX   20
 
#define LzmaDec_Construct(p)
 

Typedefs

typedef struct _CLzmaProps CLzmaProps
 

Enumerations

enum  ELzmaFinishMode { LZMA_FINISH_ANY, LZMA_FINISH_END }
 
enum  ELzmaStatus {
  LZMA_STATUS_NOT_SPECIFIED, LZMA_STATUS_FINISHED_WITH_MARK, LZMA_STATUS_NOT_FINISHED, LZMA_STATUS_NEEDS_MORE_INPUT,
  LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
}
 

Functions

SRes LzmaDec_Allocate (CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAlloc *alloc)
 
SRes LzmaDec_AllocateProbs (CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)
 
SRes LzmaDec_DecodeToBuf (CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
 
SRes LzmaDec_DecodeToDic (CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
 
void LzmaDec_Free (CLzmaDec *state, ISzAlloc *alloc)
 
void LzmaDec_FreeProbs (CLzmaDec *p, ISzAlloc *alloc)
 
void LzmaDec_Init (CLzmaDec *p)
 
SRes LzmaDecode (Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode, ELzmaStatus *status, ISzAlloc *alloc)
 
SRes LzmaProps_Decode (CLzmaProps *p, const Byte *data, unsigned size)
 

Macro Definition Documentation

◆ CLzmaProb

#define CLzmaProb   UInt16

◆ LZMA_PROPS_SIZE

#define LZMA_PROPS_SIZE   5

Definition at line 25 of file LzmaDec.h.

Referenced by LzmaProps_Decode(), and LzmaFile::Open().

◆ LZMA_REQUIRED_INPUT_MAX

#define LZMA_REQUIRED_INPUT_MAX   20

Definition at line 45 of file LzmaDec.h.

Referenced by LzmaDec_DecodeToDic().

◆ LzmaDec_Construct

#define LzmaDec_Construct (   p)
Value:
{ \
(p)->dic = 0; \
(p)->probs = 0; \
}

Definition at line 67 of file LzmaDec.h.

Referenced by LzmaDecode(), and LzmaFile::Open().

Typedef Documentation

◆ CLzmaProps

typedef struct _CLzmaProps CLzmaProps

Enumeration Type Documentation

◆ ELzmaFinishMode

Enumerator
LZMA_FINISH_ANY 
LZMA_FINISH_END 

Definition at line 79 of file LzmaDec.h.

79  {
80  LZMA_FINISH_ANY, /* finish at any point */
81  LZMA_FINISH_END /* block must be finished at the end */
ELzmaFinishMode
Definition: LzmaDec.h:79

◆ ELzmaStatus

Enumerator
LZMA_STATUS_NOT_SPECIFIED 
LZMA_STATUS_FINISHED_WITH_MARK 
LZMA_STATUS_NOT_FINISHED 
LZMA_STATUS_NEEDS_MORE_INPUT 
LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK 

Definition at line 99 of file LzmaDec.h.

99  {
100  LZMA_STATUS_NOT_SPECIFIED, /* use main error code instead */
101  LZMA_STATUS_FINISHED_WITH_MARK, /* stream was finished with end mark. */
102  LZMA_STATUS_NOT_FINISHED, /* stream was not finished */
103  LZMA_STATUS_NEEDS_MORE_INPUT, /* you must provide more input bytes */
104  LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK /* there is probability that stream was finished without end mark */
105 } ELzmaStatus;
ELzmaStatus
Definition: LzmaDec.h:99

Function Documentation

◆ LzmaDec_Allocate()

SRes LzmaDec_Allocate ( CLzmaDec state,
const Byte prop,
unsigned  propsSize,
ISzAlloc alloc 
)

Definition at line 887 of file LzmaDec.cc.

References ISzAlloc::Alloc, _CLzmaProps::dicSize, LzmaDec_AllocateProbs2(), LzmaDec_FreeDict(), LzmaDec_FreeProbs(), LzmaProps_Decode(), AlCaHLTBitMon_ParallelJobs::p, RINOK, SZ_ERROR_MEM, and SZ_OK.

Referenced by LzmaFile::Open().

887  {
888  CLzmaProps propNew;
889  SizeT dicBufSize;
890  RINOK(LzmaProps_Decode(&propNew, props, propsSize));
891  RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));
892  dicBufSize = propNew.dicSize;
893  if (p->dic == nullptr || dicBufSize != p->dicBufSize) {
894  LzmaDec_FreeDict(p, alloc);
895  p->dic = (Byte *)alloc->Alloc(alloc, dicBufSize);
896  if (p->dic == nullptr) {
897  LzmaDec_FreeProbs(p, alloc);
898  return SZ_ERROR_MEM;
899  }
900  }
901  p->dicBufSize = dicBufSize;
902  p->prop = propNew;
903  return SZ_OK;
904 }
void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)
Definition: LzmaDec.cc:827
#define RINOK(x)
Definition: Types.h:52
static void LzmaDec_FreeDict(CLzmaDec *p, ISzAlloc *alloc)
Definition: LzmaDec.cc:832
void *(* Alloc)(void *p, size_t size)
Definition: Types.h:216
size_t SizeT
Definition: Types.h:97
UInt32 dicSize
Definition: LzmaDec.h:29
#define SZ_OK
Definition: Types.h:25
static SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAlloc *alloc)
Definition: LzmaDec.cc:867
SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)
Definition: LzmaDec.cc:842
unsigned char Byte
Definition: Types.h:60
#define SZ_ERROR_MEM
Definition: Types.h:28

◆ LzmaDec_AllocateProbs()

SRes LzmaDec_AllocateProbs ( CLzmaDec p,
const Byte props,
unsigned  propsSize,
ISzAlloc alloc 
)

Definition at line 879 of file LzmaDec.cc.

References LzmaDec_AllocateProbs2(), LzmaProps_Decode(), AlCaHLTBitMon_ParallelJobs::p, RINOK, and SZ_OK.

Referenced by LzmaDecode().

879  {
880  CLzmaProps propNew;
881  RINOK(LzmaProps_Decode(&propNew, props, propsSize));
882  RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));
883  p->prop = propNew;
884  return SZ_OK;
885 }
#define RINOK(x)
Definition: Types.h:52
#define SZ_OK
Definition: Types.h:25
static SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAlloc *alloc)
Definition: LzmaDec.cc:867
SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)
Definition: LzmaDec.cc:842

◆ LzmaDec_DecodeToBuf()

SRes LzmaDec_DecodeToBuf ( CLzmaDec p,
Byte dest,
SizeT destLen,
const Byte src,
SizeT srcLen,
ELzmaFinishMode  finishMode,
ELzmaStatus status 
)

Definition at line 786 of file LzmaDec.cc.

References mps_fire::dest, LZMA_FINISH_ANY, LzmaDec_DecodeToDic(), AlCaHLTBitMon_ParallelJobs::p, TrackRefitter_38T_cff::src, mps_update::status, and SZ_OK.

Referenced by LzmaFile::DecodeAll(), and LzmaFile::DecodeBuffer().

792  {
793  SizeT outSize = *destLen;
794  SizeT inSize = *srcLen;
795  *srcLen = *destLen = 0;
796  for (;;) {
797  SizeT inSizeCur = inSize, outSizeCur, dicPos;
798  ELzmaFinishMode curFinishMode;
799  SRes res;
800  if (p->dicPos == p->dicBufSize)
801  p->dicPos = 0;
802  dicPos = p->dicPos;
803  if (outSize > p->dicBufSize - dicPos) {
804  outSizeCur = p->dicBufSize;
805  curFinishMode = LZMA_FINISH_ANY;
806  } else {
807  outSizeCur = dicPos + outSize;
808  curFinishMode = finishMode;
809  }
810 
811  res = LzmaDec_DecodeToDic(p, outSizeCur, src, &inSizeCur, curFinishMode, status);
812  src += inSizeCur;
813  inSize -= inSizeCur;
814  *srcLen += inSizeCur;
815  outSizeCur = p->dicPos - dicPos;
816  memcpy(dest, p->dic + dicPos, outSizeCur);
817  dest += outSizeCur;
818  outSize -= outSizeCur;
819  *destLen += outSizeCur;
820  if (res != 0)
821  return res;
822  if (outSizeCur == 0 || outSize == 0)
823  return SZ_OK;
824  }
825 }
ELzmaFinishMode
Definition: LzmaDec.h:79
SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
Definition: LzmaDec.cc:683
Definition: Electron.h:6
size_t SizeT
Definition: Types.h:97
int SRes
Definition: Types.h:43
#define SZ_OK
Definition: Types.h:25

◆ LzmaDec_DecodeToDic()

SRes LzmaDec_DecodeToDic ( CLzmaDec p,
SizeT  dicLimit,
const Byte src,
SizeT srcLen,
ELzmaFinishMode  finishMode,
ELzmaStatus status 
)

Definition at line 683 of file LzmaDec.cc.

References DUMMY_ERROR, DUMMY_MATCH, caHitNtupletGeneratorKernels::if(), kMatchSpecLenStart, LZMA_FINISH_ANY, LZMA_REQUIRED_INPUT_MAX, LZMA_STATUS_FINISHED_WITH_MARK, LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK, LZMA_STATUS_NEEDS_MORE_INPUT, LZMA_STATUS_NOT_FINISHED, LZMA_STATUS_NOT_SPECIFIED, LzmaDec_DecodeReal2(), LzmaDec_InitRc(), LzmaDec_InitStateReal(), LzmaDec_TryDummy(), LzmaDec_WriteRem(), AlCaHLTBitMon_ParallelJobs::p, RC_INIT_SIZE, TrackRefitter_38T_cff::src, mps_update::status, SZ_ERROR_DATA, and SZ_OK.

Referenced by LzmaDec_DecodeToBuf(), and LzmaDecode().

684  {
685  SizeT inSize = *srcLen;
686  (*srcLen) = 0;
687  LzmaDec_WriteRem(p, dicLimit);
688 
690 
691  while (p->remainLen != kMatchSpecLenStart) {
692  int checkEndMarkNow;
693 
694  if (p->needFlush != 0) {
695  for (; inSize > 0 && p->tempBufSize < RC_INIT_SIZE; (*srcLen)++, inSize--)
696  p->tempBuf[p->tempBufSize++] = *src++;
697  if (p->tempBufSize < RC_INIT_SIZE) {
699  return SZ_OK;
700  }
701  if (p->tempBuf[0] != 0)
702  return SZ_ERROR_DATA;
703 
704  LzmaDec_InitRc(p, p->tempBuf);
705  p->tempBufSize = 0;
706  }
707 
708  checkEndMarkNow = 0;
709  if (p->dicPos >= dicLimit) {
710  if (p->remainLen == 0 && p->code == 0) {
712  return SZ_OK;
713  }
714  if (finishMode == LZMA_FINISH_ANY) {
716  return SZ_OK;
717  }
718  if (p->remainLen != 0) {
720  return SZ_ERROR_DATA;
721  }
722  checkEndMarkNow = 1;
723  }
724 
725  if (p->needInitState)
727 
728  if (p->tempBufSize == 0) {
729  SizeT processed;
730  const Byte *bufLimit;
731  if (inSize < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow) {
732  int dummyRes = LzmaDec_TryDummy(p, src, inSize);
733  if (dummyRes == DUMMY_ERROR) {
734  memcpy(p->tempBuf, src, inSize);
735  p->tempBufSize = (unsigned)inSize;
736  (*srcLen) += inSize;
738  return SZ_OK;
739  }
740  if (checkEndMarkNow && dummyRes != DUMMY_MATCH) {
742  return SZ_ERROR_DATA;
743  }
744  bufLimit = src;
745  } else
746  bufLimit = src + inSize - LZMA_REQUIRED_INPUT_MAX;
747  p->buf = src;
748  if (LzmaDec_DecodeReal2(p, dicLimit, bufLimit) != 0)
749  return SZ_ERROR_DATA;
750  processed = (SizeT)(p->buf - src);
751  (*srcLen) += processed;
752  src += processed;
753  inSize -= processed;
754  } else {
755  unsigned rem = p->tempBufSize, lookAhead = 0;
756  while (rem < LZMA_REQUIRED_INPUT_MAX && lookAhead < inSize)
757  p->tempBuf[rem++] = src[lookAhead++];
758  p->tempBufSize = rem;
759  if (rem < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow) {
760  int dummyRes = LzmaDec_TryDummy(p, p->tempBuf, rem);
761  if (dummyRes == DUMMY_ERROR) {
762  (*srcLen) += lookAhead;
764  return SZ_OK;
765  }
766  if (checkEndMarkNow && dummyRes != DUMMY_MATCH) {
768  return SZ_ERROR_DATA;
769  }
770  }
771  p->buf = p->tempBuf;
772  if (LzmaDec_DecodeReal2(p, dicLimit, p->buf) != 0)
773  return SZ_ERROR_DATA;
774  lookAhead -= (rem - (unsigned)(p->buf - p->tempBuf));
775  (*srcLen) += lookAhead;
776  src += lookAhead;
777  inSize -= lookAhead;
778  p->tempBufSize = 0;
779  }
780  }
781  if (p->code == 0)
783  return (p->code == 0) ? SZ_OK : SZ_ERROR_DATA;
784 }
#define SZ_ERROR_DATA
Definition: Types.h:27
static void LzmaDec_WriteRem(CLzmaDec *p, SizeT limit)
Definition: LzmaDec.cc:444
static void LzmaDec_InitRc(CLzmaDec *p, const Byte *data)
Definition: LzmaDec.cc:647
size_t SizeT
Definition: Types.h:97
static int LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte *bufLimit)
Definition: LzmaDec.cc:467
#define LZMA_REQUIRED_INPUT_MAX
Definition: LzmaDec.h:45
#define kMatchSpecLenStart
Definition: LzmaDec.cc:146
#define SZ_OK
Definition: Types.h:25
#define RC_INIT_SIZE
Definition: LzmaDec.cc:15
unsigned char Byte
Definition: Types.h:60
static void LzmaDec_InitStateReal(CLzmaDec *p)
Definition: LzmaDec.cc:672
static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inSize)
Definition: LzmaDec.cc:494

◆ LzmaDec_Free()

void LzmaDec_Free ( CLzmaDec state,
ISzAlloc alloc 
)

Definition at line 837 of file LzmaDec.cc.

References LzmaDec_FreeDict(), LzmaDec_FreeProbs(), and AlCaHLTBitMon_ParallelJobs::p.

Referenced by LzmaFile::Close().

837  {
838  LzmaDec_FreeProbs(p, alloc);
839  LzmaDec_FreeDict(p, alloc);
840 }
void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)
Definition: LzmaDec.cc:827
static void LzmaDec_FreeDict(CLzmaDec *p, ISzAlloc *alloc)
Definition: LzmaDec.cc:832

◆ LzmaDec_FreeProbs()

void LzmaDec_FreeProbs ( CLzmaDec p,
ISzAlloc alloc 
)

Definition at line 827 of file LzmaDec.cc.

References ISzAlloc::Free, and AlCaHLTBitMon_ParallelJobs::p.

Referenced by LzmaDec_Allocate(), LzmaDec_AllocateProbs2(), LzmaDec_Free(), and LzmaDecode().

827  {
828  alloc->Free(alloc, p->probs);
829  p->probs = nullptr;
830 }
void(* Free)(void *p, void *address)
Definition: Types.h:217

◆ LzmaDec_Init()

void LzmaDec_Init ( CLzmaDec p)

Definition at line 667 of file LzmaDec.cc.

References LzmaDec_InitDicAndState(), AlCaHLTBitMon_ParallelJobs::p, and True.

Referenced by LzmaDecode(), and LzmaFile::Open().

667  {
668  p->dicPos = 0;
670 }
void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState)
Definition: LzmaDec.cc:653
#define True
Definition: Types.h:101

◆ LzmaDecode()

SRes LzmaDecode ( Byte dest,
SizeT destLen,
const Byte src,
SizeT srcLen,
const Byte propData,
unsigned  propSize,
ELzmaFinishMode  finishMode,
ELzmaStatus status,
ISzAlloc alloc 
)

Definition at line 906 of file LzmaDec.cc.

References mps_fire::dest, LZMA_STATUS_NEEDS_MORE_INPUT, LzmaDec_AllocateProbs(), LzmaDec_Construct, LzmaDec_DecodeToDic(), LzmaDec_FreeProbs(), LzmaDec_Init(), AlCaHLTBitMon_ParallelJobs::p, RC_INIT_SIZE, TrackRefitter_38T_cff::src, mps_update::status, SZ_ERROR_INPUT_EOF, and SZ_OK.

914  {
915  CLzmaDec p;
916  SRes res;
917  SizeT inSize = *srcLen;
918  SizeT outSize = *destLen;
919  *srcLen = *destLen = 0;
920  if (inSize < RC_INIT_SIZE)
921  return SZ_ERROR_INPUT_EOF;
922 
924  res = LzmaDec_AllocateProbs(&p, propData, propSize, alloc);
925  if (res != 0)
926  return res;
927  p.dic = dest;
928  p.dicBufSize = outSize;
929 
930  LzmaDec_Init(&p);
931 
932  *srcLen = inSize;
933  res = LzmaDec_DecodeToDic(&p, outSize, src, srcLen, finishMode, status);
934 
937 
938  (*destLen) = p.dicPos;
939  LzmaDec_FreeProbs(&p, alloc);
940  return res;
941 }
#define SZ_ERROR_INPUT_EOF
Definition: Types.h:32
void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)
Definition: LzmaDec.cc:827
SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
Definition: LzmaDec.cc:683
Definition: Electron.h:6
size_t SizeT
Definition: Types.h:97
int SRes
Definition: Types.h:43
SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)
Definition: LzmaDec.cc:879
#define SZ_OK
Definition: Types.h:25
#define LzmaDec_Construct(p)
Definition: LzmaDec.h:67
#define RC_INIT_SIZE
Definition: LzmaDec.cc:15
void LzmaDec_Init(CLzmaDec *p)
Definition: LzmaDec.cc:667

◆ LzmaProps_Decode()

SRes LzmaProps_Decode ( CLzmaProps p,
const Byte data,
unsigned  size 
)

Definition at line 842 of file LzmaDec.cc.

References ztail::d, data, LZMA_DIC_MIN, LZMA_PROPS_SIZE, AlCaHLTBitMon_ParallelJobs::p, findQualityFiles::size, SZ_ERROR_UNSUPPORTED, and SZ_OK.

Referenced by LzmaDec_Allocate(), and LzmaDec_AllocateProbs().

842  {
843  UInt32 dicSize;
844  Byte d;
845 
846  if (size < LZMA_PROPS_SIZE)
847  return SZ_ERROR_UNSUPPORTED;
848  else
849  dicSize = data[1] | ((UInt32)data[2] << 8) | ((UInt32)data[3] << 16) | ((UInt32)data[4] << 24);
850 
851  if (dicSize < LZMA_DIC_MIN)
852  dicSize = LZMA_DIC_MIN;
853  p->dicSize = dicSize;
854 
855  d = data[0];
856  if (d >= (9 * 5 * 5))
857  return SZ_ERROR_UNSUPPORTED;
858 
859  p->lc = d % 9;
860  d /= 9;
861  p->pb = d / 5;
862  p->lp = d % 5;
863 
864  return SZ_OK;
865 }
size
Write out results.
#define LZMA_PROPS_SIZE
Definition: LzmaDec.h:25
unsigned int UInt32
Definition: Types.h:69
#define SZ_OK
Definition: Types.h:25
d
Definition: ztail.py:151
#define LZMA_DIC_MIN
Definition: LzmaDec.cc:170
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
unsigned char Byte
Definition: Types.h:60
#define SZ_ERROR_UNSUPPORTED
Definition: Types.h:30