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.

193 lines
6.3 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. // FILE : faxdrv16.c //
  3. // //
  4. // DESCRIPTION : Implementation for the unidriver dump callback. //
  5. // //
  6. // AUTHOR : DanL. //
  7. // //
  8. // HISTORY : //
  9. // Oct 19 1999 DannyL Creation. //
  10. // //
  11. // Copyright (C) 1999 Microsoft Corporation All Rights Reserved //
  12. /////////////////////////////////////////////////////////////////////////////
  13. #include "stdhdr.h"
  14. BYTE szBuf[4] = {0xFF, 0xFF, 0xFF, 0xFF};
  15. /*
  16. - fnDump
  17. -
  18. * Purpose: Gets filled in band block from GDI and sends to BlockOut
  19. * one scan line at a time.
  20. *
  21. * Arguments:
  22. * [in] lpdv - Address of a PDEVICE structure for device data.
  23. * [in] lpptCursor - Address of a pair of POINT structures that specify the
  24. * coordinates of the current and final position of the
  25. * print head.
  26. * [in] fMode - Landscape flag. If this parameter is CD_LANDSCAPE, the
  27. * printer is in landscape mode; otherwise, it is in portrait mode.
  28. *
  29. * Returns:
  30. * Return value conflicts with documentation. Doenst seem to have
  31. * any specific meaning.
  32. *
  33. * Remarks:
  34. * For complete documentation refer to fnOEMDump in the Minidriver
  35. * Developer's Guide.
  36. */
  37. short FAR PASCAL
  38. fnDump(LPDV lpdv, LPPOINT lpptCursor, WORD fMode)
  39. {
  40. short sRet = 1;
  41. WORD iScan, i, WidthBytes, BandHeight;
  42. WORD wScanlinesPerSeg, wWAlignBytes, wSegmentInc;
  43. LPBITMAP lpbmHdr;
  44. BOOL fHuge;
  45. LPBYTE lpSrc;
  46. LPBYTE lpScanLine;
  47. LPEXTPDEV lpXPDV;
  48. WORD count = 0;
  49. BOOL fAbort = FALSE;
  50. DBG_PROC_ENTRY("fnDump");
  51. //
  52. // get pointer to our private data stored in UNIDRV's PDEVICE
  53. //
  54. lpXPDV = ((LPEXTPDEV)lpdv->lpMd);
  55. //
  56. // get ptr to PBITMAP
  57. //
  58. lpbmHdr = (LPBITMAP)((LPSTR)lpdv + lpdv->oBruteHdr);
  59. //
  60. // initialize some things
  61. //
  62. fHuge = lpbmHdr->bmSegmentIndex > 0;
  63. lpSrc = lpbmHdr->bmBits;
  64. wWAlignBytes = (lpbmHdr->bmWidth+7)>>3;
  65. WidthBytes = lpbmHdr->bmWidthBytes;
  66. BandHeight = lpbmHdr->bmHeight;
  67. DBG_TRACE2("Page dump:%d pxls X %d pxls",lpbmHdr->bmWidth,BandHeight);
  68. wScanlinesPerSeg = lpbmHdr->bmScanSegment;
  69. wSegmentInc = lpbmHdr->bmSegmentIndex;
  70. //
  71. // We take landscape orientation into cosideration on OutputPageBitmap.
  72. //
  73. for (iScan = 0; ((iScan < BandHeight) && (fAbort = QueryAbort(lpXPDV->hAppDC,0))
  74. && lpXPDV->hScanBuf);iScan += wScanlinesPerSeg)
  75. {
  76. DBG_TRACE("Inside main loop");
  77. //
  78. // get next 64K segment of scans
  79. //
  80. if (iScan)
  81. {
  82. WORD wRemainingScans = BandHeight - iScan;
  83. //
  84. // cross the segment boundary
  85. //
  86. lpSrc = (LPBYTE)MAKELONG(0,HIWORD(lpSrc)+wSegmentInc);
  87. if (wScanlinesPerSeg > wRemainingScans)
  88. wScanlinesPerSeg = wRemainingScans;
  89. }
  90. //
  91. // loop through scan lines in 64K segment
  92. //
  93. for (i=iScan, lpScanLine=lpSrc;
  94. ((i < iScan + wScanlinesPerSeg) && QueryAbort(lpXPDV->hAppDC, 0)
  95. && lpXPDV->hScanBuf); i++)
  96. {
  97. BlockOut(lpdv, lpScanLine, wWAlignBytes);
  98. lpScanLine += WidthBytes;
  99. count++;
  100. }
  101. } // end for iScan
  102. DBG_TRACE("Out of main loop");
  103. DBG_TRACE2("iScan: %d BandHeight: %d", iScan, BandHeight);
  104. DBG_TRACE1("lpXPDV->hScanBuf: 0x%lx", lpXPDV->hScanBuf);
  105. DBG_TRACE1("fAbort: %d", fAbort);
  106. DBG_TRACE1("count is: %d",count);
  107. RETURN sRet;
  108. }
  109. /*
  110. - BlockOut
  111. -
  112. * Purpose:
  113. * Copy a scan line to the global scan buffer.
  114. *
  115. * Arguments:
  116. * [in] lpdv - Address of a PDEVICE structure.
  117. * [in] lpBuf - Address of buffer containing scanline.
  118. * [in] len - width of scanline.
  119. *
  120. * Returns:
  121. * [N/A]
  122. *
  123. * Remarks:
  124. * [N/A]
  125. */
  126. short FAR PASCAL
  127. BlockOut(LPDV lpdv, LPSTR lpBuf, WORD len)
  128. {
  129. WORD wBytes;
  130. LPEXTPDEV lpXPDV;
  131. SDBG_PROC_ENTRY("BlockOut");
  132. //
  133. // get pointer to our private data stored in UNIDRV's PDEVICE
  134. //
  135. lpXPDV = ((LPEXTPDEV)lpdv->lpMd);
  136. //
  137. // convert from BYTE aligned to DWORD aligned buffer
  138. // get DWORD amount of bytes
  139. //
  140. wBytes = (WORD)DW_WIDTHBYTES((DWORD)len*8);
  141. //
  142. // check to see if need to realloc scan buffer
  143. //
  144. if ((lpXPDV->dwTotalScanBytes + wBytes) > lpXPDV->dwScanBufSize)
  145. {
  146. HANDLE hTemp;
  147. lpXPDV->dwScanBufSize += BUF_CHUNK;
  148. hTemp = GlobalReAlloc(lpXPDV->hScanBuf, lpXPDV->dwScanBufSize, 0);
  149. //
  150. // if realloc fails, call ABORTDOC to clean up scan buf
  151. //
  152. if (!hTemp)
  153. {
  154. DBG_CALL_FAIL("GlobalReAlloc ... Aborting",0);
  155. DBG_TRACE3("lpXPDV->hScanBuf: 0x%lx, lpXPDV->dwScanBufSize: %d, (ec: %d)",
  156. lpXPDV->hScanBuf,
  157. lpXPDV->dwScanBufSize,
  158. GetLastError());
  159. Control(lpdv, ABORTDOC, NULL, NULL);
  160. RETURN 0;
  161. }
  162. else
  163. {
  164. lpXPDV->hScanBuf = hTemp;
  165. lpXPDV->lpScanBuf = (char _huge *)GlobalLock(lpXPDV->hScanBuf);
  166. lpXPDV->lpScanBuf += lpXPDV->dwTotalScanBytes;
  167. }
  168. }
  169. ASSERT((lpXPDV->dwTotalScanBytes + wBytes) < lpXPDV->dwScanBufSize);
  170. //
  171. // copy scan line to scan buffer
  172. //
  173. _fmemcpy(lpXPDV->lpScanBuf, lpBuf, len);
  174. lpXPDV->lpScanBuf += len;
  175. _fmemcpy(lpXPDV->lpScanBuf, (LPSTR)szBuf, wBytes-len);
  176. lpXPDV->lpScanBuf += wBytes-len;
  177. //
  178. // update total scan bytes
  179. //
  180. lpXPDV->dwTotalScanBytes += wBytes;
  181. lpXPDV->dwTotalScans++;
  182. RETURN wBytes;
  183. }