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.

897 lines
25 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: paleng.cxx
  3. *
  4. * Palette support routines used by NT components.
  5. *
  6. * Created: 27-Nov-1990 12:28:40
  7. * Author: Patrick Haluptzok patrickh
  8. *
  9. * Copyright (c) 1990-1999 Microsoft Corporation
  10. \**************************************************************************/
  11. #include "precomp.hxx"
  12. /******************************Public*Routine******************************\
  13. * GreSetPaletteOwner
  14. *
  15. * Sets the palette owner.
  16. *
  17. \**************************************************************************/
  18. BOOL
  19. GreSetPaletteOwner(
  20. HPALETTE hpal,
  21. W32PID lPid)
  22. {
  23. BOOL bRet = FALSE;
  24. if (hpal==(HPALETTE)STOCKOBJ_PAL)
  25. {
  26. WARNING("GreSetPaletteOwner: Cannot set owner for the stock Palette\n");
  27. }
  28. else
  29. {
  30. bRet = HmgSetOwner((HOBJ)hpal,lPid,PAL_TYPE);
  31. }
  32. return (bRet);
  33. }
  34. /******************************Public*Routine******************************\
  35. * CreateSurfacePal
  36. *
  37. * Turns a physical palette into a palette managed palette for a device.
  38. *
  39. * History:
  40. * Tue 04-Dec-1990 -by- Patrick Haluptzok [patrickh]
  41. * Wrote it.
  42. \**************************************************************************/
  43. BOOL CreateSurfacePal(XEPALOBJ palSrc, FLONG iPalType, ULONG ulNumReserved, ULONG ulNumPalReg)
  44. {
  45. ASSERTGDI(iPalType == PAL_MANAGED, "ERROR: CreateSurfacePalette passed bad iPalType\n");
  46. ASSERTGDI(palSrc.bValid(), "ERROR CreateSurfacePal palSrc");
  47. ASSERTGDI(palSrc.cEntries() != 0, "ERROR CreateSurfacePal");
  48. //
  49. // If it is a Palette managed surface we must keep an exact
  50. // copy of it's origal state for certain functionality.
  51. //
  52. PALMEMOBJ pal;
  53. BOOL b;
  54. b = pal.bCreatePalette(palSrc.iPalMode(),
  55. palSrc.cEntries(),
  56. (PULONG) palSrc.apalColorGet(),
  57. 0,
  58. 0,
  59. 0,
  60. iPalType);
  61. if (b)
  62. {
  63. ASSERTGDI(pal.bIsIndexed(), "Creating a non-indexed managed surface ???");
  64. ASSERTGDI(pal.bIsPalManaged(), "ERROR PAL_MANaged not pal managed");
  65. //
  66. // Now we have to set the type or the source to be PAL_MANAGED.
  67. //
  68. palSrc.flPalSet((palSrc.flPal() & ~(PAL_FIXED)) | PAL_MANAGED);
  69. //
  70. // Set the used and foreground flags on the reserved palette entries.
  71. //
  72. PAL_ULONG palTemp;
  73. ASSERTGDI((ulNumReserved & 0x00001) == 0, "ERROR non multiple of 2 reserved colors");
  74. palSrc.ulNumReserved(ulNumReserved);
  75. pal.ulNumReserved(ulNumReserved);
  76. ulNumReserved >>= 1;
  77. ULONG iPalMode;
  78. for (iPalMode = 0; iPalMode < ulNumReserved; iPalMode++)
  79. {
  80. palTemp.ul = pal.ulEntryGet(iPalMode);
  81. palTemp.pal.peFlags = (PC_FOREGROUND | PC_USED);
  82. pal.ulEntrySet(iPalMode, palTemp.ul);
  83. palTemp.ul = pal.ulEntryGet(iPalMode + (ulNumPalReg - ulNumReserved));
  84. palTemp.pal.peFlags = (PC_FOREGROUND | PC_USED);
  85. pal.ulEntrySet(iPalMode + (ulNumPalReg - ulNumReserved), palTemp.ul);
  86. }
  87. //
  88. // Ok the palette is in perfect initial shape, copy it.
  89. //
  90. palSrc.vCopyEntriesFrom(pal);
  91. palSrc.ppalOriginal(pal.ppalGet());
  92. pal.ulTime(palSrc.ulTime());
  93. pal.vKeepIt();
  94. }
  95. return(b);
  96. }
  97. /******************************Public*Routine******************************\
  98. * ulGetNearestIndexFromColorref
  99. *
  100. * Given the surface palette and the DC palette, this returns the index in
  101. * palSurf that crColor maps to.
  102. *
  103. * Modifies: Nothing.
  104. *
  105. * Returns: Index in palSurf that crColor maps to.
  106. *
  107. * PALETTERGB puts a 2 in the high byte.
  108. * PALETTEINDEX puts a 1 in the high byte.
  109. *
  110. * History:
  111. * Mon 02-Sep-1991 -by- Patrick Haluptzok [patrickh]
  112. * Wrote it.
  113. \**************************************************************************/
  114. ULONG
  115. ulGetNearestIndexFromColorref(
  116. XEPALOBJ palSurf,
  117. XEPALOBJ palDC,
  118. ULONG crColor,
  119. ULONG seSearchExactFirst)
  120. {
  121. ASSERTGDI(palDC.bValid(), "ERROR invalid palDC");
  122. PDEV *ppdev = (PDEV *)palDC.hdev();
  123. PAL_ULONG palTemp;
  124. palTemp.ul = crColor;
  125. //
  126. // Check if it's palette managed. If it's a device bitmap for a palette managed
  127. // device it will have an invalid palette. If the palettes valid then it may be
  128. // the palette managed device's palette.
  129. //
  130. if ((!palSurf.bValid()) || (palSurf.bIsPalManaged()))
  131. {
  132. //
  133. // RGB: Match to default palette or dither
  134. //
  135. // PALETTERGB: Match RGB value to nearest entry in palette
  136. //
  137. // PALETTEINDEX: The low 16 bits is a direct index to a palette entry
  138. //
  139. //
  140. // Check if it's a color forces us to access the xlate
  141. //
  142. if (palTemp.ul & 0x03000000)
  143. {
  144. if (palTemp.ul & 0x01000000)
  145. {
  146. //
  147. // PALETTEINDEX:
  148. //
  149. // This means they have an explicit entry in the DC palette they want
  150. //
  151. palTemp.pal.peFlags = 0;
  152. if (palTemp.ul >= palDC.cEntries())
  153. {
  154. palTemp.ul = 0;
  155. }
  156. }
  157. else
  158. {
  159. //
  160. // PALETTERGB:
  161. //
  162. // Get rid of the top byte first. It's 0x02 and we want to
  163. // search with this being an RGB.
  164. //
  165. palTemp.pal.peFlags = 0;
  166. palTemp.ul = palDC.ulGetNearestFromPalentry(
  167. palTemp.pal,
  168. seSearchExactFirst
  169. );
  170. }
  171. //
  172. // If the DC's palette is the default palette, adjust if this is in the
  173. // top 10 colors, then we're done, because there's no translation of
  174. // the default palette
  175. //
  176. if (palDC.bIsPalDefault())
  177. {
  178. if (palTemp.ul >= 10)
  179. {
  180. palTemp.ul = palTemp.ul + 236;
  181. }
  182. return(palTemp.ul);
  183. }
  184. //
  185. // Now do the right thing based on whether we are on the device bitmap
  186. // or the device surface.
  187. //
  188. if ((palSurf.bValid()) && (palDC.ptransCurrent() != NULL))
  189. {
  190. return(palDC.ulTranslateDCtoCurrent(palTemp.ul));
  191. }
  192. if ((!palSurf.bValid()) && (palDC.ptransFore() != NULL))
  193. {
  194. return(palDC.ulTranslateDCtoFore(palTemp.ul));
  195. }
  196. //
  197. // App is in hosed state which is possible in multi-tasking system.
  198. // Map as best we can into static colors, get the RGB from palDC.
  199. //
  200. palTemp.pal = palDC.palentryGet(palTemp.ul);
  201. //
  202. // If PC_EXPLICIT is set just return value modulo 256.
  203. //
  204. if (palTemp.pal.peFlags == PC_EXPLICIT)
  205. {
  206. return(palTemp.ul & 0x000000FF);
  207. }
  208. }
  209. //
  210. // check for DIBINDEX
  211. //
  212. if ((palTemp.ul & 0x10ff0000) == 0x10ff0000)
  213. {
  214. return(palTemp.ul & 0x000000FF);
  215. }
  216. //
  217. // At this point palTemp is an RGB value
  218. //
  219. // Well we need to match against the default palette. We quickly
  220. // check for black and white and pass the rest through.
  221. //
  222. palTemp.pal.peFlags = 0;
  223. if (palTemp.ul == 0xFFFFFF)
  224. {
  225. palTemp.ul = 19;
  226. }
  227. else if (palTemp.ul != 0)
  228. {
  229. palTemp.ul =
  230. ((XEPALOBJ) ppalDefault).ulGetNearestFromPalentry(
  231. palTemp.pal,
  232. seSearchExactFirst
  233. );
  234. }
  235. if (palTemp.ul >= 10)
  236. {
  237. palTemp.ul = palTemp.ul + 236;
  238. }
  239. return(palTemp.ul);
  240. }
  241. //
  242. // This means they are not palette managed.
  243. //
  244. if (palTemp.ul & 0x01000000)
  245. {
  246. //
  247. // PALETTEINDEX:
  248. // This means they have an explicit entry in the DC palette they want.
  249. //
  250. palTemp.ul &= 0x0000FFFF;
  251. if (palTemp.ul >= palDC.cEntries())
  252. {
  253. palTemp.ul = 0;
  254. }
  255. palTemp.pal = palDC.palentryGet(palTemp.ul);
  256. }
  257. else if ((palTemp.ul & 0x10ff0000) == 0x10ff0000)
  258. {
  259. //
  260. // check for DIBINDEX
  261. //
  262. palTemp.ul &= 0x000000FF;
  263. return((palTemp.ul >= palSurf.cEntries()) ? 0 : palTemp.ul);
  264. }
  265. else
  266. {
  267. //
  268. // We just look for the closest RGB.
  269. //
  270. palTemp.pal.peFlags = 0;
  271. }
  272. //
  273. // Now it is time to look in the surface palette for the matching color.
  274. //
  275. return(palSurf.ulGetNearestFromPalentry(palTemp.pal, seSearchExactFirst));
  276. }
  277. /******************************Public*Routine******************************\
  278. * ulGetMatchingIndexFromColorref
  279. *
  280. * Given the surface palette and the DC palette, this returns the index in
  281. * palSurf that crColor maps to exactly, or 0xFFFFFFFF if it doesn't map
  282. * exactly to any color. Note that if the "find nearest in palette managed"
  283. * bit (0x20000000) is set, the nearest color qualifies as a match, because
  284. * that's what they're asking for. However, there is no guarantee that either
  285. * of the special bits will result in a match, because the palette may be in
  286. * an incorrect state or they could be asking for a direct index into the DC
  287. * palette that produces a color that's not in the surface's palette (in the
  288. * case of a non-palette-managed surface).
  289. *
  290. * Modifies: Nothing.
  291. *
  292. * Returns: Index in palSurf that crColor maps to.
  293. *
  294. * PALETTERGB puts a 2 in the high byte (find nearest)
  295. * PALETTEINDEX puts a 1 in the high byte (find specified index)
  296. *
  297. * History:
  298. * Sun 27-Dec-1992 -by- Michael Abrash [mikeab]
  299. * Wrote it.
  300. \**************************************************************************/
  301. ULONG
  302. ulGetMatchingIndexFromColorref(
  303. XEPALOBJ palSurf,
  304. XEPALOBJ palDC,
  305. ULONG crColor
  306. )
  307. {
  308. ASSERTGDI(palDC.bValid(), "ERROR invalid palDC");
  309. PAL_ULONG palTemp;
  310. PDEV *ppdev = (PDEV *)palDC.hdev();
  311. palTemp.ul = crColor;
  312. //
  313. // Check if it's palette managed. If it's a device bitmap for a palette managed
  314. // device it will have an invalid palette. If the palette's valid then it may be
  315. // the palette managed device's palette.
  316. //
  317. if ((!palSurf.bValid()) || (palSurf.bIsPalManaged()))
  318. {
  319. //
  320. // RGB: Match to default palette or dither
  321. //
  322. // PALETTERGB: Match RGB value to nearest entry in palette
  323. //
  324. // PALETTEINDEX: The low 16 bits is a direct index to a palette entry
  325. //
  326. //
  327. // Check if it's a color forces us to access the xlate
  328. //
  329. if (palTemp.ul & 0x03000000)
  330. {
  331. if (palTemp.ul & 0x01000000)
  332. {
  333. //
  334. // PALETTEINDEX:
  335. //
  336. // This means they have an explicit entry in the DC palette they
  337. // want; only the lower byte is valid
  338. //
  339. palTemp.ul &= 0x0000FFFF;
  340. if (palTemp.ul >= palDC.cEntries())
  341. {
  342. palTemp.ul = 0;
  343. }
  344. }
  345. else // (palTemp.ul & 0x02000000)
  346. {
  347. //
  348. // Get rid of the top byte first. It's 0x02 and we want to search
  349. // the DC's palette for the nearest match with this being an RGB.
  350. // Note that in this case the nearest match and exact match are
  351. // logically equivalent
  352. //
  353. palTemp.pal.peFlags = 0;
  354. palTemp.ul = palDC.ulGetNearestFromPalentry(palTemp.pal);
  355. }
  356. //
  357. // If the DC's palette is the default palette, adjust if this is in the
  358. // top 10 colors, then we're done, because there's no translation of
  359. // the default palette
  360. //
  361. if (palDC.bIsPalDefault())
  362. {
  363. if (palTemp.ul >= 10)
  364. {
  365. palTemp.ul = palTemp.ul + 236;
  366. }
  367. return(palTemp.ul);
  368. }
  369. //
  370. // Now do the right thing based on whether we are on the device bitmap
  371. // or the device surface
  372. //
  373. if ((palSurf.bValid()) && (palDC.ptransCurrent() != NULL))
  374. {
  375. //
  376. // We're drawing to a palette managed device surface, using the
  377. // current translation (which may be either back or fore, depending
  378. // on whether the application is in the foreground and owns the
  379. // palette)
  380. //
  381. return(palDC.ulTranslateDCtoCurrent(palTemp.ul));
  382. }
  383. if ((!palSurf.bValid()) && (palDC.ptransFore() != NULL))
  384. {
  385. //
  386. // We're drawing to a bitmap for a palette managed device, using
  387. // the fore translation (always treat drawing to a bitmap as
  388. // foreground drawing)
  389. //
  390. return(palDC.ulTranslateDCtoFore(palTemp.ul));
  391. }
  392. //
  393. // App is in hosed state which is possible in multi-tasking system.
  394. // Map as best we can into static colors, get the RGB from palDC and
  395. // try to find that in the default palette
  396. //
  397. palTemp.pal = palDC.palentryGet(palTemp.ul);
  398. //
  399. // If PC_EXPLICIT is set just return value modulo 256.
  400. //
  401. if (palTemp.pal.peFlags == PC_EXPLICIT)
  402. {
  403. return(palTemp.ul & 0x000000FF);
  404. }
  405. }
  406. //
  407. // check for DIBINDEX
  408. //
  409. if ((palTemp.ul & 0x10ff0000) == 0x10ff0000)
  410. {
  411. return(palTemp.ul & 0x000000FF);
  412. }
  413. //
  414. // Well, we're palette managed and have a plain old RGB (or failed to
  415. // find the desired translation), so we need to match against the
  416. // default palette. We quickly check for black and white and pass
  417. // the rest through.
  418. //
  419. palTemp.pal.peFlags = 0;
  420. if (palTemp.ul == 0xFFFFFF)
  421. {
  422. palTemp.ul = 19;
  423. }
  424. else if (palTemp.ul != 0)
  425. {
  426. palTemp.ul = ((XEPALOBJ) ppalDefault).ulGetMatchFromPalentry(palTemp.pal);
  427. }
  428. //
  429. // If we're in the top half of the default palette, adjust to the high end
  430. // of the 256-color palette, where the top half of the default palette
  431. // actually resides
  432. //
  433. if ((palTemp.ul != 0xFFFFFFFF) && (palTemp.ul >= 10))
  434. {
  435. palTemp.ul = palTemp.ul + 236;
  436. }
  437. return(palTemp.ul);
  438. }
  439. //
  440. // Not palette managed.
  441. //
  442. if (palTemp.ul & 0x01000000)
  443. {
  444. //
  445. // This means they have an explicit entry in the DC palette they want.
  446. // Limit the maximum explicit entry to 8 bits.
  447. //
  448. palTemp.ul &= 0x0000FFFF;
  449. //
  450. // If the index is off the end of the palette, wrap it modulo the palette
  451. // length.
  452. //
  453. if (palTemp.ul >= palDC.cEntries())
  454. {
  455. palTemp.ul = 0;
  456. }
  457. //
  458. // Search the palette for the color closest to the color selected from the
  459. // DC palette by the specified index
  460. //
  461. palTemp.pal = palDC.palentryGet(palTemp.ul);
  462. }
  463. else if ((palTemp.ul & 0x10ff0000) == 0x10ff0000)
  464. {
  465. //
  466. // check for DIBINDEX
  467. //
  468. palTemp.ul &= 0x000000FF;
  469. return((palTemp.ul >= palSurf.cEntries()) ? 0 : palTemp.ul);
  470. }
  471. else
  472. {
  473. //
  474. // We just look for the closest RGB; mask off the flags.
  475. //
  476. palTemp.pal.peFlags = 0;
  477. }
  478. //
  479. // Now it is time to look in the surface palette for the matching color.
  480. //
  481. return(palSurf.ulGetMatchFromPalentry(palTemp.pal));
  482. }
  483. /******************************Public*Routine******************************\
  484. * ulColorRefToRGB
  485. *
  486. * Given a color ref this returns the RGB it corresponds to.
  487. *
  488. * This is a helper function given a color ref that may contain
  489. * DIBINDEX value, do the appropriate translation of the DIBINDEX.
  490. *
  491. * History:
  492. * 19-Jan-2001 -by- Barton House bhouse
  493. * Wrote it.
  494. \**************************************************************************/
  495. ULONG
  496. ulColorRefToRGB(
  497. XEPALOBJ palSurf,
  498. XEPALOBJ palDC,
  499. ULONG iColorRef
  500. )
  501. {
  502. if((iColorRef & 0x10FF0000) == 0x10FF0000)
  503. {
  504. return ulIndexToRGB(palSurf, palDC, iColorRef & 0xFF);
  505. }
  506. else
  507. {
  508. return iColorRef;
  509. }
  510. }
  511. /******************************Public*Routine******************************\
  512. * ulIndexToRGB
  513. *
  514. * Given an index this returns the RGB it corresponds to.
  515. *
  516. * History:
  517. * 21-Nov-1992 -by- Patrick Haluptzok patrickh
  518. * Wrote it.
  519. \**************************************************************************/
  520. ULONG
  521. ulIndexToRGB(
  522. XEPALOBJ palSurf,
  523. XEPALOBJ palDC,
  524. ULONG iSolidColor
  525. )
  526. {
  527. ASSERTGDI(palDC.bValid(), "ERROR invalid palDC");
  528. PAL_ULONG palTemp;
  529. if (palSurf.bValid())
  530. {
  531. return(palSurf.ulIndexToRGB(iSolidColor));
  532. }
  533. //
  534. // It's a palette managed device bitmap.
  535. //
  536. if (iSolidColor < 10)
  537. {
  538. palTemp.pal = logDefaultPal.palPalEntry[iSolidColor];
  539. return(palTemp.ul);
  540. }
  541. if (iSolidColor > 245)
  542. {
  543. palTemp.pal = logDefaultPal.palPalEntry[iSolidColor - 236];
  544. return(palTemp.ul);
  545. }
  546. //
  547. // Well it's the first entry in the logical palette that mapped here in the
  548. // foreground xlate. If the foreground Xlate is invalid, who knows, return 0.
  549. //
  550. SEMOBJ semo(ghsemPalette);
  551. if (palDC.ptransFore() != NULL)
  552. {
  553. PBYTE pjTemp = palDC.ptransFore()->ajVector;
  554. palTemp.ul = palDC.cEntries();
  555. for (palTemp.ul = 0; palTemp.ul < palDC.cEntries(); palTemp.ul++,pjTemp++)
  556. {
  557. if (*pjTemp == ((BYTE) iSolidColor))
  558. return(palDC.ulEntryGet(palTemp.ul));
  559. }
  560. }
  561. //
  562. // Well we just don't know.
  563. //
  564. return(0);
  565. }
  566. /******************************Public*Routine******************************\
  567. * bIsCompatible
  568. *
  569. * This returns TRUE if the bitmap can be selected into this PDEV's memory
  570. * DC's based on "Can we determine the color information". It also returns
  571. * the palette you could use for a reference for color information.
  572. *
  573. * History:
  574. * 28-Jan-1993 -by- Patrick Haluptzok patrickh
  575. * Wrote it.
  576. \**************************************************************************/
  577. BOOL bIsCompatible(PPALETTE *pppalReference, PPALETTE ppalBM, SURFACE *pSurfBM, HDEV hdev)
  578. {
  579. BOOL bRet = TRUE;
  580. XEPALOBJ palBM(ppalBM);
  581. PDEVOBJ po(hdev);
  582. // We need to make sure this could be selected into this DC. If it is a device
  583. // managed bitmap, it must be the same device.
  584. if (((pSurfBM->iType() != STYPE_BITMAP) || (pSurfBM->dhsurf() != 0)) &&
  585. (pSurfBM->hdev() != hdev))
  586. {
  587. WARNING1("bIsCompatible failed Device surface for another PDEV\n");
  588. bRet = FALSE;
  589. }
  590. else if (palBM.bValid())
  591. {
  592. // No problem, we already have color information.
  593. *pppalReference = palBM.ppalGet();
  594. }
  595. else if (pSurfBM->iFormat() != po.iDitherFormat())
  596. {
  597. // Check surface is compatible with PDEV for selection.
  598. WARNING1("bIsCompatible: Bitmap not compatible with DC\n");
  599. bRet = FALSE;
  600. }
  601. else
  602. {
  603. // If it's not palette managed set in palette for the device. Otherwise
  604. // leave it NULL and the right stuff will happen.
  605. if (!po.bIsPalManaged())
  606. {
  607. *pppalReference = po.ppalSurf();
  608. }
  609. else
  610. {
  611. *pppalReference = (PPALETTE) NULL;
  612. ASSERTGDI(po.iDitherFormat() == BMF_8BPP, "ERROR GetDIBits no palette not 8BPP");
  613. }
  614. }
  615. return(bRet);
  616. }
  617. /******************************Public*Routine******************************\
  618. * rgbFromColorref
  619. *
  620. * Given the surface palette and the DC palette, this returns the rgb that
  621. * this colorref represents.
  622. *
  623. * Returns: RGB that crColor maps to.
  624. *
  625. * PALETTERGB puts a 2 in the high byte (find nearest)
  626. * PALETTEINDEX puts a 1 in the high byte (find specified index)
  627. *
  628. * History:
  629. * Thu 18-Feb-1993 -by- Patrick Haluptzok [patrickh]
  630. * Wrote it.
  631. \**************************************************************************/
  632. ULONG
  633. rgbFromColorref(
  634. XEPALOBJ palSurf,
  635. XEPALOBJ palDC,
  636. ULONG crColor
  637. )
  638. {
  639. ASSERTGDI(palDC.bValid(), "ERROR invalid palDC");
  640. PAL_ULONG palTemp;
  641. palTemp.ul = crColor;
  642. if (palTemp.ul & 0x01000000)
  643. {
  644. //
  645. // This means they have an explicit entry in the DC palette they
  646. // want. Only the lower byte is valid.
  647. //
  648. palTemp.ul &= 0x0000FFFF;
  649. if (palTemp.ul >= palDC.cEntries())
  650. {
  651. palTemp.ul = 0;
  652. }
  653. palTemp.pal = palDC.palentryGet(palTemp.ul);
  654. //
  655. // If PC_EXPLICIT reach into the surface palette if possible.
  656. //
  657. if (palTemp.pal.peFlags == PC_EXPLICIT)
  658. {
  659. if (palSurf.bValid())
  660. {
  661. if (palSurf.cEntries())
  662. {
  663. palTemp.ul &= 0x000000FF;
  664. if (palTemp.ul >= palSurf.cEntries())
  665. {
  666. palTemp.ul = palTemp.ul % palSurf.cEntries();
  667. }
  668. palTemp.pal = palSurf.palentryGet(palTemp.ul);
  669. }
  670. }
  671. }
  672. }
  673. palTemp.pal.peFlags = 0;
  674. return(palTemp.ul);
  675. }
  676. /******************************Public*Routine******************************\
  677. * bEqualRGB_In_Palette
  678. *
  679. * This function determines if 2 palettes contain identical RGB entries and
  680. * palette sizes and therefore have an identity xlate between them. This is
  681. * need with DIBSECTIONS which may have duplicate palette entries but still
  682. * should have identity xlates when blting between them.
  683. *
  684. * History:
  685. * 10-Mar-1994 -by- Patrick Haluptzok patrickh
  686. * Wrote it.
  687. \**************************************************************************/
  688. BOOL bEqualRGB_In_Palette(XEPALOBJ palSrc, XEPALOBJ palDst)
  689. {
  690. ASSERTGDI(palSrc.bValid(), "ERROR invalid SRC");
  691. ASSERTGDI(palDst.bValid(), "ERROR invalid DST");
  692. //
  693. // Check for equal size palettes that are == to 256 in size.
  694. // 256 is the size of our palette managed palettes.
  695. //
  696. if ((palSrc.cEntries() != palDst.cEntries()) ||
  697. (palDst.cEntries() != 256))
  698. {
  699. return(FALSE);
  700. }
  701. //
  702. // If the Dst is a DC palette make sure it contains an identity
  703. // realization in it.
  704. //
  705. UINT uiIndex;
  706. if (palDst.bIsPalDC())
  707. {
  708. //
  709. // Check the translate for the current if it's the screen, otherwise
  710. // check the translate for the foreground for a bitmap.
  711. //
  712. TRANSLATE *ptrans = palDst.ptransFore();
  713. if (ptrans == NULL)
  714. return(FALSE);
  715. uiIndex = palDst.cEntries();
  716. while(uiIndex--)
  717. {
  718. if (ptrans->ajVector[uiIndex] != uiIndex)
  719. return(FALSE);
  720. }
  721. }
  722. uiIndex = palDst.cEntries();
  723. ULONG ulTemp;
  724. while(uiIndex--)
  725. {
  726. ulTemp = palSrc.ulEntryGet(uiIndex) ^ palDst.ulEntryGet(uiIndex);
  727. if (ulTemp & 0xFFFFFF)
  728. {
  729. return(FALSE);
  730. }
  731. }
  732. return(TRUE);
  733. }