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.

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