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.

273 lines
7.8 KiB

  1. /*
  2. * Microsoft Confidential
  3. * Copyright (C) Microsoft Corporation 1996
  4. * All Rights Reserved.
  5. *
  6. * LCI.H - Diamond Memory Compression Interface (LCI)
  7. *
  8. * History:
  9. * 03-Jul-1996 jforbes Created from QCI.H
  10. *
  11. * Functions:
  12. * LCICreateCompression - Create and reset an LCI compression context
  13. * LCICompress - Compress a block of data
  14. * LCIResetCompression - Reset compression context
  15. * LCIDestroyCompression - Destroy LCI compression context
  16. * LCISetTranslationSize - Set file translation size
  17. *
  18. * Types:
  19. * LCI_CONTEXT_HANDLE - Handle to an LCI compression context
  20. * PFNALLOC - Memory allocation function for LCI
  21. * PFNFREE - Free memory function for LCI
  22. */
  23. /* --- types -------------------------------------------------------------- */
  24. #include <basetsd.h>
  25. #ifndef DIAMONDAPI
  26. #define DIAMONDAPI __cdecl
  27. #endif
  28. #ifndef _BYTE_DEFINED
  29. #define _BYTE_DEFINED
  30. typedef unsigned char BYTE;
  31. #endif
  32. #ifndef _UINT_DEFINED
  33. #define _UINT_DEFINED
  34. typedef unsigned int UINT;
  35. #endif
  36. #ifndef _ULONG_DEFINED
  37. #define _ULONG_DEFINED
  38. typedef unsigned long ULONG;
  39. #endif
  40. #ifndef FAR
  41. #ifdef BIT16
  42. #define FAR far
  43. #else
  44. #define FAR
  45. #endif
  46. #endif
  47. #ifndef HUGE
  48. #ifdef BIT16
  49. #define HUGE huge
  50. #else
  51. #define HUGE
  52. #endif
  53. #endif
  54. #ifndef _MI_MEMORY_DEFINED
  55. #define _MI_MEMORY_DEFINED
  56. typedef void HUGE * MI_MEMORY;
  57. #endif
  58. #ifndef _MHANDLE_DEFINED
  59. #define _MHANDLE_DEFINED
  60. #if defined(_AMD64_) || defined(IA64)
  61. typedef ULONG_PTR MHANDLE;
  62. #else
  63. typedef unsigned long MHANDLE;
  64. #endif
  65. #endif
  66. /* --- LCI-defined types -------------------------------------------------- */
  67. /* LCI_CONTEXT_HANDLE - Handle to an LCI compression context */
  68. typedef MHANDLE LCI_CONTEXT_HANDLE; /* hmc */
  69. /*** PFNALLOC - Memory allocation function for LCI
  70. *
  71. * Entry:
  72. * cb - Size in bytes of memory block to allocate
  73. *
  74. * Exit-Success:
  75. * Returns !NULL pointer to memory block
  76. *
  77. * Exit-Failure:
  78. * Returns NULL; insufficient memory
  79. */
  80. #ifndef _PFNALLOC_DEFINED
  81. #define _PFNALLOC_DEFINED
  82. typedef MI_MEMORY (FAR DIAMONDAPI *PFNALLOC)(ULONG cb); /* pfnma */
  83. #endif
  84. /*** PFNFREE - Free memory function for LCI
  85. *
  86. * Entry:
  87. * pv - Memory block allocated by matching PFNALLOC function
  88. *
  89. * Exit:
  90. * Memory block freed.
  91. */
  92. #ifndef _PFNFREE_DEFINED
  93. #define _PFNFREE_DEFINED
  94. typedef void (FAR DIAMONDAPI *PFNFREE)(MI_MEMORY pv); /* pfnmf */
  95. #endif
  96. /* --- prototypes --------------------------------------------------------- */
  97. /*** LCICreateCompression - Create LCI compression context
  98. *
  99. * Entry:
  100. * pcbDataBlockMax *largest uncompressed data block size desired,
  101. * gets largest uncompressed data block allowed
  102. * pvConfiguration passes implementation-specific info to compressor.
  103. * pfnma memory allocation function pointer
  104. * pfnmf memory free function pointer
  105. * pcbDstBufferMin gets required compressed data buffer size
  106. * pmchHandle gets newly-created context's handle
  107. *
  108. * Exit-Success:
  109. * Returns MCI_ERROR_NO_ERROR;
  110. * *pcbDataBlockMax, *pcbDstBufferMin, *pmchHandle filled in.
  111. *
  112. * Exit-Failure:
  113. * MCI_ERROR_NOT_ENOUGH_MEMORY, could not allocate enough memory.
  114. * MCI_ERROR_BAD_PARAMETERS, something wrong with parameters.
  115. */
  116. int FAR DIAMONDAPI LCICreateCompression(
  117. UINT FAR * pcbDataBlockMax, /* max uncompressed data block size */
  118. void FAR * pvConfiguration, /* See LZXCONFIGURATION */
  119. PFNALLOC pfnma, /* Memory allocation function ptr */
  120. PFNFREE pfnmf, /* Memory free function ptr */
  121. UINT FAR * pcbDstBufferMin, /* gets required output buffer size */
  122. LCI_CONTEXT_HANDLE FAR *pmchHandle, /* gets newly-created handle */
  123. int FAR (DIAMONDAPI *pfnlzx_output_callback)(
  124. void * pfol,
  125. unsigned char * compressed_data,
  126. long compressed_size,
  127. long uncompressed_size
  128. ),
  129. void FAR * fci_pv // not the same as the FCI client's pv
  130. );
  131. /*** LCICompress - Compress a block of data
  132. *
  133. * Entry:
  134. * hmc handle to compression context
  135. * pbSrc source buffer (uncompressed data)
  136. * cbSrc size of data to be compressed
  137. * pbDst destination buffer (for compressed data)
  138. * cbDst size of destination buffer
  139. * pcbResult receives compressed size of data
  140. *
  141. * Exit-Success:
  142. * Returns MCI_ERROR_NO_ERROR;
  143. * *pcbResult has size of compressed data in pbDst.
  144. * Compression context possibly updated.
  145. *
  146. * Exit-Failure:
  147. * MCI_ERROR_BAD_PARAMETERS, something wrong with parameters.
  148. */
  149. int FAR DIAMONDAPI LCICompress(
  150. LCI_CONTEXT_HANDLE hmc, /* compression context */
  151. void FAR * pbSrc, /* source buffer */
  152. UINT cbSrc, /* source buffer size */
  153. void FAR * pbDst, /* target buffer */
  154. UINT cbDst, /* target buffer size */
  155. ULONG FAR * pcbResult); /* gets target data size */
  156. /*** LCIResetCompression - Reset compression history (if any)
  157. *
  158. * De-compression can only be started on a block which was compressed
  159. * immediately following a LCICreateCompression() or LCIResetCompression()
  160. * call. This function forces such a new "compression boundary" to be
  161. * created (only by causing the compressor to ignore history, can the data
  162. * output be decompressed without history.)
  163. *
  164. * Entry:
  165. * hmc - handle to compression context
  166. *
  167. * Exit-Success:
  168. * Returns MCI_ERROR_NO_ERROR;
  169. * Compression context reset.
  170. *
  171. * Exit-Failure:
  172. * Returns MCI_ERROR_BAD_PARAMETERS, invalid context handle.
  173. */
  174. int FAR DIAMONDAPI LCIResetCompression(LCI_CONTEXT_HANDLE hmc);
  175. /*** LCIDestroyCompression - Destroy LCI compression context
  176. *
  177. * Entry:
  178. * hmc - handle to compression context
  179. *
  180. * Exit-Success:
  181. * Returns MCI_ERROR_NO_ERROR;
  182. * Compression context destroyed.
  183. *
  184. * Exit-Failure:
  185. * Returns MCI_ERROR_BAD_PARAMETERS, invalid context handle.
  186. */
  187. int FAR DIAMONDAPI LCIDestroyCompression(LCI_CONTEXT_HANDLE hmc);
  188. /*
  189. * Forces encoder to flush remaining output
  190. */
  191. int FAR DIAMONDAPI LCIFlushCompressorOutput(LCI_CONTEXT_HANDLE hmc);
  192. /*
  193. * Set the file translation size
  194. * (this must be done immediately after a reset, or an LCICreateCompression)
  195. */
  196. int FAR DIAMONDAPI LCISetTranslationSize(LCI_CONTEXT_HANDLE hmc, unsigned long size);
  197. /*
  198. * Returns a pointer to the input data present in LZX's buffers.
  199. *
  200. * input_position is the offset of the data from the beginning of the file
  201. * bytes_available is the number of bytes available from that offset
  202. */
  203. unsigned char * FAR DIAMONDAPI LCIGetInputData(
  204. LCI_CONTEXT_HANDLE hmc,
  205. unsigned long *input_position,
  206. unsigned long *bytes_available
  207. );
  208. /* --- constants ---------------------------------------------------------- */
  209. /* return codes */
  210. #define MCI_ERROR_NO_ERROR 0
  211. #define MCI_ERROR_NOT_ENOUGH_MEMORY 1
  212. #define MCI_ERROR_BAD_PARAMETERS 2
  213. #define MCI_ERROR_BUFFER_OVERFLOW 3
  214. #define MCI_ERROR_FAILED 4
  215. #define MCI_ERROR_CONFIGURATION 5
  216. /* --- LZX configuration details ------------------------------------- */
  217. /*** LZX pvConfiguration structure
  218. *
  219. * The SecondPartitionSize must be >= 32K. It is the amount of
  220. * data which LZX compresses before copymem'ing the window and
  221. * tree contents around.
  222. */
  223. #pragma pack (2)
  224. typedef struct {
  225. int WindowSize; // buffer size
  226. int SecondPartitionSize;
  227. } LZXCONFIGURATION; /* lcfg */
  228. #pragma pack ()
  229. typedef LZXCONFIGURATION *PLZXCONFIGURATION; /* plcfg */
  230. /* ----------------------------------------------------------------------- */