CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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)   { (p)->dic = 0; (p)->probs = 0; }
 

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

#define CLzmaProb   UInt16
#define LZMA_PROPS_SIZE   5

Definition at line 26 of file LzmaDec.h.

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

#define LZMA_REQUIRED_INPUT_MAX   20

Definition at line 48 of file LzmaDec.h.

Referenced by LzmaDec_DecodeToDic().

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

Definition at line 71 of file LzmaDec.h.

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

Typedef Documentation

typedef struct _CLzmaProps CLzmaProps

Enumeration Type Documentation

Enumerator
LZMA_FINISH_ANY 
LZMA_FINISH_END 

Definition at line 79 of file LzmaDec.h.

80 {
81  LZMA_FINISH_ANY, /* finish at any point */
82  LZMA_FINISH_END /* block must be finished at the end */
ELzmaFinishMode
Definition: LzmaDec.h:79
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 100 of file LzmaDec.h.

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

Function Documentation

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

Definition at line 947 of file LzmaDec.cc.

References ISzAlloc::Alloc, CLzmaDec::dic, CLzmaDec::dicBufSize, _CLzmaProps::dicSize, LzmaDec_AllocateProbs2(), LzmaDec_FreeDict(), LzmaDec_FreeProbs(), LzmaProps_Decode(), CLzmaDec::prop, RINOK, SZ_ERROR_MEM, and SZ_OK.

Referenced by LzmaFile::Open().

948 {
949  CLzmaProps propNew;
950  SizeT dicBufSize;
951  RINOK(LzmaProps_Decode(&propNew, props, propsSize));
952  RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));
953  dicBufSize = propNew.dicSize;
954  if (p->dic == 0 || dicBufSize != p->dicBufSize)
955  {
956  LzmaDec_FreeDict(p, alloc);
957  p->dic = (Byte *)alloc->Alloc(alloc, dicBufSize);
958  if (p->dic == 0)
959  {
960  LzmaDec_FreeProbs(p, alloc);
961  return SZ_ERROR_MEM;
962  }
963  }
964  p->dicBufSize = dicBufSize;
965  p->prop = propNew;
966  return SZ_OK;
967 }
void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)
Definition: LzmaDec.cc:880
#define RINOK(x)
Definition: Types.h:52
static void LzmaDec_FreeDict(CLzmaDec *p, ISzAlloc *alloc)
Definition: LzmaDec.cc:886
size_t SizeT
Definition: Types.h:92
void *(* Alloc)(void *p, size_t size)
Definition: Types.h:229
UInt32 dicSize
Definition: LzmaDec.h:31
#define SZ_OK
Definition: Types.h:25
static SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAlloc *alloc)
Definition: LzmaDec.cc:924
SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)
Definition: LzmaDec.cc:898
unsigned char Byte
Definition: Types.h:55
#define SZ_ERROR_MEM
Definition: Types.h:28
SRes LzmaDec_AllocateProbs ( CLzmaDec p,
const Byte props,
unsigned  propsSize,
ISzAlloc alloc 
)

Definition at line 938 of file LzmaDec.cc.

References LzmaDec_AllocateProbs2(), LzmaProps_Decode(), CLzmaDec::prop, RINOK, and SZ_OK.

Referenced by LzmaDecode().

939 {
940  CLzmaProps propNew;
941  RINOK(LzmaProps_Decode(&propNew, props, propsSize));
942  RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));
943  p->prop = propNew;
944  return SZ_OK;
945 }
CLzmaProps prop
Definition: LzmaDec.h:52
#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:924
SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)
Definition: LzmaDec.cc:898
SRes LzmaDec_DecodeToBuf ( CLzmaDec p,
Byte dest,
SizeT destLen,
const Byte src,
SizeT srcLen,
ELzmaFinishMode  finishMode,
ELzmaStatus status 
)

Definition at line 840 of file LzmaDec.cc.

References CLzmaDec::dic, CLzmaDec::dicBufSize, CLzmaDec::dicPos, LZMA_FINISH_ANY, LzmaDec_DecodeToDic(), and SZ_OK.

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

841 {
842  SizeT outSize = *destLen;
843  SizeT inSize = *srcLen;
844  *srcLen = *destLen = 0;
845  for (;;)
846  {
847  SizeT inSizeCur = inSize, outSizeCur, dicPos;
848  ELzmaFinishMode curFinishMode;
849  SRes res;
850  if (p->dicPos == p->dicBufSize)
851  p->dicPos = 0;
852  dicPos = p->dicPos;
853  if (outSize > p->dicBufSize - dicPos)
854  {
855  outSizeCur = p->dicBufSize;
856  curFinishMode = LZMA_FINISH_ANY;
857  }
858  else
859  {
860  outSizeCur = dicPos + outSize;
861  curFinishMode = finishMode;
862  }
863 
864  res = LzmaDec_DecodeToDic(p, outSizeCur, src, &inSizeCur, curFinishMode, status);
865  src += inSizeCur;
866  inSize -= inSizeCur;
867  *srcLen += inSizeCur;
868  outSizeCur = p->dicPos - dicPos;
869  memcpy(dest, p->dic + dicPos, outSizeCur);
870  dest += outSizeCur;
871  outSize -= outSizeCur;
872  *destLen += outSizeCur;
873  if (res != 0)
874  return res;
875  if (outSizeCur == 0 || outSize == 0)
876  return SZ_OK;
877  }
878 }
SizeT dicBufSize
Definition: LzmaDec.h:58
SizeT dicPos
Definition: LzmaDec.h:57
ELzmaFinishMode
Definition: LzmaDec.h:79
Byte * dic
Definition: LzmaDec.h:54
SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
Definition: LzmaDec.cc:719
size_t SizeT
Definition: Types.h:92
int SRes
Definition: Types.h:43
#define SZ_OK
Definition: Types.h:25
tuple status
Definition: ntuplemaker.py:245
SRes LzmaDec_DecodeToDic ( CLzmaDec p,
SizeT  dicLimit,
const Byte src,
SizeT srcLen,
ELzmaFinishMode  finishMode,
ELzmaStatus status 
)

Definition at line 719 of file LzmaDec.cc.

References CLzmaDec::buf, CLzmaDec::code, CLzmaDec::dicPos, DUMMY_ERROR, DUMMY_MATCH, 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(), CLzmaDec::needFlush, CLzmaDec::needInitState, RC_INIT_SIZE, CLzmaDec::remainLen, alcazmumu_cfi::src, SZ_ERROR_DATA, SZ_OK, CLzmaDec::tempBuf, and CLzmaDec::tempBufSize.

Referenced by LzmaDec_DecodeToBuf(), and LzmaDecode().

721 {
722  SizeT inSize = *srcLen;
723  (*srcLen) = 0;
724  LzmaDec_WriteRem(p, dicLimit);
725 
727 
728  while (p->remainLen != kMatchSpecLenStart)
729  {
730  int checkEndMarkNow;
731 
732  if (p->needFlush != 0)
733  {
734  for (; inSize > 0 && p->tempBufSize < RC_INIT_SIZE; (*srcLen)++, inSize--)
735  p->tempBuf[p->tempBufSize++] = *src++;
737  {
739  return SZ_OK;
740  }
741  if (p->tempBuf[0] != 0)
742  return SZ_ERROR_DATA;
743 
744  LzmaDec_InitRc(p, p->tempBuf);
745  p->tempBufSize = 0;
746  }
747 
748  checkEndMarkNow = 0;
749  if (p->dicPos >= dicLimit)
750  {
751  if (p->remainLen == 0 && p->code == 0)
752  {
754  return SZ_OK;
755  }
756  if (finishMode == LZMA_FINISH_ANY)
757  {
759  return SZ_OK;
760  }
761  if (p->remainLen != 0)
762  {
764  return SZ_ERROR_DATA;
765  }
766  checkEndMarkNow = 1;
767  }
768 
769  if (p->needInitState)
771 
772  if (p->tempBufSize == 0)
773  {
774  SizeT processed;
775  const Byte *bufLimit;
776  if (inSize < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)
777  {
778  int dummyRes = LzmaDec_TryDummy(p, src, inSize);
779  if (dummyRes == DUMMY_ERROR)
780  {
781  memcpy(p->tempBuf, src, inSize);
782  p->tempBufSize = (unsigned)inSize;
783  (*srcLen) += inSize;
785  return SZ_OK;
786  }
787  if (checkEndMarkNow && dummyRes != DUMMY_MATCH)
788  {
790  return SZ_ERROR_DATA;
791  }
792  bufLimit = src;
793  }
794  else
795  bufLimit = src + inSize - LZMA_REQUIRED_INPUT_MAX;
796  p->buf = src;
797  if (LzmaDec_DecodeReal2(p, dicLimit, bufLimit) != 0)
798  return SZ_ERROR_DATA;
799  processed = (SizeT)(p->buf - src);
800  (*srcLen) += processed;
801  src += processed;
802  inSize -= processed;
803  }
804  else
805  {
806  unsigned rem = p->tempBufSize, lookAhead = 0;
807  while (rem < LZMA_REQUIRED_INPUT_MAX && lookAhead < inSize)
808  p->tempBuf[rem++] = src[lookAhead++];
809  p->tempBufSize = rem;
810  if (rem < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)
811  {
812  int dummyRes = LzmaDec_TryDummy(p, p->tempBuf, rem);
813  if (dummyRes == DUMMY_ERROR)
814  {
815  (*srcLen) += lookAhead;
817  return SZ_OK;
818  }
819  if (checkEndMarkNow && dummyRes != DUMMY_MATCH)
820  {
822  return SZ_ERROR_DATA;
823  }
824  }
825  p->buf = p->tempBuf;
826  if (LzmaDec_DecodeReal2(p, dicLimit, p->buf) != 0)
827  return SZ_ERROR_DATA;
828  lookAhead -= (rem - (unsigned)(p->buf - p->tempBuf));
829  (*srcLen) += lookAhead;
830  src += lookAhead;
831  inSize -= lookAhead;
832  p->tempBufSize = 0;
833  }
834  }
835  if (p->code == 0)
837  return (p->code == 0) ? SZ_OK : SZ_ERROR_DATA;
838 }
#define SZ_ERROR_DATA
Definition: Types.h:27
SizeT dicPos
Definition: LzmaDec.h:57
static void LzmaDec_WriteRem(CLzmaDec *p, SizeT limit)
Definition: LzmaDec.cc:428
UInt32 code
Definition: LzmaDec.h:56
int needFlush
Definition: LzmaDec.h:64
unsigned tempBufSize
Definition: LzmaDec.h:67
unsigned remainLen
Definition: LzmaDec.h:63
static void LzmaDec_InitRc(CLzmaDec *p, const Byte *data)
Definition: LzmaDec.cc:678
size_t SizeT
Definition: Types.h:92
Byte tempBuf[20]
Definition: LzmaDec.h:68
static int LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte *bufLimit)
Definition: LzmaDec.cc:454
#define LZMA_REQUIRED_INPUT_MAX
Definition: LzmaDec.h:48
#define kMatchSpecLenStart
Definition: LzmaDec.cc:92
#define SZ_OK
Definition: Types.h:25
const Byte * buf
Definition: LzmaDec.h:55
int needInitState
Definition: LzmaDec.h:65
#define RC_INIT_SIZE
Definition: LzmaDec.cc:15
unsigned char Byte
Definition: Types.h:55
tuple status
Definition: ntuplemaker.py:245
if(conf.exists("allCellsPositionCalc"))
static void LzmaDec_InitStateReal(CLzmaDec *p)
Definition: LzmaDec.cc:707
static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inSize)
Definition: LzmaDec.cc:487
void LzmaDec_Free ( CLzmaDec state,
ISzAlloc alloc 
)

Definition at line 892 of file LzmaDec.cc.

References LzmaDec_FreeDict(), and LzmaDec_FreeProbs().

Referenced by LzmaFile::Close().

893 {
894  LzmaDec_FreeProbs(p, alloc);
895  LzmaDec_FreeDict(p, alloc);
896 }
void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)
Definition: LzmaDec.cc:880
static void LzmaDec_FreeDict(CLzmaDec *p, ISzAlloc *alloc)
Definition: LzmaDec.cc:886
void LzmaDec_FreeProbs ( CLzmaDec p,
ISzAlloc alloc 
)

Definition at line 880 of file LzmaDec.cc.

References ISzAlloc::Free, and CLzmaDec::probs.

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

881 {
882  alloc->Free(alloc, p->probs);
883  p->probs = 0;
884 }
UInt16 * probs
Definition: LzmaDec.h:53
void(* Free)(void *p, void *address)
Definition: Types.h:230
void LzmaDec_Init ( CLzmaDec p)

Definition at line 701 of file LzmaDec.cc.

References CLzmaDec::dicPos, LzmaDec_InitDicAndState(), and True.

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

702 {
703  p->dicPos = 0;
705 }
SizeT dicPos
Definition: LzmaDec.h:57
void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState)
Definition: LzmaDec.cc:685
#define True
Definition: Types.h:96
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 969 of file LzmaDec.cc.

References alignCSCRings::dest, CLzmaDec::dic, CLzmaDec::dicBufSize, CLzmaDec::dicPos, LZMA_STATUS_NEEDS_MORE_INPUT, LzmaDec_AllocateProbs(), LzmaDec_Construct, LzmaDec_DecodeToDic(), LzmaDec_FreeProbs(), LzmaDec_Init(), AlCaHLTBitMon_ParallelJobs::p, RC_INIT_SIZE, SZ_ERROR_INPUT_EOF, and SZ_OK.

972 {
973  CLzmaDec p;
974  SRes res;
975  SizeT inSize = *srcLen;
976  SizeT outSize = *destLen;
977  *srcLen = *destLen = 0;
978  if (inSize < RC_INIT_SIZE)
979  return SZ_ERROR_INPUT_EOF;
980 
981  LzmaDec_Construct(&p);
982  res = LzmaDec_AllocateProbs(&p, propData, propSize, alloc);
983  if (res != 0)
984  return res;
985  p.dic = dest;
986  p.dicBufSize = outSize;
987 
988  LzmaDec_Init(&p);
989 
990  *srcLen = inSize;
991  res = LzmaDec_DecodeToDic(&p, outSize, src, srcLen, finishMode, status);
992 
993  if (res == SZ_OK && *status == LZMA_STATUS_NEEDS_MORE_INPUT)
994  res = SZ_ERROR_INPUT_EOF;
995 
996  (*destLen) = p.dicPos;
997  LzmaDec_FreeProbs(&p, alloc);
998  return res;
999 }
#define SZ_ERROR_INPUT_EOF
Definition: Types.h:32
SizeT dicBufSize
Definition: LzmaDec.h:58
SizeT dicPos
Definition: LzmaDec.h:57
void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)
Definition: LzmaDec.cc:880
Byte * dic
Definition: LzmaDec.h:54
SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
Definition: LzmaDec.cc:719
size_t SizeT
Definition: Types.h:92
int SRes
Definition: Types.h:43
SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)
Definition: LzmaDec.cc:938
#define SZ_OK
Definition: Types.h:25
#define LzmaDec_Construct(p)
Definition: LzmaDec.h:71
#define RC_INIT_SIZE
Definition: LzmaDec.cc:15
void LzmaDec_Init(CLzmaDec *p)
Definition: LzmaDec.cc:701
tuple status
Definition: ntuplemaker.py:245
SRes LzmaProps_Decode ( CLzmaProps p,
const Byte data,
unsigned  size 
)

Definition at line 898 of file LzmaDec.cc.

References _CLzmaProps::dicSize, _CLzmaProps::lc, _CLzmaProps::lp, LZMA_DIC_MIN, LZMA_PROPS_SIZE, _CLzmaProps::pb, SZ_ERROR_UNSUPPORTED, and SZ_OK.

Referenced by LzmaDec_Allocate(), and LzmaDec_AllocateProbs().

899 {
900  UInt32 dicSize;
901  Byte d;
902 
903  if (size < LZMA_PROPS_SIZE)
904  return SZ_ERROR_UNSUPPORTED;
905  else
906  dicSize = data[1] | ((UInt32)data[2] << 8) | ((UInt32)data[3] << 16) | ((UInt32)data[4] << 24);
907 
908  if (dicSize < LZMA_DIC_MIN)
909  dicSize = LZMA_DIC_MIN;
910  p->dicSize = dicSize;
911 
912  d = data[0];
913  if (d >= (9 * 5 * 5))
914  return SZ_ERROR_UNSUPPORTED;
915 
916  p->lc = d % 9;
917  d /= 9;
918  p->pb = d / 5;
919  p->lp = d % 5;
920 
921  return SZ_OK;
922 }
unsigned pb
Definition: LzmaDec.h:30
#define LZMA_PROPS_SIZE
Definition: LzmaDec.h:26
unsigned lp
Definition: LzmaDec.h:30
unsigned int UInt32
Definition: Types.h:64
UInt32 dicSize
Definition: LzmaDec.h:31
#define SZ_OK
Definition: Types.h:25
unsigned lc
Definition: LzmaDec.h:30
#define LZMA_DIC_MIN
Definition: LzmaDec.cc:116
unsigned char Byte
Definition: Types.h:55
tuple size
Write out results.
#define SZ_ERROR_UNSUPPORTED
Definition: Types.h:30