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.

401 lines
12 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-1998 Microsoft Corporation
  9. Module Name:
  10. cmdcb.c
  11. Abstract:
  12. Implementation of GPD command callback for "ncdlxxxx.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. #include "strsafe.h"
  22. #define WriteSpoolBuf(p, s, n) \
  23. ((p)->pDrvProcs->DrvWriteSpoolBuf(p, s, n))
  24. //
  25. // For debugging.
  26. //
  27. //#define DBG_OUTPUTCHARSTR 1
  28. //
  29. // Files necessary for OEM plug-in.
  30. //
  31. //------------------------------------------------------------------
  32. // define
  33. //------------------------------------------------------------------
  34. #define N 4096
  35. #define F 18
  36. #define NIL N
  37. //-------------------------------------------------------------------
  38. // OEMFilterGraphics
  39. // Action : Compress Bitmap Data
  40. //-------------------------------------------------------------------
  41. BOOL
  42. APIENTRY
  43. OEMFilterGraphics(
  44. PDEVOBJ lpdv,
  45. PBYTE lpBuf,
  46. DWORD wLen)
  47. {
  48. DWORD v;//sorce buffer read pointer
  49. DWORD len2;//compress buffer length
  50. DWORD y,ku,ct;
  51. HANDLE hTemp;//get mem hundle
  52. LPSTR lpTemp;//write pointer
  53. LPSTR lpStart;//start pointer
  54. int i, r, s, lastmatchlen, j,len;
  55. unsigned char code[17], mask,escJ[4],c;
  56. unsigned long int work;
  57. int qq;
  58. unsigned char text[4113]; // text buffer
  59. // int dad[4097], lson[4097], rson[4353]; // tree
  60. int *dad, *lson, *rson; // tree
  61. int matchpos, matchlen;
  62. int x, p, cmp,dummy;
  63. unsigned char *key;
  64. WORD length,outcount,codeptr;
  65. length = 0;
  66. outcount = 0;
  67. {
  68. char jj;
  69. BYTE d;
  70. for(v=0 ; v<wLen ; v++)
  71. {
  72. for(d=jj=0 ; jj<8 ; jj++)
  73. {
  74. d = ((*(lpBuf+v) << jj) & 0x80) | (d >> 1);
  75. }
  76. *(lpBuf+v) = d;
  77. }
  78. }
  79. lpStart = EngAllocMem(0,wLen+11,'cenD');
  80. lpTemp = lpStart;
  81. ct = 0;
  82. ku = 1000;
  83. len2 = wLen / 3;
  84. for( j=0;j<4;j++){
  85. for( y=1;y<11;y++){
  86. if( len2 < y*ku ){
  87. escJ[ct] =(unsigned char) (0x30 + (y-1));
  88. len2 -= (y-1)*ku;
  89. ct ++;
  90. ku = ku /10;
  91. break;
  92. }
  93. }
  94. }
  95. dad = EngAllocMem(0,sizeof(int)*4097,'cenD');
  96. lson = EngAllocMem(0,sizeof(int)*4097,'cenD');
  97. rson = EngAllocMem(0,sizeof(int)*4353,'cenD');
  98. if( (dad == NULL) || (lson == NULL) || (rson == NULL) )
  99. goto no_comp;
  100. if(wLen < 200 ){ // no compress
  101. no_comp:
  102. if( lpStart != NULL ){
  103. *lpStart = 0x4a; // J
  104. for(i=0;i<4;i++){
  105. *(lpStart+(i+1)) = escJ[i]; // Parameter
  106. }
  107. outcount = 5;
  108. WriteSpoolBuf(lpdv, lpStart, outcount);
  109. WriteSpoolBuf(lpdv, lpBuf, wLen);
  110. // EngFreeMem(lpStart);
  111. }
  112. EngFreeMem(lpStart);
  113. EngFreeMem(dad);
  114. EngFreeMem(lson);
  115. EngFreeMem(rson);
  116. return(wLen);
  117. }
  118. lpTemp += 11; // address update
  119. for (i = 4097; i <= 4352; i++) *(rson+i) = NIL; // tree inital
  120. for (i = 0; i < 4096; i++) *(dad+i) = NIL;
  121. code[0] = 0; codeptr = mask = 1;
  122. s = 0; r = 4078;
  123. for (i = s; i < r; i++) text[i] = 0; // buffer inital
  124. for (len = 0; len < 18 ; len++) {
  125. c = *(lpBuf + length);
  126. length ++;
  127. if (length > wLen ) break;
  128. text[r + len] = c;
  129. }
  130. for (i = 1; i <= 18; i++){
  131. //--- insert_node(r - i);
  132. cmp = 1; key = &text[r-i]; p = 4097 + key[0];
  133. *(rson+(r-i)) = *(lson+(r-i)) = NIL; matchlen = 0;
  134. for ( ; ; ) {
  135. if (cmp >= 0) {
  136. if (*(rson+p) != NIL) p = *(rson+p);
  137. else { *(rson+p) = (r-i); *(dad+(r-i)) = p; goto down1; }
  138. } else {
  139. if (*(lson+p) != NIL) p = *(lson+p);
  140. else { *(lson+p) = (r-i); *(dad+(r-i)) = p; goto down1; }
  141. }
  142. for (x = 1; x < 18; x++)
  143. if ((cmp = key[x] - text[p + x]) != 0) break;
  144. if (x > matchlen) {
  145. matchpos = p;
  146. if ((matchlen = x) >= 18) break;
  147. }
  148. }
  149. *(dad+(r-i)) = *(dad+p); *(lson+(r-i)) = *(lson+p); *(rson+(r-i)) = *(rson+p);
  150. *(dad+*(lson+p)) = (r-i); *(dad+*(rson+p)) = (r-i);
  151. if (*(rson+*(dad+p)) == p) *(rson+*(dad+p)) = (r-i);
  152. else *(lson+*(dad+p)) = (r-i);
  153. *(dad+p) = NIL; // p
  154. down1:
  155. ; // dummy = dummy; // MSKK:10/10/2000
  156. //--- insert_node end
  157. }
  158. //--- insert_node(r);
  159. cmp = 1; key = &text[r]; p = 4097 + key[0];
  160. *(rson+r) = *(lson+r) = NIL; matchlen = 0;
  161. for ( ; ; ) {
  162. if (cmp >= 0) {
  163. if (*(rson+p) != NIL) p = *(rson+p);
  164. else { *(rson+p) = r; *(dad+r) = p; goto down2; }
  165. } else {
  166. if (*(lson+p) != NIL) p = *(lson+p);
  167. else { *(lson+p) = r; *(dad+r) = p; goto down2; }
  168. }
  169. for (x = 1; x < 18; x++)
  170. if ((cmp = key[x] - text[p + x]) != 0) break;
  171. if (x > matchlen) {
  172. matchpos = p;
  173. if ((matchlen = x) >= 18) break;
  174. }
  175. }
  176. *(dad+r) = *(dad+p); *(lson+r) = *(lson+p); *(rson+r) = *(rson+p);
  177. *(dad+*(lson+p)) = r; *(dad+*(rson+p)) = r;
  178. if (*(rson+*(dad+p)) == p) *(rson+*(dad+p)) = r;
  179. else *(lson+*(dad+p)) = r;
  180. *(dad+p) = NIL; // p
  181. down2:
  182. //---insrt_node end
  183. do {
  184. if (matchlen > len) matchlen = len;
  185. if (matchlen < 3) {
  186. matchlen = 1; code[0] |= mask; code[codeptr++] = text[r];
  187. } else {
  188. code[codeptr++] = (unsigned char) matchpos;
  189. code[codeptr++] = (unsigned char)
  190. (((matchpos >> 4) & 0xf0) | (matchlen - 3));
  191. }
  192. if ((mask <<= 1) == 0) {
  193. outcount += codeptr;
  194. //compress data > original data
  195. if(outcount >= wLen)
  196. goto no_comp;
  197. for (i = 0; i < codeptr; i++){
  198. *lpTemp = code[i];
  199. lpTemp++;
  200. }
  201. code[0] = 0; codeptr = mask = 1;
  202. }
  203. lastmatchlen = matchlen;
  204. for (i = 0; i < lastmatchlen; i++) {
  205. c = *(lpBuf + length);
  206. length ++;
  207. if (length > wLen ) break;
  208. // delete_node(s);
  209. //---------------
  210. if (*(dad+s) != NIL){
  211. if (*(rson+s) == NIL) qq = *(lson+s);
  212. else if (*(lson+s) == NIL) qq = *(rson+s);
  213. else {
  214. qq = *(lson+s);
  215. if (*(rson+qq) != NIL) {
  216. do { qq = *(rson+qq); } while (*(rson+qq) != NIL);
  217. *(rson+*(dad+qq)) = *(lson+qq); *(dad+*(lson+qq)) = *(dad+qq);
  218. *(lson+qq) = *(lson+s); *(dad+*(lson+s)) = qq;
  219. }
  220. *(rson+qq) = *(rson+s); *(dad+*(rson+s)) = qq;
  221. }
  222. *(dad+qq) = *(dad+s);
  223. if (*(rson+*(dad+s)) == s) *(rson+*(dad+s)) = qq;
  224. else *(lson+*(dad+s)) = qq;
  225. *(dad+s) = NIL;
  226. }
  227. //-------------
  228. text[s] = c;
  229. if (s < 17) text[s + 4096] = c;
  230. s = (s + 1) & 4095; r = (r + 1) & 4095;
  231. //--- insert_node(r);
  232. cmp = 1; key = &text[r]; p = 4097 + key[0];
  233. *(rson+r) = *(lson+r) = NIL; matchlen = 0;
  234. for ( ; ; ) {
  235. if (cmp >= 0) {
  236. if (*(rson+p) != NIL) p = *(rson+p);
  237. else { *(rson+p) = r; *(dad+r) = p; goto down3; }
  238. } else {
  239. if (*(lson+p) != NIL) p = *(lson+p);
  240. else { *(lson+p) = r; *(dad+r) = p; goto down3; }
  241. }
  242. for (x = 1; x < 18; x++)
  243. if ((cmp = key[x] - text[p + x]) != 0) break;
  244. if (x > matchlen) {
  245. matchpos = p;
  246. if ((matchlen = x) >= 18) break;
  247. }
  248. }
  249. *(dad+r) = *(dad+p); *(lson+r) = *(lson+p); *(rson+r) = *(rson+p);
  250. *(dad+*(lson+p)) = r; *(dad+*(rson+p)) = r;
  251. if (*(rson+*(dad+p)) == p) *(rson+*(dad+p)) = r;
  252. else *(lson+*(dad+p)) = r;
  253. *(dad+p) = NIL; // p
  254. down3:
  255. //--- insert_node end
  256. dummy = dummy;
  257. }
  258. while (i++ < lastmatchlen) {
  259. // delete_node(s);
  260. //---------------
  261. if (*(dad+s) != NIL){
  262. if (*(rson+s) == NIL) qq = *(lson+s);
  263. else if (*(lson+s) == NIL) qq = *(rson+s);
  264. else {
  265. qq = *(lson+s);
  266. if (*(rson+qq) != NIL) {
  267. do { qq = *(rson+qq); } while (*(rson+qq) != NIL);
  268. *(rson+*(dad+qq)) = *(lson+qq); *(dad+*(lson+qq)) = *(dad+qq);
  269. *(lson+qq) = *(lson+s); *(dad+*(lson+s)) = qq;
  270. }
  271. *(rson+qq) = *(rson+s); *(dad+*(rson+s)) = qq;
  272. }
  273. *(dad+qq) = *(dad+s);
  274. if (*(rson+*(dad+s)) == s) *(rson+*(dad+s)) = qq;
  275. else *(lson+*(dad+s)) = qq;
  276. *(dad+s) = NIL;
  277. }
  278. //-------------
  279. s = (s + 1) & (4095); r = (r + 1) & (4095);
  280. if (--len){
  281. //--- insert_node(r);
  282. cmp = 1; key = &text[r]; p = 4097 + key[0];
  283. *(rson+r) = *(lson+r) = NIL; matchlen = 0;
  284. for ( ; ; ) {
  285. if (cmp >= 0) {
  286. if (*(rson+p) != NIL) p = *(rson+p);
  287. else { *(rson+p) = r; *(dad+r) = p; goto down4; }
  288. } else {
  289. if (*(lson+p) != NIL) p = *(lson+p);
  290. else { *(lson+p) = r; *(dad+r) = p; goto down4; }
  291. }
  292. for (x = 1; x < 18; x++)
  293. if ((cmp = key[x] - text[p + x]) != 0) break;
  294. if (x > matchlen) {
  295. matchpos = p;
  296. if ((matchlen = x) >= 18) break;
  297. }
  298. }
  299. *(dad+r) = *(dad+p); *(lson+r) = *(lson+p); *(rson+r) = *(rson+p);
  300. *(dad+*(lson+p)) = r; *(dad+*(rson+p)) = r;
  301. if (*(rson+*(dad+p)) == p) *(rson+*(dad+p)) = r;
  302. else *(lson+*(dad+p)) = r;
  303. *(dad+p) = NIL; // p
  304. down4:
  305. dummy = dummy;
  306. //--- insert_node end
  307. }
  308. }
  309. } while (len > 0);
  310. if (codeptr > 1) {
  311. outcount += codeptr;
  312. //compress data > orignal data
  313. if(outcount >= wLen)
  314. goto no_comp;
  315. for (i = 0; i < codeptr; i++){
  316. *lpTemp = code[i];
  317. lpTemp++;
  318. }
  319. }
  320. //compress data sousin
  321. lpTemp = lpStart;
  322. // 1999 04.22
  323. ct = 1;
  324. ku = 1000;
  325. work = outcount;
  326. for( j=0;j<4;j++){
  327. for( y=1;y<11;y++){ // 1000
  328. if( work < (unsigned long int)y*ku ){
  329. *(lpTemp + ct ) =(unsigned char) (0x30+(y-1));
  330. work -= (y-1)*ku;
  331. ct ++;
  332. ku = ku /10;
  333. break;
  334. }
  335. }
  336. }
  337. *lpTemp = 0x7a;
  338. *(lpTemp+5) =0x2c;
  339. for(i=6;i<10;i++){
  340. *(lpTemp+i) = escJ[i-6];
  341. }
  342. *(lpTemp+10) = 0x2e;
  343. outcount += 11;
  344. // 1999.04.22
  345. WriteSpoolBuf(lpdv, lpTemp, outcount);
  346. //mem free
  347. EngFreeMem(lpTemp);
  348. EngFreeMem(dad);
  349. EngFreeMem(lson);
  350. EngFreeMem(rson);
  351. return(wLen);
  352. }