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.

2769 lines
77 KiB

  1. /*++
  2. Copyright (c) 1996-1999 Microsoft Corporation
  3. Module Name
  4. Abstract:
  5. Lingyun Wang
  6. Author:
  7. Enviornment:
  8. User Mode
  9. Revision History:
  10. --*/
  11. #include "precomp.hxx"
  12. #pragma hdrstop
  13. extern PFNTRANSBLT gpfnTransparentBlt;
  14. #if (_WIN32_WINNT == 0x400)
  15. typedef struct _LOGPALETTE2
  16. {
  17. USHORT PalVersion;
  18. USHORT PalNumEntries;
  19. PALETTEENTRY palPalEntry[2];
  20. } LOGPALETTE2;
  21. typedef struct _LOGPALETTE16
  22. {
  23. USHORT PalVersion;
  24. USHORT PalNumEntries;
  25. PALETTEENTRY palPalEntry[16];
  26. } LOGPALETTE16;
  27. typedef struct _LOGPALETTE256
  28. {
  29. USHORT PalVersion;
  30. USHORT PalNumEntries;
  31. PALETTEENTRY palPalEntry[256];
  32. } LOGPALETTE256;
  33. /******************************Public*Routine******************************\
  34. * StartPixel
  35. * Give a scanline pointer and position of a pixel, return the byte address
  36. * of where the pixel is at depending on the format
  37. *
  38. * History:
  39. * 2-Dec-1996 -by- Lingyun Wang [lingyunw]
  40. * Wrote it.
  41. \**************************************************************************/
  42. PBYTE StartPixel (
  43. PBYTE pjBits,
  44. ULONG xStart,
  45. ULONG iBitmapFormat
  46. )
  47. {
  48. PBYTE pjStart = pjBits;
  49. //
  50. // getting the starting pixel
  51. //
  52. switch (iBitmapFormat)
  53. {
  54. case 1:
  55. pjStart = pjBits + (xStart >> 3);
  56. break;
  57. case 4:
  58. pjStart = pjBits + (xStart >> 1);
  59. break;
  60. case 8:
  61. pjStart = pjBits + xStart;
  62. break;
  63. case 16:
  64. pjStart = pjBits + 2*xStart;
  65. break;
  66. case 24:
  67. pjStart = pjBits + 3*xStart;
  68. break;
  69. case 32:
  70. pjStart = pjBits+4*xStart;
  71. break;
  72. default:
  73. WARNING ("Startpixel -- bad iFormatSrc\n");
  74. }
  75. return (pjStart);
  76. }
  77. /******************************Public*Routine******************************\
  78. * vTransparentIdentityCopy4
  79. *
  80. * Doing a transparent copy on two same size 4BPP format DIBs
  81. *
  82. * Returns:
  83. * VOID.
  84. *
  85. * History:
  86. * 09-Dec-1996 -by- Lingyun Wang [lingyunw]
  87. * Wrote it.
  88. \**************************************************************************/
  89. VOID vTransparentIdentityCopy4 (
  90. PDIBINFO pDibInfoDst,
  91. PDIBINFO pDibInfoSrc,
  92. ULONG TransColor)
  93. {
  94. PBYTE pjDst = (PBYTE)pDibInfoDst->pvBase + pDibInfoDst->stride*pDibInfoDst->rclDIB.top
  95. + (pDibInfoDst->rclDIB.left >> 1);
  96. PBYTE pjSrc = (PBYTE)pDibInfoSrc->pvBase + pDibInfoSrc->stride*pDibInfoSrc->rclDIB.top
  97. + (pDibInfoSrc->rclDIB.left >> 1);
  98. LONG cx = pDibInfoDst->rclDIB.right - pDibInfoDst->rclDIB.left;
  99. LONG cy = pDibInfoDst->rclDIB.bottom - pDibInfoDst->rclDIB.top;
  100. PBYTE pjDstTemp;
  101. PBYTE pjSrcTemp;
  102. LONG cxTemp;
  103. BYTE jSrc=0;
  104. BYTE jDst=0;
  105. LONG iSrc, iDst;
  106. while(cy--)
  107. {
  108. cxTemp = cx;
  109. iSrc = pDibInfoSrc->rclDIB.left;
  110. iDst = pDibInfoDst->rclDIB.left;
  111. pjSrcTemp = pjSrc;
  112. pjDstTemp = pjDst;
  113. while (cxTemp--)
  114. {
  115. if (iSrc & 0x00000001)
  116. {
  117. jSrc = *pjSrcTemp & 0x0F;
  118. pjSrcTemp++;
  119. }
  120. else
  121. {
  122. jSrc = (*pjSrcTemp & 0xF0)>>4;
  123. }
  124. iSrc++;
  125. if (iDst & 0x00000001)
  126. {
  127. if (jSrc != (BYTE)TransColor)
  128. {
  129. jDst |= jSrc & 0x0F;
  130. }
  131. else
  132. {
  133. jDst |= *pjDstTemp & 0x0F;
  134. }
  135. *pjDstTemp++ = jDst;
  136. jDst = 0;
  137. }
  138. else
  139. {
  140. if (jSrc != (BYTE)TransColor)
  141. {
  142. jDst |= (jSrc << 4);
  143. }
  144. else
  145. {
  146. jDst |= *pjDstTemp & 0xF0;
  147. }
  148. }
  149. iDst++;
  150. }
  151. pjDst += pDibInfoDst->stride;
  152. pjSrc += pDibInfoSrc->stride;
  153. }
  154. }
  155. /******************************Public*Routine******************************\
  156. * vTransparentS4D1
  157. *
  158. * Doing a transparent copy from 4PP to 1BPP
  159. *
  160. * Returns:
  161. * VOID.
  162. *
  163. * History:
  164. * 09-Dec-1996 -by- Lingyun Wang [lingyunw]
  165. * Wrote it.
  166. \**************************************************************************/
  167. VOID vTransparentS4D1 (
  168. PDIBINFO pDibInfoDst,
  169. PDIBINFO pDibInfoSrc,
  170. ULONG TransColor)
  171. {
  172. PBYTE pjDst = (PBYTE)pDibInfoDst->pvBase + pDibInfoDst->stride*pDibInfoDst->rclDIB.top
  173. + (pDibInfoDst->rclDIB.left >> 3);
  174. PBYTE pjSrc = (PBYTE)pDibInfoSrc->pvBase + pDibInfoSrc->stride*pDibInfoSrc->rclDIB.top
  175. + (pDibInfoSrc->rclDIB.left >> 1);
  176. LONG cx = pDibInfoDst->rclDIB.right - pDibInfoDst->rclDIB.left;
  177. LONG cy = pDibInfoDst->rclDIB.bottom - pDibInfoDst->rclDIB.top;
  178. PBYTE pjDstTemp;
  179. PBYTE pjSrcTemp;
  180. BYTE jSrc, jDst;
  181. LONG cxTemp;
  182. BYTE rgbBlue, rgbGreen, rgbRed;
  183. LONG iSrc, iDst;
  184. LOGPALETTE2 logPal2;
  185. HPALETTE hPal;
  186. LONG i;
  187. ULONG rgbColor;
  188. BYTE xlate[16];
  189. //
  190. // build up our xlate table
  191. //
  192. logPal2.PalVersion = 0x300;
  193. logPal2.PalNumEntries = 2;
  194. for (i = 0; i < 2; i++)
  195. {
  196. logPal2.palPalEntry[i].peRed = pDibInfoDst->pbmi->bmiColors[i].rgbRed;
  197. logPal2.palPalEntry[i].peGreen = pDibInfoDst->pbmi->bmiColors[i].rgbGreen;
  198. logPal2.palPalEntry[i].peBlue = pDibInfoDst->pbmi->bmiColors[i].rgbBlue;
  199. logPal2.palPalEntry[i].peFlags = 0;
  200. }
  201. hPal = CreatePalette ((LOGPALETTE *)&logPal2);
  202. for (i = 0; i<16; i++)
  203. {
  204. rgbColor = RGB(pDibInfoSrc->pbmi->bmiColors[i].rgbRed, pDibInfoSrc->pbmi->bmiColors[i].rgbGreen,
  205. pDibInfoSrc->pbmi->bmiColors[i].rgbBlue);
  206. xlate[i] = (BYTE)GetNearestPaletteIndex(hPal, rgbColor);
  207. }
  208. if (hPal)
  209. {
  210. DeleteObject(hPal);
  211. }
  212. while(cy--)
  213. {
  214. cxTemp = cx;
  215. iSrc = pDibInfoSrc->rclDIB.left;
  216. iDst = pDibInfoDst->rclDIB.left & 0x07;
  217. pjDstTemp = pjDst;
  218. jDst = *pjDstTemp >> (8 - iDst);
  219. pjSrcTemp = pjSrc;
  220. while (cxTemp--)
  221. {
  222. if (iSrc & 0x00000001)
  223. {
  224. jSrc = *pjSrcTemp & 0x0F;
  225. pjSrcTemp++;
  226. }
  227. else
  228. {
  229. jSrc = (*pjSrcTemp & 0xF0)>>4;
  230. }
  231. iSrc++;
  232. //
  233. // put one pixel in the dest
  234. //
  235. if (jSrc != TransColor)
  236. {
  237. jDst |= xlate[jSrc]; //0 OR 1
  238. }
  239. else
  240. {
  241. jDst |= 1-xlate[jSrc];
  242. }
  243. jDst = jDst << 1;
  244. iDst++;
  245. if (!(iDst & 0x07))
  246. {
  247. *(pjDstTemp++) = jDst;
  248. jDst = 0;
  249. }
  250. }
  251. if (iDst & 0x00000007)
  252. {
  253. // We need to build up the last pel correctly.
  254. BYTE jMask = (BYTE) (0x000000FF >> (iDst & 0x00000007));
  255. jDst = (BYTE) (jDst << (8 - (iDst & 0x00000007)));
  256. *pjDstTemp = (BYTE) ((*pjDstTemp & jMask) | (jDst & ~jMask));
  257. }
  258. pjDst += pDibInfoDst->stride;
  259. pjSrc += pDibInfoSrc->stride;
  260. }
  261. }
  262. /******************************Public*Routine******************************\
  263. * vTransparentS4D4
  264. *
  265. * Doing a transparent copy from 4PP to 4bpp non identity
  266. *
  267. * Returns:
  268. * VOID.
  269. *
  270. * History:
  271. * 09-Dec-1996 -by- Lingyun Wang [lingyunw]
  272. * Wrote it.
  273. \**************************************************************************/
  274. VOID vTransparentS4D4 (
  275. PDIBINFO pDibInfoDst,
  276. PDIBINFO pDibInfoSrc,
  277. ULONG TransColor)
  278. {
  279. PBYTE pjDst = (PBYTE)pDibInfoDst->pvBase + pDibInfoDst->stride*pDibInfoDst->rclDIB.top
  280. + (pDibInfoDst->rclDIB.left >> 1);
  281. PBYTE pjSrc = (PBYTE)pDibInfoSrc->pvBase + pDibInfoSrc->stride*pDibInfoSrc->rclDIB.top
  282. + (pDibInfoSrc->rclDIB.left >> 1);
  283. LONG cx = pDibInfoDst->rclDIB.right - pDibInfoDst->rclDIB.left;
  284. LONG cy = pDibInfoDst->rclDIB.bottom - pDibInfoDst->rclDIB.top;
  285. PBYTE pjDstTemp;
  286. PBYTE pjSrcTemp;
  287. BYTE jSrc, jDst;
  288. BYTE rgbBlue, rgbGreen, rgbRed;
  289. LONG iSrc, iDst;
  290. LOGPALETTE16 logPal16;
  291. HPALETTE hPal;
  292. LONG i;
  293. ULONG cxTemp;
  294. ULONG rgbColor;
  295. BYTE xlate[16];
  296. //
  297. // build up translate table
  298. //
  299. logPal16.PalVersion = 0x300;
  300. logPal16.PalNumEntries = 16;
  301. for (i = 0; i < 16; i++)
  302. {
  303. logPal16.palPalEntry[i].peRed = pDibInfoDst->pbmi->bmiColors[i].rgbRed;
  304. logPal16.palPalEntry[i].peGreen = pDibInfoDst->pbmi->bmiColors[i].rgbGreen;
  305. logPal16.palPalEntry[i].peBlue = pDibInfoDst->pbmi->bmiColors[i].rgbBlue;
  306. logPal16.palPalEntry[i].peFlags = 0;
  307. }
  308. hPal = CreatePalette ((LOGPALETTE *)&logPal16);
  309. for (i = 0; i<16; i++)
  310. {
  311. rgbColor = RGB(pDibInfoSrc->pbmi->bmiColors[i].rgbRed, pDibInfoSrc->pbmi->bmiColors[i].rgbGreen,
  312. pDibInfoSrc->pbmi->bmiColors[i].rgbBlue);
  313. xlate[i] = (BYTE)GetNearestPaletteIndex(hPal, rgbColor);
  314. }
  315. if (hPal)
  316. {
  317. DeleteObject(hPal);
  318. }
  319. while(cy--)
  320. {
  321. cxTemp = cx;
  322. iSrc = pDibInfoSrc->rclDIB.left;
  323. iDst = pDibInfoDst->rclDIB.left;
  324. pjDstTemp = pjDst;
  325. pjSrcTemp = pjSrc;
  326. while (cxTemp--)
  327. {
  328. if (iSrc & 0x00000001)
  329. {
  330. jSrc = *pjSrcTemp & 0x0F;
  331. pjSrcTemp++;
  332. }
  333. else
  334. {
  335. jSrc = (*pjSrcTemp & 0xF0)>>4;
  336. }
  337. iSrc++;
  338. if (iDst & 0x00000001)
  339. {
  340. if (jSrc != (BYTE)TransColor)
  341. {
  342. jDst |= xlate[jSrc] & 0x0F;
  343. }
  344. else
  345. {
  346. jDst |= *pjDstTemp & 0x0F;
  347. }
  348. *pjDstTemp++ = jDst;
  349. jDst = 0;
  350. }
  351. else
  352. {
  353. if (jSrc != (BYTE)TransColor)
  354. {
  355. jDst |= (xlate[jSrc] << 4);
  356. }
  357. else
  358. {
  359. jDst |= *pjDstTemp & 0xF0;
  360. }
  361. }
  362. iDst++;
  363. }
  364. pjDst += pDibInfoDst->stride;
  365. pjSrc += pDibInfoSrc->stride;
  366. }
  367. }
  368. /******************************Public*Routine******************************\
  369. * vTransparentS4D8
  370. *
  371. * Doing a transparent copy from 4PP to 8bpp
  372. *
  373. * Returns:
  374. * VOID.
  375. *
  376. * History:
  377. * 09-Dec-1996 -by- Lingyun Wang [lingyunw]
  378. * Wrote it.
  379. \**************************************************************************/
  380. VOID vTransparentS4D8 (
  381. PDIBINFO pDibInfoDst,
  382. PDIBINFO pDibInfoSrc,
  383. ULONG TransColor)
  384. {
  385. PBYTE pjDst = (PBYTE)pDibInfoDst->pvBase + pDibInfoDst->stride*pDibInfoDst->rclDIB.top;
  386. + pDibInfoDst->rclDIB.left;
  387. PBYTE pjSrc = (PBYTE)pDibInfoSrc->pvBase + pDibInfoSrc->stride*pDibInfoSrc->rclDIB.top
  388. + (pDibInfoSrc->rclDIB.left >> 1);
  389. LONG cx = pDibInfoDst->rclDIB.right - pDibInfoDst->rclDIB.left;
  390. LONG cy = pDibInfoDst->rclDIB.bottom - pDibInfoDst->rclDIB.top;
  391. PBYTE pjDstTemp;
  392. PBYTE pjSrcTemp;
  393. BYTE jSrc;
  394. LONG cxTemp;
  395. BYTE rgbBlue, rgbGreen, rgbRed;
  396. LONG iSrc;
  397. LOGPALETTE256 logPal256;
  398. HPALETTE hPal;
  399. LONG i;
  400. ULONG rgbColor;
  401. BYTE xlate[16];
  402. logPal256.PalVersion = 0x300;
  403. logPal256.PalNumEntries = 256;
  404. for (i = 0; i < 256; i++)
  405. {
  406. logPal256.palPalEntry[i].peRed = pDibInfoDst->pbmi->bmiColors[i].rgbRed;
  407. logPal256.palPalEntry[i].peGreen = pDibInfoDst->pbmi->bmiColors[i].rgbGreen;
  408. logPal256.palPalEntry[i].peBlue = pDibInfoDst->pbmi->bmiColors[i].rgbBlue;
  409. logPal256.palPalEntry[i].peFlags = 0;
  410. }
  411. hPal = CreatePalette ((LOGPALETTE *)&logPal256);
  412. for (i = 0; i<16; i++)
  413. {
  414. rgbColor = RGB(pDibInfoSrc->pbmi->bmiColors[i].rgbRed, pDibInfoSrc->pbmi->bmiColors[i].rgbGreen,
  415. pDibInfoSrc->pbmi->bmiColors[i].rgbBlue);
  416. xlate[i] = (BYTE)GetNearestPaletteIndex(hPal, rgbColor);
  417. //Dprintf("i=%x, rgbColor = 0x%08x, xlate[i] = %x", i, rgbColor, xlate[i]);
  418. }
  419. if (hPal)
  420. {
  421. DeleteObject(hPal);
  422. }
  423. while(cy--)
  424. {
  425. cxTemp = cx;
  426. iSrc = pDibInfoSrc->rclDIB.left;
  427. pjDstTemp = pjDst;
  428. pjSrcTemp = pjSrc;
  429. while (cxTemp--)
  430. {
  431. if (iSrc & 0x00000001)
  432. {
  433. jSrc = *pjSrcTemp & 0x0F;
  434. pjSrcTemp++;
  435. }
  436. else
  437. {
  438. jSrc = (*pjSrcTemp & 0xF0)>>4;
  439. }
  440. iSrc++;
  441. if (jSrc != (BYTE)TransColor)
  442. {
  443. *pjDstTemp = xlate[jSrc];
  444. }
  445. pjDstTemp++;
  446. }
  447. pjDst += pDibInfoDst->stride;
  448. pjSrc += pDibInfoSrc->stride;
  449. }
  450. }
  451. /******************************Public*Routine******************************\
  452. * vTransparentS4D16
  453. *
  454. * Doing a transparent copy from 4BPP to 16BPP
  455. *
  456. * Returns:
  457. * VOID.
  458. *
  459. * History:
  460. * 09-Dec-1996 -by- Lingyun Wang [lingyunw]
  461. * Wrote it.
  462. \**************************************************************************/
  463. VOID vTransparentS4D16 (
  464. PDIBINFO pDibInfoDst,
  465. PDIBINFO pDibInfoSrc,
  466. ULONG TransColor)
  467. {
  468. PBYTE pjDst = (PBYTE)pDibInfoDst->pvBase + pDibInfoDst->stride*pDibInfoDst->rclDIB.top
  469. + pDibInfoDst->rclDIB.left*2;
  470. PBYTE pjSrc = (PBYTE)pDibInfoSrc->pvBase + pDibInfoSrc->stride*pDibInfoSrc->rclDIB.top
  471. + (pDibInfoSrc->rclDIB.left >> 1);
  472. LONG cx = pDibInfoDst->rclDIB.right - pDibInfoDst->rclDIB.left;
  473. LONG cy = pDibInfoDst->rclDIB.bottom - pDibInfoDst->rclDIB.top;
  474. PBYTE pjDstTemp;
  475. PBYTE pjSrcTemp;
  476. BYTE jSrc;
  477. LONG cxTemp;
  478. BYTE rgbBlue, rgbGreen, rgbRed;
  479. LONG iSrc, iDst;
  480. while(cy--)
  481. {
  482. cxTemp = cx;
  483. iSrc = pDibInfoSrc->rclDIB.left;
  484. iDst = pDibInfoDst->rclDIB.left;
  485. pjDstTemp = pjDst;
  486. pjSrcTemp = pjSrc;
  487. while (cxTemp--)
  488. {
  489. if (iSrc & 0x00000001)
  490. {
  491. jSrc = *pjSrcTemp & 0x0F;
  492. pjSrcTemp++;
  493. }
  494. else
  495. {
  496. jSrc = (*pjSrcTemp & 0xF0)>>4;
  497. }
  498. iSrc++;
  499. if (jSrc != (BYTE)TransColor)
  500. {
  501. rgbBlue = pDibInfoSrc->pbmi->bmiColors[jSrc].rgbBlue;
  502. rgbGreen = pDibInfoSrc->pbmi->bmiColors[jSrc].rgbGreen;
  503. rgbRed = pDibInfoSrc->pbmi->bmiColors[jSrc].rgbRed;
  504. //
  505. // figure out 5-5-5 or 5-6-5
  506. //
  507. if (pDibInfoDst->pbmi->bmiHeader.biCompression == BI_BITFIELDS)
  508. {
  509. //5-5-5
  510. if (*(DWORD *)&pDibInfoDst->pbmi->bmiColors[1] == 0x03E0)
  511. {
  512. *(PUSHORT)pjDstTemp = (USHORT)rgbBlue >> 3;
  513. *(PUSHORT)pjDstTemp |= (USHORT)(rgbGreen >> 3) << 5;
  514. *(PUSHORT)pjDstTemp |= (USHORT)(rgbRed >> 3) << 10;
  515. }
  516. // 5-6-5
  517. else if (*(DWORD *)&pDibInfoDst->pbmi->bmiColors[1] == 0x07E0)
  518. {
  519. *(PUSHORT)pjDstTemp = (USHORT)rgbBlue >> 3;
  520. *(PUSHORT)pjDstTemp |= (USHORT)(rgbGreen >> 2) << 5;
  521. *(PUSHORT)pjDstTemp |= (USHORT)(rgbRed >> 3) << 11;
  522. }
  523. else
  524. {
  525. WARNING ("unsupported BITFIELDS\n");
  526. }
  527. }
  528. else
  529. {
  530. *(PUSHORT)pjDstTemp = (USHORT)rgbBlue >> 3;
  531. *(PUSHORT)pjDstTemp |= (USHORT)(rgbGreen >> 3) << 5;
  532. *(PUSHORT)pjDstTemp |= (USHORT)(rgbRed >> 3) << 10;
  533. }
  534. }
  535. pjDstTemp += 2;
  536. }
  537. pjDst += pDibInfoDst->stride;
  538. pjSrc += pDibInfoSrc->stride;
  539. }
  540. }
  541. /******************************Public*Routine******************************\
  542. * vTransparentS4D24
  543. *
  544. * Doing a transparent copy from 4BPP to 24BPP
  545. *
  546. * Returns:
  547. * VOID.
  548. *
  549. * History:
  550. * 09-Dec-1996 -by- Lingyun Wang [lingyunw]
  551. * Wrote it.
  552. \**************************************************************************/
  553. VOID vTransparentS4D24 (
  554. PDIBINFO pDibInfoDst,
  555. PDIBINFO pDibInfoSrc,
  556. ULONG TransColor)
  557. {
  558. PBYTE pjDst = (PBYTE)pDibInfoDst->pvBase + pDibInfoDst->stride*pDibInfoDst->rclDIB.top
  559. + pDibInfoDst->rclDIB.left*3;
  560. PBYTE pjSrc = (PBYTE)pDibInfoSrc->pvBase + pDibInfoSrc->stride*pDibInfoSrc->rclDIB.top
  561. + (pDibInfoSrc->rclDIB.left >> 1);
  562. LONG cx = pDibInfoDst->rclDIB.right - pDibInfoDst->rclDIB.left;
  563. LONG cy = pDibInfoDst->rclDIB.bottom - pDibInfoDst->rclDIB.top;
  564. PBYTE pjDstTemp;
  565. PBYTE pjSrcTemp;
  566. LONG cxTemp;
  567. BYTE jSrc;
  568. LONG iSrc, iDst;
  569. BYTE rgbBlue, rgbGreen, rgbRed;
  570. while(cy--)
  571. {
  572. cxTemp = cx;
  573. pjDstTemp = pjDst;
  574. pjSrcTemp = pjSrc;
  575. iSrc = pDibInfoSrc->rclDIB.left;
  576. iDst = pDibInfoDst->rclDIB.left;
  577. while (cxTemp--)
  578. {
  579. if (iSrc & 0x00000001)
  580. {
  581. jSrc = *pjSrcTemp & 0x0F;
  582. pjSrcTemp++;
  583. }
  584. else
  585. {
  586. jSrc = (*pjSrcTemp & 0xF0)>>4;
  587. }
  588. iSrc++;
  589. if (jSrc != (BYTE)TransColor)
  590. {
  591. rgbBlue = pDibInfoSrc->pbmi->bmiColors[jSrc].rgbBlue;
  592. rgbGreen = pDibInfoSrc->pbmi->bmiColors[jSrc].rgbGreen;
  593. rgbRed = pDibInfoSrc->pbmi->bmiColors[jSrc].rgbRed;
  594. *(pjDstTemp++) = (BYTE) rgbBlue;
  595. *(pjDstTemp++) = (BYTE) rgbGreen;
  596. *(pjDstTemp++) = (BYTE) rgbRed;
  597. }
  598. else
  599. {
  600. pjDstTemp += 3;
  601. }
  602. }
  603. pjDst += pDibInfoDst->stride;
  604. pjSrc += pDibInfoSrc->stride;
  605. }
  606. }
  607. /******************************Public*Routine******************************\
  608. * vTransparentS4D32
  609. *
  610. * Doing a transparent copy from 4BPP to 32BPP
  611. *
  612. * Returns:
  613. * VOID.
  614. *
  615. * History:
  616. * 09-Dec-1996 -by- Lingyun Wang [lingyunw]
  617. * Wrote it.
  618. \**************************************************************************/
  619. VOID vTransparentS4D32 (
  620. PDIBINFO pDibInfoDst,
  621. PDIBINFO pDibInfoSrc,
  622. ULONG TransColor)
  623. {
  624. PBYTE pjDst = (PBYTE)pDibInfoDst->pvBase + pDibInfoDst->stride*pDibInfoDst->rclDIB.top
  625. + pDibInfoDst->rclDIB.left*4;
  626. PBYTE pjSrc = (PBYTE)pDibInfoSrc->pvBase + pDibInfoSrc->stride*pDibInfoSrc->rclDIB.top
  627. + (pDibInfoSrc->rclDIB.left >> 1);
  628. LONG cx = pDibInfoDst->rclDIB.right - pDibInfoDst->rclDIB.left;
  629. LONG cy = pDibInfoDst->rclDIB.bottom - pDibInfoDst->rclDIB.top;
  630. PBYTE pjDstTemp;
  631. PBYTE pjSrcTemp;
  632. LONG cxTemp;
  633. BYTE jSrc;
  634. LONG iSrc, iDst;
  635. BYTE rgbBlue, rgbGreen, rgbRed;
  636. while(cy--)
  637. {
  638. cxTemp = cx;
  639. pjDstTemp = pjDst;
  640. pjSrcTemp = pjSrc;
  641. iSrc = pDibInfoSrc->rclDIB.left;
  642. iDst = pDibInfoDst->rclDIB.left;
  643. while (cxTemp--)
  644. {
  645. if (iSrc & 0x00000001)
  646. {
  647. jSrc = *pjSrcTemp & 0x0F;
  648. pjSrcTemp++;
  649. }
  650. else
  651. {
  652. jSrc = (*pjSrcTemp & 0xF0)>>4;
  653. }
  654. iSrc++;
  655. if (jSrc != (BYTE)TransColor)
  656. {
  657. rgbBlue = pDibInfoSrc->pbmi->bmiColors[jSrc].rgbBlue;
  658. rgbGreen = pDibInfoSrc->pbmi->bmiColors[jSrc].rgbGreen;
  659. rgbRed = pDibInfoSrc->pbmi->bmiColors[jSrc].rgbRed;
  660. *(PULONG)pjDstTemp = (DWORD) (rgbBlue | (WORD)rgbGreen << 8 | (DWORD)rgbRed << 16);
  661. }
  662. pjDstTemp += 4;
  663. }
  664. pjDst += pDibInfoDst->stride;
  665. pjSrc += pDibInfoSrc->stride;
  666. }
  667. }
  668. /******************************Public*Routine******************************\
  669. * vTransparentS8D16
  670. *
  671. * Doing a transparent copy from 8BPP to 16BPP
  672. *
  673. * Returns:
  674. * VOID.
  675. *
  676. * History:
  677. * 09-Dec-1996 -by- Lingyun Wang [lingyunw]
  678. * Wrote it.
  679. \**************************************************************************/
  680. VOID vTransparentS8D16 (
  681. PDIBINFO pDibInfoDst,
  682. PDIBINFO pDibInfoSrc,
  683. ULONG TransColor)
  684. {
  685. PBYTE pjDst = (PBYTE)pDibInfoDst->pvBase + pDibInfoDst->stride*pDibInfoDst->rclDIB.top
  686. + pDibInfoDst->rclDIB.left*2;
  687. PBYTE pjSrc = (PBYTE)pDibInfoSrc->pvBase + pDibInfoSrc->stride*pDibInfoSrc->rclDIB.top
  688. + pDibInfoSrc->rclDIB.left;
  689. LONG cx = pDibInfoDst->rclDIB.right - pDibInfoDst->rclDIB.left;
  690. LONG cy = pDibInfoDst->rclDIB.bottom - pDibInfoDst->rclDIB.top;
  691. PBYTE pjDstTemp;
  692. PBYTE pjSrcTemp;
  693. BYTE jSrc;
  694. LONG cxTemp;
  695. BYTE rgbBlue, rgbGreen, rgbRed;
  696. while(cy--)
  697. {
  698. cxTemp = cx;
  699. pjDstTemp = pjDst;
  700. pjSrcTemp = pjSrc;
  701. while (cxTemp--)
  702. {
  703. jSrc = *pjSrcTemp++;
  704. //
  705. // put one pixel in the dest
  706. //
  707. if (jSrc != (BYTE)TransColor)
  708. {
  709. rgbBlue = pDibInfoSrc->pbmi->bmiColors[jSrc].rgbBlue;
  710. rgbGreen = pDibInfoSrc->pbmi->bmiColors[jSrc].rgbGreen;
  711. rgbRed = pDibInfoSrc->pbmi->bmiColors[jSrc].rgbRed;
  712. //
  713. // figure out 5-5-5 or 5-6-5
  714. //
  715. if (pDibInfoDst->pbmi->bmiHeader.biCompression == BI_BITFIELDS)
  716. {
  717. //5-5-5
  718. if (*(DWORD *)&pDibInfoDst->pbmi->bmiColors[1] == 0x03E0)
  719. {
  720. *(PUSHORT)pjDstTemp = (USHORT)rgbBlue >> 3;
  721. *(PUSHORT)pjDstTemp |= (USHORT)(rgbGreen >> 3) << 5;
  722. *(PUSHORT)pjDstTemp |= (USHORT)(rgbRed >> 3) << 10;
  723. }
  724. // 5-6-5
  725. else if (*(DWORD *)&pDibInfoDst->pbmi->bmiColors[1] == 0x07E0)
  726. {
  727. *(PUSHORT)pjDstTemp = (USHORT)rgbBlue >> 3;
  728. *(PUSHORT)pjDstTemp |= (USHORT)(rgbGreen >> 2) << 5;
  729. *(PUSHORT)pjDstTemp |= (USHORT)(rgbRed >> 3) << 11;
  730. }
  731. else
  732. {
  733. WARNING ("unsupported BITFIELDS\n");
  734. }
  735. }
  736. else
  737. {
  738. *(PUSHORT)pjDstTemp = (USHORT)rgbBlue >> 3;
  739. *(PUSHORT)pjDstTemp |= (USHORT)(rgbGreen >> 3) << 5;
  740. *(PUSHORT)pjDstTemp |= (USHORT)(rgbRed >> 3) << 10;
  741. }
  742. }
  743. pjDstTemp += 2;
  744. }
  745. pjDst += pDibInfoDst->stride;
  746. pjSrc += pDibInfoSrc->stride;
  747. }
  748. }
  749. /******************************Public*Routine******************************\
  750. * vTransparentS8D24
  751. *
  752. * Doing a transparent copy from 8BPP to 16BPP
  753. *
  754. * Returns:
  755. * VOID.
  756. *
  757. * History:
  758. * 09-Dec-1996 -by- Lingyun Wang [lingyunw]
  759. * Wrote it.
  760. \**************************************************************************/
  761. VOID vTransparentS8D24 (
  762. PDIBINFO pDibInfoDst,
  763. PDIBINFO pDibInfoSrc,
  764. ULONG TransColor)
  765. {
  766. PBYTE pjDst = (PBYTE)pDibInfoDst->pvBase + pDibInfoDst->stride*pDibInfoDst->rclDIB.top
  767. + pDibInfoDst->rclDIB.left*3;
  768. PBYTE pjSrc = (PBYTE)pDibInfoSrc->pvBase + pDibInfoSrc->stride*pDibInfoSrc->rclDIB.top
  769. + pDibInfoSrc->rclDIB.left;
  770. LONG cx = pDibInfoDst->rclDIB.right - pDibInfoDst->rclDIB.left;
  771. LONG cy = pDibInfoDst->rclDIB.bottom - pDibInfoDst->rclDIB.top;
  772. PBYTE pjDstTemp;
  773. PBYTE pjSrcTemp;
  774. BYTE jSrc;
  775. LONG cxTemp;
  776. BYTE rgbBlue, rgbGreen, rgbRed;
  777. while(cy--)
  778. {
  779. cxTemp = cx;
  780. pjDstTemp = pjDst;
  781. pjSrcTemp = pjSrc;
  782. while (cxTemp--)
  783. {
  784. jSrc = *pjSrcTemp++;
  785. if (jSrc != (BYTE)TransColor)
  786. {
  787. rgbBlue = pDibInfoSrc->pbmi->bmiColors[jSrc].rgbBlue;
  788. rgbGreen = pDibInfoSrc->pbmi->bmiColors[jSrc].rgbGreen;
  789. rgbRed = pDibInfoSrc->pbmi->bmiColors[jSrc].rgbRed;
  790. *(pjDstTemp++) = (BYTE) rgbBlue;
  791. *(pjDstTemp++) = (BYTE) rgbGreen;
  792. *(pjDstTemp++) = (BYTE) rgbRed;
  793. }
  794. else
  795. {
  796. pjDstTemp += 3;
  797. }
  798. }
  799. pjDst += pDibInfoDst->stride;
  800. pjSrc += pDibInfoSrc->stride;
  801. }
  802. }
  803. /******************************Public*Routine******************************\
  804. * vTransparentS8D32
  805. *
  806. * Doing a transparent copy from 8BPP to 32BPP
  807. *
  808. * Returns:
  809. * VOID.
  810. *
  811. * History:
  812. * 09-Dec-1996 -by- Lingyun Wang [lingyunw]
  813. * Wrote it.
  814. \**************************************************************************/
  815. VOID vTransparentS8D32 (
  816. PDIBINFO pDibInfoDst,
  817. PDIBINFO pDibInfoSrc,
  818. ULONG TransColor)
  819. {
  820. PBYTE pjDst = (PBYTE)pDibInfoDst->pvBase + pDibInfoDst->stride*pDibInfoDst->rclDIB.top
  821. + pDibInfoDst->rclDIB.left*4;
  822. PBYTE pjSrc = (PBYTE)pDibInfoSrc->pvBase + pDibInfoSrc->stride*pDibInfoSrc->rclDIB.top
  823. + pDibInfoSrc->rclDIB.left;
  824. LONG cx = pDibInfoDst->rclDIB.right - pDibInfoDst->rclDIB.left;
  825. LONG cy = pDibInfoDst->rclDIB.bottom - pDibInfoDst->rclDIB.top;
  826. PBYTE pjDstTemp;
  827. PBYTE pjSrcTemp;
  828. BYTE jSrc;
  829. LONG cxTemp;
  830. BYTE rgbBlue, rgbGreen, rgbRed;
  831. while(cy--)
  832. {
  833. cxTemp = cx;
  834. pjDstTemp = pjDst;
  835. pjSrcTemp = pjSrc;
  836. while (cxTemp--)
  837. {
  838. jSrc = *pjSrcTemp++;
  839. if (jSrc != (BYTE)TransColor)
  840. {
  841. rgbBlue = pDibInfoSrc->pbmi->bmiColors[jSrc].rgbBlue;
  842. rgbGreen = pDibInfoSrc->pbmi->bmiColors[jSrc].rgbGreen;
  843. rgbRed = pDibInfoSrc->pbmi->bmiColors[jSrc].rgbRed;
  844. *(PULONG)pjDstTemp = (DWORD) (rgbBlue | (WORD)rgbGreen << 8 | (DWORD)rgbRed << 16);
  845. }
  846. pjDstTemp += 4;
  847. }
  848. pjDst += pDibInfoDst->stride;
  849. pjSrc += pDibInfoSrc->stride;
  850. }
  851. }
  852. /******************************Public*Routine******************************\
  853. * vTransparentS8D1
  854. *
  855. * Doing a transparent copy from 8BPP to other 1,16,24,32bpp format DIBs
  856. *
  857. * Returns:
  858. * VOID.
  859. *
  860. * History:
  861. * 09-Dec-1996 -by- Lingyun Wang [lingyunw]
  862. * Wrote it.
  863. \**************************************************************************/
  864. VOID vTransparentS8D1 (
  865. PDIBINFO pDibInfoDst,
  866. PDIBINFO pDibInfoSrc,
  867. ULONG TransColor)
  868. {
  869. PBYTE pjDst = (PBYTE)pDibInfoDst->pvBase + pDibInfoDst->stride*pDibInfoDst->rclDIB.top;
  870. pjDst = StartPixel (pjDst, pDibInfoDst->rclDIB.left, pDibInfoDst->pbmi->bmiHeader.biBitCount);
  871. PBYTE pjSrc = (PBYTE)pDibInfoSrc->pvBase + pDibInfoSrc->stride*pDibInfoSrc->rclDIB.top
  872. + pDibInfoSrc->rclDIB.left;
  873. LONG cx = pDibInfoDst->rclDIB.right - pDibInfoDst->rclDIB.left;
  874. LONG cy = pDibInfoDst->rclDIB.bottom - pDibInfoDst->rclDIB.top;
  875. PBYTE pjDstTemp;
  876. PBYTE pjSrcTemp;
  877. BYTE jSrc;
  878. LONG cxTemp;
  879. HDC hdc;
  880. HBITMAP hbm;
  881. ULONG ulWidthDst, ulHeightDst, ulWidthSrc, ulHeightSrc;
  882. BYTE pByte[32];
  883. INT i, j;
  884. BYTE pByteSrc[256];
  885. LONG iDst;
  886. BYTE jDst;
  887. //
  888. // build the color translation table
  889. //
  890. hdc = CreateCompatibleDC (pDibInfoDst->hdc);
  891. //
  892. // save the original width/height
  893. //
  894. ulWidthDst = pDibInfoDst->pbmi->bmiHeader.biWidth;
  895. ulHeightDst = pDibInfoDst->pbmi->bmiHeader.biHeight;
  896. pDibInfoDst->pbmi->bmiHeader.biWidth = 256;
  897. pDibInfoDst->pbmi->bmiHeader.biHeight = 1;
  898. //
  899. // Create a 256X1 DIB
  900. //
  901. hbm = CreateDIBSection(hdc, (PBITMAPINFO)pDibInfoDst->pbmi, DIB_RGB_COLORS, (PVOID *)&pByte, NULL, 0);
  902. if (!hdc || !hbm)
  903. {
  904. //
  905. // It's bad to fail and return here without a return value, but it's better
  906. // than crashing later when accessing pByte. At some point it would be nice
  907. // to change the vTansparentxxxx functions to return success/failure.
  908. //
  909. if (hdc)
  910. {
  911. DeleteDC(hdc);
  912. }
  913. if (hbm)
  914. {
  915. DeleteObject(hbm);
  916. }
  917. pDibInfoDst->pbmi->bmiHeader.biWidth = ulWidthDst;
  918. pDibInfoDst->pbmi->bmiHeader.biHeight = ulHeightDst;
  919. WARNING ("failed to create hdc or hbm\n");
  920. return;
  921. }
  922. SelectObject (hdc, hbm);
  923. for (i = 0; i < 256; i++)
  924. {
  925. pByteSrc[i] = (unsigned char)i;
  926. }
  927. ulWidthSrc = pDibInfoSrc->pbmi->bmiHeader.biWidth;
  928. ulHeightSrc = pDibInfoSrc->pbmi->bmiHeader.biHeight;
  929. pDibInfoSrc->pbmi->bmiHeader.biWidth = 256;
  930. pDibInfoSrc->pbmi->bmiHeader.biHeight = 1;
  931. SetDIBits(hdc, hbm, 0, 1, pByteSrc, (PBITMAPINFO)pDibInfoSrc->pbmi,pDibInfoSrc->iUsage);
  932. //
  933. // retore bitmap width/height
  934. //
  935. pDibInfoSrc->pbmi->bmiHeader.biWidth = ulWidthSrc;
  936. pDibInfoSrc->pbmi->bmiHeader.biHeight = ulHeightSrc;
  937. pDibInfoDst->pbmi->bmiHeader.biWidth = ulWidthDst;
  938. pDibInfoDst->pbmi->bmiHeader.biHeight = ulHeightDst;
  939. //
  940. // now pByte contains all the 256 color mappings, just need to split them up
  941. //
  942. BYTE bTmp = 0;
  943. while(cy--)
  944. {
  945. cxTemp = cx;
  946. pjDstTemp = pjDst;
  947. pjSrcTemp = pjSrc;
  948. iDst = pDibInfoDst->rclDIB.left & 0x07;
  949. jDst = *pjDstTemp >> (7 - iDst);
  950. while (cxTemp--)
  951. {
  952. jSrc = *pjSrcTemp++;
  953. //
  954. // put one pixel in the dest
  955. //
  956. bTmp = pByte[jSrc >> 3];
  957. bTmp >>= 7 - (jSrc & 0x07);
  958. if (jSrc != TransColor)
  959. {
  960. jDst |= bTmp;
  961. }
  962. else
  963. {
  964. jDst |= 1-bTmp;
  965. }
  966. jDst <<= 1;
  967. iDst++;
  968. if (!(iDst & 0x07))
  969. {
  970. *(pjDstTemp++) = jDst;
  971. jDst = 0;
  972. }
  973. }
  974. pjDst += pDibInfoDst->stride;
  975. pjSrc += pDibInfoSrc->stride;
  976. }
  977. DeleteDC(hdc);
  978. DeleteObject(hbm);
  979. }
  980. /******************************Public*Routine******************************\
  981. * vTransparentS8D4
  982. *
  983. * Doing a transparent copy from 8BPP to other 1,16,24,32bpp format DIBs
  984. *
  985. * Returns:
  986. * VOID.
  987. *
  988. * History:
  989. * 09-Dec-1996 -by- Lingyun Wang [lingyunw]
  990. * Wrote it.
  991. \**************************************************************************/
  992. VOID vTransparentS8D4 (
  993. PDIBINFO pDibInfoDst,
  994. PDIBINFO pDibInfoSrc,
  995. ULONG TransColor)
  996. {
  997. PBYTE pjDst = (PBYTE)pDibInfoDst->pvBase + pDibInfoDst->stride*pDibInfoDst->rclDIB.top;
  998. pjDst = StartPixel (pjDst, pDibInfoDst->rclDIB.left, pDibInfoDst->pbmi->bmiHeader.biBitCount);
  999. PBYTE pjSrc = (PBYTE)pDibInfoSrc->pvBase + pDibInfoSrc->stride*pDibInfoSrc->rclDIB.top
  1000. + pDibInfoSrc->rclDIB.left;
  1001. LONG cx = pDibInfoDst->rclDIB.right - pDibInfoDst->rclDIB.left;
  1002. LONG cy = pDibInfoDst->rclDIB.bottom - pDibInfoDst->rclDIB.top;
  1003. PBYTE pjDstTemp;
  1004. PBYTE pjSrcTemp;
  1005. BYTE jSrc;
  1006. LONG cxTemp;
  1007. HDC hdc;
  1008. HBITMAP hbm;
  1009. ULONG ulWidthDst, ulHeightDst, ulWidthSrc, ulHeightSrc;
  1010. BYTE pByte[128];
  1011. INT i, j;
  1012. BYTE xlate[256];
  1013. BYTE pByteSrc[256];
  1014. LONG iDst;
  1015. //
  1016. // build the color translation table
  1017. //
  1018. hdc = CreateCompatibleDC (pDibInfoDst->hdc);
  1019. //
  1020. // save the original width/height
  1021. //
  1022. ulWidthDst = pDibInfoDst->pbmi->bmiHeader.biWidth;
  1023. ulHeightDst = pDibInfoDst->pbmi->bmiHeader.biHeight;
  1024. pDibInfoDst->pbmi->bmiHeader.biWidth = 256;
  1025. pDibInfoDst->pbmi->bmiHeader.biHeight = 1;
  1026. //
  1027. // Create a 256X1 DIB
  1028. //
  1029. hbm = CreateDIBSection(hdc, (PBITMAPINFO)pDibInfoDst->pbmi, DIB_RGB_COLORS, (PVOID *)&pByte, NULL, 0);
  1030. if (!hdc || !hbm)
  1031. {
  1032. //
  1033. // It's bad to fail and return here without a return value, but it's better
  1034. // than crashing later when accessing pByte. At some point it would be nice
  1035. // to change the vTansparentxxxx functions to return success/failure.
  1036. //
  1037. if (hdc)
  1038. {
  1039. DeleteDC(hdc);
  1040. }
  1041. if (hbm)
  1042. {
  1043. DeleteObject(hbm);
  1044. }
  1045. pDibInfoDst->pbmi->bmiHeader.biWidth = ulWidthDst;
  1046. pDibInfoDst->pbmi->bmiHeader.biHeight = ulHeightDst;
  1047. WARNING ("failed to create hdc or hbm\n");
  1048. return;
  1049. }
  1050. SelectObject (hdc, hbm);
  1051. for (i = 0; i < 256; i++)
  1052. {
  1053. pByteSrc[i] = (unsigned char)i;
  1054. }
  1055. ulWidthSrc = pDibInfoSrc->pbmi->bmiHeader.biWidth;
  1056. ulHeightSrc = pDibInfoSrc->pbmi->bmiHeader.biHeight;
  1057. pDibInfoSrc->pbmi->bmiHeader.biWidth = 256;
  1058. pDibInfoSrc->pbmi->bmiHeader.biHeight = 1;
  1059. SetDIBits(hdc, hbm, 0, 1, pByteSrc, (PBITMAPINFO)pDibInfoSrc->pbmi,DIB_RGB_COLORS);
  1060. //
  1061. // retore bitmap width/height
  1062. //
  1063. pDibInfoSrc->pbmi->bmiHeader.biWidth = ulWidthSrc;
  1064. pDibInfoSrc->pbmi->bmiHeader.biHeight = ulHeightSrc;
  1065. pDibInfoDst->pbmi->bmiHeader.biWidth = ulWidthDst;
  1066. pDibInfoDst->pbmi->bmiHeader.biHeight = ulHeightDst;
  1067. //
  1068. // now pByte contains all the 256 color mappings, just need to split them up
  1069. //
  1070. j = 0;
  1071. for (i = 0; i < 128; i++)
  1072. {
  1073. xlate[j] = (pByte[i] & 0xF0) >> 4;
  1074. xlate[j++] = pByte[i] & 0x0F;
  1075. }
  1076. BYTE jDst;
  1077. while(cy--)
  1078. {
  1079. cxTemp = cx;
  1080. iDst = pDibInfoDst->rclDIB.left;
  1081. pjDstTemp = pjDst;
  1082. pjSrcTemp = pjSrc;
  1083. while (cxTemp--)
  1084. {
  1085. jSrc = *pjSrcTemp++;
  1086. if (iDst & 0x00000001)
  1087. {
  1088. if (jSrc != (BYTE)TransColor)
  1089. {
  1090. jDst |= (xlate[jSrc] & 0x0F);
  1091. }
  1092. else
  1093. {
  1094. jDst |= (*pjDstTemp & 0x0F);
  1095. }
  1096. *pjDstTemp = jDst;
  1097. jDst = 0;
  1098. pjDstTemp++;
  1099. }
  1100. else
  1101. {
  1102. if (jSrc != (BYTE)TransColor)
  1103. {
  1104. jDst |= (xlate[jSrc] & 0x0F)<< 4;
  1105. }
  1106. else
  1107. {
  1108. jDst |= (*pjDstTemp & 0x0F) << 4;
  1109. }
  1110. }
  1111. iDst++;
  1112. }
  1113. pjDst += pDibInfoDst->stride;
  1114. pjSrc += pDibInfoSrc->stride;
  1115. }
  1116. DeleteDC(hdc);
  1117. DeleteObject(hbm);
  1118. }
  1119. /******************************Public*Routine******************************\
  1120. * vTransparentIdentityCopy8
  1121. *
  1122. * Doing a transparent copy on two same size 8BPP format DIBs
  1123. *
  1124. * Returns:
  1125. * VOID.
  1126. *
  1127. * History:
  1128. * 09-Dec-1996 -by- Lingyun Wang [lingyunw]
  1129. * Wrote it.
  1130. \**************************************************************************/
  1131. VOID vTransparentIdentityCopy8 (
  1132. PDIBINFO pDibInfoDst,
  1133. PDIBINFO pDibInfoSrc,
  1134. ULONG TransColor)
  1135. {
  1136. PBYTE pjDst = (PBYTE)pDibInfoDst->pvBase + pDibInfoDst->stride*pDibInfoDst->rclDIB.top
  1137. + pDibInfoDst->rclDIB.left;
  1138. PBYTE pjSrc = (PBYTE)pDibInfoSrc->pvBase + pDibInfoSrc->stride*pDibInfoSrc->rclDIB.top
  1139. + pDibInfoSrc->rclDIB.left;
  1140. LONG cx = pDibInfoSrc->rclDIB.right - pDibInfoSrc->rclDIB.left;
  1141. LONG cy = pDibInfoSrc->rclDIB.bottom - pDibInfoSrc->rclDIB.top;
  1142. PBYTE pjDstTemp;
  1143. PBYTE pjSrcTemp;
  1144. LONG cxTemp;
  1145. while(cy--)
  1146. {
  1147. cxTemp = cx;
  1148. pjDstTemp = pjDst;
  1149. pjSrcTemp = pjSrc;
  1150. while (cxTemp--)
  1151. {
  1152. if (*pjSrcTemp != (BYTE)TransColor)
  1153. {
  1154. *pjDstTemp = *pjSrcTemp;
  1155. }
  1156. pjDstTemp++;
  1157. pjSrcTemp++;
  1158. }
  1159. pjDst += pDibInfoDst->stride;
  1160. pjSrc += pDibInfoSrc->stride;
  1161. }
  1162. }
  1163. /******************************Public*Routine******************************\
  1164. * vTransparentS8D8
  1165. *
  1166. * Doing a transparent copy on two same size 8BPP format DIBs
  1167. *
  1168. * Returns:
  1169. * VOID.
  1170. *
  1171. * History:
  1172. * 09-Dec-1996 -by- Lingyun Wang [lingyunw]
  1173. * Wrote it.
  1174. \**************************************************************************/
  1175. VOID vTransparentS8D8 (
  1176. PDIBINFO pDibInfoDst,
  1177. PDIBINFO pDibInfoSrc,
  1178. ULONG TransColor)
  1179. {
  1180. PBYTE pjDst = (PBYTE)pDibInfoDst->pvBase + pDibInfoDst->stride*pDibInfoDst->rclDIB.top
  1181. + pDibInfoDst->rclDIB.left;
  1182. PBYTE pjSrc = (PBYTE)pDibInfoSrc->pvBase + pDibInfoSrc->stride*pDibInfoSrc->rclDIB.top
  1183. + pDibInfoSrc->rclDIB.left;
  1184. LONG cx = pDibInfoDst->rclDIB.right - pDibInfoDst->rclDIB.left;
  1185. LONG cy = pDibInfoDst->rclDIB.bottom - pDibInfoDst->rclDIB.top;
  1186. PBYTE pjDstTemp;
  1187. PBYTE pjSrcTemp;
  1188. LONG cxTemp;
  1189. HDC hdc;
  1190. HBITMAP hbm;
  1191. ULONG ulWidthDst, ulHeightDst, ulWidthSrc, ulHeightSrc;
  1192. INT i, j;
  1193. BYTE pByteSrc[256];
  1194. PBYTE pxlate;
  1195. LONG iDst;
  1196. //
  1197. // build the color translation table
  1198. //
  1199. hdc = CreateCompatibleDC (pDibInfoDst->hdc);
  1200. //
  1201. // save the original width/height
  1202. //
  1203. ulWidthDst = pDibInfoDst->pbmi->bmiHeader.biWidth;
  1204. ulHeightDst = pDibInfoDst->pbmi->bmiHeader.biHeight;
  1205. pDibInfoDst->pbmi->bmiHeader.biWidth = 256;
  1206. pDibInfoDst->pbmi->bmiHeader.biHeight = 1;
  1207. //
  1208. // Create a 256X1 DIB
  1209. //
  1210. hbm = CreateDIBSection(hdc, (PBITMAPINFO)pDibInfoDst->pbmi, DIB_RGB_COLORS, (PVOID *)&pxlate, NULL, 0);
  1211. if (!hdc || !hbm)
  1212. {
  1213. //
  1214. // It's bad to fail and return here without a return value, but it's better
  1215. // than crashing later when accessing pxlate. At some point it would be nice
  1216. // to change the vTansparentxxxx functions to return success/failure.
  1217. //
  1218. if (hdc)
  1219. {
  1220. DeleteDC(hdc);
  1221. }
  1222. if (hbm)
  1223. {
  1224. DeleteObject(hbm);
  1225. }
  1226. pDibInfoDst->pbmi->bmiHeader.biWidth = ulWidthDst;
  1227. pDibInfoDst->pbmi->bmiHeader.biHeight = ulHeightDst;
  1228. WARNING ("failed to create hdc or hbm\n");
  1229. return;
  1230. }
  1231. SelectObject (hdc, hbm);
  1232. for (i = 0; i < 256; i++)
  1233. {
  1234. pByteSrc[i] = (unsigned char)i;
  1235. }
  1236. ulWidthSrc = pDibInfoSrc->pbmi->bmiHeader.biWidth;
  1237. ulHeightSrc = pDibInfoSrc->pbmi->bmiHeader.biHeight;
  1238. pDibInfoSrc->pbmi->bmiHeader.biWidth = 256;
  1239. pDibInfoSrc->pbmi->bmiHeader.biHeight = 1;
  1240. SetDIBits(hdc, hbm, 0, 1, pByteSrc, (PBITMAPINFO)pDibInfoSrc->pbmi,DIB_RGB_COLORS);
  1241. //
  1242. // retore bitmap width/height
  1243. //
  1244. pDibInfoSrc->pbmi->bmiHeader.biWidth = ulWidthSrc;
  1245. pDibInfoSrc->pbmi->bmiHeader.biHeight = ulHeightSrc;
  1246. pDibInfoDst->pbmi->bmiHeader.biWidth = ulWidthDst;
  1247. pDibInfoDst->pbmi->bmiHeader.biHeight = ulHeightDst;
  1248. while(cy--)
  1249. {
  1250. cxTemp = cx;
  1251. pjDstTemp = pjDst;
  1252. pjSrcTemp = pjSrc;
  1253. while (cxTemp--)
  1254. {
  1255. if (*pjSrcTemp != (BYTE)TransColor)
  1256. {
  1257. *pjDstTemp = pxlate[*pjSrcTemp];
  1258. }
  1259. pjDstTemp++;
  1260. pjSrcTemp++;
  1261. }
  1262. pjDst += pDibInfoDst->stride;
  1263. pjSrc += pDibInfoSrc->stride;
  1264. }
  1265. DeleteObject(hbm);
  1266. DeleteDC(hdc);
  1267. }
  1268. #if 0
  1269. /******************************Public*Routine******************************\
  1270. * vTransparentIdentityCopy16
  1271. *
  1272. * Doing a transparent copy on two same size 16BPP format DIBs
  1273. *
  1274. * Returns:
  1275. * VOID.
  1276. *
  1277. * History:
  1278. * 09-Dec-1996 -by- Lingyun Wang [lingyunw]
  1279. * Wrote it.
  1280. \**************************************************************************/
  1281. VOID vTransparentIdentityCopy16 (
  1282. PDIBINFO pDibInfoDst,
  1283. PDIBINFO pDibInfoSrc,
  1284. ULONG TransColor)
  1285. {
  1286. PUSHORT pusDst = (PUSHORT)((PBYTE)pDibInfoDst->pvBase + pDibInfoDst->rclDIB.top*pDibInfoDst->stride)
  1287. + pDibInfoDst->rclDIB.left;
  1288. PUSHORT pusSrc = (PUSHORT)((PBYTE)pDibInfoSrc->pvBase + pDibInfoSrc->rclDIB.top*pDibInfoDst->stride)
  1289. + pDibInfoSrc->rclDIB.left;
  1290. LONG cx = pDibInfoDst->rclDIB.right - pDibInfoDst->rclDIB.left;
  1291. LONG cy = pDibInfoDst->rclDIB.bottom - pDibInfoDst->rclDIB.top;
  1292. PUSHORT pusDstTemp;
  1293. PUSHORT pusSrcTemp;
  1294. LONG cxTemp;
  1295. while(cy--)
  1296. {
  1297. cxTemp = cx;
  1298. pusDstTemp = pusDst;
  1299. pusSrcTemp = pusSrc;
  1300. while (cxTemp--)
  1301. {
  1302. if (*pusSrcTemp != (USHORT)TransColor)
  1303. {
  1304. *pusDstTemp = *pusSrcTemp;
  1305. }
  1306. pusDstTemp++;
  1307. pusSrcTemp++;
  1308. }
  1309. pusDst = (PUSHORT)((PBYTE)pusDst + pDibInfoDst->stride);
  1310. pusSrc = (PUSHORT)((PBYTE)pusSrc + pDibInfoSrc->stride);
  1311. }
  1312. }
  1313. /******************************Public*Routine******************************\
  1314. * vTransparentIdentityCopy24
  1315. *
  1316. * Doing a transparent copy on two same size 8BPP format DIBs
  1317. *
  1318. * Returns:
  1319. * VOID.
  1320. *
  1321. * History:
  1322. * 09-Dec-1996 -by- Lingyun Wang [lingyunw]
  1323. * Wrote it.
  1324. \**************************************************************************/
  1325. VOID vTransparentIdentityCopy24 (
  1326. PDIBINFO pDibInfoDst,
  1327. PDIBINFO pDibInfoSrc,
  1328. ULONG TransColor)
  1329. {
  1330. PBYTE pjDst = (PBYTE)pDibInfoDst->pvBase + pDibInfoDst->stride*pDibInfoDst->rclDIB.top
  1331. + pDibInfoDst->rclDIB.left*3;
  1332. PBYTE pjSrc = (PBYTE)pDibInfoSrc->pvBase + pDibInfoSrc->stride*pDibInfoSrc->rclDIB.top
  1333. + pDibInfoSrc->rclDIB.left*3;
  1334. LONG cx = pDibInfoDst->rclDIB.right - pDibInfoDst->rclDIB.left;
  1335. LONG cy = pDibInfoDst->rclDIB.bottom - pDibInfoDst->rclDIB.top;
  1336. PBYTE pjDstTemp;
  1337. PBYTE pjSrcTemp;
  1338. ULONG ulTemp;
  1339. LONG cxTemp;
  1340. while(cy--)
  1341. {
  1342. cxTemp = cx;
  1343. pjDstTemp = pjDst;
  1344. pjSrcTemp = pjSrc;
  1345. while (cxTemp--)
  1346. {
  1347. ulTemp = (ULONG) *(pjSrcTemp + 2);
  1348. ulTemp = ulTemp << 8;
  1349. ulTemp |= (ULONG) *(pjSrcTemp + 1);
  1350. ulTemp = ulTemp << 8;
  1351. ulTemp |= (ULONG) *pjSrcTemp;
  1352. if (ulTemp != TransColor)
  1353. {
  1354. *(pjDstTemp++) = (BYTE) ulTemp;
  1355. *(pjDstTemp++) = (BYTE) (ulTemp >> 8);
  1356. *(pjDstTemp++) = (BYTE) (ulTemp >> 16);
  1357. }
  1358. else
  1359. {
  1360. pjDstTemp += 3;
  1361. }
  1362. pjSrcTemp += 3;
  1363. }
  1364. pjDst += pDibInfoDst->stride;
  1365. pjSrc += pDibInfoSrc->stride;
  1366. }
  1367. }
  1368. #endif
  1369. /******************************Public*Routine******************************\
  1370. * vTransparentIdentityCopy32
  1371. *
  1372. * Doing a transparent copy on two same size 32BPP format DIBs
  1373. *
  1374. * Returns:
  1375. * VOID.
  1376. *
  1377. * History:
  1378. * 09-Dec-1996 -by- Lingyun Wang [lingyunw]
  1379. * Wrote it.
  1380. \**************************************************************************/
  1381. VOID vTransparentIdentityCopy32 (
  1382. PDIBINFO pDibInfoDst,
  1383. PDIBINFO pDibInfoSrc,
  1384. ULONG TransColor)
  1385. {
  1386. PULONG pulDst = (PULONG)((PBYTE)pDibInfoDst->pvBase + pDibInfoDst->stride*pDibInfoDst->rclDIB.top)
  1387. + pDibInfoDst->rclDIB.left;
  1388. PULONG pulSrc = (PULONG)((PBYTE)pDibInfoSrc->pvBase + pDibInfoSrc->stride*pDibInfoSrc->rclDIB.top)
  1389. + pDibInfoSrc->rclDIB.left;
  1390. LONG cx = pDibInfoDst->rclDIB.right - pDibInfoDst->rclDIB.left;
  1391. LONG cy = pDibInfoDst->rclDIB.bottom - pDibInfoDst->rclDIB.top;
  1392. PULONG pulDstTemp;
  1393. PULONG pulSrcTemp;
  1394. LONG cxTemp;
  1395. while(cy--)
  1396. {
  1397. cxTemp = cx;
  1398. pulDstTemp = pulDst;
  1399. pulSrcTemp = pulSrc;
  1400. while (cxTemp--)
  1401. {
  1402. // mask off highest byte -- workaround Memphis problem
  1403. if ((*pulSrcTemp & 0x00FFFFFF) != TransColor)
  1404. {
  1405. *pulDstTemp = *pulSrcTemp;
  1406. }
  1407. pulDstTemp++;
  1408. pulSrcTemp++;
  1409. }
  1410. pulDst = (PULONG)((PBYTE)pulDst + pDibInfoDst->stride);
  1411. pulSrc = (PULONG)((PBYTE)pulSrc + pDibInfoSrc->stride);
  1412. }
  1413. }
  1414. /******************************Public*Routine******************************\
  1415. * vTransparentS16D32
  1416. *
  1417. * Doing a transparent copy from 16BPP to 32BPP
  1418. *
  1419. * Returns:
  1420. * VOID.
  1421. *
  1422. * History:
  1423. * 22-Aug-1997 -by- Ori Gershony [orig]
  1424. * Wrote it.
  1425. \**************************************************************************/
  1426. VOID vTransparentS16D32 (
  1427. PDIBINFO pDibInfoDst,
  1428. PDIBINFO pDibInfoSrc,
  1429. ULONG TransColor)
  1430. {
  1431. PBYTE pjDst = (PBYTE)pDibInfoDst->pvBase + pDibInfoDst->stride*pDibInfoDst->rclDIB.top
  1432. + pDibInfoDst->rclDIB.left*4;
  1433. PBYTE pjSrc = (PBYTE)pDibInfoSrc->pvBase + pDibInfoSrc->stride*pDibInfoSrc->rclDIB.top
  1434. + pDibInfoSrc->rclDIB.left*2;
  1435. LONG cx = pDibInfoDst->rclDIB.right - pDibInfoDst->rclDIB.left;
  1436. LONG cy = pDibInfoDst->rclDIB.bottom - pDibInfoDst->rclDIB.top;
  1437. PBYTE pjDstTemp;
  1438. PUSHORT pjSrcTemp;
  1439. USHORT jSrc;
  1440. LONG cxTemp;
  1441. BYTE rgbBlue, rgbGreen, rgbRed;
  1442. while(cy--)
  1443. {
  1444. cxTemp = cx;
  1445. pjDstTemp = pjDst;
  1446. pjSrcTemp = (PUSHORT) pjSrc;
  1447. while (cxTemp--)
  1448. {
  1449. jSrc = *pjSrcTemp++;
  1450. //
  1451. // If 5-5-5 we should mask out the 16th bit so that we'd recognize the transparent
  1452. // color
  1453. //
  1454. if ((!(pDibInfoSrc->pbmi->bmiHeader.biCompression == BI_BITFIELDS)) ||
  1455. ((*(DWORD *)&pDibInfoSrc->pbmi->bmiColors[1] == 0x03E0)))
  1456. {
  1457. jSrc &= 0x7fff;
  1458. TransColor &= 0x7fff;
  1459. }
  1460. if (jSrc != (USHORT)TransColor)
  1461. {
  1462. //
  1463. // figure out 5-5-5 or 5-6-5
  1464. //
  1465. if (pDibInfoSrc->pbmi->bmiHeader.biCompression == BI_BITFIELDS)
  1466. {
  1467. //5-5-5
  1468. if (*(DWORD *)&pDibInfoSrc->pbmi->bmiColors[1] == 0x03E0)
  1469. {
  1470. rgbBlue = (jSrc & 0x1f) << 3;
  1471. rgbGreen = ((jSrc >> 5) & 0x1f) << 3;
  1472. rgbRed = ((jSrc >> 10) & 0x1f) << 3;
  1473. }
  1474. // 5-6-5
  1475. else if (*(DWORD *)&pDibInfoDst->pbmi->bmiColors[1] == 0x07E0)
  1476. {
  1477. rgbBlue = (jSrc & 0x1f) << 3;
  1478. rgbGreen = ((jSrc >> 5) & 0x3f) << 2;
  1479. rgbRed = ((jSrc >> 11) & 0x1f) << 3;
  1480. }
  1481. else
  1482. {
  1483. WARNING ("unsupported BITFIELDS\n");
  1484. }
  1485. }
  1486. else
  1487. {
  1488. rgbBlue = (jSrc & 0x1f) << 3;
  1489. rgbGreen = ((jSrc >> 5) & 0x1f) << 3;
  1490. rgbRed = ((jSrc >> 10) & 0x1f) << 3;
  1491. }
  1492. *(PULONG)pjDstTemp = (DWORD) (rgbBlue << 0 | (WORD)rgbGreen << 8 | (DWORD)rgbRed << 16);
  1493. }
  1494. pjDstTemp += 4;
  1495. }
  1496. pjDst += pDibInfoDst->stride;
  1497. pjSrc += pDibInfoSrc->stride;
  1498. }
  1499. }
  1500. /******************************Public*Routine******************************\
  1501. * vTransparentS24D32
  1502. *
  1503. * Doing a transparent copy from 24BPP to 32BPP
  1504. *
  1505. * Returns:
  1506. * VOID.
  1507. *
  1508. * History:
  1509. * 22-Aug-1997 -by- Ori Gershony [orig]
  1510. * Wrote it.
  1511. \**************************************************************************/
  1512. VOID vTransparentS24D32 (
  1513. PDIBINFO pDibInfoDst,
  1514. PDIBINFO pDibInfoSrc,
  1515. ULONG TransColor)
  1516. {
  1517. PBYTE pjDst = (PBYTE)pDibInfoDst->pvBase + pDibInfoDst->stride*pDibInfoDst->rclDIB.top
  1518. + pDibInfoDst->rclDIB.left*4;
  1519. PBYTE pjSrc = (PBYTE)pDibInfoSrc->pvBase + pDibInfoSrc->stride*pDibInfoSrc->rclDIB.top
  1520. + pDibInfoSrc->rclDIB.left*3;
  1521. LONG cx = pDibInfoDst->rclDIB.right - pDibInfoDst->rclDIB.left;
  1522. LONG cy = pDibInfoDst->rclDIB.bottom - pDibInfoDst->rclDIB.top;
  1523. PBYTE pjDstTemp;
  1524. PBYTE pjSrcTemp;
  1525. ULONG jSrc;
  1526. LONG cxTemp;
  1527. BYTE rgbBlue, rgbGreen, rgbRed;
  1528. while(cy--)
  1529. {
  1530. cxTemp = cx;
  1531. pjDstTemp = pjDst;
  1532. pjSrcTemp = pjSrc;
  1533. while (cxTemp--)
  1534. {
  1535. jSrc = (ULONG) *(pjSrcTemp+2);
  1536. jSrc <<= 8;
  1537. jSrc |= (ULONG) *(pjSrcTemp+1);
  1538. jSrc <<= 8;
  1539. jSrc |= (ULONG) *(pjSrcTemp);
  1540. pjSrcTemp +=3;
  1541. if (jSrc != TransColor)
  1542. {
  1543. *(PULONG)pjDstTemp = jSrc;
  1544. }
  1545. pjDstTemp += 4;
  1546. }
  1547. pjDst += pDibInfoDst->stride;
  1548. pjSrc += pDibInfoSrc->stride;
  1549. }
  1550. }
  1551. /******************************Public*Routine******************************\
  1552. * vTransparentS32D32
  1553. *
  1554. * Doing a transparent copy from 32BPP to 32BPP
  1555. *
  1556. * Returns:
  1557. * VOID.
  1558. *
  1559. * History:
  1560. * 22-Aug-1997 -by- Ori Gershony [orig]
  1561. * Wrote it.
  1562. \**************************************************************************/
  1563. #define vTransparentS32D32 vTransparentIdentityCopy32
  1564. /******************************Public*Routine******************************\
  1565. * MapTransparentColor
  1566. *
  1567. * Getting the correct transparent color mapped to the specified DIB format
  1568. * by creating a solid brush on the colorref, then PatBlt to a 1X1 DIB, the
  1569. * resulting pixel is the mapped transparent color
  1570. *
  1571. * Returns:
  1572. * VOID.
  1573. *
  1574. * History:
  1575. * 09-Dec-1996 -by- Lingyun Wang [lingyunw]
  1576. * Wrote it.
  1577. \**************************************************************************/
  1578. DWORD MapTransparentColor(
  1579. PDIBINFO pDibInfo,
  1580. COLORREF Color
  1581. )
  1582. {
  1583. HBRUSH hbr, hbrDefault;
  1584. HBITMAP hbm, hbmDefault;
  1585. HDC hdcTemp;
  1586. UINT iUsage;
  1587. PVOID pvBits = NULL;
  1588. DWORD trancolor;
  1589. ULONG ulWidth, ulHeight;
  1590. hdcTemp = CreateCompatibleDC(pDibInfo->hdc);
  1591. hbr = CreateSolidBrush (Color);
  1592. //
  1593. // save the original width/height
  1594. //
  1595. ulWidth = pDibInfo->pbmi->bmiHeader.biWidth;
  1596. ulHeight = pDibInfo->pbmi->bmiHeader.biHeight;
  1597. pDibInfo->pbmi->bmiHeader.biWidth = 1;
  1598. pDibInfo->pbmi->bmiHeader.biHeight = 1;
  1599. //
  1600. // Create a 1X1 DIB
  1601. //
  1602. hbm = CreateDIBSection(hdcTemp, (PBITMAPINFO)pDibInfo->pbmi, DIB_RGB_COLORS, &pvBits, NULL, 0);
  1603. if (hbm && hbr)
  1604. {
  1605. hbmDefault = (HBITMAP)SelectObject (hdcTemp, hbm);
  1606. hbrDefault = (HBRUSH)SelectObject (hdcTemp, hbr);
  1607. PatBlt (hdcTemp, 0, 0, 1, 1, PATCOPY);
  1608. SelectObject (hdcTemp, hbrDefault);
  1609. SelectObject (hdcTemp, hbmDefault);
  1610. }
  1611. if (pvBits)
  1612. {
  1613. switch (pDibInfo->pbmi->bmiHeader.biBitCount)
  1614. {
  1615. case 1:
  1616. trancolor = *(BYTE *)pvBits;
  1617. trancolor = (DWORD)(((BYTE)trancolor) & 0x80) >>7;
  1618. break;
  1619. case 4:
  1620. trancolor = *(BYTE *)pvBits;
  1621. trancolor = (DWORD)(((BYTE)trancolor) & 0xF0) >>4;
  1622. break;
  1623. case 8:
  1624. trancolor = (DWORD)(*(BYTE *)pvBits);
  1625. trancolor &= 0x000000FF;
  1626. break;
  1627. case 16:
  1628. trancolor = (DWORD)(*(USHORT *)pvBits);
  1629. trancolor &= 0x0000FFFF;
  1630. break;
  1631. case 24:
  1632. trancolor = *(DWORD *)pvBits;
  1633. trancolor &= 0x00FFFFFF;
  1634. break;
  1635. case 32:
  1636. trancolor = *(DWORD *)pvBits;
  1637. trancolor &= 0x00FFFFFF;
  1638. break;
  1639. }
  1640. }
  1641. pDibInfo->pbmi->bmiHeader.biWidth = ulWidth;
  1642. pDibInfo->pbmi->bmiHeader.biHeight = ulHeight;
  1643. //
  1644. // cleanup
  1645. //
  1646. DeleteObject (hbm);
  1647. DeleteObject (hbr);
  1648. DeleteDC(hdcTemp);
  1649. return (trancolor);
  1650. }
  1651. /******************************Public*Routine******************************\
  1652. * DIBMapTransparentColor
  1653. *
  1654. * Getting the correct transparent color mapped to the specified DIB format
  1655. * This is only for DIB_PAL_COLORS passed into transparentDIBits
  1656. *
  1657. * Returns:
  1658. * VOID.
  1659. *
  1660. * History:
  1661. * 09-Dec-1996 -by- Lingyun Wang [lingyunw]
  1662. * Wrote it.
  1663. \**************************************************************************/
  1664. DWORD DIBMapTransparentColor(
  1665. PDIBINFO pDibInfoDst,
  1666. PDIBINFO pDibInfoSrc,
  1667. COLORREF Color
  1668. )
  1669. {
  1670. HBITMAP hbm, hbmDefault;
  1671. HDC hdcTemp;
  1672. UINT iUsage;
  1673. PVOID pvBits;
  1674. DWORD trancolor;
  1675. ULONG ulWidth, ulHeight;
  1676. hdcTemp = CreateCompatibleDC(pDibInfoDst->hdc);
  1677. //
  1678. // save the original width/height
  1679. //
  1680. ulWidth = pDibInfoDst->pbmi->bmiHeader.biWidth;
  1681. ulHeight = pDibInfoDst->pbmi->bmiHeader.biHeight;
  1682. pDibInfoDst->pbmi->bmiHeader.biWidth = 1;
  1683. pDibInfoDst->pbmi->bmiHeader.biHeight = 1;
  1684. //
  1685. // Create a 1X1 DIB
  1686. //
  1687. hbm = CreateDIBSection(hdcTemp, (PBITMAPINFO)pDibInfoDst->pbmi, DIB_RGB_COLORS, &pvBits, NULL, 0);
  1688. if (hbm)
  1689. {
  1690. hbmDefault = (HBITMAP)SelectObject (hdcTemp, hbm);
  1691. StretchDIBits (hdcTemp,
  1692. 0,
  1693. 0,
  1694. 1,
  1695. 1,
  1696. 0,
  1697. 0,
  1698. 1,
  1699. 1,
  1700. &Color,
  1701. pDibInfoSrc->pbmi,
  1702. pDibInfoSrc->iUsage,
  1703. SRCCOPY);
  1704. SelectObject (hdcTemp, hbmDefault);
  1705. }
  1706. if (pvBits)
  1707. {
  1708. switch (pDibInfoDst->pbmi->bmiHeader.biBitCount)
  1709. {
  1710. case 4:
  1711. trancolor = *(BYTE *)pvBits;
  1712. trancolor = (DWORD)(((BYTE)trancolor) & 0xF0) >>4;
  1713. break;
  1714. case 8:
  1715. trancolor = (DWORD)(*(BYTE *)pvBits);
  1716. trancolor &= 0x000000FF;
  1717. break;
  1718. case 16:
  1719. trancolor = (DWORD)(*(USHORT *)pvBits);
  1720. trancolor &= 0x0000FFFF;
  1721. break;
  1722. case 24:
  1723. trancolor = *(DWORD *)pvBits;
  1724. trancolor &= 0x00FFFFFF;
  1725. break;
  1726. case 32:
  1727. trancolor = *(DWORD *)pvBits;
  1728. trancolor &= 0x00FFFFFF;
  1729. break;
  1730. }
  1731. }
  1732. pDibInfoDst->pbmi->bmiHeader.biWidth = ulWidth;
  1733. pDibInfoDst->pbmi->bmiHeader.biHeight = ulHeight;
  1734. //
  1735. // cleanup
  1736. //
  1737. DeleteObject (hbm);
  1738. DeleteDC(hdcTemp);
  1739. return (trancolor);
  1740. }
  1741. /******************************Public*Routine******************************\
  1742. * vTransparentMapCopy
  1743. *
  1744. * Map the Dest surface to 32bpp and does transparent on to that
  1745. *
  1746. * Returns:
  1747. * VOID.
  1748. *
  1749. * History:
  1750. * 09-Dec-1996 -by- Lingyun Wang [lingyunw]
  1751. * Wrote it.
  1752. \**************************************************************************/
  1753. VOID vTransparentMapCopy (
  1754. PDIBINFO pDibInfoDst,
  1755. PDIBINFO pDibInfoSrc,
  1756. ULONG TransColor)
  1757. {
  1758. HDC hdc = pDibInfoSrc->hdc;
  1759. ULONG cxDst = pDibInfoDst->rclDIB.right - pDibInfoDst->rclDIB.left;
  1760. ULONG cyDst = pDibInfoDst->rclDIB.bottom - pDibInfoDst->rclDIB.top;
  1761. HBITMAP hbm;
  1762. PVOID pBits;
  1763. ULONG cBytes = sizeof(BITMAPINFO) + sizeof(RGBQUAD) * 255;
  1764. PBITMAPINFO pbmi;
  1765. PVOID p = LOCALALLOC(cBytes);
  1766. if (!p)
  1767. {
  1768. WARNING("MapCopy fail to alloc mem\n");
  1769. return ;
  1770. }
  1771. ZeroMemory (p,cBytes);
  1772. pbmi = (PBITMAPINFO)p;
  1773. vCopyBitmapInfo (pbmi, pDibInfoDst->pbmi);
  1774. hdc = CreateCompatibleDC (hdc);
  1775. pbmi->bmiHeader.biBitCount = 32;
  1776. pbmi->bmiHeader.biCompression = BI_RGB;
  1777. // create a dib using 32 format
  1778. if (!(hbm = CreateCompatibleDIB (hdc, cxDst, cyDst, &pBits, pbmi)))
  1779. {
  1780. WARNING("Error in msimg32!vTransparentMapCopy: call to CreateCompatibleDIB failed\n");
  1781. if (hdc)
  1782. {
  1783. DeleteDC(hdc);
  1784. }
  1785. if (p)
  1786. {
  1787. LOCALFREE(p);
  1788. }
  1789. return;
  1790. }
  1791. SetDIBits (hdc, hbm, 0, cyDst, pDibInfoDst->pvBits, pDibInfoDst->pbmi, DIB_RGB_COLORS);
  1792. vCopyBitmapInfo (pDibInfoDst->pbmi,pbmi);
  1793. GetCompatibleDIBInfo (hbm, &pDibInfoDst->pvBase, &pDibInfoDst->stride);
  1794. PVOID pvBitsOrig = pDibInfoDst->pvBits;
  1795. pDibInfoDst->pvBits = pBits;
  1796. pDibInfoDst->rclDIB.left = 0;
  1797. pDibInfoDst->rclDIB.right = cxDst;
  1798. pDibInfoDst->rclDIB.top = 0;
  1799. pDibInfoDst->rclDIB.bottom = cyDst;
  1800. switch(pDibInfoSrc->pbmi->bmiHeader.biBitCount)
  1801. {
  1802. case 4:
  1803. vTransparentS4D32 (pDibInfoDst, pDibInfoSrc, TransColor);
  1804. break;
  1805. case 8:
  1806. vTransparentS8D32 (pDibInfoDst, pDibInfoSrc, TransColor);
  1807. break;
  1808. case 16:
  1809. vTransparentS16D32 (pDibInfoDst, pDibInfoSrc, TransColor);
  1810. break;
  1811. case 24:
  1812. vTransparentS24D32 (pDibInfoDst, pDibInfoSrc, TransColor);
  1813. break;
  1814. case 32:
  1815. vTransparentS32D32 (pDibInfoDst, pDibInfoSrc, TransColor);
  1816. break;
  1817. }
  1818. //
  1819. // If destination is a memory dc, then now is the time to set the bits at
  1820. // the destination format.
  1821. //
  1822. HBITMAP hbmDest;
  1823. if ((GetObjectType(pDibInfoDst->hdc) == OBJ_MEMDC) &&
  1824. ((hbmDest = (HBITMAP)GetCurrentObject(pDibInfoDst->hdc, OBJ_BITMAP)) != NULL))
  1825. {
  1826. SetDIBits (pDibInfoDst->hdc, hbmDest, 0, cyDst, pBits, pbmi, DIB_RGB_COLORS);
  1827. }
  1828. if (pDibInfoDst->hDIB)
  1829. {
  1830. //
  1831. // Replace the old hDIB with the one allocated above. Make sure
  1832. // the old one doesn't get leaked. pDibInfoDst->hDIB will get
  1833. // cleaned up in vCleanupDIBINFO.
  1834. //
  1835. DeleteObject(pDibInfoDst->hDIB);
  1836. pDibInfoDst->hDIB = hbm;
  1837. }
  1838. else
  1839. {
  1840. //
  1841. // This is the case where the destination was a dibsection with
  1842. // no stretching. The correct data was already written in the
  1843. // above call to SetDIBits.
  1844. //
  1845. DeleteObject(hbm);
  1846. pDibInfoDst->pvBits = pvBitsOrig;
  1847. }
  1848. if (p)
  1849. {
  1850. LOCALFREE (p);
  1851. }
  1852. if (hdc)
  1853. {
  1854. DeleteDC(hdc);
  1855. }
  1856. }
  1857. /******************************Public*Routine******************************\
  1858. * ReadScanLine
  1859. * read the scanline until it hits a transparent color pixel
  1860. *
  1861. * History:
  1862. * 26-Nov-1996 -by- Lingyun Wang [lingyunw]
  1863. * Wrote it.
  1864. \**************************************************************************/
  1865. ULONG ReadScanLine(
  1866. PBYTE pjSrc,
  1867. ULONG xStart,
  1868. ULONG xEnd,
  1869. ULONG iFormat,
  1870. ULONG TransparentColor,
  1871. PDIBINFO pDibInfoSrc)
  1872. {
  1873. ULONG cx = xEnd-xStart;
  1874. ULONG Shift = (iFormat - 3 > 0) ? iFormat : 1;
  1875. ULONG iPos;
  1876. ULONG ulSrc;
  1877. BOOL bStop = FALSE;
  1878. pjSrc = StartPixel (pjSrc, xStart, iFormat);
  1879. //
  1880. // performance can be improved by breaking this routine into many
  1881. // dealing with different format so that we can save two comparsions
  1882. // for each pixel operation. But working set size will be large
  1883. //
  1884. iPos = xStart;
  1885. //
  1886. // read one pixel at a time and compare it to the transparent color
  1887. // if it matches the transparent color, come out
  1888. //
  1889. BYTE jSrc = *pjSrc << (iPos & 0x7);
  1890. while ((iPos < xEnd) && !bStop)
  1891. {
  1892. //
  1893. // get a pixel from source and compare is to the transparent color
  1894. //
  1895. switch (iFormat)
  1896. {
  1897. case 1:
  1898. ulSrc = (ULONG) (jSrc & 0x80);
  1899. ulSrc >>= 7;
  1900. jSrc <<= 1;
  1901. if (!(iPos & 0x00000007) )
  1902. pjSrc++;
  1903. break;
  1904. case 4:
  1905. if (iPos & 0x00000001)
  1906. {
  1907. ulSrc = *pjSrc & 0x0F;
  1908. pjSrc++;
  1909. }
  1910. else
  1911. {
  1912. ulSrc = (*pjSrc & 0xF0)>>4;
  1913. }
  1914. break;
  1915. case 8:
  1916. ulSrc = (ULONG) *pjSrc;
  1917. pjSrc++;
  1918. break;
  1919. case 16:
  1920. ulSrc = (ULONG) *((PUSHORT)pjSrc);
  1921. //
  1922. // If 5-5-5 we should mask out the 16th bit so that we'd recognize the transparent
  1923. // color
  1924. //
  1925. if ((!(pDibInfoSrc->pbmi->bmiHeader.biCompression == BI_BITFIELDS)) ||
  1926. ((*(DWORD *)&pDibInfoSrc->pbmi->bmiColors[1] == 0x03E0)))
  1927. {
  1928. ulSrc &= 0x7fff;
  1929. }
  1930. pjSrc += 2;
  1931. break;
  1932. case 24:
  1933. ulSrc = *(pjSrc + 2);
  1934. ulSrc = ulSrc << 8;
  1935. ulSrc |= (ULONG) *(pjSrc + 1);
  1936. ulSrc = ulSrc << 8;
  1937. ulSrc |= (ULONG) *pjSrc;
  1938. pjSrc += 3;
  1939. break;
  1940. case 32:
  1941. ulSrc = *(PULONG)(pjSrc);
  1942. ulSrc &= 0x00ffffff; // Ignore upper byte since it doesn't contain color information
  1943. pjSrc +=4;
  1944. break;
  1945. default:
  1946. WARNING ("vTransparentScan -- bad iFormatSrc\n");
  1947. return(0);
  1948. } /*switch*/
  1949. if (ulSrc == TransparentColor)
  1950. bStop = TRUE;
  1951. iPos++;
  1952. }
  1953. return (iPos);
  1954. }
  1955. /******************************Public*Routine******************************\
  1956. * SkipScanLine
  1957. * read the scanline until it hits a non-transparent color pixel
  1958. *
  1959. * History:
  1960. * 26-Nov-1996 -by- Lingyun Wang [lingyunw]
  1961. * Wrote it.
  1962. \**************************************************************************/
  1963. ULONG SkipScanLine(
  1964. PBYTE pjSrc,
  1965. ULONG xStart,
  1966. ULONG xEnd,
  1967. ULONG iFormat,
  1968. ULONG TransparentColor,
  1969. PDIBINFO pDibInfoSrc)
  1970. {
  1971. ULONG Shift = (iFormat - 3 > 0) ? iFormat : 1;
  1972. ULONG iPos = xStart;
  1973. ULONG ulSrc;
  1974. BOOL bStop = FALSE;
  1975. pjSrc = StartPixel (pjSrc, xStart, iFormat);
  1976. //
  1977. // performance can be improved by breaking this routine into many
  1978. // dealing with different format so that we can save two comparsions
  1979. // for each pixel operation. But working set size will be large
  1980. //
  1981. //
  1982. // read one pixel at a time and compare it to the transparent color
  1983. // if it matches the transparent color, come out
  1984. //
  1985. BYTE jSrc = *pjSrc << (iPos & 0x7);
  1986. while ((iPos < xEnd) && !bStop)
  1987. {
  1988. //
  1989. // get a pixel from source and compare is to the transparent color
  1990. //
  1991. switch (iFormat)
  1992. {
  1993. case 1:
  1994. ulSrc = *pjSrc & 0x00000001;
  1995. ulSrc = (ULONG) (jSrc & 0x80);
  1996. ulSrc >>= 7;
  1997. jSrc <<= 1;
  1998. if (!(iPos & 0x00000007) )
  1999. pjSrc++;
  2000. break;
  2001. case 4:
  2002. if (iPos & 0x00000001)
  2003. {
  2004. ulSrc = *pjSrc & 0x0F;
  2005. pjSrc++;
  2006. }
  2007. else
  2008. {
  2009. ulSrc = (*pjSrc & 0xF0)>>4;
  2010. }
  2011. break;
  2012. case 8:
  2013. ulSrc = (ULONG) *pjSrc;
  2014. pjSrc++;
  2015. break;
  2016. case 16:
  2017. ulSrc = (ULONG) *((PUSHORT)pjSrc);
  2018. //
  2019. // If 5-5-5 we should mask out the 16th bit so that we'd recognize the transparent
  2020. // color
  2021. //
  2022. if ((!(pDibInfoSrc->pbmi->bmiHeader.biCompression == BI_BITFIELDS)) ||
  2023. ((*(DWORD *)&pDibInfoSrc->pbmi->bmiColors[1] == 0x03E0)))
  2024. {
  2025. ulSrc &= 0x7fff;
  2026. }
  2027. pjSrc += 2;
  2028. break;
  2029. case 24:
  2030. ulSrc = *(pjSrc + 2);
  2031. ulSrc = ulSrc << 8;
  2032. ulSrc |= (ULONG) *(pjSrc + 1);
  2033. ulSrc = ulSrc << 8;
  2034. ulSrc |= (ULONG) *pjSrc;
  2035. pjSrc += 3;
  2036. break;
  2037. case 32:
  2038. ulSrc = *(PULONG)(pjSrc);
  2039. ulSrc &= 0x00ffffff; // Ignore upper two bytes since they don't contain color information
  2040. pjSrc +=4;
  2041. break;
  2042. default:
  2043. WARNING ("vTransparentScan -- bad iFormatSrc\n");
  2044. return (0);
  2045. } /*switch*/
  2046. if (ulSrc != TransparentColor)
  2047. bStop = TRUE;
  2048. iPos++; // move to the next pixel
  2049. }
  2050. return (iPos);
  2051. }
  2052. /******************************Public*Routine******************************\
  2053. * VOID vTransparentCopyScan
  2054. *
  2055. * Read a scanline at a time and send the non-transparent pixel scans over
  2056. *
  2057. * History:
  2058. * 2-Dec-1996 -by- Lingyun Wang [lingyunw]
  2059. * Wrote it.
  2060. \**************************************************************************/
  2061. VOID vTransparentCopyScan (
  2062. PDIBINFO pDibInfoDst,
  2063. PDIBINFO pDibInfoSrc,
  2064. ULONG TransparentColor)
  2065. {
  2066. ULONG xStart;
  2067. ULONG cx = pDibInfoSrc->rclDIB.right - pDibInfoSrc->rclDIB.left;
  2068. ULONG cy = pDibInfoSrc->rclDIB.bottom - pDibInfoSrc->rclDIB.top;
  2069. ULONG xEnd;
  2070. ULONG xSrc;
  2071. ULONG ySrc = pDibInfoSrc->rclDIB.bottom;
  2072. ULONG xDst;
  2073. ULONG yDst = pDibInfoDst->rclBoundsTrim.top;
  2074. ULONG xStop, xReStart;
  2075. PBYTE pjSrc = (PBYTE)pDibInfoSrc->pvBase + pDibInfoSrc->rclDIB.top*pDibInfoSrc->stride;
  2076. //
  2077. // make the bitmap into one scanline bitmap
  2078. // since pscript will send entire bitmap over otherwise
  2079. //
  2080. LONG OldHeight = pDibInfoSrc->pbmi->bmiHeader.biHeight;
  2081. pDibInfoSrc->pbmi->bmiHeader.biHeight = 1;
  2082. while (cy--)
  2083. {
  2084. xStart = pDibInfoSrc->rclDIB.left;
  2085. xEnd = xStart + cx;
  2086. xSrc = pDibInfoSrc->rclDIB.left;
  2087. xDst = pDibInfoDst->rclBoundsTrim.left;
  2088. while (xStart < xEnd)
  2089. {
  2090. xStop = ReadScanLine((PBYTE)pjSrc,
  2091. xStart,
  2092. xEnd,
  2093. pDibInfoSrc->pbmi->bmiHeader.biBitCount,
  2094. TransparentColor,
  2095. pDibInfoSrc);
  2096. if (xStop-1 > xStart)
  2097. {
  2098. //
  2099. // send the partial scan line over
  2100. //
  2101. StretchDIBits (
  2102. pDibInfoDst->hdc,
  2103. xDst,
  2104. yDst,
  2105. xStop-xStart-1, //width
  2106. 1,
  2107. xSrc-1,
  2108. 0,
  2109. xStop-xStart-1,
  2110. 1,
  2111. (PBYTE)pjSrc,
  2112. pDibInfoSrc->pbmi,
  2113. DIB_RGB_COLORS,
  2114. SRCCOPY);
  2115. //Dprintf("StretchDIBits xDst=%x, yDst=%x, width=%x, pjSrc=%x\n",
  2116. // xDst, yDst, xStop-xStart-1,pjSrc);
  2117. }
  2118. //get to the next non transparent pixel
  2119. xReStart = SkipScanLine((PBYTE)pjSrc,
  2120. xStop-1,
  2121. xEnd,
  2122. pDibInfoSrc->pbmi->bmiHeader.biBitCount,
  2123. TransparentColor,
  2124. pDibInfoSrc);
  2125. xDst = xDst + xReStart-xStart;
  2126. xSrc = xReStart;
  2127. xStart = xReStart;
  2128. }
  2129. pjSrc += pDibInfoSrc->stride;
  2130. ySrc--;
  2131. yDst++;
  2132. }
  2133. //
  2134. // restore biHeight
  2135. //
  2136. pDibInfoSrc->pbmi->bmiHeader.biHeight = OldHeight;
  2137. //Dprintf("out of copyscan\n");
  2138. }
  2139. /******************************Public*Routine******************************\
  2140. * WinTransparentBlt
  2141. *
  2142. * Returns:
  2143. * BOOL.
  2144. *
  2145. * History:
  2146. * 09-Dec-1996 -by- Lingyun Wang [lingyunw]
  2147. * Wrote it.
  2148. \**************************************************************************/
  2149. BOOL
  2150. WinTransparentBlt(
  2151. HDC hdcDst,
  2152. int xDst,
  2153. int yDst,
  2154. int cxDst,
  2155. int cyDst,
  2156. HDC hdcSrc,
  2157. int xSrc,
  2158. int ySrc,
  2159. int cxSrc,
  2160. int cySrc,
  2161. UINT TransColor
  2162. )
  2163. {
  2164. BOOL bRet = TRUE;
  2165. DIBINFO DibInfoDst, DibInfoSrc;
  2166. PDIBINFO pDibInfoDst, pDibInfoSrc;
  2167. BOOL bReadable;
  2168. //
  2169. // parameter checking
  2170. //
  2171. if (cxDst < 0 || cyDst < 0 || cxSrc < 0 || cySrc < 0)
  2172. {
  2173. WARNING("bad parameters\n");
  2174. return (FALSE);
  2175. }
  2176. pDibInfoDst = &DibInfoDst;
  2177. ZeroMemory (pDibInfoDst, sizeof(DIBINFO));
  2178. if (!bInitDIBINFO (hdcDst, xDst, yDst, cxDst, cyDst, pDibInfoDst))
  2179. return (FALSE);
  2180. pDibInfoSrc = &DibInfoSrc;
  2181. ZeroMemory (pDibInfoSrc, sizeof(DIBINFO));
  2182. if (!bInitDIBINFO (hdcSrc, xSrc, ySrc, cxSrc, cySrc, pDibInfoSrc))
  2183. return (FALSE);
  2184. bRet = bSetupBitmapInfos (pDibInfoDst, pDibInfoSrc);
  2185. if (bRet)
  2186. {
  2187. TransColor = MapTransparentColor (pDibInfoSrc, TransColor);
  2188. bRet = bGetSrcDIBits(pDibInfoDst, pDibInfoSrc, SOURCE_TRAN, TransColor);
  2189. if (bRet)
  2190. {
  2191. // DST can be printer DC
  2192. if (pDibInfoDst->flag & PRINTER_DC)
  2193. {
  2194. bRet = TRUE;
  2195. bReadable = FALSE;
  2196. }
  2197. else
  2198. {
  2199. bRet = bGetDstDIBits (pDibInfoDst, &bReadable, SOURCE_TRAN);
  2200. }
  2201. if (bRet)
  2202. {
  2203. if (bReadable)
  2204. {
  2205. switch (pDibInfoSrc->pbmi->bmiHeader.biBitCount)
  2206. {
  2207. case 1:
  2208. // The performance of the 1BPP source case is not critical. Easiest to
  2209. // just send it through the printer code path...
  2210. vTransparentCopyScan (pDibInfoDst, pDibInfoSrc, TransColor);
  2211. break;
  2212. case 4:
  2213. if (bSameDIBformat(pDibInfoDst->pbmi,pDibInfoSrc->pbmi))
  2214. {
  2215. vTransparentIdentityCopy4 (pDibInfoDst, pDibInfoSrc, TransColor);
  2216. }
  2217. else if (pDibInfoDst->pbmi->bmiHeader.biBitCount == 4)
  2218. {
  2219. vTransparentS4D4 (pDibInfoDst, pDibInfoSrc, TransColor);
  2220. }
  2221. else if (pDibInfoDst->pbmi->bmiHeader.biBitCount == 8)
  2222. {
  2223. vTransparentS4D8(pDibInfoDst, pDibInfoSrc, TransColor);
  2224. }
  2225. else if (pDibInfoDst->pbmi->bmiHeader.biBitCount == 16)
  2226. {
  2227. vTransparentS4D16 (pDibInfoDst, pDibInfoSrc, TransColor);
  2228. }
  2229. else if (pDibInfoDst->pbmi->bmiHeader.biBitCount == 24)
  2230. {
  2231. vTransparentS4D24 (pDibInfoDst, pDibInfoSrc, TransColor);
  2232. }
  2233. else if (pDibInfoDst->pbmi->bmiHeader.biBitCount == 32)
  2234. {
  2235. vTransparentS4D32 (pDibInfoDst, pDibInfoSrc, TransColor);
  2236. }
  2237. else
  2238. { //1
  2239. vTransparentMapCopy (pDibInfoDst, pDibInfoSrc, TransColor);
  2240. }
  2241. break;
  2242. case 8:
  2243. if (bSameDIBformat(pDibInfoDst->pbmi,pDibInfoSrc->pbmi))
  2244. {
  2245. vTransparentIdentityCopy8 (pDibInfoDst, pDibInfoSrc, TransColor);
  2246. }
  2247. else if (pDibInfoDst->pbmi->bmiHeader.biBitCount == 8)
  2248. {
  2249. vTransparentS8D8 (pDibInfoDst, pDibInfoSrc, TransColor);
  2250. }
  2251. else if (pDibInfoDst->pbmi->bmiHeader.biBitCount == 16)
  2252. {
  2253. vTransparentS8D16 (pDibInfoDst, pDibInfoSrc, TransColor);
  2254. }
  2255. else if (pDibInfoDst->pbmi->bmiHeader.biBitCount == 24)
  2256. {
  2257. vTransparentS8D24 (pDibInfoDst, pDibInfoSrc, TransColor);
  2258. }
  2259. else if (pDibInfoDst->pbmi->bmiHeader.biBitCount == 32)
  2260. {
  2261. vTransparentS8D32 (pDibInfoDst, pDibInfoSrc, TransColor);
  2262. }
  2263. else
  2264. {
  2265. //1, 4
  2266. vTransparentMapCopy (pDibInfoDst, pDibInfoSrc, TransColor);
  2267. }
  2268. break;
  2269. case 16:
  2270. case 24:
  2271. case 32:
  2272. vTransparentMapCopy (pDibInfoDst, pDibInfoSrc, TransColor);
  2273. break;
  2274. default:
  2275. WARNING ("src format not currently supported\n");
  2276. bRet = FALSE;
  2277. goto CleanUp;
  2278. break;
  2279. }
  2280. //
  2281. // if we have created a temp destination DIB, send the final result to destination
  2282. // Note: do this only if we haven't called vTransparentCopyScan
  2283. //
  2284. if (pDibInfoSrc->pbmi->bmiHeader.biBitCount != 1)
  2285. {
  2286. bRet = bSendDIBINFO (hdcDst, pDibInfoDst);
  2287. }
  2288. }
  2289. else
  2290. {
  2291. //
  2292. // non-readable dest surface
  2293. //
  2294. vTransparentCopyScan (pDibInfoDst, pDibInfoSrc, TransColor);
  2295. }
  2296. }
  2297. else
  2298. {
  2299. WARNING ("GetSrcDIBits failed\n");
  2300. bRet = FALSE;
  2301. }
  2302. }
  2303. }
  2304. else
  2305. {
  2306. WARNING ("GetDstDIBits failed \n");
  2307. bRet = FALSE;
  2308. }
  2309. //
  2310. // clean up
  2311. //
  2312. CleanUp:
  2313. vCleanupDIBINFO (pDibInfoDst);
  2314. vCleanupDIBINFO (pDibInfoSrc);
  2315. return (bRet);
  2316. }
  2317. #endif
  2318. BOOL
  2319. TransparentBlt(
  2320. HDC hdcDest,
  2321. int DstX,
  2322. int DstY,
  2323. int DstCx,
  2324. int DstCy,
  2325. HDC hSrc,
  2326. int SrcX,
  2327. int SrcY,
  2328. int SrcCx,
  2329. int SrcCy,
  2330. UINT Color
  2331. )
  2332. {
  2333. BOOL bRet = FALSE;
  2334. bRet = gpfnTransparentBlt(
  2335. hdcDest,
  2336. DstX,
  2337. DstY,
  2338. DstCx,
  2339. DstCy,
  2340. (HDC)hSrc,
  2341. SrcX,
  2342. SrcY,
  2343. SrcCx,
  2344. SrcCy,
  2345. Color
  2346. );
  2347. return(bRet);
  2348. }