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.

202 lines
7.1 KiB

  1. // TXINST.h -- Class definition for CTransformInstance based on ITransformInstance
  2. //#include <stdio.h>
  3. #ifndef __TXINST_H__
  4. #define __TXINST_H__
  5. const DWORD LZX_Current_Version = 2;
  6. #define SOURCE_CHUNK (32*1024)
  7. // Defaults for the control parameters:
  8. #define WINDOW_SIZE 4 //128*1024
  9. #define SECOND_PARTITION_SIZE 2 //64*1024
  10. #define RESET_BLOCK_SIZE 4 //32*1024
  11. #define SOURCE_SIZE (32*1024)
  12. #define LXZ_DEF_OPT_FLAGS 0 // See OPT_FLAG_XXX series below
  13. #define OPT_FLAG_EXE 0x00000001 // Optimizes x86 machine code, but adds overhead
  14. // These counters are reported at the end of debug runs.
  15. extern ULONG cLZXResetDecompressor; // Number of times the decompression state has been reset
  16. extern ULONG cLZXReadFromBuffer; // Number of times we got data from this history window or
  17. // the decoding buffer.
  18. extern ULONG cLZXReadFromCurrentSpan; // Number of times we could continue decoding the current
  19. // reset interval.
  20. extern ULONG cLZXReadFromOtherSpan; // Number of times we had to abandon the current reset
  21. // interval.
  22. #ifdef _DEBUG
  23. void DumpLZXCounts();
  24. #endif // _DEBUG
  25. class CXResetData;
  26. extern CBuffer *pBufferForCompressedData; // Used to read compressed data from next transform
  27. class CTransformInstance : public CITUnknown
  28. {
  29. public:
  30. // Destructor:
  31. ~CTransformInstance(void);
  32. // Creator:
  33. static HRESULT Create(ITransformInstance *pITxInst,
  34. ULARGE_INTEGER cbUntransformedSize, // Untransformed size of data
  35. PXformControlData pXFCD, // Control data for this instance
  36. const CLSID *rclsidXForm, // Transform Class ID
  37. const WCHAR *pwszDataSpaceName, // Data space name for this instance
  38. ITransformServices *pXformServices, // Utility routines
  39. IKeyInstance *pKeyManager, // Interface to get encipheri);
  40. ITransformInstance **ppTransformInstance // Where to return interface pointer
  41. );
  42. private:
  43. CTransformInstance(IUnknown *punkOuter);
  44. class CImpITransformInstance : public IITTransformInstance
  45. {
  46. public:
  47. CImpITransformInstance(CTransformInstance *pBackObj, IUnknown *punkOuter);
  48. ~CImpITransformInstance(void);
  49. //Intialization methods
  50. HRESULT InitTransformInstance(ITransformInstance *pITxInst,
  51. ULARGE_INTEGER cbUntransformedSize, // Untransformed size of data
  52. PXformControlData pXFCD, // Control data for this instance
  53. const CLSID *rclsidXForm, // Transform Class ID
  54. const WCHAR *pwszDataSpaceName, // Data space name for this instance
  55. ITransformServices *pXformServices, // Utility routines
  56. IKeyInstance *pKeyManager); // Interface to get encipheri
  57. //static transform specific methods
  58. static MI_MEMORY __cdecl MyAlloc(ULONG);
  59. static void __cdecl MyFree(MI_MEMORY);
  60. static int __cdecl lzx_output_callback(
  61. void *pfol,
  62. unsigned char *compressed_data,
  63. long compressed_size,
  64. long uncompressed_size
  65. );
  66. //ITransformInstance methods
  67. HRESULT STDMETHODCALLTYPE ReadAt(
  68. /* [in] */ ULARGE_INTEGER ulOffset,
  69. /* [length_is][size_is][out] */ void *pv,
  70. /* [in] */ ULONG cb,
  71. /* [out] */ ULONG *pcbRead,
  72. /* [in] */ ImageSpan *pSpan);
  73. HRESULT STDMETHODCALLTYPE WriteAt(
  74. /* [in] */ ULARGE_INTEGER ulOffset,
  75. /* [size_is][in] */ const void *pv,
  76. /* [in] */ ULONG cb,
  77. /* [out] */ ULONG *pcbWritten,
  78. /* [out] */ImageSpan *pSpan);
  79. STDMETHODIMP SpaceSize(ULARGE_INTEGER *puliSize);
  80. STDMETHODIMP Flush(void);
  81. private:
  82. typedef struct _t_context
  83. {
  84. LCI_CONTEXT_HANDLE cHandle; /* compression context handle */
  85. LDI_CONTEXT_HANDLE dHandle; /* decompression context handle */
  86. LZXCONFIGURATION lcfg;
  87. LZXDECOMPRESS ldec;
  88. ULONG cbResetBlkSize;
  89. UINT cbMaxUncomBufSize;
  90. UINT cbMaxComBufSize;
  91. HRESULT hr;
  92. #if 0 //test code
  93. FILE *m_file;
  94. #endif
  95. } t_context;
  96. HRESULT DeInitTransform();
  97. int GetMulFactor()
  98. {
  99. return (m_context.cbResetBlkSize + m_context.cbMaxUncomBufSize - 1)
  100. / m_context.cbMaxUncomBufSize;
  101. // int N = m_context.cbResetBlkSize / m_context.cbMaxUncomBufSize;
  102. // if (N == 0)
  103. // N = 1;
  104. // return N;
  105. }
  106. HRESULT Commit(void);
  107. HRESULT Write(LPBYTE pbunXBuf, ULONG cbunXBuf);
  108. HRESULT ReconstructCompressionState(PBYTE pbWriteQueueBuffer);
  109. void CopyFromWindow(PBYTE pbDest, ULONG offStart, ULONG cb);
  110. HRESULT HandleReadResidue(PBYTE pb, ULONG *pcbRead, BOOL fEOS, ImageSpan *pSpan,
  111. CULINT ullBase, CULINT ullLimit,
  112. CULINT ullXferBase, CULINT ullXferLimit
  113. );
  114. HRESULT FlushQueuedOutput();
  115. ITransformInstance *m_pITxNextInst;
  116. LZX_Control_Data m_ControlData;
  117. const CLSID *m_rclsidXForm;
  118. const WCHAR *m_pwszDataSpaceName;
  119. ITransformServices *m_pXformServices;
  120. IKeyInstance *m_pKeyManager;
  121. ImageSpan m_ImageSpan;
  122. ImageSpan m_ImageSpanX;
  123. ULONG m_cbUnFlushedBuf; //number of bytes in unflushed buffer
  124. ULONG m_cbResetSpan; //number of bytes in Reset span (X+Unx - not written to disk)
  125. CBuffer m_buffReadCache; // Used when X86 machine code decompression is active.
  126. CBuffer m_buffWriteQueue; // Used to queue up full write blocks for compression.
  127. IStreamITEx *m_pStrmReconstruction; // Stream used to reconstruct the compression
  128. // state for a file we've reloaded.
  129. t_context m_context;
  130. CXResetData *m_pResetData;
  131. BOOL m_fDirty;
  132. BOOL m_fCompressionInitialed;
  133. BOOL m_fInitialed; // True => Initialing completed
  134. BOOL m_fCompressionActive;
  135. BOOL m_fDecompressionActive;
  136. CULINT m_ullResetBase;
  137. CULINT m_ullResetLimit;
  138. CULINT m_ullBuffBase;
  139. CULINT m_ullReadCursor;
  140. CULINT m_ullWindowBase;
  141. PBYTE m_pbHistoryWindow;
  142. LONG m_cbHistoryWindow;
  143. };
  144. CImpITransformInstance m_ImpITxInst;
  145. };
  146. typedef CTransformInstance *PCTransformInstance;
  147. inline CTransformInstance::CTransformInstance(IUnknown *pUnkOuter)
  148. : m_ImpITxInst(this, pUnkOuter),
  149. CITUnknown(&IID_ITransformInstance, 1, &m_ImpITxInst)
  150. {
  151. }
  152. inline CTransformInstance::~CTransformInstance(void)
  153. {
  154. }
  155. #endif // __TXINST_H__