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.

953 lines
30 KiB

  1. /*++
  2. Copyright (c) 1990-1991 Microsoft Corporation
  3. Module Name:
  4. htmapclr.h
  5. Abstract:
  6. This module contains all halftone color mapping constants for the
  7. htmapclr.c
  8. Author:
  9. 28-Mar-1992 Sat 20:56:27 updated -by- Daniel Chou (danielc)
  10. Add in ULDECI4 type, to store the stretchfacor (source -> dest)
  11. add StretchFactor in StretchInfo data structure.
  12. Add support for StretchFactor (ULDECI4 format), so we can internally
  13. turn off VGA16 when the bitmap is badly compressed.
  14. 29-Jan-1991 Tue 10:29:04 created -by- Daniel Chou (danielc)
  15. [Environment:]
  16. GDI Device Driver - Halftone.
  17. [Notes:]
  18. Revision History:
  19. --*/
  20. #ifndef _HTMAPCLR_
  21. #define _HTMAPCLR_
  22. #include "htmath.h"
  23. #define DO_CACHE_DCI 0
  24. //
  25. // Halftone process's DECI4 vlaues for the WHITE/BLACK/GRAY
  26. //
  27. #define DECI4_ONE (DECI4)10000
  28. #define DECI4_ZERO (DECI4)0
  29. #define LDECI4_ONE (LDECI4)10000
  30. #define LDECI4_ZERO (LDECI4)0
  31. #define STD_WHITE DECI4_ONE
  32. #define STD_BLACK DECI4_ZERO
  33. #define LSTD_WHITE LDECI4_ONE
  34. #define LSTD_BLACK LDECI4_ZERO
  35. #define __SCALE_FD62B(f,l,d,b) (BYTE)(((((f)-(l))*(b))+((d)>>1))/(d))
  36. #define RATIO_SCALE(p,l,h) DivFD6(p - l, h - l)
  37. #define SCALE_FD62B(f,l,h,b) __SCALE_FD62B(f,l,(h)-(l),b)
  38. #define SCALE_FD6(f,b) __SCALE_FD62B(f,FD6_0,FD6_1,b)
  39. #define SCALE_FD62B_DIF(c,d,b) (BYTE)((((c)*(b))+((d)>>1))/(d))
  40. #define SCALE_INT2B(c,r,b) (BYTE)((((c)*(b))+((r)>>1))/(r))
  41. //
  42. // The following FD6 number are used in the color computation, using #define
  43. // for easy reading
  44. //
  45. #define FD6_1p16 (FD6)1160000
  46. #define FD6_p16 (FD6)160000
  47. #define FD6_p166667 (FD6)166667
  48. #define FD6_7p787 (FD6)7787000
  49. #define FD6_16Div116 (FD6)137931
  50. #define FD6_p008856 (FD6)8856
  51. #define FD6_p068962 (FD6)68962
  52. #define FD6_p079996 (FD6)79996
  53. #define FD6_9p033 (FD6)9033000
  54. #define FD6_p4 (FD6)400000
  55. #define UDECI4_NTSC_GAMMA (UDECI4)22000
  56. #define FD6_NTSC_GAMMA UDECI4ToFD6(UDECI4_NTSC_GAMMA)
  57. #define NORMALIZED_WHITE FD6_1
  58. #define NORMALIZED_BLACK FD6_0
  59. #define CLIP_TO_NORMALIZED_BW(x) if ((FD6)(x) < FD6_0) (x) = FD6_0; \
  60. if ((FD6)(x) > FD6_1) (x) = FD6_1
  61. #define DECI4AdjToFD6(a,f) (FD6)((FD6)(a) * (FD6)(f) * (FD6)100)
  62. #define VALIDATE_CLR_ADJ(a) if ((a) < MIN_RGB_COLOR_ADJ) { \
  63. (a) = MIN_RGB_COLOR_ADJ; \
  64. } else if ((a) > MAX_RGB_COLOR_ADJ) { \
  65. (a) = MAX_RGB_COLOR_ADJ; }
  66. #define LOG_INTENSITY(i) ((FD6)(i) > (FD6)120000) ? \
  67. (NORMALIZED_WHITE + Log((i))) : \
  68. (MulFD6((FD6)(i), (FD6)659844L))
  69. #define RANGE_CIE_xy(x,y) if ((x) < CIE_x_MIN) (x) = CIE_x_MIN; else \
  70. if ((x) > CIE_x_MAX) (x) = CIE_x_MAX; \
  71. if ((y) < CIE_y_MIN) (y) = CIE_y_MIN; else \
  72. if ((y) > CIE_y_MAX) (y) = CIE_y_MAX \
  73. #define MAX_OF_3(max,a,b,c) if ((c)>((max)=(((a)>(b)) ? (a) : (b)))) (max)=(c)
  74. #define MIN_OF_3(min,a,b,c) if ((c)<((min)=(((a)<(b)) ? (a) : (b)))) (min)=(c)
  75. #define CIE_NORMAL_MONITOR 0
  76. #define CIE_NTSC 1
  77. #define CIE_CIE 2
  78. #define CIE_EBU 3
  79. #define CIE_NORMAL_PRINTER 4
  80. //
  81. // For 1 Bit per pel we have maximum 2 mapping table entries
  82. // For 4 Bit per pel we have maximum 16 mapping table entries
  83. // For 8 Bit per pel we have maximum 256 mapping table entries
  84. // For 16 Bit per pel we have maximum 65536 mapping table entries
  85. //
  86. // For 24 bits per pel, we will clip each color (0 - 255) into 0-15 (16 steps)
  87. // and provided a total 4096 colors.
  88. //
  89. #define CUBE_ENTRIES(c) ((c) * (c) * (c))
  90. #define HT_RGB_MAX_COUNT 32
  91. #define HT_RGB_CUBE_COUNT CUBE_ENTRIES(HT_RGB_MAX_COUNT)
  92. #define HT_RGB_R_INC 1
  93. #define HT_RGB_G_INC HT_RGB_MAX_COUNT
  94. #define HT_RGB_B_INC (HT_RGB_MAX_COUNT * HT_RGB_MAX_COUNT)
  95. #define VGA256_R_IDX_MAX 5
  96. #define VGA256_G_IDX_MAX 5
  97. #define VGA256_B_IDX_MAX 5
  98. #define VGA256_M_IDX_MAX 25
  99. #define VGA256_CUBE_SIZE ((VGA256_R_IDX_MAX + 1) * \
  100. (VGA256_G_IDX_MAX + 1) * \
  101. (VGA256_B_IDX_MAX + 1))
  102. #define VGA256_MONO_SIZE (VGA256_M_IDX_MAX + 1)
  103. #define VGA256_M_IDX_START VGA256_CUBE_SIZE
  104. #define VGA256_R_CUBE_INC 1
  105. #define VGA256_G_CUBE_INC (VGA256_R_IDX_MAX + 1)
  106. #define VGA256_B_CUBE_INC (VGA256_G_CUBE_INC * (VGA256_G_IDX_MAX + 1))
  107. #define VGA256_W_CUBE_INC (VGA256_R_CUBE_INC + VGA256_G_CUBE_INC + \
  108. VGA256_B_CUBE_INC)
  109. #define VGA256_R_INT_INC (FD6)(FD6_1 / VGA256_R_IDX_MAX)
  110. #define VGA256_G_INT_INC (FD6)(FD6_1 / VGA256_G_IDX_MAX)
  111. #define VGA256_B_INT_INC (FD6)(FD6_1 / VGA256_B_IDX_MAX)
  112. #define VGA256_PALETTE_COUNT (VGA256_CUBE_SIZE + VGA256_MONO_SIZE)
  113. #define RGB555_C_LEVELS 32
  114. #define RGB555_P1_CUBE_INC (RGB555_C_LEVELS * RGB555_C_LEVELS)
  115. #define RGB555_P2_CUBE_INC RGB555_C_LEVELS
  116. #define RGB555_P3_CUBE_INC 1
  117. typedef HANDLE HTMUTEX;
  118. typedef HTMUTEX *PHTMUTEX;
  119. #ifdef UMODE
  120. #define CREATE_HTMUTEX() (HTMUTEX)CreateMutex(NULL, FALSE, NULL)
  121. #define ACQUIRE_HTMUTEX(x) WaitForSingleObject((HANDLE)(x), (DWORD)~0)
  122. #define RELEASE_HTMUTEX(x) ReleaseMutex((HANDLE)(x))
  123. #define DELETE_HTMUTEX(x) CloseHandle((HANDLE)(x))
  124. #else
  125. #define CREATE_HTMUTEX() (HTMUTEX)EngCreateSemaphore()
  126. #define ACQUIRE_HTMUTEX(x) EngAcquireSemaphore((HSEMAPHORE)(x))
  127. #define RELEASE_HTMUTEX(x) EngReleaseSemaphore((HSEMAPHORE)(x))
  128. #define DELETE_HTMUTEX(x) EngDeleteSemaphore((HSEMAPHORE)(x))
  129. #endif
  130. #define NTSC_R_INT 299000
  131. #define NTSC_G_INT 587000
  132. #define NTSC_B_INT 114000
  133. typedef struct _RGBTOPRIM {
  134. BYTE Flags;
  135. BYTE ColorTableType;
  136. BYTE SrcRGBSize;
  137. BYTE DevRGBSize;
  138. } RGBTOPRIM;
  139. typedef struct _FD6RGB {
  140. FD6 R;
  141. FD6 G;
  142. FD6 B;
  143. } FD6RGB, FAR *PFD6RGB;
  144. typedef struct _FD6XYZ {
  145. FD6 X;
  146. FD6 Y;
  147. FD6 Z;
  148. } FD6XYZ, FAR *PFD6XYZ;
  149. typedef struct _FD6PRIM123 {
  150. FD6 p1;
  151. FD6 p2;
  152. FD6 p3;
  153. } FD6PRIM123, FAR *PFD6PRIM123;
  154. #define HTCF_STATIC_PTHRESHOLDS 0x01
  155. typedef struct _HTCELL {
  156. BYTE Flags;
  157. BYTE HTPatIdx;
  158. WORD wReserved;
  159. WORD cxOrg;
  160. WORD cxReal;
  161. WORD Width;
  162. WORD Height;
  163. DWORD Size;
  164. LPBYTE pThresholds;
  165. } HTCELL, *PHTCELL;
  166. #define MAPF_MONO_PRIMS 0x00000001
  167. #define MAPF_SKIP_LABLUV 0x00000002
  168. #if DBG
  169. #define DO_REGTEST 0
  170. #else
  171. #define DO_REGTEST 0
  172. #endif
  173. typedef struct _REGDATA {
  174. WORD DMin;
  175. WORD DMax;
  176. FD6 LMin;
  177. FD6 LMax;
  178. FD6 DMinMul;
  179. FD6 DMaxAdd;
  180. FD6 DMaxMul;
  181. FD6 DenAdd;
  182. FD6 DenMul;
  183. } REGDATA, *PREGDATA;
  184. #define REG_DMIN_ADD FD6_0
  185. #define REG_BASE_GAMMA (FD6) 932500
  186. #define REG_GAMMA_IDX_BASE (FD6)1050000
  187. #define MASK8BPP_GAMMA_DIV (FD6) 932500
  188. #define GET_REG_GAMMA(Idx) MulFD6(REG_BASE_GAMMA, \
  189. RaisePower(REG_GAMMA_IDX_BASE, \
  190. (FD6)(Idx) - (FD6)3, \
  191. RPF_INTEXP))
  192. #define K_REP_START (FD6) 666667
  193. #define K_REP_POWER (FD6)2000000
  194. //
  195. // Possible values:
  196. //
  197. // R G B
  198. // ------- ------- -------
  199. // 0.9859 1.0100 0.9859
  200. // 0.9789 1.0150 0.9789
  201. // 0.9720 1.0200 0.9720
  202. //
  203. #define SCM_R_GAMMA_MUL (FD6) 978900
  204. #define SCM_G_GAMMA_MUL (FD6)1015000
  205. #define SCM_B_GAMMA_MUL (FD6) 978900
  206. #define GRAY_MAX_IDX 0xFFFF
  207. #define IDXBGR_2_GRAY_BYTE(p,b,g,r) (BYTE)((p[0+(b)]+p[256+(g)]+p[512+(r)])>>8)
  208. #define BGR_2_GRAY_WORD(b,g,r) ((b)+(g)+(r))
  209. //
  210. // DEVCLRADJ
  211. //
  212. // This data structure describe how the color adjustment should be made
  213. // input RGB color and output device.
  214. //
  215. // Flags - No flag is defined.
  216. //
  217. // RedPowerAdj - The n-th power applied to the red color
  218. // before any other color adjustment, this is
  219. // a UDECI4 value. (0.0100 - 6.500)
  220. //
  221. // For example if the RED = 0.8 (DECI4=8000)
  222. // and the RedPowerGammaAdjustment = 0.7823
  223. // (DECI4 = 7823) then the red is equal to
  224. //
  225. // 0.7823
  226. // 0.8 = 0.8398
  227. //
  228. // GreenPowerAdj - The n-th power applied to the green color
  229. // before any other color adjustment, this is
  230. // a UDECI4 value. (0.0100 - 6.5000)
  231. //
  232. // BluePowerAdj - The n-th power applied to the blue color
  233. // before any other color adjustment, this is
  234. // a UDECI4 value. (0.0100 - 6.5000)
  235. //
  236. // NOTE: if the PowerGammaAdjustmenst values are
  237. // equal to 1.0 (DECI4 = 10000) then no
  238. // adjustment will be made, since any
  239. // number raised to the 1 will be equal
  240. // to itself, if this number is less than
  241. // 0.0100 (ie 100) or greater than 6.5000
  242. // (ie. 65000) then it default to 1.0000
  243. // (ie. 10000) and no adjustment is made.
  244. //
  245. // BrightnessAdj - The brightness adjustment, this is a DECI4
  246. // number range from -10000 (-1.0000) to
  247. // 10000 (1.0000). The brightness is adjusted
  248. // by apply to overall intensity for the primary
  249. // colors.
  250. //
  251. // ContrastAdj - Primary color contrast adjustment, this is
  252. // a DECI4 number range from -10000 (-1.0000)
  253. // to 10000 (1.0000). The primary color
  254. // curves are either compressed to the center or
  255. // expanded to the black/white.
  256. //
  257. // BDR - The ratio which the black dyes should be
  258. // replaced by the non-black dyes, higher the
  259. // number more black dyes are used to replace
  260. // the non-black dyes. This may saving the
  261. // color dyes but it may also loose color
  262. // saturation. this is a DECI4 number range
  263. // from -10000 to 10000 (ie. -1.0000 to 1.0000).
  264. // if this value is 0 then no repelacement is
  265. // take place.
  266. //
  267. //
  268. typedef struct _CIExy2 {
  269. UDECI4 x;
  270. UDECI4 y;
  271. } CIExy2, *PCIExy2;
  272. typedef struct _CIExy {
  273. FD6 x;
  274. FD6 y;
  275. } CIExy, FAR *PCIExy;
  276. typedef struct _CIExyY {
  277. FD6 x;
  278. FD6 y;
  279. FD6 Y;
  280. } CIExyY, *PCIExyY;
  281. typedef struct _CIEPRIMS {
  282. CIExy r;
  283. CIExy g;
  284. CIExy b;
  285. CIExy w;
  286. FD6 Yw;
  287. } CIEPRIMS, FAR *PCIEPRIMS;
  288. #define CIELUV_1976 0
  289. #define CIELAB_1976 1
  290. #define COLORSPACE_MAX_INDEX 1
  291. typedef struct _COLORSPACEXFORM {
  292. MATRIX3x3 M3x3;
  293. FD6XYZ WhiteXYZ;
  294. FD6RGB Yrgb;
  295. FD6 AUw;
  296. FD6 BVw;
  297. FD6 xW;
  298. FD6 yW;
  299. FD6 YW;
  300. } COLORSPACEXFORM, FAR *PCOLORSPACEXFORM;
  301. typedef struct _CLRXFORMBLOCK {
  302. BYTE Flags;
  303. BYTE ColorSpace;
  304. BYTE RegDataIdx;
  305. BYTE bReserved;
  306. CIEPRIMS rgbCIEPrims;
  307. CIEPRIMS DevCIEPrims;
  308. MATRIX3x3 CMYDyeMasks;
  309. FD6 DevGamma[3];
  310. } CLRXFORMBLOCK, *PCLRXFORMBLOCK;
  311. typedef struct _PRIMADJ {
  312. DWORD Flags;
  313. FD6 SrcGamma[3];
  314. FD6 DevGamma[3];
  315. FD6 Contrast;
  316. FD6 Brightness;
  317. FD6 Color;
  318. FD6 TintSinAngle;
  319. FD6 TintCosAngle;
  320. FD6 MinL;
  321. FD6 MaxL;
  322. FD6 MinLMul;
  323. FD6 MaxLMul;
  324. FD6 RangeLMul;
  325. COLORSPACEXFORM rgbCSXForm;
  326. COLORSPACEXFORM DevCSXForm;
  327. } PRIMADJ, *PPRIMADJ;
  328. #define CRTX_LEVEL_255 0
  329. #define CRTX_LEVEL_RGB 1
  330. #define CRTX_TOTAL_COUNT 2
  331. #define CRTX_PRIMMAX_255 255
  332. #define CRTX_PRIMMAX_RGB (HT_RGB_MAX_COUNT - 1)
  333. #define CRTX_SIZE_255 (sizeof(FD6XYZ) * (256 * 3))
  334. #define CRTX_SIZE_RGB (sizeof(FD6XYZ) * (HT_RGB_MAX_COUNT * 3))
  335. typedef struct _CACHERGBTOXYZ {
  336. DWORD Checksum;
  337. PFD6XYZ pFD6XYZ;
  338. WORD PrimMax;
  339. WORD SizeCRTX;
  340. } CACHERGBTOXYZ, FAR *PCACHERGBTOXYZ;
  341. #define DCA_HAS_ICM 0x00000001
  342. #define DCA_HAS_SRC_GAMMA 0x00000002
  343. #define DCA_HAS_DEST_GAMMA 0x00000004
  344. #define DCA_HAS_BW_REF_ADJ 0x00000008
  345. #define DCA_HAS_CONTRAST_ADJ 0x00000010
  346. #define DCA_HAS_BRIGHTNESS_ADJ 0x00000020
  347. #define DCA_HAS_COLOR_ADJ 0x00000040
  348. #define DCA_HAS_TINT_ADJ 0x00000080
  349. #define DCA_LOG_FILTER 0x00000100
  350. #define DCA_NEGATIVE 0x00000200
  351. #define DCA_NEED_DYES_CORRECTION 0x00000400
  352. #define DCA_HAS_BLACK_DYE 0x00000800
  353. #define DCA_DO_DEVCLR_XFORM 0x00001000
  354. #define DCA_MONO_ONLY 0x00002000
  355. #define DCA_USE_ADDITIVE_PRIMS 0x00004000
  356. #define DCA_HAS_CLRSPACE_ADJ 0x00008000
  357. #define DCA_MASK8BPP 0x00010000
  358. #define DCA_REPLACE_BLACK 0x00020000
  359. #define DCA_RGBLUTAA_MONO 0x00040000
  360. #define DCA_BBPF_AA_OFF 0x00080000
  361. #define DCA_ALPHA_BLEND 0x00100000
  362. #define DCA_CONST_ALPHA 0x00200000
  363. #define DCA_XLATE_555_666 0x00400000
  364. #define DCA_AB_PREMUL_SRC 0x00800000
  365. #define DCA_AB_DEST 0x01000000
  366. #define DCA_XLATE_332 0x02000000
  367. #define DCA_NO_MAPPING_TABLE 0x40000000
  368. #define DCA_NO_ANY_ADJ 0x80000000
  369. #define SIZE_XLATE_555 (((4 << 6) | (4 << 3) | 4) + 1)
  370. #define SIZE_XLATE_666 (((5 << 6) | (5 << 3) | 5) + 1)
  371. #define ADJ_FORCE_MONO 0x0001
  372. #define ADJ_FORCE_NEGATIVE 0x0002
  373. #define ADJ_FORCE_ADDITIVE_PRIMS 0x0004
  374. #define ADJ_FORCE_ICM 0x0008
  375. #define ADJ_FORCE_BRUSH 0x0010
  376. #define ADJ_FORCE_NO_EXP_AA 0x0020
  377. #define ADJ_FORCE_IDXBGR_MONO 0x0040
  378. #define ADJ_FORCE_ALPHA_BLEND 0x0080
  379. #define ADJ_FORCE_CONST_ALPHA 0x0100
  380. #define ADJ_FORCE_AB_PREMUL_SRC 0x0200
  381. #define ADJ_FORCE_AB_DEST 0x0400
  382. #define ADJ_FORCE_DEVXFORM 0x8000
  383. typedef struct _CTSTDINFO {
  384. BYTE cbPrim;
  385. BYTE SrcOrder;
  386. BYTE DestOrder;
  387. BYTE BMFDest;
  388. } CTSTDINFO;
  389. typedef struct _RGBORDER {
  390. BYTE Index;
  391. BYTE Order[3];
  392. } RGBORDER;
  393. typedef union _CTSTD_UNION {
  394. DWORD dw;
  395. CTSTDINFO b;
  396. } CTSTD_UNION;
  397. #define DMIF_GRAY 0x01
  398. typedef struct _DEVMAPINFO {
  399. BYTE Flags;
  400. BYTE LSft[3];
  401. CTSTDINFO CTSTDInfo;
  402. DWORD Mul[3];
  403. DWORD MulAdd;
  404. RGBORDER DstOrder;
  405. FD6 BlackChk;
  406. } DEVMAPINFO, *PDEVMAPINFO;
  407. typedef struct _DEVCLRADJ {
  408. HTCOLORADJUSTMENT ca;
  409. DEVMAPINFO DMI;
  410. PRIMADJ PrimAdj;
  411. PCLRXFORMBLOCK pClrXFormBlock;
  412. PCACHERGBTOXYZ pCRTXLevel255;
  413. PCACHERGBTOXYZ pCRTXLevelRGB;
  414. } DEVCLRADJ, FAR *PDEVCLRADJ;
  415. #define SIZE_BGR_MAPPING_TABLE (sizeof(BGR8) * (HT_RGB_CUBE_COUNT + 2))
  416. //
  417. // Following define must corresponsed to the InputFuncTable[] definitions
  418. //
  419. #define IDXIF_BMF1BPP_START 0
  420. #define IDXIF_BMF16BPP_START 6
  421. #define IDXIF_BMF24BPP_START 9
  422. #define IDXIF_BMF32BPP_START 13
  423. #define BF_GRAY_BITS 8
  424. #define BF_GRAY_TABLE_COUNT (1 << BF_GRAY_BITS)
  425. #define BFIF_RGB_888 0x01
  426. typedef struct _BFINFO {
  427. BYTE Flags;
  428. BYTE BitmapFormat;
  429. BYTE BitStart[3];
  430. BYTE BitCount[3];
  431. DWORD BitsRGB[3];
  432. RGBORDER RGBOrder;
  433. } BFINFO, FAR *PBFINFO;
  434. #define LUTAA_HDR_COUNT 6
  435. #define LUTAA_HDR_SIZE (LUTAA_HDR_COUNT * sizeof(DWORD))
  436. #define GET_LUTAAHDR(h,p) CopyMemory((LPBYTE)&(h[0]), \
  437. (LPBYTE)(p) - LUTAA_HDR_SIZE, \
  438. LUTAA_HDR_SIZE)
  439. typedef struct _RGBLUTAA {
  440. DWORD Checksum;
  441. DWORD ExtBGR[LUTAA_HDR_COUNT];
  442. LONG IdxBGR[256 * 3];
  443. } RGBLUTAA, *PRGBLUTAA;
  444. #define LUTSIZE_ANTI_ALIASING (sizeof(RGBLUTAA))
  445. //
  446. // DEVICECOLORINFO
  447. //
  448. // This data structure is a collection of the device characteristics and
  449. // will used by the halftone DLL to carry out the color composition for the
  450. // designated device.
  451. //
  452. // HalftoneDLLID - The ID for the structure, is #define as
  453. // HALFTONE_DLL_ID = "DCHT"
  454. //
  455. // HTCallBackFunction - a 32-bit pointer to the caller supplied
  456. // callback function which used by the halftone
  457. // DLL to obtained the source/destination bitmap
  458. // pointer durning the halftone process.
  459. //
  460. // pPrimMonoMappingTable - a pointer to the PRIMMONO data structure
  461. // array, this is the dye density mapping table
  462. // for the reduced gamut from 24-bit colors,
  463. // initially is NULL, and it will cached only
  464. // when the first time the source bitmap is
  465. // 24-bit per pel.
  466. //
  467. // pPrimColorMappingTable - a pointer to the PRIMCOLOR data structure
  468. // array, this is the dye density mapping table
  469. // for the reduced gamut from 24-bit colors,
  470. // initially is NULL, and it will cached only
  471. // when the first time the source bitmap is
  472. // 24-bit per pel.
  473. //
  474. // Flags - Various flag defined the initialization
  475. // requirements.
  476. //
  477. // DCIF_HAS_BLACK_DYE
  478. //
  479. // The device has true black dye, for this
  480. // version, this flag always set.
  481. //
  482. // DCIF_ADDITIVE_PRIMS
  483. //
  484. // Specified that final device primaries
  485. // are additively, that is adding device
  486. // primaries will produce lighter result.
  487. // (this is true for monitor device and
  488. // certainly false for the reflect devices
  489. // such as printers).
  490. //
  491. // pPrimMonoMappingTable - Pointer to a table which contains the cached
  492. // RGB -> Single dye density entries, this table
  493. // will be computed and cahced when first time
  494. // halftone a 24-bit RGB bitmap to monochrome
  495. // surface.
  496. //
  497. // pPrimMonoMappingTable - Pointer to a table which contains the cached
  498. // RGB -> three dyes densities entries, this
  499. // table will be computed and cahced when first
  500. // time halftone a 24-bit RGB bitmap to color
  501. // surface.
  502. //
  503. // pHTDyeDensity - Pointer to an array of DECI4 HTDensity values,
  504. // size of the array are MaximumHTDensityIndex.
  505. //
  506. // Prim3SolidInfo - Device solid dyes concentration information,
  507. // see RIM3SOLIDINFO data structure.
  508. //
  509. // RGBToXYZ - a 3 x 3 matrix used to transform from device
  510. // RGB color values to the C.I.E color X, Y, Z
  511. // values.
  512. //
  513. // DeviceResXDPI - Specified the device horizontal (x direction)
  514. // resolution in 'dots per inch' measurement.
  515. //
  516. // DeviceResYDPI - Specified the device vertical (y direction)
  517. // resolution in 'dots per inch' measurement.
  518. //
  519. // DevicePelsDPI - Specified the device pel/dot/nozzle diameter
  520. // (if rounded) or width/height (if squared) in
  521. // 'dots per inch' measurement.
  522. //
  523. // This value is measure as if each pel only
  524. // touch each at edge of the pel.
  525. //
  526. // HTPatGamma - Gamma for the input RGB value * halftone
  527. // pattern gamma correction.
  528. //
  529. // DensityBWRef - The reference black/white point for the
  530. // device.
  531. //
  532. // IlluminantIndex - Specified the default illuminant of the light
  533. // source which the object will be view under.
  534. // The predefined value has ILLUMINANT_xxxx
  535. // form.
  536. //
  537. // RGAdj - Current Red/Green Tint adjustment.
  538. //
  539. // BYAdj - Current Blue/Yellow Tint adjustment.
  540. //
  541. // HalftonePattern - the HALFTONEPATTERN data structure.
  542. //
  543. //
  544. #define DCIF_HAS_BLACK_DYE 0x00000001
  545. #define DCIF_ADDITIVE_PRIMS 0x00000002
  546. #define DCIF_NEED_DYES_CORRECTION 0x00000004
  547. #define DCIF_SQUARE_DEVICE_PEL 0x00000008
  548. #define DCIF_CLUSTER_HTCELL 0x00000010
  549. #define DCIF_SUPERCELL_M 0x00000020
  550. #define DCIF_SUPERCELL 0x00000040
  551. #define DCIF_FORCE_ICM 0x00000080
  552. #define DCIF_USE_8BPP_BITMASK 0x00000100
  553. #define DCIF_MONO_8BPP_BITMASK 0x00000200
  554. #define DCIF_DO_DEVCLR_XFORM 0x00000400
  555. #define DCIF_CMY8BPPMASK_SAME_LEVEL 0x00000800
  556. #define DCIF_PRINT_DRAFT_MODE 0x00001000
  557. #define DCIF_INVERT_8BPP_BITMASK_IDX 0x00002000
  558. #define DCIF_HAS_DENSITY 0x00004000
  559. typedef struct _CMY8BPPMASK {
  560. BYTE cC;
  561. BYTE cM;
  562. BYTE cY;
  563. BYTE Max;
  564. BYTE Mask;
  565. BYTE SameLevel;
  566. WORD PatSubC;
  567. WORD PatSubM;
  568. WORD PatSubY;
  569. FD6 MaxMulC;
  570. FD6 MaxMulM;
  571. FD6 MaxMulY;
  572. FD6 KCheck;
  573. FD6 DenC[6];
  574. FD6 DenM[6];
  575. FD6 DenY[6];
  576. BYTE bXlate[256];
  577. BYTE GenerateXlate;
  578. BYTE bReserved[3];
  579. } CMY8BPPMASK, *PCMY8BPPMASK;
  580. #define AB_BGR_SIZE (sizeof(BYTE) * 256 * 3)
  581. #define AB_BGR_CA_SIZE (sizeof(WORD) * 256 * 3)
  582. #define AB_CONST_SIZE (sizeof(WORD) * 256)
  583. #define AB_CONST_OFFSET ((AB_BGR_SIZE + AA_BGR_CA_SIZE) / sizeof(WORD))
  584. #define AB_CONST_MAX 0xFF
  585. #define AB_DCI_SIZE (AB_BGR_SIZE + AB_BGR_CA_SIZE + AB_CONST_SIZE)
  586. #define BYTE2CONSTALPHA(b) (((LONG)(b) << 8) | 0xFF)
  587. typedef struct _DEVICECOLORINFO {
  588. DWORD HalftoneDLLID;
  589. HTMUTEX HTMutex;
  590. _HTCALLBACKFUNC HTCallBackFunction;
  591. DWORD HTInitInfoChecksum;
  592. DWORD HTSMPChecksum;
  593. CLRXFORMBLOCK ClrXFormBlock;
  594. HTCELL HTCell;
  595. DWORD Flags;
  596. WORD DeviceResXDPI;
  597. WORD DeviceResYDPI;
  598. FD6 DevPelRatio;
  599. HTCOLORADJUSTMENT ca;
  600. PRIMADJ PrimAdj;
  601. CMY8BPPMASK CMY8BPPMask;
  602. CACHERGBTOXYZ CRTX[CRTX_TOTAL_COUNT];
  603. RGBLUTAA rgbLUT;
  604. RGBLUTAA rgbLUTPat;
  605. WORD PrevConstAlpha;
  606. WORD CurConstAlpha;
  607. LPBYTE pAlphaBlendBGR;
  608. #if DBG
  609. LPVOID pMemLink;
  610. LONG cbMemTot;
  611. LONG cbMemMax;
  612. #endif
  613. } DEVICECOLORINFO, FAR *PDEVICECOLORINFO;
  614. typedef struct _CDCIDATA {
  615. DWORD Checksum;
  616. struct _CDCIDATA FAR *pNextCDCIData;
  617. CLRXFORMBLOCK ClrXFormBlock;
  618. DWORD DCIFlags;
  619. WORD DevResXDPI;
  620. WORD DevResYDPI;
  621. FD6 DevPelRatio;
  622. HTCELL HTCell;
  623. } CDCIDATA, FAR *PCDCIDATA;
  624. typedef struct _CSMPBMP {
  625. struct _CSMPBMP FAR *pNextCSMPBmp;
  626. WORD PatternIndex;
  627. WORD cxPels;
  628. WORD cyPels;
  629. WORD cxBytes;
  630. } CSMPBMP, FAR *PCSMPBMP;
  631. typedef struct _CSMPDATA {
  632. DWORD Checksum;
  633. struct _CSMPDATA FAR *pNextCSMPData;
  634. PCSMPBMP pCSMPBmpHead;
  635. } CSMPDATA, FAR *PCSMPDATA;
  636. typedef struct _BGRMAPCACHE {
  637. PBGR8 pMap;
  638. LONG cRef;
  639. DWORD Checksum;
  640. } BGRMAPCACHE, *PBGRMAPCACHE;
  641. #define BGRMC_MAX_COUNT 5
  642. #define BGRMC_SIZE_INC (BGRMC_MAX_COUNT * 2)
  643. typedef struct _HTGLOBAL {
  644. HMODULE hModule;
  645. HTMUTEX HTMutexCDCI;
  646. HTMUTEX HTMutexCSMP;
  647. HTMUTEX HTMutexBGRMC;
  648. PCDCIDATA pCDCIDataHead;
  649. PCSMPDATA pCSMPDataHead;
  650. PBGRMAPCACHE pBGRMC;
  651. LONG cBGRMC;
  652. LONG cAllocBGRMC;
  653. LONG cIdleBGRMC;
  654. WORD CDCICount;
  655. WORD CSMPCount;
  656. } HTGLOBAL;
  657. #define R_INDEX 0
  658. #define G_INDEX 1
  659. #define B_INDEX 2
  660. #define X_INDEX 0
  661. #define Y_INDEX 1
  662. #define Z_INDEX 2
  663. //
  664. // For easy coding/reading purpose we will defined following to be used when
  665. // reference to the CIEMATRIX data structure.
  666. //
  667. #define CIE_Xr(Matrix3x3) Matrix3x3.m[X_INDEX][R_INDEX]
  668. #define CIE_Xg(Matrix3x3) Matrix3x3.m[X_INDEX][G_INDEX]
  669. #define CIE_Xb(Matrix3x3) Matrix3x3.m[X_INDEX][B_INDEX]
  670. #define CIE_Yr(Matrix3x3) Matrix3x3.m[Y_INDEX][R_INDEX]
  671. #define CIE_Yg(Matrix3x3) Matrix3x3.m[Y_INDEX][G_INDEX]
  672. #define CIE_Yb(Matrix3x3) Matrix3x3.m[Y_INDEX][B_INDEX]
  673. #define CIE_Zr(Matrix3x3) Matrix3x3.m[Z_INDEX][R_INDEX]
  674. #define CIE_Zg(Matrix3x3) Matrix3x3.m[Z_INDEX][G_INDEX]
  675. #define CIE_Zb(Matrix3x3) Matrix3x3.m[Z_INDEX][B_INDEX]
  676. //
  677. // HALFTONERENDER
  678. //
  679. // pDeviceColorInfo - Pointer to the DECICECOLORINFO data structure
  680. //
  681. // pDevClrAdj - Pointer to the DEVCLRADJ data structure.
  682. //
  683. // pBitbltParams - Pointer to the BITBLTPARAMS data structure
  684. //
  685. // pSrcSurfaceInfo - Pointer to the source HTSURFACEINFO data
  686. // structure.
  687. //
  688. // pDestSurfaceInfo - Pointer to the destination HTSURFACEINFO data
  689. // structure.
  690. //
  691. // pDeviceColorInfo - Pointer to the DECICECOLORINFO data structure
  692. //
  693. //
  694. typedef struct _HALFTONERENDER {
  695. PDEVICECOLORINFO pDeviceColorInfo;
  696. PDEVCLRADJ pDevClrAdj;
  697. PBITBLTPARAMS pBitbltParams;
  698. PHTSURFACEINFO pSrcSI;
  699. PHTSURFACEINFO pSrcMaskSI;
  700. PHTSURFACEINFO pDestSI;
  701. LPVOID pAAHdr;
  702. LPBYTE pXlate8BPP;
  703. BFINFO BFInfo;
  704. } HALFTONERENDER, FAR *PHALFTONERENDER;
  705. typedef struct _HT_DHI {
  706. DEVICEHALFTONEINFO DHI;
  707. DEVICECOLORINFO DCI;
  708. } HT_DHI, FAR *PHT_DHI;
  709. #define PHT_DHI_DCI_OF(x) (((PHT_DHI)pDeviceHalftoneInfo)->DCI.x)
  710. #define PDHI_TO_PDCI(x) (PDEVICECOLORINFO)&(((PHT_DHI)(x))->DCI)
  711. #define PDCI_TO_PDHI(x) (PDEVICEHALFTONEINFO)((DWORD)(x) - \
  712. FIELD_OFFSET(HT_DHI, DCI))
  713. //
  714. // Functions prototype
  715. //
  716. PDEVICECOLORINFO
  717. HTENTRY
  718. pDCIAdjClr(
  719. PDEVICEHALFTONEINFO pDeviceHalftoneInfo,
  720. PHTCOLORADJUSTMENT pHTColorAdjustment,
  721. PDEVCLRADJ *ppDevClrAdj,
  722. DWORD cbAlooc,
  723. WORD ForceFlags,
  724. CTSTDINFO CTSTDInfo,
  725. PLONG pError
  726. );
  727. VOID
  728. HTENTRY
  729. ComputeColorSpaceXForm(
  730. PDEVICECOLORINFO pDCI,
  731. PCIEPRIMS pCIEPrims,
  732. PCOLORSPACEXFORM pCSXForm,
  733. INT StdIlluminant
  734. );
  735. LONG
  736. HTENTRY
  737. ComputeBGRMappingTable(
  738. PDEVICECOLORINFO pDCI,
  739. PDEVCLRADJ pDevClrAdj,
  740. PCOLORTRIAD pSrcClrTriad,
  741. PBGR8 pbgr
  742. );
  743. LONG
  744. HTENTRY
  745. CreateDyesColorMappingTable(
  746. PHALFTONERENDER pHalftoneRender
  747. );
  748. VOID
  749. HTENTRY
  750. ComputeRGBLUTAA(
  751. PDEVICECOLORINFO pDCI,
  752. PDEVCLRADJ pDevClrAdj,
  753. PRGBLUTAA prgbLUT
  754. );
  755. LONG
  756. TrimBGRMapCache(
  757. VOID
  758. );
  759. PBGR8
  760. FindBGRMapCache(
  761. PBGR8 pDeRefMap,
  762. DWORD Checksum
  763. );
  764. #define FIND_BGRMAPCACHE(Checksum) FindBGRMapCache(NULL, Checksum)
  765. #define DEREF_BGRMAPCACHE(pMap) FindBGRMapCache(pMap, 0)
  766. BOOL
  767. AddBGRMapCache(
  768. PBGR8 pMap,
  769. DWORD Checksum
  770. );
  771. #endif // _HTMAPCLR_