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.

1433 lines
29 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: tranblt.cxx
  3. *
  4. * Transparent BLT
  5. *
  6. * Created: 21-Jun-1996
  7. * Author: Mark Enstrom [marke]
  8. *
  9. * Copyright (c) 1996-1999 Microsoft Corporation
  10. \**************************************************************************/
  11. #include "precomp.hxx"
  12. /**************************************************************************\
  13. *
  14. * XLATE_TO_BGRA - match palette indexed color to BGRA
  15. *
  16. * Arguments:
  17. *
  18. *
  19. *
  20. * Return Value:
  21. *
  22. *
  23. *
  24. * History:
  25. *
  26. * 4/9/1997 Mark Enstrom [marke]
  27. *
  28. \**************************************************************************/
  29. #define XLATE_TO_BGRA(pxlo,cIndex,ulDst) \
  30. if (cIndex > pxlo->cEntries) \
  31. { \
  32. cIndex = cIndex % pxlo->cEntries; \
  33. } \
  34. \
  35. ulDst = ((XLATE *) pxlo)->ai[cIndex]
  36. /******************************Public*Routine******************************\
  37. * Routines to load a pixel and convert it to BGRA representaion for
  38. * blending operations
  39. *
  40. * Arguments:
  41. *
  42. *
  43. *
  44. * Return Value:
  45. *
  46. *
  47. *
  48. * History:
  49. *
  50. * 12/2/1996 Mark Enstrom [marke]
  51. *
  52. \**************************************************************************/
  53. VOID
  54. vLoadAndConvert1ToBGRA(
  55. PULONG pulDstAddr,
  56. PBYTE pSrcAddr,
  57. LONG SrcX,
  58. LONG SrcCx,
  59. XLATEOBJ *pxlo
  60. )
  61. {
  62. BYTE SrcByte;
  63. ASSERTGDI((pxlo->flXlate & XO_TABLE),"vLoadAndConvert1ToBGRA: xlate must be XO_TABLE");
  64. if (pxlo->flXlate & XO_TABLE)
  65. {
  66. pSrcAddr = pSrcAddr + (SrcX >> 3);
  67. LONG cxUnalignedStart = 7 & (8 - (SrcX & 7));
  68. cxUnalignedStart = MIN(SrcCx,cxUnalignedStart);
  69. //
  70. // unaligned start
  71. //
  72. if (cxUnalignedStart)
  73. {
  74. LONG iDst = 7 - (SrcX & 0x07);
  75. SrcByte = *pSrcAddr;
  76. pSrcAddr++;
  77. while (cxUnalignedStart--)
  78. {
  79. ULONG ulDst = ((SrcByte & (1 << iDst)) >> iDst);
  80. XLATE_TO_BGRA(pxlo,ulDst,ulDst);
  81. ulDst = ulDst | 0xFF000000;
  82. *pulDstAddr = ulDst;
  83. pulDstAddr++;
  84. SrcCx--;
  85. iDst--;
  86. }
  87. }
  88. //
  89. // aligned whole bytes
  90. //
  91. while (SrcCx >= 8)
  92. {
  93. ULONG ulDst;
  94. ULONG ulIndex;
  95. SrcCx -= 8;
  96. SrcByte = *pSrcAddr;
  97. ulIndex = (ULONG)((SrcByte & 0x80) >> 7);
  98. XLATE_TO_BGRA(pxlo,ulIndex,ulDst);
  99. *(pulDstAddr + 0) = ulDst | 0xff000000;
  100. ulIndex = ((SrcByte & 0x40) >> 6);
  101. XLATE_TO_BGRA(pxlo,ulIndex,ulDst);
  102. *(pulDstAddr + 1) = ulDst | 0xff000000;
  103. ulIndex = ((SrcByte & 0x20) >> 5);
  104. XLATE_TO_BGRA(pxlo,ulIndex,ulDst);
  105. *(pulDstAddr + 2) = ulDst | 0xff000000;
  106. ulIndex = ((SrcByte & 0x10) >> 4);
  107. XLATE_TO_BGRA(pxlo,ulIndex,ulDst);
  108. *(pulDstAddr + 3) = ulDst | 0xff000000;
  109. ulIndex = ((SrcByte & 0x08) >> 3);
  110. XLATE_TO_BGRA(pxlo,ulIndex,ulDst);
  111. *(pulDstAddr + 4) = ulDst | 0xff000000;
  112. ulIndex = ((SrcByte & 0x04) >> 2);
  113. XLATE_TO_BGRA(pxlo,ulIndex,ulDst);
  114. *(pulDstAddr + 5) = ulDst | 0xff000000;
  115. ulIndex = ((SrcByte & 0x02) >> 1);
  116. XLATE_TO_BGRA(pxlo,ulIndex,ulDst);
  117. *(pulDstAddr + 6) = ulDst | 0xff000000;
  118. ulIndex = ((SrcByte & 0x01) >> 0);
  119. XLATE_TO_BGRA(pxlo,ulIndex,ulDst);
  120. *(pulDstAddr + 7) = ulDst | 0xff000000;
  121. pSrcAddr++;
  122. pulDstAddr+=8;
  123. }
  124. //
  125. // unaligned end
  126. //
  127. if (SrcCx)
  128. {
  129. BYTE SrcByte = *pSrcAddr;
  130. LONG iDst = 7;
  131. while (SrcCx)
  132. {
  133. ULONG ulDst = ((SrcByte & (1 << iDst)) >> iDst);
  134. XLATE_TO_BGRA(pxlo,ulDst,ulDst);
  135. *pulDstAddr = ulDst | 0xff000000;
  136. pulDstAddr++;
  137. SrcCx--;
  138. iDst--;
  139. }
  140. }
  141. }
  142. }
  143. /**************************************************************************\
  144. * vLoadAndConvert4ToBGRA
  145. *
  146. *
  147. * Arguments:
  148. *
  149. *
  150. *
  151. * Return Value:
  152. *
  153. *
  154. *
  155. * History:
  156. *
  157. * 1/22/1997 Mark Enstrom [marke]
  158. *
  159. \**************************************************************************/
  160. VOID
  161. vLoadAndConvert4ToBGRA(
  162. PULONG pulDstAddr,
  163. PBYTE pSrcAddr,
  164. LONG SrcX,
  165. LONG SrcCx,
  166. XLATEOBJ *pxlo
  167. )
  168. {
  169. ASSERTGDI((pxlo->flXlate & XO_TABLE),"vLoadAndConvert1ToBGRA: xlate must be XO_TABLE");
  170. if (pxlo->flXlate & XO_TABLE)
  171. {
  172. ULONG ulIndex;
  173. ULONG ulDst;
  174. BYTE SrcByte;
  175. LONG cxUnalignedStart;
  176. pSrcAddr = pSrcAddr + (SrcX >> 1);
  177. cxUnalignedStart = 1 & (2 - (SrcX & 1));
  178. cxUnalignedStart = MIN(SrcCx,cxUnalignedStart);
  179. //
  180. // unaligned start
  181. //
  182. if (cxUnalignedStart)
  183. {
  184. SrcByte = *pSrcAddr;
  185. ulIndex = (SrcByte & 0x0f);
  186. XLATE_TO_BGRA(pxlo,ulIndex,ulDst);
  187. *pulDstAddr = ulDst | 0xff000000;
  188. pSrcAddr++;
  189. pulDstAddr++;
  190. SrcCx--;
  191. }
  192. //
  193. // aligned whole bytes
  194. //
  195. while (SrcCx >= 2)
  196. {
  197. SrcCx -= 2;
  198. SrcByte = *pSrcAddr;
  199. ulIndex = (SrcByte >> 4);
  200. XLATE_TO_BGRA(pxlo,ulIndex,ulDst);
  201. *(pulDstAddr + 0) = ulDst | 0xff000000;
  202. ulIndex = (SrcByte & 0x0f);
  203. XLATE_TO_BGRA(pxlo,ulIndex,ulDst);
  204. *(pulDstAddr + 1) = ulDst | 0xff000000;
  205. pSrcAddr++;
  206. pulDstAddr+=2;
  207. }
  208. //
  209. // unaligned end
  210. //
  211. if (SrcCx)
  212. {
  213. SrcByte = *pSrcAddr;
  214. ulIndex = (SrcByte >> 4);
  215. XLATE_TO_BGRA(pxlo,ulIndex,ulDst);
  216. *pulDstAddr = ulDst | 0xff000000;
  217. }
  218. }
  219. }
  220. /**************************************************************************\
  221. * vLoadAndConvert8ToBGRA
  222. *
  223. *
  224. * Arguments:
  225. *
  226. *
  227. *
  228. * Return Value:
  229. *
  230. *
  231. *
  232. * History:
  233. *
  234. * 1/22/1997 Mark Enstrom [marke]
  235. *
  236. \**************************************************************************/
  237. VOID
  238. vLoadAndConvert8ToBGRA(
  239. PULONG pulDstAddr,
  240. PBYTE pSrcAddr,
  241. LONG SrcX,
  242. LONG SrcCx,
  243. XLATEOBJ *pxlo
  244. )
  245. {
  246. ASSERTGDI((pxlo->flXlate & XO_TABLE),"vLoadAndConvert1ToBGRA: xlate must be XO_TABLE");
  247. if (pxlo->flXlate & XO_TABLE)
  248. {
  249. PBYTE pjSrc = pSrcAddr + SrcX;
  250. PBYTE pjEnd = pjSrc + SrcCx;
  251. while (pjSrc != pjEnd)
  252. {
  253. ALPHAPIX apix;
  254. BYTE jTemp;
  255. ULONG ulDst;
  256. ulDst = (ULONG)*pjSrc;
  257. XLATE_TO_BGRA(pxlo,ulDst,ulDst);
  258. apix.ul = ulDst | 0xff000000;
  259. *pulDstAddr = apix.ul;
  260. pulDstAddr++;
  261. pjSrc++;
  262. }
  263. }
  264. }
  265. /**************************************************************************\
  266. * vLoadAndConvertRGB16_565ToBGRA
  267. *
  268. *
  269. * Arguments:
  270. *
  271. *
  272. *
  273. * Return Value:
  274. *
  275. *
  276. *
  277. * History:
  278. *
  279. * 1/22/1997 Mark Enstrom [marke]
  280. *
  281. \**************************************************************************/
  282. VOID
  283. vLoadAndConvertRGB16_565ToBGRA(
  284. PULONG pulDstAddr,
  285. PBYTE pSrcAddr,
  286. LONG SrcX,
  287. LONG SrcCx,
  288. XLATEOBJ *pxlo
  289. )
  290. {
  291. PUSHORT pusSrc = (PUSHORT)pSrcAddr + SrcX;
  292. ULONG ul;
  293. //
  294. // unaligned single at start
  295. //
  296. if ((ULONG_PTR)pusSrc & 0x02)
  297. {
  298. ul = *pusSrc;
  299. *pulDstAddr = (((ul << 8) & 0xf80000)
  300. | ((ul << 3) & 0x070000)
  301. | ((ul << 5) & 0x00fc00)
  302. | ((ul >> 1) & 0x000300)
  303. | ((ul << 3) & 0x0000f8)
  304. | ((ul >> 2) & 0x000007)
  305. | 0xff000000);
  306. pusSrc++;
  307. pulDstAddr++;
  308. SrcCx--;
  309. }
  310. //
  311. // aligned
  312. //
  313. PUSHORT pusEnd = pusSrc + (SrcCx & ~1);
  314. while (pusSrc != pusEnd)
  315. {
  316. ul = *(PULONG)pusSrc;
  317. *pulDstAddr = (((ul << 8) & 0xf80000)
  318. | ((ul << 3) & 0x070000)
  319. | ((ul << 5) & 0x00fc00)
  320. | ((ul >> 1) & 0x000300)
  321. | ((ul << 3) & 0x0000f8)
  322. | ((ul >> 2) & 0x000007)
  323. | 0xff000000);
  324. *(pulDstAddr+1) = (((ul >> 8) & 0xf80000)
  325. | ((ul >> 13) & 0x070000)
  326. | ((ul >> 11) & 0x00fc00)
  327. | ((ul >> 17) & 0x000300)
  328. | ((ul >> 13) & 0x0000f8)
  329. | ((ul >> 18) & 0x000007)
  330. | 0xff000000);
  331. pusSrc+= 2;
  332. pulDstAddr+=2;
  333. }
  334. //
  335. // end unaligned
  336. //
  337. if (SrcCx & 1)
  338. {
  339. ul = *pusSrc;
  340. *pulDstAddr = (((ul << 8) & 0xf80000)
  341. | ((ul << 3) & 0x070000)
  342. | ((ul << 5) & 0x00fc00)
  343. | ((ul >> 1) & 0x000300)
  344. | ((ul << 3) & 0x0000f8)
  345. | ((ul >> 2) & 0x000007)
  346. | 0xff000000);
  347. }
  348. }
  349. /**************************************************************************\
  350. * vLoadAndConvertRGB16_555ToBGRA
  351. *
  352. *
  353. * Arguments:
  354. *
  355. *
  356. *
  357. * Return Value:
  358. *
  359. *
  360. *
  361. * History:
  362. *
  363. * 1/22/1997 Mark Enstrom [marke]
  364. *
  365. \**************************************************************************/
  366. VOID
  367. vLoadAndConvertRGB16_555ToBGRA(
  368. PULONG pulDstAddr,
  369. PBYTE pSrcAddr,
  370. LONG SrcX,
  371. LONG SrcCx,
  372. XLATEOBJ *pxlo
  373. )
  374. {
  375. PUSHORT pusSrc = (PUSHORT)pSrcAddr + SrcX;
  376. ULONG ul;
  377. //
  378. // unaligned single at start
  379. //
  380. if ((ULONG_PTR)pusSrc & 0x02)
  381. {
  382. ul = *pusSrc;
  383. *pulDstAddr = (((ul << 9) & 0xf80000)
  384. | ((ul << 4) & 0x070000)
  385. | ((ul << 6) & 0x00f800)
  386. | ((ul << 1) & 0x000700)
  387. | ((ul << 3) & 0x0000f8)
  388. | ((ul >> 2) & 0x000007)
  389. | 0xff000000);
  390. pusSrc++;
  391. pulDstAddr++;
  392. SrcCx--;
  393. }
  394. //
  395. // aligned
  396. //
  397. PUSHORT pusEnd = pusSrc + (SrcCx & ~1);
  398. while (pusSrc != pusEnd)
  399. {
  400. ULONG ul = *(PULONG)pusSrc;
  401. *pulDstAddr = (((ul << 9) & 0xf80000)
  402. | ((ul << 4) & 0x070000)
  403. | ((ul << 6) & 0x00f800)
  404. | ((ul << 1) & 0x000700)
  405. | ((ul << 3) & 0x0000f8)
  406. | ((ul >> 2) & 0x000007)
  407. | 0xff000000);
  408. *(pulDstAddr+1) = (((ul >> 7) & 0xf80000)
  409. | ((ul >> 12) & 0x070000)
  410. | ((ul >> 10) & 0x00f800)
  411. | ((ul >> 15) & 0x000700)
  412. | ((ul >> 13) & 0x0000f8)
  413. | ((ul >> 18) & 0x000007)
  414. | 0xff000000);
  415. pusSrc+= 2;
  416. pulDstAddr+=2;
  417. }
  418. //
  419. // end unaligned
  420. //
  421. if (SrcCx & 1)
  422. {
  423. ul = *pusSrc;
  424. *pulDstAddr = (((ul << 9) & 0xf80000)
  425. | ((ul << 4) & 0x070000)
  426. | ((ul << 6) & 0x00f800)
  427. | ((ul << 1) & 0x000700)
  428. | ((ul << 3) & 0x0000f8)
  429. | ((ul >> 2) & 0x000007)
  430. | 0xff000000);
  431. }
  432. }
  433. /**************************************************************************\
  434. * vLoadAndConvert16BitfieldsToBGRA
  435. *
  436. *
  437. * Arguments:
  438. *
  439. *
  440. *
  441. * Return Value:
  442. *
  443. *
  444. *
  445. * History:
  446. *
  447. * 1/22/1997 Mark Enstrom [marke]
  448. *
  449. \**************************************************************************/
  450. VOID
  451. vLoadAndConvert16BitfieldsToBGRA(
  452. PULONG pulDstAddr,
  453. PBYTE pSrcAddr,
  454. LONG SrcX,
  455. LONG SrcCx,
  456. XLATEOBJ *pxlo
  457. )
  458. {
  459. PUSHORT pusSrc = (PUSHORT)pSrcAddr + SrcX;
  460. PUSHORT pusEnd = pusSrc + SrcCx;
  461. while (pusSrc != pusEnd)
  462. {
  463. ULONG ulTmp;
  464. ulTmp = *pusSrc;
  465. ulTmp = (((XLATE *)pxlo)->ulTranslate(ulTmp));
  466. *pulDstAddr = ulTmp | 0xff000000;
  467. pusSrc++;
  468. pulDstAddr++;
  469. }
  470. }
  471. /**************************************************************************\
  472. * vLoadAndConvertRGB24ToBGRA
  473. *
  474. *
  475. * Arguments:
  476. *
  477. *
  478. *
  479. * Return Value:
  480. *
  481. *
  482. *
  483. * History:
  484. *
  485. * 1/22/1997 Mark Enstrom [marke]
  486. *
  487. \**************************************************************************/
  488. VOID
  489. vLoadAndConvertRGB24ToBGRA(
  490. PULONG pulDstAddr,
  491. PBYTE pSrcAddr,
  492. LONG SrcX,
  493. LONG SrcCx,
  494. XLATEOBJ *pxlo
  495. )
  496. {
  497. PBYTE pjSrc = pSrcAddr + 3 * SrcX;
  498. PBYTE pjEnd = pjSrc + 3 * SrcCx;
  499. while (pjSrc != pjEnd)
  500. {
  501. ALPHAPIX pixRet;
  502. pixRet.pix.r = *(((PBYTE)pjSrc));
  503. pixRet.pix.g = *(((PBYTE)pjSrc)+1);
  504. pixRet.pix.b = *(((PBYTE)pjSrc)+2);
  505. pixRet.pix.a = 0xff;
  506. *pulDstAddr = pixRet.ul;
  507. pjSrc += 3;
  508. pulDstAddr++;
  509. }
  510. }
  511. /**************************************************************************\
  512. * vLoadAndConvertBGR24ToBGRA
  513. *
  514. *
  515. * Arguments:
  516. *
  517. *
  518. *
  519. * Return Value:
  520. *
  521. *
  522. *
  523. * History:
  524. *
  525. * 5/4/2000 bhouse
  526. *
  527. \**************************************************************************/
  528. VOID
  529. vLoadAndConvertBGR24ToBGRA(
  530. PULONG pulDstAddr,
  531. PBYTE pSrcAddr,
  532. LONG SrcX,
  533. LONG SrcCx,
  534. XLATEOBJ *pxlo
  535. )
  536. {
  537. PBYTE pjSrc = pSrcAddr + 3 * SrcX;
  538. PBYTE pjEnd = pjSrc + 3 * SrcCx;
  539. while (pjSrc != pjEnd)
  540. {
  541. ALPHAPIX pixRet;
  542. pixRet.pix.b = *(((PBYTE)pjSrc));
  543. pixRet.pix.g = *(((PBYTE)pjSrc)+1);
  544. pixRet.pix.r = *(((PBYTE)pjSrc)+2);
  545. pixRet.pix.a = 0xff;
  546. *pulDstAddr = pixRet.ul;
  547. pjSrc += 3;
  548. pulDstAddr++;
  549. }
  550. }
  551. /**************************************************************************\
  552. * vLoadAndConvertRGB32ToBGRA
  553. *
  554. *
  555. * Arguments:
  556. *
  557. *
  558. *
  559. * Return Value:
  560. *
  561. *
  562. *
  563. * History:
  564. *
  565. * 1/22/1997 Mark Enstrom [marke]
  566. *
  567. \**************************************************************************/
  568. VOID
  569. vLoadAndConvertRGB32ToBGRA(
  570. PULONG pulDstAddr,
  571. PBYTE pSrcAddr,
  572. LONG SrcX,
  573. LONG SrcCx,
  574. XLATEOBJ *pxlo
  575. )
  576. {
  577. PULONG pulSrc = (PULONG)pSrcAddr + SrcX;
  578. PULONG pulEnd = pulSrc + SrcCx;
  579. while (pulSrc != pulEnd)
  580. {
  581. ALPHAPIX pixIn;
  582. ALPHAPIX pixOut;
  583. pixIn.ul = *pulSrc;
  584. pixOut.pix.r = pixIn.pix.b;
  585. pixOut.pix.g = pixIn.pix.g;
  586. pixOut.pix.b = pixIn.pix.r;
  587. pixOut.pix.a = 0xff;
  588. *pulDstAddr = pixOut.ul;
  589. pulSrc++;
  590. pulDstAddr++;
  591. }
  592. }
  593. /**************************************************************************\
  594. * vLoadAndConvert32BitfieldsToBGRA
  595. *
  596. *
  597. * Arguments:
  598. *
  599. *
  600. *
  601. * Return Value:
  602. *
  603. *
  604. *
  605. * History:
  606. *
  607. * 1/22/1997 Mark Enstrom [marke]
  608. *
  609. \**************************************************************************/
  610. VOID
  611. vLoadAndConvert32BitfieldsToBGRA(
  612. PULONG pulDstAddr,
  613. PBYTE pSrcAddr,
  614. LONG SrcX,
  615. LONG SrcCx,
  616. XLATEOBJ *pxlo
  617. )
  618. {
  619. PULONG pulSrc = (PULONG)pSrcAddr + SrcX;
  620. PULONG pulEnd = pulSrc + SrcCx;
  621. while (pulSrc != pulEnd)
  622. {
  623. ULONG ulTmp;
  624. ulTmp = *pulSrc;
  625. ulTmp = (((XLATE *)pxlo)->ulTranslate(ulTmp));
  626. ulTmp |= 0xff000000;
  627. *pulDstAddr = ulTmp;
  628. pulSrc++;
  629. pulDstAddr++;
  630. }
  631. }
  632. //
  633. //
  634. // STORE ROUTINES
  635. //
  636. //
  637. #define PALETTE_MATCH(pixIn,ppalDst,ppalDstDC) \
  638. { \
  639. BYTE jSwap; \
  640. \
  641. pixIn.pix.a = 0x02; \
  642. jSwap = pixIn.pix.r; \
  643. pixIn.pix.r = pixIn.pix.b; \
  644. pixIn.pix.b = jSwap; \
  645. \
  646. pixIn.ul = ulGetNearestIndexFromColorref( \
  647. ppalDst, \
  648. ppalDstDC, \
  649. pixIn.ul, \
  650. ppalDst.cEntries() ? \
  651. SE_DO_SEARCH_EXACT_FIRST : \
  652. SE_DONT_SEARCH_EXACT_FIRST \
  653. \
  654. ); \
  655. } \
  656. /**************************************************************************\
  657. * vConvertAndSaveBGRATo1
  658. *
  659. *
  660. * Arguments:
  661. *
  662. *
  663. *
  664. * Return Value:
  665. *
  666. *
  667. *
  668. * History:
  669. *
  670. * 1/22/1997 Mark Enstrom [marke]
  671. *
  672. \**************************************************************************/
  673. VOID
  674. vConvertAndSaveBGRATo1(
  675. PBYTE pDst,
  676. PULONG pulSrc,
  677. LONG cx,
  678. LONG DstX,
  679. XLATEOBJ *pxlo,
  680. XEPALOBJ ppalDst,
  681. XEPALOBJ ppalDstDC
  682. )
  683. {
  684. PBYTE pjDst = pDst + (DstX >> 3);
  685. LONG iDst = DstX & 7;
  686. //
  687. // unaligned byte
  688. //
  689. if (iDst)
  690. {
  691. BYTE DstByte = *pjDst;
  692. LONG iShift = 7 - iDst;
  693. LONG cxUnaligned = iShift + 1;
  694. cxUnaligned = MIN(cxUnaligned,cx);
  695. cx -= cxUnaligned;
  696. while (cxUnaligned--)
  697. {
  698. ALPHAPIX pixIn;
  699. pixIn.ul = *pulSrc;
  700. PALETTE_MATCH(pixIn,ppalDst,ppalDstDC);
  701. pixIn.ul = pixIn.ul << iShift;
  702. DstByte = DstByte & (~(1 << iShift));
  703. DstByte |= (BYTE)pixIn.ul;
  704. pulSrc++;
  705. iShift--;
  706. }
  707. *pjDst = DstByte;
  708. pjDst++;
  709. }
  710. //
  711. // aligned whole bytes
  712. //
  713. while (cx >= 8)
  714. {
  715. ALPHAPIX pixIn;
  716. BYTE DstByte;
  717. pixIn.ul = *pulSrc;
  718. PALETTE_MATCH(pixIn,ppalDst,ppalDstDC);
  719. DstByte = (BYTE)(pixIn.ul << 7);
  720. pixIn.ul = *(pulSrc+1);
  721. PALETTE_MATCH(pixIn,ppalDst,ppalDstDC);
  722. DstByte |= (BYTE)(pixIn.ul << 6);
  723. pixIn.ul = *(pulSrc+2);
  724. PALETTE_MATCH(pixIn,ppalDst,ppalDstDC);
  725. DstByte |= (BYTE)(pixIn.ul << 5);
  726. pixIn.ul = *(pulSrc+3);
  727. PALETTE_MATCH(pixIn,ppalDst,ppalDstDC);
  728. DstByte |= (BYTE)(pixIn.ul << 4);
  729. pixIn.ul = *(pulSrc+4);
  730. PALETTE_MATCH(pixIn,ppalDst,ppalDstDC);
  731. DstByte |= (BYTE)(pixIn.ul << 3);
  732. pixIn.ul = *(pulSrc+5);
  733. PALETTE_MATCH(pixIn,ppalDst,ppalDstDC);
  734. DstByte |= (BYTE)(pixIn.ul << 2);
  735. pixIn.ul = *(pulSrc+6);
  736. PALETTE_MATCH(pixIn,ppalDst,ppalDstDC);
  737. DstByte |= (BYTE)(pixIn.ul << 1);
  738. pixIn.ul = *(pulSrc+7);
  739. PALETTE_MATCH(pixIn,ppalDst,ppalDstDC);
  740. DstByte |= (BYTE)(pixIn.ul << 0);
  741. *pjDst = DstByte;
  742. pjDst++;
  743. pulSrc += 8;
  744. cx -= 8;
  745. }
  746. //
  747. // unaligned end
  748. //
  749. if (cx)
  750. {
  751. BYTE iShift = 7;
  752. BYTE DstByte = *pjDst;
  753. while (cx--)
  754. {
  755. ALPHAPIX pixIn;
  756. pixIn.ul = *pulSrc;
  757. PALETTE_MATCH(pixIn,ppalDst,ppalDstDC);
  758. pixIn.ul = pixIn.ul << iShift;
  759. DstByte = DstByte & (~(1 << iShift));
  760. DstByte |= (BYTE)pixIn.ul;
  761. pulSrc++;
  762. iShift--;
  763. }
  764. *pjDst = DstByte;
  765. }
  766. }
  767. /**************************************************************************\
  768. * vConvertAndSaveBGRATo4
  769. *
  770. *
  771. * Arguments:
  772. *
  773. *
  774. *
  775. * Return Value:
  776. *
  777. *
  778. *
  779. * History:
  780. *
  781. * 1/22/1997 Mark Enstrom [marke]
  782. *
  783. \**************************************************************************/
  784. VOID
  785. vConvertAndSaveBGRATo4(
  786. PBYTE pDst,
  787. PULONG pulSrc,
  788. LONG cx,
  789. LONG DstX,
  790. XLATEOBJ *pxlo,
  791. XEPALOBJ ppalDst,
  792. XEPALOBJ ppalDstDC
  793. )
  794. {
  795. PBYTE pjDst = pDst + (DstX >> 1);
  796. LONG iDst = DstX & 1;
  797. PBYTE pxlate = XLATEOBJ_pGetXlate555(pxlo);
  798. if (pxlate == NULL)
  799. {
  800. WARNING("vConvertAndSaveBGRA: To4Failed to generate rgb333 xlate table\n");
  801. return;
  802. }
  803. //
  804. // make sure params are valid
  805. //
  806. if (cx == 0)
  807. {
  808. return;
  809. }
  810. //
  811. // unaligned byte
  812. //
  813. if (iDst)
  814. {
  815. BYTE DstByte = *pjDst;
  816. ALPHAPIX pixIn;
  817. pixIn.ul = *pulSrc;
  818. pixIn.ul = XLATEOBJ_BGR32ToPalSurf(pxlo,pxlate,pixIn.ul);
  819. DstByte = (DstByte & 0xf0) | (BYTE)pixIn.ul;
  820. *pjDst = DstByte;
  821. pjDst++;
  822. pulSrc++;
  823. cx--;
  824. }
  825. //
  826. // aligned whole bytes
  827. //
  828. while (cx >= 2)
  829. {
  830. BYTE DstByte;
  831. ALPHAPIX pixIn;
  832. pixIn.ul = *pulSrc;
  833. pixIn.ul = XLATEOBJ_BGR32ToPalSurf(pxlo,pxlate,pixIn.ul);
  834. DstByte = (BYTE)(pixIn.ul << 4);
  835. pixIn.ul = *(pulSrc+1);
  836. pixIn.ul = XLATEOBJ_BGR32ToPalSurf(pxlo,pxlate,pixIn.ul);
  837. DstByte |= (BYTE)(pixIn.ul);
  838. *pjDst = DstByte;
  839. pjDst++;
  840. pulSrc += 2;
  841. cx -= 2;
  842. }
  843. //
  844. // unaligned end
  845. //
  846. if (cx)
  847. {
  848. BYTE DstByte = *pjDst;
  849. ALPHAPIX pixIn;
  850. pixIn.ul = *pulSrc;
  851. pixIn.ul = XLATEOBJ_BGR32ToPalSurf(pxlo,pxlate,pixIn.ul);
  852. DstByte = (DstByte & 0x0f) | (BYTE)(pixIn.ul << 4);
  853. *pjDst = DstByte;
  854. }
  855. }
  856. /**************************************************************************\
  857. * vConvertAndSaveBGRATo8
  858. *
  859. *
  860. * Arguments:
  861. *
  862. *
  863. *
  864. * Return Value:
  865. *
  866. *
  867. *
  868. * History:
  869. *
  870. * 1/22/1997 Mark Enstrom [marke]
  871. *
  872. \**************************************************************************/
  873. VOID
  874. vConvertAndSaveBGRATo8(
  875. PBYTE pDst,
  876. PULONG pulSrc,
  877. LONG cx,
  878. LONG DstX,
  879. XLATEOBJ *pxlo,
  880. XEPALOBJ ppalDst,
  881. XEPALOBJ ppalDstDC
  882. )
  883. {
  884. PBYTE pxlate = XLATEOBJ_pGetXlate555(pxlo);
  885. if (pxlate == NULL)
  886. {
  887. WARNING("vConvertAndSaveBGRATo8: Failed to generate rgb333 xlate table\n");
  888. return;
  889. }
  890. PBYTE pjDst = (PBYTE)pDst + DstX;
  891. PBYTE pjEnd = pjDst + cx;
  892. while (pjDst != pjEnd)
  893. {
  894. ALPHAPIX pixIn;
  895. pixIn.ul = *pulSrc;
  896. pixIn.ul = XLATEOBJ_BGR32ToPalSurf(pxlo,pxlate,pixIn.ul);
  897. *pjDst = (BYTE)pixIn.ul;
  898. pulSrc++;
  899. pjDst++;
  900. }
  901. }
  902. /**************************************************************************\
  903. * vConvertAndSaveBGRAToRGB16_565
  904. *
  905. *
  906. * Arguments:
  907. *
  908. *
  909. *
  910. * Return Value:
  911. *
  912. *
  913. *
  914. * History:
  915. *
  916. * 1/22/1997 Mark Enstrom [marke]
  917. *
  918. \**************************************************************************/
  919. VOID
  920. vConvertAndSaveBGRAToRGB16_565(
  921. PBYTE pjDst,
  922. PULONG pulSrc,
  923. LONG cx,
  924. LONG DstX,
  925. XLATEOBJ *pxlo,
  926. XEPALOBJ ppalDst,
  927. XEPALOBJ ppalDstDC
  928. )
  929. {
  930. PUSHORT pusDst = (PUSHORT)pjDst + DstX;
  931. PUSHORT pusEnd = pusDst + cx;
  932. while (pusDst != pusEnd)
  933. {
  934. ALPHAPIX pixIn;
  935. ALPHAPIX pixOut;
  936. pixIn.ul = *pulSrc;
  937. pixOut.ul = ((pixIn.pix.r & 0xf8) << 8) |
  938. ((pixIn.pix.g & 0xfc) << 3) |
  939. ((pixIn.pix.b & 0xf8) >> 3);
  940. *pusDst = (USHORT)pixOut.ul;
  941. pulSrc++;
  942. pusDst++;
  943. }
  944. }
  945. /**************************************************************************\
  946. * vConvertAndSaveBGRAToRGB16_555
  947. *
  948. *
  949. * Arguments:
  950. *
  951. *
  952. *
  953. * Return Value:
  954. *
  955. *
  956. *
  957. * History:
  958. *
  959. * 1/22/1997 Mark Enstrom [marke]
  960. *
  961. \**************************************************************************/
  962. VOID
  963. vConvertAndSaveBGRAToRGB16_555(
  964. PBYTE pjDst,
  965. PULONG pulSrc,
  966. LONG cx,
  967. LONG DstX,
  968. XLATEOBJ *pxlo,
  969. XEPALOBJ ppalDst,
  970. XEPALOBJ ppalDstDC
  971. )
  972. {
  973. PUSHORT pusDst = (PUSHORT)pjDst + DstX;
  974. PUSHORT pusEnd = pusDst + cx;
  975. while (pusDst != pusEnd)
  976. {
  977. ALPHAPIX pixIn;
  978. ALPHAPIX pixOut;
  979. pixIn.ul = *pulSrc;
  980. pixOut.ul = ((pixIn.pix.r & 0xf8) << 7) |
  981. ((pixIn.pix.g & 0xf8) << 2) |
  982. ((pixIn.pix.b & 0xf8) >> 3);
  983. *pusDst = (USHORT)pixOut.ul;
  984. pulSrc++;
  985. pusDst++;
  986. }
  987. }
  988. /**************************************************************************\
  989. * vConvertAndSaveBGRATo16Bitfields
  990. *
  991. *
  992. * Arguments:
  993. *
  994. *
  995. *
  996. * Return Value:
  997. *
  998. *
  999. *
  1000. * History:
  1001. *
  1002. * 1/22/1997 Mark Enstrom [marke]
  1003. *
  1004. \**************************************************************************/
  1005. VOID
  1006. vConvertAndSaveBGRAToRGB16Bitfields(
  1007. PBYTE pjDst,
  1008. PULONG pulSrc,
  1009. LONG cx,
  1010. LONG DstX,
  1011. XLATEOBJ *pxlo,
  1012. XEPALOBJ ppalDst,
  1013. XEPALOBJ ppalDstDC
  1014. )
  1015. {
  1016. PUSHORT pusDst = (PUSHORT)pjDst + DstX;
  1017. PUSHORT pusEnd = pusDst + cx;
  1018. while (pusDst != pusEnd)
  1019. {
  1020. ALPHAPIX pixIn;
  1021. ALPHAPIX pixOut;
  1022. pixIn.ul = *pulSrc;
  1023. pixOut.ul = (((XLATE *)pxlo)->ulTranslate(pixIn.ul));
  1024. *pusDst = (USHORT)pixOut.ul;
  1025. pulSrc++;
  1026. pusDst++;
  1027. }
  1028. }
  1029. /**************************************************************************\
  1030. * vConvertAndSaveBGRAToRGB24
  1031. *
  1032. *
  1033. * Arguments:
  1034. *
  1035. *
  1036. *
  1037. * Return Value:
  1038. *
  1039. *
  1040. *
  1041. * History:
  1042. *
  1043. * 1/22/1997 Mark Enstrom [marke]
  1044. *
  1045. \**************************************************************************/
  1046. VOID
  1047. vConvertAndSaveBGRAToRGB24(
  1048. PBYTE pDst,
  1049. PULONG pulSrc,
  1050. LONG cx,
  1051. LONG DstX,
  1052. XLATEOBJ *pxlo,
  1053. XEPALOBJ ppalDst,
  1054. XEPALOBJ ppalDstDC
  1055. )
  1056. {
  1057. PBYTE pjDst = (PBYTE)pDst + (3 * DstX);
  1058. PBYTE pjEnd = pjDst + (3 * cx);
  1059. while (pjDst != pjEnd)
  1060. {
  1061. ALPHAPIX pixIn;
  1062. pixIn.ul = *pulSrc;
  1063. *pjDst = pixIn.pix.r;
  1064. *(pjDst+1) = pixIn.pix.g;
  1065. *(pjDst+2) = pixIn.pix.b;
  1066. pulSrc++;
  1067. pjDst+=3;
  1068. }
  1069. }
  1070. /**************************************************************************\
  1071. * vConvertAndSaveBGRAToBGR24
  1072. *
  1073. *
  1074. * Arguments:
  1075. *
  1076. *
  1077. *
  1078. * Return Value:
  1079. *
  1080. *
  1081. *
  1082. * History:
  1083. *
  1084. * 5/4/2000 bhouse
  1085. *
  1086. \**************************************************************************/
  1087. VOID
  1088. vConvertAndSaveBGRAToBGR24(
  1089. PBYTE pDst,
  1090. PULONG pulSrc,
  1091. LONG cx,
  1092. LONG DstX,
  1093. XLATEOBJ *pxlo,
  1094. XEPALOBJ ppalDst,
  1095. XEPALOBJ ppalDstDC
  1096. )
  1097. {
  1098. PBYTE pjDst = (PBYTE)pDst + (3 * DstX);
  1099. PBYTE pjEnd = pjDst + (3 * cx);
  1100. while (pjDst != pjEnd)
  1101. {
  1102. ALPHAPIX pixIn;
  1103. pixIn.ul = *pulSrc;
  1104. *pjDst = pixIn.pix.b;
  1105. *(pjDst+1) = pixIn.pix.g;
  1106. *(pjDst+2) = pixIn.pix.r;
  1107. pulSrc++;
  1108. pjDst+=3;
  1109. }
  1110. }
  1111. /**************************************************************************\
  1112. * vConvertAndSaveBGRATo32Bitfields
  1113. *
  1114. *
  1115. * Arguments:
  1116. *
  1117. *
  1118. *
  1119. * Return Value:
  1120. *
  1121. *
  1122. *
  1123. * History:
  1124. *
  1125. * 1/22/1997 Mark Enstrom [marke]
  1126. *
  1127. \**************************************************************************/
  1128. VOID
  1129. vConvertAndSaveBGRATo32Bitfields(
  1130. PBYTE pjDst,
  1131. PULONG pulSrc,
  1132. LONG cx,
  1133. LONG DstX,
  1134. XLATEOBJ *pxlo,
  1135. XEPALOBJ ppalDst,
  1136. XEPALOBJ ppalDstDC
  1137. )
  1138. {
  1139. PULONG pulDst = (PULONG)pjDst + DstX;
  1140. PULONG pulEnd = pulDst + cx;
  1141. while (pulDst != pulEnd)
  1142. {
  1143. ALPHAPIX pixIn;
  1144. ALPHAPIX pixOut;
  1145. pixIn.ul = *pulSrc;
  1146. pixOut.ul = (((XLATE *)pxlo)->ulTranslate(pixIn.ul));
  1147. *pulDst = pixOut.ul;
  1148. pulSrc++;
  1149. pulDst++;
  1150. }
  1151. }
  1152. /**************************************************************************\
  1153. * vConvertAndSaveBGRAToRGB32
  1154. *
  1155. *
  1156. * Arguments:
  1157. *
  1158. *
  1159. *
  1160. * Return Value:
  1161. *
  1162. *
  1163. *
  1164. * History:
  1165. *
  1166. * 1/22/1997 Mark Enstrom [marke]
  1167. *
  1168. \**************************************************************************/
  1169. VOID
  1170. vConvertAndSaveBGRAToRGB32(
  1171. PBYTE pjDst,
  1172. PULONG pulSrc,
  1173. LONG cx,
  1174. LONG DstX,
  1175. XLATEOBJ *pxlo,
  1176. XEPALOBJ ppalDst,
  1177. XEPALOBJ ppalDstDC
  1178. )
  1179. {
  1180. PULONG pulDst = (PULONG)pjDst + DstX;
  1181. PULONG pulEnd = pulDst + cx;
  1182. while (pulDst != pulEnd)
  1183. {
  1184. ALPHAPIX pixIn;
  1185. ALPHAPIX pixOut;
  1186. pixIn.ul = *pulSrc;
  1187. pixOut.pix.r = pixIn.pix.b;
  1188. pixOut.pix.g = pixIn.pix.g;
  1189. pixOut.pix.b = pixIn.pix.r;
  1190. pixOut.pix.a = 0;
  1191. *pulDst = pixOut.ul;
  1192. pulSrc++;
  1193. pulDst++;
  1194. }
  1195. }