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.

321 lines
7.5 KiB

  1. //-----------------------------------------------------------------------------
  2. // This files contains the module name for this mini driver. Each mini driver
  3. // must have a unique module name. The module name is used to obtain the
  4. // module handle of this Mini Driver. The module handle is used by the
  5. // generic library to load in tables from the Mini Driver.
  6. //-----------------------------------------------------------------------------
  7. /*++
  8. Copyright (c) 1996-1999 Microsoft Corporation
  9. Module Name:
  10. cmdcb.c
  11. Abstract:
  12. Implementation of GPD command callback for "test.gpd":
  13. OEMCommandCallback
  14. Environment:
  15. Windows NT Unidrv driver
  16. Revision History:
  17. 04/07/97 -zhanw-
  18. Created it.
  19. --*/
  20. #include "pdev.h"
  21. //////////////////////////////////////////////////////////////////////////
  22. // Function: BInitOEMExtraData
  23. //
  24. // Description: Initializes OEM Extra data.
  25. //
  26. //
  27. // Parameters:
  28. //
  29. // pOEMExtra Pointer to a OEM Extra data.
  30. //
  31. // dwSize Size of OEM extra data.
  32. //
  33. //
  34. // Returns: TRUE if successful; FALSE otherwise.
  35. //
  36. //
  37. // Comments:
  38. //
  39. //
  40. // History:
  41. // 02/11/97 APresley Created.
  42. //
  43. //////////////////////////////////////////////////////////////////////////
  44. BOOL BInitOEMExtraData(POEMUD_EXTRADATA pOEMExtra)
  45. {
  46. // Initialize OEM Extra data.
  47. pOEMExtra->dmExtraHdr.dwSize = sizeof(OEMUD_EXTRADATA);
  48. pOEMExtra->dmExtraHdr.dwSignature = OEM_SIGNATURE;
  49. pOEMExtra->dmExtraHdr.dwVersion = OEM_VERSION;
  50. pOEMExtra->bComp = FALSE;
  51. return TRUE;
  52. }
  53. //////////////////////////////////////////////////////////////////////////
  54. // Function: BMergeOEMExtraData
  55. //
  56. // Description: Validates and merges OEM Extra data.
  57. //
  58. //
  59. // Parameters:
  60. //
  61. // pdmIn pointer to an input OEM private devmode containing the settings
  62. // to be validated and merged. Its size is current.
  63. //
  64. // pdmOut pointer to the output OEM private devmode containing the
  65. // default settings.
  66. //
  67. //
  68. // Returns: TRUE if valid; FALSE otherwise.
  69. //
  70. //
  71. // Comments:
  72. //
  73. //
  74. // History:
  75. // 02/11/97 APresley Created.
  76. // 04/08/97 ZhanW Modified the interface
  77. //
  78. //////////////////////////////////////////////////////////////////////////
  79. BOOL BMergeOEMExtraData(
  80. POEMUD_EXTRADATA pdmIn,
  81. POEMUD_EXTRADATA pdmOut
  82. )
  83. {
  84. if(pdmIn && pdmOut) {
  85. //
  86. // copy over the private fields, if they are valid
  87. //
  88. pdmOut->bComp = pdmIn->bComp;
  89. }
  90. return TRUE;
  91. }
  92. #define MASTER_UNIT 600
  93. #define WRITESPOOLBUF(p, s, n) \
  94. ((p)->pDrvProcs->DrvWriteSpoolBuf(p, s, n))
  95. #define PARAM(p,n) \
  96. (*((p)+(n)))
  97. //
  98. // Command callback ID's
  99. //
  100. #define CMD_XMOVE_ABS 10 // X-move Absolute
  101. #define CMD_YMOVE_ABS 11 // Y-move Absolute
  102. #define CMD_CR 12
  103. #define CMD_LF 13
  104. #define CMD_SEND_BLOCK_DATA 14
  105. #define CMD_ENABLE_OEM_COMP 15
  106. #define CMD_DISALBE_COMP 16
  107. INT APIENTRY OEMCommandCallback(
  108. PDEVOBJ pdevobj,
  109. DWORD dwCmdCbID,
  110. DWORD dwCount,
  111. PDWORD pdwParams
  112. )
  113. {
  114. INT i;
  115. BYTE Cmd[16];
  116. DWORD dwDestX, dwDestY;
  117. DWORD dwDataWidth;
  118. DWORD dwDataSize;
  119. INT iRet = 0;
  120. POEMUD_EXTRADATA lpOemData;
  121. VERBOSE(("OEMCommandCallback entry - %d, %d\r\n",
  122. dwCmdCbID, dwCount));
  123. //
  124. // verify pdevobj okay
  125. //
  126. ASSERT(VALID_PDEVOBJ(pdevobj));
  127. lpOemData = (POEMUD_EXTRADATA)(pdevobj->pOEMDM);
  128. //
  129. // fill in printer commands
  130. //
  131. i = 0;
  132. switch (dwCmdCbID) {
  133. case CMD_XMOVE_ABS:
  134. case CMD_YMOVE_ABS:
  135. //
  136. // The commands require 4 parameters
  137. //
  138. if (dwCount < 4 || !pdwParams) return 0;
  139. VERBOSE(("MOVE_ABS - %d, %d, %d, %d\r\n",
  140. PARAM(pdwParams, 0),PARAM(pdwParams, 1),
  141. PARAM(pdwParams, 2),PARAM(pdwParams, 3)));
  142. dwDestX = (PARAM(pdwParams, 0) * PARAM(pdwParams, 2)) / MASTER_UNIT;
  143. dwDestY = (PARAM(pdwParams, 1) * PARAM(pdwParams, 3)) / MASTER_UNIT;
  144. Cmd[i++] = (BYTE)'\x9B';
  145. Cmd[i++] = 'P';
  146. Cmd[i++] = (BYTE)(dwDestX >> 8);
  147. Cmd[i++] = (BYTE)(dwDestX);
  148. Cmd[i++] = (BYTE)(dwDestY >> 8);
  149. Cmd[i++] = (BYTE)(dwDestY);
  150. WRITESPOOLBUF(pdevobj, Cmd, i);
  151. switch (dwCmdCbID) {
  152. case CMD_XMOVE_ABS:
  153. iRet = dwDestX;
  154. break;
  155. case CMD_YMOVE_ABS:
  156. iRet = dwDestY;
  157. break;
  158. }
  159. break;
  160. case CMD_CR:
  161. // Added to check the NULL pointer.
  162. if (pdwParams == NULL) return -1;
  163. dwDestY = (PARAM(pdwParams, 0) * PARAM(pdwParams, 1)) / MASTER_UNIT;
  164. Cmd[i++] = (BYTE)'\x9B';
  165. Cmd[i++] = 'P';
  166. Cmd[i++] = 0;
  167. Cmd[i++] = 0;
  168. Cmd[i++] = (BYTE)(dwDestY >> 8);
  169. Cmd[i++] = (BYTE)dwDestY;
  170. WRITESPOOLBUF(pdevobj, Cmd, i);
  171. break;
  172. case CMD_LF:
  173. // DUMMY entry.
  174. break;
  175. case CMD_SEND_BLOCK_DATA:
  176. // Added to check the NULL pointer.
  177. if (pdwParams == NULL) return -1;
  178. dwDataWidth = PARAM(pdwParams, 0) * 8;
  179. Cmd[i++] = (BYTE)'\x9B';
  180. Cmd[i++] = 'S';
  181. Cmd[i++] = (BYTE)(dwDataWidth >> 8);
  182. Cmd[i++] = (BYTE)(dwDataWidth);
  183. // In case it is OEMCompression data, we already
  184. // embedded printing command and data length.
  185. if (!lpOemData->bComp) {
  186. dwDataSize = PARAM(pdwParams, 1);
  187. Cmd[i++] = (BYTE)'\x9B';
  188. Cmd[i++] = 'I';
  189. Cmd[i++] = COMP_NONE;
  190. Cmd[i++] = (BYTE)(dwDataSize >> 8);
  191. Cmd[i++] = (BYTE)(dwDataSize);
  192. }
  193. WRITESPOOLBUF(pdevobj, Cmd, i);
  194. break;
  195. case CMD_ENABLE_OEM_COMP:
  196. lpOemData->bComp = TRUE;
  197. break;
  198. case CMD_DISALBE_COMP:
  199. lpOemData->bComp = FALSE;
  200. break;
  201. }
  202. return iRet;
  203. }
  204. INT
  205. APIENTRY
  206. OEMCompression(
  207. PDEVOBJ pdevobj,
  208. PBYTE pInBuf,
  209. PBYTE pOutBuf,
  210. DWORD dwInLen,
  211. DWORD dwOutLen)
  212. {
  213. INT iRet = -1;
  214. INT iRetRLE, iRetMHE;
  215. DWORD dwMHECeil = 0xc00000; // Can be any.
  216. if (pInBuf == NULL && dwInLen != 0) return -1;
  217. if (pOutBuf == NULL && dwOutLen != 0) return -1;
  218. // Compression algorithm (per each scanline)
  219. #if defined(RLETEST)
  220. if (LGCompRLE(NULL, pInBuf, dwInLen, 1) <= (INT)(dwOutLen * 2 / 3)) {
  221. iRet = LGCompRLE(pOutBuf, pInBuf, dwInLen, 1);
  222. }
  223. #elif defined(MHETEST)
  224. if (LGCompMHE(NULL, pInBuf, dwInLen, 1) <= (INT)(dwOutLen * 2 / 3)) {
  225. iRet = LGCompMHE(pOutBuf, pInBuf, dwInLen, 1);
  226. }
  227. #else // Normal case.
  228. iRetRLE = LGCompRLE(NULL, pInBuf, dwInLen, 1);
  229. if (iRetRLE >= 0 && iRetRLE < (INT)dwInLen / 2) {
  230. // Ok with RLE.
  231. iRet = LGCompRLE(pOutBuf, pInBuf, dwInLen, 1);
  232. }
  233. else if (iRetRLE <= (INT)dwInLen) {
  234. // Try MHE.
  235. iRetMHE = LGCompMHE(NULL, pInBuf, dwInLen, 1);
  236. if (iRetMHE > 0 && iRetMHE < iRetRLE && iRetMHE < (INT)dwMHECeil) {
  237. // Go with MHE.
  238. iRet = LGCompMHE(pOutBuf, pInBuf, dwInLen, 1);
  239. }
  240. else {
  241. // Go with RLE.
  242. iRet = LGCompRLE(pOutBuf, pInBuf, dwInLen, 1);
  243. }
  244. }
  245. #endif // NORMAL
  246. VERBOSE(("OEMCompression - dwInLen=%d,dwOutLen=%d,iRet = %d\n",
  247. dwInLen, dwOutLen, iRet));
  248. return iRet;
  249. }