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.

1744 lines
65 KiB

  1. //***************************************************************************************************
  2. // N4DIZ.C
  3. //
  4. // Functions of dither and color matching (For N4 printer)
  5. //---------------------------------------------------------------------------------------------------
  6. // copyright(C) 1997-1999 CASIO COMPUTER CO.,LTD. / CASIO ELECTRONICS MANUFACTURING CO.,LTD.
  7. //***************************************************************************************************
  8. #include <WINDOWS.H>
  9. #include <WINBASE.H>
  10. #include "PDEV.H"
  11. #include "strsafe.h" // Security-Code 2002.3.6
  12. //***************************************************************************************************
  13. // Data define
  14. //***************************************************************************************************
  15. /*----------------------------------------------------------------------------
  16. Pattern original(Ver.3)
  17. ----------------------------------------------------------------------------*/
  18. const static BYTE MgtGinTbl[3] = { 144, 136, 116 };
  19. const static BYTE MgtTilTbl[3][4][4] = {
  20. /*--- Dispersion ----*/
  21. { { 0, 8, 2, 10 },
  22. { 12, 4, 14, 6 },
  23. { 3, 11, 1, 9 },
  24. { 15, 7, 13, 5 } },
  25. /*--- Net ----*/
  26. { { 1, 3, 14, 12 },
  27. { 8, 10, 4, 6 },
  28. { 15, 13, 0, 2 },
  29. { 5, 7, 9, 11 } },
  30. /*--- Center ----*/
  31. { { 12, 9, 5, 13 },
  32. { 4, 0, 1, 10 },
  33. { 8, 3, 2, 6 },
  34. { 15, 7, 11, 14 } }
  35. };
  36. const static BYTE YelGinTbl[3] = { 120, 120, 120 };
  37. const static BYTE YelTilTbl[3][4][4] = {
  38. /*--- Net ----*/
  39. { { 0, 2, 14, 12 },
  40. { 8, 10, 5, 7 },
  41. { 15, 13, 1, 3 },
  42. { 4, 6, 9, 11 } },
  43. /*--- Center ----*/
  44. { { 12, 9, 5, 13 },
  45. { 4, 0, 1, 10 },
  46. { 8, 3, 2, 6 },
  47. { 15, 7, 11, 14 } },
  48. /*--- Center ----*/
  49. { { 12, 9, 5, 13 },
  50. { 4, 0, 1, 10 },
  51. { 8, 3, 2, 6 },
  52. { 15, 7, 11, 14 } }
  53. };
  54. const static BYTE BlaGinTbl[3] = { 100, 100, 100 };
  55. const static BYTE BlaTilTbl[3][4][4] = {
  56. /*--- Dispersion ----*/
  57. { { 0, 8, 2, 10 },
  58. { 12, 4, 14, 6 },
  59. { 3, 11, 1, 9 },
  60. { 15, 7, 13, 5 } },
  61. /*--- Dispersion ----*/
  62. { { 0, 8, 2, 10 },
  63. { 12, 4, 14, 6 },
  64. { 3, 11, 1, 9 },
  65. { 15, 7, 13, 5 } },
  66. /*--- Net ----*/
  67. { { 0, 2, 14, 12 },
  68. { 8, 10, 5, 7 },
  69. { 15, 13, 1, 3 },
  70. { 4, 6, 9, 11 } }
  71. };
  72. #define STRMGT 16
  73. const static BYTE MgtTilNum[17] = {
  74. 2, 11, 13, 4, 15, 6, 3, 12, 1, 10, 16, 7, 14, 5, 8, 0, 9
  75. };
  76. /*----------------------------------------------------------------------------
  77. Pattern original(Ver.3) For enter to printer
  78. ----------------------------------------------------------------------------*/
  79. const static BYTE Bun4x4All[16] = { /* Dither pattern (4*4) */
  80. 0, 8, 2, 10,
  81. 12, 4, 14, 6,
  82. 3, 11, 1, 9,
  83. 15, 7, 13, 5
  84. };
  85. const static BYTE Bun2x2All[16] = { /* Dither pattern (2*2) */
  86. 0, 2,
  87. 3, 1
  88. };
  89. /*==== Detail ====*/
  90. const static BYTE Bun8x8Bla[64] = { /* black */
  91. /*---- Dispersion ----*/
  92. 3, 35, 11, 43, 1, 33, 9, 41,
  93. 51, 19, 59, 27, 49, 17, 57, 25,
  94. 15, 47, 7, 39, 13, 45, 5, 37,
  95. 63, 31, 55, 23, 61, 29, 53, 21,
  96. 0, 32, 8, 40, 2, 34, 10, 42,
  97. 48, 16, 56, 24, 50, 18, 58, 26,
  98. 12, 44, 4, 36, 14, 46, 6, 38,
  99. 60, 28, 52, 20, 62, 30, 54, 22
  100. };
  101. const static BYTE Bun8x8Cyn[64] = { /* cyan */
  102. /*---- Dispersion ----*/
  103. 0, 63, 15, 51, 3, 60, 12, 48,
  104. 16, 32, 31, 47, 19, 35, 28, 44,
  105. 56, 8, 55, 7, 59, 11, 52, 4,
  106. 36, 24, 40, 23, 39, 27, 43, 20,
  107. 14, 50, 2, 61, 13, 49, 1, 62,
  108. 30, 46, 18, 34, 29, 45, 17, 33,
  109. 54, 6, 58, 10, 53, 5, 57, 9,
  110. 41, 22, 38, 26, 42, 21, 37, 25
  111. };
  112. const static BYTE Bun8x8Mgt[64] = { /* magenta */
  113. /*---- Dispersion ----*/
  114. 0, 31, 55, 39, 13, 17, 57, 41,
  115. 48, 32, 8, 23, 61, 45, 5, 25,
  116. 12, 16, 56, 40, 2, 29, 53, 37,
  117. 60, 44, 4, 24, 50, 34, 10, 21,
  118. 3, 28, 52, 36, 14, 18, 58, 42,
  119. 51, 35, 11, 20, 62, 46, 6, 26,
  120. 15, 19, 59, 43, 1, 30, 54, 38,
  121. 63, 47, 7, 27, 49, 33, 9, 22
  122. };
  123. /*==== Normal ====*/
  124. const static BYTE Mid8x8Cyn[64] = { /* cyan */
  125. /*---- Net ----*/
  126. 32, 19, 14, 62, 63, 60, 2, 7,
  127. 54, 4, 9, 31, 59, 22, 24, 58,
  128. 50, 27, 42, 29, 16, 11, 40, 46,
  129. 15, 37, 57, 53, 1, 6, 34, 38,
  130. 0, 10, 45, 49, 25, 55, 51, 20,
  131. 5, 36, 33, 18, 13, 43, 47, 35,
  132. 56, 52, 39, 3, 8, 30, 41, 26,
  133. 44, 48, 21, 23, 61, 28, 17, 12
  134. };
  135. const static BYTE Mid8x8Bla[64] = { /* black */
  136. /*---- Dispersion ----*/
  137. 3, 35, 11, 43, 1, 33, 9, 41,
  138. 51, 19, 59, 27, 49, 17, 57, 25,
  139. 15, 47, 7, 39, 13, 45, 5, 37,
  140. 63, 31, 55, 23, 61, 29, 53, 21,
  141. 0, 32, 8, 40, 2, 34, 10, 42,
  142. 48, 16, 56, 24, 50, 18, 58, 26,
  143. 12, 44, 4, 36, 14, 46, 6, 38,
  144. 60, 28, 52, 20, 62, 30, 54, 22
  145. };
  146. const static BYTE Mid8x8Mgt[64] = { /* Magenta */
  147. /*---- Net ----*/
  148. 44, 48, 21, 23, 61, 28, 17, 12,
  149. 56, 52, 39, 3, 8, 30, 41, 26,
  150. 5, 36, 33, 18, 13, 43, 47, 35,
  151. 0, 10, 45, 49, 25, 55, 51, 20,
  152. 15, 37, 57, 53, 1, 6, 34, 38,
  153. 50, 27, 42, 29, 16, 11, 40, 46,
  154. 54, 4, 9, 31, 59, 22, 24, 58,
  155. 32, 19, 14, 62, 63, 60, 2, 7
  156. };
  157. const static BYTE Mid8x8Yel[64] = { /* Yellow */
  158. /*---- Net ----*/
  159. 50, 0, 8, 56, 48, 2, 10, 58,
  160. 30, 32, 40, 20, 28, 34, 42, 22,
  161. 14, 60, 52, 4, 12, 62, 54, 6,
  162. 46, 16, 24, 36, 44, 18, 26, 38,
  163. 49, 3, 11, 59, 51, 1, 9, 57,
  164. 29, 35, 43, 23, 31, 33, 41, 21,
  165. 13, 63, 55, 7, 15, 61, 53, 5,
  166. 45, 19, 27, 39, 47, 17, 25, 37
  167. };
  168. /*==== collage ====*/
  169. const static BYTE Syu8x8Cyn[64] = { /* cyan */
  170. /*---- center ----*/
  171. 61, 45, 16, 12, 8, 28, 41, 57,
  172. 5, 25, 36, 52, 48, 32, 21, 1,
  173. 9, 29, 43, 59, 63, 47, 17, 13,
  174. 49, 33, 23, 3, 7, 27, 37, 53,
  175. 62, 46, 19, 15, 11, 31, 42, 58,
  176. 6, 26, 39, 55, 51, 35, 22, 2,
  177. 10, 30, 40, 56, 60, 44, 18, 14,
  178. 50, 34, 20, 0, 4, 24, 38, 54
  179. };
  180. const static BYTE Syu8x8Mgt[64] = { /* magenta */
  181. /*---- center ----*/
  182. 49, 13, 9, 61, 50, 14, 10, 62,
  183. 33, 29, 25, 45, 34, 30, 26, 46,
  184. 20, 40, 39, 19, 23, 43, 36, 16,
  185. 4, 56, 55, 3, 7, 59, 52, 0,
  186. 8, 60, 51, 15, 11, 63, 48, 12,
  187. 24, 44, 35, 31, 27, 47, 32, 28,
  188. 37, 17, 21, 41, 38, 18, 22, 42,
  189. 53, 1, 5, 57, 54, 2, 6, 58
  190. };
  191. const static BYTE Syu8x8Yel[64] = { /* yellow */
  192. /*---- center ----*/
  193. 5, 13, 39, 59, 58, 43, 17, 7,
  194. 23, 31, 49, 44, 36, 50, 25, 15,
  195. 41, 52, 26, 18, 10, 28, 53, 33,
  196. 61, 34, 8, 0, 2, 20, 46, 60,
  197. 62, 42, 16, 6, 4, 12, 38, 63,
  198. 37, 55, 24, 14, 22, 30, 54, 45,
  199. 11, 29, 48, 32, 40, 51, 27, 19,
  200. 3, 21, 47, 56, 57, 35, 9, 1
  201. };
  202. const static BYTE Wgt001[8][8] = {
  203. { 0, 8, 56, 48, 2, 10, 58, 50 },
  204. { 32, 40, 20, 28, 34, 42, 22, 30 },
  205. { 60, 52, 4, 12, 62, 54, 6, 14 },
  206. { 16, 24, 36, 44, 18, 26, 38, 46 },
  207. { 3, 11, 59, 51, 1, 9, 57, 49 },
  208. { 35, 43, 23, 31, 33, 41, 21, 29 },
  209. { 63, 55, 7, 15, 61, 53, 5, 13 },
  210. { 19, 27, 39, 47, 17, 25, 37, 45 }
  211. };
  212. const static BYTE Wgt002[8][8] = {
  213. { 5, 13, 39, 59, 58, 43, 17, 7 },
  214. { 23, 31, 49, 44, 36, 50, 25, 15 },
  215. { 41, 52, 26, 18, 10, 28, 53, 33 },
  216. { 61, 34, 8, 0, 2, 20, 46, 60 },
  217. { 62, 42, 16, 6, 4, 12, 38, 63 },
  218. { 37, 55, 24, 14, 22, 30, 54, 45 },
  219. { 11, 29, 48, 32, 40, 51, 27, 19 },
  220. { 3, 21, 47, 56, 57, 35, 9, 1 }
  221. };
  222. const static SHORT SinTbl[256] = {
  223. 0, 3, 6, 9, 12, 15, 18, 21,
  224. 25, 28, 31, 34, 37, 40, 43, 46,
  225. 49, 52, 54, 57, 60, 63, 66, 68,
  226. 71, 73, 76, 79, 81, 83, 86, 88,
  227. 90, 92, 95, 97, 99, 101, 103, 104,
  228. 106, 108, 110, 111, 113, 114, 115, 117,
  229. 118, 119, 120, 121, 122, 123, 124, 125,
  230. 125, 126, 126, 127, 127, 127, 127, 127,
  231. 127, 127, 127, 127, 127, 126, 126, 125,
  232. 125, 124, 123, 123, 122, 121, 120, 119,
  233. 117, 116, 115, 113, 112, 110, 109, 107,
  234. 105, 104, 102, 100, 98, 96, 94, 91,
  235. 89, 87, 85, 82, 80, 77, 75, 72,
  236. 70, 67, 64, 61, 59, 56, 53, 50,
  237. 47, 44, 41, 38, 35, 32, 29, 26,
  238. 23, 20, 17, 14, 11, 7, 4, 1,
  239. -1, -4, -7, -11, -14, -17, -20, -23,
  240. -26, -29, -32, -35, -38, -41, -44, -47,
  241. -50, -53, -56, -59, -61, -64, -67, -70,
  242. -72, -75, -77, -80, -82, -85, -87, -89,
  243. -91, -94, -96, -98, -100, -102, -104, -105,
  244. -107, -109, -110, -112, -113, -115, -116, -117,
  245. -119, -120, -121, -122, -123, -123, -124, -125,
  246. -125, -126, -126, -127, -127, -127, -127, -127,
  247. -127, -127, -127, -127, -127, -126, -126, -125,
  248. -125, -124, -123, -122, -121, -120, -119, -118,
  249. -117, -115, -114, -113, -111, -110, -108, -106,
  250. -104, -103, -101, -99, -97, -95, -92, -90,
  251. -88, -86, -83, -81, -79, -76, -73, -71,
  252. -68, -66, -63, -60, -57, -54, -52, -49,
  253. -46, -43, -40, -37, -34, -31, -28, -25,
  254. -21, -18, -15, -12, -9, -6, -3, 0
  255. };
  256. /*============================================================================
  257. Gamma revision table
  258. ============================================================================*/
  259. const static BYTE GamTbl014[256] = {
  260. 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,
  261. 0x01, 0x02, 0x02, 0x03, 0x03, 0x03, 0x04, 0x04,
  262. 0x05, 0x05, 0x06, 0x06, 0x07, 0x07, 0x08, 0x08,
  263. 0x09, 0x09, 0x0a, 0x0a, 0x0b, 0x0c, 0x0c, 0x0d,
  264. 0x0d, 0x0e, 0x0f, 0x0f, 0x10, 0x11, 0x11, 0x12,
  265. 0x13, 0x13, 0x14, 0x15, 0x15, 0x16, 0x17, 0x17,
  266. 0x18, 0x19, 0x1a, 0x1a, 0x1b, 0x1c, 0x1c, 0x1d,
  267. 0x1e, 0x1f, 0x20, 0x20, 0x21, 0x22, 0x23, 0x23,
  268. 0x24, 0x25, 0x26, 0x27, 0x28, 0x28, 0x29, 0x2a,
  269. 0x2b, 0x2c, 0x2d, 0x2d, 0x2e, 0x2f, 0x30, 0x31,
  270. 0x32, 0x33, 0x34, 0x34, 0x35, 0x36, 0x37, 0x38,
  271. 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3e, 0x3f,
  272. 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
  273. 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
  274. 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
  275. 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x60,
  276. 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
  277. 0x69, 0x6a, 0x6b, 0x6c, 0x6e, 0x6f, 0x70, 0x71,
  278. 0x72, 0x73, 0x74, 0x75, 0x76, 0x78, 0x79, 0x7a,
  279. 0x7b, 0x7c, 0x7d, 0x7e, 0x80, 0x81, 0x82, 0x83,
  280. 0x84, 0x85, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c,
  281. 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x94, 0x95, 0x96,
  282. 0x97, 0x98, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0xa0,
  283. 0xa1, 0xa2, 0xa3, 0xa5, 0xa6, 0xa7, 0xa8, 0xaa,
  284. 0xab, 0xac, 0xad, 0xaf, 0xb0, 0xb1, 0xb2, 0xb4,
  285. 0xb5, 0xb6, 0xb7, 0xb9, 0xba, 0xbb, 0xbd, 0xbe,
  286. 0xbf, 0xc0, 0xc2, 0xc3, 0xc4, 0xc6, 0xc7, 0xc8,
  287. 0xca, 0xcb, 0xcc, 0xce, 0xcf, 0xd0, 0xd1, 0xd3,
  288. 0xd4, 0xd5, 0xd7, 0xd8, 0xd9, 0xdb, 0xdc, 0xde,
  289. 0xdf, 0xe0, 0xe2, 0xe3, 0xe4, 0xe6, 0xe7, 0xe8,
  290. 0xea, 0xeb, 0xec, 0xee, 0xef, 0xf1, 0xf2, 0xf3,
  291. 0xf5, 0xf6, 0xf8, 0xf9, 0xfa, 0xfc, 0xfd, 0xff
  292. };
  293. const static BYTE GamTbl016[256] = {
  294. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  295. 0x00, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02,
  296. 0x03, 0x03, 0x03, 0x03, 0x04, 0x04, 0x05, 0x05,
  297. 0x05, 0x06, 0x06, 0x07, 0x07, 0x07, 0x08, 0x08,
  298. 0x09, 0x09, 0x0a, 0x0a, 0x0b, 0x0b, 0x0c, 0x0c,
  299. 0x0d, 0x0d, 0x0e, 0x0e, 0x0f, 0x0f, 0x10, 0x11,
  300. 0x11, 0x12, 0x12, 0x13, 0x13, 0x14, 0x15, 0x15,
  301. 0x16, 0x17, 0x17, 0x18, 0x19, 0x19, 0x1a, 0x1b,
  302. 0x1b, 0x1c, 0x1d, 0x1e, 0x1e, 0x1f, 0x20, 0x20,
  303. 0x21, 0x22, 0x23, 0x23, 0x24, 0x25, 0x26, 0x27,
  304. 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2b, 0x2c, 0x2d,
  305. 0x2e, 0x2f, 0x30, 0x30, 0x31, 0x32, 0x33, 0x34,
  306. 0x35, 0x36, 0x37, 0x38, 0x38, 0x39, 0x3a, 0x3b,
  307. 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43,
  308. 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b,
  309. 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53,
  310. 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5b, 0x5c,
  311. 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63, 0x65,
  312. 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6d, 0x6e,
  313. 0x6f, 0x70, 0x71, 0x72, 0x74, 0x75, 0x76, 0x77,
  314. 0x78, 0x7a, 0x7b, 0x7c, 0x7d, 0x7f, 0x80, 0x81,
  315. 0x82, 0x83, 0x85, 0x86, 0x87, 0x89, 0x8a, 0x8b,
  316. 0x8c, 0x8e, 0x8f, 0x90, 0x92, 0x93, 0x94, 0x95,
  317. 0x97, 0x98, 0x99, 0x9b, 0x9c, 0x9d, 0x9f, 0xa0,
  318. 0xa1, 0xa3, 0xa4, 0xa5, 0xa7, 0xa8, 0xaa, 0xab,
  319. 0xac, 0xae, 0xaf, 0xb0, 0xb2, 0xb3, 0xb5, 0xb6,
  320. 0xb8, 0xb9, 0xba, 0xbc, 0xbd, 0xbf, 0xc0, 0xc2,
  321. 0xc3, 0xc4, 0xc6, 0xc7, 0xc9, 0xca, 0xcc, 0xcd,
  322. 0xcf, 0xd0, 0xd2, 0xd3, 0xd5, 0xd6, 0xd8, 0xd9,
  323. 0xdb, 0xdc, 0xde, 0xdf, 0xe1, 0xe2, 0xe4, 0xe5,
  324. 0xe7, 0xe8, 0xea, 0xec, 0xed, 0xef, 0xf0, 0xf2,
  325. 0xf3, 0xf5, 0xf7, 0xf8, 0xfa, 0xfb, 0xfd, 0xff
  326. };
  327. //***************************************************************************************************
  328. // Function
  329. //***************************************************************************************************
  330. //===================================================================================================
  331. // Make dither pattern
  332. //===================================================================================================
  333. VOID WINAPI N4DizPtnMak(
  334. LPN4DIZINF lpDiz,
  335. DWORD dizNum,
  336. DWORD diz // Type of dithering
  337. )
  338. {
  339. WORD cntTil; // count
  340. WORD cntXax; // count
  341. WORD cntYax; // count
  342. WORD strXax;
  343. WORD strYax;
  344. WORD dotGin;
  345. DWORD num;
  346. LPBYTE DizTblCyn; // Dither pattern table(CMYK)
  347. LPBYTE DizTblMgt;
  348. LPBYTE DizTblYel;
  349. LPBYTE DizTblBla;
  350. DizTblCyn = lpDiz->Diz.Tbl[dizNum][0];
  351. DizTblMgt = lpDiz->Diz.Tbl[dizNum][1];
  352. DizTblYel = lpDiz->Diz.Tbl[dizNum][2];
  353. DizTblBla = lpDiz->Diz.Tbl[dizNum][3];
  354. /*---- Make black pattern for monochrome ----*/
  355. if(lpDiz->ColMon == N4_MON){
  356. for(cntTil = 0; cntTil < 4; cntTil++){
  357. for(cntYax = 0; cntYax < 8; cntYax++){
  358. for(cntXax = 0; cntXax < 8; cntXax++){
  359. if(diz == N4_DIZ_SML){
  360. num = (DWORD)Bun8x8Bla[cntYax*8+cntXax] * 4;
  361. }else if(diz == N4_DIZ_MID){
  362. num = (DWORD)Mid8x8Yel[cntYax*8+cntXax] * 4;
  363. }else{
  364. num = (DWORD)Syu8x8Yel[cntYax*8+cntXax] * 4;
  365. }
  366. num += (DWORD)Bun2x2All[cntTil];
  367. // DizTblBla[(cntTil/2)*8+cntYax][(cntTil%2)*8+cntXax] = num;
  368. DizTblBla[((cntTil / 2) * 8 + cntYax) * 16 + ((cntTil % 2) * 8 + cntXax)] = (BYTE)num;
  369. }
  370. }
  371. }
  372. return;
  373. }
  374. /*---- Make magenta cyan pattern ----*/
  375. strXax = 6;
  376. strYax = 0xffff;
  377. dotGin = MgtGinTbl[diz];
  378. for(cntTil = 0; cntTil < 17; cntTil++){
  379. strXax += 4;
  380. strYax += 1;
  381. num = (DWORD)STRMGT * 17 + (DWORD)MgtTilNum[cntTil];
  382. num = num * 255 / (17 * 17);
  383. // DizTblMgt[strYax % 17][strXax % 17] = num;
  384. DizTblMgt[(strYax % 17) * 17 + (strXax % 17)] = (BYTE)num;
  385. DizTblCyn[(strYax % 17) * 17 + (16 - strXax % 17)] = (BYTE)num;
  386. for(cntYax = 0; cntYax < 4; cntYax++){
  387. for(cntXax = 0; cntXax < 4; cntXax++){
  388. num = (DWORD)MgtTilTbl[diz][cntYax][cntXax] * 17
  389. + (DWORD)MgtTilNum[cntTil];
  390. /* dot gain revision */
  391. if(num < (17*17/2)){
  392. num = num * dotGin / 100;
  393. }else{
  394. num -= 17*17/2;
  395. num = num * (100 - dotGin/2) / 50;
  396. num += (17*17/2) * dotGin / 100;
  397. }
  398. if(num < 4){ num = 4; }
  399. num = num * 255 / (17 * 17);
  400. // DizTblMgt[(strYax+cntYax+1)%17][(strXax+cntXax)%17] = num;
  401. DizTblMgt[((strYax + cntYax + 1) % 17) * 17 + ((strXax + cntXax) % 17)] = (BYTE)num;
  402. // DizTblCyn[(strYax+cntYax+1)%17][16-(strXax+cntXax)%17] = num;
  403. DizTblCyn[((strYax + cntYax + 1) % 17) * 17 + (16 - (strXax + cntXax) % 17)] = (BYTE)num;
  404. }
  405. }
  406. }
  407. /*---- Make yellow pattern ----*/
  408. dotGin = YelGinTbl[diz];
  409. for(cntTil = 0; cntTil < 16; cntTil++){
  410. for(cntYax = 0; cntYax < 4; cntYax++){
  411. for(cntXax = 0; cntXax < 4; cntXax++){
  412. num = (DWORD)YelTilTbl[diz][cntYax][cntXax] * 16
  413. + (DWORD)Bun4x4All[cntTil];
  414. /* dot gain revision */
  415. if(num < (16*16/2)){
  416. num = num * dotGin / 100;
  417. }else{
  418. num -= 16*16/2;
  419. num = num * (100 - dotGin/2) / 50;
  420. num += (16*16/2) * dotGin / 100;
  421. }
  422. num *= 255;
  423. num /= 16 * 16;
  424. if(num < 4){ num = 4; }
  425. // DizTblYel[(cntTil/4)*4 + cntYax][(cntTil%4)*4 + cntXax] = num;
  426. DizTblYel[((cntTil / 4) * 4 + cntYax) * 16 + ((cntTil % 4) * 4 + cntXax)] = (BYTE)num;
  427. }
  428. }
  429. }
  430. /*---- Make black pattern ----*/
  431. dotGin = BlaGinTbl[diz];
  432. for(cntTil = 0; cntTil < 16; cntTil++){
  433. for(cntYax = 0; cntYax < 4; cntYax++){
  434. for(cntXax = 0; cntXax < 4; cntXax++){
  435. num = (DWORD)BlaTilTbl[diz][cntYax][cntXax] * 16
  436. + (DWORD)Bun4x4All[cntTil];
  437. /* dot gain revision */
  438. if(num < (16*16/2)){
  439. num = num * dotGin / 100;
  440. }else{
  441. num -= 16*16/2;
  442. num = num * (100 - dotGin/2) / 50;
  443. num += (16*16/2) * dotGin / 100;
  444. }
  445. num *= 255;
  446. num /= 16 * 16;
  447. if(num < 4){ num = 4; }
  448. // DizTblBla[(cntTil/4)*4 + cntYax][(cntTil%4)*4 + cntXax] = num;
  449. DizTblBla[((cntTil / 4) * 4 + cntYax) * 16 + ((cntTil % 4) * 4 + cntXax)] = (BYTE)num;
  450. }
  451. }
  452. }
  453. }
  454. //===================================================================================================
  455. // Make dither pattern (for printer entry)
  456. //===================================================================================================
  457. VOID WINAPI N4DizPtnPrn(
  458. LPN4DIZINF lpDiz,
  459. DWORD dizNum,
  460. DWORD colNum, // Color number(0:C 1:M 2:Y 3:K)
  461. DWORD ptnSkl, // Density(0�`255)
  462. LPBYTE ptnAdr // Dither pattern
  463. )
  464. {
  465. WORD nijRit; /* dot gain(blot rate�j */
  466. DWORD vldDot;
  467. DWORD cnt064; /* counter */
  468. DWORD cnt016; /* counter */
  469. DWORD cntXax; /* counter */
  470. DWORD cntYax; /* counter */
  471. LPBYTE srcAdr;
  472. /*---- Source dither table address set ----*/
  473. if(dizNum == N4_DIZ_SML){
  474. switch(colNum){
  475. case 0:
  476. nijRit = 144;
  477. srcAdr = (LPBYTE)Bun8x8Cyn;
  478. break;
  479. case 1:
  480. nijRit = 144;
  481. srcAdr = (LPBYTE)Bun8x8Mgt;
  482. break;
  483. case 2:
  484. nijRit = 132;
  485. srcAdr = (LPBYTE)Mid8x8Yel;
  486. break;
  487. case 3:
  488. default:
  489. if (lpDiz->ColMon == N4_MON) {
  490. nijRit = 100;
  491. srcAdr = (LPBYTE)Bun8x8Bla;
  492. } else {
  493. nijRit = 100;
  494. srcAdr = (LPBYTE)Bun8x8Bla;
  495. }
  496. break;
  497. }
  498. }else if(dizNum == N4_DIZ_MID){
  499. switch(colNum){
  500. case 0:
  501. nijRit = 120;
  502. srcAdr = (LPBYTE)Mid8x8Cyn;
  503. break;
  504. case 1:
  505. nijRit = 120;
  506. srcAdr = (LPBYTE)Mid8x8Mgt;
  507. break;
  508. case 2:
  509. nijRit = 132;
  510. srcAdr = (LPBYTE)Mid8x8Yel;
  511. break;
  512. case 3:
  513. default:
  514. if (lpDiz->ColMon == N4_MON) {
  515. nijRit = 100;
  516. srcAdr = (LPBYTE)Mid8x8Yel;
  517. } else {
  518. nijRit = 100;
  519. srcAdr = (LPBYTE)Bun8x8Bla;
  520. }
  521. break;
  522. }
  523. }else if(dizNum == N4_DIZ_RUG) {
  524. switch(colNum){
  525. case 0:
  526. nijRit = 120;
  527. srcAdr = (LPBYTE)Syu8x8Cyn;
  528. break;
  529. case 1:
  530. nijRit = 120;
  531. srcAdr = (LPBYTE)Syu8x8Mgt;
  532. break;
  533. case 2:
  534. nijRit = 132;
  535. srcAdr = (LPBYTE)Mid8x8Yel;
  536. break;
  537. case 3:
  538. default:
  539. if (lpDiz->ColMon == N4_MON) {
  540. nijRit = 100;
  541. srcAdr = (LPBYTE)Syu8x8Yel;
  542. } else {
  543. nijRit = 100;
  544. srcAdr = (LPBYTE)Bun8x8Bla;
  545. }
  546. break;
  547. }
  548. }else{
  549. nijRit = 100;
  550. switch(colNum){
  551. case 0:
  552. srcAdr = (LPBYTE)Bun8x8Cyn;
  553. break;
  554. case 1:
  555. srcAdr = (LPBYTE)Bun8x8Mgt;
  556. break;
  557. case 2:
  558. srcAdr = (LPBYTE)Mid8x8Yel;
  559. break;
  560. case 3:
  561. default:
  562. if (lpDiz->ColMon == N4_MON) {
  563. srcAdr = (LPBYTE)Mid8x8Yel;
  564. } else {
  565. srcAdr = (LPBYTE)Bun8x8Bla;
  566. }
  567. break;
  568. }
  569. }
  570. /*---- Get dot gain ----*/
  571. if(ptnSkl <= (DWORD)(255 * nijRit / 200)){
  572. vldDot = ((DWORD)32 * 32 * ptnSkl / 255) * 100 / nijRit;
  573. }else{
  574. vldDot = ((DWORD)20480 * ptnSkl - (DWORD)26112 * nijRit);
  575. vldDot /= ((DWORD)10200 - (DWORD)51 * nijRit);
  576. vldDot += 512;
  577. }
  578. /*---- Make pattern ----*/
  579. for(cntYax = 0 ; cntYax < 32 ; cntYax ++){
  580. ptnAdr[cntYax*4] = 0x00;
  581. ptnAdr[cntYax*4 + 1] = 0x00;
  582. ptnAdr[cntYax*4 + 2] = 0x00;
  583. ptnAdr[cntYax*4 + 3] = 0x00;
  584. for(cntXax = 0 ; cntXax < 32 ; cntXax ++){
  585. /*---- 16 * 16 No ----*/
  586. cnt016 = Bun4x4All[4 * (cntYax/8) + cntXax/8];
  587. cnt064 = srcAdr[8*(cntYax%8) + cntXax%8];
  588. /*---- Make dither pattern ----*/
  589. if(vldDot > 16 * cnt064 + cnt016){
  590. ptnAdr[cntYax*4 + cntXax/8] |= ((BYTE)0x80 >> (cntXax % 8));
  591. }
  592. }
  593. }
  594. }
  595. //===================================================================================================
  596. // Make toner density table
  597. //===================================================================================================
  598. VOID WINAPI N4TnrTblMak(
  599. LPN4DIZINF lpDiz,
  600. LONG tnrDns
  601. )
  602. {
  603. LONG innNum;
  604. LONG outNum;
  605. LPBYTE InnTblCmy;
  606. tnrDns *= 2; // set twice as tnrdns
  607. InnTblCmy = lpDiz->Tnr.Tbl;
  608. /*---- Make CMYK conversion table ----*/
  609. if(tnrDns < 0){
  610. for(innNum = 0 ; innNum < 256 ; innNum++){
  611. if(innNum == 255){ outNum = 255;
  612. }else{ outNum = innNum * (255 + tnrDns) / 255;
  613. }
  614. InnTblCmy[innNum] = (BYTE)outNum;
  615. }
  616. }else{
  617. for(innNum = 0 ; innNum < 256 ; innNum++){
  618. if(innNum == 0){ outNum = 0;
  619. }else{ outNum = (innNum + tnrDns) * 255 / (255 + tnrDns);
  620. }
  621. InnTblCmy[innNum] = (BYTE)outNum;
  622. }
  623. }
  624. }
  625. //===================================================================================================
  626. // Dithering(Not stretch)
  627. //===================================================================================================
  628. DWORD WINAPI N4Diz001( // Number of lines
  629. LPN4DIZINF lpDiz,
  630. DWORD xaxSiz, // x pixel
  631. DWORD strXax, // x start position
  632. DWORD strYax, // y start position
  633. LPBYTE cmyBuf,
  634. LPBYTE linBufCyn, // Line buffer(C)
  635. LPBYTE linBufMgt, // Line buffer(M)
  636. LPBYTE linBufYel, // Line buffer(Y)
  637. LPBYTE linBufBla // Line buffer(K)
  638. )
  639. {
  640. DWORD cntHrz;
  641. BYTE tmpByt;
  642. DWORD dizNum;
  643. LPBYTE DizTblCyn;
  644. LPBYTE DizTblMgt;
  645. LPBYTE DizTblYel;
  646. LPBYTE DizTblBla;
  647. dizNum = lpDiz->Diz.Num;
  648. DizTblCyn = lpDiz->Diz.Tbl[dizNum][0];
  649. DizTblMgt = lpDiz->Diz.Tbl[dizNum][1];
  650. DizTblYel = lpDiz->Diz.Tbl[dizNum][2];
  651. DizTblBla = lpDiz->Diz.Tbl[dizNum][3];
  652. /*---- Not stretch ----*/
  653. if(lpDiz->ColMon == N4_COL){
  654. DizTblCyn += strYax % 17 * 17;
  655. DizTblMgt += strYax % 17 * 17;
  656. DizTblYel += strYax % 16 * 16;
  657. DizTblBla += strYax % 16 * 16;
  658. for(cntHrz = 0 ; cntHrz < xaxSiz ; cntHrz++){
  659. tmpByt = (BYTE)0x80 >> (cntHrz % 8);
  660. // if(cmyBuf[cntHrz*4+0] > DizTblCyn[strYax%17][strXax%17]){
  661. if (cmyBuf[cntHrz * 4 + 0] > DizTblCyn[strXax % 17]) {
  662. linBufCyn[cntHrz / 8] |= tmpByt;
  663. }
  664. // if(cmyBuf[cntHrz*4+1] > DizTblMgt[strYax%17][strXax%17]){
  665. if (cmyBuf[cntHrz * 4 + 1] > DizTblMgt[strXax % 17]) {
  666. linBufMgt[cntHrz / 8] |= tmpByt;
  667. }
  668. // if(cmyBuf[cntHrz*4+2] > DizTblYel[strYax%16][strXax%16]){
  669. if (cmyBuf[cntHrz * 4 + 2] > DizTblYel[strXax % 16]) {
  670. linBufYel[cntHrz / 8] |= tmpByt;
  671. }
  672. // if(cmyBuf[cntHrz*4+3] > DizTblBla[strYax%16][strXax%16]){
  673. if (cmyBuf[cntHrz * 4 + 3] > DizTblBla[strXax % 16]) {
  674. linBufBla[cntHrz / 8] |= tmpByt;
  675. }
  676. strXax++;
  677. }
  678. } else {
  679. DizTblBla += strYax % 16 * 16;
  680. for(cntHrz = 0 ; cntHrz < xaxSiz ; cntHrz++){
  681. tmpByt = (BYTE)0x80 >> (cntHrz % 8);
  682. // if(cmyBuf[cntHrz*4+3] > DizTblBla[strYax%16][strXax%16]){
  683. if (cmyBuf[ cntHrz * 4 + 3] > DizTblBla[strXax % 16]) {
  684. linBufBla[cntHrz / 8] |= tmpByt;
  685. }
  686. strXax++;
  687. }
  688. }
  689. return 1;
  690. }
  691. //===================================================================================================
  692. // Dither(Stretch )
  693. //===================================================================================================
  694. DWORD WINAPI N4Diz00n(
  695. LPN4DIZINF lpDiz,
  696. DWORD xaxSiz,
  697. DWORD strXax,
  698. DWORD strYax,
  699. DWORD xaxOfs,
  700. DWORD yaxOfs,
  701. DWORD xaxNrt,
  702. DWORD xaxDnt,
  703. DWORD yaxNrt,
  704. DWORD yaxDnt,
  705. DWORD linByt,
  706. LPBYTE cmyBuf,
  707. LPBYTE linBufCyn,
  708. LPBYTE linBufMgt,
  709. LPBYTE linBufYel,
  710. LPBYTE linBufBla
  711. )
  712. {
  713. DWORD cntHrz;
  714. DWORD cntXax;
  715. DWORD cntYax;
  716. DWORD xaxSet;
  717. DWORD yaxSet;
  718. DWORD tmpXax;
  719. DWORD tmpYax;
  720. DWORD tmpBuf;
  721. BYTE tmpByt;
  722. DWORD dizNum;
  723. LPBYTE DizTblCyn;
  724. LPBYTE DizTblMgt;
  725. LPBYTE DizTblYel;
  726. LPBYTE DizTblBla;
  727. dizNum = lpDiz->Diz.Num;
  728. DizTblCyn = lpDiz->Diz.Tbl[dizNum][0];
  729. DizTblMgt = lpDiz->Diz.Tbl[dizNum][1];
  730. DizTblYel = lpDiz->Diz.Tbl[dizNum][2];
  731. DizTblBla = lpDiz->Diz.Tbl[dizNum][3];
  732. // Check of zero divide 2002.3.23 >>>
  733. if ((xaxDnt == 0) || (yaxDnt == 0)) {
  734. ERR(("N4Diz00n() 0Div-Check [xaxDnt,yaxDnt=0] \n"));
  735. return 0;
  736. }
  737. // Check of zero divide 2002.3.23 <<<
  738. /*---- Stretch ----*/
  739. if(lpDiz->ColMon == N4_COL){
  740. // yaxSet = (USINT)(yaxOfs + 1) * yaxNrt / yaxDnt;
  741. // yaxSet -= (USINT)yaxOfs * yaxNrt / yaxDnt;
  742. yaxSet = (yaxOfs + 1) * yaxNrt / yaxDnt;
  743. yaxSet -= yaxOfs * yaxNrt / yaxDnt;
  744. tmpXax = 0;
  745. for(cntHrz = 0 ; cntHrz < xaxSiz ; cntHrz++){
  746. // xaxSet = (USINT)(xaxOfs + cntHrz + 1) * xaxNrt / xaxDnt;
  747. // xaxSet -= (USINT)(xaxOfs + cntHrz) * xaxNrt / xaxDnt;
  748. xaxSet = (xaxOfs + cntHrz + 1) * xaxNrt / xaxDnt;
  749. xaxSet -= (xaxOfs + cntHrz) * xaxNrt / xaxDnt;
  750. for(cntXax = 0 ; cntXax < xaxSet ; cntXax ++){
  751. tmpByt = (BYTE)0x80 >> (tmpXax % 8);
  752. tmpBuf = tmpXax / 8;
  753. tmpYax = strYax;
  754. for(cntYax = 0 ; cntYax < yaxSet ; cntYax++){
  755. // if(cmyBuf[cntHrz*4+0] > DizTblCyn[tmpYax%17][strXax%17]){
  756. if (cmyBuf[cntHrz * 4 + 0] > DizTblCyn[(tmpYax % 17) * 17 + (strXax % 17)]) {
  757. linBufCyn[tmpBuf] |= tmpByt;
  758. }
  759. // if(cmyBuf[cntHrz*4+1] > DizTblMgt[tmpYax%17][strXax%17]){
  760. if (cmyBuf[cntHrz * 4 + 1] > DizTblMgt[(tmpYax % 17) * 17 + (strXax % 17)]) {
  761. linBufMgt[tmpBuf] |= tmpByt;
  762. }
  763. // if(cmyBuf[cntHrz*4+2] > DizTblYel[tmpYax%16][strXax%16]){
  764. if (cmyBuf[cntHrz * 4 + 2] > DizTblYel[(tmpYax % 16) * 16 + (strXax % 16)]) {
  765. linBufYel[tmpBuf] |= tmpByt;
  766. }
  767. // if(cmyBuf[cntHrz*4+3] > DizTblBla[tmpYax%16][strXax%16]){
  768. if (cmyBuf[cntHrz * 4 + 3] > DizTblBla[(tmpYax % 16) * 16 + (strXax % 16)]) {
  769. linBufBla[tmpBuf] |= tmpByt;
  770. }
  771. tmpBuf += linByt;
  772. tmpYax++;
  773. }
  774. strXax++;
  775. tmpXax++;
  776. }
  777. }
  778. } else {
  779. // yaxSet = (USHRT)(((USINT)yaxOfs + 1) * yaxNrt / yaxDnt);
  780. // yaxSet -= (USHRT)((USINT)yaxOfs * yaxNrt / yaxDnt);
  781. yaxSet = (yaxOfs + 1) * yaxNrt / yaxDnt;
  782. yaxSet -= yaxOfs * yaxNrt / yaxDnt;
  783. tmpXax = 0;
  784. for(cntHrz = 0 ; cntHrz < xaxSiz ; cntHrz++){
  785. // xaxSet = (USHRT)(((USINT)xaxOfs + cntHrz + 1) * xaxNrt / xaxDnt);
  786. // xaxSet -= (USHRT)(((USINT)xaxOfs + cntHrz) * xaxNrt / xaxDnt);
  787. xaxSet = (xaxOfs + cntHrz + 1) * xaxNrt / xaxDnt;
  788. xaxSet -= (xaxOfs + cntHrz) * xaxNrt / xaxDnt;
  789. for(cntXax = 0 ; cntXax < xaxSet ; cntXax ++){
  790. tmpByt = (BYTE)0x80 >> (tmpXax % 8);
  791. tmpBuf = tmpXax / 8;
  792. tmpYax = strYax;
  793. for(cntYax = 0 ; cntYax < yaxSet ; cntYax++){
  794. // if(cmyBuf[cntHrz*4+3] > DizTblBla[tmpYax%16][strXax%16]){
  795. if (cmyBuf[cntHrz * 4 + 3] > DizTblBla[(tmpYax % 16) * 16 + (strXax % 16)]) {
  796. linBufBla[tmpBuf] |= tmpByt;
  797. }
  798. tmpBuf += linByt;
  799. tmpYax++;
  800. }
  801. strXax++;
  802. tmpXax++;
  803. }
  804. }
  805. }
  806. return yaxSet;
  807. }
  808. #define CMYLOW 6
  809. //===================================================================================================
  810. // GOSA-KAKUSAN(Not stretch)
  811. //===================================================================================================
  812. DWORD WINAPI N4Gos001(
  813. LPN4DIZINF lpDiz,
  814. DWORD xaxSiz,
  815. DWORD strXax,
  816. DWORD strYax,
  817. LPBYTE cmyBuf,
  818. LPBYTE linBufCyn,
  819. LPBYTE linBufMgt,
  820. LPBYTE linBufYel,
  821. LPBYTE linBufBla
  822. )
  823. {
  824. LONG strHrz;
  825. LONG endHrz;
  826. LONG idc;
  827. LONG i;
  828. LONG k;
  829. SHORT m00;
  830. SHORT m01;
  831. SHORT m02;
  832. SHORT m03;
  833. SHORT sum;
  834. SHORT shiKii;
  835. SHORT gos;
  836. SHORT num;
  837. WORD strCol;
  838. WORD j;
  839. LPSHORT CmyGo0;
  840. LPSHORT CmyGo1;
  841. DWORD GosTblXSize;
  842. DWORD YaxOfsCmy;
  843. if ((strYax & 1) == 0) {
  844. CmyGo0 = lpDiz->GosCMYK.Tbl[0];
  845. CmyGo1 = lpDiz->GosCMYK.Tbl[1];
  846. } else {
  847. CmyGo0 = lpDiz->GosCMYK.Tbl[1];
  848. CmyGo1 = lpDiz->GosCMYK.Tbl[0];
  849. }
  850. GosTblXSize = lpDiz->GosCMYK.Siz;
  851. YaxOfsCmy = lpDiz->GosCMYK.Yax;
  852. CmyGo0 += 4;
  853. CmyGo1 += 4;
  854. if(lpDiz->ColMon == N4_COL){ strCol = 0; }else{ strCol = 3; }
  855. if(strYax - YaxOfsCmy != 1){
  856. for(i = 0 ; (DWORD)i < GosTblXSize * 4 ; i++){
  857. CmyGo1[i] = 0;
  858. }
  859. }
  860. YaxOfsCmy = strYax;
  861. CmyGo0 += strXax * 4;
  862. CmyGo1 += strXax * 4;
  863. /*---- filter set ----*/
  864. switch(strYax % 6){
  865. case 0: /*---- evn1 >> filter ----*/
  866. m00=3; m01=5; m02=3; m03=7; idc = +1; break;
  867. case 1: /*---- odd1 >> filter ----*/
  868. m00=1; m01=5; m02=3; m03=7; idc = +1; break;
  869. case 2: /*---- evn2 >> filter ----*/
  870. m00=4; m01=5; m02=4; m03=8; idc = +1; break;
  871. case 3: /*---- odd2 << filter ----*/
  872. m00=1; m01=3; m02=0; m03=7; idc = -1; break;
  873. case 4: /*---- evn3 << filter ----*/
  874. m00=2; m01=4; m02=0; m03=8; idc = -1; break;
  875. case 5: /*---- odd4 >> filter ----*/
  876. default:
  877. m00=3; m01=8; m02=3; m03=8; idc = +1; break;
  878. }
  879. sum = m00 + m01 + m02 + m03;
  880. if(idc == +1){
  881. strHrz = 0; endHrz = xaxSiz;
  882. }else{
  883. strHrz = xaxSiz - 1; endHrz = -1;
  884. }
  885. for(i = strHrz ; i != endHrz ; i+=idc){
  886. for(j = strCol ; j < 4 ; j++){
  887. k = i * 4 + j;
  888. num = cmyBuf[k];
  889. if(num < CMYLOW){ num = 0; }
  890. shiKii = num / 2 + 52;
  891. if(j != 2){ /* except yellow */
  892. if((num > 112)&&(num < 144)){
  893. shiKii +=
  894. ((SHORT)Wgt001[strYax%8][(i+strXax)%8]-32)*256/128;
  895. }else{
  896. shiKii +=
  897. ((SHORT)Wgt002[strYax%8][(i+strXax)%8]-32)*num/128;
  898. }
  899. }
  900. gos = ( CmyGo1[k - 4] * m00 +
  901. CmyGo1[k ] * m01 +
  902. CmyGo1[k + 4] * m02 +
  903. CmyGo0[k - idc*4] * m03
  904. ) / sum;
  905. if(gos + num > shiKii){
  906. CmyGo0[k] = num + gos - 255;
  907. /*---- enter line buffer ----*/
  908. if(j == 0){
  909. linBufCyn[i/8] |= ((BYTE)0x80 >> (i%8));
  910. }else if(j == 1){
  911. linBufMgt[i/8] |= ((BYTE)0x80 >> (i%8));
  912. }else if(j == 2){
  913. linBufYel[i/8] |= ((BYTE)0x80 >> (i%8));
  914. }else{
  915. linBufBla[i/8] |= ((BYTE)0x80 >> (i%8));
  916. }
  917. }else{
  918. CmyGo0[k] = num + gos;
  919. }
  920. }
  921. }
  922. lpDiz->GosCMYK.Yax = YaxOfsCmy;
  923. return 1;
  924. }
  925. //===================================================================================================
  926. // GOSA-KAKUSAN(Stretch)
  927. //===================================================================================================
  928. DWORD WINAPI N4Gos00n(
  929. LPN4DIZINF lpDiz,
  930. DWORD xaxSiz,
  931. DWORD strXax,
  932. DWORD strYax,
  933. DWORD xaxOfs,
  934. DWORD yaxOfs,
  935. DWORD xaxNrt,
  936. DWORD xaxDnt,
  937. DWORD yaxNrt,
  938. DWORD yaxDnt,
  939. DWORD linByt,
  940. LPBYTE cmyBuf,
  941. LPBYTE linBufCyn,
  942. LPBYTE linBufMgt,
  943. LPBYTE linBufYel,
  944. LPBYTE linBufBla
  945. )
  946. {
  947. LONG cntHrz;
  948. LONG cntYax;
  949. LONG cntXax;
  950. LONG yaxSet;
  951. LONG xaxSet;
  952. LONG strHrz;
  953. LONG endHrz;
  954. LONG idc;
  955. LONG i;
  956. LONG k;
  957. SHORT m00;
  958. SHORT m01;
  959. SHORT m02;
  960. SHORT m03;
  961. SHORT sum;
  962. SHORT shiKii;
  963. SHORT gos;
  964. SHORT num;
  965. LPSHORT bak;
  966. WORD strCol;
  967. WORD j;
  968. LPSHORT CmyGo0;
  969. LPSHORT CmyGo1;
  970. DWORD GosTblXSize;
  971. DWORD YaxOfsCmy;
  972. // Check of zero divide 2002.3.23 >>>
  973. if ((xaxDnt == 0) || (yaxDnt == 0)) {
  974. ERR(("N4Gos00n() 0Div-Check [xaxDnt,yaxDnt=0] \n"));
  975. return 0;
  976. }
  977. // Check of zero divide 2002.3.23 <<<
  978. if ((strYax & 1) == 0) { // y coordinates is even number?
  979. CmyGo0 = lpDiz->GosCMYK.Tbl[0];
  980. CmyGo1 = lpDiz->GosCMYK.Tbl[1];
  981. } else {
  982. CmyGo0 = lpDiz->GosCMYK.Tbl[1];
  983. CmyGo1 = lpDiz->GosCMYK.Tbl[0];
  984. }
  985. GosTblXSize = lpDiz->GosCMYK.Siz;
  986. YaxOfsCmy = lpDiz->GosCMYK.Yax;
  987. CmyGo0 += 4;
  988. CmyGo1 += 4;
  989. if(lpDiz->ColMon == N4_COL){ strCol = 0; }else{ strCol = 3; }
  990. if(strYax - YaxOfsCmy != 1){
  991. for(i = 0 ; (DWORD)i < GosTblXSize * 4 ; i++){
  992. CmyGo1[i] = 0;
  993. }
  994. }
  995. YaxOfsCmy = strYax;
  996. CmyGo0 += strXax * 4;
  997. CmyGo1 += strXax * 4;
  998. yaxSet = (yaxOfs + 1) * yaxNrt / yaxDnt;
  999. yaxSet -= yaxOfs * yaxNrt / yaxDnt;
  1000. for(cntYax = 0 ; cntYax < yaxSet ; cntYax++){
  1001. /*---- filter set ----*/
  1002. switch(strYax % 6){
  1003. case 0: /*---- evn1 >> filter ----*/
  1004. m00=3; m01=5; m02=3; m03=7; idc = +1; break;
  1005. case 1: /*---- odd1 >> filter ----*/
  1006. m00=1; m01=5; m02=3; m03=7; idc = +1; break;
  1007. case 2: /*---- evn2 >> filter ----*/
  1008. m00=4; m01=5; m02=4; m03=8; idc = +1; break;
  1009. case 3: /*---- odd2 << filter ----*/
  1010. m00=1; m01=3; m02=0; m03=7; idc = -1; break;
  1011. case 4: /*---- evn3 << filter ----*/
  1012. m00=2; m01=4; m02=0; m03=8; idc = -1; break;
  1013. case 5: /*---- odd4 >> filter ----*/
  1014. default:
  1015. m00=3; m01=8; m02=3; m03=8; idc = +1; break;
  1016. }
  1017. sum = m00 + m01 + m02 + m03;
  1018. if(idc == +1){
  1019. strHrz = 0; endHrz = xaxSiz;
  1020. i = 0;
  1021. }else{
  1022. strHrz = xaxSiz - 1; endHrz = -1;
  1023. i = (xaxOfs + xaxSiz) * xaxNrt / xaxDnt;
  1024. i -= xaxOfs * xaxNrt / xaxDnt;
  1025. i -= 1;
  1026. }
  1027. for(cntHrz = strHrz ; cntHrz != endHrz ; cntHrz+=idc){
  1028. xaxSet = (xaxOfs + cntHrz + 1) * xaxNrt / xaxDnt;
  1029. xaxSet -= (xaxOfs + cntHrz) * xaxNrt / xaxDnt;
  1030. for(cntXax = 0 ; cntXax < xaxSet ; cntXax ++){
  1031. for(j = strCol ; j < 4 ; j++){
  1032. k = i * 4 + j;
  1033. num = cmyBuf[cntHrz * 4 + j];
  1034. if(num < CMYLOW){ num = 0; }
  1035. shiKii = num / 2 + 52;
  1036. if(j != 2){ /* except yellow */
  1037. if((num > 112)&&(num < 144)){
  1038. shiKii +=
  1039. ((SHORT)Wgt001[strYax%8][(strXax+i)%8]-32)*256/128;
  1040. }else{
  1041. shiKii +=
  1042. ((SHORT)Wgt002[strYax%8][(strXax+i)%8]-32)*num/128;
  1043. }
  1044. }
  1045. gos = ( CmyGo1[k - 4] * m00 +
  1046. CmyGo1[k ] * m01 +
  1047. CmyGo1[k + 4] * m02 +
  1048. CmyGo0[k - idc * 4] * m03
  1049. ) / sum;
  1050. if(gos + num > shiKii){
  1051. CmyGo0[k] = num + gos - 255;
  1052. /*---- enter line buffer ----*/
  1053. if(j == 0){
  1054. linBufCyn[i/8] |= ((BYTE)0x80 >> (i%8));
  1055. }else if(j == 1){
  1056. linBufMgt[i/8] |= ((BYTE)0x80 >> (i%8));
  1057. }else if(j == 2){
  1058. linBufYel[i/8] |= ((BYTE)0x80 >> (i%8));
  1059. }else{
  1060. linBufBla[i/8] |= ((BYTE)0x80 >> (i%8));
  1061. }
  1062. }else{
  1063. CmyGo0[k] = num + gos;
  1064. }
  1065. }
  1066. i += idc;
  1067. }
  1068. }
  1069. bak = CmyGo1;
  1070. CmyGo1 = CmyGo0;
  1071. CmyGo0 = bak;
  1072. linBufCyn += linByt;
  1073. linBufMgt += linByt;
  1074. linBufYel += linByt;
  1075. linBufBla += linByt;
  1076. strYax++;
  1077. }
  1078. if (yaxSet != 0) {
  1079. lpDiz->GosCMYK.Yax = YaxOfsCmy + yaxSet - 1;
  1080. }
  1081. return yaxSet;
  1082. }
  1083. #define BUNKAI (SHORT)8
  1084. //===================================================================================================
  1085. // RGB GOSA-Dispersion
  1086. //===================================================================================================
  1087. VOID WINAPI N4RgbGos(
  1088. LPN4DIZINF lpDiz,
  1089. DWORD xaxSiz,
  1090. DWORD drwXax,
  1091. DWORD yaxOfs,
  1092. LPBYTE rgbBuf
  1093. )
  1094. {
  1095. SHORT m00;
  1096. SHORT m01;
  1097. SHORT m02;
  1098. SHORT m03;
  1099. SHORT sum;
  1100. SHORT j;
  1101. SHORT gos;
  1102. SHORT out;
  1103. LONG i;
  1104. LONG k;
  1105. LONG idc;
  1106. LONG strXax;
  1107. LONG endXax;
  1108. LPSHORT RgbGo0;
  1109. LPSHORT RgbGo1;
  1110. DWORD GosTblXSize;
  1111. DWORD YaxOfsRgb;
  1112. if ((yaxOfs & 1) == 0) { // Y coodinate is even number?
  1113. RgbGo0 = lpDiz->GosRGB.Tbl[0];
  1114. RgbGo1 = lpDiz->GosRGB.Tbl[1];
  1115. } else {
  1116. RgbGo0 = lpDiz->GosRGB.Tbl[1];
  1117. RgbGo1 = lpDiz->GosRGB.Tbl[0];
  1118. }
  1119. GosTblXSize = lpDiz->GosRGB.Siz;
  1120. YaxOfsRgb = lpDiz->GosRGB.Yax;
  1121. RgbGo0 += 3;
  1122. RgbGo1 += 3;
  1123. if(yaxOfs - YaxOfsRgb != 1){
  1124. for(i = 0 ; (DWORD)i < GosTblXSize * 3 ; i++){
  1125. RgbGo1[i] = 0;
  1126. }
  1127. }
  1128. lpDiz->GosRGB.Yax = yaxOfs;
  1129. RgbGo0 += drwXax * 3;
  1130. RgbGo1 += drwXax * 3;
  1131. /*---- filter set ----*/
  1132. switch(yaxOfs % 6){
  1133. case 0: /*---- evn1 >> filter ----*/
  1134. m00=3; m01=5; m02=3; m03=7;
  1135. idc = +1; strXax = 0; endXax = xaxSiz;
  1136. break;
  1137. case 1: /*---- odd1 >> filter ----*/
  1138. m00=1; m01=5; m02=3; m03=7;
  1139. idc = +1; strXax = 0; endXax = xaxSiz;
  1140. break;
  1141. case 2: /*---- evn2 >> filter ----*/
  1142. m00=4; m01=5; m02=4; m03=8;
  1143. idc = +1; strXax = 0; endXax = xaxSiz;
  1144. break;
  1145. case 3: /*---- odd2 << filter ----*/
  1146. m00=1; m01=3; m02=0; m03=7;
  1147. idc = -1; strXax = xaxSiz - 1; endXax = -1;
  1148. break;
  1149. case 4: /*---- evn3 << filter ----*/
  1150. m00=2; m01=4; m02=0; m03=8;
  1151. idc = -1; strXax = xaxSiz - 1; endXax = -1;
  1152. break;
  1153. case 5: /*---- odd4 >> filter ----*/
  1154. default:
  1155. m00=3; m01=8; m02=3; m03=8;
  1156. idc = +1; strXax = 0; endXax = xaxSiz;
  1157. break;
  1158. }
  1159. sum = m00 + m01 + m02 + m03;
  1160. /*---- GOSA-dispersion ----*/
  1161. for(i = strXax ; i != endXax ; i += idc){
  1162. for(j = 0 ; j < 3 ; j++){
  1163. k = i * 3 + j;
  1164. gos = ( m00 * RgbGo1[k - 3] +
  1165. m01 * RgbGo1[k ] +
  1166. m02 * RgbGo1[k + 3] +
  1167. m03 * RgbGo0[k - idc*3]
  1168. ) / sum;
  1169. out = gos + rgbBuf[k];
  1170. out = out / BUNKAI;
  1171. out = out * BUNKAI;
  1172. if(out > 255){ out = 255; }
  1173. else if(out < 0){ out = 0; }
  1174. RgbGo0[k] = (gos + (SHORT)rgbBuf[k]) - out;
  1175. rgbBuf[k] = (BYTE)out;
  1176. }
  1177. }
  1178. return;
  1179. }
  1180. //===================================================================================================
  1181. // Color Matching(Speed is high)
  1182. //===================================================================================================
  1183. VOID WINAPI N4ColMch000(
  1184. LPN4DIZINF lpDiz,
  1185. LPRGB rgbAdr,
  1186. LPCMYK cmyAdr,
  1187. DWORD xaxSiz,
  1188. DWORD blaCnv
  1189. )
  1190. {
  1191. LPRGB endAdr;
  1192. LPCMYK LokUppRgbCmy; // Lut table
  1193. LPBYTE innTblCmy; // Toner density table
  1194. LONG tmpRed;
  1195. LONG tmpGrn;
  1196. LONG tmpBlu;
  1197. LONG tmpCal;
  1198. CMYK tmpCmy;
  1199. LokUppRgbCmy = lpDiz->Lut.Tbl;
  1200. innTblCmy = lpDiz->Tnr.Tbl;
  1201. for(endAdr = rgbAdr+xaxSiz ; rgbAdr < endAdr ; rgbAdr++){
  1202. tmpRed = rgbAdr->Red;
  1203. tmpGrn = rgbAdr->Green;
  1204. tmpBlu = rgbAdr->Blue;
  1205. if((blaCnv == 0)&&((tmpRed | tmpGrn | tmpBlu) == 0)){
  1206. tmpCmy.Cyn = 0;
  1207. tmpCmy.Mgt = 0;
  1208. tmpCmy.Yel = 0;
  1209. tmpCmy.Bla = 255;
  1210. *cmyAdr = tmpCmy;
  1211. cmyAdr++;
  1212. continue;
  1213. }
  1214. tmpCal = tmpRed / N4_GLDSPC * N4_GLDNUM * N4_GLDNUM;
  1215. tmpCal += tmpGrn / N4_GLDSPC * N4_GLDNUM;
  1216. tmpCal += tmpBlu / N4_GLDSPC;
  1217. tmpCmy = LokUppRgbCmy[tmpCal];
  1218. tmpCmy.Cyn = innTblCmy[tmpCmy.Cyn];
  1219. tmpCmy.Mgt = innTblCmy[tmpCmy.Mgt];
  1220. tmpCmy.Yel = innTblCmy[tmpCmy.Yel];
  1221. tmpCmy.Bla = innTblCmy[tmpCmy.Bla];
  1222. *cmyAdr = tmpCmy;
  1223. cmyAdr++;
  1224. }
  1225. }
  1226. //===================================================================================================
  1227. // Color Matching(Speed is normal)
  1228. //===================================================================================================
  1229. VOID WINAPI N4ColMch001(
  1230. LPN4DIZINF lpDiz,
  1231. LPRGB rgbAdr,
  1232. LPCMYK cmyAdr,
  1233. DWORD xaxSiz,
  1234. DWORD blaCnv
  1235. )
  1236. {
  1237. LONG tmpRed;
  1238. LONG tmpGrn;
  1239. LONG tmpBlu;
  1240. LONG tmpR01;
  1241. LONG tmpR02;
  1242. LONG tmpG01;
  1243. LONG tmpG02;
  1244. LONG tmpB01;
  1245. LONG tmpB02;
  1246. LONG ln1;
  1247. LONG ln2;
  1248. LONG ln3;
  1249. LONG tmpC00;
  1250. LONG tmpM00;
  1251. LONG tmpY00;
  1252. LONG tmpK00;
  1253. LONG tmpC01;
  1254. LONG tmpM01;
  1255. LONG tmpY01;
  1256. LONG tmpK01;
  1257. LONG tmpC02;
  1258. LONG tmpM02;
  1259. LONG tmpY02;
  1260. LONG tmpK02;
  1261. LONG tmpC03;
  1262. LONG tmpM03;
  1263. LONG tmpY03;
  1264. LONG tmpK03;
  1265. LPCMYK LokUppRgbCmy;
  1266. LPBYTE innTblCmy;
  1267. LPRGB CchRgb;
  1268. LPCMYK CchCmy;
  1269. LPRGB endAdr;
  1270. DWORD cch;
  1271. RGBS tmpRgb;
  1272. CMYK tmpCmy;
  1273. LokUppRgbCmy = lpDiz->Lut.Tbl;
  1274. innTblCmy = lpDiz->Tnr.Tbl;
  1275. CchRgb = lpDiz->Lut.CchRgb;
  1276. CchCmy = lpDiz->Lut.CchCmy;
  1277. for(endAdr = rgbAdr+xaxSiz ; rgbAdr < endAdr ; rgbAdr++){
  1278. tmpRgb = *rgbAdr;
  1279. tmpRed = tmpRgb.Red;
  1280. tmpGrn = tmpRgb.Green;
  1281. tmpBlu = tmpRgb.Blue;
  1282. if((blaCnv == 0)&&((tmpRed | tmpGrn | tmpBlu) == 0)){
  1283. tmpCmy.Cyn = 0;
  1284. tmpCmy.Mgt = 0;
  1285. tmpCmy.Yel = 0;
  1286. tmpCmy.Bla = 255;
  1287. *cmyAdr = tmpCmy;
  1288. cmyAdr++;
  1289. continue;
  1290. }
  1291. cch = ( tmpRed * 49 + tmpGrn * 9 + tmpBlu ) % N4_CCHNUM;
  1292. if( (CchRgb[cch].Red == tmpRgb.Red) &&
  1293. (CchRgb[cch].Green == tmpRgb.Green) &&
  1294. (CchRgb[cch].Blue == tmpRgb.Blue)
  1295. ){
  1296. *cmyAdr = CchCmy[cch];
  1297. cmyAdr++;
  1298. continue;
  1299. }
  1300. /*---- RGB -> CMYK ----*/
  1301. tmpR01 = tmpRed * 31 / 255;
  1302. tmpR02 = (tmpRed * 31 + 254) / 255;
  1303. tmpG01 = tmpGrn * 31 / 255;
  1304. tmpG02 = (tmpGrn * 31 + 254) / 255;
  1305. tmpB01 = tmpBlu * 31 / 255;
  1306. tmpB02 = (tmpBlu * 31 + 254) / 255;
  1307. ln2 = tmpRed - tmpR01*255/31;
  1308. if(ln2 == 0){
  1309. tmpCmy = LokUppRgbCmy[tmpR01 * N4_GLDNUM * N4_GLDNUM + tmpG01 * N4_GLDNUM + tmpB01];
  1310. tmpC00 = tmpCmy.Cyn;
  1311. tmpM00 = tmpCmy.Mgt;
  1312. tmpY00 = tmpCmy.Yel;
  1313. tmpK00 = tmpCmy.Bla;
  1314. tmpCmy = LokUppRgbCmy[tmpR01 * N4_GLDNUM * N4_GLDNUM + tmpG01 * N4_GLDNUM + tmpB02];
  1315. tmpC01 = tmpCmy.Cyn;
  1316. tmpM01 = tmpCmy.Mgt;
  1317. tmpY01 = tmpCmy.Yel;
  1318. tmpK01 = tmpCmy.Bla;
  1319. tmpCmy = LokUppRgbCmy[tmpR01 * N4_GLDNUM * N4_GLDNUM + tmpG02 * N4_GLDNUM + tmpB01];
  1320. tmpC02 = tmpCmy.Cyn;
  1321. tmpM02 = tmpCmy.Mgt;
  1322. tmpY02 = tmpCmy.Yel;
  1323. tmpK02 = tmpCmy.Bla;
  1324. tmpCmy = LokUppRgbCmy[tmpR01 * N4_GLDNUM * N4_GLDNUM + tmpG02 * N4_GLDNUM + tmpB02];
  1325. tmpC03 = tmpCmy.Cyn;
  1326. tmpM03 = tmpCmy.Mgt;
  1327. tmpY03 = tmpCmy.Yel;
  1328. tmpK03 = tmpCmy.Bla;
  1329. }else{
  1330. ln1 = tmpR02*255/31 - tmpRed;
  1331. if(ln1 == 0){
  1332. tmpCmy = LokUppRgbCmy[tmpR02 * N4_GLDNUM * N4_GLDNUM + tmpG01 * N4_GLDNUM + tmpB01];
  1333. tmpC00 = tmpCmy.Cyn;
  1334. tmpM00 = tmpCmy.Mgt;
  1335. tmpY00 = tmpCmy.Yel;
  1336. tmpK00 = tmpCmy.Bla;
  1337. tmpCmy = LokUppRgbCmy[tmpR02 * N4_GLDNUM * N4_GLDNUM + tmpG01 * N4_GLDNUM + tmpB02];
  1338. tmpC01 = tmpCmy.Cyn;
  1339. tmpM01 = tmpCmy.Mgt;
  1340. tmpY01 = tmpCmy.Yel;
  1341. tmpK01 = tmpCmy.Bla;
  1342. tmpCmy = LokUppRgbCmy[tmpR02 * N4_GLDNUM * N4_GLDNUM + tmpG02 * N4_GLDNUM + tmpB01];
  1343. tmpC02 = tmpCmy.Cyn;
  1344. tmpM02 = tmpCmy.Mgt;
  1345. tmpY02 = tmpCmy.Yel;
  1346. tmpK02 = tmpCmy.Bla;
  1347. tmpCmy = LokUppRgbCmy[tmpR02 * N4_GLDNUM * N4_GLDNUM + tmpG02 * N4_GLDNUM + tmpB02];
  1348. tmpC03 = tmpCmy.Cyn;
  1349. tmpM03 = tmpCmy.Mgt;
  1350. tmpY03 = tmpCmy.Yel;
  1351. tmpK03 = tmpCmy.Bla;
  1352. }else{
  1353. ln3 = ln1 + ln2;
  1354. tmpCmy = LokUppRgbCmy[tmpR01 * N4_GLDNUM * N4_GLDNUM + tmpG01 * N4_GLDNUM + tmpB01];
  1355. tmpC00 = ln1 * tmpCmy.Cyn;
  1356. tmpM00 = ln1 * tmpCmy.Mgt;
  1357. tmpY00 = ln1 * tmpCmy.Yel;
  1358. tmpK00 = ln1 * tmpCmy.Bla;
  1359. tmpCmy = LokUppRgbCmy[tmpR02 * N4_GLDNUM * N4_GLDNUM + tmpG01 * N4_GLDNUM + tmpB01];
  1360. tmpC00 += ln2 * tmpCmy.Cyn;
  1361. tmpM00 += ln2 * tmpCmy.Mgt;
  1362. tmpY00 += ln2 * tmpCmy.Yel;
  1363. tmpK00 += ln2 * tmpCmy.Bla;
  1364. tmpC00 /= ln3;
  1365. tmpM00 /= ln3;
  1366. tmpY00 /= ln3;
  1367. tmpK00 /= ln3;
  1368. tmpCmy = LokUppRgbCmy[tmpR01 * N4_GLDNUM * N4_GLDNUM + tmpG01 * N4_GLDNUM + tmpB02];
  1369. tmpC01 = ln1 * tmpCmy.Cyn;
  1370. tmpM01 = ln1 * tmpCmy.Mgt;
  1371. tmpY01 = ln1 * tmpCmy.Yel;
  1372. tmpK01 = ln1 * tmpCmy.Bla;
  1373. tmpCmy = LokUppRgbCmy[tmpR02 * N4_GLDNUM * N4_GLDNUM + tmpG01 * N4_GLDNUM + tmpB02];
  1374. tmpC01 += ln2 * tmpCmy.Cyn;
  1375. tmpM01 += ln2 * tmpCmy.Mgt;
  1376. tmpY01 += ln2 * tmpCmy.Yel;
  1377. tmpK01 += ln2 * tmpCmy.Bla;
  1378. tmpC01 /= ln3;
  1379. tmpM01 /= ln3;
  1380. tmpY01 /= ln3;
  1381. tmpK01 /= ln3;
  1382. tmpCmy = LokUppRgbCmy[tmpR01 * N4_GLDNUM * N4_GLDNUM + tmpG02 * N4_GLDNUM + tmpB01];
  1383. tmpC02 = ln1 * tmpCmy.Cyn;
  1384. tmpM02 = ln1 * tmpCmy.Mgt;
  1385. tmpY02 = ln1 * tmpCmy.Yel;
  1386. tmpK02 = ln1 * tmpCmy.Bla;
  1387. tmpCmy = LokUppRgbCmy[tmpR02 * N4_GLDNUM * N4_GLDNUM + tmpG02 * N4_GLDNUM + tmpB01];
  1388. tmpC02 += ln2 * tmpCmy.Cyn;
  1389. tmpM02 += ln2 * tmpCmy.Mgt;
  1390. tmpY02 += ln2 * tmpCmy.Yel;
  1391. tmpK02 += ln2 * tmpCmy.Bla;
  1392. tmpC02 /= ln3;
  1393. tmpM02 /= ln3;
  1394. tmpY02 /= ln3;
  1395. tmpK02 /= ln3;
  1396. tmpCmy = LokUppRgbCmy[tmpR01 * N4_GLDNUM * N4_GLDNUM + tmpG02 * N4_GLDNUM + tmpB02];
  1397. tmpC03 = ln1 * tmpCmy.Cyn;
  1398. tmpM03 = ln1 * tmpCmy.Mgt;
  1399. tmpY03 = ln1 * tmpCmy.Yel;
  1400. tmpK03 = ln1 * tmpCmy.Bla;
  1401. tmpCmy = LokUppRgbCmy[tmpR02 * N4_GLDNUM * N4_GLDNUM + tmpG02 * N4_GLDNUM + tmpB02];
  1402. tmpC03 += ln2 * tmpCmy.Cyn;
  1403. tmpM03 += ln2 * tmpCmy.Mgt;
  1404. tmpY03 += ln2 * tmpCmy.Yel;
  1405. tmpK03 += ln2 * tmpCmy.Bla;
  1406. tmpC03 /= ln3;
  1407. tmpM03 /= ln3;
  1408. tmpY03 /= ln3;
  1409. tmpK03 /= ln3;
  1410. }
  1411. }
  1412. ln2 = tmpGrn - tmpG01*255/31;
  1413. if(ln2 != 0){
  1414. ln1 = tmpG02*255/31 - tmpGrn;
  1415. if(ln1 == 0){
  1416. tmpC00 = tmpC02;
  1417. tmpM00 = tmpM02;
  1418. tmpY00 = tmpY02;
  1419. tmpK00 = tmpK02;
  1420. tmpC01 = tmpC03;
  1421. tmpM01 = tmpM03;
  1422. tmpY01 = tmpY03;
  1423. tmpK01 = tmpK03;
  1424. }else{
  1425. ln3 = ln1 + ln2;
  1426. tmpC00 = (ln1*tmpC00 + ln2*tmpC02) / ln3;
  1427. tmpM00 = (ln1*tmpM00 + ln2*tmpM02) / ln3;
  1428. tmpY00 = (ln1*tmpY00 + ln2*tmpY02) / ln3;
  1429. tmpK00 = (ln1*tmpK00 + ln2*tmpK02) / ln3;
  1430. tmpC01 = (ln1*tmpC01 + ln2*tmpC03) / ln3;
  1431. tmpM01 = (ln1*tmpM01 + ln2*tmpM03) / ln3;
  1432. tmpY01 = (ln1*tmpY01 + ln2*tmpY03) / ln3;
  1433. tmpK01 = (ln1*tmpK01 + ln2*tmpK03) / ln3;
  1434. }
  1435. }
  1436. ln2 = tmpBlu - tmpB01*255/31;
  1437. if(ln2 != 0){
  1438. ln1 = tmpB02*255/31 - tmpBlu;
  1439. if(ln1 == 0){
  1440. tmpC00 = tmpC01;
  1441. tmpM00 = tmpM01;
  1442. tmpY00 = tmpY01;
  1443. tmpK00 = tmpK01;
  1444. }else{
  1445. ln3 = ln1 + ln2;
  1446. tmpC00 = (ln1*tmpC00 + ln2*tmpC01) / ln3;
  1447. tmpM00 = (ln1*tmpM00 + ln2*tmpM01) / ln3;
  1448. tmpY00 = (ln1*tmpY00 + ln2*tmpY01) / ln3;
  1449. tmpK00 = (ln1*tmpK00 + ln2*tmpK01) / ln3;
  1450. }
  1451. }
  1452. tmpCmy.Cyn = innTblCmy[tmpC00];
  1453. tmpCmy.Mgt = innTblCmy[tmpM00];
  1454. tmpCmy.Yel = innTblCmy[tmpY00];
  1455. tmpCmy.Bla = innTblCmy[tmpK00];
  1456. *cmyAdr = tmpCmy;
  1457. cmyAdr++;
  1458. CchRgb[cch] = tmpRgb;
  1459. CchCmy[cch] = tmpCmy;
  1460. }
  1461. }
  1462. //===================================================================================================
  1463. // RGB -> CMYK Conversion(No matching)
  1464. //===================================================================================================
  1465. VOID WINAPI N4ColCnvSld(
  1466. LPN4DIZINF lpDiz,
  1467. LPRGB rgbAdr,
  1468. LPCMYK cmyAdr,
  1469. DWORD xaxSiz
  1470. )
  1471. {
  1472. LPRGB endAdr;
  1473. BYTE red;
  1474. BYTE grn;
  1475. BYTE blu;
  1476. BYTE cyn;
  1477. BYTE mgt;
  1478. BYTE yel;
  1479. BYTE bla;
  1480. LPBYTE innTblCmy;
  1481. innTblCmy = lpDiz->Tnr.Tbl;
  1482. for(endAdr = rgbAdr + xaxSiz; rgbAdr < endAdr; rgbAdr++, cmyAdr++){
  1483. red = rgbAdr->Red;
  1484. grn = rgbAdr->Green;
  1485. blu = rgbAdr->Blue;
  1486. if((red == 0)&&(grn == 0)&&(blu == 0)){
  1487. cmyAdr->Cyn = 0;
  1488. cmyAdr->Mgt = 0;
  1489. cmyAdr->Yel = 0;
  1490. cmyAdr->Bla = 255;
  1491. } else {
  1492. cyn = 255 - red;
  1493. mgt = 255 - grn;
  1494. yel = 255 - blu;
  1495. if(cyn > mgt){
  1496. if(mgt > yel){
  1497. bla = yel / 4;
  1498. }else{
  1499. bla = mgt / 4;
  1500. }
  1501. }else{
  1502. if(cyn > yel){
  1503. bla = yel / 4;
  1504. }else{
  1505. bla = cyn / 4;
  1506. }
  1507. }
  1508. cyn -= bla;
  1509. mgt -= bla;
  1510. yel -= bla;
  1511. if(innTblCmy != NULL){
  1512. cmyAdr->Cyn = innTblCmy[GamTbl014[cyn]];
  1513. cmyAdr->Mgt = innTblCmy[GamTbl014[mgt]];
  1514. cmyAdr->Yel = innTblCmy[GamTbl014[yel]];
  1515. cmyAdr->Bla = innTblCmy[bla];
  1516. }else{
  1517. cmyAdr->Cyn = GamTbl014[cyn];
  1518. cmyAdr->Mgt = GamTbl014[mgt];
  1519. cmyAdr->Yel = GamTbl014[yel];
  1520. cmyAdr->Bla = bla;
  1521. }
  1522. }
  1523. }
  1524. return;
  1525. }
  1526. //===================================================================================================
  1527. // RGB -> CMYK conversion
  1528. //===================================================================================================
  1529. VOID WINAPI N4ColCnvLin(
  1530. LPN4DIZINF lpDiz,
  1531. LPRGB rgbAdr,
  1532. LPCMYK cmyAdr,
  1533. DWORD xaxSiz
  1534. )
  1535. {
  1536. LPRGB endAdr;
  1537. WORD red;
  1538. WORD grn;
  1539. WORD blu;
  1540. WORD mid;
  1541. BYTE cyn;
  1542. BYTE mgt;
  1543. BYTE yel;
  1544. for(endAdr = rgbAdr + xaxSiz; rgbAdr < endAdr; rgbAdr++, cmyAdr++){
  1545. red = rgbAdr->Red;
  1546. grn = rgbAdr->Green;
  1547. blu = rgbAdr->Blue;
  1548. mid = (red + grn + blu)/3;
  1549. if(mid > 240){
  1550. cmyAdr->Cyn = 0;
  1551. cmyAdr->Mgt = 0;
  1552. cmyAdr->Yel = 0;
  1553. cmyAdr->Bla = 0;
  1554. } else {
  1555. cyn = 255;
  1556. mgt = 255;
  1557. yel = 255;
  1558. mid += (255 - mid)/8;
  1559. if(red > mid){ cyn = 0; }
  1560. if(grn > mid){ mgt = 0; }
  1561. if(blu > mid){ yel = 0; }
  1562. if((cyn & mgt & yel)==255){
  1563. cmyAdr->Cyn = 0;
  1564. cmyAdr->Mgt = 0;
  1565. cmyAdr->Yel = 0;
  1566. cmyAdr->Bla = 255;
  1567. } else {
  1568. cmyAdr->Cyn = cyn;
  1569. cmyAdr->Mgt = mgt;
  1570. cmyAdr->Yel = yel;
  1571. cmyAdr->Bla = 0;
  1572. }
  1573. }
  1574. }
  1575. return;
  1576. }
  1577. //===================================================================================================
  1578. // RGB -> CMYK conversion (for monochrome)
  1579. //===================================================================================================
  1580. VOID WINAPI N4ColCnvMon(
  1581. LPN4DIZINF lpDiz,
  1582. DWORD diz,
  1583. LPRGB rgbAdr,
  1584. LPCMYK cmyAdr,
  1585. DWORD xaxSiz
  1586. )
  1587. {
  1588. LPRGB endAdr;
  1589. LONG red;
  1590. LONG grn;
  1591. LONG blu;
  1592. LONG bla;
  1593. LPBYTE innTblCmy;
  1594. innTblCmy = lpDiz->Tnr.Tbl;
  1595. if (diz == N4_DIZ_SML) {
  1596. for(endAdr = rgbAdr + xaxSiz; rgbAdr < endAdr; rgbAdr++, cmyAdr++){
  1597. red = rgbAdr->Red;
  1598. grn = rgbAdr->Green;
  1599. blu = rgbAdr->Blue;
  1600. bla = 255 - (red*3 + grn*5 + blu*2) / 10;
  1601. if(bla > 128) { bla += SinTbl[bla] / 4; } else { bla += SinTbl[bla] / 24; }
  1602. if(bla != 0) { bla = (bla + 24) * 255 / (255 + 24); }
  1603. cmyAdr->Cyn = 0;
  1604. cmyAdr->Mgt = 0;
  1605. cmyAdr->Yel = 0;
  1606. if(innTblCmy != NULL){
  1607. cmyAdr->Bla = innTblCmy[GamTbl016[(BYTE)bla]];
  1608. }else{
  1609. cmyAdr->Bla = GamTbl016[(BYTE)bla];
  1610. }
  1611. }
  1612. } else if (diz == N4_DIZ_MID) {
  1613. for(endAdr = rgbAdr + xaxSiz; rgbAdr < endAdr; rgbAdr++, cmyAdr++){
  1614. red = rgbAdr->Red;
  1615. grn = rgbAdr->Green;
  1616. blu = rgbAdr->Blue;
  1617. bla = 255 - (red*3 + grn*5 + blu*2) / 10;
  1618. if(bla > 128) { bla += SinTbl[bla] / 8; } else { bla += SinTbl[bla] / 16; }
  1619. if(bla != 0) { bla = (bla + 24) * 255 / (255 + 24); }
  1620. cmyAdr->Cyn = 0;
  1621. cmyAdr->Mgt = 0;
  1622. cmyAdr->Yel = 0;
  1623. if(innTblCmy != NULL){
  1624. cmyAdr->Bla = innTblCmy[GamTbl016[(BYTE)bla]];
  1625. }else{
  1626. cmyAdr->Bla = GamTbl016[(BYTE)bla];
  1627. }
  1628. }
  1629. } else if (diz == N4_DIZ_RUG) {
  1630. for(endAdr = rgbAdr + xaxSiz; rgbAdr < endAdr; rgbAdr++, cmyAdr++){
  1631. red = rgbAdr->Red;
  1632. grn = rgbAdr->Green;
  1633. blu = rgbAdr->Blue;
  1634. bla = 255 - (red*3 + grn*5 + blu*2) / 10;
  1635. if(bla > 128) { bla += SinTbl[bla] / 32; } else { bla += SinTbl[bla] / 8; }
  1636. if(bla != 0) { bla = (bla + 24) * 255 / (255 + 24); }
  1637. cmyAdr->Cyn = 0;
  1638. cmyAdr->Mgt = 0;
  1639. cmyAdr->Yel = 0;
  1640. if(innTblCmy != NULL){
  1641. cmyAdr->Bla = innTblCmy[GamTbl016[(BYTE)bla]];
  1642. }else{
  1643. cmyAdr->Bla = GamTbl016[(BYTE)bla];
  1644. }
  1645. }
  1646. } else {
  1647. for(endAdr = rgbAdr + xaxSiz; rgbAdr < endAdr; rgbAdr++, cmyAdr++){
  1648. red = rgbAdr->Red;
  1649. grn = rgbAdr->Green;
  1650. blu = rgbAdr->Blue;
  1651. bla = 255 - (red*3 + grn*5 + blu*2) / 10;
  1652. if(bla > 128) { bla += SinTbl[bla] / 6; } else { bla += SinTbl[bla] / 24; }
  1653. if(bla != 0) { bla = (bla + 24) * 255 / (255 + 24); }
  1654. cmyAdr->Cyn = 0;
  1655. cmyAdr->Mgt = 0;
  1656. cmyAdr->Yel = 0;
  1657. if(innTblCmy != NULL){
  1658. cmyAdr->Bla = innTblCmy[GamTbl016[(BYTE)bla]];
  1659. }else{
  1660. cmyAdr->Bla = GamTbl016[(BYTE)bla];
  1661. }
  1662. }
  1663. }
  1664. return;
  1665. }
  1666. // End of N4DIZ.C