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.

225 lines
6.3 KiB

  1. #include <windef.h>
  2. #include <wingdi.h>
  3. #include <unidrv.h>
  4. #include "../modinit.c"
  5. #define SCANLINE_BUFFER_SIZE 1280 // A3 landscape scanline length + extra
  6. // Delta Raw Compression routine
  7. int DeltaRawCompress(LPBYTE, LPBYTE, LPBYTE, WORD, WORD);
  8. LPWRITESPOOLBUF WriteSpoolBuf;
  9. LPALLOCMEM UniDrvAllocMem;
  10. LPFREEMEM UniDrvFreeMem;
  11. typedef struct tagQLASERDV
  12. {
  13. BOOL bFirst;
  14. WORD wLastScanLineLen;
  15. BYTE lpLastScanLine[SCANLINE_BUFFER_SIZE];
  16. } QLASERDV, FAR *LPQLASERDV;
  17. BOOL MiniDrvEnablePDEV(LPDV lpdv, ULONG *pdevcaps)
  18. {
  19. lpdv->fMdv = FALSE;
  20. if (!(lpdv->lpMdv = UniDrvAllocMem(sizeof(QLASERDV))))
  21. return FALSE;
  22. lpdv->fMdv = TRUE;
  23. ((LPQLASERDV)lpdv->lpMdv)->bFirst = FALSE;
  24. ((LPQLASERDV)lpdv->lpMdv)->wLastScanLineLen = 0;
  25. return TRUE;
  26. }
  27. VOID MiniDrvDisablePDEV(LPDV lpdv)
  28. {
  29. if (lpdv->fMdv)
  30. {
  31. UniDrvFreeMem(lpdv->lpMdv);
  32. lpdv->fMdv = FALSE;
  33. }
  34. }
  35. VOID FAR PASCAL fnOEMOutputCmd(LPDV lpdv, WORD wCmdCbId, PDWORD lpdwParams)
  36. {
  37. if (wCmdCbId == 1) // StartPage
  38. {
  39. WriteSpoolBuf(lpdv, "\033}0;0;3B", 8);
  40. ((LPQLASERDV)lpdv->lpMdv)->bFirst = TRUE;
  41. }
  42. }
  43. WORD FAR PASCAL CBFilterGraphics(LPDV lpdv, LPBYTE lpBuf, WORD wLen)
  44. {
  45. BYTE CompressedScanLine[SCANLINE_BUFFER_SIZE];
  46. BYTE HeaderScanLine[4];
  47. WORD nCompBufLen;
  48. LPQLASERDV lpQDV = lpdv->lpMdv;
  49. if (lpQDV->bFirst)
  50. {
  51. ZeroMemory(lpQDV->lpLastScanLine, (WORD)SCANLINE_BUFFER_SIZE);
  52. lpQDV->bFirst = FALSE;
  53. }
  54. nCompBufLen = (WORD) DeltaRawCompress(lpBuf, lpQDV->lpLastScanLine,
  55. CompressedScanLine, (lpQDV->wLastScanLineLen > wLen)
  56. ? lpQDV->wLastScanLineLen : wLen, 0);
  57. HeaderScanLine[0] = 0;
  58. HeaderScanLine[1] = 0;
  59. HeaderScanLine[2] = (BYTE) (nCompBufLen >> 8);
  60. HeaderScanLine[3] = (BYTE) nCompBufLen;
  61. WriteSpoolBuf(lpdv, (LPBYTE) HeaderScanLine, 4);
  62. WriteSpoolBuf(lpdv, (LPBYTE) CompressedScanLine, nCompBufLen);
  63. CopyMemory(lpQDV->lpLastScanLine, lpBuf, wLen);
  64. if (lpQDV->wLastScanLineLen > wLen)
  65. ZeroMemory(lpQDV->lpLastScanLine + wLen, lpQDV->wLastScanLineLen - wLen);
  66. lpQDV->wLastScanLineLen = wLen;
  67. return nCompBufLen;
  68. }
  69. DRVFN MiniDrvFnTab[] =
  70. {
  71. { INDEX_MiniDrvEnablePDEV, (PFN)MiniDrvEnablePDEV },
  72. { INDEX_MiniDrvDisablePDEV, (PFN)MiniDrvDisablePDEV },
  73. { INDEX_OEMOutputCmd, (PFN)fnOEMOutputCmd },
  74. { INDEX_OEMWriteSpoolBuf, (PFN)CBFilterGraphics },
  75. };
  76. BOOL MiniDrvEnableDriver(MINIDRVENABLEDATA *pEnableData)
  77. {
  78. if (pEnableData == NULL)
  79. return FALSE;
  80. if (pEnableData->cbSize == 0)
  81. {
  82. pEnableData->cbSize = sizeof (MINIDRVENABLEDATA);
  83. return TRUE;
  84. }
  85. if (pEnableData->cbSize < sizeof (MINIDRVENABLEDATA)
  86. || HIBYTE(pEnableData->DriverVersion)
  87. < HIBYTE(MDI_DRIVER_VERSION))
  88. {
  89. // Wrong size and/or mismatched version
  90. return FALSE;
  91. }
  92. // Load callbacks provided by the Unidriver
  93. if (!bLoadUniDrvCallBack(pEnableData,
  94. INDEX_UniDrvWriteSpoolBuf, (PFN *) &WriteSpoolBuf)
  95. || !bLoadUniDrvCallBack(pEnableData,
  96. INDEX_UniDrvAllocMem, (PFN *) &UniDrvAllocMem)
  97. || !bLoadUniDrvCallBack(pEnableData,
  98. INDEX_UniDrvFreeMem, (PFN *) &UniDrvFreeMem))
  99. {
  100. return FALSE;
  101. }
  102. pEnableData->cMiniDrvFn
  103. = sizeof (MiniDrvFnTab) / sizeof(MiniDrvFnTab[0]);
  104. pEnableData->pMiniDrvFn = MiniDrvFnTab;
  105. return TRUE;
  106. }
  107. /*************************************************
  108. *
  109. * Image Delta Compression Routine
  110. *
  111. *===================================================
  112. * Input:
  113. * nbyte : # of byte, raw data
  114. * Image_string: pointer of raw data
  115. * Prn_string : pointer of compress data
  116. * Output:
  117. * Ret_count : # of byte, compress data
  118. **************************************************/
  119. int DeltaRawCompress( Image_string, //pbData,
  120. ORG_image, //pbSeedRow,
  121. Prn_string, //pbReturn,
  122. nbyte, //usTotalBytes
  123. nMagics) //Magic number
  124. LPBYTE Image_string; /* pointer to original string */
  125. LPBYTE ORG_image; /* pointer to previous scanline's string */
  126. LPBYTE Prn_string; /* pointer to return string */
  127. WORD nbyte; /* original number of bytes */
  128. WORD nMagics; //Magic number
  129. {
  130. int c, Ret_count, Skip_flag, Skip_count;
  131. unsigned int i, j, k, outcount;
  132. LPBYTE Diff_ptr;
  133. LPBYTE ORG_ptr;
  134. LPBYTE Skip_ptr;
  135. BYTE Diff_byte;
  136. BYTE Diff_mask[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
  137. BOOL bstart = TRUE;
  138. outcount = 0;
  139. Ret_count = 0;
  140. ORG_ptr = ORG_image;
  141. Skip_flag = TRUE;
  142. Skip_ptr = Prn_string++;
  143. *Skip_ptr = Skip_count = (nMagics/8)/8;
  144. k = (nbyte+7)/8;
  145. for(i=0;i<k;i++)
  146. {
  147. Diff_byte = 0;
  148. Diff_ptr = Prn_string++;
  149. for(j=0;j<8;j++)
  150. {
  151. if ( (i*8+j) >= nbyte ){
  152. *Prn_string++= 0;
  153. Diff_byte |= Diff_mask[j];
  154. outcount++;
  155. } else {
  156. c = *Image_string++;
  157. if(c != *ORG_ptr){
  158. *ORG_ptr++ = c;
  159. *Prn_string++= c;
  160. Diff_byte |= Diff_mask[j];
  161. outcount++;
  162. } else {
  163. ORG_ptr++;
  164. }
  165. }
  166. }
  167. if(Diff_byte == 0){
  168. if(Skip_flag == TRUE){
  169. Skip_count++;
  170. Prn_string--;
  171. }else{
  172. *Diff_ptr = Diff_byte;
  173. outcount++;
  174. }
  175. }else{
  176. if(Skip_flag == TRUE){
  177. Skip_flag = FALSE;
  178. *Skip_ptr = Skip_count;
  179. outcount++;
  180. *Diff_ptr = Diff_byte;
  181. outcount++;
  182. }else{
  183. *Diff_ptr = Diff_byte;
  184. outcount++;
  185. }
  186. Ret_count = outcount;
  187. }
  188. }
  189. return(Ret_count);
  190. }