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.

166 lines
3.8 KiB

  1. /*==============================================================================
  2. This module provides MMR rendering support for viewing faxes.
  3. 19-Jan-94 RajeevD Integrated into IFAX viewer.
  4. ==============================================================================*/
  5. #ifdef VIEWMMR
  6. #include <memory.h>
  7. #include "viewrend.hpp"
  8. //==============================================================================
  9. MMRVIEW::MMRVIEW (DWORD nType)
  10. {
  11. _fmemset ((LPBYTE) this + sizeof(LPVOID), 0, sizeof(MMRVIEW) - sizeof(LPVOID));
  12. DEBUGCHK (lpSpool == NULL);
  13. DEBUGCHK (lpCodec == NULL);
  14. DEBUGCHK (lpbufIn == NULL);
  15. nTypeOut = nType;
  16. }
  17. //==============================================================================
  18. MMRVIEW::~MMRVIEW ()
  19. {
  20. if (lpSpool) SpoolReadClose (lpSpool);
  21. if (lpCodec) GlobalFreePtr (lpCodec);
  22. if (lpbufIn) SpoolFreeBuf (lpbufIn);
  23. }
  24. //==============================================================================
  25. BOOL MMRVIEW::Init (LPVOID lpFilePath, LPVIEWINFO lpvi, LPWORD lpwBandSize)
  26. {
  27. UINT cbCodec;
  28. if (!this)
  29. return_error (("VIEWREND could not allocate context!\r\n"));
  30. // Open spool file.
  31. lpSpool = SpoolReadOpen (lpFilePath, &sh);
  32. if (!lpSpool)
  33. return_error (("VIEWREND could not open spool file!\r\n"));
  34. // Fill VIEWINFO.
  35. lpvi->cPage = SpoolReadCountPages (lpSpool);
  36. lpvi->xRes = sh.xRes;
  37. lpvi->yRes = sh.yRes;
  38. lpvi->yMax = 0;
  39. // Set band size.
  40. DEBUGCHK (lpwBandSize);
  41. cbBand = *lpwBandSize;
  42. if (cbBand < 2 * sh.cbLine)
  43. {
  44. cbBand = 2 * sh.cbLine;
  45. *lpwBandSize = cbBand;
  46. }
  47. // Set up codec.
  48. fcp.nTypeIn = MMR_DATA;
  49. fcp.nTypeOut = LRAW_DATA;
  50. fcp.cbLine = sh.cbLine;
  51. DEBUGCHK (fcp.nKFactor == 0);
  52. // Query codec.
  53. cbCodec = FaxCodecInit (NULL, &fcp);
  54. if (!cbCodec)
  55. return_error (("VIEWREND could not init codec!\r\n"));
  56. // Initialize codec.
  57. lpCodec = GlobalAllocPtr (0, cbCodec);
  58. if (!lpCodec)
  59. return_error (("VIEWREND could not allocate codec!\r\n"));
  60. return SetPage (0);
  61. }
  62. //==============================================================================
  63. BOOL MMRVIEW::SetPage (UINT iPage)
  64. {
  65. if (!SpoolReadSetPage (lpSpool, iPage))
  66. return FALSE;
  67. fEOP = FALSE;
  68. if (lpbufIn)
  69. {
  70. SpoolFreeBuf (lpbufIn);
  71. lpbufIn = NULL;
  72. }
  73. FaxCodecInit (lpCodec, &fcp);
  74. return TRUE;
  75. }
  76. //==============================================================================
  77. BOOL MMRVIEW::GetBand (LPBITMAP lpbmBand)
  78. {
  79. DEBUGCHK (lpbmBand && lpbmBand->bmBits);
  80. // Fill descriptor.
  81. lpbmBand->bmType = 0;
  82. lpbmBand->bmWidth = 8 * fcp.cbLine;
  83. lpbmBand->bmWidthBytes = fcp.cbLine;
  84. lpbmBand->bmPlanes = 1;
  85. lpbmBand->bmBitsPixel = 1;
  86. // Trap end of page.
  87. if (fEOP)
  88. {
  89. lpbmBand->bmHeight = 0;
  90. return TRUE;
  91. }
  92. // Set up output buffer.
  93. bufOut.lpbBegBuf = (LPBYTE) lpbmBand->bmBits;
  94. bufOut.wLengthBuf = cbBand;
  95. bufOut.Reset();
  96. bufOut.dwMetaData = LRAW_DATA;
  97. while (1)
  98. {
  99. // Fetch input buffer?
  100. if (!lpbufIn)
  101. {
  102. if (!(lpbufIn = SpoolReadGetBuf (lpSpool)))
  103. return_error (("VIEWREND could not fetch input buffer.\r\n"));
  104. switch (lpbufIn->dwMetaData)
  105. {
  106. case END_OF_PAGE:
  107. case END_OF_JOB:
  108. // metabuffers will be freed in SetPage or destructor.
  109. fEOP = TRUE;
  110. goto done;
  111. case MMR_DATA:
  112. break;
  113. default:
  114. continue;
  115. }
  116. }
  117. switch (FaxCodecConvert (lpCodec, lpbufIn, &bufOut))
  118. {
  119. case FC_DECODE_ERR:
  120. return_error (("VIEWREND fatal MMR decode error!\r\n"));
  121. case FC_INPUT_EMPTY:
  122. SpoolFreeBuf (lpbufIn);
  123. lpbufIn = NULL;
  124. continue;
  125. case FC_OUTPUT_FULL:
  126. goto done;
  127. }
  128. } // while (1)
  129. done:
  130. if (nTypeOut == HRAW_DATA)
  131. BitReverseBuf (&bufOut);
  132. lpbmBand->bmHeight = bufOut.wLengthData / fcp.cbLine;
  133. return TRUE;
  134. }
  135. #endif // VIEWMMR