goat3d

diff libs/openctm/liblzma/LzmaDec.h @ 14:188c697b3b49

- added a document describing the goat3d file format chunk hierarchy - started an alternative XML-based file format - added the openctm library
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 26 Sep 2013 04:47:05 +0300
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libs/openctm/liblzma/LzmaDec.h	Thu Sep 26 04:47:05 2013 +0300
     1.3 @@ -0,0 +1,223 @@
     1.4 +/* LzmaDec.h -- LZMA Decoder
     1.5 +2008-10-04 : Igor Pavlov : Public domain */
     1.6 +
     1.7 +#ifndef __LZMADEC_H
     1.8 +#define __LZMADEC_H
     1.9 +
    1.10 +#include "Types.h"
    1.11 +
    1.12 +/* #define _LZMA_PROB32 */
    1.13 +/* _LZMA_PROB32 can increase the speed on some CPUs,
    1.14 +   but memory usage for CLzmaDec::probs will be doubled in that case */
    1.15 +
    1.16 +#ifdef _LZMA_PROB32
    1.17 +#define CLzmaProb UInt32
    1.18 +#else
    1.19 +#define CLzmaProb UInt16
    1.20 +#endif
    1.21 +
    1.22 +
    1.23 +/* ---------- LZMA Properties ---------- */
    1.24 +
    1.25 +#define LZMA_PROPS_SIZE 5
    1.26 +
    1.27 +typedef struct _CLzmaProps
    1.28 +{
    1.29 +  unsigned lc, lp, pb;
    1.30 +  UInt32 dicSize;
    1.31 +} CLzmaProps;
    1.32 +
    1.33 +/* LzmaProps_Decode - decodes properties
    1.34 +Returns:
    1.35 +  SZ_OK
    1.36 +  SZ_ERROR_UNSUPPORTED - Unsupported properties
    1.37 +*/
    1.38 +
    1.39 +SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size);
    1.40 +
    1.41 +
    1.42 +/* ---------- LZMA Decoder state ---------- */
    1.43 +
    1.44 +/* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case.
    1.45 +   Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */
    1.46 +
    1.47 +#define LZMA_REQUIRED_INPUT_MAX 20
    1.48 +
    1.49 +typedef struct
    1.50 +{
    1.51 +  CLzmaProps prop;
    1.52 +  CLzmaProb *probs;
    1.53 +  Byte *dic;
    1.54 +  const Byte *buf;
    1.55 +  UInt32 range, code;
    1.56 +  SizeT dicPos;
    1.57 +  SizeT dicBufSize;
    1.58 +  UInt32 processedPos;
    1.59 +  UInt32 checkDicSize;
    1.60 +  unsigned state;
    1.61 +  UInt32 reps[4];
    1.62 +  unsigned remainLen;
    1.63 +  int needFlush;
    1.64 +  int needInitState;
    1.65 +  UInt32 numProbs;
    1.66 +  unsigned tempBufSize;
    1.67 +  Byte tempBuf[LZMA_REQUIRED_INPUT_MAX];
    1.68 +} CLzmaDec;
    1.69 +
    1.70 +#define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; }
    1.71 +
    1.72 +void LzmaDec_Init(CLzmaDec *p);
    1.73 +
    1.74 +/* There are two types of LZMA streams:
    1.75 +     0) Stream with end mark. That end mark adds about 6 bytes to compressed size.
    1.76 +     1) Stream without end mark. You must know exact uncompressed size to decompress such stream. */
    1.77 +
    1.78 +typedef enum
    1.79 +{
    1.80 +  LZMA_FINISH_ANY,   /* finish at any point */
    1.81 +  LZMA_FINISH_END    /* block must be finished at the end */
    1.82 +} ELzmaFinishMode;
    1.83 +
    1.84 +/* ELzmaFinishMode has meaning only if the decoding reaches output limit !!!
    1.85 +
    1.86 +   You must use LZMA_FINISH_END, when you know that current output buffer
    1.87 +   covers last bytes of block. In other cases you must use LZMA_FINISH_ANY.
    1.88 +
    1.89 +   If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK,
    1.90 +   and output value of destLen will be less than output buffer size limit.
    1.91 +   You can check status result also.
    1.92 +
    1.93 +   You can use multiple checks to test data integrity after full decompression:
    1.94 +     1) Check Result and "status" variable.
    1.95 +     2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.
    1.96 +     3) Check that output(srcLen) = compressedSize, if you know real compressedSize.
    1.97 +        You must use correct finish mode in that case. */
    1.98 +
    1.99 +typedef enum
   1.100 +{
   1.101 +  LZMA_STATUS_NOT_SPECIFIED,               /* use main error code instead */
   1.102 +  LZMA_STATUS_FINISHED_WITH_MARK,          /* stream was finished with end mark. */
   1.103 +  LZMA_STATUS_NOT_FINISHED,                /* stream was not finished */
   1.104 +  LZMA_STATUS_NEEDS_MORE_INPUT,            /* you must provide more input bytes */
   1.105 +  LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK  /* there is probability that stream was finished without end mark */
   1.106 +} ELzmaStatus;
   1.107 +
   1.108 +/* ELzmaStatus is used only as output value for function call */
   1.109 +
   1.110 +
   1.111 +/* ---------- Interfaces ---------- */
   1.112 +
   1.113 +/* There are 3 levels of interfaces:
   1.114 +     1) Dictionary Interface
   1.115 +     2) Buffer Interface
   1.116 +     3) One Call Interface
   1.117 +   You can select any of these interfaces, but don't mix functions from different
   1.118 +   groups for same object. */
   1.119 +
   1.120 +
   1.121 +/* There are two variants to allocate state for Dictionary Interface:
   1.122 +     1) LzmaDec_Allocate / LzmaDec_Free
   1.123 +     2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs
   1.124 +   You can use variant 2, if you set dictionary buffer manually.
   1.125 +   For Buffer Interface you must always use variant 1.
   1.126 +
   1.127 +LzmaDec_Allocate* can return:
   1.128 +  SZ_OK
   1.129 +  SZ_ERROR_MEM         - Memory allocation error
   1.130 +  SZ_ERROR_UNSUPPORTED - Unsupported properties
   1.131 +*/
   1.132 +   
   1.133 +SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc);
   1.134 +void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc);
   1.135 +
   1.136 +SRes LzmaDec_Allocate(CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAlloc *alloc);
   1.137 +void LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc);
   1.138 +
   1.139 +/* ---------- Dictionary Interface ---------- */
   1.140 +
   1.141 +/* You can use it, if you want to eliminate the overhead for data copying from
   1.142 +   dictionary to some other external buffer.
   1.143 +   You must work with CLzmaDec variables directly in this interface.
   1.144 +
   1.145 +   STEPS:
   1.146 +     LzmaDec_Constr()
   1.147 +     LzmaDec_Allocate()
   1.148 +     for (each new stream)
   1.149 +     {
   1.150 +       LzmaDec_Init()
   1.151 +       while (it needs more decompression)
   1.152 +       {
   1.153 +         LzmaDec_DecodeToDic()
   1.154 +         use data from CLzmaDec::dic and update CLzmaDec::dicPos
   1.155 +       }
   1.156 +     }
   1.157 +     LzmaDec_Free()
   1.158 +*/
   1.159 +
   1.160 +/* LzmaDec_DecodeToDic
   1.161 +   
   1.162 +   The decoding to internal dictionary buffer (CLzmaDec::dic).
   1.163 +   You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!
   1.164 +
   1.165 +finishMode:
   1.166 +  It has meaning only if the decoding reaches output limit (dicLimit).
   1.167 +  LZMA_FINISH_ANY - Decode just dicLimit bytes.
   1.168 +  LZMA_FINISH_END - Stream must be finished after dicLimit.
   1.169 +
   1.170 +Returns:
   1.171 +  SZ_OK
   1.172 +    status:
   1.173 +      LZMA_STATUS_FINISHED_WITH_MARK
   1.174 +      LZMA_STATUS_NOT_FINISHED
   1.175 +      LZMA_STATUS_NEEDS_MORE_INPUT
   1.176 +      LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
   1.177 +  SZ_ERROR_DATA - Data error
   1.178 +*/
   1.179 +
   1.180 +SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit,
   1.181 +    const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
   1.182 +
   1.183 +
   1.184 +/* ---------- Buffer Interface ---------- */
   1.185 +
   1.186 +/* It's zlib-like interface.
   1.187 +   See LzmaDec_DecodeToDic description for information about STEPS and return results,
   1.188 +   but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need
   1.189 +   to work with CLzmaDec variables manually.
   1.190 +
   1.191 +finishMode:
   1.192 +  It has meaning only if the decoding reaches output limit (*destLen).
   1.193 +  LZMA_FINISH_ANY - Decode just destLen bytes.
   1.194 +  LZMA_FINISH_END - Stream must be finished after (*destLen).
   1.195 +*/
   1.196 +
   1.197 +SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen,
   1.198 +    const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
   1.199 +
   1.200 +
   1.201 +/* ---------- One Call Interface ---------- */
   1.202 +
   1.203 +/* LzmaDecode
   1.204 +
   1.205 +finishMode:
   1.206 +  It has meaning only if the decoding reaches output limit (*destLen).
   1.207 +  LZMA_FINISH_ANY - Decode just destLen bytes.
   1.208 +  LZMA_FINISH_END - Stream must be finished after (*destLen).
   1.209 +
   1.210 +Returns:
   1.211 +  SZ_OK
   1.212 +    status:
   1.213 +      LZMA_STATUS_FINISHED_WITH_MARK
   1.214 +      LZMA_STATUS_NOT_FINISHED
   1.215 +      LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
   1.216 +  SZ_ERROR_DATA - Data error
   1.217 +  SZ_ERROR_MEM  - Memory allocation error
   1.218 +  SZ_ERROR_UNSUPPORTED - Unsupported properties
   1.219 +  SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).
   1.220 +*/
   1.221 +
   1.222 +SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
   1.223 +    const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,
   1.224 +    ELzmaStatus *status, ISzAlloc *alloc);
   1.225 +
   1.226 +#endif