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.

139 lines
3.3 KiB

  1. /*==============================================================================
  2. This source file is an example of a faxcodec.dll client.
  3. DATE NAME COMMENT
  4. 13-Apr-93 rajeevd Moved out of faxcodec.dll
  5. 18-Nov-93 rajeevd Updated to new faxcodec API.
  6. ==============================================================================*/
  7. #include <windows.h>
  8. #include <buffers.h>
  9. #include <faxcodec.h>
  10. /*==============================================================================
  11. This procedure performs any conversion indicated by a star in the table below:
  12. Output
  13. HRAW LRAW MH MR MMR
  14. HRAW * * *
  15. LRAW * * *
  16. Input MH * * * *
  17. MR * * * *
  18. MMR * * * *
  19. The input and output are assumed to be in non-overlapping memory buffers.
  20. ==============================================================================*/
  21. UINT MemConvert // returns output data size (0 on failure)
  22. (
  23. LPBYTE lpbIn, // input data pointer
  24. UINT cbIn, // input data size
  25. DWORD nTypeIn, // input data encoding
  26. LPBYTE lpbOut, // output buffer pointer
  27. UINT cbOut, // output buffer size
  28. DWORD nTypeOut, // output data encoding
  29. UINT cbLine, // scan line width
  30. UINT nKFactor // K factor (significant if nTypeOut==MR_DATA)
  31. )
  32. {
  33. UINT cbRet = 0;
  34. BUFFER bufIn, bufOut, bufEOP;
  35. BOOL fRevIn, fRevOut;
  36. HANDLE hContext;
  37. LPVOID lpContext;
  38. UINT cbContext;
  39. FC_PARAM fcp;
  40. FC_STATUS fcs;
  41. // Set up input buffer.
  42. bufIn.lpbBegBuf = lpbIn;
  43. bufIn.wLengthBuf = cbIn;
  44. bufIn.lpbBegData = lpbIn;
  45. bufIn.wLengthData = cbIn;
  46. bufIn.dwMetaData = nTypeIn;
  47. // Set up output buffer.
  48. bufOut.lpbBegBuf = lpbOut;
  49. bufOut.lpbBegData = lpbOut;
  50. bufOut.wLengthBuf = cbOut;
  51. bufOut.wLengthData = 0;
  52. bufOut.dwMetaData = nTypeOut;
  53. // Initialize EOP buffer
  54. bufEOP.dwMetaData = END_OF_PAGE;
  55. // Handle input bit reversal.
  56. if (nTypeIn == HRAW_DATA)
  57. {
  58. fRevIn = TRUE;
  59. BitReverseBuf (&bufIn);
  60. }
  61. else fRevIn = FALSE;
  62. // Detect output bit reversal.
  63. if (nTypeOut == HRAW_DATA)
  64. {
  65. fRevOut = TRUE;
  66. nTypeOut = LRAW_DATA;
  67. }
  68. else fRevOut = FALSE;
  69. // Initialize parameters.
  70. fcp.nTypeIn = nTypeIn;
  71. fcp.nTypeOut = nTypeOut;
  72. fcp.cbLine = cbLine;
  73. fcp.nKFactor = nKFactor;
  74. // Query for size of context.
  75. cbContext = FaxCodecInit (NULL, &fcp);
  76. if (!cbContext)
  77. goto err;
  78. // Allocate context memory.
  79. hContext = GlobalAlloc (GMEM_FIXED, cbContext);
  80. if (!hContext)
  81. goto err;
  82. lpContext = GlobalLock (hContext);
  83. // Initialize context.
  84. FaxCodecInit (lpContext, &fcp);
  85. // Convert data in single pass.
  86. fcs = FaxCodecConvert (lpContext, &bufIn, &bufOut);
  87. // Flush EOFB for nTypeOut == MMR_DATA
  88. FaxCodecConvert (lpContext, &bufEOP, &bufOut);
  89. // Free context memory.
  90. GlobalUnlock (hContext);
  91. GlobalFree (hContext);
  92. // Undo input bit reversal.
  93. if (fRevIn)
  94. {
  95. bufIn.lpbBegData = lpbIn;
  96. bufIn.wLengthData = cbIn;
  97. BitReverseBuf (&bufIn);
  98. }
  99. // Handle output bit reversal.
  100. if (fRevOut)
  101. BitReverseBuf (&bufOut);
  102. if (fcs == FC_INPUT_EMPTY)
  103. cbRet = bufOut.wLengthData;
  104. err:
  105. return cbRet;
  106. }