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.

1648 lines
77 KiB

  1. //***************************************************************************************************
  2. // COLMATCH.C
  3. //
  4. // Functions of color matching
  5. //---------------------------------------------------------------------------------------------------
  6. // copyright(C) 1997-2000 CASIO COMPUTER CO.,LTD. / CASIO ELECTRONICS MANUFACTURING CO.,LTD.
  7. //***************************************************************************************************
  8. #include "PDEV.H"
  9. #include "PRNCTL.H"
  10. #include "strsafe.h" // Security-Code 2002.3.6
  11. //---------------------------------------------------------------------------------------------------
  12. // Byte/Bit table
  13. //---------------------------------------------------------------------------------------------------
  14. static const BYTE BitTbl[8] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
  15. //---------------------------------------------------------------------------------------------------
  16. // Define LUT file name
  17. //---------------------------------------------------------------------------------------------------
  18. #define N501LUTR L"CPN5RGB.LT3" // For N5-XX1 printer
  19. //---------------------------------------------------------------------------------------------------
  20. // Define Dither file name
  21. //---------------------------------------------------------------------------------------------------
  22. #define N501DIZ L"CPN5NML.DIZ" // For N5-XX1 printer
  23. //---------------------------------------------------------------------------------------------------
  24. // Define DLL name
  25. //---------------------------------------------------------------------------------------------------
  26. #define CSN5RESDLL L"CSN5RES.DLL" // For N5-XX1 printer
  27. //---------------------------------------------------------------------------------------------------
  28. // Define data
  29. //---------------------------------------------------------------------------------------------------
  30. #define DPI300 300
  31. #define DPI600 600
  32. static BYTE ORG_MODE_IN[] = "\x1Bz\xD0\x01";
  33. static BYTE ORG_MODE_OUT[] = "\x1Bz\x00\x01";
  34. static BYTE PALETTE_SELECT[] = "Cd,%d,%d*";
  35. static BYTE PLANE_RESET[] = "Da,0,0,0,0*";
  36. // Replacement of strsafe-api 2002.3.6 >>>
  37. //#ifdef wsprintf
  38. //#undef wsprintf
  39. //#endif // wsprintf
  40. //#define wsprintf sprintf
  41. // Replacement of strsafe-api 2002.3.6 <<<
  42. //***************************************************************************************************
  43. // Prototype declaration
  44. //***************************************************************************************************
  45. static BOOL BmpBufAlloc(PDEVOBJ, WORD, WORD, WORD, WORD, WORD, WORD, WORD, WORD, LPBMPBIF);
  46. static void BmpBufFree(LPBMPBIF);
  47. static void BmpBufClear(LPBMPBIF);
  48. static void BmpPrint(PDEVOBJ, LPBMPBIF, POINT, WORD, WORD, WORD);
  49. static void BmpRGBCnv(LPRGB, LPBYTE, WORD, WORD, WORD, LPRGBQUAD);
  50. static BOOL ColMchInfSet(PDEVOBJ);
  51. static BOOL DizInfSet(PDEVOBJ);
  52. static UINT GetDizPat(PDEVOBJ);
  53. static BOOL DizFileOpen(PDEVOBJ, LPDIZINF);
  54. static BOOL ColUcrTblMak(PDEVOBJ, LPCMYK);
  55. static BOOL ColGryTblMak(PDEVOBJ, LPCMYK);
  56. static BOOL ColLutMakGlbMon(PDEVOBJ);
  57. //***************************************************************************************************
  58. // Functions
  59. //***************************************************************************************************
  60. //===================================================================================================
  61. // Initialize the members of color-matching
  62. //===================================================================================================
  63. BOOL FAR PASCAL ColMatchInit(
  64. PDEVOBJ pdevobj // Pointer to PDEVOBJ structure
  65. )
  66. {
  67. LPBYTE lpColIF; // N5 Color Matching information
  68. LPRGBINF lpRGBInfImg; // RGB Color change information
  69. LPCMYKINF lpCMYKInfImg; // CMYK Color information
  70. UINT num001;
  71. SHORT KToner;
  72. DWORD allocSize;
  73. PMYPDEV pOEM = (PMYPDEV)pdevobj->pdevOEM;
  74. MY_VERBOSE(("ColMatchInit() Start *****\n"));
  75. pOEM->Col.Mch.Mode = pOEM->iColorMatching;
  76. pOEM->Col.Mch.Diz = pOEM->iDithering;
  77. pOEM->Col.Mch.Bright = 0; // 0 fixed
  78. pOEM->Col.Mch.Contrast = 0; // 0 fixed
  79. pOEM->Col.Mch.GamRed = 10; // Color balance(R) : 10 fixed
  80. pOEM->Col.Mch.GamGreen = 10; // Color balance(G) : 10 fixed
  81. pOEM->Col.Mch.GamBlue = 10; // Color balance(B) : 10 fixed
  82. pOEM->Col.Mch.Speed = pOEM->iBitFont;
  83. pOEM->Col.Mch.LutNum = 0; // LUT table number
  84. MY_VERBOSE(("CMINit ENT Tn=%d Col=%d Mod=%d DZ=%d Cyk=%d Sp=%d Prt=%d\n", pOEM->iTone, pOEM->iColor,
  85. pOEM->Col.Mch.Mode,pOEM->Col.Mch.Diz,pOEM->Col.Mch.CmyBlk,pOEM->Col.Mch.Speed,pOEM->Printer));
  86. if (pOEM->Printer == PRN_N5) { // N5 printer
  87. if ((lpColIF = MemAllocZ( // RGB Color change/Color Matching/Dither pattern Information
  88. (DWORD)((sizeof(RGBINF) + sizeof(CMYKINF) + sizeof(COLMCHINF) + sizeof(DIZINF))))) == NULL) {
  89. ERR(("Init Alloc ERROR!!\n"));
  90. return 0;
  91. }
  92. pOEM->Col.lpColIF = lpColIF; // RGB Color change/Color Matching/Dither pattern Information
  93. pOEM->Col.Mch.lpRGBInf = (LPRGBINF)lpColIF; lpColIF += sizeof(RGBINF);
  94. pOEM->Col.Mch.lpCMYKInf = (LPCMYKINF)lpColIF; lpColIF += sizeof(CMYKINF);
  95. pOEM->Col.Mch.lpColMch = (LPCOLMCHINF)lpColIF; lpColIF += sizeof(COLMCHINF);
  96. pOEM->Col.Mch.lpDizInf = (LPDIZINF)lpColIF; lpColIF += sizeof(DIZINF);
  97. MY_VERBOSE(("ColMatchInit() MemAllocZ(lpColIF)\n"));
  98. pOEM->Col.wReso = (pOEM->iResolution == XX_RES_300DPI) ? DPI300 : DPI600;
  99. MY_VERBOSE(("ColMatchInit() pOEM->Col.wReso[%d] \n", pOEM->Col.wReso));
  100. if (pOEM->iColor == XX_COLOR_SINGLE
  101. || pOEM->iColor == XX_COLOR_MANY
  102. || pOEM->iColor == XX_COLOR_MANY2) { // Color?
  103. pOEM->Col.ColMon = CMMCOL; // Color
  104. } else {
  105. pOEM->Col.ColMon = CMMMON; // Monochrome
  106. }
  107. MY_VERBOSE(("ColMatchInit() pOEM->Col.ColMon[%d] \n", pOEM->Col.ColMon));
  108. if (pOEM->Col.ColMon == CMMCOL) { // Color?
  109. if (pOEM->Col.wReso == DPI300) { // 300DPI?
  110. if (pOEM->iColor == XX_COLOR_SINGLE) {
  111. pOEM->Col.Dot = XX_TONE_2;
  112. } else {
  113. pOEM->Col.Dot = XX_TONE_16;
  114. }
  115. } else { // 600DPI?
  116. if (pOEM->iColor == XX_COLOR_SINGLE) {
  117. pOEM->Col.Dot = XX_TONE_2;
  118. } else if (pOEM->iColor == XX_COLOR_MANY) {
  119. pOEM->Col.Dot = XX_TONE_4;
  120. } else {
  121. pOEM->Col.Dot = XX_TONE_16;
  122. }
  123. }
  124. MY_VERBOSE(("ColMatchInit() Col.Dot[%d] \n", pOEM->Col.Dot));
  125. if (pOEM->Col.wReso == DPI300) { // 300DPI?
  126. if (pOEM->Col.Dot == XX_TONE_2) { // 2value?
  127. CM_VERBOSE(("N5_MOD_300_TONE_2\n"));
  128. pOEM->Col.DatBit = 1; pOEM->Col.BytDot = 8;
  129. } else { // 16value
  130. CM_VERBOSE(("N5_MOD_300_TONE_16\n"));
  131. pOEM->Col.DatBit = 4; pOEM->Col.BytDot = 2;
  132. }
  133. } else { // 600DPI
  134. if (pOEM->Col.Dot == XX_TONE_2) { // 2value?
  135. CM_VERBOSE(("N5_MOD_600_TONE_2\n"));
  136. pOEM->Col.DatBit = 1; pOEM->Col.BytDot = 8;
  137. } else if (pOEM->Col.Dot == XX_TONE_4) { // 4value?
  138. CM_VERBOSE(("N5_MOD_600_TONE_4\n"));
  139. pOEM->Col.DatBit = 2; pOEM->Col.BytDot = 4;
  140. } else { // 16value?
  141. CM_VERBOSE(("N5_MOD_600_TONE_16\n"));
  142. pOEM->Col.DatBit = 4; pOEM->Col.BytDot = 2;
  143. }
  144. }
  145. }
  146. MY_VERBOSE(("ColMatchInit() DatBit[%d] BytDot[%d]\n", pOEM->Col.DatBit, pOEM->Col.BytDot));
  147. // Color Matching setting
  148. pOEM->Col.Mch.CmyBlk = Yes; // Black replacement
  149. pOEM->Col.Mch.GryKToner = No; // Gray black toner print
  150. pOEM->Col.Mch.Ucr = UCRNOO; // UCR No
  151. pOEM->Col.Mch.KToner = pOEM->iCmyBlack; // Black toner usage
  152. switch (pOEM->iCmyBlack) {
  153. case XX_CMYBLACK_GRYBLK:
  154. pOEM->Col.Mch.CmyBlk = Yes;
  155. pOEM->Col.Mch.GryKToner = Yes;
  156. pOEM->Col.Mch.Ucr = UCR001; //+CASIO 2001/02/15
  157. break;
  158. case XX_CMYBLACK_BLKTYPE1:
  159. pOEM->Col.Mch.Ucr = UCR001;
  160. pOEM->Col.Mch.CmyBlk = Yes;
  161. pOEM->Col.Mch.GryKToner = No;
  162. break;
  163. case XX_CMYBLACK_BLKTYPE2:
  164. pOEM->Col.Mch.Ucr = UCR002;
  165. pOEM->Col.Mch.CmyBlk = Yes;
  166. pOEM->Col.Mch.GryKToner = No;
  167. break;
  168. case XX_CMYBLACK_BLACK:
  169. pOEM->Col.Mch.CmyBlk = Yes;
  170. pOEM->Col.Mch.GryKToner = No;
  171. break;
  172. case XX_CMYBLACK_TYPE1:
  173. pOEM->Col.Mch.Ucr = UCR001;
  174. pOEM->Col.Mch.CmyBlk = No;
  175. break;
  176. case XX_CMYBLACK_TYPE2:
  177. pOEM->Col.Mch.Ucr = UCR002;
  178. pOEM->Col.Mch.CmyBlk = No;
  179. break;
  180. case XX_CMYBLACK_NONE:
  181. pOEM->Col.Mch.CmyBlk = No;
  182. break;
  183. default:
  184. break;
  185. }
  186. MY_VERBOSE(("ColMatchInit() Mch.CmyBlk[%d] Mch.KToner[%d] Mch.Ucr[%d] \n",
  187. pOEM->Col.Mch.CmyBlk, pOEM->Col.Mch.KToner, pOEM->Col.Mch.Ucr));
  188. pOEM->Col.Mch.PColor = No; // Primary color processing ?
  189. pOEM->Col.Mch.Tnr = 0; // Depth of color(Tonor)
  190. pOEM->Col.Mch.SubDef = Yes; // Not change setting of color balance, bright and contrast ?
  191. pOEM->Col.Mch.LutMakGlb = No; // Global LUT make ?
  192. pOEM->Col.Mch.CchMch = (UINT)-1; // Cache initialize
  193. pOEM->Col.Mch.CchCnv = (UINT)-1;
  194. pOEM->Col.Mch.CchRGB.Red = 255;
  195. pOEM->Col.Mch.CchRGB.Grn = 255;
  196. pOEM->Col.Mch.CchRGB.Blu = 255;
  197. lpRGBInfImg = pOEM->Col.Mch.lpRGBInf; // RGB Color change information
  198. lpRGBInfImg->Lgt = 0; // 0 fixed Brightness adjustment
  199. lpRGBInfImg->Con = 0; // 0 fixed Contrast adjustment
  200. lpRGBInfImg->Crm = 0; // 0 fixed Chroma adjustment
  201. lpRGBInfImg->Gmr = 10; // 10 fixed Color balance(Gamma revision)(Red)
  202. lpRGBInfImg->Gmg = 10; // 10 fixed Color balance(Gamma revision)(Green)
  203. lpRGBInfImg->Gmb = 10; // 10 fixed Color balance(Gamma revision)(Blue)
  204. lpRGBInfImg->Dns = NULL; // NULL fixed Toner density table
  205. lpRGBInfImg->DnsRgb = 0; // 0 fixed RGB density
  206. lpCMYKInfImg = pOEM->Col.Mch.lpCMYKInf; // CMYK Color change information
  207. if (pOEM->Col.Mch.Mode == XX_COLORMATCH_VIV) { // Vivid?
  208. lpCMYKInfImg->Viv = 20;
  209. }
  210. lpCMYKInfImg->Dns = NULL; // NULL fixed Toner density table
  211. lpCMYKInfImg->DnsCyn = 0; // 0 fixed Depth of color(Cyan)
  212. lpCMYKInfImg->DnsMgt = 0; // 0 fixed Depth of color(Magenta)
  213. lpCMYKInfImg->DnsYel = 0; // 0 fixed Depth of color(Yellow)
  214. lpCMYKInfImg->DnsBla = 0; // 0 fixed Depth of color(Black)
  215. MY_VERBOSE(("ColMatchInit() ColMchInfSet()\n"));
  216. if (ColMchInfSet(pdevobj) == FALSE) { // Color Matching information setting
  217. return 0;
  218. }
  219. MY_VERBOSE(("ColMatchInit() DizInfSet()\n"));
  220. if (DizInfSet(pdevobj) == FALSE) { // Dither pattern information setting
  221. return 0;
  222. }
  223. // RGB convert area (*Temp area)
  224. if ((pOEM->Col.lpTmpRGB = MemAlloc(sizeof(RGBS))) == NULL) {
  225. return 0;
  226. }
  227. // CMYK convert area (*Temp area)
  228. allocSize = (pOEM->iColor != XX_MONO) ? sizeof(CMYK) : 1;
  229. if ((pOEM->Col.lpTmpCMYK = MemAlloc(allocSize)) == NULL) {
  230. return 0;
  231. }
  232. // Draw information (*Temp area)
  233. if ((pOEM->Col.lpDrwInf = MemAlloc(sizeof(DRWINF))) == NULL) {
  234. return 0;
  235. }
  236. }
  237. return TRUE;
  238. }
  239. //===================================================================================================
  240. // Disable the color-matching
  241. //===================================================================================================
  242. BOOL FAR PASCAL ColMatchDisable(
  243. PDEVOBJ pdevobj // Pointer to PDEVOBJ structure
  244. )
  245. {
  246. UINT num001;
  247. PMYPDEV pOEM = (PMYPDEV)pdevobj->pdevOEM;
  248. MY_VERBOSE(("ColMatchDisable() Start\n"));
  249. if (pOEM->Col.lpLut032 != NULL) { // Free LUT32GRID
  250. MemFree(pOEM->Col.lpLut032);
  251. }
  252. if (pOEM->Col.lpUcr != NULL) { // Free UCR table
  253. MemFree(pOEM->Col.lpUcr);
  254. }
  255. if (pOEM->Col.lpLutMakGlb != NULL) { // Free LUTMAKGLG
  256. MemFree(pOEM->Col.lpLutMakGlb);
  257. }
  258. if (pOEM->Col.lpGryTbl != NULL) { // Free Gray transfer table
  259. MemFree(pOEM->Col.lpGryTbl);
  260. }
  261. if (pOEM->Col.lpColIF != NULL) { // Free RGB Color change/Color Matching/Dither pattern Information
  262. MemFree(pOEM->Col.lpColIF);
  263. }
  264. if (pOEM->Col.LutTbl != NULL) { // Free Look-up table buffer
  265. MemFree(pOEM->Col.LutTbl);
  266. }
  267. if (pOEM->Col.CchRGB != NULL) { // Free Cache table for RGB
  268. MemFree(pOEM->Col.CchRGB);
  269. }
  270. if (pOEM->Col.CchCMYK != NULL) { // Free Cache table for CMYK
  271. MemFree(pOEM->Col.CchCMYK);
  272. }
  273. for (num001 = 0; num001 < 4; num001++) { // Free Dither pattern table
  274. if (pOEM->Col.DizTbl[num001] != NULL) {
  275. MemFree(pOEM->Col.DizTbl[num001]);
  276. }
  277. }
  278. if (pOEM->Col.lpTmpRGB != NULL) { // Free RGB convert area (*Temp area)
  279. MemFree(pOEM->Col.lpTmpRGB);
  280. }
  281. if (pOEM->Col.lpTmpCMYK != NULL) { // Free CMYK convert area (*Temp area)
  282. MemFree(pOEM->Col.lpTmpCMYK);
  283. }
  284. if (pOEM->Col.lpDrwInf != NULL) { // Free Draw information (*Temp area)
  285. MemFree(pOEM->Col.lpDrwInf);
  286. }
  287. MY_VERBOSE(("ColMatchDisable() End\n"));
  288. return TRUE;
  289. }
  290. //===================================================================================================
  291. // DIB spools to the printer
  292. //===================================================================================================
  293. BOOL FAR PASCAL DIBtoPrn(
  294. PDEVOBJ pdevobj,
  295. PBYTE pSrcBmp,
  296. PBITMAPINFOHEADER pBitmapInfoHeader,
  297. PBYTE pColorTable,
  298. PIPPARAMS pIPParams)
  299. {
  300. BMPBIF bmpBuf; // BMPBIF structure
  301. POINT drwPos; // Start position for spooling
  302. WORD dstWByt; // X size of destination bitmap data
  303. LONG dstX; // X coordinates of destination bitmap data
  304. LONG dstY; // Y coordinates of destination bitmap data
  305. LONG dstYEnd; // The last Y coordinates(+1) of destination bitmap data
  306. WORD dstScn; // Number of destination bitmap data lines
  307. WORD srcY; // Y coordinates of source bitmap data
  308. LONG srcWByt; // Y size of source bitmap data
  309. MAG xMag; // X magnification
  310. MAG yMag; // Y magnification
  311. POINT pos; // Start position for drawing
  312. POINT off; // coordinates of source bitmap data
  313. WORD setCnt; // count
  314. LPCMYK lpCMYK; // CMYK temporary data buffer
  315. LPRGB lpRGB; // RGB temporary data buffer
  316. BYTE Cmd[64];
  317. WORD wlen;
  318. LPSTR pDestEnd; // 2002.3.6
  319. size_t szRemLen; // 2002.3.6
  320. PMYPDEV pOEM = (PMYPDEV)pdevobj->pdevOEM;
  321. MY_VERBOSE(("ImagePro DIBtoPrn() Start\n"));
  322. MY_VERBOSE(("ImagePro ENTRY Dx=%d Dy=%d SxSiz=%d SySiz=%d BC=%d Sz=%d\n",
  323. pIPParams->ptOffset.x, pIPParams->ptOffset.y,
  324. pBitmapInfoHeader->biWidth, pBitmapInfoHeader->biHeight, pBitmapInfoHeader->biBitCount,
  325. pIPParams->dwSize));
  326. // Initialization of
  327. // RGB buffer :(X size of source bitmap data) * 3
  328. // CMYK buffer :(X size of source bitmap data) * 4
  329. // CMYK bit buffer :((X size of source bitmap data) * (Magnification of X) + 7) / 8 * (Y size of source bitmap data) * (Magnification of Y))
  330. memset(&bmpBuf, 0x00, sizeof(BMPBIF));
  331. MY_VERBOSE(("ImagePro BmpBufAlloc()\n"));
  332. if (BmpBufAlloc(pdevobj, (WORD)pBitmapInfoHeader->biWidth, (WORD)pBitmapInfoHeader->biHeight, 0, 0, 1, 1, 1, 1, &bmpBuf) == FALSE) {
  333. ERR(("Alloc ERROR!!\n"));
  334. return FALSE;
  335. }
  336. bmpBuf.Diz = pOEM->iDithering;
  337. bmpBuf.Style = 0;
  338. bmpBuf.DatBit = pOEM->Col.DatBit;
  339. dstWByt = (WORD)((pBitmapInfoHeader->biWidth + pOEM->Col.BytDot - 1) / pOEM->Col.BytDot);
  340. srcWByt = (pBitmapInfoHeader->biWidth * pBitmapInfoHeader->biBitCount + 31L) / 32L * 4L;
  341. drwPos.x = dstX = pIPParams->ptOffset.x;
  342. dstY = pIPParams->ptOffset.y;
  343. srcY = 0;
  344. dstYEnd = pIPParams->ptOffset.y + pBitmapInfoHeader->biHeight;
  345. MY_VERBOSE(("ImagePro dstWByt[%d] srcWByt[%d]\n", dstWByt, srcWByt));
  346. MY_VERBOSE(("ImagePro dstX[%d] dstY[%d] dstYEnd[%d]\n", dstX, dstY, dstYEnd));
  347. // Convert DIB and spool to the printer
  348. for (;dstY < dstYEnd;) {
  349. BmpBufClear(&bmpBuf);
  350. drwPos.y = dstY;
  351. MY_VERBOSE(("ImagePro drwPos.x[%d] drwPos.y[%d] Drv.Bit.Lin[%d]\n", drwPos.x, drwPos.y, bmpBuf.Drv.Bit.Lin));
  352. for (dstScn = 0; dstY < dstYEnd && dstScn < bmpBuf.Drv.Bit.Lin; dstScn++, dstY++) {
  353. MY_VERBOSE(("ImagePro dstY[%d] dstScn[%d]\n", dstY, dstScn));
  354. MY_VERBOSE(("ImagePro BmpRGBCnv()\n"));
  355. // DUMP_VERBOSE(pSrcBmp,64);
  356. //----------------------------------------------------------------------------------------------------
  357. // Convert 1 line RGB bitmap data into 24bit (for 1pixel) RGB bitmap data
  358. BmpRGBCnv(bmpBuf.Drv.Rgb.Pnt,
  359. pSrcBmp,
  360. pBitmapInfoHeader->biBitCount,
  361. 0,
  362. (WORD)pBitmapInfoHeader->biWidth,
  363. (LPRGBQUAD)pColorTable);
  364. // Convert RGB=0 into RGB=1
  365. lpRGB = bmpBuf.Drv.Rgb.Pnt;
  366. if ((pOEM->iCmyBlack == XX_CMYBLACK_BLKTYPE1)
  367. || (pOEM->iCmyBlack == XX_CMYBLACK_BLKTYPE2)) {
  368. for (setCnt = 0; setCnt < pBitmapInfoHeader->biWidth; setCnt++) {
  369. if ((lpRGB[setCnt].Blu | lpRGB[setCnt].Grn |lpRGB[setCnt].Red) == 0) {
  370. lpRGB[setCnt].Blu = 1; lpRGB[setCnt].Grn = 1; lpRGB[setCnt].Red = 1;
  371. }
  372. }
  373. }
  374. // DUMP_VERBOSE((LPBYTE)bmpBuf.Drv.Rgb.Pnt,64);
  375. MY_VERBOSE(("ImagePro ColMatching()\n"));
  376. //----------------------------------------------------------------------------------------------------
  377. // Convert RGB into CMYK
  378. bmpBuf.Drv.Rgb.AllWhite = (WORD)ColMatching(
  379. pdevobj,
  380. No,
  381. No,
  382. (LPRGB)bmpBuf.Drv.Rgb.Pnt,
  383. (WORD)pBitmapInfoHeader->biWidth,
  384. (LPCMYK)bmpBuf.Drv.Cmyk.Pnt);
  385. // DUMP_VERBOSE((LPBYTE)bmpBuf.Drv.Cmyk.Pnt,64);
  386. lpCMYK = bmpBuf.Drv.Cmyk.Pnt;
  387. if (pOEM->iDithering == XX_DITH_NON) {
  388. for (setCnt = 0; setCnt < pBitmapInfoHeader->biWidth; setCnt++) {
  389. if (lpCMYK[setCnt].Cyn != 0) { lpCMYK[setCnt].Cyn = 255; }
  390. if (lpCMYK[setCnt].Mgt != 0) { lpCMYK[setCnt].Mgt = 255; }
  391. if (lpCMYK[setCnt].Yel != 0) { lpCMYK[setCnt].Yel = 255; }
  392. if (lpCMYK[setCnt].Bla != 0) { lpCMYK[setCnt].Bla = 255; }
  393. }
  394. }
  395. MY_VERBOSE(("ImagePro Dithering()\n"));
  396. //----------------------------------------------------------------------------------------------------
  397. pos.x = dstX; pos.y = dstY; // Drawing start position
  398. off.x = 0; off.y = 0; // Coordinates of source bitmap data
  399. xMag.Nrt = 1; xMag.Dnt = 1; // X magnification
  400. yMag.Nrt = 1; yMag.Dnt = 1; // Y magnification
  401. Dithering(
  402. pdevobj,
  403. (WORD)bmpBuf.Drv.Rgb.AllWhite,
  404. (WORD)pBitmapInfoHeader->biWidth,
  405. pos,
  406. off,
  407. xMag,
  408. yMag,
  409. (LPCMYK)bmpBuf.Drv.Cmyk.Pnt,
  410. (DWORD)dstWByt,
  411. bmpBuf.Drv.Bit.Pnt[CYAN] + dstWByt * dstScn,
  412. bmpBuf.Drv.Bit.Pnt[MGENTA] + dstWByt * dstScn,
  413. bmpBuf.Drv.Bit.Pnt[YELLOW] + dstWByt * dstScn,
  414. bmpBuf.Drv.Bit.Pnt[BLACK] + dstWByt * dstScn
  415. );
  416. // DUMP_VERBOSE((LPBYTE)bmpBuf.Drv.Bit.Pnt[CYAN] + dstWByt * dstScn,64); MY_VERBOSE(("\n"));
  417. // DUMP_VERBOSE((LPBYTE)bmpBuf.Drv.Bit.Pnt[MGENTA] + dstWByt * dstScn,64); MY_VERBOSE(("\n"));
  418. // DUMP_VERBOSE((LPBYTE)bmpBuf.Drv.Bit.Pnt[YELLOW] + dstWByt * dstScn,64); MY_VERBOSE(("\n"));
  419. // DUMP_VERBOSE((LPBYTE)bmpBuf.Drv.Bit.Pnt[BLACK] + dstWByt * dstScn,64); MY_VERBOSE(("\n"));
  420. srcY++;
  421. pSrcBmp += srcWByt;
  422. }
  423. if (dstScn != 0) {
  424. // Spool to printer
  425. MY_VERBOSE(("ImagePro BmpPrint()\n"));
  426. BmpPrint(pdevobj, &bmpBuf, drwPos, (WORD)pBitmapInfoHeader->biWidth, dstScn, dstWByt);
  427. }
  428. }
  429. // Set back palette (Palette No. is fixed , All plane(CMYK) is OK )
  430. // Same as palette state before OEMImageProcessing call
  431. MY_VERBOSE(("ImagePro WRITESPOOLBUF()\n"));
  432. WRITESPOOLBUF(pdevobj, ORG_MODE_IN, BYTE_LENGTH(ORG_MODE_IN));
  433. // Replacement of strsafe-api 2002.3.6 >>>
  434. // wlen = (WORD)wsprintf(Cmd, PALETTE_SELECT, 0, DEFAULT_PALETTE_INDEX);
  435. if (S_OK != StringCbPrintfExA(Cmd, sizeof(Cmd),
  436. &pDestEnd, &szRemLen,
  437. STRSAFE_IGNORE_NULLS | STRSAFE_NULL_ON_FAILURE,
  438. PALETTE_SELECT, 0, DEFAULT_PALETTE_INDEX)) {
  439. BmpBufFree(&bmpBuf);
  440. return FALSE;
  441. }
  442. wlen = (WORD)(pDestEnd - Cmd);
  443. // Replacement of strsafe-api 2002.3.6 <<<
  444. WRITESPOOLBUF(pdevobj, Cmd, wlen);
  445. WRITESPOOLBUF(pdevobj, PLANE_RESET, BYTE_LENGTH(PLANE_RESET));
  446. WRITESPOOLBUF(pdevobj, ORG_MODE_OUT, BYTE_LENGTH(ORG_MODE_OUT));
  447. BmpBufFree(&bmpBuf);
  448. CM_VERBOSE(("ImagePro End\n\n"));
  449. return TRUE;
  450. }
  451. //===================================================================================================
  452. // Convert RGB data into CMYK data
  453. //===================================================================================================
  454. BOOL FAR PASCAL ColMatching( // AllWhite?
  455. PDEVOBJ pdevobj, // Pointer to pdevobj structure
  456. UINT PColor, // 1 dot line / Char12P or less point?
  457. UINT BCnvFix, // Black replacement fixation?(No:dialog use)
  458. LPRGB lpInRGB, // RGB line(Input)
  459. UINT MchSiz, // RGB size
  460. LPCMYK lpInCMYK // CMYK line(Output)
  461. )
  462. {
  463. LPRGB lpRGB; // RGB line
  464. LPCMYK lpCMYK; // CMYK line
  465. LPCMYKINF lpCMYKInf; // CMYK Color change information
  466. UINT chkCnt; // RGB check counter for white
  467. LPCOLMCHINF lpColMch; // Color Matching Information
  468. UINT cMch; // Color Matching type
  469. UINT bCnv; // Black replacement
  470. PMYPDEV pOEM = (PMYPDEV)pdevobj->pdevOEM;
  471. if (MchSiz == 1) { // RGB size=1 ?
  472. lpRGB = pOEM->Col.lpTmpRGB; // RGB convert area (*Temp area)
  473. lpCMYK = pOEM->Col.lpTmpCMYK; // CMYK convert area (*Temp area)
  474. *lpRGB = *lpInRGB; // Input RGB
  475. } else {
  476. lpRGB = lpInRGB; // RGB line
  477. lpCMYK = lpInCMYK; // CMYK line
  478. }
  479. for (chkCnt = 0; chkCnt < MchSiz; chkCnt++) { // check of All white
  480. if ((lpRGB[chkCnt].Blu & lpRGB[chkCnt].Grn & lpRGB[chkCnt].Red) != 0xff) { break; }
  481. }
  482. if (chkCnt >= MchSiz) { // All white data?
  483. if (MchSiz == 1) { // White set to CMYK
  484. lpInCMYK->Cyn = 0x00;
  485. lpInCMYK->Mgt = 0x00;
  486. lpInCMYK->Yel = 0x00;
  487. lpInCMYK->Bla = 0x00;
  488. }
  489. return Yes; // All white
  490. }
  491. if (chkCnt != 0) { // White data existence in the left end?
  492. memset(lpCMYK, 0x00, chkCnt * sizeof(CMYK)); // White set to CMYK
  493. (HPBYTE)lpCMYK += chkCnt * sizeof(CMYK); // Change of the head position of CMYK area
  494. (HPBYTE)lpInCMYK += chkCnt * sizeof(CMYK); // Change of the head position of CMYK area
  495. (HPBYTE)lpRGB += chkCnt * sizeof(RGBS); // Change of the head position of RGB area
  496. MchSiz -= chkCnt; // Change of RGB size
  497. }
  498. if (pOEM->Col.ColMon == CMMCOL) { // Color?
  499. if ((PColor == Yes && pOEM->Col.Mch.PColor == Yes) || pOEM->Col.Mch.Diz == XX_DITH_NON) {
  500. cMch = MCHPRG; // Color Matching progressive
  501. } else if (pOEM->Col.Mch.Mode == XX_COLORMATCH_NONE) {
  502. cMch = MCHSLD; // Color Matching Solid
  503. } else {
  504. if (pOEM->Col.Mch.Speed == Yes) { // Color Matching High speed?
  505. cMch = MCHFST; // Color Matching LUT First
  506. } else {
  507. cMch = MCHNML; // Color Matching LUT Normal
  508. }
  509. }
  510. bCnv = KCGNON; // Black unreplacement(Three color toner printings of black)
  511. if ((pOEM->Col.Mch.CmyBlk == Yes && pOEM->Col.Mch.GryKToner == No) ||
  512. (BCnvFix == Yes)) {
  513. bCnv = KCGBLA; // Black replacement (RGB=0 -> K)
  514. }
  515. if (pOEM->Col.Mch.CmyBlk == Yes && pOEM->Col.Mch.GryKToner == Yes) {
  516. bCnv = KCGGRY; // Black & gray replacement (R=G=B -> K)
  517. }
  518. // UCR?
  519. if (pOEM->Col.Mch.CmyBlk == No && pOEM->Col.Mch.Ucr != UCRNOO && BCnvFix == No) {
  520. bCnv = KCGNON; // Black unreplacement(Three color toner printings of black)
  521. }
  522. MY_VERBOSE((" ColMatching ICM USE !! [%d]\n", pOEM->iIcmMode));
  523. if (pOEM->iIcmMode == XX_ICM_USE && BCnvFix == No) {// ICM ?
  524. cMch = MCHSLD; // Color Matching Solid
  525. bCnv = KCGNON; // Black unreplacement
  526. }
  527. } else {
  528. cMch = MCHMON; // Color Matching MONO
  529. bCnv = KCGNON; // Black unreplacement
  530. }
  531. if (MchSiz == 1) {
  532. if (pOEM->Col.Mch.CchMch == cMch && // With cash information all same?
  533. pOEM->Col.Mch.CchCnv == bCnv &&
  534. pOEM->Col.Mch.CchRGB.Red == lpRGB->Red &&
  535. pOEM->Col.Mch.CchRGB.Grn == lpRGB->Grn &&
  536. pOEM->Col.Mch.CchRGB.Blu == lpRGB->Blu) {
  537. *lpInCMYK = pOEM->Col.Mch.CchCMYK; // Output CMYK setting
  538. return No; // Existence except for white data
  539. } else {
  540. pOEM->Col.Mch.CchMch = cMch; // Update cache (CMYK is eliminated)
  541. pOEM->Col.Mch.CchCnv = bCnv;
  542. pOEM->Col.Mch.CchRGB = *lpRGB;
  543. }
  544. }
  545. // if (pOEM->Col.Mch.LutMakGlb == No && pOEM->Col.Mch.SubDef == No) {
  546. // ColControl(pdevobj, lpRGB, MchSiz); // RGB Color cotrol
  547. // }
  548. lpCMYKInf = pOEM->Col.Mch.lpCMYKInf; // CMYK Color cotrol information
  549. lpColMch = pOEM->Col.Mch.lpColMch; // Color Matching information
  550. lpColMch->Mch = (DWORD)cMch; // Color Matching
  551. lpColMch->Bla = (DWORD)bCnv; // Black replacement
  552. MY_VERBOSE(("N501_ColMchPrc() Mch=[%d] Bla=[%d] Ucr=[%d] UcrCmy=[%d] UcrTnr=[%d] UcrBla=[%d]\n",
  553. lpColMch->Mch, lpColMch->Bla, lpColMch->Ucr, lpColMch->UcrCmy, lpColMch->UcrTnr, lpColMch->UcrBla));
  554. MY_VERBOSE((" LutGld=[%d] ColQty=[%d]\n",lpColMch->LutGld, lpColMch->ColQty));
  555. N501_ColMchPrc((DWORD)MchSiz, lpRGB, lpCMYK, lpColMch);
  556. if (pOEM->Col.Mch.LutMakGlb == No && (lpCMYKInf->Viv != 0 || lpCMYKInf->Dns != NULL)) {
  557. MY_VERBOSE(("N501_ColCtrCmy() Viv=[%d] DnsCyn=[%d] DnsMgt=[%d] DnsYel=[%d] DnsBla=[%d]\n",
  558. lpCMYKInf->Viv, lpCMYKInf->DnsCyn, lpCMYKInf->DnsMgt, lpCMYKInf->DnsYel, lpCMYKInf->DnsBla));
  559. N501_ColCtrCmy((DWORD)MchSiz, lpCMYK, lpCMYKInf);
  560. }
  561. if (MchSiz == 1) { // RGB size=1 ?
  562. *lpInCMYK = *lpCMYK; // output CMYK setting
  563. pOEM->Col.Mch.CchCMYK = *lpCMYK; // Update cache (CMYK)
  564. }
  565. return No; // Existence except for white data
  566. }
  567. //===================================================================================================
  568. // Convert CMYK data into Dither data
  569. //===================================================================================================
  570. UINT FAR PASCAL Dithering( // Output line count
  571. PDEVOBJ pdevobj, // Pointer to pdevobj structure
  572. UINT AllWhite, // All white data?
  573. UINT XSize, // X Size
  574. POINT Pos, // Start position for drawing
  575. POINT Off, // Y size of source bitmap data
  576. MAG XMag, // X magnification
  577. MAG YMag, // Y magnification
  578. LPCMYK lpCMYK, // CMYK line
  579. DWORD LinByt, // Dither pattern buffer size(Byte / 1Line)
  580. LPBYTE lpCBuf, // Line buffer(C)
  581. LPBYTE lpMBuf, // Line buffer(M)
  582. LPBYTE lpYBuf, // Line buffer(Y)
  583. LPBYTE lpKBuf // Line buffer(K)
  584. )
  585. {
  586. LPDIZINF lpDiz;
  587. LPDRWINF lpDrw;
  588. UINT linNum;
  589. DWORD whtByt;
  590. PMYPDEV pOEM = (PMYPDEV)pdevobj->pdevOEM;
  591. MY_VERBOSE(("ImagePro Dithering() Start\n"));
  592. // Check of zero divide 2002.3.23 >>>
  593. if ((YMag.Dnt == 0) || (XMag.Dnt == 0)) {
  594. ERR(("Dithering() 0Div-Check [YMag.Dnt, XMag.Dnt=0] \n"));
  595. return 0;
  596. }
  597. // Check of zero divide 2002.3.23 <<<
  598. if (AllWhite == Yes) { // All White data?
  599. linNum = MagPixel(Off.y, YMag.Nrt, YMag.Dnt); // Housing line number
  600. whtByt = (DWORD)LinByt * linNum; // White set byte number
  601. MY_VERBOSE(("ImagePro Dithering() linNum[%d] whtByt[%d] \n", linNum, whtByt));
  602. if (pOEM->Col.ColMon == CMMCOL) { // Color?
  603. memset(lpCBuf, 0x00, whtByt); // White set to CMYK
  604. memset(lpMBuf, 0x00, whtByt);
  605. memset(lpYBuf, 0x00, whtByt);
  606. }
  607. memset(lpKBuf, 0x00, whtByt);
  608. MY_VERBOSE(("ImagePro Dithering() AllWhite=Yes\n"));
  609. return linNum;
  610. }
  611. lpDiz = pOEM->Col.Mch.lpDizInf; // Dither pattern information
  612. MY_VERBOSE((" ColMon=[%d] PrnMod=[%d] PrnKnd=[%d] DizKnd=[%d] DizPat=[%d]\n",
  613. lpDiz->ColMon, lpDiz->PrnMod, lpDiz->PrnKnd, lpDiz->DizKnd, lpDiz->DizPat));
  614. MY_VERBOSE((" DizSls=[%d] SizCyn=[%d] SizMgt=[%d] SizYel=[%d] SizBla=[%d]\n",
  615. lpDiz->DizSls, lpDiz->SizCyn, lpDiz->SizMgt, lpDiz->SizYel, lpDiz->SizBla));
  616. lpDrw = pOEM->Col.lpDrwInf; // Draw information (*Temp area)
  617. lpDrw->XaxSiz = (DWORD)XSize; // X Pixel number
  618. lpDrw->StrXax = (DWORD)Pos.x; // Start position for drawing X
  619. lpDrw->StrYax = (DWORD)Pos.y; // Start position for drawing Y
  620. lpDrw->XaxNrt = (DWORD)XMag.Nrt; // X Magnification numerator
  621. lpDrw->XaxDnt = (DWORD)XMag.Dnt; // X Magnification Denominator
  622. lpDrw->YaxNrt = (DWORD)YMag.Nrt; // Y Magnification Numerator
  623. lpDrw->YaxDnt = (DWORD)YMag.Dnt; // Y Magnification Denominator
  624. lpDrw->XaxOfs = (DWORD)Off.x; // X Offset
  625. lpDrw->YaxOfs = (DWORD)Off.y; // Y Offset
  626. lpDrw->LinDot = (DWORD)XSize; // Destination, 1 line dot number
  627. lpDrw->LinByt = (DWORD)LinByt; // Destination, 1 line byte number
  628. lpDrw->CmyBuf = (LPCMYK)lpCMYK; // CMYK data buffer
  629. lpDrw->LinBufCyn = lpCBuf; // Destination buffer(CMYK)
  630. lpDrw->LinBufMgt = lpMBuf;
  631. lpDrw->LinBufYel = lpYBuf;
  632. lpDrw->LinBufBla = lpKBuf;
  633. lpDrw->AllLinNum = 0; // Total of the line number for Image
  634. MY_VERBOSE(("N501_ColDizPrc() XaxSiz=[%d] StrXax=[%d] StrYax=[%d] XaxNrt=[%d] XaxDnt=[%d]\n",
  635. lpDrw->XaxSiz, lpDrw->StrXax, lpDrw->StrYax, lpDrw->XaxNrt, lpDrw->XaxDnt));
  636. MY_VERBOSE(("N501_ColDizPrc() YaxNrt=[%d] YaxDnt=[%d] XaxOfs=[%d] YaxOfs=[%d] LinDot=[%d] LinByt=[%d]\n",
  637. lpDrw->YaxNrt, lpDrw->YaxDnt, lpDrw->XaxOfs, lpDrw->YaxOfs, lpDrw->LinDot, lpDrw->LinByt));
  638. N501_ColDizPrc(lpDiz, lpDrw); // Dithering
  639. MY_VERBOSE(("Dithering() End\n"));
  640. return (WORD)lpDrw->AllLinNum; // Housing line number
  641. }
  642. //===================================================================================================
  643. // Color control
  644. //===================================================================================================
  645. VOID FAR PASCAL ColControl(
  646. PDEVOBJ pdevobj, // Pointer to pdevobj structure
  647. LPRGB lpRGB, // RGB Line
  648. UINT RGBSiz // RGB Size
  649. )
  650. {
  651. LPRGBINF lpRGBInf; // RGB Color change information
  652. PMYPDEV pOEM = (PMYPDEV)pdevobj->pdevOEM;
  653. lpRGBInf = pOEM->Col.Mch.lpRGBInf;
  654. N501_ColCtrRgb((DWORD)RGBSiz, lpRGB, lpRGBInf); // RGB Color cntrol
  655. return;
  656. }
  657. //===================================================================================================
  658. // Allocate bitmap data buffer
  659. //---------------------------------------------------------------------------------------------------
  660. // Allocate size
  661. // RGB buffer :Source bitmap Xsize * 3
  662. // CMYK buffer :Source bitmap Xsize * 4
  663. // CMYK bit buffer :2 value (Source Xsize * XNrt + 7) / 8 * Source Ysize * YNrt
  664. // :4 value (Source Xsize * XNrt + 3) / 4 * Source Ysize * YNrt
  665. // :16 value (Source Xsize * XNrt + 1) / 2 * Source Ysize * YNrt
  666. //===================================================================================================
  667. BOOL BmpBufAlloc(
  668. PDEVOBJ pdevobj, // Pointer to pdevobj structure
  669. WORD SrcXSiz, // Source bitmap data Xsize
  670. WORD SrcYSiz, // Source bitmap data Ysize
  671. WORD SrcXOff, // Source X offset
  672. WORD SrcYOff, // Source Y offset
  673. WORD XNrt, // Magnification of X (numerator)
  674. WORD XDnt, // Magnification of X (denominator)
  675. WORD YNrt, // Magnification of Y (numerator)
  676. WORD YDnt, // Magnification of Y (denominator)
  677. LPBMPBIF lpBmpBuf // Pointer to bitmap buffer structure
  678. )
  679. {
  680. WORD setSiz;
  681. WORD setCnt;
  682. WORD alcErr; // Allocate error?
  683. WORD bytDot; // DPI
  684. WORD xSiz;
  685. WORD ySiz;
  686. WORD alcLin;
  687. DWORD alcSiz;
  688. PMYPDEV pOEM = (PMYPDEV)pdevobj->pdevOEM;
  689. alcErr = Yes;
  690. bytDot = pOEM->Col.BytDot;
  691. // Check of zero divide 2002.3.23 >>>
  692. if ((XDnt == 0) || (YDnt == 0)) {
  693. ERR(("BmpBufAlloc() 0Div-Check [XDnt, YDnt=0] \n"));
  694. return 0;
  695. }
  696. // Check of zero divide 2002.3.23 <<<
  697. xSiz = (WORD)(((DWORD)SrcXOff + SrcXSiz) * XNrt / XDnt);
  698. xSiz -= (WORD)((DWORD)SrcXOff * XNrt / XDnt);
  699. MY_VERBOSE(("BmpBufAlloc() xSiz[%d] \n", xSiz));
  700. ySiz = (WORD)(((DWORD)SrcYOff + SrcYSiz + 2) * YNrt / YDnt);
  701. ySiz -= (WORD)((DWORD)SrcYOff * YNrt / YDnt);
  702. MY_VERBOSE(("BmpBufAlloc() ySiz[%d] \n", ySiz));
  703. // The size of CMYK bit buffer
  704. if (((DWORD)((xSiz + bytDot - 1) / bytDot) * ySiz) < (64L * 1024L - 1L)) {
  705. alcLin = ySiz;
  706. } else { // Over 64KB?
  707. alcLin = (WORD)((64L * 1024L - 1L) / ((xSiz + bytDot - 1) / bytDot));
  708. }
  709. MY_VERBOSE(("BmpBufAlloc() bytDot[%d] \n", bytDot));
  710. alcSiz = ((xSiz + bytDot - 1) / bytDot) * alcLin; // The size of CMYK bit buffer(8bit boundary)
  711. MY_VERBOSE(("BmpBufAlloc() alcLin[%d] \n", alcLin));
  712. MY_VERBOSE(("BmpBufAlloc() alcSiz[%ld] \n", alcSiz));
  713. for ( ; ; ) { // Allocation
  714. // The number of lines that required
  715. lpBmpBuf->Drv.Bit.BseLin = (WORD)((DWORD)(YNrt + YDnt - 1) / YDnt);
  716. if (lpBmpBuf->Drv.Bit.BseLin > alcLin) {
  717. break;
  718. }
  719. MY_VERBOSE(("BmpBufAlloc() Drv.Bit.BseLin[%d] \n", lpBmpBuf->Drv.Bit.BseLin));
  720. lpBmpBuf->Drv.Rgb.Siz = SrcXSiz * 3; // RGB buffer
  721. if ((lpBmpBuf->Drv.Rgb.Pnt = (LPRGB)MemAllocZ(lpBmpBuf->Drv.Rgb.Siz)) == NULL) {
  722. break;
  723. }
  724. MY_VERBOSE(("BmpBufAlloc() Drv.Rgb.Siz[%d] \n", lpBmpBuf->Drv.Rgb.Siz));
  725. lpBmpBuf->Drv.Cmyk.Siz = SrcXSiz * 4; // CMYK buffer
  726. if ((lpBmpBuf->Drv.Cmyk.Pnt = (LPCMYK)MemAllocZ(lpBmpBuf->Drv.Cmyk.Siz)) == NULL) {
  727. break;
  728. }
  729. MY_VERBOSE(("BmpBufAlloc() Drv.Cmyk.Siz[%d] \n", lpBmpBuf->Drv.Cmyk.Siz));
  730. if (pOEM->iColor == XX_COLOR_SINGLE
  731. || pOEM->iColor == XX_COLOR_MANY
  732. || pOEM->iColor == XX_COLOR_MANY2) { // Color?
  733. setSiz = 4; // CMYK
  734. } else { // Mono?
  735. setSiz = 1; // K
  736. }
  737. MY_VERBOSE(("BmpBufAlloc() setSiz[%d] \n", setSiz));
  738. // CMYK bit buffer
  739. for (setCnt = 0; setCnt < setSiz; setCnt++) {
  740. if ((lpBmpBuf->Drv.Bit.Pnt[setCnt] = MemAllocZ(alcSiz)) == NULL) {
  741. break;
  742. }
  743. }
  744. if (setCnt == setSiz) {
  745. lpBmpBuf->Drv.Bit.Siz = alcSiz;
  746. lpBmpBuf->Drv.Bit.Lin = alcLin;
  747. alcErr = No; // Allocate OK
  748. }
  749. break;
  750. }
  751. if (alcErr == Yes) { // Allocate error?
  752. BmpBufFree(lpBmpBuf);
  753. return FALSE;
  754. }
  755. return TRUE;
  756. }
  757. //===================================================================================================
  758. // Free bitmap data buffer
  759. //===================================================================================================
  760. void BmpBufFree(
  761. LPBMPBIF lpBmpBuf // Pointer to bitmap buffer structure
  762. )
  763. {
  764. WORD chkCnt;
  765. if (lpBmpBuf->Drv.Rgb.Pnt) { // Free RGB buffer
  766. MemFree(lpBmpBuf->Drv.Rgb.Pnt);
  767. lpBmpBuf->Drv.Rgb.Pnt = NULL;
  768. }
  769. if (lpBmpBuf->Drv.Cmyk.Pnt) { // Free CMYK buffer
  770. MemFree(lpBmpBuf->Drv.Cmyk.Pnt);
  771. lpBmpBuf->Drv.Cmyk.Pnt = NULL;
  772. }
  773. // CMYK bit buffer
  774. for (chkCnt = 0; chkCnt < 4; chkCnt++) { // CMYK(2/4/16value)bitmap buffer
  775. if (lpBmpBuf->Drv.Bit.Pnt[chkCnt]) {
  776. MemFree(lpBmpBuf->Drv.Bit.Pnt[chkCnt]);
  777. lpBmpBuf->Drv.Bit.Pnt[chkCnt] = NULL;
  778. }
  779. }
  780. return;
  781. }
  782. //===================================================================================================
  783. // Clear CMYK bitmap data buffer
  784. //===================================================================================================
  785. void BmpBufClear(
  786. LPBMPBIF lpBmpBuf // Pointer to bitmap buffer structure
  787. )
  788. {
  789. WORD chkCnt;
  790. MY_VERBOSE(("BmpBufClear() Siz[%ld] \n", lpBmpBuf->Drv.Bit.Siz));
  791. for (chkCnt = 0; chkCnt < 4; chkCnt++) { // Clear CMYK(2/4/16value)bit buffer
  792. if (lpBmpBuf->Drv.Bit.Pnt[chkCnt]) {
  793. memset(lpBmpBuf->Drv.Bit.Pnt[chkCnt], 0x00, (WORD)lpBmpBuf->Drv.Bit.Siz);
  794. }
  795. }
  796. return;
  797. }
  798. //===================================================================================================
  799. // Spool bitmap data
  800. //===================================================================================================
  801. void BmpPrint(
  802. PDEVOBJ pdevobj, // Pointer to pdevobj structure
  803. LPBMPBIF lpBmpBuf, // Pointer to bitmap buffer structure
  804. POINT Pos, // Start position for spooling
  805. WORD Width, // Width(dot)
  806. WORD Height, // Height(dot)
  807. WORD WidthByte // Width(byte)
  808. )
  809. {
  810. DRWBMP drwBmp; // For Spooling bitmap data structure
  811. DRWBMPCMYK drwBmpCMYK; // For Spooling CMYK bitmap data structure
  812. WORD colCnt;
  813. PMYPDEV pOEM = (PMYPDEV)pdevobj->pdevOEM;
  814. static const CMYK colTbl[4] = { // CMYK table
  815. { 0, 0, 0, 255}, // Black
  816. { 0, 0, 255, 0}, // Yellow
  817. { 0, 255, 0, 0}, // Magenta
  818. {255, 0, 0, 0} // Cyan
  819. };
  820. static const WORD plnTbl[4] = { // Plane table
  821. PLN_BLACK,
  822. PLN_YELLOW,
  823. PLN_MGENTA,
  824. PLN_CYAN
  825. };
  826. static const WORD frmTbl[4] = {0, 3, 2, 1}; // Frame table
  827. drwBmpCMYK.Style = lpBmpBuf->Style;
  828. drwBmpCMYK.DataBit = lpBmpBuf->DatBit;
  829. drwBmpCMYK.DrawPos = Pos;
  830. drwBmpCMYK.Width = Width;
  831. drwBmpCMYK.Height = Height;
  832. drwBmpCMYK.WidthByte = WidthByte;
  833. MY_VERBOSE(("BmpPrint() Style[%d] DatBit[%d]\n", drwBmpCMYK.Style, lpBmpBuf->DatBit));
  834. MY_VERBOSE((" Width[%d] Height[%d] WidthByte[%d]\n", Width, Height, WidthByte));
  835. // Color?
  836. if (pOEM->iColor == XX_COLOR_SINGLE
  837. || pOEM->iColor == XX_COLOR_MANY
  838. || pOEM->iColor == XX_COLOR_MANY2) {
  839. for (colCnt = 0; colCnt < 4; colCnt++) { // Setting value for spooling bitmap data
  840. MY_VERBOSE((" colCnt[%d]\n", colCnt));
  841. drwBmpCMYK.Plane = PLN_ALL; // All Plane is OK
  842. drwBmpCMYK.Frame = frmTbl[colCnt];
  843. drwBmpCMYK.lpBit = lpBmpBuf->Drv.Bit.Pnt[colCnt]/* + WidthByte*/;
  844. PrnBitmapCMYK(pdevobj, &drwBmpCMYK); // Spool bitmap data
  845. }
  846. } else { // Mono
  847. // Setting value for spooling bitmap data
  848. drwBmpCMYK.Plane = plnTbl[0];
  849. drwBmpCMYK.Frame = frmTbl[0];
  850. drwBmpCMYK.lpBit = lpBmpBuf->Drv.Bit.Pnt[0]/* + WidthByte*/;
  851. PrnBitmapCMYK(pdevobj, &drwBmpCMYK); // Spool bitmap data
  852. }
  853. return;
  854. }
  855. //===================================================================================================
  856. // Convert 1 line RGB bitmap data into 24bit (for 1pixel) RGB bitmap data
  857. //===================================================================================================
  858. void BmpRGBCnv(
  859. LPRGB lpRGB, // Pointer to destination bitmap data
  860. LPBYTE lpSrc, // Pointer to source bitmap data
  861. WORD SrcBit, // Pixel of source bitmap data
  862. WORD SrcX, // X coordinates of source bitmap data
  863. WORD SrcXSiz, // X size of source bitmap data
  864. LPRGBQUAD lpPlt // Color palette table of source bitmap data(1/4/8pixel)
  865. )
  866. {
  867. WORD setCnt;
  868. BYTE colNum;
  869. LPWORD lpWSrc;
  870. MY_VERBOSE(("BmpRGBCnv SrcBit[%d]\n", SrcBit));
  871. switch (SrcBit) {
  872. case 1: // 1 bit
  873. for (setCnt = 0; setCnt < SrcXSiz; setCnt++, SrcX++) {
  874. // Foreground color?
  875. if (!(lpSrc[SrcX / 8] & BitTbl[SrcX & 0x0007])) {
  876. lpRGB[setCnt].Blu = lpPlt[0].rgbBlue;
  877. lpRGB[setCnt].Grn = lpPlt[0].rgbGreen;
  878. lpRGB[setCnt].Red = lpPlt[0].rgbRed;
  879. } else {
  880. lpRGB[setCnt].Blu = lpPlt[1].rgbBlue;
  881. lpRGB[setCnt].Grn = lpPlt[1].rgbGreen;
  882. lpRGB[setCnt].Red = lpPlt[1].rgbRed;
  883. }
  884. }
  885. break;
  886. case 4: // 4bit
  887. for (setCnt = 0; setCnt < SrcXSiz; setCnt++, SrcX++) {
  888. if (!(SrcX & 0x0001)) { // A even number coordinates?
  889. colNum = lpSrc[SrcX / 2] / 16;
  890. } else {
  891. colNum = lpSrc[SrcX / 2] % 16;
  892. }
  893. lpRGB[setCnt].Blu = lpPlt[colNum].rgbBlue;
  894. lpRGB[setCnt].Grn = lpPlt[colNum].rgbGreen;
  895. lpRGB[setCnt].Red = lpPlt[colNum].rgbRed;
  896. }
  897. break;
  898. case 8: // 8bit
  899. for (setCnt = 0; setCnt < SrcXSiz; setCnt++, SrcX++) {
  900. colNum = lpSrc[SrcX];
  901. lpRGB[setCnt].Blu = lpPlt[colNum].rgbBlue;
  902. lpRGB[setCnt].Grn = lpPlt[colNum].rgbGreen;
  903. lpRGB[setCnt].Red = lpPlt[colNum].rgbRed;
  904. }
  905. break;
  906. case 16: // 16bit
  907. lpWSrc = (LPWORD)lpSrc + SrcX;
  908. for (setCnt = 0; setCnt < SrcXSiz; setCnt++, lpWSrc++) {
  909. lpRGB[setCnt].Blu = (BYTE)((*lpWSrc & 0x001f) << 3);
  910. lpRGB[setCnt].Grn = (BYTE)((*lpWSrc & 0x03e0) >> 2);
  911. lpRGB[setCnt].Red = (BYTE)((*lpWSrc / 0x0400) << 3);
  912. }
  913. break;
  914. case 24: // 24 bit
  915. lpSrc += SrcX * 3;
  916. for (setCnt = 0; setCnt < SrcXSiz; setCnt++, lpSrc += 3) {
  917. lpRGB[setCnt].Red = lpSrc[0];
  918. lpRGB[setCnt].Grn = lpSrc[1];
  919. lpRGB[setCnt].Blu = lpSrc[2];
  920. }
  921. break;
  922. case 32: // 32bit
  923. lpSrc += SrcX * 4;
  924. for (setCnt = 0; setCnt < SrcXSiz; setCnt++, lpSrc += 4) {
  925. lpRGB[setCnt].Blu = lpSrc[0];
  926. lpRGB[setCnt].Grn = lpSrc[1];
  927. lpRGB[setCnt].Red = lpSrc[2];
  928. }
  929. break;
  930. }
  931. return;
  932. }
  933. //===================================================================================================
  934. // Color Matching information setting
  935. //===================================================================================================
  936. BOOL ColMchInfSet( // TRUE / FALSE
  937. PDEVOBJ pdevobj // Pointer to pdevobj structure
  938. )
  939. {
  940. static LPTSTR N501LutNam[] = { // N501 LUT file name
  941. N501LUTR // Color Matching
  942. };
  943. LPCOLMCHINF lpColMch; // Color Matching information
  944. UINT ColMch; // Color Matching Method
  945. UINT lutTbl; // LUT file table number
  946. UINT lutNum; // LUT number(0:direct 1:linear *Except for N403:0Fixed)
  947. LPTSTR lutNam; // LUT file name
  948. LPTSTR filNam; // LUT file name(FULL PATH)
  949. DWORD pthSiz; // DRIVER PATH
  950. HANDLE hFile; // file handle
  951. HPBYTE hpLoad; // LUT pointer
  952. DWORD seek; // LUT seek
  953. LPBYTE lpLut032Buf; // First LUT 32 GRID area
  954. LPBYTE lpLut032Wrk; // First LUT 32 GRID work area
  955. LPBYTE lpLutMakGlbBuf; // Sum LUT area
  956. LPBYTE lpLutMakGlbWrk; // Sum LUT work area
  957. LPCMYK LutAdr;
  958. DWORD dwRet;
  959. PMYPDEV pOEM = (PMYPDEV)pdevobj->pdevOEM;
  960. MY_VERBOSE(("\nColMchInfSet() Start\n"));
  961. lpColMch = pOEM->Col.Mch.lpColMch; // Color Matching Information
  962. lpColMch->Bla = KCGNON;
  963. lpColMch->LutGld = 0;
  964. lpColMch->Ucr = pOEM->Col.Mch.Ucr;
  965. lpColMch->UcrCmy = 40; // UCR quantity 40%
  966. lpColMch->UcrBla = 90; // Ink version generation quantity 90%
  967. lpColMch->UcrTnr = 270; //+Toner gross weight 270% CASIO 20001/02/15
  968. lpColMch->UcrTbl = NULL; // UCK table
  969. lpColMch->GryTbl = NULL; // Gray transfer table
  970. if (pOEM->Col.ColMon == CMMMON) { // Mono?
  971. lpColMch->Mch = MCHMON;
  972. // if ((ColLutMakGlbMon(pdevobj)) == FALSE) {
  973. // return FALSE;
  974. // }
  975. return TRUE;
  976. }
  977. if (pOEM->Col.Mch.Speed == Yes) { // First?
  978. lpColMch->Mch = MCHFST;
  979. } else {
  980. lpColMch->Mch = MCHNML;
  981. }
  982. if (pOEM->Col.Mch.Diz == XX_DITH_NON) { // Not Dithering?
  983. lpColMch->Mch = MCHPRG; // progressive
  984. return TRUE;
  985. }
  986. lutNum = 0; // LUT number(0:direct 1:linear *Except for N403:0Fixed)
  987. lutTbl = 0; // number of LUT table array
  988. ColMch = pOEM->Col.Mch.Mode; // Color Matching mode
  989. if (pOEM->Printer == PRN_N5) { // N5 printer
  990. if (ColMch == XX_COLORMATCH_BRI
  991. || ColMch == XX_COLORMATCH_VIV) { // Brightness or Vivid?
  992. lutTbl = 0;
  993. lutNum = LUT_XD;
  994. } else if (ColMch == XX_COLORMATCH_TINT) { // tincture?
  995. lutTbl = 0;
  996. lutNum = LUT_YD;
  997. } else if (ColMch == XX_COLORMATCH_NONE) {
  998. lpColMch->Mch = MCHSLD; // Solid
  999. lutTbl = 0;
  1000. lutNum = LUT_XD;
  1001. }
  1002. lutNam = N501LutNam[lutTbl]; // LUT file name
  1003. }
  1004. if ((filNam = MemAllocZ(MAX_PATH * sizeof(TCHAR))) == NULL) {
  1005. return FALSE;
  1006. }
  1007. pthSiz = GetModuleFileName(pdevobj->hOEM, filNam, MAX_PATH);
  1008. pthSiz -= ((sizeof(CSN5RESDLL) / sizeof(WCHAR)) - 1);
  1009. // Replacement of strsafe-api 2002.3.6 >>>
  1010. // lstrcpy(&filNam[pthSiz], lutNam);
  1011. if (S_OK != StringCchCopy(&filNam[pthSiz], MAX_PATH - pthSiz, lutNam)) {
  1012. MemFree(filNam);
  1013. return FALSE;
  1014. }
  1015. // Replacement of strsafe-api 2002.3.6 <<<
  1016. MY_VERBOSE(("LUT filNam [%ws]\n", filNam));
  1017. if (INVALID_HANDLE_VALUE == (hFile = CreateFile(filNam,
  1018. GENERIC_READ, FILE_SHARE_READ, NULL,
  1019. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL))) {
  1020. ERR(("Error opening LUT file %ws (%d)\n", filNam, GetLastError()));
  1021. MemFree(filNam);
  1022. return FALSE;
  1023. }
  1024. MemFree(filNam);
  1025. if ((hpLoad = MemAlloc(LUTFILESIZ)) == NULL) { // LUT read buffer
  1026. CloseHandle(hFile);
  1027. return FALSE;
  1028. }
  1029. MY_VERBOSE(("ColMchInfSet() LUT file read\n"));
  1030. if (FALSE == ReadFile(hFile, // LUT file read
  1031. hpLoad, LUTFILESIZ, &dwRet, NULL)) {
  1032. ERR(("Error reading LUT file %ws (%d)\n", filNam, GetLastError()));
  1033. // Abort
  1034. MemFree(hpLoad);
  1035. CloseHandle(hFile);
  1036. return FALSE;
  1037. }
  1038. MY_VERBOSE(("ColMchInfSet() N501_ColLutDatRdd()\n"));
  1039. MY_VERBOSE(("ColMchInfSet() lutNum[%d] \n", lutNum));
  1040. // if ((seek = (N501_ColLutDatRdd((LPBYTE)hpLoad, (DWORD)lutNum))) == 0) {
  1041. if ((seek = (N501_ColLutDatRdd((LPBYTE)hpLoad, lutNum))) == 0) {
  1042. MemFree(hpLoad);
  1043. CloseHandle(hFile);
  1044. return FALSE;
  1045. }
  1046. lpColMch->LutAdr = (LPCMYK)(hpLoad + seek); // LUT file Head address + seek
  1047. LutAdr = (LPCMYK)(hpLoad + seek);
  1048. pOEM->Col.LutTbl = hpLoad; // LUT table
  1049. if (lpColMch->Mch == MCHSLD) { // Color Matching Solid?
  1050. MY_VERBOSE(("ColMchInfSet() Mch == MCHSLD \n"));
  1051. // Black & gray replacement ?
  1052. if (pOEM->Col.Mch.GryKToner == Yes && pOEM->Col.Mch.CmyBlk == Yes) {
  1053. // Gray transfer table make
  1054. if ((ColGryTblMak(pdevobj, LutAdr)) == FALSE) {
  1055. MemFree(hpLoad);
  1056. CloseHandle(hFile);
  1057. return FALSE;
  1058. }
  1059. }
  1060. if (lpColMch->Ucr != UCRNOO) { // UCR?
  1061. MY_VERBOSE(("ColMchInfSet() Mch == MCHSLD && Ucr != UCRNOO \n"));
  1062. if ((ColUcrTblMak(pdevobj, (LPCMYK)(hpLoad + seek))) == FALSE) {
  1063. MemFree(hpLoad);
  1064. CloseHandle(hFile);
  1065. return FALSE;
  1066. }
  1067. }
  1068. CloseHandle(hFile);
  1069. return TRUE;
  1070. }
  1071. MY_VERBOSE(("ColMchInfSet() Global LUT Start\n"));
  1072. if (pOEM->Col.Mch.Mode == XX_COLORMATCH_VIV) {
  1073. MY_VERBOSE(("ColMchInfSet() Global LUT area\n"));
  1074. // Global LUT area
  1075. if ((lpLutMakGlbBuf = MemAlloc(LUTMAKGLBSIZ)) == NULL) {
  1076. MemFree(hpLoad);
  1077. CloseHandle(hFile);
  1078. return FALSE;
  1079. }
  1080. // Global LUT work area
  1081. MY_VERBOSE(("ColMchInfSet() Global LUT work area\n"));
  1082. if ((lpLutMakGlbWrk = MemAlloc(LUTGLBWRK)) == NULL) {
  1083. MemFree(lpLutMakGlbBuf);
  1084. MemFree(hpLoad);
  1085. CloseHandle(hFile);
  1086. return FALSE;
  1087. }
  1088. // Make Global LUT
  1089. MY_VERBOSE(("ColMchInfSet() N501_ColLutMakGlb()\n"));
  1090. if ((N501_ColLutMakGlb(NULL, (LPCMYK)(hpLoad + seek), pOEM->Col.Mch.lpRGBInf, pOEM->Col.Mch.lpCMYKInf,
  1091. (LPCMYK)lpLutMakGlbBuf, lpLutMakGlbWrk)) != ERRNON) {
  1092. MemFree(lpLutMakGlbWrk);
  1093. MemFree(lpLutMakGlbBuf);
  1094. MemFree(hpLoad);
  1095. CloseHandle(hFile);
  1096. return FALSE;
  1097. }
  1098. pOEM->Col.lpLutMakGlb = lpLutMakGlbBuf;
  1099. pOEM->Col.Mch.LutMakGlb = Yes;
  1100. lpColMch->LutAdr = (LPCMYK)lpLutMakGlbBuf;
  1101. LutAdr = (LPCMYK)lpLutMakGlbBuf;
  1102. MemFree(lpLutMakGlbWrk);
  1103. }
  1104. if (pOEM->Col.Mch.Speed == Yes) { // First?
  1105. // First LUT 32 GRID area
  1106. MY_VERBOSE(("ColMchInfSet() First LUT 32 GRID area\n"));
  1107. if ((lpLut032Buf = MemAlloc(LUT032SIZ)) == NULL) {
  1108. if (lpLutMakGlbBuf != NULL) {
  1109. MemFree(lpLutMakGlbBuf);
  1110. }
  1111. MemFree(hpLoad);
  1112. CloseHandle(hFile);
  1113. return FALSE;
  1114. }
  1115. // First LUT(32GRID) wark area
  1116. if ((lpLut032Wrk = MemAlloc(LUT032WRK)) == NULL) {
  1117. if (lpLutMakGlbBuf != NULL) {
  1118. MemFree(lpLutMakGlbBuf);
  1119. }
  1120. MemFree(lpLut032Buf);
  1121. MemFree(hpLoad);
  1122. CloseHandle(hFile);
  1123. return FALSE;
  1124. }
  1125. // First LUT(32GRID) Make
  1126. MY_VERBOSE(("ColMchInfSet() N501_ColLutMak032()\n"));
  1127. N501_ColLutMak032(LutAdr, (LPCMYK)lpLut032Buf, lpLut032Wrk);
  1128. MemFree(lpLut032Wrk);
  1129. lpColMch->LutAdr = (LPCMYK)lpLut032Buf;
  1130. LutAdr = (LPCMYK)lpLut032Buf;
  1131. pOEM->Col.lpLut032 = lpLut032Buf;
  1132. }
  1133. MY_VERBOSE(("ColMchInfSet() Black & gray replacement ?\n"));
  1134. // Black & gray replacement ?
  1135. if (pOEM->Col.Mch.GryKToner == Yes && pOEM->Col.Mch.CmyBlk == Yes) {
  1136. MY_VERBOSE(("ColMchInfSet() Black & gray replacement [Yes]\n"));
  1137. if ((ColGryTblMak(pdevobj, LutAdr)) == FALSE) { // Gray transfer table make
  1138. if (lpLutMakGlbBuf != NULL) {
  1139. MemFree(lpLutMakGlbBuf);
  1140. }
  1141. if (lpLut032Buf != NULL) {
  1142. MemFree(lpLut032Buf);
  1143. }
  1144. MemFree(hpLoad);
  1145. CloseHandle(hFile);
  1146. return FALSE;
  1147. }
  1148. }
  1149. if (lpColMch->Ucr != UCRNOO && // UCR & (Normal or First)?
  1150. (lpColMch->Mch == MCHFST || lpColMch->Mch == MCHNML) ) {
  1151. // UCR table create
  1152. MY_VERBOSE(("ColMchInfSet() ColUcrTblMak()\n"));
  1153. if ((ColUcrTblMak(pdevobj, LutAdr)) == FALSE) {
  1154. if (lpLutMakGlbBuf != NULL) {
  1155. MemFree(lpLutMakGlbBuf);
  1156. }
  1157. if (lpLut032Buf != NULL) {
  1158. MemFree(lpLut032Buf);
  1159. }
  1160. MemFree(hpLoad);
  1161. CloseHandle(hFile);
  1162. return FALSE;
  1163. }
  1164. MY_VERBOSE(("ColMchInfSet() ColUcrTblMak() OK!!\n"));
  1165. }
  1166. CloseHandle(hFile);
  1167. lpColMch->ColQty = (DWORD)0; // The color designated number
  1168. lpColMch->ColAdr = NULL; // Color designated table
  1169. if ((pOEM->Col.CchRGB = MemAlloc(CCHRGBSIZ)) == NULL) {
  1170. return FALSE;
  1171. }
  1172. if ((pOEM->Col.CchCMYK = MemAlloc(CCHCMYSIZ)) == NULL) {
  1173. MemFree(pOEM->Col.CchRGB);
  1174. return FALSE;
  1175. }
  1176. lpColMch->CchRgb = (LPRGB)pOEM->Col.CchRGB;
  1177. lpColMch->CchCmy = (LPCMYK)pOEM->Col.CchCMYK;
  1178. MY_VERBOSE(("ColMchInfSet() N501_ColCchIni()\n"));
  1179. N501_ColCchIni(lpColMch); // Cache table initialize
  1180. MY_VERBOSE(("ColMchInfSet() End\n"));
  1181. return TRUE;
  1182. }
  1183. //===================================================================================================
  1184. // Dither information setting
  1185. //===================================================================================================
  1186. BOOL DizInfSet( // TRUE / FALSE
  1187. PDEVOBJ pdevobj // Pointer to pdevobj structure
  1188. )
  1189. {
  1190. LPDIZINF lpDiz; // Dither pattern information
  1191. DWORD dizSizC; // Dither pattern size(C)
  1192. DWORD dizSizM; // Dither pattern size(M)
  1193. DWORD dizSizY; // Dither pattern size(Y)
  1194. DWORD dizSizK; // Dither pattern size(K)
  1195. PMYPDEV pOEM = (PMYPDEV)pdevobj->pdevOEM;
  1196. MY_VERBOSE(("DizInfSet() Start\n"));
  1197. lpDiz = pOEM->Col.Mch.lpDizInf; // Dither pattern information
  1198. if (pOEM->Col.ColMon == CMMCOL) { // Color?
  1199. lpDiz->ColMon = CMMCOL;
  1200. } else { // Mono
  1201. lpDiz->ColMon = CMMMON;
  1202. } // Get dither pattern
  1203. if ((lpDiz->DizPat = (DWORD)GetDizPat(pdevobj)) == 0xff) {
  1204. return TRUE; // TRUE(Not dithering)
  1205. }
  1206. if (pOEM->Printer == PRN_N5) { // N5 printer
  1207. if (pOEM->Col.wReso == DPI300) { // 300DPI?
  1208. if (pOEM->Col.Dot == XX_TONE_2) { // 2value?
  1209. MY_VERBOSE(("DizInfSet() PrnMod=PRM302\n"));
  1210. lpDiz->PrnMod = PRM302;
  1211. } else { // 16value
  1212. MY_VERBOSE(("DizInfSet() PrnMod=PRM316\n"));
  1213. lpDiz->PrnMod = PRM316;
  1214. }
  1215. } else { // 600DPI
  1216. if (pOEM->Col.Dot == XX_TONE_2) { // 2value?
  1217. MY_VERBOSE(("DizInfSet() PrnMod=PRM602\n"));
  1218. lpDiz->PrnMod = PRM602;
  1219. } else if (pOEM->Col.Dot == XX_TONE_4){ // 4value?
  1220. MY_VERBOSE(("DizInfSet() PrnMod=PRM604\n"));
  1221. lpDiz->PrnMod = PRM604;
  1222. } else if (pOEM->Col.Dot == XX_TONE_16){ // 16value?
  1223. MY_VERBOSE(("DizInfSet() PrnMod=PRM616\n"));
  1224. lpDiz->PrnMod = PRM616;
  1225. }
  1226. }
  1227. lpDiz->TblCyn = NULL; // To acquire dither pattern size
  1228. lpDiz->TblMgt = NULL;
  1229. lpDiz->TblYel = NULL;
  1230. lpDiz->TblBla = NULL;
  1231. MY_VERBOSE(("DizInfSet() DizFileOpen()\n"));
  1232. lpDiz->DizKnd = KNDIMG; // Dither Kind
  1233. if ((DizFileOpen(pdevobj, lpDiz)) == FALSE) { // Get dither pattern size
  1234. return FALSE;
  1235. }
  1236. dizSizC = lpDiz->SizCyn * lpDiz->SizCyn * lpDiz->DizSls;
  1237. dizSizM = lpDiz->SizMgt * lpDiz->SizMgt * lpDiz->DizSls;
  1238. dizSizY = lpDiz->SizYel * lpDiz->SizYel * lpDiz->DizSls;
  1239. dizSizK = lpDiz->SizBla * lpDiz->SizBla * lpDiz->DizSls;
  1240. MY_VERBOSE(("DizInfSet() dizSizC[%d] M[%d] Y[%d] K[%d]\n", dizSizC, dizSizM, dizSizY, dizSizK));
  1241. }
  1242. MY_VERBOSE(("DizInfSet() Dither pattern table area Alloc\n"));
  1243. if (lpDiz->ColMon == CMMCOL) { // Color?
  1244. lpDiz->SizCyn = dizSizC; // Dither pattern table(Cyan)
  1245. if ((pOEM->Col.DizTbl[0] = MemAlloc(dizSizC)) == NULL) {
  1246. return FALSE;
  1247. }
  1248. lpDiz->TblCyn = (LPBYTE)pOEM->Col.DizTbl[0];
  1249. lpDiz->SizMgt = dizSizM; // Dither pattern table(Magenta)
  1250. if ((pOEM->Col.DizTbl[1] = MemAlloc(dizSizM)) == NULL) {
  1251. return FALSE;
  1252. }
  1253. lpDiz->TblMgt = (LPBYTE)pOEM->Col.DizTbl[1];
  1254. lpDiz->SizYel = dizSizY; // Dither pattern table(Yellow)
  1255. if ((pOEM->Col.DizTbl[2] = MemAlloc(dizSizY)) == NULL) {
  1256. return FALSE;
  1257. }
  1258. lpDiz->TblYel = (LPBYTE)pOEM->Col.DizTbl[2];
  1259. }
  1260. lpDiz->SizBla = dizSizK; // Dither pattern table(Black)
  1261. if ((pOEM->Col.DizTbl[3] = MemAlloc(dizSizK)) == NULL) {
  1262. return FALSE;
  1263. }
  1264. lpDiz->TblBla = (LPBYTE)pOEM->Col.DizTbl[3];
  1265. MY_VERBOSE(("DizInfSet() DizFileOpen()\n"));
  1266. if ((DizFileOpen(pdevobj, lpDiz)) == FALSE) { // Make dither pattern
  1267. return FALSE;
  1268. }
  1269. MY_VERBOSE(("DizInfSet() End\n"));
  1270. return TRUE; // TRUE
  1271. }
  1272. //===================================================================================================
  1273. // Get Dither pattern type
  1274. //===================================================================================================
  1275. UINT GetDizPat( // Dither pattern(0xff: Not dithering)
  1276. PDEVOBJ pdevobj // Pointer to pdevobj structure
  1277. )
  1278. {
  1279. static const WORD DizNumTbl[XX_MAXDITH] = {DIZMID, // DITH_IMG
  1280. DIZRUG, // DITH_GRP
  1281. DIZSML, // DITH_TXT
  1282. 0xff, // DITH_GOSA
  1283. DIZMID, // DITH_NORMAL
  1284. DIZMID, // DITH_HS_NORMAL
  1285. DIZSML, // DITH_DETAIL
  1286. DIZRUG, // DITH_EMPTY
  1287. DIZSTO, // DITH_SPREAD
  1288. DIZMID // DITH_NON
  1289. };
  1290. UINT dizPat;
  1291. PMYPDEV pOEM = (PMYPDEV)pdevobj->pdevOEM;
  1292. dizPat = DizNumTbl[pOEM->Col.Mch.Diz];
  1293. return dizPat;
  1294. }
  1295. //===================================================================================================
  1296. // Read dither file
  1297. //===================================================================================================
  1298. BOOL DizFileOpen(
  1299. PDEVOBJ pdevobj, // Pointer to pdevobj structure
  1300. LPDIZINF lpDiz // Dither pattern
  1301. )
  1302. {
  1303. LPTSTR drvPth;
  1304. LPTSTR filNam;
  1305. DWORD pthSiz;
  1306. HANDLE hFile;
  1307. LPBYTE lpDizBuf;
  1308. LPBYTE lpDizWrkBuf;
  1309. DWORD dwRet;
  1310. PMYPDEV pOEM = (PMYPDEV)pdevobj->pdevOEM;
  1311. MY_VERBOSE(("DizFileOpen() Start\n"));
  1312. if ((filNam = MemAllocZ(MAX_PATH * sizeof(TCHAR))) == NULL) {
  1313. return FALSE;
  1314. }
  1315. pthSiz = GetModuleFileName(pdevobj->hOEM, filNam, MAX_PATH);
  1316. pthSiz -= ((sizeof(CSN5RESDLL) / sizeof(WCHAR)) - 1);
  1317. // Replacement of strsafe-api 2002.3.6 >>>
  1318. // lstrcpy(&filNam[pthSiz], N501DIZ); // Dither file name (FULL PATH)
  1319. if (S_OK != StringCchCopy(&filNam[pthSiz], MAX_PATH - pthSiz, N501DIZ)) {
  1320. MemFree(filNam);
  1321. return FALSE;
  1322. }
  1323. // Replacement of strsafe-api 2002.3.6 <<<
  1324. MY_VERBOSE(("DIZ filNam [%ws]\n", filNam));
  1325. if (INVALID_HANDLE_VALUE == (hFile = CreateFile(filNam,
  1326. GENERIC_READ, FILE_SHARE_READ, NULL,
  1327. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL))) {
  1328. ERR(("Error opening DIZ file %ws (%d)\n", filNam, GetLastError()));
  1329. MemFree(filNam);
  1330. return 0;
  1331. }
  1332. MemFree(filNam);
  1333. if ((lpDizBuf = MemAlloc(DIZFILESIZ)) == NULL) {
  1334. CloseHandle(hFile);
  1335. return FALSE;
  1336. }
  1337. if ((lpDizWrkBuf = MemAlloc(DIZINFWRK)) == NULL) {
  1338. MemFree(lpDizBuf);
  1339. CloseHandle(hFile);
  1340. return FALSE;
  1341. }
  1342. if (FALSE == ReadFile(hFile, lpDizBuf, DIZFILESIZ, &dwRet, NULL)) {
  1343. ERR(("Error reading DIZ file %ws (%d)\n", filNam, GetLastError()));
  1344. // Abort
  1345. MemFree(lpDizWrkBuf);
  1346. MemFree(lpDizBuf);
  1347. CloseHandle(hFile);
  1348. return FALSE;
  1349. }
  1350. MY_VERBOSE(("N501_ColDizInfSet() ColMon=[%d] PrnMod=[%d] PrnKnd=[%d] DizKnd=[%d] DizPat=[%d]\n",
  1351. lpDiz->ColMon, lpDiz->PrnMod, lpDiz->PrnKnd, lpDiz->DizKnd, lpDiz->DizPat));
  1352. MY_VERBOSE((" DizSls=[%d] SizCyn=[%d] SizMgt=[%d] SizYel=[%d] SizBla=[%d]\n",
  1353. lpDiz->DizSls, lpDiz->SizCyn, lpDiz->SizMgt, lpDiz->SizYel, lpDiz->SizBla));
  1354. if ((N501_ColDizInfSet((LPBYTE)lpDizBuf, lpDiz, lpDizWrkBuf)) != ERRNON) {
  1355. MemFree(lpDizWrkBuf);
  1356. MemFree(lpDizBuf);
  1357. CloseHandle(hFile);
  1358. return FALSE;
  1359. }
  1360. MemFree(lpDizWrkBuf);
  1361. MemFree(lpDizBuf);
  1362. CloseHandle(hFile);
  1363. MY_VERBOSE(("DizFileOpen() End\n"));
  1364. return TRUE;
  1365. }
  1366. //#if defined(CPN5SERIES) // N501
  1367. //===================================================================================================
  1368. // Make UCR table
  1369. //===================================================================================================
  1370. BOOL ColUcrTblMak( // TRUE / FALSE
  1371. PDEVOBJ pdevobj, // Pointer to pdevobj structure
  1372. LPCMYK LutAdr // LUT address
  1373. )
  1374. {
  1375. LPCOLMCHINF lpColMch;
  1376. LPBYTE lpUcrTbl;
  1377. LPBYTE lpUcrWrk;
  1378. PMYPDEV pOEM = (PMYPDEV)pdevobj->pdevOEM;
  1379. MY_VERBOSE(("\nColUcrTblMak() MemAlloc(UCRTBLSIZ)\n"));
  1380. lpColMch = pOEM->Col.Mch.lpColMch;
  1381. if ((lpUcrTbl = MemAlloc(UCRTBLSIZ)) == NULL) {
  1382. return FALSE;
  1383. }
  1384. MY_VERBOSE(("ColUcrTblMak() MemAlloc(UCRWRKSIZ)\n"));
  1385. if ((lpUcrWrk = MemAlloc(UCRWRKSIZ)) == NULL) {
  1386. MemFree(lpUcrTbl);
  1387. return FALSE;
  1388. }
  1389. MY_VERBOSE(("ColUcrTblMak() N501_ColUcrTblMak()\n"));
  1390. if ((N501_ColUcrTblMak(lpColMch->Mch, LutAdr, (LPCMYK)lpUcrTbl, lpUcrWrk)) != ERRNON) {
  1391. MemFree(lpUcrWrk);
  1392. MemFree(lpUcrTbl);
  1393. return FALSE;
  1394. }
  1395. lpColMch->UcrTbl = (LPCMYK)lpUcrTbl;
  1396. pOEM->Col.lpUcr = lpUcrTbl;
  1397. MemFree(lpUcrWrk);
  1398. MY_VERBOSE(("ColUcrTblMak() End\n"));
  1399. return TRUE;
  1400. }
  1401. //===================================================================================================
  1402. // Make Gray transfer table
  1403. //===================================================================================================
  1404. BOOL ColGryTblMak( // TRUE / FALSE
  1405. PDEVOBJ pdevobj, // Pointer to pdevobj structure
  1406. LPCMYK LutAdr // LUT address
  1407. )
  1408. {
  1409. LPCOLMCHINF lpColMch;
  1410. LPBYTE lpGryTbl;
  1411. LPBYTE lpCmpBuf;
  1412. PMYPDEV pOEM = (PMYPDEV)pdevobj->pdevOEM;
  1413. MY_VERBOSE(("\nColGryTblMak() \n"));
  1414. lpColMch = pOEM->Col.Mch.lpColMch;
  1415. if ((lpGryTbl = MemAlloc(GRYTBLSIZ)) == NULL) { // Gray transfer table area
  1416. return FALSE;
  1417. }
  1418. if ((lpCmpBuf = MemAlloc(LUTGLBWRK)) == NULL) { // Gray transfer table work area
  1419. MemFree(lpGryTbl);
  1420. return FALSE;
  1421. }
  1422. // Make Gray transfer table
  1423. if ((N501_ColGryTblMak(lpColMch->Mch, LutAdr, lpGryTbl, lpCmpBuf)) != ERRNON) {
  1424. MemFree(lpCmpBuf);
  1425. MemFree(lpGryTbl);
  1426. return FALSE;
  1427. }
  1428. lpColMch->GryTbl = (LPBYTE)lpGryTbl;
  1429. pOEM->Col.lpGryTbl = lpGryTbl;
  1430. MemFree(lpCmpBuf);
  1431. MY_VERBOSE(("ColGryTblMak() End\n"));
  1432. return TRUE;
  1433. }
  1434. //#endif
  1435. //#if defined(CPN5SERIES) || defined(CPE8SERIES) // N501
  1436. //===================================================================================================
  1437. // Make LUT table (MONO)
  1438. //===================================================================================================
  1439. BOOL ColLutMakGlbMon( // TRUE / FALSE
  1440. PDEVOBJ pdevobj // Pointer to pdevobj structure
  1441. )
  1442. {
  1443. LPCOLMCHINF lpColMch;
  1444. LPRGB lpRGB;
  1445. LPBYTE lpLutMakGlbBuf;
  1446. LPBYTE lpLutMakGlbWrk;
  1447. PMYPDEV pOEM = (PMYPDEV)pdevobj->pdevOEM;
  1448. MY_VERBOSE(("\nColLutMakGlbMon() \n"));
  1449. lpColMch = pOEM->Col.Mch.lpColMch;
  1450. lpRGB = NULL; // Not sRGB
  1451. // Global LUT area
  1452. if ((lpLutMakGlbBuf = MemAlloc(LUTMAKGLBSIZ)) == NULL) {
  1453. return FALSE;
  1454. }
  1455. if ((lpLutMakGlbWrk = MemAlloc(LUTGLBWRK)) == NULL) { // Global LUT work area
  1456. MemFree(lpLutMakGlbBuf);
  1457. return FALSE;
  1458. }
  1459. // Make Gray transfer table (MONO)
  1460. if ((N501_ColLutMakGlbMon(lpRGB, pOEM->Col.Mch.lpRGBInf, pOEM->Col.Mch.lpCMYKInf,
  1461. (LPCMYK)lpLutMakGlbBuf, lpLutMakGlbWrk)) != ERRNON) {
  1462. MemFree(lpLutMakGlbWrk);
  1463. MemFree(lpLutMakGlbBuf);
  1464. return FALSE;
  1465. }
  1466. lpColMch->LutAdr = (LPCMYK)lpLutMakGlbBuf;
  1467. pOEM->Col.lpLutMakGlb = lpLutMakGlbBuf;
  1468. pOEM->Col.Mch.LutMakGlb = Yes;
  1469. MemFree(lpLutMakGlbWrk);
  1470. MY_VERBOSE(("ColLutMakGlbMon() End\n"));
  1471. return TRUE;
  1472. }
  1473. //#endif
  1474. // End of File