Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

166 lines
4.6 KiB

  1. #ifndef _XPRESS_H_
  2. #define _XPRESS_H_
  3. #ifdef _MSC_VER
  4. #pragma once
  5. #endif
  6. /* -------------------------------------------------------------------- */
  7. /* */
  8. /* Copyright (c) 1991-1999 by Andrew Kadatch */
  9. /* */
  10. /* -------------------------------------------------------------------- */
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. /* ---------------------- Common declarations ------------------------- */
  15. /* ------------------- */
  16. // max. size of input block
  17. #define XPRESS_MAX_BLOCK_LOG 16
  18. #define XPRESS_MAX_BLOCK (1 << XPRESS_MAX_BLOCK_LOG)
  19. // preferred data alignment to avoid misaligned accesses
  20. #define XPRESS_ALIGNMENT 8
  21. // declare default calling convention used in xpress
  22. #if !defined (UNIX) && !defined (XPRESS_CALL)
  23. #define XPRESS_CALL __stdcall
  24. #endif
  25. // user-supplied callback function that allocates memory
  26. // if there is no memory available it shall return NULL
  27. typedef
  28. void *
  29. XPRESS_CALL
  30. XpressAllocFn
  31. (
  32. void *context, // user-defined context (as passed to XpressEncodeCreate)
  33. int size // size of memory block to allocate
  34. );
  35. // user-supplied callback function that releases memory
  36. typedef
  37. void
  38. XPRESS_CALL
  39. XpressFreeFn
  40. (
  41. void *context, // user-defined context (as passed to XpressEncodeClose)
  42. void *address // pointer to the block to be freed
  43. );
  44. /* ----------------------------- Encoder ------------------------------ */
  45. /* ------- */
  46. // declare unique anonymous types for type safety
  47. typedef struct {int XpressEncodeDummy;} *XpressEncodeStream;
  48. // allocate and initialize encoder's data structures
  49. // returns NULL if callback returned NULL (not enough memory)
  50. XpressEncodeStream
  51. XPRESS_CALL
  52. XpressEncodeCreate
  53. (
  54. int MaxOrigSize, // max size of original data block
  55. void *context, // user-defined context info (will be passed to AllocFn)
  56. XpressAllocFn *AllocFn, // memory allocation callback
  57. int CompressionLevel // use 0 for speed, 9 for quality
  58. );
  59. // callback function called by XpressEncode to indicate compression progress
  60. typedef
  61. void
  62. XPRESS_CALL
  63. XpressProgressFn
  64. (
  65. void *context, // user-defined context
  66. int compressed // size of processed original data
  67. );
  68. // returns size of compressed data
  69. // if compression failed then compressed buffer is left as is, and
  70. // original data should be saved instead
  71. int
  72. XPRESS_CALL
  73. XpressEncode
  74. (
  75. XpressEncodeStream stream, // encoder's workspace
  76. void *CompAdr, int CompSize, // compressed data region
  77. const void *OrigAdr, int OrigSize, // input data block
  78. XpressProgressFn *ProgressFn, // NULL or progress callback
  79. void *ProgressContext, // user-defined context that will be passed to ProgressFn
  80. int ProgressSize // call ProgressFn each time ProgressSize bytes processed
  81. );
  82. // invalidate input stream and release workspace memory
  83. void
  84. XPRESS_CALL
  85. XpressEncodeClose
  86. (
  87. XpressEncodeStream stream, // encoder's workspace
  88. void *context, XpressFreeFn *FreeFn // memory releasing callback
  89. );
  90. /* ----------------------------- Decoder ------------------------------ */
  91. /* ------- */
  92. // declare unique anonymous types for type safety
  93. typedef struct {int XpressDecodeDummy;} *XpressDecodeStream;
  94. // allocate memory for decoder. Returns NULL if not enough memory.
  95. XpressDecodeStream
  96. XPRESS_CALL
  97. XpressDecodeCreate
  98. (
  99. void *context, // user-defined context info (will be passed to AllocFn)
  100. XpressAllocFn *AllocFn // memory allocation callback
  101. );
  102. // decode compressed block. Returns # of decoded bytes or -1 otherwise
  103. int
  104. XPRESS_CALL
  105. XpressDecode
  106. (
  107. XpressDecodeStream stream, // decoder's workspace
  108. void *OrigAdr, int OrigSize, // original data region
  109. int DecodeSize, // # of bytes to decode ( <= OrigSize)
  110. const void *CompAdr, int CompSize // compressed data block
  111. );
  112. void
  113. XPRESS_CALL
  114. XpressDecodeClose
  115. (
  116. XpressDecodeStream stream, // encoder's workspace
  117. void *context, // user-defined context info (will be passed to FreeFn)
  118. XpressFreeFn *FreeFn // callback that releases the memory
  119. );
  120. /* ------------------------------ CRC32 ------------------------------- */
  121. /* ----- */
  122. int
  123. XPRESS_CALL
  124. XpressCrc32
  125. (
  126. const void *data, // beginning of data block
  127. int bytes, // number of bytes
  128. int crc // initial value
  129. );
  130. #ifdef __cplusplus
  131. };
  132. #endif
  133. #endif /* _XPRESS_H_ */