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.

1194 lines
48 KiB

  1. //***************************************************************************************************
  2. // PRNCTL.C
  3. //
  4. // Functions of controlling printer
  5. //---------------------------------------------------------------------------------------------------
  6. // copyright(C) 1997-1999 CASIO COMPUTER CO.,LTD. / CASIO ELECTRONICS MANUFACTURING CO.,LTD.
  7. //***************************************************************************************************
  8. #include "PDEV.H"
  9. #include <stdio.h>
  10. #include "PRNCTL.H"
  11. #include "strsafe.h" // Security-Code 2002.3.6
  12. // Replacement of API 2002.3.6 >>>
  13. //#ifdef wsprintf
  14. //#undef wsprintf
  15. //#endif // wsprintf
  16. //#define wsprintf sprintf
  17. // Replacement of API 2002.3.6 >>>
  18. //***************************************************************************************************
  19. // Data define
  20. //***************************************************************************************************
  21. //---------------------------------------------------------------------------------------------------
  22. // Type of pressing raster image
  23. //---------------------------------------------------------------------------------------------------
  24. #define RASTER_COMP 0 // Press
  25. #define RASTER_NONCOMP 1 // Not press
  26. #define RASTER_EMPTY 2 // Empty
  27. //---------------------------------------------------------------------------------------------------
  28. // Buffer for setting command
  29. //---------------------------------------------------------------------------------------------------
  30. static BYTE CmdBuf[1 * 1024]; // 1KB
  31. //---------------------------------------------------------------------------------------------------
  32. // Structure for setting command
  33. //---------------------------------------------------------------------------------------------------
  34. typedef const struct {
  35. WORD Size; // Command size
  36. LPBYTE Cmd; // Command buffer
  37. } CMDDEF, FAR *LPCMDDEF;
  38. //===================================================================================================
  39. // Command define
  40. //===================================================================================================
  41. //---------------------------------------------------------------------------------------------------
  42. // Change mode
  43. //---------------------------------------------------------------------------------------------------
  44. static CMDDEF ModOrgIn = { 4, "\x1b""z""\xd0\x01"}; // ESC/Page -> original
  45. static CMDDEF ModOrgOut = { 4, "\x1b""z""\x00\x01"}; // original -> ESC/Page
  46. //---------------------------------------------------------------------------------------------------
  47. // Setting overwrite
  48. //---------------------------------------------------------------------------------------------------
  49. static CMDDEF CfgWrtMod = { 6, "\x1d""%uowE"}; // Setting overwrite
  50. //---------------------------------------------------------------------------------------------------
  51. // Setting spool positon
  52. //---------------------------------------------------------------------------------------------------
  53. static CMDDEF PosAbsHrz = { 4, "\x1d""%dX"}; // Horizontal
  54. static CMDDEF PosAbsVtc = { 4, "\x1d""%dY"}; // Vertical
  55. //---------------------------------------------------------------------------------------------------
  56. // Spool bitmap data
  57. //---------------------------------------------------------------------------------------------------
  58. static CMDDEF ImgDrw = {16, "\x1d""%u;%u;%u;%dbi{I"}; // Spool bit image
  59. static CMDDEF ImgRasStr = {15, "\x1d""%u;%u;%u;%dbrI"}; // Start spool raster image
  60. static CMDDEF ImgRasEnd = { 4, "\x1d""erI"}; // End spool raster image
  61. static CMDDEF ImgRasDrw = { 6, "\x1d""%ur{I"}; // Spool raster image
  62. static CMDDEF ImgRasNon = { 6, "\x1d""%uu{I"}; // Spool raster image(Not press)
  63. static CMDDEF ImgRasEpy = { 5, "\x1d""%ueI"}; // Spool empty raster image
  64. //---------------------------------------------------------------------------------------------------
  65. // CASIO original
  66. //---------------------------------------------------------------------------------------------------
  67. static CMDDEF OrgColCmy = {15, "Cc,%u,%u,%u,%u*"}; // CMYK
  68. static CMDDEF OrgDrwPln = {15, "Da,%u,%u,%u,%u*"}; // Setting plane
  69. static CMDDEF OrgImgCmy = {26, "Cj%w,%u,%u,%u,%l,%l,%u,%u*"}; // CMYK bitimage
  70. static BYTE OVERWRITE[] =
  71. "\x1D" "1owE" //MOV1
  72. "\x1D" "0tsE";
  73. //***************************************************************************************************
  74. // Prototype declaration
  75. //***************************************************************************************************
  76. static WORD PlaneCmdStore(PDEVOBJ, LPBYTE, WORD);
  77. static void BitImgImgCmd(PDEVOBJ, WORD, WORD, WORD, WORD, WORD, WORD, LPBYTE);
  78. static BOOL RasterImgCmd(PDEVOBJ, WORD, WORD, WORD, WORD, WORD, WORD, WORD, LPBYTE, LPBYTE);
  79. static WORD RasterSize(WORD, WORD, WORD, WORD, LPBYTE);
  80. static WORD RasterComp(LPBYTE, WORD, LPBYTE, LPBYTE, LPWORD);
  81. static void CMYKImgCmd(PDEVOBJ, WORD, LONG, LONG, WORD, WORD, WORD, WORD, WORD, DWORD, DWORD, LPBYTE, LPBYTE, LONG, LONG);
  82. static WORD CmdCopy(LPBYTE, LPCMDDEF);
  83. static WORD CmdStore(LPBYTE, LPCMDDEF, LPINT);
  84. static WORD INTtoASC(LPBYTE, int);
  85. static WORD USINTtoASC(LPBYTE, WORD);
  86. static WORD LONGtoASC(LPBYTE, LONG);
  87. static WORD USLONGtoASC(LPBYTE, DWORD);
  88. //***************************************************************************************************
  89. // Functions
  90. //***************************************************************************************************
  91. //===================================================================================================
  92. // Spool bitmap data
  93. //===================================================================================================
  94. void FAR PASCAL PrnBitmap(
  95. PDEVOBJ pdevobj, // Pointer to PDEVOBJ structure
  96. LPDRWBMP lpBmp // Pointer to DRWBMP structure
  97. )
  98. {
  99. WORD siz,size;
  100. WORD comp;
  101. WORD width; // dot
  102. WORD height; // dot
  103. WORD widthByte; // byte
  104. LPBYTE lpTmpBuf;
  105. LPBYTE lpSchBit;
  106. LPBYTE lpBit; // Pointer to Bitmap data
  107. POINT drwPos;
  108. WORD higSiz; // dot
  109. WORD higCnt;
  110. WORD strHigCnt;
  111. WORD widLCnt; // Width from the left edge
  112. WORD widRCnt; // Width from the right edge
  113. WORD invLft; // Invalid size from the left edge
  114. WORD invRgt; // Invalid size from the right edge
  115. WORD img1st; // Spool first image data?
  116. int pam[4];
  117. int palm[1];
  118. PMYPDEV pOEM = (PMYPDEV)pdevobj->pdevOEM;
  119. lpTmpBuf = NULL;
  120. width = lpBmp->Width;
  121. height = lpBmp->Height;
  122. widthByte = lpBmp->WidthByte;
  123. comp = No;
  124. MY_VERBOSE((" PB "));
  125. img1st = Yes;
  126. lpSchBit = lpBmp->lpBit;
  127. for (higCnt = 0; higCnt < height; higCnt++) {
  128. higSiz = 0;
  129. invLft = 0;
  130. invRgt = 0;
  131. for (; higCnt < height; higCnt++) { // 1 Spool bitmap data
  132. // Search NULL data from the left edge
  133. for (widLCnt = 0; widLCnt < widthByte; widLCnt++) {
  134. if (lpSchBit[widLCnt] != 0x00) {
  135. if (higSiz == 0) { // first line�H
  136. strHigCnt = higCnt;
  137. invLft = widLCnt; // Invalid size from the left edge
  138. } else {
  139. if (invLft > widLCnt) {
  140. invLft = widLCnt; // Renew invalid size from the left edge
  141. }
  142. }
  143. // Search NULL data from the right edge
  144. for (widRCnt = 0; widRCnt < widthByte; widRCnt++) {
  145. if (lpSchBit[widthByte - widRCnt - 1] != 0x00) {
  146. if (higSiz == 0) { // first line�H
  147. invRgt = widRCnt; // Invalid size from the right edge
  148. } else {
  149. if (invRgt > widRCnt) {
  150. invRgt = widRCnt; // Renew invalid size from the right edge
  151. }
  152. }
  153. break;
  154. }
  155. }
  156. higSiz++; // Renew height size
  157. break;
  158. }
  159. }
  160. lpSchBit += widthByte; // Next line bitmap data
  161. if (widLCnt == widthByte && higSiz != 0) { // 1line all NULL data & There were data except NULL data in previous line
  162. break; // Go to spool bitmap data
  163. }
  164. }
  165. if (higSiz != 0) { // There are data for spool�H
  166. if (img1st == Yes) { // Spool for the first time
  167. // Compress?
  168. if (pOEM->iCompress != XX_COMPRESS_OFF) {
  169. if ((lpTmpBuf = MemAllocZ(widthByte * height)) != NULL) {
  170. comp = Yes;
  171. }
  172. }
  173. // Original mode in
  174. siz = CmdCopy(CmdBuf, &ModOrgIn);
  175. // Color�H
  176. if (pOEM->iColor == XX_COLOR_SINGLE || pOEM->iColor == XX_COLOR_MANY) {
  177. pam[0] = lpBmp->Color.Cyn;
  178. pam[1] = lpBmp->Color.Mgt;
  179. pam[2] = lpBmp->Color.Yel;
  180. pam[3] = lpBmp->Color.Bla;
  181. siz += CmdStore(CmdBuf + siz, &OrgColCmy, pam);
  182. siz += PlaneCmdStore(pdevobj, CmdBuf + siz, lpBmp->Plane);
  183. }
  184. // Original mode out
  185. siz += CmdCopy(CmdBuf + siz, &ModOrgOut);
  186. if (siz != 0) { // There are data for spool?
  187. WRITESPOOLBUF(pdevobj, CmdBuf, siz);
  188. }
  189. img1st = No; // Not first time
  190. }
  191. drwPos.x = lpBmp->DrawPos.x + invLft * 8; // x coordinates
  192. drwPos.y = lpBmp->DrawPos.y + strHigCnt; // y coordinates
  193. palm[0] = drwPos.x;
  194. siz = CmdStore(CmdBuf, &PosAbsHrz, palm);
  195. palm[0] = drwPos.y;
  196. siz += CmdStore(CmdBuf + siz, &PosAbsVtc, palm);
  197. if (siz != 0) { // There are data for spool?
  198. WRITESPOOLBUF(pdevobj, CmdBuf, siz);
  199. }
  200. lpBit = lpBmp->lpBit + widthByte * strHigCnt;
  201. if (comp == Yes) { // Compress?
  202. if (RasterImgCmd(pdevobj, pOEM->iCompress, width, higSiz,
  203. widthByte, 0, invLft, invRgt, lpBit, lpTmpBuf) == No) {
  204. comp = No; // But compress rate is poor, no compress
  205. }
  206. }
  207. if (comp == No) { // Not compress
  208. BitImgImgCmd(pdevobj, width, higSiz, widthByte, 0, invLft, invRgt, lpBit);
  209. }
  210. }
  211. }
  212. if (lpTmpBuf) {
  213. MemFree(lpTmpBuf);
  214. }
  215. return;
  216. }
  217. //===================================================================================================
  218. // Spool CMYK bitmap data
  219. //===================================================================================================
  220. void FAR PASCAL PrnBitmapCMYK(
  221. PDEVOBJ pdevobj, // Pointer to PDEVOBJ structure
  222. LPDRWBMPCMYK lpBmp // Pointer to DRWBMPCMYK structure
  223. )
  224. {
  225. WORD siz;
  226. WORD comp;
  227. WORD width; // dot
  228. WORD height; // dot
  229. WORD widthByte;
  230. LPBYTE lpSchBit; // Pointer to bitmap data
  231. LPBYTE lpBit; // Pointer to bitmap data
  232. LONG xPos;
  233. LONG yPos;
  234. WORD posClpLft; // Clipping dot size
  235. DWORD posAdj; // 1/7200inch
  236. WORD higSiz; // dot
  237. WORD higCnt;
  238. WORD strHigCnt;
  239. WORD widLCnt;
  240. WORD widRCnt;
  241. WORD invLft; // Invalid size from the left edge
  242. WORD invRgt; // Invalid size from the right edge
  243. DWORD invLftBit; // Invalid bit size from the left edge
  244. DWORD invRgtBit; // Invalid bit size from the right edge
  245. WORD rgtBit; // Valid bit size from the right edge
  246. WORD img1st; // Spool for the first time
  247. DWORD dstSiz;
  248. LPBYTE lpDst;
  249. LPBYTE lpTmp;
  250. int pam[1];
  251. WORD img1st_2; // Spool for the first time
  252. PMYPDEV pOEM = (PMYPDEV)pdevobj->pdevOEM;
  253. MY_VERBOSE((" CM "));
  254. // Check of zero divide 2002.3.23 >>>
  255. if (lpBmp->DataBit == 0) {
  256. ERR(("PrnBitmapCMYK() 0Div-Check [lpBmp->DataBit=0] \n"));
  257. return;
  258. }
  259. // Check of zero divide 2002.3.23 <<<
  260. lpTmp = NULL;
  261. posAdj = 7200 / pOEM->Col.wReso; // 1/7200inch
  262. width = lpBmp->Width;
  263. height = lpBmp->Height;
  264. widthByte = lpBmp->WidthByte;
  265. comp = No;
  266. if (pOEM->iCompress != XX_COMPRESS_OFF) {
  267. if ((lpTmp = MemAllocZ(widthByte * height)) != NULL) {
  268. comp = Yes;
  269. }
  270. }
  271. img1st = Yes;
  272. img1st_2 = Yes;
  273. lpSchBit = lpBmp->lpBit;
  274. for (higCnt = 0; higCnt < height; higCnt++) {
  275. higSiz = 0;
  276. invLft = 0;
  277. invRgt = 0;
  278. for (; higCnt < height; higCnt++) { // 1 Spool bitmap data
  279. // Search NULL data from the left edge
  280. for (widLCnt = 0; widLCnt < widthByte; widLCnt++) {
  281. if (lpSchBit[widLCnt] != 0x00) {
  282. if (higSiz == 0) {
  283. strHigCnt = higCnt; // first line
  284. invLft = widLCnt; // Invalid size from the left edge
  285. } else {
  286. if (invLft > widLCnt) {
  287. invLft = widLCnt; // Renew invalid size from the left edge
  288. }
  289. }
  290. // Search NULL data from the right edge
  291. for (widRCnt = 0; widRCnt < widthByte; widRCnt++) {
  292. if (lpSchBit[widthByte - widRCnt - 1] != 0x00) {
  293. if (higSiz == 0) { // first line
  294. invRgt = widRCnt; // Invalid size from the right edge
  295. } else {
  296. if (invRgt > widRCnt) {
  297. invRgt = widRCnt; // Renew size from the right edge
  298. }
  299. }
  300. break;
  301. }
  302. }
  303. higSiz++; // Renew height size
  304. break;
  305. }
  306. }
  307. lpSchBit += widthByte; // Next line bitmap data
  308. if (widLCnt == widthByte && higSiz != 0) { // 1line all NULL data & There were data except NULL data in previous line
  309. break; // goto spool
  310. }
  311. }
  312. if (higSiz != 0) { // There are data for spool
  313. if (img1st_2 == Yes) {
  314. WRITESPOOLBUF(pdevobj, OVERWRITE, BYTE_LENGTH(OVERWRITE));
  315. img1st_2 = No;
  316. }
  317. // When Colormode is XX_COLOR_MANY ,not compress
  318. if (comp == Yes && pOEM->iColor == XX_COLOR_MANY) {
  319. comp = No;
  320. }
  321. if (comp == No && img1st == Yes) {
  322. // Original mode in
  323. siz = CmdCopy(CmdBuf, &ModOrgIn);
  324. // Plane
  325. siz += PlaneCmdStore(pdevobj, CmdBuf + siz, lpBmp->Plane);
  326. if (siz != 0) { // There are data for spool
  327. WRITESPOOLBUF(pdevobj, CmdBuf, siz);
  328. }
  329. img1st = No; // not first
  330. }
  331. invLftBit = (DWORD)invLft * 8;
  332. if (invRgt != 0) {
  333. if ((rgtBit = (WORD)((DWORD)width * lpBmp->DataBit % 8)) == 0) {
  334. rgtBit = 8;
  335. }
  336. if (rgtBit == 8) {
  337. invRgtBit = (DWORD)invRgt * 8;
  338. } else {
  339. invRgtBit = ((DWORD)invRgt - 1) * 8 + rgtBit;
  340. }
  341. } else {
  342. invRgtBit = 0;
  343. }
  344. posClpLft = (WORD)(invLftBit / lpBmp->DataBit);
  345. // Start position of spooling
  346. xPos = ((LONG)lpBmp->DrawPos.x + posClpLft) * posAdj;
  347. yPos = ((LONG)lpBmp->DrawPos.y + strHigCnt) * posAdj;
  348. lpBit = lpBmp->lpBit + widthByte * strHigCnt;
  349. // Spool CMYK bit image
  350. CMYKImgCmd(pdevobj, comp, xPos, yPos, lpBmp->Frame, lpBmp->DataBit, width, higSiz, widthByte,
  351. invLftBit, invRgtBit, lpBit, lpTmp, (LONG)lpBmp->DrawPos.x + posClpLft, (LONG)lpBmp->DrawPos.y + strHigCnt);
  352. }
  353. }
  354. if (img1st == No) { // Already spool
  355. // Original mode out
  356. siz = CmdCopy(CmdBuf, &ModOrgOut);
  357. WRITESPOOLBUF(pdevobj, CmdBuf, siz);
  358. }
  359. if (lpTmp) {
  360. MemFree(lpTmp);
  361. }
  362. return;
  363. }
  364. //===================================================================================================
  365. // Spool plane command
  366. //===================================================================================================
  367. WORD PlaneCmdStore( // Size of command
  368. PDEVOBJ pdevobj, // Pointer to PDEVOBJ structure
  369. LPBYTE lpDst,
  370. WORD Plane
  371. )
  372. {
  373. int pam[4];
  374. WORD siz;
  375. PMYPDEV pOEM = (PMYPDEV)pdevobj->pdevOEM;
  376. if (Plane & PLN_CYAN) {
  377. pam[0] = 0; // Spool
  378. } else {
  379. pam[0] = 1; // Not spool
  380. }
  381. if (Plane & PLN_MGENTA) {
  382. pam[1] = 0; // Spool
  383. } else {
  384. pam[1] = 1; // Not spool
  385. }
  386. if (Plane & PLN_YELLOW) {
  387. pam[2] = 0; // Spool
  388. } else {
  389. pam[2] = 1; // Not spool
  390. }
  391. if (Plane & PLN_BLACK) {
  392. pam[3] = 0; // Spool
  393. } else {
  394. pam[3] = 1; // Not spool
  395. }
  396. siz = CmdStore(lpDst, &OrgDrwPln, pam);
  397. return siz;
  398. }
  399. //===================================================================================================
  400. // Spool bitimage command data
  401. //===================================================================================================
  402. void BitImgImgCmd(
  403. PDEVOBJ pdevobj, // Pointer to PDEVOBJ structure
  404. WORD Width, // dot
  405. WORD Height, // dot
  406. WORD WidthByte, // byte
  407. WORD Rotation, // rotare(0fixed)
  408. WORD InvLeft, // Invalid size from the left edge
  409. WORD InvRight, // Invalid size from the right edge
  410. LPBYTE lpBit // Bitmap data
  411. )
  412. {
  413. int pam[10];
  414. WORD siz;
  415. WORD widByt;
  416. WORD linCnt;
  417. if (InvLeft == 0 && InvRight == 0) { // There are no invalid size
  418. pam[0] = WidthByte * Height; // Number of Data byte
  419. pam[1] = Width;
  420. pam[2] = Height;
  421. pam[3] = Rotation;
  422. siz = CmdStore(CmdBuf, &ImgDrw, pam);
  423. WRITESPOOLBUF(pdevobj, CmdBuf, siz);
  424. WRITESPOOLBUF(pdevobj, lpBit, pam[0]);
  425. } else { // There are invalid size
  426. widByt = WidthByte - InvLeft - InvRight; // Width byte
  427. pam[0] = widByt * Height;
  428. if (InvRight == 0) { // There are no invalid size from the right edge
  429. pam[1] = Width - InvLeft * 8; // Width bit image
  430. } else {
  431. pam[1] = widByt * 8; // Width bit image
  432. }
  433. pam[2] = Height; // Height bit image
  434. pam[3] = Rotation;
  435. siz = CmdStore(CmdBuf, &ImgDrw, pam);
  436. WRITESPOOLBUF(pdevobj, CmdBuf, siz);
  437. for (linCnt = 0; linCnt < Height; linCnt++) { // Spool bitmap data by 1 line
  438. lpBit += InvLeft;
  439. WRITESPOOLBUF(pdevobj, lpBit, widByt);
  440. lpBit += widByt;
  441. lpBit += InvRight;
  442. }
  443. }
  444. return;
  445. }
  446. //===================================================================================================
  447. // Spool raster image command data
  448. //===================================================================================================
  449. BOOL RasterImgCmd(
  450. PDEVOBJ pdevobj, // Pointer to PDEVOBJ structure
  451. WORD Comp,
  452. WORD Width, // dot
  453. WORD Height, // dot
  454. WORD WidthByte, // byte
  455. WORD Rotation, // rotate(0:fixed)
  456. WORD InvLeft, // Invalid size from the left edge
  457. WORD InvRight, // Invalid size from the left edge
  458. LPBYTE lpBit, // Pointer to bitmap data
  459. LPBYTE lpBuf // Pointer to raster image data buffer
  460. )
  461. {
  462. int pam[4];
  463. WORD siz;
  464. WORD widByt;
  465. WORD setCnt;
  466. WORD ras; // Type of raster image
  467. WORD befRas; // Type of raster image(Privious line)
  468. LPBYTE lpLas; // Privious raster data
  469. WORD dstSiz; // byte size
  470. WORD rasSiz; // Raster image data byte size
  471. WORD rasEpy;
  472. MY_VERBOSE((" RAS "));
  473. widByt = WidthByte - InvLeft - InvRight; // Width byte (Not include invalid size)
  474. if (Comp == XX_COMPRESS_AUTO) {
  475. // Get raster image size
  476. rasSiz = RasterSize(Height, widByt, InvLeft, InvRight, lpBit);
  477. if (rasSiz > (widByt * Height / 5 * 4)) { // Raster rate is more than 80%
  478. return No; // Error
  479. }
  480. }
  481. pam[0] = 4;
  482. if (InvRight == 0) { // No invalid size from the right edge
  483. pam[1] = Width - InvLeft * 8; // Width
  484. } else {
  485. pam[1] = widByt * 8; // Width
  486. }
  487. pam[2] = Height; // Height
  488. pam[3] = Rotation;
  489. siz = CmdStore(CmdBuf, &ImgRasStr, pam);
  490. WRITESPOOLBUF(pdevobj, CmdBuf, siz);
  491. lpLas = NULL;
  492. rasSiz = 0;
  493. rasEpy = 0;
  494. for (setCnt = 0; setCnt < Height; setCnt++) {
  495. lpBit += InvLeft;
  496. // Compress
  497. ras = RasterComp(lpBuf + rasSiz, widByt, lpBit, lpLas, &dstSiz);
  498. if (setCnt != 0 && befRas != ras) { // Not same as raster state of previous line
  499. if (befRas == RASTER_COMP) {
  500. pam[0] = rasSiz;
  501. siz = CmdStore(CmdBuf, &ImgRasDrw, pam);
  502. WRITESPOOLBUF(pdevobj, CmdBuf, siz); // Spool command
  503. WRITESPOOLBUF(pdevobj, lpBuf, rasSiz); // Spool data
  504. rasSiz = 0;
  505. } else if (befRas == RASTER_EMPTY) {
  506. pam[0] = rasEpy;
  507. siz = CmdStore(CmdBuf, &ImgRasEpy, pam);
  508. WRITESPOOLBUF(pdevobj, CmdBuf, siz);
  509. rasEpy = 0;
  510. }
  511. } // Spool state of current line
  512. if (ras == RASTER_COMP) {
  513. rasSiz += dstSiz;
  514. } else if (ras == RASTER_EMPTY) {
  515. rasEpy++;
  516. } else {
  517. pam[0] = dstSiz;
  518. siz = CmdStore(CmdBuf, &ImgRasNon, pam);
  519. WRITESPOOLBUF(pdevobj, CmdBuf, siz); // Spool command
  520. WRITESPOOLBUF(pdevobj, lpBit, dstSiz); // Spool data
  521. }
  522. befRas = ras; // Renew
  523. lpLas = lpBit; // Renew
  524. lpBit += widByt; // Renew
  525. lpBit += InvRight;
  526. }
  527. if (rasSiz != 0) { // There are raster data without spooling
  528. pam[0] = rasSiz;
  529. siz = CmdStore(CmdBuf, &ImgRasDrw, pam);
  530. WRITESPOOLBUF(pdevobj, CmdBuf, siz); // Spool command
  531. WRITESPOOLBUF(pdevobj, lpBuf, rasSiz); // Spool data
  532. } else if (rasEpy != 0) { // There are empty raster data without spooling
  533. pam[0] = rasEpy;
  534. siz = CmdStore(CmdBuf, &ImgRasEpy, pam);
  535. WRITESPOOLBUF(pdevobj, CmdBuf, siz); // Spool command
  536. }
  537. siz = CmdCopy(CmdBuf, &ImgRasEnd);
  538. WRITESPOOLBUF(pdevobj, CmdBuf, siz);
  539. return Yes;
  540. }
  541. //===================================================================================================
  542. // Get size of raster image
  543. //===================================================================================================
  544. WORD RasterSize(
  545. WORD Height, // dot
  546. WORD WidthByte, // byte
  547. WORD InvLeft,
  548. WORD InvRight,
  549. LPBYTE lpBit
  550. )
  551. {
  552. WORD rasSiz;
  553. WORD chkCnt;
  554. WORD rasEpy;
  555. LPBYTE lpLas;
  556. WORD dstCnt;
  557. WORD srcCnt;
  558. WORD empSiz;
  559. BYTE cmpDat;
  560. WORD equCnt;
  561. rasSiz = 0;
  562. rasEpy = 0;
  563. lpLas = NULL;
  564. for (chkCnt = 0; chkCnt < Height; chkCnt++) { // Check size of raster image
  565. lpBit += InvLeft;
  566. srcCnt = WidthByte;
  567. for (; srcCnt != 0; srcCnt--) {
  568. if (lpBit[srcCnt - 1] != 0x00) {
  569. break;
  570. }
  571. }
  572. if (srcCnt == 0) { // 1 line All white data?
  573. rasEpy++;
  574. lpLas = lpBit;
  575. lpBit += WidthByte;
  576. lpBit += InvRight;
  577. continue;
  578. }
  579. if (rasEpy != 0) {
  580. rasSiz += 8;
  581. rasEpy = 0;
  582. }
  583. empSiz = WidthByte - srcCnt;
  584. for (dstCnt = 0, srcCnt = 0; srcCnt < WidthByte; ) {
  585. if (lpLas != NULL) {
  586. if (lpLas[srcCnt] == lpBit[srcCnt]) {
  587. equCnt = 1;
  588. srcCnt++;
  589. for (; srcCnt < WidthByte; srcCnt++) {
  590. if (lpLas[srcCnt] != lpBit[srcCnt]) {
  591. break;
  592. }
  593. equCnt++;
  594. }
  595. if (srcCnt == WidthByte) {
  596. rasSiz++;
  597. break;
  598. }
  599. }
  600. rasSiz++;
  601. if (equCnt >= 63) {
  602. rasSiz += ((equCnt / 255) + 1);
  603. }
  604. }
  605. if (srcCnt < (WidthByte - 1) && lpBit[srcCnt] == lpBit[srcCnt + 1]) {
  606. cmpDat = lpBit[srcCnt];
  607. equCnt = 2;
  608. for (srcCnt += 2; srcCnt < WidthByte; srcCnt++) {
  609. if (cmpDat != lpBit[srcCnt]) {
  610. break;
  611. }
  612. equCnt++;
  613. }
  614. rasSiz += 2;
  615. if (equCnt >= 63) {
  616. rasSiz += equCnt / 255 + 1;
  617. }
  618. } else {
  619. if (WidthByte < (dstCnt + 9)) {
  620. rasSiz += WidthByte - empSiz + 9;
  621. break;
  622. }
  623. if ((WidthByte - srcCnt) < 8) {
  624. rasSiz += WidthByte - srcCnt + 1;
  625. srcCnt += WidthByte - srcCnt;
  626. } else {
  627. rasSiz += 9;
  628. srcCnt += 8;
  629. }
  630. }
  631. }
  632. lpLas = lpBit;
  633. lpBit += WidthByte;
  634. lpBit += InvRight;
  635. }
  636. return rasSiz;
  637. }
  638. //===================================================================================================
  639. // Compress raster image
  640. //===================================================================================================
  641. WORD RasterComp(
  642. LPBYTE lpDst,
  643. WORD Siz,
  644. LPBYTE lpSrc,
  645. LPBYTE lpLas,
  646. LPWORD lpDstSiz
  647. )
  648. {
  649. WORD dstCnt;
  650. WORD srcCnt;
  651. WORD empSiz;
  652. BYTE cmpDat;
  653. WORD equCnt;
  654. WORD setCnt;
  655. BYTE flgByt;
  656. WORD flgPnt;
  657. static const BYTE flgTbl[8] = {0x00, 0x01, 0x02, 0x04,
  658. 0x08, 0x10, 0x20, 0x40};
  659. srcCnt = Siz;
  660. for (; srcCnt != 0; srcCnt--) {
  661. if (lpSrc[srcCnt - 1] != 0x00) {
  662. break;
  663. }
  664. }
  665. if (srcCnt == 0) {
  666. *lpDstSiz = 0;
  667. return RASTER_EMPTY;
  668. }
  669. empSiz = Siz - srcCnt;
  670. for (dstCnt = 0, srcCnt = 0; srcCnt < Siz; ) {
  671. if (lpLas != NULL) {
  672. if (lpLas[srcCnt] == lpSrc[srcCnt]) {
  673. equCnt = 1;
  674. srcCnt++;
  675. for (; srcCnt < Siz; srcCnt++) {
  676. if (lpLas[srcCnt] != lpSrc[srcCnt]) {
  677. break;
  678. }
  679. equCnt++;
  680. }
  681. if (srcCnt == Siz) {
  682. break;
  683. }
  684. if (Siz < (dstCnt + equCnt / 255 + 1)) {
  685. *lpDstSiz = Siz - empSiz;
  686. return RASTER_NONCOMP;
  687. }
  688. if (equCnt < 63) {
  689. lpDst[dstCnt++] = 0x80 | (BYTE)equCnt;
  690. } else {
  691. lpDst[dstCnt++] = 0x80 | 0x3f;
  692. for (equCnt -= 63; equCnt >= 255; equCnt -= 255) {
  693. lpDst[dstCnt++] = 0xff;
  694. }
  695. lpDst[dstCnt++] = (BYTE)equCnt;
  696. }
  697. }
  698. }
  699. if (srcCnt < (Siz - 1) && lpSrc[srcCnt] == lpSrc[srcCnt + 1]) {
  700. cmpDat = lpSrc[srcCnt];
  701. equCnt = 2;
  702. for (srcCnt += 2; srcCnt < Siz; srcCnt++) {
  703. if (cmpDat != lpSrc[srcCnt]) {
  704. break;
  705. }
  706. equCnt++;
  707. }
  708. if (Siz < (dstCnt + equCnt / 255 + 2)) {
  709. *lpDstSiz = Siz - empSiz;
  710. return RASTER_NONCOMP;
  711. }
  712. if (equCnt < 63) {
  713. lpDst[dstCnt++] = 0xc0 | (BYTE)equCnt;
  714. } else {
  715. lpDst[dstCnt++] = 0xc0 | 0x3f;
  716. for (equCnt -= 63; equCnt >= 255; equCnt -= 255) {
  717. lpDst[dstCnt++] = 0xff;
  718. }
  719. lpDst[dstCnt++] = (BYTE)equCnt;
  720. }
  721. lpDst[dstCnt++] = cmpDat;
  722. } else {
  723. if (Siz < (dstCnt + 9)) {
  724. *lpDstSiz = Siz - empSiz;
  725. return RASTER_NONCOMP;
  726. }
  727. flgPnt = dstCnt;
  728. dstCnt++;
  729. flgByt = 0x00;
  730. if (lpLas != NULL) {
  731. for (setCnt = 0; srcCnt < Siz && setCnt < 8; srcCnt++, setCnt++) {
  732. if (lpLas[srcCnt] != lpSrc[srcCnt]) {
  733. lpDst[dstCnt++] = lpSrc[srcCnt];
  734. flgByt |= flgTbl[setCnt];
  735. }
  736. }
  737. } else {
  738. for (setCnt = 0; srcCnt < Siz && setCnt < 8; srcCnt++, setCnt++) {
  739. lpDst[dstCnt++] = lpSrc[srcCnt];
  740. flgByt |= flgTbl[setCnt];
  741. }
  742. }
  743. lpDst[flgPnt] = flgByt;
  744. }
  745. }
  746. if (Siz == dstCnt) {
  747. *lpDstSiz = Siz - empSiz;
  748. return RASTER_NONCOMP;
  749. }
  750. lpDst[dstCnt++] = 0x80;
  751. *lpDstSiz = dstCnt;
  752. return RASTER_COMP;
  753. }
  754. //===================================================================================================
  755. // Spool CMYK Bit image command
  756. //===================================================================================================
  757. void CMYKImgCmd(
  758. PDEVOBJ pdevobj, // Pointer to PDEVOBJ structure
  759. WORD Comp,
  760. LONG XPos,
  761. LONG YPos,
  762. WORD Frame,
  763. WORD DataBit, // (1:2value 2:4value 4:16value)
  764. WORD Width, // dot
  765. WORD Height, // dot
  766. WORD WidthByte, // byte
  767. DWORD InvLeft, // Invalid size from the left edge
  768. DWORD InvRight, // Invalid size from the right edge
  769. LPBYTE lpBit,
  770. LPBYTE lpTmp,
  771. LONG XPos_P,
  772. LONG YPos_P
  773. )
  774. {
  775. int pam[11];
  776. WORD siz;
  777. WORD widByt; // Width byte(Not include invalid size)
  778. WORD Plane;
  779. LPBYTE lpDst; // Memory copy
  780. LPBYTE lpSrc; // Memory copy
  781. WORD linCnt;
  782. DWORD widBit; // Width bit(Not include invalid size)
  783. DWORD dstSiz;
  784. DWORD rasSiz;
  785. PMYPDEV pOEM = (PMYPDEV)pdevobj->pdevOEM;
  786. // Check of zero divide 2002.3.23 >>>
  787. if (DataBit == 0) {
  788. ERR(("CMYKImgCmd() 0Div-Check [DataBit=0] \n"));
  789. return;
  790. }
  791. // Check of zero divide 2002.3.23 <<<
  792. widBit = (DWORD)Width * DataBit - InvLeft - InvRight;
  793. if (Comp == Yes) { // Compress
  794. siz = CmdCopy(CmdBuf, &ModOrgIn); // Original mode in
  795. if (pOEM->iColor == XX_COLOR_SINGLE || pOEM->iColor == XX_COLOR_MANY) {
  796. pam[0] = 0;
  797. pam[1] = 0;
  798. pam[2] = 0;
  799. pam[3] = 0;
  800. if (Frame == 1) {
  801. pam[0] = 255;
  802. Plane = PLN_CYAN;
  803. }
  804. if (Frame == 2) {
  805. pam[1] = 255;
  806. Plane = PLN_MGENTA;
  807. }
  808. if (Frame == 3) {
  809. pam[2] = 255;
  810. Plane = PLN_YELLOW;
  811. }
  812. if (Frame == 0) {
  813. pam[3] = 255;
  814. Plane = PLN_BLACK;
  815. }
  816. siz += CmdStore(CmdBuf + siz, &OrgColCmy, pam);
  817. siz += PlaneCmdStore(pdevobj, CmdBuf + siz, Plane);
  818. }
  819. siz += CmdCopy(CmdBuf + siz, &ModOrgOut); // Original mode out
  820. if (siz != 0) { // There are data for spool�H
  821. WRITESPOOLBUF(pdevobj, CmdBuf, siz);
  822. }
  823. pam[0] = XPos_P;
  824. siz = CmdStore(CmdBuf, &PosAbsHrz, pam);
  825. pam[0] = YPos_P;
  826. siz += CmdStore(CmdBuf + siz, &PosAbsVtc, pam);
  827. if (siz != 0) { // There are data for spool
  828. WRITESPOOLBUF(pdevobj, CmdBuf, siz);
  829. }
  830. if (RasterImgCmd(pdevobj, pOEM->iCompress, Width, Height,
  831. WidthByte, 0, (WORD)((InvLeft + 7) / 8), (WORD)((InvRight + 7) / 8), lpBit, lpTmp) == No) {
  832. // Not compress because compress rate is poor
  833. BitImgImgCmd(pdevobj, Width, Height, WidthByte, 0, (WORD)((InvLeft + 7) / 8), (WORD)((InvRight + 7) / 8), lpBit);
  834. }
  835. }
  836. if (Comp == No) { // Not compress
  837. pam[2] = 0;
  838. pam[3] = Frame;
  839. pam[4] = DataBit;
  840. pam[5] = HIWORD(XPos);
  841. pam[6] = LOWORD(XPos);
  842. pam[7] = HIWORD(YPos);
  843. pam[8] = LOWORD(YPos);
  844. pam[10] = Height;
  845. if (InvLeft == 0 && InvRight == 0) { // Not include invalid size
  846. pam[0] = 0; // Data byte size (high byte)
  847. pam[1] = WidthByte * Height; // Data byte size (low byte)
  848. pam[9] = Width;
  849. siz = CmdStore(CmdBuf, &OrgImgCmy, pam);
  850. WRITESPOOLBUF(pdevobj, CmdBuf, siz);
  851. WRITESPOOLBUF(pdevobj, lpBit, pam[1]);
  852. } else { // Include invalid size
  853. widByt = (WORD)((widBit + 7) / 8);
  854. pam[0] = 0; // Data byte size (high byte)
  855. pam[1] = widByt * Height; // Data byte size (low byte)
  856. pam[9] = (WORD)(widBit / DataBit);
  857. siz = CmdStore(CmdBuf, &OrgImgCmy, pam);
  858. WRITESPOOLBUF(pdevobj, CmdBuf, siz);
  859. for (linCnt = 0; linCnt < Height; linCnt++) { // Spool bitmap data by 1 line
  860. WRITESPOOLBUF(pdevobj, lpBit + (WORD)(InvLeft / 8), widByt);
  861. lpBit += WidthByte;
  862. }
  863. }
  864. }
  865. return;
  866. }
  867. //===================================================================================================
  868. // Copy command buffer
  869. //===================================================================================================
  870. WORD CmdCopy(
  871. LPBYTE lpDst,
  872. LPCMDDEF lpCmdInf
  873. )
  874. {
  875. WORD siz;
  876. LPBYTE lpCmd;
  877. lpCmd = lpCmdInf->Cmd;
  878. for (siz = 0; siz < lpCmdInf->Size; siz++) {
  879. lpDst[siz] = lpCmd[siz];
  880. }
  881. return siz;
  882. }
  883. //===================================================================================================
  884. // Copy command data
  885. //===================================================================================================
  886. WORD CmdStore(
  887. LPBYTE lpDst,
  888. LPCMDDEF CmdInf,
  889. LPINT lpPam
  890. )
  891. {
  892. LPBYTE lpCmd;
  893. BYTE cmdDat;
  894. WORD cmdCnt;
  895. WORD setCnt;
  896. WORD pamCnt;
  897. WORD upmDat;
  898. int pamDat;
  899. DWORD dDat;
  900. LONG lDat;
  901. setCnt = 0;
  902. pamCnt = 0;
  903. lpCmd = CmdInf->Cmd;
  904. for (cmdCnt = 0; cmdCnt < CmdInf->Size; cmdCnt++) { // Copy
  905. cmdDat = *lpCmd++;
  906. if (cmdDat != '%') {
  907. lpDst[setCnt++] = cmdDat;
  908. } else {
  909. cmdCnt++;
  910. switch (cmdDat = *lpCmd++) { // Type
  911. case 'u':
  912. setCnt += USINTtoASC(&lpDst[setCnt], (WORD)lpPam[pamCnt++]);
  913. break;
  914. case 'd':
  915. setCnt += INTtoASC(&lpDst[setCnt], lpPam[pamCnt++]);
  916. break;
  917. #if 0 /* 441435: Currently Not used */
  918. case 'y':
  919. upmDat = (WORD)lpPam[pamCnt++];
  920. if (upmDat == 0 || (upmDat / 100) != 0) {
  921. setCnt += USINTtoASC(&lpDst[setCnt], (WORD)(upmDat / 100));
  922. }
  923. if ((upmDat % 100) != 0) {
  924. lpDst[setCnt++] = '.';
  925. setCnt += USINTtoASC(&lpDst[setCnt], (WORD)(upmDat % 100));
  926. }
  927. break;
  928. case 'z':
  929. pamDat = lpPam[pamCnt++];
  930. if (upmDat == 0 || (upmDat / 100) != 0) {
  931. setCnt += INTtoASC(&lpDst[setCnt], (pamDat / 100));
  932. }
  933. if ((pamDat % 100) != 0) {
  934. lpDst[setCnt++] = '.';
  935. if (pamDat < 0) {
  936. pamDat = 0 - pamDat;
  937. }
  938. setCnt += USINTtoASC(&lpDst[setCnt], (WORD)(pamDat % 100));
  939. }
  940. break;
  941. #endif /* 441435: Currently Not used */
  942. case 'w':
  943. dDat = MAKELONG(lpPam[pamCnt + 1], lpPam[pamCnt]);
  944. setCnt += USLONGtoASC(&lpDst[setCnt], dDat);
  945. pamCnt += 2;
  946. break;
  947. case 'l':
  948. lDat = MAKELONG(lpPam[pamCnt + 1], lpPam[pamCnt]);
  949. setCnt += LONGtoASC(&lpDst[setCnt], lDat);
  950. pamCnt += 2;
  951. break;
  952. #if 0 /* 441435: Currently Not used */
  953. case 'b':
  954. lpDst[setCnt++] = (BYTE)lpPam[pamCnt++];
  955. break;
  956. #endif /* 441435: Currently Not used */
  957. case '%':
  958. lpDst[setCnt++] = cmdDat;
  959. break;
  960. }
  961. }
  962. }
  963. return setCnt;
  964. }
  965. //===================================================================================================
  966. // int -> ascii
  967. //===================================================================================================
  968. WORD INTtoASC(
  969. LPBYTE lpDst,
  970. int Dat // Conversion data
  971. )
  972. {
  973. WORD setCnt;
  974. WORD divDat;
  975. WORD setVal;
  976. setCnt = 0;
  977. if (Dat == 0) {
  978. lpDst[setCnt++] = '0';
  979. return setCnt;
  980. }
  981. if (Dat < 0) {
  982. lpDst[setCnt++] = '-';
  983. Dat = 0 - Dat;
  984. }
  985. setVal = No;
  986. for (divDat = 10000; divDat != 1; divDat /= 10) {
  987. if (setVal == Yes) {
  988. lpDst[setCnt++] = (BYTE)(Dat / divDat + '0');
  989. } else {
  990. if (Dat >= (int)divDat) {
  991. lpDst[setCnt++] = (BYTE)(Dat / divDat + '0');
  992. setVal = Yes;
  993. }
  994. }
  995. Dat %= divDat;
  996. }
  997. lpDst[setCnt++] = (BYTE)(Dat + '0');
  998. return setCnt;
  999. }
  1000. //===================================================================================================
  1001. // usint -> ascii
  1002. //===================================================================================================
  1003. WORD USINTtoASC(
  1004. LPBYTE lpDst,
  1005. WORD Dat
  1006. )
  1007. {
  1008. WORD setCnt;
  1009. WORD divDat;
  1010. WORD setVal;
  1011. setCnt = 0;
  1012. if (Dat == 0) {
  1013. lpDst[setCnt++] = '0';
  1014. return setCnt;
  1015. }
  1016. setVal = No;
  1017. for (divDat = 10000; divDat != 1; divDat /= 10) {
  1018. if (setVal == Yes) {
  1019. lpDst[setCnt++] = (BYTE)(Dat / divDat + '0');
  1020. } else {
  1021. if (Dat >= divDat) {
  1022. lpDst[setCnt++] = (BYTE)(Dat / divDat + '0');
  1023. setVal = Yes;
  1024. }
  1025. }
  1026. Dat %= divDat;
  1027. }
  1028. lpDst[setCnt++] = (BYTE)(Dat + '0');
  1029. return setCnt;
  1030. }
  1031. //===================================================================================================
  1032. // long -> ascii
  1033. //===================================================================================================
  1034. WORD LONGtoASC(
  1035. LPBYTE lpDst,
  1036. LONG Dat
  1037. )
  1038. {
  1039. WORD setCnt;
  1040. DWORD divDat;
  1041. WORD setVal;
  1042. setCnt = 0;
  1043. if (Dat == 0) {
  1044. lpDst[setCnt++] = '0';
  1045. return setCnt;
  1046. }
  1047. if (Dat < 0) {
  1048. lpDst[setCnt++] = '-';
  1049. Dat = 0 - Dat;
  1050. }
  1051. setVal = No;
  1052. for (divDat = 1000000000; divDat != 1; divDat /= 10) {
  1053. if (setVal == Yes) {
  1054. lpDst[setCnt++] = (BYTE)(Dat / divDat + '0');
  1055. } else {
  1056. if (Dat >= (LONG)divDat) {
  1057. lpDst[setCnt++] = (BYTE)(Dat / divDat + '0');
  1058. setVal = Yes;
  1059. }
  1060. }
  1061. Dat %= divDat;
  1062. }
  1063. lpDst[setCnt++] = (BYTE)(Dat + '0');
  1064. return setCnt;
  1065. }
  1066. //===================================================================================================
  1067. // uslong -> ascii
  1068. //===================================================================================================
  1069. WORD USLONGtoASC(
  1070. LPBYTE lpDst,
  1071. DWORD Dat
  1072. )
  1073. {
  1074. WORD setCnt;
  1075. DWORD divDat;
  1076. WORD setVal;
  1077. setCnt = 0;
  1078. if (Dat == 0) {
  1079. lpDst[setCnt++] = '0';
  1080. return setCnt;
  1081. }
  1082. setVal = No;
  1083. for (divDat = 1000000000; divDat != 1; divDat /= 10) {
  1084. if (setVal == Yes) {
  1085. lpDst[setCnt++] = (BYTE)(Dat / divDat + '0');
  1086. } else {
  1087. if (Dat >= divDat) {
  1088. lpDst[setCnt++] = (BYTE)(Dat / divDat + '0');
  1089. setVal = Yes;
  1090. }
  1091. }
  1092. Dat %= divDat;
  1093. }
  1094. lpDst[setCnt++] = (BYTE)(Dat + '0');
  1095. return setCnt;
  1096. }
  1097. // End of File