LzmaStateDecode.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. LzmaStateDecode.h
  3. LZMA Decoder interface (State version)
  4. LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01)
  5. http://www.7-zip.org/
  6. LZMA SDK is licensed under two licenses:
  7. 1) GNU Lesser General Public License (GNU LGPL)
  8. 2) Common Public License (CPL)
  9. It means that you can select one of these two licenses and
  10. follow rules of that license.
  11. SPECIAL EXCEPTION:
  12. Igor Pavlov, as the author of this code, expressly permits you to
  13. statically or dynamically link your code (or bind by name) to the
  14. interfaces of this file without subjecting your linked code to the
  15. terms of the CPL or GNU LGPL. Any modifications or additions
  16. to this file, however, are subject to the LGPL or CPL terms.
  17. */
  18. #ifndef __LZMASTATEDECODE_H
  19. #define __LZMASTATEDECODE_H
  20. #include "LzmaTypes.h"
  21. /* #define _LZMA_PROB32 */
  22. /* It can increase speed on some 32-bit CPUs,
  23. but memory usage will be doubled in that case */
  24. #ifdef _LZMA_PROB32
  25. #define CProb UInt32
  26. #else
  27. #define CProb UInt16
  28. #endif
  29. #define LZMA_RESULT_OK 0
  30. #define LZMA_RESULT_DATA_ERROR 1
  31. #define LZMA_BASE_SIZE 1846
  32. #define LZMA_LIT_SIZE 768
  33. #define LZMA_PROPERTIES_SIZE 5
  34. typedef struct _CLzmaProperties
  35. {
  36. int lc;
  37. int lp;
  38. int pb;
  39. UInt32 DictionarySize;
  40. }CLzmaProperties;
  41. int LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size);
  42. #define LzmaGetNumProbs(lzmaProps) (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((lzmaProps)->lc + (lzmaProps)->lp)))
  43. #define kLzmaInBufferSize 64 /* don't change it. it must be larger than kRequiredInBufferSize */
  44. #define kLzmaNeedInitId (-2)
  45. typedef struct _CLzmaDecoderState
  46. {
  47. CLzmaProperties Properties;
  48. CProb *Probs;
  49. unsigned char *Dictionary;
  50. unsigned char Buffer[kLzmaInBufferSize];
  51. int BufferSize;
  52. UInt32 Range;
  53. UInt32 Code;
  54. UInt32 DictionaryPos;
  55. UInt32 GlobalPos;
  56. UInt32 DistanceLimit;
  57. UInt32 Reps[4];
  58. int State;
  59. int RemainLen; /* -2: decoder needs internal initialization
  60. -1: stream was finished,
  61. 0: ok
  62. > 0: need to write RemainLen bytes as match Reps[0],
  63. */
  64. unsigned char TempDictionary[4]; /* it's required when DictionarySize = 0 */
  65. } CLzmaDecoderState;
  66. #define LzmaDecoderInit(vs) { (vs)->RemainLen = kLzmaNeedInitId; (vs)->BufferSize = 0; }
  67. /* LzmaDecode: decoding from input stream to output stream.
  68. If finishDecoding != 0, then there are no more bytes in input stream
  69. after inStream[inSize - 1]. */
  70. int LzmaDecode(CLzmaDecoderState *vs,
  71. const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,
  72. unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed,
  73. int finishDecoding);
  74. #endif