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.

1430 lines
60 KiB

  1. //***************************************************************************************************
  2. // COLMATCH.C
  3. //
  4. // Functions of color matching
  5. //---------------------------------------------------------------------------------------------------
  6. // copyright(C) 1997-1999 CASIO COMPUTER CO.,LTD. / CASIO ELECTRONICS MANUFACTURING CO.,LTD.
  7. //***************************************************************************************************
  8. #include "PDEV.H"
  9. //#include "DEBUG.H"
  10. #include "PRNCTL.H"
  11. #include "strsafe.h" // Security-Code 2002.3.6
  12. //---------------------------------------------------------------------------------------------------
  13. // Byte/Bit table
  14. //---------------------------------------------------------------------------------------------------
  15. static const BYTE BitTbl[8] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
  16. //---------------------------------------------------------------------------------------------------
  17. // Table for numbering dither method
  18. //---------------------------------------------------------------------------------------------------
  19. static const WORD DizNumTbl[7] = {1, // XX_DITHERING_OFF
  20. 1, // XX_DITHERING_ON
  21. 0, // XX_DITHERING_DET
  22. 1, // XX_DITHERING_PIC
  23. 2, // XX_DITHERING_GRA
  24. 0, // XX_DITHERING_CAR
  25. 3 // XX_DITHERING_GOSA
  26. };
  27. #define MAX_DIZNUM (sizeof DizNumTbl / sizeof DizNumTbl[0])
  28. //---------------------------------------------------------------------------------------------------
  29. // Define LUT fine name
  30. //---------------------------------------------------------------------------------------------------
  31. #define N4LUT000 L"CPN4RGB0.LUT" // For N4 printer
  32. #define N4LUT001 L"CPN4RGB1.LUT"
  33. #define N4LUT002 L"CPN4RGB2.LUT"
  34. #define N4LUT003 L"CPN4RGB3.LUT"
  35. #define N4LUT004 L"CPN4RGB4.LUT"
  36. #define N4LUT005 L"CPN4RGB5.LUT"
  37. #define N403LUTX L"CPN4RGBX.LUT" // For N4-612 printer
  38. #define N403LUTY L"CPN4RGBY.LUT"
  39. //---------------------------------------------------------------------------------------------------
  40. // Define DLL name
  41. //---------------------------------------------------------------------------------------------------
  42. #define CSN46RESDLL L"CSN46RES.DLL"
  43. //---------------------------------------------------------------------------------------------------
  44. // Define data
  45. //---------------------------------------------------------------------------------------------------
  46. #define DPI300 300
  47. #define DPI600 600
  48. static BYTE ORG_MODE_IN[] = "\x1Bz\xD0\x01";
  49. static BYTE ORG_MODE_OUT[] = "\x1Bz\x00\x01";
  50. static BYTE PALETTE_SELECT[] = "Cd,%d,%d*";
  51. static BYTE PLANE_RESET[] = "Da,0,0,0,0*";
  52. // Replacement of strsafe-api 2002.3.6 >>>
  53. //#ifdef wsprintf
  54. //#undef wsprintf
  55. //#endif // wsprintf
  56. //#define wsprintf sprintf
  57. // Replacement of strsafe-api 2002.3.6 <<<
  58. //***************************************************************************************************
  59. // Prototype declaration
  60. //***************************************************************************************************
  61. static BOOL DizTblSetN4(PDEVOBJ, WORD);
  62. static BOOL DizTblSetN403(PDEVOBJ, WORD);
  63. static BOOL LutFileLoadN4(PDEVOBJ, WORD, WORD, WORD);
  64. static BOOL LutFileLoadN403(PDEVOBJ, WORD, WORD);
  65. static BOOL TnrTblSetN4(PDEVOBJ, SHORT);
  66. static BOOL TnrTblSetN403(PDEVOBJ, SHORT);
  67. static BOOL ColGosTblSet(LPN4DIZINF, WORD);
  68. static void ColGosTblFree(LPN4DIZINF);
  69. static void ColRgbGos(PDEVOBJ, WORD, WORD, WORD, LPBYTE);
  70. static BOOL BmpBufAlloc(PDEVOBJ, WORD, WORD, WORD, WORD, WORD, WORD, WORD, WORD, LPBMPBIF);
  71. static void BmpBufFree(LPBMPBIF);
  72. static void BmpBufClear(LPBMPBIF);
  73. static WORD Dithering001(PDEVOBJ, WORD, WORD, WORD, WORD, WORD, WORD, LPBYTE, LPBYTE, LPBYTE, LPBYTE, LPBYTE);
  74. static void BmpPrint(PDEVOBJ, LPBMPBIF, POINT, WORD, WORD, WORD);
  75. static void BmpRGBCnv(LPRGB, LPBYTE, WORD, WORD, WORD, LPRGBQUAD);
  76. //***************************************************************************************************
  77. // Functions
  78. //***************************************************************************************************
  79. //===================================================================================================
  80. // Initialize the members of color-matching
  81. //===================================================================================================
  82. BOOL FAR PASCAL ColMatchInit(
  83. PDEVOBJ pdevobj // Pointer to PDEVOBJ structure
  84. )
  85. {
  86. LPN4DIZINF lpN4DizInf; // N4DIZINF structure
  87. LPN403DIZINF lpN403DizInf; // N403DIZINF structure
  88. PMYPDEV pOEM = (PMYPDEV)pdevobj->pdevOEM;
  89. pOEM->Col.Mch.Mode = pOEM->iColorMatching;
  90. pOEM->Col.Mch.Diz = pOEM->iDithering;
  91. pOEM->Col.Mch.PColor = No;
  92. pOEM->Col.Mch.Toner = 0;
  93. if (pOEM->iCmyBlack == XX_CMYBLACK_ON) { // Replace K with CMY?
  94. pOEM->Col.Mch.CmyBlk = 1;
  95. } else {
  96. pOEM->Col.Mch.CmyBlk = 0; // Use black toner
  97. }
  98. // 0 fixed
  99. pOEM->Col.Mch.Bright = 0;
  100. // 0 fixed
  101. pOEM->Col.Mch.Contrast = 0;
  102. // Color balance(R) : 10 fixed
  103. pOEM->Col.Mch.GamRed = 10;
  104. // Color balance(G) : 10 fixed
  105. pOEM->Col.Mch.GamGreen = 10;
  106. // Color balance(B) : 10 fixed
  107. pOEM->Col.Mch.GamBlue = 10;
  108. pOEM->Col.Mch.Speed = pOEM->iBitFont;
  109. pOEM->Col.Mch.Gos32 = No;
  110. pOEM->Col.Mch.LutNum = 0; // LUT table number
  111. pOEM->Col.Mch.TnrNum = 0; // Toner density table number
  112. pOEM->Col.Mch.SubDef = Yes; // Not change setting of color balance, bright and contrast?
  113. CM_VERBOSE(("CMINit ENT Tn=%d Col=%d Mod=%d DZ=%d Cyk=%d Sp=%d Prt=%d\n", pOEM->iTone, pOEM->iColor, pOEM->Col.Mch.Mode,pOEM->Col.Mch.Diz,pOEM->Col.Mch.CmyBlk,pOEM->Col.Mch.Speed,pOEM->Printer));
  114. if (pOEM->Printer != PRN_N403) { // N4 printer
  115. if ((pOEM->Col.N4.lpDizInf = MemAllocZ(sizeof(N4DIZINF))) == NULL) {
  116. ERR(("Alloc ERROR!!\n"));
  117. return 0;
  118. }
  119. lpN4DizInf = pOEM->Col.N4.lpDizInf;
  120. if (pOEM->iColor != XX_MONO) {
  121. lpN4DizInf->ColMon = N4_COL; // Color
  122. } else {
  123. lpN4DizInf->ColMon = N4_MON; // Monochrome
  124. }
  125. if (pOEM->iResolution == XX_RES_300DPI) {
  126. pOEM->Col.wReso = DPI300;
  127. }
  128. pOEM->Col.DatBit = 1;
  129. pOEM->Col.BytDot = 8; // Numbers of DPI(2 value)
  130. if (pOEM->iBitFont == XX_BITFONT_OFF) {
  131. pOEM->Col.Mch.Gos32 = Yes;
  132. }
  133. pOEM->Col.Mch.Speed = Yes;
  134. if (pOEM->Col.Mch.Diz != XX_DITHERING_GOSA) {
  135. // Make dither table for N4 printer
  136. if (DizTblSetN4(pdevobj, pOEM->Col.Mch.Diz) == FALSE) {
  137. ERR(("DizTblSetN4 ERROR!!\n"));
  138. return 0;
  139. }
  140. }
  141. if (lpN4DizInf->ColMon == N4_COL) {
  142. if (pOEM->Col.Mch.Mode != XX_COLORMATCH_NONE) {
  143. // Load LUT file
  144. if (LutFileLoadN4(pdevobj,
  145. pOEM->Col.Mch.Mode,
  146. pOEM->Col.Mch.Diz,
  147. pOEM->Col.Mch.Speed) == FALSE) {
  148. ERR(("LutFileLoadN4 ERROR!!\n"));
  149. return 0;
  150. }
  151. pOEM->Col.Mch.LutNum = 0; // Lut table number
  152. }
  153. // Make toner density table
  154. if (TnrTblSetN4(pdevobj, pOEM->Col.Mch.Toner) == FALSE) {
  155. ERR(("TnrTblSetN4 ERROR!!\n"));
  156. return 0;
  157. }
  158. pOEM->Col.Mch.TnrNum = 0; // Toner density table number
  159. }
  160. } else { // N403 printer
  161. if ((pOEM->Col.N403.lpDizInf = MemAllocZ(sizeof(N403DIZINF))) == NULL) {
  162. ERR(("Init Alloc ERROR!!\n"));
  163. return 0;
  164. }
  165. lpN403DizInf = pOEM->Col.N403.lpDizInf;
  166. if (pOEM->Col.Mch.Mode == XX_COLORMATCH_VIV) {
  167. pOEM->Col.Mch.Viv = 20;
  168. }
  169. pOEM->Col.wReso = (pOEM->iResolution == XX_RES_300DPI) ? DPI300 : DPI600;
  170. if (pOEM->iColor != XX_MONO) {
  171. lpN403DizInf->ColMon = N403_COL; // Color
  172. } else {
  173. lpN403DizInf->ColMon = N403_MON; // Monochrome
  174. }
  175. if (pOEM->iColor == XX_COLOR_SINGLE) {
  176. lpN403DizInf->PrnMod = (pOEM->iResolution == XX_RES_300DPI) ? N403_MOD_300B1 : N403_MOD_600B1;
  177. }
  178. if (pOEM->iColor == XX_COLOR_MANY) {
  179. lpN403DizInf->PrnMod = (pOEM->iResolution == XX_RES_300DPI) ? N403_MOD_300B4 : N403_MOD_600B2;
  180. }
  181. if (lpN403DizInf->PrnMod == N403_MOD_300B1) { // 300DPI 2 value
  182. CM_VERBOSE(("N403_MOD_300B1\n"));
  183. pOEM->Col.DatBit = 1;
  184. pOEM->Col.BytDot = 8; // Number of DPI(2 value)
  185. } else if (lpN403DizInf->PrnMod == N403_MOD_300B4) { // 300DPI 16 value
  186. CM_VERBOSE(("N403_MOD_300B4\n"));
  187. pOEM->Col.DatBit = 4;
  188. pOEM->Col.BytDot = 2;
  189. } else if (lpN403DizInf->PrnMod == N403_MOD_600B1) { // 600DPI 2 value
  190. CM_VERBOSE(("N403_MOD_600B1\n"));
  191. pOEM->Col.DatBit = 1;
  192. pOEM->Col.BytDot = 8;
  193. } else { // 600DPI 4 value
  194. CM_VERBOSE(("N403_MOD_600B2\n"));
  195. pOEM->Col.DatBit = 2;
  196. pOEM->Col.BytDot = 4;
  197. }
  198. // Make dither table for N4-612 printer
  199. if (DizTblSetN403(pdevobj, pOEM->Col.Mch.Diz) == FALSE) {
  200. ERR(("diztblset n403 ERROR!!\n"));
  201. return 0;
  202. }
  203. if (lpN403DizInf->ColMon == N403_COL) {
  204. if (pOEM->Col.Mch.Mode != XX_COLORMATCH_NONE) {
  205. // Load LUT file
  206. if (LutFileLoadN403(pdevobj,
  207. pOEM->Col.Mch.Mode,
  208. pOEM->Col.Mch.Speed) == FALSE) {
  209. ERR(("lutfileloadn4 ERROR!!\n"));
  210. return 0;
  211. }
  212. pOEM->Col.Mch.LutNum = 0;
  213. }
  214. // Make toner density table
  215. if (TnrTblSetN403(pdevobj, pOEM->Col.Mch.Toner) == FALSE) {
  216. ERR(("tnrtblsetn4 ERROR!!\n"));
  217. return 0;
  218. }
  219. pOEM->Col.Mch.TnrNum = 0;
  220. }
  221. }
  222. CM_VERBOSE(("ColMatchInit End pOEM->Col.wReso= %d\n",pOEM->Col.wReso));
  223. return TRUE;
  224. }
  225. //===================================================================================================
  226. // DIB spools to the printer
  227. //===================================================================================================
  228. BOOL FAR PASCAL DIBtoPrn(
  229. PDEVOBJ pdevobj,
  230. PBYTE pSrcBmp,
  231. PBITMAPINFOHEADER pBitmapInfoHeader,
  232. PBYTE pColorTable,
  233. PIPPARAMS pIPParams)
  234. {
  235. BMPBIF bmpBuf; // BMPBIF structure
  236. POINT drwPos; // Start position for spooling
  237. WORD dstWByt; // X size of destination bitmap data
  238. LONG dstX; // X coordinates of destination bitmap data
  239. LONG dstY; // Y coordinates of destination bitmap data
  240. LONG dstYEnd; // The last Y coordinates(+1) of destination bitmap data
  241. WORD dstScn; // Number of destination bitmap data lines
  242. WORD srcY; // Y coordinates of source bitmap data
  243. LONG srcWByt; // Y size of source bitmap data
  244. WORD setCnt; // count
  245. LPCMYK lpCMYK; // CMYK temporary data buffer
  246. BYTE Cmd[64];
  247. WORD wlen;
  248. LPSTR pDestEnd; // 2002.3.6
  249. size_t szRemLen; // 2002.3.6
  250. PMYPDEV pOEM = (PMYPDEV)pdevobj->pdevOEM;
  251. CM_VERBOSE((" ImagePro ENTRY Dx=%d Dy=%d SxSiz=%d SySiz=%d BC=%d Sz=%d ",
  252. pIPParams->ptOffset.x, pIPParams->ptOffset.y,
  253. pBitmapInfoHeader->biWidth, pBitmapInfoHeader->biHeight, pBitmapInfoHeader->biBitCount,
  254. pIPParams->dwSize));
  255. if (pOEM->Printer != PRN_N403) { // N4 printer
  256. if (pOEM->iDithering == XX_DITHERING_GOSA) {
  257. if (pOEM->Col.N4.lpDizInf->GosRGB.Siz < (DWORD)pBitmapInfoHeader->biWidth) {
  258. ColGosTblFree(pOEM->Col.N4.lpDizInf);
  259. if ((ColGosTblSet(pOEM->Col.N4.lpDizInf, (WORD)pBitmapInfoHeader->biWidth)) == FALSE) {
  260. return FALSE;
  261. }
  262. }
  263. }
  264. }
  265. // Initialization of
  266. // RGB buffer :(X size of source bitmap data) * 3
  267. // CMYK buffer :(X size of source bitmap data) * 4
  268. // CMYK bit buffer :((X size of source bitmap data) * (Magnification of X) + 7) / 8 * (Y size of source bitmap data) * (Magnification of Y))
  269. memset(&bmpBuf, 0x00, sizeof(BMPBIF));
  270. if (BmpBufAlloc(pdevobj, (WORD)pBitmapInfoHeader->biWidth, (WORD)pBitmapInfoHeader->biHeight, 0, 0, 1, 1, 1, 1, &bmpBuf) == FALSE) {
  271. ERR(("Alloc ERROR!!\n"));
  272. return FALSE;
  273. }
  274. bmpBuf.Diz = pOEM->iDithering;
  275. bmpBuf.Style = 0;
  276. bmpBuf.DatBit = pOEM->Col.DatBit;
  277. dstWByt = (WORD)((pBitmapInfoHeader->biWidth + pOEM->Col.BytDot - 1) / pOEM->Col.BytDot);
  278. srcWByt = (pBitmapInfoHeader->biWidth * pBitmapInfoHeader->biBitCount + 31L) / 32L * 4L;
  279. drwPos.x = dstX = pIPParams->ptOffset.x;
  280. dstY = pIPParams->ptOffset.y;
  281. srcY = 0;
  282. dstYEnd = pIPParams->ptOffset.y + pBitmapInfoHeader->biHeight;
  283. // Convert DIB and spool to the printer
  284. for (;dstY < dstYEnd; ) {
  285. BmpBufClear(&bmpBuf);
  286. drwPos.y = dstY;
  287. for (dstScn = 0; dstY < dstYEnd && dstScn < bmpBuf.Drv.Bit.Lin; dstScn++, dstY++) {
  288. // Convert 1 line RGB bitmap data into 24bit (for 1pixel) RGB bitmap data
  289. BmpRGBCnv(bmpBuf.Drv.Rgb.Pnt, pSrcBmp, pBitmapInfoHeader->biBitCount, 0,
  290. (WORD)pBitmapInfoHeader->biWidth, (LPRGBQUAD)pColorTable);
  291. if (pOEM->Col.Mch.Gos32 == Yes) {
  292. ColRgbGos(pdevobj, (WORD)pBitmapInfoHeader->biWidth, (WORD)dstX, (WORD)dstY, (LPBYTE)bmpBuf.Drv.Rgb.Pnt);
  293. }
  294. // Convert RGB into CMYK
  295. bmpBuf.Drv.Rgb.AllWhite = (WORD)StrColMatching(pdevobj, (WORD)pBitmapInfoHeader->biWidth, bmpBuf.Drv.Rgb.Pnt, bmpBuf.Drv.Cmyk.Pnt);
  296. lpCMYK = bmpBuf.Drv.Cmyk.Pnt;
  297. if (pOEM->iDithering == XX_DITHERING_OFF) {
  298. for (setCnt = 0; setCnt < pBitmapInfoHeader->biWidth; setCnt++) {
  299. if (lpCMYK[setCnt].Cyn != 0) { lpCMYK[setCnt].Cyn = 255; }
  300. if (lpCMYK[setCnt].Mgt != 0) { lpCMYK[setCnt].Mgt = 255; }
  301. if (lpCMYK[setCnt].Yel != 0) { lpCMYK[setCnt].Yel = 255; }
  302. if (lpCMYK[setCnt].Bla != 0) { lpCMYK[setCnt].Bla = 255; }
  303. }
  304. }
  305. Dithering001(pdevobj, (WORD)pOEM->iDithering, (WORD)pBitmapInfoHeader->biWidth, (WORD)dstX, (WORD)dstY,
  306. srcY, (WORD)bmpBuf.Drv.Rgb.AllWhite, (LPBYTE)bmpBuf.Drv.Cmyk.Pnt,
  307. bmpBuf.Drv.Bit.Pnt[CYAN] + dstWByt * dstScn,
  308. bmpBuf.Drv.Bit.Pnt[MGENTA] + dstWByt * dstScn,
  309. bmpBuf.Drv.Bit.Pnt[YELLOW] + dstWByt * dstScn,
  310. bmpBuf.Drv.Bit.Pnt[BLACK] + dstWByt * dstScn);
  311. srcY++;
  312. pSrcBmp += srcWByt;
  313. }
  314. if (dstScn != 0) {
  315. // Spool to printer
  316. BmpPrint(pdevobj, &bmpBuf, drwPos, (WORD)pBitmapInfoHeader->biWidth, dstScn, dstWByt);
  317. }
  318. }
  319. // Set back palette (Palette No. is fixed , All plane(CMYK) is OK )
  320. // Same as palette state before OEMImageProcessing call
  321. WRITESPOOLBUF(pdevobj, ORG_MODE_IN, BYTE_LENGTH(ORG_MODE_IN));
  322. // Replacement of strsafe-api 2002.3.6 >>>
  323. // wlen = (WORD)wsprintf(Cmd, PALETTE_SELECT, 0, DEFAULT_PALETTE_INDEX);
  324. if (S_OK != StringCbPrintfExA(Cmd, sizeof(Cmd),
  325. &pDestEnd, &szRemLen,
  326. STRSAFE_IGNORE_NULLS | STRSAFE_NULL_ON_FAILURE,
  327. PALETTE_SELECT, 0, DEFAULT_PALETTE_INDEX)) {
  328. BmpBufFree(&bmpBuf);
  329. return FALSE;
  330. }
  331. wlen = (WORD)(pDestEnd - Cmd);
  332. // Replacement of strsafe-api 2002.3.6 <<<
  333. WRITESPOOLBUF(pdevobj, Cmd, wlen);
  334. WRITESPOOLBUF(pdevobj, PLANE_RESET, BYTE_LENGTH(PLANE_RESET));
  335. WRITESPOOLBUF(pdevobj, ORG_MODE_OUT, BYTE_LENGTH(ORG_MODE_OUT));
  336. BmpBufFree(&bmpBuf);
  337. CM_VERBOSE(("ImagePro End\n"));
  338. return TRUE;
  339. }
  340. //===================================================================================================
  341. // Convert RGB data into CMYK data
  342. //===================================================================================================
  343. BOOL FAR PASCAL StrColMatching(
  344. PDEVOBJ pdevobj, // Pointer to pdevobj structure
  345. WORD MchSiz, // X size of RGB
  346. LPRGB lpRGB, // RGB buffer
  347. LPCMYK lpCMYK // CMYK buffer
  348. )
  349. {
  350. LPN4DIZINF lpN4DizInf; // N4DIZINF structure
  351. LPN403DIZINF lpN403DizInf; // N403DIZINF structure
  352. WORD chkCnt; // RGB white data check count
  353. DWORD bCnv; // Replace black
  354. PMYPDEV pOEM = (PMYPDEV)pdevobj->pdevOEM;
  355. for (chkCnt = 0; chkCnt < MchSiz; chkCnt++) { // Check RGB data
  356. if (lpRGB[chkCnt].Blue != 0xff || lpRGB[chkCnt].Green != 0xff || lpRGB[chkCnt].Red != 0xff) {
  357. break; // There are data except white data
  358. }
  359. }
  360. if (chkCnt >= MchSiz) {
  361. return Yes; // All RGB data is white
  362. }
  363. if (pOEM->Printer != PRN_N403) { // N4 printer
  364. lpN4DizInf = pOEM->Col.N4.lpDizInf;
  365. bCnv = pOEM->Col.Mch.CmyBlk;
  366. if (lpN4DizInf->ColMon == N4_COL) { // Color
  367. // Convert RGB data
  368. if (pOEM->Col.Mch.Diz == XX_DITHERING_OFF) {
  369. N4ColCnvLin(lpN4DizInf, lpRGB, lpCMYK, (DWORD)MchSiz);
  370. } else if (/*pOEM->Col.Mch.KToner == Yes && */MchSiz == 1 &&
  371. lpRGB->Blue == lpRGB->Green && lpRGB->Blue == lpRGB->Red) {
  372. // For monochrome
  373. N4ColCnvMon(lpN4DizInf, (DWORD)DizNumTbl[pOEM->Col.Mch.Diz], lpRGB, lpCMYK, (DWORD)MchSiz);
  374. } else if (pOEM->Col.Mch.Mode != XX_COLORMATCH_NONE) {
  375. if (pOEM->Col.Mch.Speed == Yes) {
  376. N4ColMch000(lpN4DizInf, lpRGB, lpCMYK, (DWORD)MchSiz, bCnv);
  377. } else {
  378. N4ColMch001(lpN4DizInf, lpRGB, lpCMYK, (DWORD)MchSiz, bCnv);
  379. }
  380. } else {
  381. N4ColCnvSld(lpN4DizInf, lpRGB, lpCMYK, (DWORD)MchSiz);
  382. }
  383. } else { // For monochrome
  384. N4ColCnvMon(lpN4DizInf, (DWORD)DizNumTbl[pOEM->Col.Mch.Diz], lpRGB, lpCMYK, (DWORD)MchSiz);
  385. }
  386. } else { // N403 printer
  387. lpN403DizInf = pOEM->Col.N403.lpDizInf;
  388. bCnv = pOEM->Col.Mch.CmyBlk;
  389. if (lpN403DizInf->ColMon == N403_COL) { // Color
  390. if (pOEM->Col.Mch.Diz == XX_DITHERING_OFF) {
  391. N403ColCnvL02(lpN403DizInf, lpRGB, lpCMYK, (DWORD)MchSiz);
  392. } else if (/*pOEM->Col.Mch.KToner == Yes && */MchSiz == 1 &&
  393. lpRGB->Blue == lpRGB->Green && lpRGB->Blue == lpRGB->Red) {
  394. // For monochrome
  395. N403ColCnvMon(lpN403DizInf, lpRGB, lpCMYK, (DWORD)MchSiz);
  396. } else if (pOEM->Col.Mch.Mode != XX_COLORMATCH_NONE) {
  397. if (pOEM->Col.Mch.Speed == Yes) {
  398. N403ColMch000(lpN403DizInf, lpRGB, lpCMYK, (DWORD)MchSiz, bCnv);
  399. } else {
  400. N403ColMch001(lpN403DizInf, lpRGB, lpCMYK, (DWORD)MchSiz, bCnv);
  401. }
  402. if (pOEM->Col.Mch.Mode == XX_COLORMATCH_VIV) {
  403. N403ColVivPrc(lpN403DizInf, lpCMYK, (DWORD)MchSiz, (DWORD)pOEM->Col.Mch.Viv);
  404. }
  405. } else {
  406. N403ColCnvSld(lpN403DizInf, lpRGB, lpCMYK, (DWORD)MchSiz, bCnv);
  407. }
  408. } else { // For monochrome
  409. N403ColCnvMon(lpN403DizInf, lpRGB, lpCMYK, (DWORD)MchSiz);
  410. }
  411. }
  412. return No; // There are data except white data
  413. }
  414. //===================================================================================================
  415. // Allocate GOSA-KAKUSAN table (Only for N4 printer)
  416. //===================================================================================================
  417. BOOL ColGosTblSet(
  418. LPN4DIZINF lpN4DizInf, // Pointer to N4DIZINF structure
  419. WORD XSize // Xsize
  420. )
  421. {
  422. if ((lpN4DizInf->GosRGB.Tbl[0] = MemAllocZ((DWORD)(XSize + 2) * sizeof(SHORT) * 3)) == NULL) {
  423. return 0;
  424. }
  425. if ((lpN4DizInf->GosRGB.Tbl[1] = MemAllocZ((DWORD)(XSize + 2) * sizeof(SHORT) * 3)) == NULL) {
  426. return 0;
  427. }
  428. if ((lpN4DizInf->GosCMYK.Tbl[0] = MemAllocZ((DWORD)(XSize + 2) * sizeof(SHORT) * 4)) == NULL) {
  429. return 0;
  430. }
  431. if ((lpN4DizInf->GosCMYK.Tbl[1] = MemAllocZ((DWORD)(XSize + 2) * sizeof(SHORT) * 4)) == NULL) {
  432. return 0;
  433. }
  434. lpN4DizInf->GosRGB.Num = 0;
  435. lpN4DizInf->GosCMYK.Num = 0;
  436. lpN4DizInf->GosRGB.Siz = XSize;
  437. lpN4DizInf->GosCMYK.Siz = XSize;
  438. lpN4DizInf->GosRGB.Yax = 0xffffffff;
  439. lpN4DizInf->GosCMYK.Yax = 0xffffffff;
  440. return TRUE;
  441. }
  442. //===================================================================================================
  443. // Free GOSA-KAKUSAN table (Only for N4 printer)
  444. //===================================================================================================
  445. void ColGosTblFree(
  446. LPN4DIZINF lpN4DizInf // Pointer to N4DIZINF structure
  447. )
  448. {
  449. if (lpN4DizInf->GosRGB.Tbl[0]) {
  450. MemFree(lpN4DizInf->GosRGB.Tbl[0]);
  451. lpN4DizInf->GosRGB.Tbl[0] = NULL;
  452. }
  453. if (lpN4DizInf->GosRGB.Tbl[1]) {
  454. MemFree(lpN4DizInf->GosRGB.Tbl[1])
  455. lpN4DizInf->GosRGB.Tbl[1] = NULL;
  456. }
  457. if (lpN4DizInf->GosCMYK.Tbl[0]) {
  458. MemFree(lpN4DizInf->GosCMYK.Tbl[0]);
  459. lpN4DizInf->GosCMYK.Tbl[0] = NULL;
  460. }
  461. if (lpN4DizInf->GosCMYK.Tbl[1]) {
  462. MemFree(lpN4DizInf->GosCMYK.Tbl[1]);
  463. lpN4DizInf->GosCMYK.Tbl[1] = NULL;
  464. }
  465. return;
  466. }
  467. //===================================================================================================
  468. // RGB data conversion(For GOSA-KAKUSAN, only for N4)
  469. //===================================================================================================
  470. void ColRgbGos(
  471. PDEVOBJ pdevobj,
  472. WORD XSize,
  473. WORD XPos,
  474. WORD YOff,
  475. LPBYTE lpRGB
  476. )
  477. {
  478. LPN4DIZINF lpN4DizInf;
  479. PMYPDEV pOEM = (PMYPDEV)pdevobj->pdevOEM;
  480. if (pOEM->Printer == PRN_N403) {
  481. return;
  482. }
  483. lpN4DizInf = pOEM->Col.N4.lpDizInf;
  484. N4RgbGos(lpN4DizInf, (DWORD)XSize, (DWORD)XPos, (DWORD)YOff, lpRGB);
  485. return;
  486. }
  487. //===================================================================================================
  488. // Free dither table, toner density table , Lut table, N403DIZINF(N4DIZINF) structure buffer
  489. //===================================================================================================
  490. void FAR PASCAL DizLutTnrTblFree(
  491. PDEVOBJ pdevobj
  492. )
  493. {
  494. int i;
  495. DWORD dizNum;
  496. WORD alcCnt;
  497. WORD alcTbl;
  498. PMYPDEV pOEM = (PMYPDEV)pdevobj->pdevOEM;
  499. if (pOEM->Printer != PRN_N403
  500. && NULL != pOEM->Col.N4.lpDizInf) {
  501. // N4 printer
  502. CM_VERBOSE(("OEMDisablePDEV N4\n"));
  503. if (pOEM->Col.Mch.Diz != XX_DITHERING_GOSA) {
  504. dizNum = DizNumTbl[pOEM->Col.Mch.Diz]; // Dither number
  505. for (i = 0; i < 4; i++) {
  506. if (pOEM->Col.N4.lpDizInf->Diz.Tbl[dizNum][i]) {
  507. MemFree(pOEM->Col.N4.lpDizInf->Diz.Tbl[dizNum][i]);
  508. pOEM->Col.N4.lpDizInf->Diz.Tbl[dizNum][i] = NULL;
  509. }
  510. }
  511. }
  512. if (pOEM->Col.N4.lpDizInf->Tnr.Tbl) {
  513. MemFree(pOEM->Col.N4.lpDizInf->Tnr.Tbl);
  514. pOEM->Col.N4.lpDizInf->Tnr.Tbl = NULL;
  515. }
  516. if (pOEM->Col.Mch.Mode != XX_COLORMATCH_NONE) {
  517. if (pOEM->Col.N4.lpDizInf->Lut.Tbl) {
  518. MemFree(pOEM->Col.N4.lpDizInf->Lut.Tbl);
  519. pOEM->Col.N4.lpDizInf->Lut.Tbl = NULL;
  520. }
  521. if (pOEM->Col.Mch.Speed == No) {
  522. if (pOEM->Col.N4.lpDizInf->Lut.CchRgb) {
  523. MemFree(pOEM->Col.N4.lpDizInf->Lut.CchRgb);
  524. pOEM->Col.N4.lpDizInf->Lut.CchRgb = NULL;
  525. }
  526. if (pOEM->Col.N4.lpDizInf->Lut.CchCmy) {
  527. MemFree(pOEM->Col.N4.lpDizInf->Lut.CchCmy);
  528. pOEM->Col.N4.lpDizInf->Lut.CchCmy = NULL;
  529. }
  530. }
  531. }
  532. if (pOEM->iDithering == XX_DITHERING_GOSA) {
  533. ColGosTblFree(pOEM->Col.N4.lpDizInf);
  534. }
  535. if (pOEM->Col.N4.lpDizInf) {
  536. MemFree(pOEM->Col.N4.lpDizInf);
  537. pOEM->Col.N4.lpDizInf = NULL;
  538. }
  539. } else if (NULL != pOEM->Col.N403.lpDizInf) {
  540. // N4-612 printer
  541. CM_VERBOSE(("OEMDisablePDEV N403\n"));
  542. dizNum = DizNumTbl[pOEM->Col.Mch.Diz];
  543. if (pOEM->Col.N403.lpDizInf->PrnMod == N403_MOD_600B2 && pOEM->Col.Mch.Diz == XX_DITHERING_DET) {
  544. alcTbl = 1;
  545. } else {
  546. alcTbl = 4;
  547. }
  548. for (alcCnt = 0; alcCnt < alcTbl; alcCnt++) {
  549. if (pOEM->Col.N403.lpDizInf->Diz.Tbl[dizNum][alcCnt]) {
  550. MemFree(pOEM->Col.N403.lpDizInf->Diz.Tbl[dizNum][alcCnt]);
  551. pOEM->Col.N403.lpDizInf->Diz.Tbl[dizNum][alcCnt] = NULL;
  552. }
  553. }
  554. if (pOEM->Col.N403.lpDizInf->PrnMod == N403_MOD_600B2) {
  555. for (i = 0; i < 4; i++) {
  556. if (pOEM->Col.N403.lpDizInf->EntDiz.Tbl[i]) {
  557. MemFree(pOEM->Col.N403.lpDizInf->EntDiz.Tbl[i]);
  558. pOEM->Col.N403.lpDizInf->EntDiz.Tbl[i] = NULL;
  559. }
  560. }
  561. }
  562. if (pOEM->Col.N403.lpDizInf->Tnr.Tbl) {
  563. MemFree(pOEM->Col.N403.lpDizInf->Tnr.Tbl);
  564. pOEM->Col.N403.lpDizInf->Tnr.Tbl = NULL;
  565. }
  566. if (pOEM->Col.Mch.Mode != XX_COLORMATCH_NONE) {
  567. if (pOEM->Col.N403.lpDizInf->Lut.Tbl) {
  568. MemFree(pOEM->Col.N403.lpDizInf->Lut.Tbl);
  569. pOEM->Col.N403.lpDizInf->Lut.Tbl = NULL;
  570. }
  571. if (pOEM->Col.Mch.Speed == No) {
  572. if (pOEM->Col.N403.lpDizInf->Lut.CchRgb) {
  573. MemFree(pOEM->Col.N403.lpDizInf->Lut.CchRgb);
  574. pOEM->Col.N403.lpDizInf->Lut.CchRgb = NULL;
  575. }
  576. if (pOEM->Col.N403.lpDizInf->Lut.CchCmy) {
  577. MemFree(pOEM->Col.N403.lpDizInf->Lut.CchCmy);
  578. pOEM->Col.N403.lpDizInf->Lut.CchCmy = NULL;
  579. }
  580. }
  581. }
  582. if (pOEM->Col.N403.lpDizInf) {
  583. MemFree(pOEM->Col.N403.lpDizInf);
  584. pOEM->Col.N403.lpDizInf = NULL;
  585. }
  586. }
  587. }
  588. //===================================================================================================
  589. // Allocate bitmap data buffer
  590. //---------------------------------------------------------------------------------------------------
  591. // Allocate size
  592. // RGB buffer :Source bitmap Xsize * 3
  593. // CMYK buffer :Source bitmap Xsize * 4
  594. // CMYK bit buffer :2 value (Source Xsize * XNrt + 7) / 8 * Source Ysize * YNrt
  595. // :4 value (Source Xsize * XNrt + 3) / 4 * Source Ysize * YNrt
  596. // :16 value (Source Xsize * XNrt + 1) / 2 * Source Ysize * YNrt
  597. //===================================================================================================
  598. BOOL BmpBufAlloc(
  599. PDEVOBJ pdevobj, // Pointer to pdevobj structure
  600. WORD SrcXSiz, // Source bitmap data Xsize
  601. WORD SrcYSiz, // Source bitmap data Ysize
  602. WORD SrcXOff, // Source X offset
  603. WORD SrcYOff, // Source Y offset
  604. WORD XNrt, // Magnification of X (numerator)
  605. WORD XDnt, // Magnification of X (denominator)
  606. WORD YNrt, // Magnification of Y (numerator)
  607. WORD YDnt, // Magnification of Y (denominator)
  608. LPBMPBIF lpBmpBuf // Pointer to bitmap buffer structure
  609. )
  610. {
  611. WORD setSiz;
  612. WORD setCnt;
  613. WORD alcErr; // Allocate error?
  614. WORD bytDot; // DPI
  615. WORD xSiz;
  616. WORD ySiz;
  617. WORD alcLin;
  618. DWORD alcSiz;
  619. PMYPDEV pOEM = (PMYPDEV)pdevobj->pdevOEM;
  620. alcErr = Yes;
  621. bytDot = pOEM->Col.BytDot;
  622. // Check of zero divide 2002.3.23 >>>
  623. if ((XDnt == 0) || (YDnt == 0)) {
  624. ERR(("BmpBufAlloc() 0Div-Check [XDnt, YDnt=0] \n"));
  625. return 0;
  626. }
  627. // Check of zero divide 2002.3.23 <<<
  628. xSiz = (WORD)(((DWORD)SrcXOff + SrcXSiz) * XNrt / XDnt);
  629. xSiz -= (WORD)((DWORD)SrcXOff * XNrt / XDnt);
  630. ySiz = (WORD)(((DWORD)SrcYOff + SrcYSiz + 2) * YNrt / YDnt);
  631. ySiz -= (WORD)((DWORD)SrcYOff * YNrt / YDnt);
  632. // The size of CMYK bit buffer
  633. if (((DWORD)((xSiz + bytDot - 1) / bytDot) * ySiz) < (64L * 1024L - 1L)) {
  634. alcLin = ySiz;
  635. } else { // Over 64kb?
  636. alcLin = (WORD)((64L * 1024L - 1L) / ((xSiz + bytDot - 1) / bytDot));
  637. }
  638. alcSiz = ((xSiz + bytDot - 1) / bytDot) * alcLin; // The size of CMYK bit buffer(8bit boundary)
  639. for ( ; ; ) { // Allocation
  640. // The number of lines that required.
  641. lpBmpBuf->Drv.Bit.BseLin = (WORD)((DWORD)(YNrt + YDnt - 1) / YDnt);
  642. if (lpBmpBuf->Drv.Bit.BseLin > alcLin) {
  643. break;
  644. }
  645. lpBmpBuf->Drv.Rgb.Siz = SrcXSiz * 3; // RGB buffer
  646. if ((lpBmpBuf->Drv.Rgb.Pnt = (LPRGB)MemAllocZ(lpBmpBuf->Drv.Rgb.Siz)) == NULL) {
  647. break;
  648. }
  649. lpBmpBuf->Drv.Cmyk.Siz = SrcXSiz * 4; // CMYK buffer
  650. if ((lpBmpBuf->Drv.Cmyk.Pnt = (LPCMYK)MemAllocZ(lpBmpBuf->Drv.Cmyk.Siz)) == NULL) {
  651. break;
  652. }
  653. if (pOEM->iColor == XX_COLOR_SINGLE || pOEM->iColor == XX_COLOR_MANY) { // Color?
  654. setSiz = 4; // CMYK
  655. } else { // Mono?
  656. setSiz = 1; // K
  657. }
  658. // CMYK bit buffer
  659. for (setCnt = 0; setCnt < setSiz; setCnt++) {
  660. if ((lpBmpBuf->Drv.Bit.Pnt[setCnt] = MemAllocZ(alcSiz)) == NULL) {
  661. break;
  662. }
  663. }
  664. if (setCnt == setSiz) {
  665. lpBmpBuf->Drv.Bit.Siz = alcSiz;
  666. lpBmpBuf->Drv.Bit.Lin = alcLin;
  667. alcErr = No; // Allocate OK
  668. }
  669. break;
  670. }
  671. if (alcErr == Yes) { // Allocate error?
  672. BmpBufFree(lpBmpBuf);
  673. return FALSE;
  674. }
  675. return TRUE;
  676. }
  677. //===================================================================================================
  678. // Free bitmap data buffer
  679. //===================================================================================================
  680. void BmpBufFree(
  681. LPBMPBIF lpBmpBuf // Pointer to bitmap buffer structure
  682. )
  683. {
  684. WORD chkCnt;
  685. if (lpBmpBuf->Drv.Rgb.Pnt) { // Free RGB buffer
  686. MemFree(lpBmpBuf->Drv.Rgb.Pnt);
  687. lpBmpBuf->Drv.Rgb.Pnt = NULL;
  688. }
  689. if (lpBmpBuf->Drv.Cmyk.Pnt) { // Free CMYK buffer
  690. MemFree(lpBmpBuf->Drv.Cmyk.Pnt);
  691. lpBmpBuf->Drv.Cmyk.Pnt = NULL;
  692. }
  693. // CMYK bit buffer
  694. for (chkCnt = 0; chkCnt < 4; chkCnt++) { // CMYK(2/4/16value)bitmap buffer
  695. if (lpBmpBuf->Drv.Bit.Pnt[chkCnt]) {
  696. MemFree(lpBmpBuf->Drv.Bit.Pnt[chkCnt]);
  697. lpBmpBuf->Drv.Bit.Pnt[chkCnt] = NULL;
  698. }
  699. }
  700. return;
  701. }
  702. //===================================================================================================
  703. // Clear CMYK bitmap data buffer
  704. //===================================================================================================
  705. void BmpBufClear(
  706. LPBMPBIF lpBmpBuf // Pointer to bitmap buffer structure
  707. )
  708. {
  709. WORD chkCnt;
  710. for (chkCnt = 0; chkCnt < 4; chkCnt++) { // Clear CMYK(2/4/16value)bit buffer
  711. if (lpBmpBuf->Drv.Bit.Pnt[chkCnt]) {
  712. memset(lpBmpBuf->Drv.Bit.Pnt[chkCnt], 0x00, (WORD)lpBmpBuf->Drv.Bit.Siz);
  713. }
  714. }
  715. return;
  716. }
  717. //===================================================================================================
  718. // Dithering
  719. //===================================================================================================
  720. WORD Dithering001( // Number of lines
  721. PDEVOBJ pdevobj, // Pointer to PDEVOBJ structure
  722. WORD Diz, // Type of dither
  723. WORD XSize, // Numer of Xpixel
  724. WORD XPos, // Start X position for spooling
  725. WORD YPos, // Start Y position for spooling
  726. WORD YOff, // Y offset(Only for GOSA-KAKUSAN)
  727. WORD AllWhite, // All white data?
  728. LPBYTE lpCMYKBuf, // CMYK buffer
  729. LPBYTE lpCBuf, // Line buffer(C)
  730. LPBYTE lpMBuf, // Line buffer(M)
  731. LPBYTE lpYBuf, // Line buffer(Y)
  732. LPBYTE lpKBuf // Line buffer(K)
  733. )
  734. {
  735. DWORD dizLin = 0; /* 441436: Assume failing dither => 0 lines */
  736. /* NOTE: Nobody uses the return value of Dithering001 */
  737. LPN4DIZINF lpN4DizInf;
  738. LPN403DIZINF lpN403DizInf;
  739. PMYPDEV pOEM = (PMYPDEV)pdevobj->pdevOEM;
  740. if (AllWhite == Yes) {
  741. return 1; // Number of line
  742. }
  743. if (pOEM->Printer != PRN_N403) { // N4 printer
  744. lpN4DizInf = pOEM->Col.N4.lpDizInf;
  745. if (Diz == XX_DITHERING_GOSA) {
  746. dizLin = N4Gos001(lpN4DizInf,
  747. (DWORD)XSize, (DWORD)XPos, (DWORD)YPos, lpCMYKBuf, lpCBuf, lpMBuf, lpYBuf, lpKBuf);
  748. } else {
  749. lpN4DizInf->Diz.Num = DizNumTbl[Diz];
  750. dizLin = N4Diz001(lpN4DizInf,
  751. (DWORD)XSize, (DWORD)XPos, (DWORD)YPos, lpCMYKBuf, lpCBuf, lpMBuf, lpYBuf, lpKBuf);
  752. }
  753. } else { // N4-612 printer
  754. lpN403DizInf = pOEM->Col.N403.lpDizInf;
  755. lpN403DizInf->Diz.Num = DizNumTbl[Diz];
  756. if (lpN403DizInf->PrnMod == N403_MOD_300B1 || lpN403DizInf->PrnMod == N403_MOD_600B1) {
  757. dizLin = N403Diz002(lpN403DizInf,
  758. (DWORD)XSize,
  759. (DWORD)XPos, (DWORD)YPos,
  760. (DWORD)0, (DWORD)0,
  761. (DWORD)1, (DWORD)1,
  762. (DWORD)1, (DWORD)1,
  763. (LPCMYK)lpCMYKBuf, lpCBuf, lpMBuf, lpYBuf, lpKBuf);
  764. /* } else if (lpN403DizInf->PrnMod == N403_MOD_300B2) {
  765. dizLin = N403Diz004(lpN403DizInf,
  766. (DWORD)XSize,
  767. (DWORD)XPos, (DWORD)YPos,
  768. (DWORD)0, (DWORD)0,
  769. (DWORD)1, (DWORD)1,
  770. (DWORD)1, (DWORD)1,
  771. (LPCMYK)lpCMYKBuf, lpCBuf, lpMBuf, lpYBuf, lpKBuf);
  772. */ } else if (lpN403DizInf->PrnMod == N403_MOD_600B2) {
  773. // Addition of a condition (XX_DITHERING_OFF) 2002.3.28 >>>
  774. // if (lpN403DizInf->ColMon == N403_MON || Diz == XX_DITHERING_ON) {
  775. if (lpN403DizInf->ColMon == N403_MON || Diz == XX_DITHERING_ON || Diz == XX_DITHERING_OFF) {
  776. // Addition of a condition (XX_DITHERING_OFF) 2002.3.28 <<<
  777. dizLin = N403Diz004(lpN403DizInf,
  778. (DWORD)XSize,
  779. (DWORD)XPos, (DWORD)YPos,
  780. (DWORD)0, (DWORD)0,
  781. (DWORD)1, (DWORD)1,
  782. (DWORD)1, (DWORD)1,
  783. (LPCMYK)lpCMYKBuf, lpCBuf, lpMBuf, lpYBuf, lpKBuf);
  784. } else if (lpN403DizInf->ColMon == N403_MON || Diz == XX_DITHERING_DET) {
  785. dizLin = N403DizSml(lpN403DizInf,
  786. (DWORD)XSize,
  787. (DWORD)XPos, (DWORD)YPos,
  788. (DWORD)0, (DWORD)0,
  789. (DWORD)1, (DWORD)1,
  790. (DWORD)1, (DWORD)1,
  791. (LPCMYK)lpCMYKBuf, lpCBuf, lpMBuf, lpYBuf, lpKBuf);
  792. }
  793. } else {
  794. dizLin = N403Diz016(lpN403DizInf,
  795. (DWORD)XSize,
  796. (DWORD)XPos, (DWORD)YPos,
  797. (DWORD)0, (DWORD)0,
  798. (DWORD)1, (DWORD)1,
  799. (DWORD)1, (DWORD)1,
  800. (LPCMYK)lpCMYKBuf, lpCBuf, lpMBuf, lpYBuf, lpKBuf);
  801. }
  802. }
  803. return (WORD)dizLin;
  804. }
  805. //===================================================================================================
  806. // Spool bitmap data
  807. //===================================================================================================
  808. void BmpPrint(
  809. PDEVOBJ pdevobj, // Pointer to pdevobj structure
  810. LPBMPBIF lpBmpBuf, // Pointer to bitmap buffer structure
  811. POINT Pos, // Start position for spooling
  812. WORD Width, // Width(dot)
  813. WORD Height, // Height(dot)
  814. WORD WidthByte // Width(byte)
  815. )
  816. {
  817. DRWBMP drwBmp; // For Spooling bitmap data structure
  818. DRWBMPCMYK drwBmpCMYK; // For Spooling CMYK bitmap data structure
  819. WORD colCnt;
  820. PMYPDEV pOEM = (PMYPDEV)pdevobj->pdevOEM;
  821. static const CMYK colTbl[4] = { // CMYK table
  822. { 0, 0, 0, 255}, // Black
  823. { 0, 0, 255, 0}, // Yellow
  824. { 0, 255, 0, 0}, // Magenta
  825. {255, 0, 0, 0} // Cyan
  826. };
  827. static const WORD plnTbl[4] = { // Plane table
  828. PLN_BLACK,
  829. PLN_YELLOW,
  830. PLN_MGENTA,
  831. PLN_CYAN
  832. };
  833. static const WORD frmTbl[4] = {0, 3, 2, 1}; // Frame table(For N4-612)
  834. // Not N4-612 printer?
  835. if (pOEM->Printer != PRN_N403) {
  836. drwBmp.Style = lpBmpBuf->Style;
  837. drwBmp.DrawPos = Pos;
  838. drwBmp.Diz = lpBmpBuf->Diz;
  839. drwBmp.Width = Width;
  840. drwBmp.Height = Height;
  841. drwBmp.WidthByte = WidthByte;
  842. // Color?
  843. if (pOEM->iColor == XX_COLOR_SINGLE || pOEM->iColor == XX_COLOR_MANY) {
  844. for (colCnt = 0; colCnt < 4; colCnt++) { // Setting value for spooling bitmap data
  845. drwBmp.Plane = plnTbl[colCnt]; // For each plane
  846. drwBmp.Color = colTbl[colCnt];
  847. drwBmp.lpBit = lpBmpBuf->Drv.Bit.Pnt[colCnt]/* + WidthByte*/;
  848. PrnBitmap(pdevobj, &drwBmp); // Spool bitmap data
  849. }
  850. } else { // Mono
  851. // Setting value for spooling bitmap data
  852. drwBmp.Color = colTbl[0];
  853. drwBmp.lpBit = lpBmpBuf->Drv.Bit.Pnt[0]/* + WidthByte*/;
  854. PrnBitmap(pdevobj, &drwBmp); // Spool bitmap data
  855. }
  856. } else { // N4-612 printer?
  857. drwBmpCMYK.Style = lpBmpBuf->Style;
  858. drwBmpCMYK.DataBit = lpBmpBuf->DatBit;
  859. drwBmpCMYK.DrawPos = Pos;
  860. drwBmpCMYK.Width = Width;
  861. drwBmpCMYK.Height = Height;
  862. drwBmpCMYK.WidthByte = WidthByte;
  863. // Color?
  864. if (pOEM->iColor == XX_COLOR_SINGLE || pOEM->iColor == XX_COLOR_MANY) {
  865. for (colCnt = 0; colCnt < 4; colCnt++) { // Setting value for spooling bitmap data
  866. // For each plane
  867. drwBmpCMYK.Plane = PLN_ALL; // All Plane is OK
  868. drwBmpCMYK.Frame = frmTbl[colCnt];
  869. drwBmpCMYK.lpBit = lpBmpBuf->Drv.Bit.Pnt[colCnt]/* + WidthByte*/;
  870. PrnBitmapCMYK(pdevobj, &drwBmpCMYK); // Spool bitmap data
  871. }
  872. } else { // Mono
  873. // Setting value for spooling bitmap data
  874. drwBmpCMYK.Plane = plnTbl[0];
  875. drwBmpCMYK.Frame = frmTbl[0];
  876. drwBmpCMYK.lpBit = lpBmpBuf->Drv.Bit.Pnt[0]/* + WidthByte*/;
  877. PrnBitmapCMYK(pdevobj, &drwBmpCMYK); // Spool bitmap data
  878. }
  879. }
  880. return;
  881. }
  882. //===================================================================================================
  883. // Allocate dither table(N4 printer)
  884. //===================================================================================================
  885. BOOL DizTblSetN4(
  886. PDEVOBJ pdevobj, // Pointer to pdevobj structure
  887. WORD Diz // Type of dither
  888. )
  889. {
  890. DWORD dizNum;
  891. LPN4DIZINF lpN4DizInf;
  892. PMYPDEV pOEM = (PMYPDEV)pdevobj->pdevOEM;
  893. lpN4DizInf = pOEM->Col.N4.lpDizInf;
  894. dizNum = DizNumTbl[Diz];
  895. lpN4DizInf->Diz.Num = dizNum;
  896. if ((lpN4DizInf->Diz.Tbl[dizNum][0] = MemAllocZ(N4_DIZSIZ_CM)) == NULL) {
  897. return 0;
  898. }
  899. if ((lpN4DizInf->Diz.Tbl[dizNum][1] = MemAllocZ(N4_DIZSIZ_CM)) == NULL) {
  900. return 0;
  901. }
  902. if ((lpN4DizInf->Diz.Tbl[dizNum][2] = MemAllocZ(N4_DIZSIZ_YK)) == NULL) {
  903. return 0;
  904. }
  905. if ((lpN4DizInf->Diz.Tbl[dizNum][3] = MemAllocZ(N4_DIZSIZ_YK)) == NULL) {
  906. return 0;
  907. }
  908. N4DizPtnMak(lpN4DizInf, dizNum, dizNum); // Make dither pattern
  909. return TRUE;
  910. }
  911. //===================================================================================================
  912. // Allocate dither table(N4-612 printer)
  913. //===================================================================================================
  914. BOOL DizTblSetN403(
  915. PDEVOBJ pdevobj, // Pointer to pdevobj structure
  916. WORD Diz // Type of dither
  917. )
  918. {
  919. DWORD dizNum;
  920. DWORD alcSiz;
  921. WORD alcCnt;
  922. WORD alcTbl;
  923. LPN403DIZINF lpN403DizInf;
  924. PMYPDEV pOEM = (PMYPDEV)pdevobj->pdevOEM;
  925. lpN403DizInf = pOEM->Col.N403.lpDizInf;
  926. dizNum = DizNumTbl[Diz];
  927. lpN403DizInf->Diz.Num = dizNum;
  928. if (lpN403DizInf->PrnMod == N403_MOD_300B1 || lpN403DizInf->PrnMod == N403_MOD_600B1) {
  929. alcSiz = N403_DIZSIZ_B1;
  930. } else if (/*lpN403DizInf->PrnMod == N403_MOD_300B2 ||*/ lpN403DizInf->PrnMod == N403_MOD_600B2) {
  931. alcSiz = N403_DIZSIZ_B2;
  932. } else {
  933. alcSiz = N403_DIZSIZ_B4;
  934. }
  935. if (lpN403DizInf->ColMon == N403_COL && lpN403DizInf->PrnMod == N403_MOD_600B2 && Diz == XX_DITHERING_DET) {
  936. alcTbl = 1;
  937. } else {
  938. alcTbl = 4;
  939. }
  940. for (alcCnt = 0; alcCnt < alcTbl; alcCnt++) {
  941. if ((lpN403DizInf->Diz.Tbl[dizNum][alcCnt] = MemAllocZ(alcSiz)) == NULL) {
  942. ERR(("DizTbl ALLOC ERROR!!\n"));
  943. return 0;
  944. }
  945. }
  946. if (lpN403DizInf->ColMon == N403_COL && lpN403DizInf->PrnMod == N403_MOD_600B2) {
  947. alcSiz = N403_ENTDIZSIZ_B2;
  948. for (alcCnt = 0; alcCnt < 4; alcCnt++) {
  949. if ((lpN403DizInf->EntDiz.Tbl[alcCnt] = MemAllocZ(alcSiz)) == NULL) {
  950. ERR(("EntDizTbl ALLOC ERROR!!\n"));
  951. return 0;
  952. }
  953. }
  954. }
  955. N403DizPtnMak(lpN403DizInf, dizNum, dizNum); // Make dither pattern
  956. return TRUE;
  957. }
  958. //===================================================================================================
  959. // Load LUT file(For N4 printer)
  960. //===================================================================================================
  961. BOOL LutFileLoadN4(
  962. PDEVOBJ pdevobj, // Pointer to pdevobj structure
  963. WORD Mch, // Type of color match
  964. WORD Diz, // Type of dither
  965. WORD Speed // speed?
  966. )
  967. {
  968. HANDLE fp_Lut;
  969. OFSTRUCT opeBuf;
  970. WORD setCnt;
  971. LPBYTE lpDst;
  972. LPN4DIZINF lpN4DizInf;
  973. DWORD nSize;
  974. WCHAR LutName[MAX_PATH], *pTemp;
  975. int i;
  976. BOOL bRet;
  977. DWORD dwRet;
  978. PMYPDEV pOEM = (PMYPDEV)pdevobj->pdevOEM;
  979. nSize = GetModuleFileName(pdevobj->hOEM, LutName, MAX_PATH);
  980. nSize -= (sizeof (CSN46RESDLL) / sizeof (WCHAR) - 1);
  981. // Choice of LUT file
  982. pTemp = N4LUT000; // Default value.
  983. if (Mch == XX_COLORMATCH_NORMAL) {
  984. if (Diz != XX_DITHERING_GOSA) {
  985. pTemp = N4LUT000;
  986. } else {
  987. pTemp = N4LUT003;
  988. }
  989. } else if (Mch == XX_COLORMATCH_VIVCOL) {
  990. if (Diz != XX_DITHERING_GOSA) {
  991. pTemp = N4LUT001;
  992. } else {
  993. pTemp = N4LUT004;
  994. }
  995. } else if (Mch == XX_COLORMATCH_NATCOL) {
  996. if (Diz != XX_DITHERING_GOSA) {
  997. pTemp = N4LUT002;
  998. } else {
  999. pTemp = N4LUT005;
  1000. }
  1001. }
  1002. // Replacement of strsafe-api 2002.3.6 >>>
  1003. // lstrcpy(&LutName[nSize], pTemp);
  1004. if (S_OK != StringCchCopy(&LutName[nSize], MAX_PATH - nSize, pTemp))
  1005. return 0;
  1006. // Replacement of strsafe-api 2002.3.6 <<<
  1007. CM_VERBOSE(("n403 Newbuf--> %ws\n", LutName));
  1008. // Open LUT file
  1009. if (INVALID_HANDLE_VALUE == (fp_Lut = CreateFile(LutName,
  1010. GENERIC_READ, FILE_SHARE_READ, NULL,
  1011. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL))) {
  1012. ERR(("Error opening LUT file %ws (%d)\n",
  1013. LutName, GetLastError()));
  1014. return 0;
  1015. }
  1016. lpN4DizInf = pOEM->Col.N4.lpDizInf;
  1017. if ((lpN4DizInf->Lut.Tbl = MemAllocZ((DWORD)N4_LUTTBLSIZ)) == NULL) {
  1018. CloseHandle(fp_Lut); /* 441434 */
  1019. return 0;
  1020. }
  1021. lpDst = (LPBYTE)(lpN4DizInf->Lut.Tbl);
  1022. // Load LUT data
  1023. for(setCnt = 0 ; setCnt < (N4_GLDNUM / 8) ; setCnt++) {
  1024. if (FALSE == ReadFile(fp_Lut,
  1025. &lpDst[(DWORD)setCnt * 8L * N4_GLDNUM * N4_GLDNUM * 4L],
  1026. (8L * N4_GLDNUM * N4_GLDNUM * 4L), &dwRet, NULL)
  1027. || 0 == dwRet) {
  1028. ERR(("Error reading LUT file %ws (%d)\n",
  1029. LutName, GetLastError()));
  1030. // Abort
  1031. CloseHandle(fp_Lut);
  1032. return FALSE;
  1033. }
  1034. }
  1035. // Close LUT file
  1036. if (FALSE == CloseHandle(fp_Lut)) {
  1037. ERR(("Error closing LUT file %ws (%d)\n",
  1038. LutName, GetLastError()));
  1039. }
  1040. if (Speed == No) {
  1041. if ((lpN4DizInf->Lut.CchRgb = MemAllocZ(N4_CCHRGBSIZ)) == NULL) {
  1042. return 0;
  1043. }
  1044. if ((lpN4DizInf->Lut.CchCmy = MemAllocZ(N4_CCHCMYSIZ)) == NULL) {
  1045. return 0;
  1046. }
  1047. memset(lpN4DizInf->Lut.CchRgb, 0xff, N4_CCHRGBSIZ);
  1048. memset(lpN4DizInf->Lut.CchCmy, 0x00, N4_CCHCMYSIZ);
  1049. }
  1050. return TRUE;
  1051. }
  1052. //===================================================================================================
  1053. // Load LUT file(For N4-612 printer)
  1054. //===================================================================================================
  1055. BOOL LutFileLoadN403(
  1056. PDEVOBJ pdevobj, // Pointer to pdevobj structure
  1057. WORD Mch, // Type of color matching
  1058. WORD Speed
  1059. )
  1060. {
  1061. HANDLE fp_Lut;
  1062. OFSTRUCT opeBuf;
  1063. WORD setCnt;
  1064. LPBYTE lpDst;
  1065. LPN403DIZINF lpN403DizInf;
  1066. DWORD nSize;
  1067. WCHAR LutName[MAX_PATH], *pTemp;
  1068. int i;
  1069. BOOL bRet;
  1070. DWORD dwRet;
  1071. PMYPDEV pOEM = (PMYPDEV)pdevobj->pdevOEM;
  1072. nSize = GetModuleFileName(pdevobj->hOEM, LutName, MAX_PATH);
  1073. nSize -= (sizeof (CSN46RESDLL) / sizeof (WCHAR) - 1);
  1074. // Choice of LUT file
  1075. if (Mch == XX_COLORMATCH_IRO) {
  1076. pTemp = N403LUTY;
  1077. } else {
  1078. pTemp = N403LUTX;
  1079. }
  1080. // Replacement of strsafe-api 2002.3.6 >>>
  1081. // lstrcpy(&LutName[nSize], pTemp);
  1082. if (S_OK != StringCchCopy(&LutName[nSize], MAX_PATH - nSize, pTemp))
  1083. return 0;
  1084. // Replacement of strsafe-api 2002.3.6 <<<
  1085. CM_VERBOSE(("n403 Newbuf--> %ws\n", LutName));
  1086. // Open LUT file
  1087. if (INVALID_HANDLE_VALUE == (fp_Lut = CreateFile( LutName,
  1088. GENERIC_READ, FILE_SHARE_READ, NULL,
  1089. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL))) {
  1090. ERR(("Error opening LUT file %ws (%d)\n",
  1091. LutName, GetLastError()));
  1092. return 0;
  1093. }
  1094. lpN403DizInf = pOEM->Col.N403.lpDizInf;
  1095. if ((lpN403DizInf->Lut.Tbl = MemAllocZ((DWORD)N403_LUTTBLSIZ))== NULL) {
  1096. CloseHandle(fp_Lut); /* 441433 */
  1097. return 0;
  1098. }
  1099. lpDst = (LPBYTE)(lpN403DizInf->Lut.Tbl);
  1100. // Load LUT data
  1101. for(setCnt = 0 ; setCnt < (N403_GLDNUM / 8) ; setCnt++) {
  1102. if (FALSE == ReadFile(fp_Lut,
  1103. &lpDst[(DWORD)setCnt * 8L * N403_GLDNUM * N403_GLDNUM * 4L],
  1104. (8L * N403_GLDNUM * N403_GLDNUM * 4L), &dwRet, NULL)
  1105. || 0 == dwRet) {
  1106. ERR(("Error reading LUT file %ws (%d)\n",
  1107. LutName, GetLastError()));
  1108. // Abort
  1109. CloseHandle(fp_Lut);
  1110. return FALSE;
  1111. }
  1112. }
  1113. // Close LUT file
  1114. if (FALSE == CloseHandle(fp_Lut)) {
  1115. ERR(("Error closing LUT file %ws (%d)\n",
  1116. LutName, GetLastError()));
  1117. }
  1118. if (Speed == No) {
  1119. if ((lpN403DizInf->Lut.CchRgb = MemAllocZ(N403_CCHRGBSIZ)) == NULL) {
  1120. return 0;
  1121. }
  1122. if ((lpN403DizInf->Lut.CchCmy = MemAllocZ(N403_CCHCMYSIZ)) == NULL) {
  1123. return 0;
  1124. }
  1125. memset(lpN403DizInf->Lut.CchRgb, 0xff, N403_CCHRGBSIZ);
  1126. memset(lpN403DizInf->Lut.CchCmy, 0x00, N403_CCHCMYSIZ);
  1127. }
  1128. return TRUE;
  1129. }
  1130. //===================================================================================================
  1131. // Allocate toner density table(For N4 printer)
  1132. //===================================================================================================
  1133. BOOL TnrTblSetN4(
  1134. PDEVOBJ pdevobj, // Pointer to pdevobj structure
  1135. SHORT Tnr // Toner density(-30~30)
  1136. )
  1137. {
  1138. LPN4DIZINF lpN4DizInf;
  1139. PMYPDEV pOEM = (PMYPDEV)pdevobj->pdevOEM;
  1140. lpN4DizInf = pOEM->Col.N4.lpDizInf;
  1141. if ((lpN4DizInf->Tnr.Tbl = MemAllocZ(N4_TNRTBLSIZ)) == NULL) {
  1142. return 0;
  1143. }
  1144. N4TnrTblMak(lpN4DizInf, (LONG)Tnr);
  1145. return TRUE;
  1146. }
  1147. //===================================================================================================
  1148. // Allocate toner density table(For N4-612 printer)
  1149. //===================================================================================================
  1150. BOOL TnrTblSetN403(
  1151. PDEVOBJ pdevobj, // Pointer to pdevobj structure
  1152. SHORT Tnr // Toner density(-30~30)
  1153. )
  1154. {
  1155. LPN403DIZINF lpN403DizInf;
  1156. PMYPDEV pOEM = (PMYPDEV)pdevobj->pdevOEM;
  1157. lpN403DizInf = pOEM->Col.N403.lpDizInf;
  1158. if ((lpN403DizInf->Tnr.Tbl = MemAllocZ(N403_TNRTBLSIZ)) == NULL) {
  1159. return 0;
  1160. }
  1161. N403TnrTblMak(lpN403DizInf, (LONG)Tnr);
  1162. return TRUE;
  1163. }
  1164. //===================================================================================================
  1165. // Convert 1 line RGB bitmap data into 24bit (for 1pixel) RGB bitmap data
  1166. //===================================================================================================
  1167. void BmpRGBCnv(
  1168. LPRGB lpRGB, // Pointer to destination bitmap data
  1169. LPBYTE lpSrc, // Pointer to source bitmap data
  1170. WORD SrcBit, // Pixel of source bitmap data
  1171. WORD SrcX, // X coordinates of source bitmap data
  1172. WORD SrcXSiz, // X size of source bitmap data
  1173. LPRGBQUAD lpPlt // Color palette table of source bitmap data(1/4/8pixel)
  1174. )
  1175. {
  1176. WORD setCnt;
  1177. BYTE colNum;
  1178. LPWORD lpWSrc;
  1179. switch (SrcBit) {
  1180. case 1: // 1 bit
  1181. for (setCnt = 0; setCnt < SrcXSiz; setCnt++, SrcX++) {
  1182. // Foreground color?
  1183. if (!(lpSrc[SrcX / 8] & BitTbl[SrcX & 0x0007])) {
  1184. lpRGB[setCnt].Blue = lpPlt[0].rgbBlue;
  1185. lpRGB[setCnt].Green = lpPlt[0].rgbGreen;
  1186. lpRGB[setCnt].Red = lpPlt[0].rgbRed;
  1187. } else {
  1188. lpRGB[setCnt].Blue = lpPlt[1].rgbBlue;
  1189. lpRGB[setCnt].Green = lpPlt[1].rgbGreen;
  1190. lpRGB[setCnt].Red = lpPlt[1].rgbRed;
  1191. }
  1192. }
  1193. break;
  1194. case 4: // 4bit
  1195. for (setCnt = 0; setCnt < SrcXSiz; setCnt++, SrcX++) {
  1196. if (!(SrcX & 0x0001)) { // A even number coordinates?
  1197. colNum = lpSrc[SrcX / 2] / 16;
  1198. } else {
  1199. colNum = lpSrc[SrcX / 2] % 16;
  1200. }
  1201. lpRGB[setCnt].Blue = lpPlt[colNum].rgbBlue;
  1202. lpRGB[setCnt].Green = lpPlt[colNum].rgbGreen;
  1203. lpRGB[setCnt].Red = lpPlt[colNum].rgbRed;
  1204. }
  1205. break;
  1206. case 8: // 8bit
  1207. for (setCnt = 0; setCnt < SrcXSiz; setCnt++, SrcX++) {
  1208. colNum = lpSrc[SrcX];
  1209. lpRGB[setCnt].Blue = lpPlt[colNum].rgbBlue;
  1210. lpRGB[setCnt].Green = lpPlt[colNum].rgbGreen;
  1211. lpRGB[setCnt].Red = lpPlt[colNum].rgbRed;
  1212. }
  1213. break;
  1214. case 16: // 16bit
  1215. lpWSrc = (LPWORD)lpSrc + SrcX;
  1216. for (setCnt = 0; setCnt < SrcXSiz; setCnt++, lpWSrc++) {
  1217. lpRGB[setCnt].Blue = (BYTE)((*lpWSrc & 0x001f) << 3);
  1218. lpRGB[setCnt].Green = (BYTE)((*lpWSrc & 0x03e0) >> 2);
  1219. lpRGB[setCnt].Red = (BYTE)((*lpWSrc / 0x0400) << 3);
  1220. }
  1221. break;
  1222. case 24: // 24 bit
  1223. lpSrc += SrcX * 3;
  1224. for (setCnt = 0; setCnt < SrcXSiz; setCnt++, lpSrc += 3) {
  1225. lpRGB[setCnt].Red = lpSrc[0];
  1226. lpRGB[setCnt].Green = lpSrc[1];
  1227. lpRGB[setCnt].Blue = lpSrc[2];
  1228. // lpRGB[setCnt].Blue = lpSrc[0];
  1229. // lpRGB[setCnt].Green = lpSrc[1];
  1230. // lpRGB[setCnt].Red = lpSrc[2];
  1231. }
  1232. // memcpy(lpRGB, lpSrc, SrcXSiz * 3);
  1233. break;
  1234. case 32: // 32bit
  1235. lpSrc += SrcX * 4;
  1236. for (setCnt = 0; setCnt < SrcXSiz; setCnt++, lpSrc += 4) {
  1237. lpRGB[setCnt].Blue = lpSrc[0];
  1238. lpRGB[setCnt].Green = lpSrc[1];
  1239. lpRGB[setCnt].Red = lpSrc[2];
  1240. }
  1241. break;
  1242. }
  1243. return;
  1244. }
  1245. // End of File