Source code of Windows XP (NT5)
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.

717 lines
19 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: fastdib.c
  3. *
  4. * CreateCompatibleDIB implementation.
  5. *
  6. * Created: 23-Jan-1996 21:08:18
  7. * Author: Gilman Wong [gilmanw]
  8. *
  9. * Copyright (c) 1996 Microsoft Corporation
  10. *
  11. \**************************************************************************/
  12. #include <windows.h>
  13. #include <stddef.h>
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include "mtk.h"
  17. BOOL APIENTRY GetDIBTranslationVector(HDC hdcMem, HPALETTE hpal, BYTE *pbVector);
  18. static BOOL bFillBitmapInfo(HDC hdc, HPALETTE hpal, BITMAPINFO *pbmi);
  19. static BOOL bFillColorTable(HDC hdc, HPALETTE hpal, BITMAPINFO *pbmi);
  20. static UINT MyGetSystemPaletteEntries(HDC hdc, UINT iStartIndex, UINT nEntries,
  21. LPPALETTEENTRY lppe);
  22. static BOOL bComputeLogicalToSurfaceMap(HDC hdc, HPALETTE hpal,
  23. BYTE *pajVector);
  24. /******************************Public*Routine******************************\
  25. * CreateCompatibleDIB
  26. *
  27. * Create a DIB section with an optimal format w.r.t. the specified hdc.
  28. *
  29. * If DIB <= 8bpp, then the DIB color table is initialized based on the
  30. * specified palette. If the palette handle is NULL, then the system
  31. * palette is used.
  32. *
  33. * Note: The hdc must be a direct DC (not an info or memory DC).
  34. *
  35. * Note: On palettized displays, if the system palette changes the
  36. * UpdateDIBColorTable function should be called to maintain
  37. * the identity palette mapping between the DIB and the display.
  38. *
  39. * Returns:
  40. * Valid bitmap handle if successful, NULL if error.
  41. *
  42. * History:
  43. * 23-Jan-1996 -by- Gilman Wong [gilmanw]
  44. * Wrote it.
  45. \**************************************************************************/
  46. //HBITMAP APIENTRY
  47. HBITMAP
  48. SSDIB_CreateCompatibleDIB(HDC hdc, HPALETTE hpal, ULONG ulWidth, ULONG ulHeight,
  49. PVOID *ppvBits)
  50. {
  51. HBITMAP hbmRet = (HBITMAP) NULL;
  52. BYTE aj[sizeof(BITMAPINFO) + (sizeof(RGBQUAD) * 255)];
  53. BITMAPINFO *pbmi = (BITMAPINFO *) aj;
  54. //
  55. // Validate hdc.
  56. //
  57. if ( GetObjectType(hdc) != OBJ_DC )
  58. {
  59. SS_DBGPRINT("CreateCompatibleDIB: not OBJ_DC\n");
  60. return hbmRet;
  61. }
  62. memset(aj, 0, sizeof(aj));
  63. if ( bFillBitmapInfo(hdc, hpal, pbmi) )
  64. {
  65. //
  66. // Change bitmap size to match specified dimensions.
  67. //
  68. pbmi->bmiHeader.biWidth = ulWidth;
  69. pbmi->bmiHeader.biHeight = ulHeight;
  70. if (pbmi->bmiHeader.biCompression == BI_RGB)
  71. {
  72. pbmi->bmiHeader.biSizeImage = 0;
  73. }
  74. else
  75. {
  76. if ( pbmi->bmiHeader.biBitCount == 16 )
  77. pbmi->bmiHeader.biSizeImage = ulWidth * ulHeight * 2;
  78. else if ( pbmi->bmiHeader.biBitCount == 32 )
  79. pbmi->bmiHeader.biSizeImage = ulWidth * ulHeight * 4;
  80. else
  81. pbmi->bmiHeader.biSizeImage = 0;
  82. }
  83. pbmi->bmiHeader.biClrUsed = 0;
  84. pbmi->bmiHeader.biClrImportant = 0;
  85. //
  86. // Create the DIB section. Let Win32 allocate the memory and return
  87. // a pointer to the bitmap surface.
  88. //
  89. hbmRet = CreateDIBSection(hdc, pbmi, DIB_RGB_COLORS, ppvBits, NULL, 0);
  90. GdiFlush();
  91. if ( !hbmRet )
  92. {
  93. SS_DBGPRINT("CreateCompatibleDIB: CreateDIBSection failed\n");
  94. }
  95. }
  96. else
  97. {
  98. SS_DBGPRINT("CreateCompatibleDIB: bFillBitmapInfo failed\n");
  99. }
  100. return hbmRet;
  101. }
  102. /******************************Public*Routine******************************\
  103. * UpdateDIBColorTable
  104. *
  105. * Synchronize the DIB color table to the specified palette hpal.
  106. * If hpal is NULL, then use the system palette.
  107. *
  108. * Returns:
  109. * TRUE if successful, FALSE otherwise.
  110. *
  111. * History:
  112. * 23-Jan-1996 -by- Gilman Wong [gilmanw]
  113. * Wrote it.
  114. \**************************************************************************/
  115. BOOL APIENTRY
  116. SSDIB_UpdateColorTable(HDC hdcMem, HDC hdc, HPALETTE hpal)
  117. {
  118. BOOL bRet = FALSE;
  119. HBITMAP hbm;
  120. DIBSECTION ds;
  121. BYTE aj[(sizeof(RGBQUAD) + sizeof(PALETTEENTRY)) * 256];
  122. LPPALETTEENTRY lppe = (LPPALETTEENTRY) aj;
  123. LPRGBQUAD prgb = (LPRGBQUAD) (lppe + 256);
  124. ULONG i, cColors;
  125. //
  126. // Validate hdc.
  127. //
  128. if ( GetObjectType(hdc) != OBJ_DC )
  129. {
  130. SS_DBGPRINT("UpdateDIBColorTable: not OBJ_DC\n");
  131. return bRet;
  132. }
  133. if ( GetObjectType(hdcMem) != OBJ_MEMDC )
  134. {
  135. SS_DBGPRINT("UpdateDIBColorTable: not OBJ_MEMDC\n");
  136. return bRet;
  137. }
  138. //
  139. // Get the bitmap handle out of the memdc.
  140. //
  141. hbm = GetCurrentObject(hdcMem, OBJ_BITMAP);
  142. //
  143. // Validate bitmap (must be DIB section).
  144. //
  145. if ( (GetObject(hbm, sizeof(ds), &ds) == sizeof(ds)) &&
  146. ds.dsBm.bmBits )
  147. {
  148. //
  149. // Get palette entries from specified palette or system palette.
  150. //
  151. cColors = 1 << ds.dsBmih.biBitCount;
  152. if ( hpal ? GetPaletteEntries(hpal, 0, cColors, lppe)
  153. : MyGetSystemPaletteEntries(hdc, 0, cColors, lppe)
  154. )
  155. {
  156. UINT i;
  157. //
  158. // Convert to RGBQUAD.
  159. //
  160. for (i = 0; i < cColors; i++)
  161. {
  162. prgb[i].rgbRed = lppe[i].peRed;
  163. prgb[i].rgbGreen = lppe[i].peGreen;
  164. prgb[i].rgbBlue = lppe[i].peBlue;
  165. prgb[i].rgbReserved = 0;
  166. }
  167. //
  168. // Set the DIB color table.
  169. //
  170. bRet = (BOOL) SetDIBColorTable(hdcMem, 0, cColors, prgb);
  171. if (!bRet)
  172. {
  173. SS_DBGPRINT("UpdateDIBColorTable: SetDIBColorTable failed\n");
  174. }
  175. }
  176. else
  177. {
  178. SS_DBGPRINT("UpdateDIBColorTable: MyGetSystemPaletteEntries failed\n");
  179. }
  180. }
  181. else
  182. {
  183. SS_DBGPRINT("UpdateDIBColorTable: GetObject failed\n");
  184. }
  185. return bRet;
  186. }
  187. /******************************Public*Routine******************************\
  188. * GetCompatibleDIBInfo
  189. *
  190. * Copies pointer to bitmap origin to ppvBase and bitmap stride to plStride.
  191. * Win32 DIBs can be created bottom-up (the default) with the origin at the
  192. * lower left corner or top-down with the origin at the upper left corner.
  193. * If the bitmap is top-down, *plStride is positive; if bottom-up, *plStride
  194. * us negative.
  195. *
  196. * Also, because of restrictions on the alignment of scan lines the width
  197. * the bitmap is often not the same as the stride (stride is the number of
  198. * bytes between vertically adjacent pixels).
  199. *
  200. * The ppvBase and plStride value returned will allow you to address any
  201. * given pixel (x, y) in the bitmap as follows:
  202. *
  203. * PIXEL *ppix;
  204. *
  205. * ppix = (PIXEL *) (((BYTE *)*ppvBase) + (y * *plStride) + (x * sizeof(PIXEL)));
  206. *
  207. * Returns:
  208. * TRUE if successful, FALSE otherwise.
  209. *
  210. * History:
  211. * 02-Feb-1996 -by- Gilman Wong [gilmanw]
  212. * Wrote it.
  213. \**************************************************************************/
  214. static BOOL APIENTRY
  215. GetCompatibleDIBInfo(HBITMAP hbm, PVOID *ppvBase, LONG *plStride)
  216. {
  217. BOOL bRet = FALSE;
  218. DIBSECTION ds;
  219. //
  220. // Call GetObject to return a DIBSECTION. If successful, the
  221. // bitmap is a DIB section and we can retrieve the pointer to
  222. // the bitmap bits and other parameters.
  223. //
  224. if ( (GetObject(hbm, sizeof(ds), &ds) == sizeof(ds))
  225. && ds.dsBm.bmBits )
  226. {
  227. // For backwards compatibility with Get/SetBitmapBits, GDI does
  228. // not accurately report the bitmap pitch in bmWidthBytes. It
  229. // always computes bmWidthBytes assuming WORD-aligned scanlines
  230. // regardless of the platform.
  231. //
  232. // Therefore, if the platform is WinNT, which uses DWORD-aligned
  233. // scanlines, adjust the bmWidthBytes value.
  234. {
  235. OSVERSIONINFO osvi;
  236. osvi.dwOSVersionInfoSize = sizeof(osvi);
  237. if (GetVersionEx(&osvi))
  238. {
  239. if ( osvi.dwPlatformId == VER_PLATFORM_WIN32_NT )
  240. {
  241. ds.dsBm.bmWidthBytes = (ds.dsBm.bmWidthBytes + 3) & ~3;
  242. }
  243. }
  244. else
  245. {
  246. SS_DBGPRINT1("GetCompatibleDIBInfo: GetVersionEx failed with %d\n", GetLastError());
  247. return bRet;
  248. }
  249. }
  250. //
  251. // If biHeight is positive, then the bitmap is a bottom-up DIB.
  252. // If biHeight is negative, then the bitmap is a top-down DIB.
  253. //
  254. if ( ds.dsBmih.biHeight > 0 )
  255. {
  256. *ppvBase = (PVOID) (((int) ds.dsBm.bmBits) + (ds.dsBm.bmWidthBytes * (ds.dsBm.bmHeight - 1)));
  257. *plStride = (ULONG) (-ds.dsBm.bmWidthBytes);
  258. }
  259. else
  260. {
  261. *ppvBase = ds.dsBm.bmBits;
  262. *plStride = ds.dsBm.bmWidthBytes;
  263. }
  264. bRet = TRUE;
  265. }
  266. else
  267. {
  268. SS_DBGPRINT("GetCompatibleDIBInfo: cannot get pointer to DIBSECTION bmBits\n");
  269. }
  270. return bRet;
  271. }
  272. /******************************Public*Routine******************************\
  273. * GetDIBTranslationVector
  274. *
  275. * Copies the translation vector that maps colors in the specified palette,
  276. * hpal, to the DIB selected into the specified DC, hdcMem.
  277. *
  278. * Effects:
  279. *
  280. * Returns:
  281. * TRUE if successful, FALSE otherwise.
  282. *
  283. * History:
  284. * 02-Feb-1996 -by- Gilman Wong [gilmanw]
  285. * Wrote it.
  286. \**************************************************************************/
  287. static BOOL APIENTRY
  288. GetDIBTranslationVector(HDC hdcMem, HPALETTE hpal, BYTE *pbVector)
  289. {
  290. BOOL bRet = FALSE;
  291. HBITMAP hbm;
  292. DIBSECTION ds;
  293. //
  294. // Validate parameters.
  295. //
  296. if ( GetObjectType(hdcMem) != OBJ_MEMDC ||
  297. GetObjectType(hpal) != OBJ_PAL ||
  298. !pbVector )
  299. {
  300. SS_DBGPRINT("GetDIBTranslationVector: bad parameter\n");
  301. return bRet;
  302. }
  303. //
  304. // The function bComputeLogicalToSurfaceMap cannot handle palettes
  305. // greater than 256 entries.
  306. //
  307. if ( GetPaletteEntries(hpal, 0, 1, NULL) > 256 )
  308. {
  309. SS_DBGPRINT("GetDIBTranslationVector: palette too big\n");
  310. return bRet;
  311. }
  312. //
  313. // The DIB must have a color table.
  314. //
  315. hbm = GetCurrentObject(hdcMem, OBJ_BITMAP);
  316. if ( (GetObject(hbm, sizeof(ds), &ds) == sizeof(ds))
  317. && (ds.dsBmih.biBitCount <= 8) )
  318. {
  319. bRet = bComputeLogicalToSurfaceMap(hdcMem, hpal, pbVector);
  320. }
  321. else
  322. {
  323. SS_DBGPRINT("GetDIBTranslationVector: not a DIB section\n");
  324. return bRet;
  325. }
  326. return bRet;
  327. }
  328. //////////////////// Below here are internal-only routines ////////////////////
  329. /******************************Public*Routine******************************\
  330. * bFillBitmapInfo
  331. *
  332. * Fills in the fields of a BITMAPINFO so that we can create a bitmap
  333. * that matches the format of the display.
  334. *
  335. * This is done by creating a compatible bitmap and calling GetDIBits
  336. * to return the color masks. This is done with two calls. The first
  337. * call passes in biBitCount = 0 to GetDIBits which will fill in the
  338. * base BITMAPINFOHEADER data. The second call to GetDIBits (passing
  339. * in the BITMAPINFO filled in by the first call) will return the color
  340. * table or bitmasks, as appropriate.
  341. *
  342. * Returns:
  343. * TRUE if successful, FALSE otherwise.
  344. *
  345. * History:
  346. * 07-Jun-1995 -by- Gilman Wong [gilmanw]
  347. * Wrote it.
  348. \**************************************************************************/
  349. static BOOL
  350. bFillBitmapInfo(HDC hdc, HPALETTE hpal, BITMAPINFO *pbmi)
  351. {
  352. HBITMAP hbm;
  353. BOOL bRet = FALSE;
  354. //
  355. // Create a dummy bitmap from which we can query color format info
  356. // about the device surface.
  357. //
  358. if ( (hbm = CreateCompatibleBitmap(hdc, 1, 1)) != NULL )
  359. {
  360. pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  361. //
  362. // Call first time to fill in BITMAPINFO header.
  363. //
  364. GetDIBits(hdc, hbm, 0, 0, NULL, pbmi, DIB_RGB_COLORS);
  365. if ( pbmi->bmiHeader.biBitCount <= 8 )
  366. {
  367. bRet = bFillColorTable(hdc, hpal, pbmi);
  368. }
  369. else
  370. {
  371. if ( pbmi->bmiHeader.biCompression == BI_BITFIELDS )
  372. {
  373. //
  374. // Call a second time to get the color masks.
  375. // It's a GetDIBits Win32 "feature".
  376. //
  377. GetDIBits(hdc, hbm, 0, pbmi->bmiHeader.biHeight, NULL, pbmi,
  378. DIB_RGB_COLORS);
  379. }
  380. bRet = TRUE;
  381. }
  382. DeleteObject(hbm);
  383. }
  384. else
  385. {
  386. SS_DBGPRINT("bFillBitmapInfo: CreateCompatibleBitmap failed\n");
  387. }
  388. return bRet;
  389. }
  390. /******************************Public*Routine******************************\
  391. * bFillColorTable
  392. *
  393. * Initialize the color table of the BITMAPINFO pointed to by pbmi. Colors
  394. * are set to the current system palette.
  395. *
  396. * Note: call only valid for displays of 8bpp or less.
  397. *
  398. * Returns:
  399. * TRUE if successful, FALSE otherwise.
  400. *
  401. * History:
  402. * 23-Jan-1996 -by- Gilman Wong [gilmanw]
  403. * Wrote it.
  404. \**************************************************************************/
  405. static BOOL
  406. bFillColorTable(HDC hdc, HPALETTE hpal, BITMAPINFO *pbmi)
  407. {
  408. BOOL bRet = FALSE;
  409. BYTE aj[sizeof(PALETTEENTRY) * 256];
  410. LPPALETTEENTRY lppe = (LPPALETTEENTRY) aj;
  411. RGBQUAD *prgb = (RGBQUAD *) &pbmi->bmiColors[0];
  412. ULONG i, cColors;
  413. cColors = 1 << pbmi->bmiHeader.biBitCount;
  414. if ( cColors <= 256 )
  415. {
  416. if ( hpal ? GetPaletteEntries(hpal, 0, cColors, lppe)
  417. : MyGetSystemPaletteEntries(hdc, 0, cColors, lppe) )
  418. {
  419. UINT i;
  420. for (i = 0; i < cColors; i++)
  421. {
  422. prgb[i].rgbRed = lppe[i].peRed;
  423. prgb[i].rgbGreen = lppe[i].peGreen;
  424. prgb[i].rgbBlue = lppe[i].peBlue;
  425. prgb[i].rgbReserved = 0;
  426. }
  427. bRet = TRUE;
  428. }
  429. else
  430. {
  431. SS_DBGPRINT("bFillColorTable: MyGetSystemPaletteEntries failed\n");
  432. }
  433. }
  434. return bRet;
  435. }
  436. /******************************Public*Routine******************************\
  437. * MyGetSystemPaletteEntries
  438. *
  439. * Internal version of GetSystemPaletteEntries.
  440. *
  441. * GetSystemPaletteEntries fails on some 4bpp devices. This version
  442. * will detect the 4bpp case and supply the hardcoded 16-color VGA palette.
  443. * Otherwise, it will pass the call on to GDI's GetSystemPaletteEntries.
  444. *
  445. * It is expected that this call will only be called in the 4bpp and 8bpp
  446. * cases as it is not necessary for OpenGL to query the system palette
  447. * for > 8bpp devices.
  448. *
  449. * History:
  450. * 17-Aug-1995 -by- Gilman Wong [gilmanw]
  451. * Wrote it.
  452. \**************************************************************************/
  453. static PALETTEENTRY gapeVgaPalette[16] =
  454. {
  455. { 0, 0, 0, 0 },
  456. { 0x80,0, 0, 0 },
  457. { 0, 0x80,0, 0 },
  458. { 0x80,0x80,0, 0 },
  459. { 0, 0, 0x80, 0 },
  460. { 0x80,0, 0x80, 0 },
  461. { 0, 0x80,0x80, 0 },
  462. { 0x80,0x80,0x80, 0 },
  463. { 0xC0,0xC0,0xC0, 0 },
  464. { 0xFF,0, 0, 0 },
  465. { 0, 0xFF,0, 0 },
  466. { 0xFF,0xFF,0, 0 },
  467. { 0, 0, 0xFF, 0 },
  468. { 0xFF,0, 0xFF, 0 },
  469. { 0, 0xFF,0xFF, 0 },
  470. { 0xFF,0xFF,0xFF, 0 }
  471. };
  472. static UINT
  473. MyGetSystemPaletteEntries(HDC hdc, UINT iStartIndex, UINT nEntries,
  474. LPPALETTEENTRY lppe)
  475. {
  476. int nDeviceBits;
  477. nDeviceBits = GetDeviceCaps(hdc, BITSPIXEL) * GetDeviceCaps(hdc, PLANES);
  478. //
  479. // Some 4bpp displays will fail the GetSystemPaletteEntries call.
  480. // So if detected, return the hardcoded table.
  481. //
  482. if ( nDeviceBits == 4 )
  483. {
  484. if ( lppe )
  485. {
  486. nEntries = min(nEntries, (16 - iStartIndex));
  487. memcpy(lppe, &gapeVgaPalette[iStartIndex],
  488. nEntries * sizeof(PALETTEENTRY));
  489. }
  490. else
  491. nEntries = 16;
  492. return nEntries;
  493. }
  494. else
  495. {
  496. return GetSystemPaletteEntries(hdc, iStartIndex, nEntries, lppe);
  497. }
  498. }
  499. /******************************Public*Routine******************************\
  500. * bComputeLogicalToSurfaceMap
  501. *
  502. * Copy logical palette to surface palette translation vector to the buffer
  503. * pointed to by pajVector. The logical palette is specified by hpal. The
  504. * surface is specified by hdc.
  505. *
  506. * Note: The hdc may identify either a direct (display) dc or a DIB memory dc.
  507. * If hdc is a display dc, then the surface palette is the system palette.
  508. * If hdc is a memory dc, then the surface palette is the DIB color table.
  509. *
  510. * History:
  511. * 27-Jan-1996 -by- Gilman Wong [gilmanw]
  512. * Wrote it.
  513. \**************************************************************************/
  514. static BOOL
  515. bComputeLogicalToSurfaceMap(HDC hdc, HPALETTE hpal, BYTE *pajVector)
  516. {
  517. BOOL bRet = FALSE;
  518. HPALETTE hpalSurf;
  519. ULONG cEntries, cSysEntries;
  520. DWORD dwDcType = GetObjectType(hdc);
  521. LPPALETTEENTRY lppeTmp, lppeEnd;
  522. BYTE aj[sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * 512) + (sizeof(RGBQUAD) * 256)];
  523. LOGPALETTE *ppal = (LOGPALETTE *) aj;
  524. LPPALETTEENTRY lppeSurf = &ppal->palPalEntry[0];
  525. LPPALETTEENTRY lppe = lppeSurf + 256;
  526. RGBQUAD *prgb = (RGBQUAD *) (lppe + 256);
  527. //
  528. // Determine number of colors in each palette.
  529. //
  530. cEntries = GetPaletteEntries(hpal, 0, 1, NULL);
  531. if ( dwDcType == OBJ_DC )
  532. cSysEntries = MyGetSystemPaletteEntries(hdc, 0, 1, NULL);
  533. else
  534. cSysEntries = 256;
  535. //
  536. // Get the logical palette entries.
  537. //
  538. cEntries = GetPaletteEntries(hpal, 0, cEntries, lppe);
  539. //
  540. // Get the surface palette entries.
  541. //
  542. if ( dwDcType == OBJ_DC )
  543. {
  544. cSysEntries = MyGetSystemPaletteEntries(hdc, 0, cSysEntries, lppeSurf);
  545. lppeTmp = lppeSurf;
  546. lppeEnd = lppeSurf + cSysEntries;
  547. for (; lppeTmp < lppeEnd; lppeTmp++)
  548. lppeTmp->peFlags = 0;
  549. }
  550. else
  551. {
  552. RGBQUAD *prgbTmp;
  553. //
  554. // First get RGBQUADs from DIB color table...
  555. //
  556. cSysEntries = GetDIBColorTable(hdc, 0, cSysEntries, prgb);
  557. //
  558. // ...then convert RGBQUADs into PALETTEENTRIES.
  559. //
  560. prgbTmp = prgb;
  561. lppeTmp = lppeSurf;
  562. lppeEnd = lppeSurf + cSysEntries;
  563. while ( lppeTmp < lppeEnd )
  564. {
  565. lppeTmp->peRed = prgbTmp->rgbRed;
  566. lppeTmp->peGreen = prgbTmp->rgbGreen;
  567. lppeTmp->peBlue = prgbTmp->rgbBlue;
  568. lppeTmp->peFlags = 0;
  569. lppeTmp++;
  570. prgbTmp++;
  571. }
  572. }
  573. //
  574. // Construct a translation vector by using GetNearestPaletteIndex to
  575. // map each entry in the logical palette to the surface palette.
  576. //
  577. if ( cEntries && cSysEntries )
  578. {
  579. //
  580. // Create a temporary logical palette that matches the surface
  581. // palette retrieved above.
  582. //
  583. ppal->palVersion = 0x300;
  584. ppal->palNumEntries = (USHORT) cSysEntries;
  585. if ( hpalSurf = CreatePalette(ppal) )
  586. {
  587. //
  588. // Translate each logical palette entry into a surface palette
  589. // index.
  590. //
  591. lppeTmp = lppe;
  592. lppeEnd = lppe + cEntries;
  593. for ( ; lppeTmp < lppeEnd; lppeTmp++, pajVector++)
  594. {
  595. *pajVector = (BYTE) GetNearestPaletteIndex(
  596. hpalSurf,
  597. RGB(lppeTmp->peRed,
  598. lppeTmp->peGreen,
  599. lppeTmp->peBlue)
  600. );
  601. }
  602. bRet = TRUE;
  603. DeleteObject(hpalSurf);
  604. }
  605. else
  606. {
  607. SS_DBGPRINT("bComputeLogicalToSurfaceMap: CreatePalette failed\n");
  608. }
  609. }
  610. else
  611. {
  612. SS_DBGPRINT("bComputeLogicalToSurfaceMap: failed to get pal info\n");
  613. }
  614. return bRet;
  615. }