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.

1320 lines
54 KiB

  1. //***************************************************************************************************
  2. // N5COLMH.C
  3. //
  4. // Functions color matching (For N5 printer)
  5. //---------------------------------------------------------------------------------------------------
  6. // copyright(C) 1997-2000 CASIO COMPUTER CO.,LTD. / CASIO ELECTRONICS MANUFACTURING CO.,LTD.
  7. //***************************************************************************************************
  8. #include <WINDOWS.H>
  9. #include <WINBASE.H>
  10. #include "COLDEF.H"
  11. #include "COMDIZ.H"
  12. #include "N5COLMH.H"
  13. #include "strsafe.h" // Security-Code 2002.3.6
  14. //===================================================================================================
  15. // Dot gain revision table
  16. //===================================================================================================
  17. //static BYTE GinTblP10[256] = {
  18. // /* 00 */ 0x00,0x01,0x02,0x04,0x05,0x06,0x07,0x09,
  19. // /* 08 */ 0x0a,0x0b,0x0c,0x0d,0x0f,0x10,0x11,0x12,
  20. // /* 10 */ 0x13,0x15,0x16,0x17,0x18,0x1a,0x1b,0x1c,
  21. // /* 18 */ 0x1d,0x1e,0x20,0x21,0x22,0x23,0x24,0x26,
  22. // /* 20 */ 0x27,0x28,0x29,0x2b,0x2c,0x2d,0x2e,0x2f,
  23. // /* 28 */ 0x31,0x32,0x33,0x34,0x35,0x37,0x38,0x39,
  24. // /* 30 */ 0x3a,0x3b,0x3d,0x3e,0x3f,0x40,0x41,0x43,
  25. // /* 38 */ 0x44,0x45,0x46,0x47,0x48,0x4a,0x4b,0x4c,
  26. // /* 40 */ 0x4d,0x4e,0x50,0x51,0x52,0x53,0x54,0x55,
  27. // /* 48 */ 0x57,0x58,0x59,0x5a,0x5b,0x5c,0x5e,0x5f,
  28. // /* 50 */ 0x60,0x61,0x62,0x63,0x65,0x66,0x67,0x68,
  29. // /* 58 */ 0x69,0x6a,0x6b,0x6d,0x6e,0x6f,0x70,0x71,
  30. // /* 60 */ 0x72,0x73,0x74,0x76,0x77,0x78,0x79,0x7a,
  31. // /* 68 */ 0x7b,0x7c,0x7d,0x7e,0x7f,0x81,0x82,0x83,
  32. // /* 70 */ 0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,
  33. // /* 78 */ 0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,
  34. // /* 80 */ 0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,
  35. // /* 88 */ 0x9b,0x9c,0x9d,0x9e,0x9f,0xa0,0xa1,0xa2,
  36. // /* 90 */ 0xa3,0xa4,0xa5,0xa5,0xa6,0xa7,0xa8,0xa9,
  37. // /* 98 */ 0xaa,0xab,0xac,0xac,0xad,0xae,0xaf,0xb0,
  38. // /* a0 */ 0xb1,0xb2,0xb3,0xb3,0xb4,0xb5,0xb6,0xb7,
  39. // /* a8 */ 0xb8,0xb9,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,
  40. // /* b0 */ 0xbe,0xbf,0xc0,0xc1,0xc2,0xc3,0xc4,0xc4,
  41. // /* b8 */ 0xc5,0xc6,0xc7,0xc8,0xc9,0xc9,0xca,0xcb,
  42. // /* c0 */ 0xcc,0xcd,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,
  43. // /* c8 */ 0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd7,0xd8,
  44. // /* d0 */ 0xd9,0xda,0xdb,0xdb,0xdc,0xdd,0xde,0xdf,
  45. // /* d8 */ 0xdf,0xe0,0xe1,0xe2,0xe3,0xe4,0xe4,0xe5,
  46. // /* e0 */ 0xe6,0xe7,0xe8,0xe8,0xe9,0xea,0xeb,0xec,
  47. // /* e8 */ 0xec,0xed,0xee,0xef,0xf0,0xf0,0xf1,0xf2,
  48. // /* f0 */ 0xf3,0xf4,0xf5,0xf5,0xf6,0xf7,0xf8,0xf9,
  49. // /* f8 */ 0xf9,0xfa,0xfb,0xfc,0xfd,0xfd,0xfe,0xff
  50. //};
  51. //---------------------------------------------------------------------------------------------------
  52. // Color matching(high speed)
  53. //---------------------------------------------------------------------------------------------------
  54. #if !defined(CP80W9X) // CP-E8000 is invalid
  55. static VOID ExeColMch000(
  56. DWORD,
  57. LPRGB,
  58. LPCMYK,
  59. LPCOLMCHINF
  60. );
  61. #endif
  62. //---------------------------------------------------------------------------------------------------
  63. // Color matching(normal speed)
  64. //---------------------------------------------------------------------------------------------------
  65. #if !defined(CP80W9X) // CP-E8000 is invalid
  66. static VOID ExeColMch001(
  67. DWORD,
  68. LPRGB,
  69. LPCMYK,
  70. LPCOLMCHINF
  71. );
  72. #endif
  73. //---------------------------------------------------------------------------------------------------
  74. // Color matching(solid)
  75. //---------------------------------------------------------------------------------------------------
  76. static VOID ExeColCnvSld(
  77. DWORD,
  78. LPRGB,
  79. LPCMYK,
  80. LPCOLMCHINF
  81. );
  82. //---------------------------------------------------------------------------------------------------
  83. // RGB -> CMYK(2Level) conversion (for 1dot line)
  84. //---------------------------------------------------------------------------------------------------
  85. #if !defined(CP80W9X) // CP-E8000 is invalid
  86. static VOID ExeColCnvL02(
  87. DWORD,
  88. LPRGB,
  89. LPCMYK
  90. );
  91. #endif
  92. //---------------------------------------------------------------------------------------------------
  93. // RGB -> K conversion (for monochrome)
  94. //---------------------------------------------------------------------------------------------------
  95. static VOID ExeColCnvMon(
  96. DWORD,
  97. LPRGB,
  98. LPCMYK,
  99. LPCOLMCHINF
  100. );
  101. //---------------------------------------------------------------------------------------------------
  102. // Color matching(UCR)
  103. //---------------------------------------------------------------------------------------------------
  104. #if !defined(CP80W9X) // CP-E8000 is invalid
  105. static VOID ExeColMchUcr(
  106. LPCMYK,
  107. LPRGB,
  108. DWORD,
  109. DWORD,
  110. DWORD,
  111. DWORD, //+ UCR (Toner gross weight) CASIO 2001/02/15
  112. LPCMYK
  113. );
  114. #endif
  115. //***************************************************************************************************
  116. // Function
  117. //***************************************************************************************************
  118. //===================================================================================================
  119. // Cache table initialize
  120. //===================================================================================================
  121. VOID WINAPI N501ColCchIni( // Return value no
  122. LPCOLMCHINF mchInf // Color matching information
  123. )
  124. {
  125. DWORD cnt;
  126. RGBS colRgb;
  127. CMYK colCmy;
  128. LPRGB cchRgb;
  129. LPCMYK cchCmy;
  130. if ((mchInf->CchRgb == NULL) || (mchInf->CchCmy == NULL)) return;
  131. cchRgb = mchInf->CchRgb;
  132. cchCmy = mchInf->CchCmy;
  133. colRgb.Red = colRgb.Grn = colRgb.Blu = 255;
  134. colCmy.Cyn = colCmy.Mgt = colCmy.Yel = colCmy.Bla = 0;
  135. /*----- Cache table initialize -----------------------------------*/
  136. for (cnt = 0; cnt < CCHTBLSIZ; cnt++) {
  137. *cchRgb = colRgb;
  138. *cchCmy = colCmy;
  139. cchRgb++;
  140. cchCmy++;
  141. }
  142. return;
  143. }
  144. //===================================================================================================
  145. // Gray transfer table make
  146. //===================================================================================================
  147. #if !defined(CP80W9X) // CP-E8000 is invalid
  148. DWORD WINAPI N501ColGryTblMak( // ERRNON : OK
  149. // ERRILLPRM : Parameter error
  150. DWORD colMch, // Color matching
  151. LPCMYK lutAdr, // LUT address
  152. LPBYTE gryTbl, // Gray transfer table (*1)
  153. LPBYTE wrk // Work (*2)
  154. )
  155. {
  156. COLMCHINF mchInf; // Color matching information
  157. LPRGB rgb; // struct ColRgb rgb[256]
  158. LPCMYK gry; // struct ColCmy gry[256]
  159. DWORD n, tmp, tmC, tmM, tmY;
  160. /*----- Input parameter check --------------------------------------------------*/
  161. if ((lutAdr == NULL) || (gryTbl == NULL) || (wrk == NULL)) return ERRILLPRM;
  162. /*----- Work buffer setting ----------------------------------------------------*/
  163. rgb = (LPRGB)wrk; /* Work for gray transformation RGB 768B */
  164. gry = (LPCMYK)(wrk + (sizeof(RGBS) * 256));
  165. /* Work for gray transformation CMYK 1024B */
  166. /*----- Color matching information setting for gray value table generation -----*/
  167. mchInf.Mch = MCHNML; /* Color matching nornal */
  168. mchInf.Bla = KCGNON; /* Black replacement NO Fixed */
  169. mchInf.Ucr = UCRNOO; /* UCR NO Fixed */
  170. mchInf.LutAdr = lutAdr; /* LUT address input value */
  171. mchInf.ColQty = (DWORD)0; /* Color quality 0 Fixed */
  172. mchInf.ColAdr = NULL; /* Color address NULL Fixed */
  173. mchInf.CchRgb = NULL; /* Cache for RGB NULL Fixed */
  174. mchInf.CchCmy = NULL; /* Cache for CMYK NULL Fixed */
  175. /*----- Gray value(RGB value before transformation) setting --------------------*/
  176. for (n = 0; n < (DWORD)256; n++)
  177. rgb[n].Red = rgb[n].Grn = rgb[n].Blu = (BYTE)n;
  178. /*----- Gray value(RGB -> CMYK) ------------------------------------------------*/
  179. switch (colMch) {
  180. case MCHNML: ExeColMch001((DWORD)256, rgb, gry, &mchInf); break;
  181. default: ExeColCnvSld((DWORD)256, rgb, gry, &mchInf); break;
  182. }
  183. /*----- Gray transfer table setting --------------------------------------------*/
  184. for (n = 0; n < (DWORD)256; n++) {
  185. tmC = gry[n].Cyn;
  186. tmM = gry[n].Mgt;
  187. tmY = gry[n].Yel;
  188. tmp = (tmC * (DWORD)30 + tmM * (DWORD)59 + tmY * (DWORD)11) / (DWORD)100;
  189. gryTbl[n] = (BYTE)tmp;
  190. }
  191. gryTbl[255] = (BYTE)0; /* White is '0' fix */
  192. /* gryTbl[0] �` [16] adjusted to line (gryTbl[0](Black) is '255' fix) */
  193. tmp = (DWORD)255 - gryTbl[16];
  194. for (n = 0; n < (DWORD)16; n++) {
  195. gryTbl[n] = (BYTE)((tmp * ((DWORD)16 - n)) / (DWORD)16) + gryTbl[16];
  196. }
  197. return ERRNON;
  198. }
  199. #endif
  200. //===================================================================================================
  201. // UCR table Make
  202. //===================================================================================================
  203. #if !defined(CP80W9X) // CP-E8000 is invalid
  204. DWORD WINAPI N501ColUcrTblMak( // ERRNON : OK
  205. // ERRILLPRM : Parameter error
  206. DWORD colMch, // Color matching
  207. LPCMYK lutAdr, // LUT address
  208. LPCMYK ucrTbl, // Table for UCR
  209. LPBYTE wrk // Work
  210. )
  211. {
  212. COLMCHINF mchInf; // Color matching information
  213. LPRGB rgb; // struct ColRgb rgb[256]
  214. LPCMYK gry; // struct ColCmy gry[257]
  215. LPCMYK gryCyn; // Gray value (Cyan conversion value)
  216. LPCMYK dnsCyn; // Density value (Cyan conversion value)
  217. DWORD loC, hiC, loM, hiM, loY, hiY, loK, hiK, saC, saM, saY, saK, n, m;
  218. DWORD tmp, tmC, tmM, tmY;
  219. /*----- Input parameter check --------------------------------------------------*/
  220. if ((colMch != MCHFST) && (colMch != MCHNML) && (colMch != MCHSLD))
  221. return ERRILLPRM;
  222. if ((lutAdr == NULL) || (ucrTbl == NULL) || (wrk == NULL)) return ERRILLPRM;
  223. /*----- Work buffer setting ----------------------------------------------------*/
  224. rgb = (LPRGB)wrk; /* Work for gray transformation RGB 768B */
  225. gry = (LPCMYK)(wrk + (sizeof(RGBS) * 256));
  226. /* Work for gray transformation CMYK 1028B */
  227. /*----- LUT table pointer setting ----------------------------------------------*/
  228. gryCyn = ucrTbl;
  229. dnsCyn = ucrTbl + 256;
  230. /*----- Color matching information setting for gray value table generation -----*/
  231. mchInf.Mch = colMch; /* Color matching input value */
  232. mchInf.Bla = KCGNON; /* Black replacement NO Fixed */
  233. mchInf.Ucr = UCRNOO; /* UCR NO Fixed */
  234. mchInf.LutAdr = lutAdr; /* LUT address input value */
  235. mchInf.ColQty = (DWORD)0; /* Color quality 0 Fixed */
  236. mchInf.ColAdr = NULL; /* Color address NULL Fixed */
  237. mchInf.CchRgb = NULL; /* Cache for RGB NULL Fixed */
  238. mchInf.CchCmy = NULL; /* Cache for CMYK NULL Fixed */
  239. /*----- Gray value(RGB value before transformation) setting ---------------------*/
  240. for (n = 0; n < (DWORD)256; n++)
  241. rgb[n].Red = rgb[n].Grn = rgb[n].Blu = (BYTE)(255 - n);
  242. /*----- Gray value(RGB -> CMYK) -------------------------------------------------*/
  243. switch (colMch) {
  244. case MCHFST: ExeColMch000((DWORD)256, rgb, gry, &mchInf); break;
  245. case MCHNML: ExeColMch001((DWORD)256, rgb, gry, &mchInf); break;
  246. // default: ExeColCnvSld((DWORD)256, rgb, gry, mchInf.Bla); break;
  247. default: ExeColCnvSld((DWORD)256, rgb, gry, &mchInf); break;
  248. }
  249. /*----- Gray value(K) setting ---------------------------------------------------*/
  250. // for (n = 0; n < (DWORD)256; n++) gry[n].Bla = GinTblP10[n];
  251. for (n = 0; n < (DWORD)256; n++) {
  252. //CASIO 2001/02/15 ->
  253. // tmC = gry[255 - n].Cyn;
  254. // tmM = gry[255 - n].Mgt;
  255. // tmY = gry[255 - n].Yel;
  256. tmC = gry[n].Cyn;
  257. tmM = gry[n].Mgt;
  258. tmY = gry[n].Yel;
  259. tmp = (tmC * (DWORD)30 + tmM * (DWORD)59 + tmY * (DWORD)11) / (DWORD)100;
  260. // gry[n].Bla = (BYTE)(255 - tmp);
  261. gry[n].Bla = (BYTE)tmp;
  262. //CASIO 2001/02/15 <-
  263. }
  264. /* gry[0] �` [16].Bla adjusted to line (gry[0].Bla(White) is '0' fix) */
  265. tmp = gry[16].Bla;
  266. for (n = 0; n < (DWORD)16; n++) {
  267. gry[n].Bla = (BYTE)((tmp * n + (DWORD)15) / (DWORD)16);
  268. }
  269. /*----- Gray value, Limiter value setting for density value calculation ---------*/
  270. gry[256].Cyn = gry[256].Mgt = gry[256].Yel = gry[256].Bla = (BYTE)255;
  271. /*----- Gray value, Density value(Each Cyan conversion value) calculation -------*/
  272. for (n = 0; n < (DWORD)256; n++) {
  273. loC = gry[n].Cyn; hiC = gry[n + 1].Cyn; saC = (hiC > loC)? hiC - loC: 0;
  274. loM = gry[n].Mgt; hiM = gry[n + 1].Mgt; saM = (hiM > loM)? hiM - loM: 0;
  275. loY = gry[n].Yel; hiY = gry[n + 1].Yel; saY = (hiY > loY)? hiY - loY: 0;
  276. loK = gry[n].Bla; hiK = gry[n + 1].Bla; saK = (hiK > loK)? hiK - loK: 0;
  277. for (m = 0; m < saC; m++) gryCyn[m + loC].Mgt = (BYTE)(saM * m / saC + loM);
  278. for (m = 0; m < saC; m++) gryCyn[m + loC].Yel = (BYTE)(saY * m / saC + loY);
  279. for (m = 0; m < saC; m++) gryCyn[m + loC].Bla = (BYTE)(saK * m / saC + loK);
  280. for (m = 0; m < saM; m++) dnsCyn[m + loM].Mgt = (BYTE)(saC * m / saM + loC);
  281. for (m = 0; m < saY; m++) dnsCyn[m + loY].Yel = (BYTE)(saC * m / saY + loC);
  282. }
  283. //CASIO 2001/02/15 ->
  284. gryCyn[255].Mgt = gryCyn[255].Yel = gryCyn[255].Bla =
  285. dnsCyn[255].Mgt = dnsCyn[255].Yel = (BYTE)255;
  286. //CASIO 2001/02/15 <-
  287. return ERRNON;
  288. }
  289. #endif
  290. //===================================================================================================
  291. // Color matching procedure
  292. //---------------------------------------------------------------------------------------------------
  293. // RGB -> CMYK
  294. //===================================================================================================
  295. VOID WINAPI N501ColMchPrc( // Return value no
  296. DWORD xaxSiz, // X Size (Pixel)
  297. LPRGB rgbAdr, // RGB (input)
  298. LPCMYK cmyAdr, // CMYK (output)
  299. LPCOLMCHINF mchInf // Color matching information
  300. )
  301. {
  302. switch (mchInf->Mch) {
  303. #if !defined(CP80W9X) // CP-E8000 is invalid
  304. case MCHFST: // LUT transformation(high speed)
  305. ExeColMch000(xaxSiz, rgbAdr, cmyAdr, mchInf);
  306. break;
  307. case MCHNML: // LUT transformation(normal speed)
  308. ExeColMch001(xaxSiz, rgbAdr, cmyAdr, mchInf);
  309. break;
  310. case MCHSLD: // NO (solid)
  311. // ExeColCnvSld(xaxSiz, rgbAdr, cmyAdr, mchInf->Bla);
  312. ExeColCnvSld(xaxSiz, rgbAdr, cmyAdr, mchInf);
  313. break;
  314. case MCHPRG: // Primary color(progressive)
  315. ExeColCnvL02(xaxSiz, rgbAdr, cmyAdr);
  316. break;
  317. #endif
  318. case MCHMON: // Monochrome
  319. // ExeColCnvMon(xaxSiz, rgbAdr, cmyAdr);
  320. ExeColCnvMon(xaxSiz, rgbAdr, cmyAdr, mchInf);
  321. break;
  322. default: // Indistinct
  323. // ExeColCnvSld(xaxSiz, rgbAdr, cmyAdr, mchInf->Bla);
  324. ExeColCnvSld(xaxSiz, rgbAdr, cmyAdr, mchInf);
  325. }
  326. return;
  327. }
  328. //===================================================================================================
  329. // Palette table transformation procedure
  330. //---------------------------------------------------------------------------------------------------
  331. // RGB -> CMYK
  332. //===================================================================================================
  333. #if !defined(CP80W9X) // CP-E8000����
  334. VOID WINAPI N501ColPtcPrc( // Return value no
  335. DWORD colBit, // Data bit value
  336. DWORD xaxSiz, // Xsize (pixel)
  337. LPBYTE srcAdr, // RGB (input)
  338. LPCMYK dstAdr, // CMYK (output)
  339. LPCMYK pltAdr // Palette table address
  340. )
  341. {
  342. DWORD cntXax;
  343. DWORD cntBit;
  344. DWORD bitNum;
  345. BYTE pltNum;
  346. /*===== 256 color (8bit) ===============================================*/
  347. if (colBit == 8) {
  348. for (cntXax = xaxSiz; cntXax > 0; cntXax--) {
  349. *dstAdr = pltAdr[*srcAdr]; dstAdr++;
  350. srcAdr++;
  351. }
  352. return;
  353. }
  354. /*===== 16 color (4bit) ================================================*/
  355. if (colBit == 4) {
  356. for (cntXax = xaxSiz / 2; cntXax > 0; cntXax--) {
  357. *dstAdr = pltAdr[*srcAdr >> 4]; dstAdr++; *srcAdr <<= 4;
  358. *dstAdr = pltAdr[*srcAdr >> 4]; dstAdr++;
  359. srcAdr++;
  360. }
  361. if (xaxSiz % 2)
  362. *dstAdr = pltAdr[*srcAdr >> 4];
  363. return;
  364. }
  365. /*==== 4 color (2bit) =================================================*/
  366. if (colBit == 2) {
  367. for (cntXax = xaxSiz / 4; cntXax > 0; cntXax--) {
  368. *dstAdr = pltAdr[*srcAdr >> 6]; dstAdr++; *srcAdr <<= 2;
  369. *dstAdr = pltAdr[*srcAdr >> 6]; dstAdr++; *srcAdr <<= 2;
  370. *dstAdr = pltAdr[*srcAdr >> 6]; dstAdr++; *srcAdr <<= 2;
  371. *dstAdr = pltAdr[*srcAdr >> 6]; dstAdr++;
  372. srcAdr++;
  373. }
  374. for (cntXax = xaxSiz % 4; cntXax > 0; cntXax--) {
  375. *dstAdr = pltAdr[*srcAdr >> 6]; dstAdr++; *srcAdr <<= 2;
  376. }
  377. return;
  378. }
  379. /*===== 2 color (1bit) ================================================*/
  380. if (colBit == 1) {
  381. for (cntXax = xaxSiz / 8; cntXax > 0; cntXax--) {
  382. *dstAdr = pltAdr[*srcAdr >> 7]; dstAdr++; *srcAdr <<= 1;
  383. *dstAdr = pltAdr[*srcAdr >> 7]; dstAdr++; *srcAdr <<= 1;
  384. *dstAdr = pltAdr[*srcAdr >> 7]; dstAdr++; *srcAdr <<= 1;
  385. *dstAdr = pltAdr[*srcAdr >> 7]; dstAdr++; *srcAdr <<= 1;
  386. *dstAdr = pltAdr[*srcAdr >> 7]; dstAdr++; *srcAdr <<= 1;
  387. *dstAdr = pltAdr[*srcAdr >> 7]; dstAdr++; *srcAdr <<= 1;
  388. *dstAdr = pltAdr[*srcAdr >> 7]; dstAdr++; *srcAdr <<= 1;
  389. *dstAdr = pltAdr[*srcAdr >> 7]; dstAdr++;
  390. srcAdr++;
  391. }
  392. for (cntXax = xaxSiz % 8; cntXax > 0; cntXax--) {
  393. *dstAdr = pltAdr[*srcAdr >> 7]; dstAdr++; *srcAdr <<= 1;
  394. }
  395. return;
  396. }
  397. /*===== Others(7, 6, 5, 3bit) =========================================*/
  398. bitNum = 0;
  399. for (cntXax = 0; cntXax < xaxSiz; cntXax++) {
  400. pltNum = (BYTE)0x00;
  401. for (cntBit = colBit; cntBit > 0; cntBit--) {
  402. if (srcAdr[bitNum / 8] & ((BYTE)0x80 >> bitNum % 8)) {
  403. pltNum |= ((BYTE)0x01 << (cntBit - 1));
  404. }
  405. bitNum++;
  406. }
  407. *dstAdr = pltAdr[pltNum]; dstAdr++;
  408. }
  409. return;
  410. }
  411. #endif
  412. //===================================================================================================
  413. // CMYK -> RGB conversion
  414. //===================================================================================================
  415. VOID WINAPI N501ColCnvC2r( // Return value no
  416. DWORD xaxSiz, // Xsize (pixel)
  417. LPCMYK cmyAdr, // CMYK (input)
  418. LPRGB rgbAdr, // RGB (output)
  419. DWORD gldNum, // LUT Grid number
  420. LPBYTE lutTblRgb // LUT Address (R->G->B)
  421. )
  422. {
  423. DWORD tmpC00, tmpM00, tmpY00, tmpK00;
  424. DWORD tmpC01, tmpM01, tmpY01, tmpK01;
  425. DWORD lenCyn, lenMgt, lenYel, lenBla;
  426. DWORD tmpRed, tmpGrn, tmpBlu;
  427. DWORD calPrm;
  428. LPCMYK endAdr;
  429. LPRGB lutCmy;
  430. RGBS tmpRgb, tmpRgbSav;
  431. LPRGB lutTbl;
  432. RGBS lutTbl000;
  433. lutTbl = (LPRGB)lutTblRgb;
  434. lutTbl000.Red = lutTbl->Blu;
  435. lutTbl000.Grn = lutTbl->Grn;
  436. lutTbl000.Blu = lutTbl->Red;
  437. for (endAdr = cmyAdr + xaxSiz; cmyAdr < endAdr; cmyAdr++) {
  438. tmpC00 = cmyAdr->Cyn;
  439. tmpM00 = cmyAdr->Mgt;
  440. tmpY00 = cmyAdr->Yel;
  441. tmpK00 = cmyAdr->Bla;
  442. /*----- Monochrome ----------------------------------------------------------*/
  443. if ((tmpC00 | tmpM00 | tmpY00) == 0) {
  444. if (tmpK00 == 0) { *rgbAdr = lutTbl000; rgbAdr++; continue; }
  445. tmpK01 = tmpK00;
  446. tmpK00 = tmpK00 * (gldNum - 1) / 255;
  447. lenBla = tmpK01 * (gldNum - 1) - tmpK00 * 255;
  448. tmpK01 = (tmpK01 * (gldNum - 1) + 254) / 255;
  449. calPrm = (DWORD)255 - lenBla;
  450. tmpRgb = lutTbl[tmpK00 * gldNum * gldNum * gldNum];
  451. tmpRed = calPrm * tmpRgb.Red;
  452. tmpGrn = calPrm * tmpRgb.Grn;
  453. tmpBlu = calPrm * tmpRgb.Blu;
  454. calPrm = lenBla;
  455. tmpRgb = lutTbl[tmpK01 * gldNum * gldNum * gldNum];
  456. tmpRed += calPrm * tmpRgb.Red;
  457. tmpGrn += calPrm * tmpRgb.Grn;
  458. tmpBlu += calPrm * tmpRgb.Blu;
  459. tmpRed += (DWORD)255 / 2;
  460. tmpGrn += (DWORD)255 / 2;
  461. tmpBlu += (DWORD)255 / 2;
  462. // tmpRgb.Red = (BYTE)(tmpRed / (DWORD)255);
  463. // tmpRgb.Blu = (BYTE)(tmpBlu / (DWORD)255);
  464. tmpRgb.Red = (BYTE)(tmpBlu / (DWORD)255);
  465. tmpRgb.Grn = (BYTE)(tmpGrn / (DWORD)255);
  466. tmpRgb.Blu = (BYTE)(tmpRed / (DWORD)255);
  467. *rgbAdr = tmpRgb;
  468. rgbAdr++;
  469. continue;
  470. }
  471. /*----- CMYK -> RGB ---------------------------------------------------------*/
  472. tmpC01 = tmpC00;
  473. tmpC00 = tmpC00 * (gldNum - 1) / 255;
  474. lenCyn = tmpC01 * (gldNum - 1) - tmpC00 * 255;
  475. tmpC01 = (tmpC01 * (gldNum - 1) + 254) / 255;
  476. tmpM01 = tmpM00;
  477. tmpM00 = tmpM00 * (gldNum - 1) / 255;
  478. lenMgt = tmpM01 * (gldNum - 1) - tmpM00 * 255;
  479. tmpM01 = (tmpM01 * (gldNum - 1) + 254) / 255;
  480. tmpY01 = tmpY00;
  481. tmpY00 = tmpY00 * (gldNum - 1) / 255;
  482. lenYel = tmpY01 * (gldNum - 1) - tmpY00 * 255;
  483. tmpY01 = (tmpY01 * (gldNum - 1) + 254) / 255;
  484. tmpK01 = tmpK00;
  485. tmpK00 = tmpK00 * (gldNum - 1) / 255;
  486. lenBla = tmpK01 * (gldNum - 1) - tmpK00 * 255;
  487. tmpK01 = (tmpK01 * (gldNum - 1) + 254) / 255;
  488. lutCmy = lutTbl + tmpK00 * gldNum * gldNum * gldNum;
  489. /* 0 */
  490. calPrm = ((DWORD)255-lenCyn)*((DWORD)255-lenMgt)*((DWORD)255-lenYel);
  491. tmpRgb = lutCmy[((tmpC00*gldNum)+tmpM00)*gldNum+tmpY00];
  492. tmpRed = calPrm * tmpRgb.Red;
  493. tmpGrn = calPrm * tmpRgb.Grn;
  494. tmpBlu = calPrm * tmpRgb.Blu;
  495. /* 1 */
  496. calPrm = ((DWORD)255-lenCyn)*((DWORD)255-lenMgt)*lenYel;
  497. tmpRgb = lutCmy[((tmpC00*gldNum)+tmpM00)*gldNum+tmpY01];
  498. tmpRed += calPrm * tmpRgb.Red;
  499. tmpGrn += calPrm * tmpRgb.Grn;
  500. tmpBlu += calPrm * tmpRgb.Blu;
  501. /* 2 */
  502. calPrm = ((DWORD)255-lenCyn)*lenMgt*((DWORD)255-lenYel);
  503. tmpRgb = lutCmy[((tmpC00*gldNum)+tmpM01)*gldNum+tmpY00];
  504. tmpRed += calPrm * tmpRgb.Red;
  505. tmpGrn += calPrm * tmpRgb.Grn;
  506. tmpBlu += calPrm * tmpRgb.Blu;
  507. /* 3 */
  508. calPrm = ((DWORD)255-lenCyn)*lenMgt*lenYel;
  509. tmpRgb = lutCmy[((tmpC00*gldNum)+tmpM01)*gldNum+tmpY01];
  510. tmpRed += calPrm * tmpRgb.Red;
  511. tmpGrn += calPrm * tmpRgb.Grn;
  512. tmpBlu += calPrm * tmpRgb.Blu;
  513. /* 4 */
  514. calPrm = lenCyn*((DWORD)255-lenMgt)*((DWORD)255-lenYel);
  515. tmpRgb = lutCmy[((tmpC01*gldNum)+tmpM00)*gldNum+tmpY00];
  516. tmpRed += calPrm * tmpRgb.Red;
  517. tmpGrn += calPrm * tmpRgb.Grn;
  518. tmpBlu += calPrm * tmpRgb.Blu;
  519. /* 5 */
  520. calPrm = lenCyn*((DWORD)255-lenMgt)*lenYel;
  521. tmpRgb = lutCmy[((tmpC01*gldNum)+tmpM00)*gldNum+tmpY01];
  522. tmpRed += calPrm * tmpRgb.Red;
  523. tmpGrn += calPrm * tmpRgb.Grn;
  524. tmpBlu += calPrm * tmpRgb.Blu;
  525. /* 6 */
  526. calPrm = lenCyn*lenMgt*((DWORD)255-lenYel);
  527. tmpRgb = lutCmy[((tmpC01*gldNum)+tmpM01)*gldNum+tmpY00];
  528. tmpRed += calPrm * tmpRgb.Red;
  529. tmpGrn += calPrm * tmpRgb.Grn;
  530. tmpBlu += calPrm * tmpRgb.Blu;
  531. /* 7 */
  532. calPrm = lenCyn*lenMgt*lenYel;
  533. tmpRgb = lutCmy[((tmpC01*gldNum)+tmpM01)*gldNum+tmpY01];
  534. tmpRed += calPrm * tmpRgb.Red;
  535. tmpGrn += calPrm * tmpRgb.Grn;
  536. tmpBlu += calPrm * tmpRgb.Blu;
  537. tmpRed += (DWORD)255 * 255 * 255 / 2;
  538. tmpGrn += (DWORD)255 * 255 * 255 / 2;
  539. tmpBlu += (DWORD)255 * 255 * 255 / 2;
  540. // tmpRgbSav.Red = (BYTE)(tmpRed / ((DWORD)255 * 255 * 255));
  541. // tmpRgbSav.Blu = (BYTE)(tmpBlu / ((DWORD)255 * 255 * 255));
  542. tmpRgbSav.Red = (BYTE)(tmpBlu / ((DWORD)255 * 255 * 255));
  543. tmpRgbSav.Grn = (BYTE)(tmpGrn / ((DWORD)255 * 255 * 255));
  544. tmpRgbSav.Blu = (BYTE)(tmpRed / ((DWORD)255 * 255 * 255));
  545. if (tmpK01 == tmpK00) { *rgbAdr = tmpRgbSav; rgbAdr++; continue; }
  546. lutCmy = lutTbl + tmpK01 * gldNum * gldNum * gldNum;
  547. /* 0 */
  548. calPrm = ((DWORD)255-lenCyn)*((DWORD)255-lenMgt)*((DWORD)255-lenYel);
  549. tmpRgb = lutCmy[((tmpC00*gldNum)+tmpM00)*gldNum+tmpY00];
  550. tmpRed = calPrm * tmpRgb.Red;
  551. tmpGrn = calPrm * tmpRgb.Grn;
  552. tmpBlu = calPrm * tmpRgb.Blu;
  553. /* 1 */
  554. calPrm = ((DWORD)255-lenCyn)*((DWORD)255-lenMgt)*lenYel;
  555. tmpRgb = lutCmy[((tmpC00*gldNum)+tmpM00)*gldNum+tmpY01];
  556. tmpRed += calPrm * tmpRgb.Red;
  557. tmpGrn += calPrm * tmpRgb.Grn;
  558. tmpBlu += calPrm * tmpRgb.Blu;
  559. /* 2 */
  560. calPrm = ((DWORD)255-lenCyn)*lenMgt*((DWORD)255-lenYel);
  561. tmpRgb = lutCmy[((tmpC00*gldNum)+tmpM01)*gldNum+tmpY00];
  562. tmpRed += calPrm * tmpRgb.Red;
  563. tmpGrn += calPrm * tmpRgb.Grn;
  564. tmpBlu += calPrm * tmpRgb.Blu;
  565. /* 3 */
  566. calPrm = ((DWORD)255-lenCyn)*lenMgt*lenYel;
  567. tmpRgb = lutCmy[((tmpC00*gldNum)+tmpM01)*gldNum+tmpY01];
  568. tmpRed += calPrm * tmpRgb.Red;
  569. tmpGrn += calPrm * tmpRgb.Grn;
  570. tmpBlu += calPrm * tmpRgb.Blu;
  571. /* 4 */
  572. calPrm = lenCyn*((DWORD)255-lenMgt)*((DWORD)255-lenYel);
  573. tmpRgb = lutCmy[((tmpC01*gldNum)+tmpM00)*gldNum+tmpY00];
  574. tmpRed += calPrm * tmpRgb.Red;
  575. tmpGrn += calPrm * tmpRgb.Grn;
  576. tmpBlu += calPrm * tmpRgb.Blu;
  577. /* 5 */
  578. calPrm = lenCyn*((DWORD)255-lenMgt)*lenYel;
  579. tmpRgb = lutCmy[((tmpC01*gldNum)+tmpM00)*gldNum+tmpY01];
  580. tmpRed += calPrm * tmpRgb.Red;
  581. tmpGrn += calPrm * tmpRgb.Grn;
  582. tmpBlu += calPrm * tmpRgb.Blu;
  583. /* 6 */
  584. calPrm = lenCyn*lenMgt*((DWORD)255-lenYel);
  585. tmpRgb = lutCmy[((tmpC01*gldNum)+tmpM01)*gldNum+tmpY00];
  586. tmpRed += calPrm * tmpRgb.Red;
  587. tmpGrn += calPrm * tmpRgb.Grn;
  588. tmpBlu += calPrm * tmpRgb.Blu;
  589. /* 7 */
  590. calPrm = lenCyn*lenMgt*lenYel;
  591. tmpRgb = lutCmy[((tmpC01*gldNum)+tmpM01)*gldNum+tmpY01];
  592. tmpRed += calPrm * tmpRgb.Red;
  593. tmpGrn += calPrm * tmpRgb.Grn;
  594. tmpBlu += calPrm * tmpRgb.Blu;
  595. tmpRed += (DWORD)255 * 255 * 255 / 2;
  596. tmpGrn += (DWORD)255 * 255 * 255 / 2;
  597. tmpBlu += (DWORD)255 * 255 * 255 / 2;
  598. // tmpRgb.Red = (BYTE)(tmpRed / ((DWORD)255 * 255 * 255));
  599. // tmpRgb.Blu = (BYTE)(tmpBlu / ((DWORD)255 * 255 * 255));
  600. tmpRgb.Red = (BYTE)(tmpBlu / ((DWORD)255 * 255 * 255));
  601. tmpRgb.Grn = (BYTE)(tmpGrn / ((DWORD)255 * 255 * 255));
  602. tmpRgb.Blu = (BYTE)(tmpRed / ((DWORD)255 * 255 * 255));
  603. calPrm = (DWORD)255 - lenBla;
  604. tmpRed = calPrm * tmpRgbSav.Red;
  605. tmpGrn = calPrm * tmpRgbSav.Grn;
  606. tmpBlu = calPrm * tmpRgbSav.Blu;
  607. calPrm = lenBla;
  608. tmpRed += calPrm * tmpRgb.Red;
  609. tmpGrn += calPrm * tmpRgb.Grn;
  610. tmpBlu += calPrm * tmpRgb.Blu;
  611. tmpRed += (DWORD)255 / 2;
  612. tmpGrn += (DWORD)255 / 2;
  613. tmpBlu += (DWORD)255 / 2;
  614. tmpRgb.Red = (BYTE)(tmpRed / (DWORD)255);
  615. tmpRgb.Grn = (BYTE)(tmpGrn / (DWORD)255);
  616. tmpRgb.Blu = (BYTE)(tmpBlu / (DWORD)255);
  617. *rgbAdr = tmpRgb;
  618. rgbAdr++;
  619. }
  620. return;
  621. }
  622. //***************************************************************************************************
  623. // Static functions
  624. //***************************************************************************************************
  625. //---------------------------------------------------------------------------------------------------
  626. // Color matching(high speed) (for 32GridLUT)
  627. //---------------------------------------------------------------------------------------------------
  628. #if !defined(CP80W9X) // CP-E8000 is invalid
  629. static VOID ExeColMch000( // Return value no
  630. DWORD xaxSiz, // Xsize (pixel)
  631. LPRGB rgbAdr, // RGB (input)
  632. LPCMYK cmyAdr, // CMYK (output)
  633. LPCOLMCHINF mchInf // Color matching information
  634. )
  635. {
  636. DWORD tmpRed, tmpGrn, tmpBlu;
  637. DWORD blaCnv, ucr;
  638. DWORD ucrCmy, ucrBla;
  639. DWORD ucrTnr;
  640. LPRGB endAdr;
  641. LPCMYK lutTbl, ucrTbl;
  642. CMYK tmpCmy;
  643. LPBYTE gryTbl;
  644. blaCnv = mchInf->Bla;
  645. ucr = mchInf->Ucr;
  646. ucrCmy = mchInf->UcrCmy;
  647. ucrBla = mchInf->UcrBla;
  648. ucrTnr = mchInf->UcrTnr; //+CASIO 2001/02/15
  649. ucrTbl = mchInf->UcrTbl;
  650. gryTbl = mchInf->GryTbl;
  651. lutTbl = mchInf->LutAdr;
  652. for (endAdr = rgbAdr + xaxSiz; rgbAdr < endAdr; rgbAdr++) {
  653. tmpRed = rgbAdr->Red;
  654. tmpGrn = rgbAdr->Grn;
  655. tmpBlu = rgbAdr->Blu;
  656. if (blaCnv == KCGGRY) {
  657. if ((tmpRed == tmpGrn) && (tmpRed == tmpBlu)) {
  658. tmpCmy.Cyn = tmpCmy.Mgt = tmpCmy.Yel = 0;
  659. // tmpCmy.Bla = 255 - GinTblP10[tmpRed];
  660. tmpCmy.Bla = gryTbl[tmpRed];
  661. *cmyAdr = tmpCmy;
  662. cmyAdr++;
  663. continue;
  664. }
  665. } else if (blaCnv == KCGBLA) {
  666. if ((tmpRed | tmpGrn | tmpBlu) == 0) {
  667. tmpCmy.Cyn = tmpCmy.Mgt = tmpCmy.Yel = 0;
  668. tmpCmy.Bla = 255;
  669. *cmyAdr = tmpCmy;
  670. cmyAdr++;
  671. continue;
  672. }
  673. }
  674. *cmyAdr = lutTbl[tmpRed / 8 * GLDNUM032 * GLDNUM032 +
  675. tmpGrn / 8 * GLDNUM032 +
  676. tmpBlu / 8];
  677. /*----- UCR Procedure -------------------------------------------------------*/
  678. // if (ucr != UCRNOO) ExeColMchUcr(cmyAdr, rgbAdr, ucr, ucrTbl);
  679. if (ucr != UCRNOO)
  680. // CASIO 2001/02/15 ->
  681. // ExeColMchUcr(cmyAdr, rgbAdr, ucr, ucrCmy, ucrBla, ucrTbl);
  682. ExeColMchUcr(cmyAdr, rgbAdr, ucr, ucrCmy, ucrBla, ucrTnr, ucrTbl);
  683. // CASIO 2001/02/15 <-
  684. cmyAdr++;
  685. }
  686. return;
  687. }
  688. #endif
  689. //---------------------------------------------------------------------------------------------------
  690. // Color matching(normal speed) (for 16Grid)
  691. //---------------------------------------------------------------------------------------------------
  692. #if !defined(CP80W9X) // CP-E8000 is invalid
  693. static VOID ExeColMch001( // Return value no
  694. DWORD xaxSiz, // Xsize (pixel)
  695. LPRGB rgbAdr, // RGB (input)
  696. LPCMYK cmyAdr, // CMYK (output)
  697. LPCOLMCHINF mchInf // Color matching information
  698. )
  699. {
  700. DWORD tmpR00, tmpG00, tmpB00;
  701. DWORD lenRed, lenGrn, lenBlu;
  702. DWORD lenR00, lenG00, lenB00;
  703. DWORD tmpRxC, tmpGxM, tmpBxY, tmpBla;
  704. DWORD calPrm;
  705. DWORD cch;
  706. DWORD blaCnv;
  707. DWORD n, colDefQty, ucr, cchTblSiz;
  708. DWORD ucrCmy, ucrBla;
  709. DWORD ucrTnr;
  710. LPCMYK lutTbl;
  711. LPCMYK lutCur;
  712. LPCMYK ucrTbl;
  713. RGBS tmpRgb, cchBufRgb;
  714. LPRGB cchRgb;
  715. CMYK tmpCmy, cchBufCmy;
  716. LPCMYK cchCmy;
  717. CMYK cmyBla;
  718. LPCOLCOLDEF colDef;
  719. LPBYTE gryTbl;
  720. blaCnv = mchInf->Bla;
  721. ucr = mchInf->Ucr;
  722. ucrCmy = mchInf->UcrCmy;
  723. ucrBla = mchInf->UcrBla;
  724. ucrTnr = mchInf->UcrTnr; //+CASIO 2001/02/15
  725. ucrTbl = mchInf->UcrTbl;
  726. gryTbl = mchInf->GryTbl;
  727. lutTbl = mchInf->LutAdr;
  728. colDefQty = mchInf->ColQty;
  729. colDef = mchInf->ColAdr;
  730. if ((mchInf->CchRgb == NULL) || (mchInf->CchCmy == NULL)) {
  731. cchTblSiz = (DWORD)1;
  732. cchRgb = &cchBufRgb;
  733. cchCmy = &cchBufCmy;
  734. cchRgb->Red = cchRgb->Grn = cchRgb->Blu = (BYTE)255;
  735. cchCmy->Cyn = cchCmy->Mgt = cchCmy->Yel = cchCmy->Bla = (BYTE)0;
  736. } else {
  737. cchTblSiz = CCHTBLSIZ;
  738. cchRgb = mchInf->CchRgb;
  739. cchCmy = mchInf->CchCmy;
  740. }
  741. cmyBla.Cyn = cmyBla.Mgt = cmyBla.Yel = 0; cmyBla.Bla = 255;
  742. for (; xaxSiz > 0; xaxSiz--) {
  743. tmpRgb = *rgbAdr++;
  744. tmpB00 = tmpRgb.Blu; tmpG00 = tmpRgb.Grn; tmpR00 = tmpRgb.Red;
  745. if (blaCnv == KCGGRY) {
  746. if ((tmpR00 == tmpG00) && (tmpR00 == tmpB00)) {
  747. tmpCmy = cmyBla;
  748. // tmpCmy.Bla -= GinTblP10[tmpR00];
  749. tmpCmy.Bla = gryTbl[tmpR00];
  750. *cmyAdr++ = tmpCmy;
  751. continue;
  752. }
  753. } else if (blaCnv == KCGBLA) {
  754. if ((tmpR00 | tmpG00 | tmpB00) == 0) {
  755. *cmyAdr++ = cmyBla;
  756. continue;
  757. }
  758. }
  759. /*----- Color setting -------------------------------------------------------*/
  760. if (colDefQty) {
  761. for (n = 0; n < colDefQty; n++) {
  762. if ((colDef[n].Red == (BYTE)tmpR00) &&
  763. (colDef[n].Grn == (BYTE)tmpG00) &&
  764. (colDef[n].Blu == (BYTE)tmpB00)) {
  765. cmyAdr->Cyn = colDef[n].Cyn;
  766. cmyAdr->Mgt = colDef[n].Mgt;
  767. cmyAdr->Yel = colDef[n].Yel;
  768. cmyAdr->Bla = colDef[n].Bla;
  769. cmyAdr++;
  770. break;
  771. }
  772. }
  773. if (n != colDefQty) continue;
  774. }
  775. /*----- Color matching cache -----------------------------------------------*/
  776. cch = (tmpR00 * 49 + tmpG00 * 9 + tmpB00) % cchTblSiz;
  777. if ((cchRgb[cch].Red == (BYTE)tmpR00) &&
  778. (cchRgb[cch].Grn == (BYTE)tmpG00) &&
  779. (cchRgb[cch].Blu == (BYTE)tmpB00)) {
  780. *cmyAdr++ = cchCmy[cch];
  781. continue;
  782. }
  783. /*----- RGB -> CMYK transformation ------------------------------------------*/
  784. tmpRxC = tmpR00;
  785. tmpR00 = tmpRxC * (GLDNUM016 - 1) / 255;
  786. lenRed = tmpRxC * (GLDNUM016 - 1) - tmpR00 * 255;
  787. lenR00 = (DWORD)255 - lenRed;
  788. tmpGxM = tmpG00;
  789. tmpG00 = tmpGxM * (GLDNUM016 - 1) / 255;
  790. lenGrn = tmpGxM * (GLDNUM016 - 1) - tmpG00 * 255;
  791. lenG00 = (DWORD)255 - lenGrn;
  792. tmpBxY = tmpB00;
  793. tmpB00 = tmpBxY * (GLDNUM016 - 1) / 255;
  794. lenBlu = tmpBxY * (GLDNUM016 - 1) - tmpB00 * 255;
  795. lenB00 = (DWORD)255 - lenBlu;
  796. lutCur = &lutTbl[(tmpR00 * GLDNUM016 + tmpG00) * GLDNUM016 + tmpB00];
  797. /* 0 */
  798. calPrm = lenR00 * lenG00 * lenB00;
  799. tmpCmy = *lutCur;
  800. tmpRxC = calPrm * tmpCmy.Cyn;
  801. tmpGxM = calPrm * tmpCmy.Mgt;
  802. tmpBxY = calPrm * tmpCmy.Yel;
  803. tmpBla = calPrm * tmpCmy.Bla;
  804. /* 1 */
  805. if (lenBlu) {
  806. calPrm = lenR00 * lenG00 * lenBlu;
  807. tmpCmy = *(lutCur + 1);
  808. tmpRxC += calPrm * tmpCmy.Cyn;
  809. tmpGxM += calPrm * tmpCmy.Mgt;
  810. tmpBxY += calPrm * tmpCmy.Yel;
  811. tmpBla += calPrm * tmpCmy.Bla;
  812. }
  813. /* 2 */
  814. if (lenGrn) {
  815. calPrm = lenR00 * lenGrn * lenB00;
  816. tmpCmy = *(lutCur + GLDNUM016);
  817. tmpRxC += calPrm * tmpCmy.Cyn;
  818. tmpGxM += calPrm * tmpCmy.Mgt;
  819. tmpBxY += calPrm * tmpCmy.Yel;
  820. tmpBla += calPrm * tmpCmy.Bla;
  821. }
  822. /* 3 */
  823. if (lenGrn && lenBlu) {
  824. calPrm = lenR00 * lenGrn * lenBlu;
  825. tmpCmy = *(lutCur + (GLDNUM016 + 1));
  826. tmpRxC += calPrm * tmpCmy.Cyn;
  827. tmpGxM += calPrm * tmpCmy.Mgt;
  828. tmpBxY += calPrm * tmpCmy.Yel;
  829. tmpBla += calPrm * tmpCmy.Bla;
  830. }
  831. /* 4 */
  832. if (lenRed) {
  833. calPrm = lenRed * lenG00 * lenB00;
  834. tmpCmy = *(lutCur + (GLDNUM016 * GLDNUM016));
  835. tmpRxC += calPrm * tmpCmy.Cyn;
  836. tmpGxM += calPrm * tmpCmy.Mgt;
  837. tmpBxY += calPrm * tmpCmy.Yel;
  838. tmpBla += calPrm * tmpCmy.Bla;
  839. }
  840. /* 5 */
  841. if (lenRed && lenBlu) {
  842. calPrm = lenRed * lenG00 * lenBlu;
  843. tmpCmy = *(lutCur + (GLDNUM016 * GLDNUM016 + 1));
  844. tmpRxC += calPrm * tmpCmy.Cyn;
  845. tmpGxM += calPrm * tmpCmy.Mgt;
  846. tmpBxY += calPrm * tmpCmy.Yel;
  847. tmpBla += calPrm * tmpCmy.Bla;
  848. }
  849. /* 6 */
  850. if (lenRed && lenGrn) {
  851. calPrm = lenRed * lenGrn * lenB00;
  852. tmpCmy = *(lutCur + ((GLDNUM016 + 1) * GLDNUM016));
  853. tmpRxC += calPrm * tmpCmy.Cyn;
  854. tmpGxM += calPrm * tmpCmy.Mgt;
  855. tmpBxY += calPrm * tmpCmy.Yel;
  856. tmpBla += calPrm * tmpCmy.Bla;
  857. }
  858. /* 7 */
  859. if (lenRed && lenGrn && lenBlu) {
  860. calPrm = lenRed * lenGrn * lenBlu;
  861. tmpCmy = *(lutCur + ((GLDNUM016 + 1) * GLDNUM016 + 1));
  862. tmpRxC += calPrm * tmpCmy.Cyn;
  863. tmpGxM += calPrm * tmpCmy.Mgt;
  864. tmpBxY += calPrm * tmpCmy.Yel;
  865. tmpBla += calPrm * tmpCmy.Bla;
  866. }
  867. tmpRxC += (DWORD)255 * 255 * 255 / 2;
  868. tmpGxM += (DWORD)255 * 255 * 255 / 2;
  869. tmpBxY += (DWORD)255 * 255 * 255 / 2;
  870. tmpBla += (DWORD)255 * 255 * 255 / 2;
  871. tmpCmy.Cyn = (BYTE)(tmpRxC / ((DWORD)255 * 255 * 255));
  872. tmpCmy.Mgt = (BYTE)(tmpGxM / ((DWORD)255 * 255 * 255));
  873. tmpCmy.Yel = (BYTE)(tmpBxY / ((DWORD)255 * 255 * 255));
  874. tmpCmy.Bla = (BYTE)(tmpBla / ((DWORD)255 * 255 * 255));
  875. /*----- UCR proceure --------------------------------------------------------*/
  876. // if (ucr != UCRNOO) ExeColMchUcr(&tmpCmy, &tmpRgb, ucr, ucrTbl);
  877. if (ucr != UCRNOO)
  878. // CASIO 2001/02/15 ->
  879. // ExeColMchUcr(&tmpCmy, &tmpRgb, ucr, ucrCmy, ucrBla, ucrTbl);
  880. ExeColMchUcr(&tmpCmy, &tmpRgb, ucr, ucrCmy, ucrBla, ucrTnr, ucrTbl);
  881. // CASIO 2001/02/15 <-
  882. *cmyAdr++ = tmpCmy;
  883. /*----- Color matching cache ------------------------------------------------*/
  884. cchRgb[cch] = tmpRgb; cchCmy[cch] = tmpCmy;
  885. }
  886. return;
  887. }
  888. #endif
  889. //---------------------------------------------------------------------------------------------------
  890. // Color matching(solid)
  891. //---------------------------------------------------------------------------------------------------
  892. static VOID ExeColCnvSld( // Return value no
  893. DWORD xaxSiz, // Xsize (pixel)
  894. LPRGB rgbAdr, // RGB (input)
  895. LPCMYK cmyAdr, // CMYK (output)
  896. // DWORD blaCnv // Black replacement
  897. LPCOLMCHINF mchInf // Color matching information
  898. )
  899. {
  900. DWORD tmpRed, tmpGrn, tmpBlu;
  901. DWORD blaCnv, ucr, ucrCmy, ucrBla;
  902. DWORD ucrTnr;
  903. LPCMYK ucrTbl;
  904. LPRGB endAdr;
  905. LPBYTE gryTbl;
  906. blaCnv = mchInf->Bla;
  907. ucr = mchInf->Ucr;
  908. ucrCmy = mchInf->UcrCmy;
  909. ucrBla = mchInf->UcrBla;
  910. ucrTnr = mchInf->UcrTnr; //+CASIO 2001/02/15
  911. ucrTbl = mchInf->UcrTbl;
  912. gryTbl = mchInf->GryTbl;
  913. for (endAdr = rgbAdr + xaxSiz; rgbAdr < endAdr; rgbAdr++) {
  914. tmpRed = rgbAdr->Red;
  915. tmpGrn = rgbAdr->Grn;
  916. tmpBlu = rgbAdr->Blu;
  917. if (blaCnv == KCGGRY) {
  918. if ((tmpRed == tmpGrn) && (tmpRed == tmpBlu)) {
  919. cmyAdr->Cyn = cmyAdr->Mgt = cmyAdr->Yel = 0;
  920. // cmyAdr->Bla = 255 - GinTblP10[tmpRed];
  921. cmyAdr->Bla = gryTbl[tmpRed];
  922. cmyAdr++;
  923. continue;
  924. }
  925. } else if (blaCnv == KCGBLA) {
  926. if ((tmpRed | tmpGrn | tmpBlu) == 0) {
  927. cmyAdr->Cyn = cmyAdr->Mgt = cmyAdr->Yel = 0;
  928. cmyAdr->Bla = 255;
  929. cmyAdr++;
  930. continue;
  931. }
  932. }
  933. cmyAdr->Cyn = (BYTE)(255 - tmpRed);
  934. cmyAdr->Mgt = (BYTE)(255 - tmpGrn);
  935. cmyAdr->Yel = (BYTE)(255 - tmpBlu);
  936. cmyAdr->Bla = 0;
  937. #if !defined(CP80W9X) // CP-E8000 is invalid
  938. /*----- UCR proceure --------------------------------------------------------*/
  939. if (ucr != UCRNOO)
  940. // CASIO 2001/02/15 ->
  941. // ExeColMchUcr(cmyAdr, rgbAdr, ucr, ucrCmy, ucrBla, ucrTbl);
  942. ExeColMchUcr(cmyAdr, rgbAdr, ucr, ucrCmy, ucrBla, ucrTnr, ucrTbl);
  943. // CASIO 2001/02/15 <-
  944. #endif
  945. cmyAdr++;
  946. }
  947. return;
  948. }
  949. //---------------------------------------------------------------------------------------------------
  950. // RGB -> CMYK(2Level) conversion (for 1dot line)
  951. //---------------------------------------------------------------------------------------------------
  952. #if !defined(CP80W9X) // CP-E8000 is invalid
  953. static VOID ExeColCnvL02( // Return value no
  954. DWORD xaxSiz, // Xsize (pixel)
  955. LPRGB rgbAdr, // RGB (input)
  956. LPCMYK cmyAdr // CMYK (output)
  957. )
  958. {
  959. DWORD tmpRed, tmpGrn, tmpBlu;
  960. DWORD tmpMid;
  961. LPRGB endAdr;
  962. BYTE tmpCyn, tmpMgt, tmpYel;
  963. for (endAdr = rgbAdr + xaxSiz; rgbAdr < endAdr; rgbAdr++) {
  964. tmpRed = rgbAdr->Red;
  965. tmpGrn = rgbAdr->Grn;
  966. tmpBlu = rgbAdr->Blu;
  967. tmpMid = (tmpRed + tmpGrn + tmpBlu) / 3;
  968. if (tmpMid > 240) {
  969. cmyAdr->Cyn = cmyAdr->Mgt = cmyAdr->Yel = cmyAdr->Bla = 0;
  970. cmyAdr++;
  971. continue;
  972. }
  973. tmpCyn = tmpMgt = tmpYel = 255;
  974. tmpMid += (255 - tmpMid) / 8;
  975. if (tmpRed > tmpMid) tmpCyn = 0;
  976. if (tmpGrn > tmpMid) tmpMgt = 0;
  977. if (tmpBlu > tmpMid) tmpYel = 0;
  978. if ((tmpCyn & tmpMgt & tmpYel) == 255) {
  979. cmyAdr->Cyn = cmyAdr->Mgt = cmyAdr->Yel = 0;
  980. cmyAdr->Bla = 255;
  981. cmyAdr++;
  982. continue;
  983. }
  984. cmyAdr->Cyn = tmpCyn;
  985. cmyAdr->Mgt = tmpMgt;
  986. cmyAdr->Yel = tmpYel;
  987. cmyAdr->Bla = 0;
  988. cmyAdr++;
  989. }
  990. return;
  991. }
  992. #endif
  993. //---------------------------------------------------------------------------------------------------
  994. // RGB -> K conversion (for monochrome)
  995. //---------------------------------------------------------------------------------------------------
  996. static VOID ExeColCnvMon( // Return value no
  997. DWORD xaxSiz, // Xsize (pixel)
  998. LPRGB rgbAdr, // RGB (input)
  999. LPCMYK cmyAdr, // CMYK (output)
  1000. LPCOLMCHINF mchInf // Color matching information
  1001. )
  1002. {
  1003. DWORD tmpRed, tmpGrn, tmpBlu;
  1004. CMYK tmpCmy;
  1005. LPRGB endAdr;
  1006. LPBYTE gryTbl;
  1007. gryTbl = (LPBYTE)(mchInf->LutAdr);
  1008. tmpCmy.Cyn = tmpCmy.Mgt = tmpCmy.Yel = 0;
  1009. for (endAdr = rgbAdr + xaxSiz; rgbAdr < endAdr; rgbAdr++) {
  1010. tmpRed = rgbAdr->Red;
  1011. tmpGrn = rgbAdr->Grn;
  1012. tmpBlu = rgbAdr->Blu;
  1013. // tmpCmy.Bla = (BYTE)255 - GinTblP10[(tmpRed * 3 + tmpGrn * 5 + tmpBlu * 2) / 10];
  1014. tmpCmy.Bla = gryTbl[(tmpRed*3 + tmpGrn*5 + tmpBlu*2) / 10];
  1015. *cmyAdr = tmpCmy;
  1016. cmyAdr++;
  1017. }
  1018. return;
  1019. }
  1020. //---------------------------------------------------------------------------------------------------
  1021. // Color matching(UCR)
  1022. //---------------------------------------------------------------------------------------------------
  1023. #if !defined(CP80W9X) // CP-E8000 is invalid
  1024. static VOID ExeColMchUcr( // Return value no
  1025. LPCMYK cmy, // CMYK (input, output)
  1026. LPRGB rgb, // RGB (input)
  1027. DWORD ucr, // UCR type
  1028. DWORD ucrCmy, // UCR (UCR quantity)
  1029. DWORD ucrBla, // UCR (ink version generation quantity)
  1030. DWORD ucrTnr, // UCR (Toner gross weight)
  1031. LPCMYK ucrTbl // UCR table
  1032. )
  1033. {
  1034. LPCMYK gryCyn; // Gray value (Cyan conversion value)
  1035. LPCMYK dnsCyn; // Density value (Cyan conversion value)
  1036. DWORD blaGen, min, sub, rgbMin, rgbMax, tmp;
  1037. DWORD ttlTnr, adjVal;
  1038. DWORD ucrQty;
  1039. // DWORD gryRat, ucrRat, blaRat, gryDns;
  1040. LONG cyn, mgt, yel, bla;
  1041. DWORD xx = 128; /* @@@ */
  1042. gryCyn = ucrTbl;
  1043. dnsCyn = ucrTbl + 256;
  1044. ucrTnr = (ucrTnr * (DWORD)255) / (DWORD)100; //+CASIO 2001/02/15
  1045. cyn = cmy->Cyn;
  1046. mgt = cmy->Mgt;
  1047. yel = cmy->Yel;
  1048. bla = cmy->Bla;
  1049. /*----- Minimum density calculation of CMY --------------------------------------*/
  1050. min = cyn;
  1051. if (min > dnsCyn[mgt].Mgt) min = dnsCyn[mgt].Mgt;
  1052. if (min > dnsCyn[yel].Yel) min = dnsCyn[yel].Yel;
  1053. if (ucr == UCR001) { /* Type�T(for char, graphic) */
  1054. /*----- Gray degree calculation ----------------------------------------------*/
  1055. rgbMin = rgbMax = rgb->Red;
  1056. if (rgbMin > rgb->Grn) rgbMin = rgb->Grn;
  1057. if (rgbMin > rgb->Blu) rgbMin = rgb->Blu;
  1058. if (rgbMax < rgb->Grn) rgbMax = rgb->Grn;
  1059. if (rgbMax < rgb->Blu) rgbMax = rgb->Blu;
  1060. // CASIO 2001/02/15 ->
  1061. // sub = (DWORD)255 - (rgbMax - rgbMin);
  1062. // blaGen = min * sub / (DWORD)255;
  1063. //
  1064. // gryRat = ((rgbMax - rgbMin) * 100) / 255;
  1065. // gryRat = (gryRat < (DWORD)20)? (DWORD)20 - gryRat: (DWORD)0;
  1066. // /* Gray rate [100%] = 20, [80% or less] = 0 */
  1067. //
  1068. // /* UCR rate case of gray-rate(gryRat) 100 to 80%, +20 to +0 */
  1069. // ucrRat = ucrCmy + gryRat;
  1070. // /* Black rate case of gray-rate(gryRat) 100 to 80%, +10 to +0 */
  1071. // blaRat = ucrBla + (gryRat / 2);
  1072. //
  1073. // /* Black rate, case of gray-density(gryDns) 100 to 80%, +10 to +0 */
  1074. // gryDns = rgbMin * 100 / 255;
  1075. // gryDns = (gryDns < (DWORD)20)? (DWORD)20 - gryDns: (DWORD)0;
  1076. // blaRat += (gryDns / 2);
  1077. //
  1078. // if (ucrRat > (DWORD)100) ucrRat = (DWORD)100;
  1079. // if (blaRat > (DWORD)100) blaRat = (DWORD)100;
  1080. //
  1081. // ucrQty = (blaGen * ucrRat) / 100;
  1082. // blaGen = (blaGen * blaRat) / 100;
  1083. sub = rgbMax - rgbMin;
  1084. if (sub > (DWORD)50) blaGen = (DWORD)0;
  1085. else {
  1086. if (sub <= (DWORD)10) {
  1087. tmp = (DWORD)10 - sub;
  1088. ucrCmy += tmp;
  1089. ucrBla += tmp;
  1090. }
  1091. if (sub <= (DWORD)5) {
  1092. tmp = ((DWORD)5 - sub) * (DWORD)2;
  1093. ucrCmy += tmp;
  1094. }
  1095. if (ucrCmy > 100) ucrCmy = 100;
  1096. if (ucrBla > 100) ucrBla = 100;
  1097. tmp = (DWORD)50 - sub;
  1098. blaGen = min * tmp / (DWORD)50;
  1099. }
  1100. // CASIO 2001/02/15 <-
  1101. } else { /* Type�U(for image) */
  1102. // CASIO 2001/02/15 ->
  1103. // /* UCR processing be NOP, */
  1104. // /* in the case that minimum density is smaller than the prescription value (50%) */
  1105. // if (min < 127) return;
  1106. //
  1107. // /* Density revision (127-255 -> 0-255) */
  1108. //// min = ((min - 127) * 255 + 64) / 128;
  1109. // min = ((min - 127) * 255 + 64) / xx;
  1110. //
  1111. // /* Gamma 3.0 approximation (If the speed-up is necessary table transformation) */
  1112. // if (min <= 63) blaGen = 0;
  1113. // else if (min <= 127) blaGen = ((min - 63) * 15 + 32) / 64;
  1114. // else if (min <= 191) blaGen = ((min - 127) * ( 79 - 15) + 32) / 64 + 15;
  1115. // else blaGen = ((min - 191) * (255 - 79) + 32) / 64 + 79;
  1116. //
  1117. // ucrQty = (blaGen * ucrCmy) / 100; /* UCR quantity */
  1118. // blaGen = (blaGen * ucrBla) / 100; /* ink version generation quantity */
  1119. /* K generation no, */
  1120. /* in the case that minimum density is smaller than the prescription value (50%) */
  1121. if (min < 127) blaGen = 0;
  1122. else {
  1123. /* Density revision (127-255 -> 0-255) */
  1124. // min = ((min - 127) * 255 + 64) / 128;
  1125. min = ((min - 127) * 255 + 64) / xx;
  1126. /* Gamma 3.0 approximation (If the speed-up is necessary table transformation) */
  1127. if (min <= 63) blaGen = 0;
  1128. else if (min <= 127) blaGen = ((min- 63) * 15 + 32) / 64;
  1129. else if (min <= 191) blaGen = ((min-127) * ( 79-15) + 32) / 64 + 15;
  1130. else blaGen = ((min-191) * (255-79) + 32) / 64 + 79;
  1131. }
  1132. // CASIO 2001/02/15 <-
  1133. }
  1134. /*----- Toner gross weight calculation(input CMYK value) ------------------------*/
  1135. ttlTnr = cyn + mgt + yel + bla;
  1136. if ((blaGen == 0) && (ttlTnr <= ucrTnr)) return;
  1137. /*----- Ink version generation (K replacement) ----------------------------------*/
  1138. // CASIO 2001/02/15 ->
  1139. // if (blaGen == 0) return;
  1140. //
  1141. // ucrQty = (blaGen * ucrCmy) / 100; /* UCR quantity */
  1142. // blaGen = (blaGen * ucrBla) / 100; /* ink version generation quantity */
  1143. //
  1144. ////cyn -= blaGen; /* Adjustment with a gray value */
  1145. // cyn -= ucrQty; /* Adjustment with a gray value */
  1146. ////mgt -= gryCyn[blaGen].Mgt;
  1147. // mgt -= gryCyn[ucrQty].Mgt;
  1148. ////yel -= gryCyn[blaGen].Yel;
  1149. // yel -= gryCyn[ucrQty].Yel;
  1150. // bla += gryCyn[blaGen].Bla;
  1151. if (blaGen) {
  1152. ucrQty = (blaGen * ucrCmy) / 100; /* UCR quantity */
  1153. blaGen = (blaGen * ucrBla) / 100; /* ink version generation quantity*/
  1154. cyn -= ucrQty; /* Adjustment with a gray value */
  1155. mgt -= gryCyn[ucrQty].Mgt;
  1156. yel -= gryCyn[ucrQty].Yel;
  1157. bla += gryCyn[blaGen].Bla;
  1158. ttlTnr = cyn + mgt + yel + bla; /* Toner gross weight calculation */
  1159. }
  1160. /*----- Toner gross weight restriction ---------------------------------*/
  1161. if (ttlTnr > ucrTnr) {
  1162. adjVal = (ttlTnr - ucrTnr + 2) / 3;
  1163. cyn -= adjVal;
  1164. mgt -= adjVal;
  1165. yel -= adjVal;
  1166. }
  1167. // CASIO 2001/02/15 <-
  1168. if (cyn < 0) cyn = 0; /* BYTE value(0 - 255) adjustment */
  1169. if (mgt < 0) mgt = 0;
  1170. if (yel < 0) yel = 0;
  1171. if (bla < 0) bla = 0;
  1172. if (cyn > 255) cyn = 255;
  1173. if (mgt > 255) mgt = 255;
  1174. if (yel > 255) yel = 255;
  1175. if (bla > 255) bla = 255;
  1176. cmy->Cyn = (BYTE)cyn; /* UCR processing value setting */
  1177. cmy->Mgt = (BYTE)mgt;
  1178. cmy->Yel = (BYTE)yel;
  1179. cmy->Bla = (BYTE)bla;
  1180. return;
  1181. }
  1182. #endif
  1183. // End of N5COLMH.C