Leaked source code of windows server 2003
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.

191 lines
6.8 KiB

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