LzmaDecode.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. LzmaDecode.h
  3. LZMA Decoder interface
  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 __LZMADECODE_H
  19. #define __LZMADECODE_H
  20. #include "LzmaTypes.h"
  21. /* #define _LZMA_IN_CB */
  22. /* Use callback for input data */
  23. /* #define _LZMA_OUT_READ */
  24. /* Use read function for output data */
  25. /* #define _LZMA_PROB32 */
  26. /* It can increase speed on some 32-bit CPUs,
  27. but memory usage will be doubled in that case */
  28. /* #define _LZMA_LOC_OPT */
  29. /* Enable local speed optimizations inside code */
  30. #ifdef _LZMA_PROB32
  31. #define CProb UInt32
  32. #else
  33. #define CProb UInt16
  34. #endif
  35. #define LZMA_RESULT_OK 0
  36. #define LZMA_RESULT_DATA_ERROR 1
  37. #ifdef _LZMA_IN_CB
  38. typedef struct _ILzmaInCallback
  39. {
  40. int (*Read)(void *object, const unsigned char **buffer, SizeT *bufferSize);
  41. } ILzmaInCallback;
  42. #endif
  43. #define LZMA_BASE_SIZE 1846
  44. #define LZMA_LIT_SIZE 768
  45. #define LZMA_PROPERTIES_SIZE 5
  46. typedef struct _CLzmaProperties
  47. {
  48. int lc;
  49. int lp;
  50. int pb;
  51. #ifdef _LZMA_OUT_READ
  52. UInt32 DictionarySize;
  53. #endif
  54. }CLzmaProperties;
  55. int LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size);
  56. #define LzmaGetNumProbs(Properties) (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((Properties)->lc + (Properties)->lp)))
  57. #define kLzmaNeedInitId (-2)
  58. typedef struct _CLzmaDecoderState
  59. {
  60. CLzmaProperties Properties;
  61. CProb *Probs;
  62. #ifdef _LZMA_IN_CB
  63. const unsigned char *Buffer;
  64. const unsigned char *BufferLim;
  65. #endif
  66. #ifdef _LZMA_OUT_READ
  67. unsigned char *Dictionary;
  68. UInt32 Range;
  69. UInt32 Code;
  70. UInt32 DictionaryPos;
  71. UInt32 GlobalPos;
  72. UInt32 DistanceLimit;
  73. UInt32 Reps[4];
  74. int State;
  75. int RemainLen;
  76. unsigned char TempDictionary[4];
  77. #endif
  78. } CLzmaDecoderState;
  79. #ifdef _LZMA_OUT_READ
  80. #define LzmaDecoderInit(vs) { (vs)->RemainLen = kLzmaNeedInitId; }
  81. #endif
  82. int LzmaDecode(CLzmaDecoderState *vs,
  83. #ifdef _LZMA_IN_CB
  84. ILzmaInCallback *inCallback,
  85. #else
  86. const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed,
  87. #endif
  88. unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed);
  89. #endif