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.

1437 lines
48 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: xlateobj.hxx
  3. *
  4. * This file contains the class prototypes for palettes and xlates
  5. *
  6. * Created: 08-Nov-1990 19:30:06
  7. * Author: Patrick Haluptzok patrickh
  8. *
  9. * Copyright (c) 1990-1999 Microsoft Corporation
  10. *
  11. * TERMINOLOGY:
  12. *
  13. * Logical hpal: Something an application creates. These exist in the
  14. * hdc.
  15. *
  16. * Physical hpal: An hpal that describes a surface. These are unique per
  17. * hsurf. They can only be changed by GDI, not directly
  18. * by an application.
  19. *
  20. * Every hdc has 3 fields for compatibiliy with Win3.0 Animate
  21. * palette functionality.
  22. *
  23. * The first one is in the DCLEVEL:
  24. *
  25. * HPALETTE hpal; // Indicates the current hpal for the DC.
  26. *
  27. * These fields are not in the DCLEVEL:
  28. *
  29. * HDC hdcHpalPrev; // These two hdc fields enable tracking where
  30. * HDC hdcHpalNext; // a hpal has been selected in.
  31. *
  32. * Every hpal has 2 fields for compatibility with Win3.0 Animate.
  33. *
  34. * HDC hdcHead; // The head of the list for the dc's that
  35. * // this hpal is selected into
  36. * ULONG cRef; // count of dc's and levels this baby is
  37. * // selected into
  38. *
  39. * When a hpal is selected into a hdc, the hdc is added into a
  40. * linked list of hdc associated with the hpal. The reference
  41. * count for the hpal is incremented. The previous hpal has
  42. * it's reference count decremented, and the hdc is taken out
  43. * of it's linked list. This is so we can run down the list
  44. * of DC the palette is selected into to do the AnimatePalette.
  45. *
  46. * The hpal is saved with SaveDC. SaveDC increments the reference count
  47. * of the corresponding hpal and copies it to the new level.
  48. *
  49. * On RestoreDC decrement the old hpal's reference count. If the hpal's
  50. * on the levels are different, the new hpal must be added back in the
  51. * linked list, ***NOTE: it doesn't need to increment the reference count
  52. * for the new level's hpal, the reference count already has
  53. * this level added in it.
  54. *
  55. * A RealizePalette creates a xlateobj for mapping entries from the hdc's
  56. * hpal to the hsurf's hpal if the surface is managed by the window manager.
  57. * If the surface is not window managed the mapping is so trivial that a
  58. * xlateobj is not created.
  59. *
  60. * GLOBAL Notions:
  61. *
  62. * STOCKOBJ_PAL
  63. * PPALETTE ppalDefault;
  64. * PPALETTE ppalDefaultSurface8bpp;
  65. *
  66. * STOCKOBJ_PAL is what every DC has when it is called by GetDC. It is
  67. * the special case palette that is always locked, non-modifiable and
  68. * contains the 20 default colors. The constructors and destructors and
  69. * methods all should do the right thing for the default palette, i.e.
  70. * never really lock it or modify it, but allow everyone to look at it
  71. * and copy it.
  72. *
  73. * Tue 04-Dec-1990 -by- Patrick Haluptzok [patrickh]
  74. * update
  75. \**************************************************************************/
  76. #ifndef _XLATEOBJ_
  77. #define _XLATEOBJ_
  78. #ifndef GDIFLAGS_ONLY // used for gdikdx
  79. typedef struct _PIXEL32
  80. {
  81. BYTE b;
  82. BYTE g;
  83. BYTE r;
  84. BYTE a;
  85. }PIXEL32,*PPIXEL32;
  86. typedef union _ALPHAPIX
  87. {
  88. PIXEL32 pix;
  89. RGBQUAD rgb;
  90. ULONG ul;
  91. } ALPHAPIX,*PALPHAPIX;
  92. typedef union _PAL_ULONG
  93. {
  94. PALETTEENTRY pal;
  95. ULONG ul;
  96. } PAL_ULONG;
  97. typedef union _BGR_ULONG
  98. {
  99. RGBQUAD rgb;
  100. ULONG ul;
  101. } BGR_ULONG;
  102. typedef union _HDEVPPAL
  103. {
  104. HDEV hdev;
  105. PPALETTE ppal;
  106. } HDEVPPAL;
  107. typedef struct _PAL_LOGPALETTE
  108. {
  109. SHORT palVersion;
  110. SHORT palNumEntries;
  111. PALETTEENTRY palPalEntry[20];
  112. } PAL_LOGPALETTE;
  113. // The translate structure is used on palette managed devices to convert
  114. // logical palette indices to physical palette indices.
  115. typedef struct _TRANSLATE
  116. {
  117. ULONG iUniq; // Surface time this translate was made for. 0 if rerealize necesary.
  118. BYTE ajVector[1]; // NOTE: THIS IS A VARIABLE-LENGTH FIELD AND MUST BE LAST
  119. } TRANSLATE;
  120. typedef TRANSLATE *PTRANSLATE;
  121. typedef struct _TRANSLATE20
  122. {
  123. ULONG iUniq;
  124. BYTE ajVector[20];
  125. } TRANSLATE20;
  126. extern TRANSLATE20 defaultTranslate;
  127. extern PAL_LOGPALETTE logDefaultPal;
  128. extern BYTE HalftoneColorCube[];
  129. //
  130. // forward reference
  131. //
  132. // NOTE: the cache size must be a power of 2, quicker modula calculation.
  133. #define XLATE_CACHE_SIZE ((ULONG) 8)
  134. #define XLATE_MODULA (XLATE_CACHE_SIZE - (ULONG) 1)
  135. #endif // GDIFLAGS_ONLY used for gdikdx
  136. #define DIB_PAL_NONE 3
  137. // PALOBJ flags - Fist bunch are defined in winddi.h
  138. //#define PAL_INDEXED 0x00000001
  139. //#define PAL_BITFIELDS 0x00000002
  140. //#define PAL_RGB 0x00000004
  141. //#define PAL_BGR 0x00000008
  142. //#define PAL_CMYK 0x00000010
  143. #define PAL_DC 0x00000100 // See below for comments
  144. #define PAL_FIXED 0x00000200
  145. #define PAL_FREE 0x00000400
  146. #define PAL_MANAGED 0x00000800
  147. #define PAL_NOSTATIC 0x00001000
  148. #define PAL_MONOCHROME 0x00002000
  149. #define PAL_BRUSHHACK 0x00004000
  150. #define PAL_DIBSECTION 0x00008000
  151. #define PAL_NOSTATIC256 0x00010000
  152. #define PAL_HT 0x00100000
  153. #define PAL_RGB16_555 0x00200000
  154. #define PAL_RGB16_565 0x00400000
  155. #define PAL_GAMMACORRECT 0x00800000 // This bit is only for palette on surface
  156. //
  157. // PAL_DIBSECTION is set when the palette is created for a DIBSECTION being
  158. // created with DIB_PAL_COLORS. When this happens we should attempt to map
  159. // the colors directly as identity xlate if possible, rather than doing the
  160. // first color match wins routine.
  161. //
  162. // PAL_DC specifies the palette was created by an application through
  163. // CreatePalette. These palettes only live in DC's, never in
  164. // surfaces. These may be selected into multiple DC's, with the
  165. // restriction that only one of the DC's hsurf's hpal is of type
  166. // PAL_MANAGED
  167. // Physical palettes are unique to an hsurf. No two surfaces have
  168. // the same palette, though their entries may be the same. (They can also
  169. // share color tables if it's a palette for a DirectDRaw object.) There are
  170. // 3 different PAL_SURF types.
  171. // 1. PAL_FIXED is a fixed palette. If this flag is set then
  172. // the palette for this surface cannot be changed.
  173. // 2. PAL_FREE means the palette is completely free. If it's selected into
  174. // a DC with an hpal, the DC's hpal will map right in 1-1. This is the
  175. // type of palette a Bitmap would have.
  176. // 3. PAL_MANAGED means this palette has some entries fixed and
  177. // some are settable. The fixed entries must be the first 10 and
  178. // last 10. This is what a palette managed device has.
  179. // PAL_NOSTATIC is a flag that signifies that for this PAL_MANAGED surface
  180. // only two colors black, white, (first and last) are reserved.
  181. // PAL_MONOCHROME is the flag stuck on monochrome bitmaps that should
  182. // have their 0-> mapped to the foreground color of the dest DC and
  183. // the 1-> mapped to the background color. The flag is put on palettes
  184. // of bitmaps created via the call CreateBitmap, CreateBitmapIndirect.
  185. // CreateDIBitmap treats monochromes just like 4,8 etc. it looks at
  186. // the associated color table with the bitmap and therefore doesn't
  187. // mark the palette PAL_MONOCHROME. This flag is required for
  188. // Win 3.0 compatibility.
  189. // There are 2 classes of palettes:
  190. //
  191. // A. PAL_INDEXED - the palette is described by an array of RGB's.
  192. // 1. PAL_MONOCHROME - is a subset of PAL_INDEXED
  193. //
  194. // B. Not PAL_INDEXED, cEntries == 0
  195. // the palette has no table, it describes how to convert
  196. // the bits directly into RGBs via masks.
  197. // 1. PAL_RGB - Classical RGB.
  198. // PAL_RGB specifies a palette as being true RGB. An application creates
  199. // an RGB palette by calling CreatePalette with numentries equal to 0.
  200. // The byte order from low to high is R, G, B, flag.
  201. // PAL_BGR specifies RGB expect the ordering from low to high is
  202. // B, G, R, flags
  203. // If the palette has less than 20 colors simultaneously then it must be a
  204. // fixed palette or a free palette, none of the entries may be settable
  205. // and the driver may pass back any colors it wants for it's palette.
  206. // Windows3.1 flags for palette matching
  207. #define PC_USED 0x10
  208. #define PC_FOREGROUND 0x20
  209. #ifndef GDIFLAGS_ONLY // used for gdikdx
  210. //
  211. // in some cases build an xlate table from rgb333 to palette entries
  212. //
  213. typedef PBYTE PRGB555XLATE;
  214. #endif // GDIFLAGS_ONLY used for gdikdx
  215. // Specify on calls to search for nearest COLORREFs or PALENTRYs whether
  216. // to do an exact match search before doing the nearest match, since an
  217. // exact search is so much faster.
  218. #define SE_DONT_SEARCH_EXACT_FIRST 0x00
  219. #define SE_DO_SEARCH_EXACT_FIRST 0x01
  220. //
  221. // ulXlatePalUnique maintains "time" of the last change to a palette or xlateobj.
  222. // This is needed to tell if a xlateobj or translate is valid.
  223. //
  224. #ifndef GDIFLAGS_ONLY // used for gdikdx
  225. extern ULONG ulXlatePalUnique;
  226. extern PAL_ULONG aPalHalftone[];
  227. //
  228. // Function prototype for palette-specific routines to convert a
  229. // PALETTEENTRY to the destination device's color format.
  230. //
  231. class PALETTE;
  232. typedef ULONG (FASTCALL *PFN_GetFromPalentry)(PALETTE*, ULONG);
  233. //
  234. // Function prototype for optimized routines to convert between two
  235. // bitfields (or RGB or BGR) format colors.
  236. //
  237. typedef ULONG (FASTCALL *PFN_pfnXlate)(XLATEOBJ*, ULONG);
  238. /******************************Public*Class*******************************\
  239. * class PALETTE
  240. *
  241. * Palette class
  242. *
  243. * History:
  244. * 07-Nov-1990 -by- Patrick Haluptzok patrickh
  245. * Wrote it.
  246. \**************************************************************************/
  247. class PALETTE : public OBJECT
  248. {
  249. public:
  250. FLONG flPal; // flags in palette
  251. ULONG cEntries; // count of entries currently in palette
  252. ULONG ulTime; // Time that specifies when the palette
  253. // was last modified. Use this to determine
  254. // if xlateobj are still valid.
  255. HDC hdcHead; // Head of the linked list of DC's this hpalette
  256. // is selected into so we traverse all the DC's
  257. // an hpal is selected into to do AnimatePalette
  258. // ect. correctly
  259. HDEVPPAL hSelected; // For a PAL_DC this is the hdev of the pdev
  260. // this
  261. // palette is selected into. We track this
  262. // because a palette can only be selected into
  263. // the DC's of 1 device at a
  264. // time. The DEVLOCK of the pdev serializes
  265. // access to the pxlates in the palDC.
  266. // For a PAL_MANAGED palette this is
  267. // the hpal of its default palette.
  268. ULONG cRefhpal; // For a PAL_DC this is the
  269. // count of times this hpal is selected into a DC.
  270. // For a PAL_xxx this is the
  271. // index in the cache table of where the last
  272. // hxlate used for this surf palette was stuffed.
  273. ULONG cRefRegular; // For a PAL_MANAGED this is the number of reserved
  274. // entries.
  275. // For the special case where we have created a DIB
  276. // via DIB_PAL_COLORS, we store the actual length of
  277. // the DIB's color table here so we don't have to
  278. // make as big an xlate
  279. // For a DIBSECTION bitmap this is the count of
  280. // entries that are used. This is for
  281. // Get/SetDIBColorTable to remember the ClrUsed.
  282. HDEV hdevOwner; // Pointer to PDEV who create this palette by EngCreatePalette()
  283. // this entry is used only for the palette on the surface.
  284. // [note] later to 'union' with someelse value which
  285. // is only used for logical palette.
  286. PTRANSLATE ptransFore; // Foreground mapping.
  287. PTRANSLATE ptransCurrent; // Current mapping which may == ptransFore.
  288. PTRANSLATE ptransOld; // The old translate for UpdateColors.
  289. // This needs to be kept around to support
  290. // UpdateColors.
  291. PFN_GetFromPalentry pfnGetNearestFromPalentry;
  292. PFN_GetFromPalentry pfnGetMatchFromPalentry;
  293. // Indirect functions to convert a PALETTEENTRY
  294. // to the destination device's color format
  295. ULONG ulRGBTime;
  296. PRGB555XLATE pRGBXlate; // prgbXlate is allocated for a palette when doing
  297. // translations from 16,24,32 bit per pixel formats
  298. // to the palette format. ulRGBTime is used to determine
  299. // if the xlate is valid.
  300. PAL_ULONG *apalColor; // Pointer to color table. Usually points to
  301. // &apalColorTabe[0], except for a DirectDraw
  302. // GetDC surface, for which it points directly to
  303. // the screen surface's color table
  304. PALETTE *ppalColor; // Palette that owns the color table
  305. // NOTE: THIS IS A VARIABLE-LENGTH FIELD AND MUST BE LAST
  306. PAL_ULONG apalColorTable[1]; // array of rgb values that each index corresponds
  307. // plus array of intensities from least intense to most
  308. // intense (plus index to corresponding rgb value)
  309. };
  310. typedef PALETTE *PPALETTE;
  311. /******************************Public*Class********************************\
  312. * XLATE
  313. *
  314. * This is the data structure for an xlate object. An xlate tranlates
  315. * indices from being relative one palette to being relative to another.
  316. *
  317. * History:
  318. * Mon 07-Mar-1994 -by- Patrick Haluptzok [patrickh]
  319. * Derive off of XLATEOBJ.
  320. *
  321. * 18-Nov-1990 -by- Patrick Haluptzok patrickh
  322. * Wrote it.
  323. \**************************************************************************/
  324. class XLATE : public _XLATEOBJ
  325. {
  326. public:
  327. // ULONG iUniq; // Uniqueness
  328. // FLONG flXlate; // Accelerator flags
  329. // USHORT iSrcType; // Src palette type
  330. // USHORT iDstType; // Dst palette type
  331. // ULONG cEntries; // Count of entries in table
  332. // ULONG *pulXlate; // Pointer to translation vector.
  333. ULONG iBackSrc; // tracked for blting to monochrome
  334. ULONG iForeDst; // tracked for blting from monochrome
  335. ULONG iBackDst; // tracked for blting from monochrome
  336. LONG lCacheIndex; // Is XLATE_CACHE_JOURNAL if for journal play back
  337. // Is XLATE_CACHE_INVALID if it's not in cache
  338. // Otherwise it's the cache index.
  339. PPALETTE ppalSrc; // Points to Src palette.
  340. PPALETTE ppalDst; // Points to Dst palette.
  341. PPALETTE ppalDstDC; // Points to Dst DC palette.
  342. HANDLE hcmXform; // ICM Color Transform for operation
  343. LONG lIcmMode; // ICM mode for operation
  344. FLONG flPrivate; // Private accelerator flags
  345. // NOTE: THIS IS A VARIABLE-LENGTH FIELD AND MUST BE LAST
  346. ULONG ai[1]; // The translation vector.
  347. public:
  348. BOOL bIsIdentity() { return(flXlate & XO_TRIVIAL); }
  349. ULONG ulTranslate(ULONG cIndex) { return(XLATEOBJ_iXlate(this, cIndex)); }
  350. VOID vSetIndex(ULONG ulIndex, ULONG ulValue)
  351. {
  352. ASSERTGDI(ulIndex < cEntries, "ERROR XLATE vSetIndex");
  353. ai[ulIndex] = ulValue;
  354. }
  355. VOID FASTCALL vMapNewXlate(PTRANSLATE ptrans);
  356. VOID vCheckForTrivial();
  357. VOID vCheckForICM(HANDLE hcmXform,ULONG lIcmMode);
  358. PFN_pfnXlate pfnXlateBetweenBitfields();
  359. };
  360. typedef XLATE *PXLATE;
  361. //
  362. // This class is for the global identity xlate we have sitting around.
  363. //
  364. class XLATE256 : public XLATE
  365. {
  366. public:
  367. ULONG aiExtra[255]; // We have a 256 array of ident xlate.
  368. };
  369. class XLATE2 : public XLATE
  370. {
  371. public:
  372. ULONG aiExtra[1]; // We have a 2 entry array.
  373. };
  374. extern XLATE256 xloIdent;
  375. // The following constants are for reserved uniqueness values.
  376. // 1 is reserved for the identity xlate.
  377. // 2 is reserved for the palette time for a palette managed bitmap palette.
  378. // If ever wrapping is an issue I would increment by 2, start at an even #
  379. // and put the reserved times at odd offsets.
  380. #define XLATE_IDENTITY_UNIQ 1
  381. #define COMPAT_PAL_MAN_BM_UNIQ 2
  382. #define XLATE_START_UNIQ 3
  383. //
  384. // The 2 common palettes used in Windows are:
  385. // The palette for mononchrome bitmaps
  386. // The default logical palette for DC's
  387. //
  388. extern PPALETTE ppalDefault;
  389. extern PPALETTE gppalRGB;
  390. extern PPALETTE ppalDefaultSurface8bpp;
  391. extern PPALETTE ppalMono;
  392. extern HPALETTE hpalMono;
  393. /******************************Public*Structure****************************\
  394. * P_BITFIELDS
  395. *
  396. * This supports the 16 and 32 bit-bitfield palette types. The bitfields
  397. * for each color are assumed to be contiguous and don't overlap.
  398. *
  399. * Let a 16 or 32 bit index be represented by:
  400. *
  401. * { X | Y | Z } where X is the high ignored bits, Y is the color bits
  402. * for a particular Color and Z is the ignored low bits.
  403. *
  404. * cColorRight = (Y > 8) ? (Z + Y - 8) : (Z);
  405. *
  406. * Let w=0 for red, w=8 for green, w=16 for blue
  407. *
  408. * cColorLeft = (Y > 8) ? (w) : (w + 8 - Y)
  409. *
  410. * We compute this for R,G,B and from these we can transform the colors
  411. * from RGB to indexes and back again no matter how wide or what order
  412. * the bitfields for each of the colors is.
  413. *
  414. * History:
  415. * 08-Nov-1991 -by- Patrick Haluptzok patrickh
  416. * Wrote it.
  417. \**************************************************************************/
  418. typedef struct _P_BITFIELDS
  419. {
  420. FLONG flRed; // Masks for the corresponding bits
  421. FLONG flGre;
  422. FLONG flBlu;
  423. ULONG cRedLeft;
  424. ULONG cGreLeft;
  425. ULONG cBluLeft;
  426. ULONG cRedRight;
  427. ULONG cGreRight;
  428. ULONG cBluRight;
  429. ULONG cRedMiddle;
  430. ULONG cGreMiddle;
  431. ULONG cBluMiddle;
  432. } P_BITFIELDS;
  433. /******************************Public*Class*******************************\
  434. * class XEPALOBJ
  435. *
  436. * Palette User Object
  437. *
  438. * History:
  439. * Thu 29-Aug-1991 -by- Patrick Haluptzok [patrickh]
  440. * changed it to be XEPALOBJ
  441. *
  442. * 07-Nov-1990 -by- Patrick Haluptzok patrickh
  443. * Wrote it.
  444. \**************************************************************************/
  445. class XEPALOBJ /* xepal */
  446. {
  447. protected:
  448. PPALETTE ppal;
  449. public:
  450. XEPALOBJ() { ppal = (PPALETTE) NULL; }
  451. XEPALOBJ(PPALETTE ppalNew) { ppal = ppalNew; }
  452. VOID vAltCheckLock(HPALETTE hpal)
  453. {
  454. ppal = (PPALETTE) HmgShareCheckLock((HOBJ)hpal, PAL_TYPE);
  455. }
  456. VOID vAltLock(HPALETTE hpal)
  457. {
  458. ppal = (PPALETTE) HmgShareLock((HOBJ)hpal, PAL_TYPE);
  459. }
  460. VOID vAltUnlock()
  461. {
  462. if (ppal != (PPALETTE) NULL)
  463. {
  464. DEC_SHARE_REF_CNT(ppal);
  465. ppal = (PPALETTE) NULL;
  466. }
  467. }
  468. // These are the common functions
  469. HPALETTE hpal() { return((HPALETTE) ppal->hGet()); }
  470. BOOL bValid() { return(ppal != (PPALETTE) NULL); }
  471. BOOL bIsPalDefault() { return(ppal == ppalDefault); }
  472. VOID vSetPID(W32PID pid) { HmgSetOwner((HOBJ)hpal(), pid, PAL_TYPE); }
  473. VOID vRefPalette() { if (ppal != NULL) INC_SHARE_REF_CNT(ppal); }
  474. VOID vUnrefPalette();
  475. BOOL bDeletePalette(BOOL bCleanup = FALSE, CLEANUPTYPE cutype = CLEANUP_NONE); // release associated memory
  476. // Bitfield functions
  477. FLONG flRed() { return(((P_BITFIELDS *) ppal->apalColor)->flRed); }
  478. VOID flRed(FLONG flNew) { ((P_BITFIELDS *) ppal->apalColor)->flRed = flNew; }
  479. FLONG flGre() { return(((P_BITFIELDS *) ppal->apalColor)->flGre); }
  480. VOID flGre(FLONG flNew) { ((P_BITFIELDS *) ppal->apalColor)->flGre = flNew; }
  481. FLONG flBlu() { return(((P_BITFIELDS *) ppal->apalColor)->flBlu); }
  482. VOID flBlu(FLONG flNew) { ((P_BITFIELDS *) ppal->apalColor)->flBlu = flNew; }
  483. ULONG& cRedLeft() { return(((P_BITFIELDS *) ppal->apalColor)->cRedLeft); }
  484. VOID cRedLeft(ULONG ul) { ((P_BITFIELDS *) ppal->apalColor)->cRedLeft = ul; }
  485. ULONG& cGreLeft() { return(((P_BITFIELDS *) ppal->apalColor)->cGreLeft); }
  486. VOID cGreLeft(ULONG ul) { ((P_BITFIELDS *) ppal->apalColor)->cGreLeft = ul; }
  487. ULONG& cBluLeft() { return(((P_BITFIELDS *) ppal->apalColor)->cBluLeft); }
  488. VOID cBluLeft(ULONG ul) { ((P_BITFIELDS *) ppal->apalColor)->cBluLeft = ul; }
  489. ULONG& cRedRight() { return(((P_BITFIELDS *) ppal->apalColor)->cRedRight); }
  490. VOID cRedRight(ULONG ul) { ((P_BITFIELDS *) ppal->apalColor)->cRedRight = ul; }
  491. ULONG& cGreRight() { return(((P_BITFIELDS *) ppal->apalColor)->cGreRight); }
  492. VOID cGreRight(ULONG ul) { ((P_BITFIELDS *) ppal->apalColor)->cGreRight = ul; }
  493. ULONG& cBluRight() { return(((P_BITFIELDS *) ppal->apalColor)->cBluRight); }
  494. VOID cBluRight(ULONG ul) { ((P_BITFIELDS *) ppal->apalColor)->cBluRight = ul; }
  495. ULONG& cRedMiddle() { return(((P_BITFIELDS *) ppal->apalColor)->cRedMiddle); }
  496. VOID cRedMiddle(ULONG ul) { ((P_BITFIELDS *) ppal->apalColor)->cRedMiddle = ul; }
  497. ULONG& cGreMiddle() { return(((P_BITFIELDS *) ppal->apalColor)->cGreMiddle); }
  498. VOID cGreMiddle(ULONG ul) { ((P_BITFIELDS *) ppal->apalColor)->cGreMiddle = ul; }
  499. ULONG& cBluMiddle() { return(((P_BITFIELDS *) ppal->apalColor)->cBluMiddle); }
  500. VOID cBluMiddle(ULONG ul) { ((P_BITFIELDS *) ppal->apalColor)->cBluMiddle = ul; }
  501. ULONG ulBitfieldToRGB(ULONG ulIndex);
  502. ULONG ulIndexToRGB(ULONG ulIndex);
  503. // General functions
  504. PPALETTE ppalGet() { return(ppal); }
  505. PVOID pvPalette() { return((PVOID) ppal); }
  506. VOID ppalSet(PPALETTE ppalNew) { ppal = ppalNew; }
  507. FLONG flPal() { return(ppal->flPal); }
  508. VOID flPalSet(FLONG flag) { ppal->flPal = flag; }
  509. VOID flPal(FLONG flag) { ppal->flPal |= flag; }
  510. ULONG iPalMode() { return(ppal->flPal & (PAL_RGB | PAL_BGR | PAL_CMYK | PAL_INDEXED | PAL_BITFIELDS)); }
  511. BOOL bIsRGB() { return(ppal->flPal & PAL_RGB); }
  512. BOOL bIsBGR() { return(ppal->flPal & PAL_BGR); }
  513. BOOL bIs565() { return(ppal->flPal & PAL_RGB16_565); }
  514. BOOL bIs555() { return(ppal->flPal & PAL_RGB16_555); }
  515. BOOL bIsCMYK() { return(ppal->flPal & PAL_CMYK); }
  516. BOOL bIsIndexed() { return(ppal->cEntries); }
  517. BOOL bIsPalDC() { return(ppal->flPal & PAL_DC); }
  518. BOOL bIsBitfields() { return(ppal->flPal & PAL_BITFIELDS); }
  519. BOOL bIsPalDibsection() { return(ppal->flPal & PAL_DIBSECTION); }
  520. BOOL bIsHalftone() { return(ppal->flPal & PAL_HT);}
  521. ULONG cEntries() { return(ppal->cEntries); }
  522. VOID cEntries(ULONG ulTemp) { ppal->cEntries = ulTemp; }
  523. PPALETTE ppalColor() { return(ppal->ppalColor); }
  524. PAL_ULONG *apalColorGet() { return(ppal->apalColor); }
  525. VOID vComputeCallTables();
  526. VOID apalColorSet(PPALETTE ppalGlobal)
  527. {
  528. if (ppal->ppalColor != ppal)
  529. {
  530. // Handle re-assignment case
  531. DEC_SHARE_REF_CNT(ppal->ppalColor);
  532. }
  533. INC_SHARE_REF_CNT(ppalGlobal);
  534. ppal->apalColor = ppalGlobal->apalColor;
  535. ppal->ppalColor = ppalGlobal;
  536. }
  537. VOID apalResetColorTable()
  538. {
  539. if (ppal->ppalColor != ppal)
  540. {
  541. // Handle re-assignment case
  542. DEC_SHARE_REF_CNT(ppal->ppalColor);
  543. }
  544. // Note that this does not transfer ownership of the color table
  545. ppal->apalColor = &ppal->apalColorTable[0];
  546. ppal->ppalColor = ppal;
  547. }
  548. ULONG ulTime()
  549. {
  550. if (ppal->ppalColor != ppal)
  551. {
  552. // Note if color table lives in different PALETTE, get time from there.
  553. return(ppal->ppalColor->ulTime);
  554. }
  555. else
  556. {
  557. return(ppal->ulTime);
  558. }
  559. }
  560. VOID ulTime(ULONG ulNewTime)
  561. {
  562. ppal->ulTime = ulNewTime;
  563. if (ppal->ppalColor != ppal)
  564. {
  565. // Note if color table lives in different PALETTE, update that's ulTime, too.
  566. ppal->ppalColor->ulTime = ulNewTime;
  567. }
  568. }
  569. VOID vUpdateTime() { ulTime(ulGetNewUniqueness(ulXlatePalUnique)); }
  570. VOID vSetHTPal() { ppal->flPal |= PAL_HT; }
  571. VOID vClearHTPal() { ppal->flPal &= ~PAL_HT; }
  572. BOOL bIsHTPal() { return(ppal->flPal & PAL_HT); }
  573. PALETTEENTRY palentryGet(ULONG ulIndex)
  574. {
  575. ASSERTGDI(ulIndex < ppal->cEntries, "ERROR palentryGet: ulIndex > cEntries");
  576. return(ppal->apalColor[ulIndex].pal);
  577. }
  578. ULONG ulEntryGet(ULONG ulIndex)
  579. {
  580. ASSERTGDI(ulIndex < ppal->cEntries, "ERROR ulentryGet: ulIndex > cEntries");
  581. return(ppal->apalColor[ulIndex].ul);
  582. }
  583. VOID palentrySet(ULONG ulIndex, PALETTEENTRY palentry)
  584. {
  585. ASSERTGDI(ulIndex < ppal->cEntries, "ERROR palentrySet: ulIndex > cEntries");
  586. ppal->apalColor[ulIndex].pal = palentry;
  587. }
  588. VOID ulEntrySet(ULONG ulIndex, ULONG ulRGB)
  589. {
  590. ASSERTGDI(ulIndex < ppal->cEntries, "ERROR palentrySet: ulIndex > cEntries");
  591. ppal->apalColor[ulIndex].ul = ulRGB;
  592. }
  593. ULONG ulSetEntries(ULONG iStart, ULONG cEntry, CONST PALETTEENTRY *ppalentry);
  594. ULONG ulAnimatePalette(ULONG iStart, ULONG cEntry, CONST PALETTEENTRY *ppalentry);
  595. ULONG ulGetEntries(ULONG iStart, ULONG cEntry, PPALETTEENTRY ppalentry, BOOL bZeroFlags);
  596. ULONG ulGetNearestFromPalentryNoExactMatchFirst(CONST PALETTEENTRY palentry);
  597. ULONG ulGetMatchFromPalentry(CONST PALETTEENTRY palentry)
  598. {
  599. return(ppal->pfnGetMatchFromPalentry(ppal, *((ULONG*) &palentry)));
  600. }
  601. ULONG ulGetMatchFromPalentry(CONST ULONG palentry)
  602. {
  603. return(ppal->pfnGetMatchFromPalentry(ppal, palentry));
  604. }
  605. ULONG ulGetNearestFromPalentry(CONST PALETTEENTRY palentry)
  606. {
  607. return(ppal->pfnGetNearestFromPalentry(ppal, *((ULONG*) &palentry)));
  608. }
  609. ULONG ulGetNearestFromPalentry(CONST ULONG palentry)
  610. {
  611. return(ppal->pfnGetNearestFromPalentry(ppal, palentry));
  612. }
  613. ULONG ulGetNearestFromPalentry(
  614. CONST PALETTEENTRY palentry,
  615. ULONG seSearchExactFirst
  616. )
  617. {
  618. ULONG ul;
  619. if (seSearchExactFirst == SE_DONT_SEARCH_EXACT_FIRST)
  620. {
  621. ul = ulGetNearestFromPalentryNoExactMatchFirst(palentry);
  622. }
  623. else
  624. {
  625. ul = ulGetNearestFromPalentry(palentry);
  626. }
  627. return(ul);
  628. }
  629. VOID vInitMono();
  630. VOID vInitVGA();
  631. VOID vInit256Rainbow();
  632. VOID vInit256Default();
  633. // These are the DC palette functions - PALOBJDC
  634. VOID hdcHead(HDC hdcHead)
  635. {
  636. ASSERTGDI(ppal->flPal & PAL_DC, "ERROR hdcHead() passed invalid palette type\n");
  637. ppal->hdcHead = hdcHead;
  638. }
  639. HDC hdcHead()
  640. {
  641. ASSERTGDI(ppal->flPal & PAL_DC, "ERROR hdcHead() 1passed invalid palette type\n");
  642. return(ppal->hdcHead);
  643. }
  644. VOID cRefhpal(ULONG ulTemp)
  645. {
  646. ASSERTGDI(ppal->flPal & PAL_DC, "ERROR cRefhpal not called on PAL_DC1\n");
  647. ppal->cRefhpal = ulTemp;
  648. }
  649. ULONG cRefhpal()
  650. {
  651. ASSERTGDI(ppal->flPal & PAL_DC, "ERROR cRefhpal not called on PAL_DC\n");
  652. return(ppal->cRefhpal);
  653. }
  654. VOID iXlateIndex(ULONG ulTemp)
  655. {
  656. ASSERTGDI(!(ppal->flPal & PAL_DC), "ERROR iXlateIndex called on PAL_DC1\n");
  657. ASSERTGDI(ulTemp < XLATE_CACHE_SIZE, "ERROR saving too large cache index \n");
  658. ppal->cRefhpal = ulTemp;
  659. }
  660. ULONG iXlateIndex()
  661. {
  662. ASSERTGDI(!(ppal->flPal & PAL_DC), "ERROR iXlateIndex called on PAL_DC\n");
  663. ASSERTGDI(ppal->cRefhpal < XLATE_CACHE_SIZE, "ERROR retrieving out of bounds cache index \n");
  664. return(ppal->cRefhpal);
  665. }
  666. VOID ptransFore(PTRANSLATE ptrans)
  667. {
  668. ASSERTGDI(ppal->flPal & PAL_DC, "ERROR pxlFore() passed invalid palette type\n");
  669. ppal->ptransFore = ptrans;
  670. }
  671. PTRANSLATE ptransFore()
  672. {
  673. ASSERTGDI(ppal->flPal & PAL_DC, "ERROR pxlFore() 1passed invalid palette type\n");
  674. return(ppal->ptransFore);
  675. }
  676. VOID ptransCurrent(PTRANSLATE ptrans)
  677. {
  678. ASSERTGDI(ppal->flPal & PAL_DC, "ERROR ptransCurrent() passed invalid palette type\n");
  679. ppal->ptransCurrent = ptrans;
  680. }
  681. PTRANSLATE ptransCurrent()
  682. {
  683. ASSERTGDI(ppal->flPal & PAL_DC, "ERROR ptransCurrent() 1passed invalid palette type\n");
  684. return(ppal->ptransCurrent);
  685. }
  686. VOID ptransOld(PTRANSLATE ptrans)
  687. {
  688. ASSERTGDI(ppal->flPal & PAL_DC, "ERROR ptransOld() passed invalid palette type\n");
  689. ppal->ptransOld = ptrans;
  690. }
  691. PTRANSLATE ptransOld()
  692. {
  693. ASSERTGDI(ppal->flPal & PAL_DC, "ERROR ptransOld() 1passed invalid palette type\n");
  694. return(ppal->ptransOld);
  695. }
  696. //
  697. // For ResizePalette
  698. //
  699. BOOL bSwap(PPALETTE*,ULONG,ULONG);
  700. //
  701. // This returns the index in the surface palette an index in the dc
  702. // palette maps to. It assumes you checked for a valid ptrans and a
  703. // valid index range.
  704. //
  705. ULONG ulTranslateDCtoCurrent(ULONG ulIndex)
  706. {
  707. ASSERTGDI(ppal->flPal & PAL_DC, "ERROR GDI ulTranslateIndex");
  708. ASSERTGDI(ulIndex < ppal->cEntries, "ERROR GDI ulTranslateIndex1");
  709. ASSERTGDI(ppal->ptransCurrent != (PTRANSLATE) NULL, "ERROR GDI ulTranslateIndex2");
  710. return((ULONG) ppal->ptransCurrent->ajVector[ulIndex]);
  711. }
  712. //
  713. // This returns the index in the surface palette an index in the dc
  714. // palette maps to. It assumes you checked for a valid ptrans and a
  715. // valid index range.
  716. //
  717. ULONG ulTranslateDCtoFore(ULONG ulIndex)
  718. {
  719. ASSERTGDI(ppal->flPal & PAL_DC, "ERROR GDI ulTranslateIndex1");
  720. ASSERTGDI(ulIndex < ppal->cEntries, "ERROR GDI ulTranslateIndex11");
  721. ASSERTGDI(ppal->ptransFore != (PTRANSLATE) NULL, "ERROR GDI ulTranslateIndex21");
  722. return((ULONG) ppal->ptransFore->ajVector[ulIndex]);
  723. }
  724. //
  725. // For a palette managed DC this is the hdev the palette is selected into.
  726. //
  727. HDEV hdev()
  728. {
  729. ASSERTGDI(ppal->flPal & PAL_DC, "ERROR hdev() passed invalid palette type\n");
  730. return(ppal->hSelected.hdev);
  731. }
  732. VOID hdev(HDEV hdev)
  733. {
  734. ASSERTGDI(ppal->flPal & PAL_DC, "ERROR hdev() 1passed invalid palette type\n");
  735. ppal->hSelected.hdev = hdev;
  736. }
  737. BOOL bSet_hdev(HDEV hdev);
  738. VOID vInc_cRef()
  739. {
  740. ASSERTGDI(ppal->flPal & PAL_DC, "vInc_cRef() passed invalid palette type\n");
  741. InterlockedIncrement((PLONG) &(ppal->cRefhpal));
  742. }
  743. VOID vDec_cRef()
  744. {
  745. ASSERTGDI(ppal->flPal & PAL_DC, "vDec_cRef() passed invalid palette type\n");
  746. ASSERTGDI(ppal->cRefhpal != 0, "cRefhpal == 0 in vDec Palette");
  747. InterlockedDecrement((PLONG) &(ppal->cRefhpal));
  748. }
  749. // These are the surface palette functions - PALOBJS
  750. BOOL bIsPalFixed() { return(ppal->flPal & PAL_FIXED); }
  751. BOOL bIsPalManaged() { return(ppal->flPal & PAL_MANAGED); }
  752. BOOL bIsPalFree() { return(ppal->flPal & PAL_FREE); }
  753. BOOL bIsMonochrome() { return((ppal != NULL) && (ppal->flPal & PAL_MONOCHROME)); }
  754. VOID vCopy_rgbquad(RGBQUAD *prgbquad, ULONG iStart, ULONG cEntries);
  755. VOID vCopy_cmykquad(ULONG *pcmykquad, ULONG iStart, ULONG cEntries);
  756. ULONG ulGetExactIndexFromPalentry(PAL_ULONG Color);
  757. PTRANSLATE ptransMapIn(XEPALOBJ palDC, BOOL bForeground, ULONG *pulUsedChanged, ULONG *pulUnUsedChanged);
  758. BOOL bJamItIn(XEPALOBJ palDC, BOOL bForeground, BOOL *pulUsedChanged, BOOL *pulUnUsedEntriesChanged);
  759. ULONG ulRealizeOnFree(XEPALOBJ palDC);
  760. VOID ulNumReserved(ULONG ulTemp)
  761. {
  762. ASSERTGDI(!(ppal->flPal & PAL_DC), "ERROR ulNumReserved called on PAL_DC1\n");
  763. ASSERTGDI(ulTemp < ppal->cEntries, "ERROR saving too large free index \n");
  764. ppal->cRefRegular = ulTemp;
  765. }
  766. ULONG cColorTableLength() {
  767. ASSERTGDI(!(ppal->flPal & PAL_DC), "ERROR cColorTableLength called on PAL_DC1\n");
  768. return ppal->cRefRegular;
  769. }
  770. VOID cColorTableLength(ULONG ulLength) {
  771. ASSERTGDI(!(ppal->flPal & PAL_DC), "ERROR cColorTableLength called on PAL_DC1\n");
  772. ppal->cRefRegular = ulLength;
  773. }
  774. ULONG ulNumReserved()
  775. {
  776. ASSERTGDI(!(ppal->flPal & PAL_DC), "ERROR ulNumReserved called on PAL_DC\n");
  777. ASSERTGDI(ppal->cRefRegular <= (ppal->cEntries - 1), "ERROR retrieving out of bounds free index \n");
  778. ASSERTGDI(ppal->cRefRegular >= 1, "ERROR ulNumReserved too small\n");
  779. return(ppal->cRefRegular);
  780. }
  781. BOOL bIsNoStatic()
  782. {
  783. return(ppal->flPal & PAL_NOSTATIC);
  784. }
  785. BOOL bIsNoStatic256()
  786. {
  787. return(ppal->flPal & PAL_NOSTATIC256);
  788. }
  789. VOID vSetNoStatic()
  790. {
  791. ppal->flPal = (ppal->flPal | PAL_NOSTATIC) & ~PAL_NOSTATIC256;
  792. }
  793. VOID vSetNoStatic256()
  794. {
  795. ppal->flPal = (ppal->flPal | PAL_NOSTATIC256) & ~PAL_NOSTATIC;
  796. }
  797. VOID vMakeNoXlate();
  798. PPALETTE ppalOriginal()
  799. {
  800. ASSERTGDI(ppal->flPal & PAL_MANAGED, "ERROR hpalOriginal() passed invalid palette type\n");
  801. return(ppal->hSelected.ppal);
  802. }
  803. VOID ppalOriginal(PPALETTE ppalNew)
  804. {
  805. ASSERTGDI(ppal->flPal & PAL_MANAGED, "ERROR hpalOriginal() 1passed invalid palette type\n");
  806. ppal->hSelected.ppal = ppalNew;
  807. }
  808. VOID vCopyEntriesFrom(XEPALOBJ palSrc)
  809. {
  810. RtlCopyMemory(apalColorGet(),
  811. palSrc.apalColorGet(),
  812. (UINT) (MIN(palSrc.cEntries(), cEntries())) * sizeof(PAL_ULONG));
  813. }
  814. VOID vFill_rgbquads(RGBQUAD *prgb, ULONG iStart, ULONG cEntries);
  815. VOID vFill_triples(RGBTRIPLE *prgb, ULONG iStart, ULONG cEntries);
  816. VOID vAddToList(XDCOBJ& dco);
  817. VOID vRemoveFromList(XDCOBJ& dco);
  818. VOID vGetEntriesFrom(XEPALOBJ palDC, XEPALOBJ palSurf, PUSHORT pusIndices, ULONG cEntry);
  819. BOOL bEqualEntries(XEPALOBJ pal);
  820. BOOL bGenColorXlate555();
  821. PRGB555XLATE pGetRGBXlate();
  822. BYTE Xlate555(BYTE r,BYTE g, BYTE b)
  823. {
  824. return(ppal->pRGBXlate[
  825. ((r & 0xf8) << 7) ||
  826. ((g & 0xf8) << 2) ||
  827. ((b & 0xf8) >> 3)]);
  828. }
  829. //
  830. // ICM: GammaCorrection stuff for 8bpp surface
  831. //
  832. BOOL bNeedGammaCorrection() { return(ppal->flPal & PAL_GAMMACORRECT); }
  833. BOOL bNeedGammaCorrection(BOOL b) { SETFLAG(b,ppal->flPal,PAL_GAMMACORRECT);return (b); }
  834. VOID CorrectColors(PPALETTEENTRY ppalentry, ULONG cEntries);
  835. HDEV hdevOwner() { return(ppal->hdevOwner); }
  836. HDEV hdevOwner(HDEV hdev_) { ppal->hdevOwner = hdev_;return(hdev_); }
  837. };
  838. /*********************************Class************************************\
  839. * class EPALOBJ : public XEPALOBJ
  840. *
  841. * Used for creating a user object from a pointer to the object.
  842. *
  843. * History:
  844. * Wed 28-Aug-1991 -by- Patrick Haluptzok [patrickh]
  845. * Wrote it.
  846. \**************************************************************************/
  847. class EPALOBJ : public XEPALOBJ /* palo */
  848. {
  849. public:
  850. EPALOBJ() {ppal = (PPALETTE) NULL; }
  851. EPALOBJ(HPALETTE hpal) {ppal = (PPALETTE) HmgShareCheckLock((HOBJ)hpal, PAL_TYPE);}
  852. ~EPALOBJ()
  853. {
  854. if (ppal != (PPALETTE) NULL)
  855. {
  856. DEC_SHARE_REF_CNT(ppal);
  857. }
  858. }
  859. };
  860. /******************************Public*Class********************************\
  861. * class PALMEMOBJ
  862. *
  863. * Palette Memory Object
  864. *
  865. * History:
  866. * 07-Nov-1990 -by- Patrick Haluptzok patrickh
  867. * Wrote it.
  868. \**************************************************************************/
  869. class PALMEMOBJ : public XEPALOBJ /* epalmo */
  870. {
  871. private:
  872. BOOL bKeep;
  873. public:
  874. PALMEMOBJ() {bKeep = FALSE; ppal = (PPALETTE) NULL;}
  875. BOOL bCreatePalette(ULONG iMode, ULONG cColors, ULONG *pulColors,
  876. FLONG flRed, FLONG flGreen, FLONG flBlue,
  877. ULONG iType);
  878. BOOL bCreateHTPalette(LONG iFormatHT, GDIINFO *pGdiInfo);
  879. ~PALMEMOBJ();
  880. VOID vKeepIt() { bKeep = TRUE; }
  881. };
  882. // structure for entry in the xlate cache.
  883. typedef struct _XLATETABLE
  884. {
  885. ULONG ulReference; // How many people are currently using it.
  886. PXLATE pxlate;
  887. ULONG ulPalSrc; // palette src time when xlate created
  888. ULONG ulPalDst; // palette dst time when xlate created
  889. ULONG ulPalSrcDC; // palette src DC time when xlate created
  890. ULONG ulPalDstDC; // palette dst DC time when xlate created
  891. } XLATETABLE;
  892. extern XLATETABLE xlateTable[XLATE_CACHE_SIZE];
  893. extern ULONG ulTableIndex;
  894. #endif // GDIFLAGS_ONLY used for gdikdx
  895. // This signifies the xlate wasn't put in the cache. The destructor
  896. // checks for this and deletes it if it's not in the cache.
  897. #define XLATE_CACHE_JOURNAL -2
  898. #define XLATE_CACHE_INVALID -1
  899. // This describes the overall logic of surface to surface xlates.
  900. // There are basically n types of xlates to worry about:
  901. //
  902. // 1. XO_TRIVIAL - no translation occurs, identity.
  903. //
  904. // 2. XO_TABLE - look up in a table for the correct table translation.
  905. //
  906. // a. XO_TO_MONO - look in to table for the correct tranlation,
  907. // but when getting it out of the cache make sure iBackSrc is the
  908. // same. iBackSrc goes to 1, everything else to 0.
  909. // b. XLATE_FROM_MONO - look into table for the correct translation
  910. // but when getting it out of the cache make sure iBackDst and
  911. // iForeDst are both still valid. 1 goes to iBackDst, 0 to iForeDst.
  912. // c. just plain jane indexed to indexed or rgb translation.
  913. //
  914. // 3. XO_RGB_SRC - Have to call XLATEOBJ_iXlate to get it translated.
  915. //
  916. // a. XO_TO_MONO - we have saved the iBackColor in ai[0]
  917. // b. just plain jane RGB to indexed. Grab the RGB, find the closest
  918. // match in Dst palette. Lot's of work.
  919. //
  920. // 4. XO_RGB_BOTH - Bit mashing time. Call XLATEOBJ_iXlate
  921. //
  922. // The code is written to quickly recognize the XO_TRIVIAL case, efficiently
  923. // compute and cache the translate table for the type XO_TABLE case, and
  924. // do the correct, expensive work required for cases 3 and 4.
  925. // #define XO_TRIVIAL 0x00000001
  926. // #define XO_TABLE 0x00000002
  927. // #define XO_TO_MONO 0x00000004
  928. // #define XO_FROM_CMYK 0x00000008
  929. // #define XO_DEVICE_ICM 0x00000010
  930. // #define XO_HOST_ICM 0x00000020
  931. #define XLATE_FROM_MONO 0x00000100
  932. #define XLATE_RGB_SRC 0x00000200
  933. #define XLATE_RGB_BOTH 0x00000400
  934. #define XLATE_PAL_MANAGED 0x00000800
  935. #define XLATE_USE_CURRENT 0x00001000
  936. #define XLATE_USE_SURFACE_PAL 0x00002000 // Only used with MultiMonitor system
  937. #define XLATE_USE_FOREGROUND 0x00004000 // Only used with MultiMonitor system
  938. #ifndef GDIFLAGS_ONLY // used for gdikdx
  939. extern "C" ULONG XLATEOBJ_iXlate(XLATEOBJ *pxo, ULONG cIndex);
  940. PXLATE
  941. CreateXlateObject(
  942. HANDLE hcmXform,
  943. LONG lIcmMode,
  944. XEPALOBJ palSrc,
  945. XEPALOBJ palDst,
  946. XEPALOBJ palSrcDC,
  947. XEPALOBJ palDstDC,
  948. ULONG iForeDst,
  949. ULONG iBackDst,
  950. ULONG iBackSrc,
  951. ULONG flCreate
  952. );
  953. PXLATE
  954. pCreateXlate(
  955. ULONG ulNumEntries
  956. );
  957. /*********************************Class************************************\
  958. * EXLATEOBJ
  959. *
  960. * This is the user object for a palette translation table.
  961. *
  962. * History:
  963. * Wed 09-Mar-1994 -by- Patrick Haluptzok [patrickh]
  964. * Get rid of stack object, clean up.
  965. *
  966. * Sun 05-May-1991 -by- Patrick Haluptzok [patrickh]
  967. * add new DDI changes to code, deja vu.
  968. *
  969. * Mon 04-Feb-1991 -by- Patrick Haluptzok [patrickh]
  970. * add DDI changes to code.
  971. *
  972. * Mon 03-Dec-1990 -by- Patrick Haluptzok [patrickh]
  973. * wrote the first pass for NT.
  974. \**************************************************************************/
  975. class EXLATEOBJ
  976. {
  977. protected:
  978. XLATE *pxlate;
  979. public:
  980. EXLATEOBJ() { pxlate = (PXLATE) NULL; }
  981. EXLATEOBJ(PXLATE pxlateNew) { pxlate = pxlateNew; }
  982. ~EXLATEOBJ() { vAltUnlock(); }
  983. BOOL bValid() { return(pxlate != (PXLATE) NULL); }
  984. XLATE *pxlo() { return(pxlate); }
  985. VOID vMakeIdentity() { pxlate = &xloIdent; }
  986. PXLATE pInitXlate(PXLATE pxlateN)
  987. {
  988. return(pxlate = pxlateN);
  989. }
  990. PXLATE pCreateXlateObject(ULONG ul)
  991. {
  992. return(pxlate = pCreateXlate(ul));
  993. }
  994. PXLATE pInitXlateNoCache(
  995. HANDLE hcmXform,
  996. LONG lIcmMode,
  997. XEPALOBJ palSrc,
  998. XEPALOBJ palDst,
  999. XEPALOBJ palDstDC,
  1000. ULONG iForeDst, // For Mono->Color 0 goes to it
  1001. ULONG iBackDst, // For Mono->Color 1 goes to it
  1002. ULONG iBackSrc, // For Color->Mono index goes to 1
  1003. ULONG flCreate = 0) // Used for Multi-Monitor System
  1004. {
  1005. //
  1006. // Cache ignorant initializer for Xlates. Good for short lived palettes.
  1007. //
  1008. return(pxlate = CreateXlateObject(
  1009. hcmXform,
  1010. lIcmMode,
  1011. palSrc,
  1012. palDst,
  1013. palDstDC,
  1014. palDstDC,
  1015. iForeDst,
  1016. iBackDst,
  1017. iBackSrc,
  1018. flCreate
  1019. )
  1020. );
  1021. }
  1022. ULONG iBackSrc() { return(pxlate->iBackSrc); }
  1023. ULONG iForeDst() { return(pxlate->iForeDst); }
  1024. ULONG iBackDst() { return(pxlate->iBackDst); }
  1025. PPALETTE ppalSrc() { return(pxlate->ppalSrc); }
  1026. PPALETTE ppalDst() { return(pxlate->ppalDst); }
  1027. PPALETTE ppalDstDC() { return(pxlate->ppalDstDC);}
  1028. VOID vAltLock(PXLATE pxlateN) { pxlate = (PXLATE) pxlateN;}
  1029. VOID vAltUnlock()
  1030. {
  1031. if (pxlate != (PXLATE) NULL)
  1032. {
  1033. if (pxlate->lCacheIndex >= 0)
  1034. {
  1035. //
  1036. // It's in the cache
  1037. //
  1038. ASSERTGDI(pxlate->lCacheIndex < XLATE_CACHE_SIZE, "ERROR not a cache index");
  1039. ASSERTGDI(xlateTable[pxlate->lCacheIndex].ulReference != 0, "ERROR xlateindex too small");
  1040. InterlockedDecrement((LPLONG) &(xlateTable[pxlate->lCacheIndex].ulReference));
  1041. }
  1042. else if (pxlate->lCacheIndex == XLATE_CACHE_INVALID)
  1043. {
  1044. VFREEMEM(pxlate);
  1045. }
  1046. #if DBG
  1047. else
  1048. {
  1049. ASSERTGDI(pxlate->lCacheIndex == XLATE_CACHE_JOURNAL, "ERROR cacheIndex not valid");
  1050. }
  1051. #endif
  1052. }
  1053. }
  1054. BOOL bMakeXlate(PUSHORT,XEPALOBJ,SURFACE*,ULONG,ULONG);
  1055. BOOL bInitXlateObj(HANDLE hcmXform,
  1056. LONG lIcmMode,
  1057. XEPALOBJ palSrc,
  1058. XEPALOBJ palDst,
  1059. XEPALOBJ palSrcDC,
  1060. XEPALOBJ palDstDC,
  1061. ULONG iForeDst, // For Mono->Color 0 goes to it
  1062. ULONG iBackDst, // For Mono->Color 1 goes to it
  1063. ULONG iBackSrc, // For Color->Mono index goes to 1
  1064. ULONG flCreate = 0); // Used for Multi-Monitor System
  1065. VOID vAddToCache(XEPALOBJ palSrc,
  1066. XEPALOBJ palDest,
  1067. XEPALOBJ palSrcDC,
  1068. XEPALOBJ palDestDC);
  1069. BOOL bSearchCache(XEPALOBJ palSrc,
  1070. XEPALOBJ palDst,
  1071. XEPALOBJ palSrcDC,
  1072. XEPALOBJ palDstDC,
  1073. ULONG iForeDst,
  1074. ULONG iBackDst,
  1075. ULONG iBackSrc,
  1076. ULONG flCreate);
  1077. BOOL bCreateXlateFromTable(ULONG cEntries, PULONG pIndices, XEPALOBJ palDst);
  1078. VOID vDelete();
  1079. };
  1080. PBYTE
  1081. XLATEOBJ_pGetXlate555(
  1082. XLATEOBJ *pxlo
  1083. );
  1084. BYTE
  1085. XLATEOBJ_ulIndexToPalSurf(
  1086. XLATEOBJ *,
  1087. PBYTE,
  1088. ULONG
  1089. );
  1090. BYTE
  1091. XLATEOBJ_RGB32ToPalSurf(
  1092. XLATEOBJ *,
  1093. PBYTE,
  1094. ULONG
  1095. );
  1096. BYTE
  1097. XLATEOBJ_BGR32ToPalSurf(
  1098. XLATEOBJ *,
  1099. PBYTE,
  1100. ULONG
  1101. );
  1102. BYTE
  1103. XLATEOBJ_RGB16_565ToPalSurf(
  1104. XLATEOBJ *,
  1105. PBYTE,
  1106. ULONG
  1107. );
  1108. BYTE
  1109. XLATEOBJ_RGB16_555ToPalSurf(
  1110. XLATEOBJ *,
  1111. PBYTE,
  1112. ULONG
  1113. );
  1114. typedef BYTE (*PFN_XLATE_RGB_TO_PALETTE)(XLATEOBJ *,PBYTE,ULONG);
  1115. /******************************Public*Class********************************\
  1116. * class XLATEMEMOBJ
  1117. *
  1118. * Xlate Memory Object
  1119. *
  1120. * History:
  1121. * 07-Nov-1990 -by- Patrick Haluptzok patrickh
  1122. * Wrote it.
  1123. \**************************************************************************/
  1124. class XLATEMEMOBJ : public EXLATEOBJ /* xlmo */
  1125. {
  1126. public:
  1127. XLATEMEMOBJ(XEPALOBJ palSurf, XEPALOBJ palDC);
  1128. ~XLATEMEMOBJ();
  1129. };
  1130. //
  1131. // Prototypes for internal functions used in palette management.
  1132. //
  1133. BOOL
  1134. bDeletePalette(
  1135. HPAL hpal,
  1136. BOOL bCleanup = FALSE,
  1137. CLEANUPTYPE cutype = CLEANUP_NONE
  1138. );
  1139. ULONG
  1140. rgbFromColorref(
  1141. XEPALOBJ palSurf,
  1142. XEPALOBJ palDC,
  1143. ULONG crColor
  1144. );
  1145. ULONG
  1146. ulGetNearestIndexFromColorref(
  1147. XEPALOBJ palSurf,
  1148. XEPALOBJ palDC,
  1149. ULONG crColor,
  1150. ULONG seSearchExactFirst = SE_DO_SEARCH_EXACT_FIRST
  1151. );
  1152. ULONG
  1153. ulGetMatchingIndexFromColorref(
  1154. XEPALOBJ palSurf,
  1155. XEPALOBJ palDC,
  1156. ULONG crColor
  1157. );
  1158. ULONG
  1159. ulIndexToRGB(
  1160. XEPALOBJ palSrc,
  1161. XEPALOBJ palDC,
  1162. ULONG iSolidColor
  1163. );
  1164. ULONG
  1165. ulColorRefToRGB(
  1166. XEPALOBJ palSrc,
  1167. XEPALOBJ palDC,
  1168. ULONG iSolidColor
  1169. );
  1170. BOOL
  1171. bIsCompatible(
  1172. PPALETTE *pppalReference,
  1173. PPALETTE ppalBM,
  1174. SURFACE *pSurfBM,
  1175. HDEV hdev
  1176. );
  1177. VOID
  1178. vDeleteXLATEOBJ(
  1179. PXLATE pxlate
  1180. );
  1181. BOOL
  1182. CreateSurfacePal(
  1183. XEPALOBJ palSrc,
  1184. FLONG iPalType,
  1185. ULONG ulNumReserved,
  1186. ULONG ulNumPalReg
  1187. );
  1188. VOID
  1189. ParseBits(
  1190. FLONG flag,
  1191. ULONG *pcRight,
  1192. ULONG *pcLeft,
  1193. ULONG *pcMiddle,
  1194. ULONG cForColor
  1195. );
  1196. VOID
  1197. vMatchAPal(
  1198. PDC pdc,
  1199. XEPALOBJ palSurf,
  1200. XEPALOBJ palDC,
  1201. ULONG *pulnPhysChanged,
  1202. ULONG *pulnTransChanged
  1203. );
  1204. PTRANSLATE
  1205. ptransMatchAPal(
  1206. PDC pdc,
  1207. XEPALOBJ palSurf,
  1208. XEPALOBJ palDC,
  1209. BOOL bForeground,
  1210. ULONG *pulnPhysChanged,
  1211. ULONG *pulnTransChanged
  1212. );
  1213. BOOL
  1214. bEqualRGB_In_Palette(
  1215. XEPALOBJ,
  1216. XEPALOBJ
  1217. );
  1218. PPALETTE
  1219. CreatePhysicalPalette(
  1220. HDC hdc,
  1221. HPALETTE hpal
  1222. );
  1223. PPALETTE
  1224. ppalGetPPal(
  1225. HDC hdc,
  1226. HPALETTE hpal
  1227. );
  1228. VOID
  1229. vResetSurfacePalette(
  1230. HDEV hdev
  1231. );
  1232. //
  1233. // asm accelerator for ulGetNearestPalentry
  1234. //
  1235. extern "C" {
  1236. PPALETTEENTRY
  1237. ppalSearchNearestEntry(
  1238. PPALETTEENTRY ppalTemp,
  1239. CONST PALETTEENTRY palentry,
  1240. ULONG cEntries,
  1241. PUINT pArrayOfSquares
  1242. );
  1243. }
  1244. PPALETTE
  1245. ppalGet_ip(
  1246. XEPALOBJ,
  1247. HANDLE,
  1248. PPDEV
  1249. );
  1250. #endif
  1251. #endif // GDIFLAGS_ONLY used for gdikdx