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.

106 lines
3.1 KiB

  1. /*=============================================================================
  2. This code module dispatches external C calls to internal C++ calls.
  3. DATE NAME COMMENTS
  4. 12-Apr-93 RajeevD Adapted to C++ from WFW.
  5. ==============================================================================*/
  6. #include <ifaxos.h>
  7. #include <faxcodec.h>
  8. #include <memory.h>
  9. #include "context.hpp"
  10. #ifdef DEBUG
  11. #ifdef WIN32
  12. DBGPARAM dpCurSettings = {"AWCODC32"};
  13. #else
  14. DBGPARAM dpCurSettings = {"FAXCODEC"};
  15. #endif
  16. #endif
  17. #ifndef WIN32
  18. BOOL WINAPI LibMain
  19. (HANDLE hInst, WORD wSeg, WORD wHeap, LPSTR lpszCmd)
  20. { return 1; }
  21. extern "C" {int WINAPI WEP (int nParam);}
  22. #pragma alloc_text(INIT_TEXT,WEP)
  23. int WINAPI WEP (int nParam)
  24. { return 1; }
  25. #endif
  26. #define CONTEXT_SLACK (RAWBUF_SLACK + 2*CHANGE_SLACK)
  27. //==============================================================================
  28. UINT WINAPI FaxCodecInit (LPVOID lpContext, LPFC_PARAM lpParam)
  29. {
  30. // Do we need double buffered change vector?
  31. BOOL f2DInit =
  32. lpParam->nTypeIn == MR_DATA
  33. || lpParam->nTypeIn == MMR_DATA
  34. || lpParam->nTypeOut == MR_DATA
  35. || lpParam->nTypeOut == MMR_DATA;
  36. // Enforce 64K limit on size of context.
  37. DEBUGCHK (!(lpParam->cbLine > (f2DInit? 1875U : 3750U)));
  38. if (lpParam->cbLine > (f2DInit? 1875U : 3750U)) return 0;
  39. // Enforce nonzero K factor if encoding MR.
  40. DEBUGCHK (lpParam->nKFactor || lpParam->nTypeOut != MR_DATA);
  41. if (lpContext)
  42. ((LPCODEC) lpContext)->Init (lpParam, f2DInit);
  43. return sizeof(CODEC) + CONTEXT_SLACK + (f2DInit ? 33:17) * lpParam->cbLine;
  44. }
  45. //==============================================================================
  46. UINT WINAPI FaxCodecConvert
  47. (LPVOID lpContext, LPBUFFER lpbufIn, LPBUFFER lpbufOut)
  48. {
  49. return ((LPCODEC) lpContext)->Convert (lpbufIn, lpbufOut);
  50. }
  51. //==============================================================================
  52. void WINAPI FaxCodecCount (LPVOID lpContext, LPFC_COUNT lpCountOut)
  53. {
  54. LPFC_COUNT lpCountIn = &((LPCODEC) lpContext)->fcCount;
  55. DEBUGMSG(1,("FaxCodecCount: good=%ld bad=%ld\n consec=%ld",
  56. lpCountIn->cTotalGood, lpCountIn->cTotalBad, lpCountIn->cMaxRunBad));
  57. _fmemcpy (lpCountOut, lpCountIn, sizeof(FC_COUNT));
  58. _fmemset (lpCountIn, 0, sizeof(FC_COUNT));
  59. }
  60. //==============================================================================
  61. void WINAPI InvertBuf (LPBUFFER lpbuf)
  62. {
  63. LPBYTE lpb = lpbuf->lpbBegData;
  64. WORD cb = lpbuf->wLengthData;
  65. DEBUGCHK (lpbuf && lpbuf->wLengthData % 4 == 0);
  66. while (cb--) *lpb++ = ~*lpb;
  67. }
  68. //==============================================================================
  69. void WINAPI FaxCodecChange
  70. (
  71. LPBYTE lpbLine, // input LRAW scan line
  72. UINT cbLine, // scan line byte width
  73. LPSHORT lpsChange // output change vector
  74. )
  75. {
  76. T4STATE t4;
  77. t4.lpbIn = lpbLine;
  78. t4.lpbOut = (LPBYTE) lpsChange;
  79. t4.cbIn = (WORD)cbLine;
  80. t4.cbOut = cbLine * 16;
  81. t4.cbLine = (WORD)cbLine;
  82. t4.wColumn = 0;
  83. t4.wColor = 0;
  84. t4.wWord = 0;
  85. t4.wBit = 0;
  86. t4.cbSlack = CHANGE_SLACK;
  87. t4.wRet = RET_BEG_OF_PAGE;
  88. RawToChange (&t4);
  89. }