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.

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