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.

779 lines
15 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. #if !(_WIN32_WINNT >= 0x500)
  13. /******************************Public*Routine******************************\
  14. * Routines to load a pixel and convert it to BGRA representaion for
  15. * blending operations
  16. *
  17. * Arguments:
  18. *
  19. *
  20. *
  21. * Return Value:
  22. *
  23. *
  24. *
  25. * History:
  26. *
  27. * 12/2/1996 Mark Enstrom [marke]
  28. *
  29. \**************************************************************************/
  30. VOID
  31. vLoadAndConvert1ToBGRA(
  32. PULONG pulDstAddr,
  33. PBYTE pSrcAddr,
  34. LONG SrcX,
  35. LONG SrcCx,
  36. PVOID pDibInfo
  37. )
  38. {
  39. BYTE SrcByte;
  40. LONG cxUnalignedStart = 7 & (8 - (SrcX & 7));
  41. PULONG ppal = (PULONG)&((PDIBINFO)pDibInfo)->pbmi->bmiColors[0];
  42. pSrcAddr = pSrcAddr + (SrcX >> 3);
  43. cxUnalignedStart = MIN(SrcCx,cxUnalignedStart);
  44. //
  45. // unaligned start
  46. //
  47. if (cxUnalignedStart)
  48. {
  49. LONG iDst = 7 - (SrcX & 0x07);
  50. SrcByte = *pSrcAddr;
  51. pSrcAddr++;
  52. while (cxUnalignedStart--)
  53. {
  54. ULONG ulSrc = ((SrcByte & (1 << iDst)) >> iDst);
  55. ulSrc = ppal[ulSrc] | 0xFF000000;
  56. *pulDstAddr = ulSrc;
  57. pulDstAddr++;
  58. SrcCx--;
  59. iDst--;
  60. }
  61. }
  62. //
  63. // aligned whole bytes
  64. //
  65. while (SrcCx >= 8)
  66. {
  67. SrcCx -= 8;
  68. SrcByte = *pSrcAddr;
  69. *(pulDstAddr + 0) = (ppal[(SrcByte & 0x80) >> 7] | 0xff000000);
  70. *(pulDstAddr + 1) = (ppal[(SrcByte & 0x40) >> 6] | 0xff000000);
  71. *(pulDstAddr + 2) = (ppal[(SrcByte & 0x20) >> 5] | 0xff000000);
  72. *(pulDstAddr + 3) = (ppal[(SrcByte & 0x10) >> 4] | 0xff000000);
  73. *(pulDstAddr + 4) = (ppal[(SrcByte & 0x08) >> 3] | 0xff000000);
  74. *(pulDstAddr + 5) = (ppal[(SrcByte & 0x04) >> 2] | 0xff000000);
  75. *(pulDstAddr + 6) = (ppal[(SrcByte & 0x02) >> 1] | 0xff000000);
  76. *(pulDstAddr + 7) = (ppal[(SrcByte & 0x01) >> 0] | 0xff000000);
  77. pSrcAddr++;
  78. pulDstAddr+=8;
  79. }
  80. //
  81. // unaligned end
  82. //
  83. if (SrcCx)
  84. {
  85. BYTE SrcByte = *pSrcAddr;
  86. LONG iDst = 7;
  87. while (SrcCx)
  88. {
  89. ULONG ulSrc = ((SrcByte & (1 << iDst)) >> iDst);
  90. ulSrc = ppal[ulSrc] | 0xff000000;
  91. *pulDstAddr = ulSrc;
  92. pulDstAddr++;
  93. SrcCx--;
  94. iDst--;
  95. }
  96. }
  97. }
  98. /**************************************************************************\
  99. * vLoadAndConvert4ToBGRA
  100. *
  101. *
  102. * Arguments:
  103. *
  104. *
  105. *
  106. * Return Value:
  107. *
  108. *
  109. *
  110. * History:
  111. *
  112. * 1/22/1997 Mark Enstrom [marke]
  113. *
  114. \**************************************************************************/
  115. VOID
  116. vLoadAndConvert4ToBGRA(
  117. PULONG pulDstAddr,
  118. PBYTE pSrcAddr,
  119. LONG SrcX,
  120. LONG SrcCx,
  121. PVOID pDibInfo
  122. )
  123. {
  124. BYTE SrcByte;
  125. pSrcAddr = pSrcAddr + (SrcX >> 1);
  126. LONG cxUnalignedStart = 1 & (2 - (SrcX & 1));
  127. PULONG ppal = (PULONG)&((PDIBINFO)pDibInfo)->pbmi->bmiColors[0];
  128. cxUnalignedStart = MIN(SrcCx,cxUnalignedStart);
  129. //
  130. // unaligned start
  131. //
  132. if (cxUnalignedStart)
  133. {
  134. SrcByte = *pSrcAddr;
  135. *pulDstAddr = ppal[SrcByte & 0x0f] | 0xff000000;
  136. pSrcAddr++;
  137. pulDstAddr++;
  138. SrcCx--;
  139. }
  140. //
  141. // aligned whole bytes
  142. //
  143. while (SrcCx >= 2)
  144. {
  145. SrcCx -= 2;
  146. SrcByte = *pSrcAddr;
  147. *(pulDstAddr + 0) = ppal[(SrcByte >> 4) ] | 0xff000000;
  148. *(pulDstAddr + 1) = ppal[(SrcByte & 0x0f)] | 0xff000000;
  149. pSrcAddr++;
  150. pulDstAddr+=2;
  151. }
  152. //
  153. // unaligned end
  154. //
  155. if (SrcCx)
  156. {
  157. SrcByte = *pSrcAddr;
  158. *pulDstAddr = ppal[SrcByte >> 4] | 0xff000000;
  159. }
  160. }
  161. /**************************************************************************\
  162. * vLoadAndConvert8ToBGRA
  163. *
  164. *
  165. * Arguments:
  166. *
  167. *
  168. *
  169. * Return Value:
  170. *
  171. *
  172. *
  173. * History:
  174. *
  175. * 1/22/1997 Mark Enstrom [marke]
  176. *
  177. \**************************************************************************/
  178. VOID
  179. vLoadAndConvert8ToBGRA(
  180. PULONG pulDstAddr,
  181. PBYTE pSrcAddr,
  182. LONG SrcX,
  183. LONG SrcCx,
  184. PVOID pDibInfo
  185. )
  186. {
  187. PBYTE pjSrc = pSrcAddr + SrcX;
  188. PBYTE pjEnd = pjSrc + SrcCx;
  189. PULONG ppal = (PULONG)&((PDIBINFO)pDibInfo)->pbmi->bmiColors[0];
  190. while (pjSrc != pjEnd)
  191. {
  192. *pulDstAddr = ppal[*pjSrc] | 0xff000000;
  193. pulDstAddr++;
  194. pjSrc++;
  195. }
  196. }
  197. /**************************************************************************\
  198. * vLoadAndConvertRGB16_565ToBGRA
  199. *
  200. *
  201. * Arguments:
  202. *
  203. *
  204. *
  205. * Return Value:
  206. *
  207. *
  208. *
  209. * History:
  210. *
  211. * 1/22/1997 Mark Enstrom [marke]
  212. *
  213. \**************************************************************************/
  214. VOID
  215. vLoadAndConvertRGB16_565ToBGRA(
  216. PULONG pulDstAddr,
  217. PBYTE pSrcAddr,
  218. LONG SrcX,
  219. LONG SrcCx,
  220. PVOID pDibInfo
  221. )
  222. {
  223. PUSHORT pusSrc = (PUSHORT)pSrcAddr + SrcX;
  224. PUSHORT pusEnd = pusSrc + SrcCx;
  225. while (pusSrc != pusEnd)
  226. {
  227. ALPHAPIX pixIn;
  228. ALPHAPIX pixOut;
  229. pixIn.ul = *pusSrc;
  230. pixOut.pix.r = (BYTE)((pixIn.ul & 0xf800) >> 8);
  231. pixOut.pix.g = (BYTE)((pixIn.ul & 0x07e0) >> 3);
  232. pixOut.pix.b = (BYTE)((pixIn.ul & 0x001f) << 3);
  233. pixOut.pix.a = 0xff;
  234. *pulDstAddr = pixOut.ul;
  235. pusSrc++;
  236. pulDstAddr++;
  237. }
  238. }
  239. /**************************************************************************\
  240. * vLoadAndConvertRGB16_555ToBGRA
  241. *
  242. *
  243. * Arguments:
  244. *
  245. *
  246. *
  247. * Return Value:
  248. *
  249. *
  250. *
  251. * History:
  252. *
  253. * 1/22/1997 Mark Enstrom [marke]
  254. *
  255. \**************************************************************************/
  256. VOID
  257. vLoadAndConvertRGB16_555ToBGRA(
  258. PULONG pulDstAddr,
  259. PBYTE pSrcAddr,
  260. LONG SrcX,
  261. LONG SrcCx,
  262. PVOID pDibInfo
  263. )
  264. {
  265. PUSHORT pusSrc = (PUSHORT)pSrcAddr + SrcX;
  266. PUSHORT pusEnd = pusSrc + SrcCx;
  267. while (pusSrc != pusEnd)
  268. {
  269. ALPHAPIX pixIn;
  270. ALPHAPIX pixOut;
  271. pixIn.ul = *pusSrc;
  272. pixOut.pix.r = (BYTE)((pixIn.ul & 0x7c00) >> 7);
  273. pixOut.pix.g = (BYTE)((pixIn.ul & 0x03e0) >> 2);
  274. pixOut.pix.b = (BYTE)((pixIn.ul & 0x001f) << 3);
  275. pixOut.pix.a = 0xff;
  276. *pulDstAddr = pixOut.ul;
  277. pusSrc++;
  278. pulDstAddr++;
  279. }
  280. }
  281. /**************************************************************************\
  282. * vLoadAndConvert16BitfieldsToBGRA
  283. *
  284. *
  285. * Arguments:
  286. *
  287. *
  288. *
  289. * Return Value:
  290. *
  291. *
  292. *
  293. * History:
  294. *
  295. * 1/22/1997 Mark Enstrom [marke]
  296. *
  297. \**************************************************************************/
  298. VOID
  299. vLoadAndConvert16BitfieldsToBGRA(
  300. PULONG pulDstAddr,
  301. PBYTE pSrcAddr,
  302. LONG SrcX,
  303. LONG SrcCx,
  304. PVOID pDibInfo
  305. )
  306. {
  307. PUSHORT pusSrc = (PUSHORT)pSrcAddr + SrcX;
  308. PUSHORT pusEnd = pusSrc + SrcCx;
  309. while (pusSrc != pusEnd)
  310. {
  311. ULONG ulTmp;
  312. ulTmp = *pusSrc;
  313. //ulTmp = ppal.ulBitfieldToRGB(ulTmp);
  314. ulTmp |= 0xff000000;
  315. *pulDstAddr = ulTmp;
  316. pusSrc++;
  317. pulDstAddr++;
  318. }
  319. }
  320. /**************************************************************************\
  321. * vLoadAndConvertRGB24ToBGRA
  322. *
  323. *
  324. * Arguments:
  325. *
  326. *
  327. *
  328. * Return Value:
  329. *
  330. *
  331. *
  332. * History:
  333. *
  334. * 1/22/1997 Mark Enstrom [marke]
  335. *
  336. \**************************************************************************/
  337. VOID
  338. vLoadAndConvertRGB24ToBGRA(
  339. PULONG pulDstAddr,
  340. PBYTE pSrcAddr,
  341. LONG SrcX,
  342. LONG SrcCx,
  343. PVOID pDibInfo
  344. )
  345. {
  346. PBYTE pjSrc = pSrcAddr + 3 * SrcX;
  347. PBYTE pjEnd = pjSrc + 3 * SrcCx;
  348. while (pjSrc != pjEnd)
  349. {
  350. ALPHAPIX pixRet;
  351. pixRet.pix.b = *(((PBYTE)pjSrc));
  352. pixRet.pix.g = *(((PBYTE)pjSrc)+1);
  353. pixRet.pix.r = *(((PBYTE)pjSrc)+2);
  354. pixRet.pix.a = 0xff;
  355. *pulDstAddr = pixRet.ul;
  356. pjSrc += 3;
  357. pulDstAddr++;
  358. }
  359. }
  360. /**************************************************************************\
  361. * vLoadAndConvertRGB32ToBGRA
  362. *
  363. *
  364. * Arguments:
  365. *
  366. *
  367. *
  368. * Return Value:
  369. *
  370. *
  371. *
  372. * History:
  373. *
  374. * 1/22/1997 Mark Enstrom [marke]
  375. *
  376. \**************************************************************************/
  377. VOID
  378. vLoadAndConvertRGB32ToBGRA(
  379. PULONG pulDstAddr,
  380. PBYTE pSrcAddr,
  381. LONG SrcX,
  382. LONG SrcCx,
  383. PVOID pDibInfo
  384. )
  385. {
  386. PULONG pulSrc = (PULONG)pSrcAddr + SrcX;
  387. PULONG pulEnd = pulSrc + SrcCx;
  388. while (pulSrc != pulEnd)
  389. {
  390. ALPHAPIX pixIn;
  391. ALPHAPIX pixOut;
  392. pixIn.ul = *pulSrc;
  393. pixOut.pix.r = pixIn.pix.b;
  394. pixOut.pix.g = pixIn.pix.g;
  395. pixOut.pix.b = pixIn.pix.r;
  396. pixOut.pix.a = pixIn.pix.a;
  397. *pulDstAddr = pixOut.ul;
  398. pulSrc++;
  399. pulDstAddr++;
  400. }
  401. }
  402. /**************************************************************************\
  403. * vLoadAndConvert32BitfieldsToBGRA
  404. *
  405. *
  406. * Arguments:
  407. *
  408. *
  409. *
  410. * Return Value:
  411. *
  412. *
  413. *
  414. * History:
  415. *
  416. * 1/22/1997 Mark Enstrom [marke]
  417. *
  418. \**************************************************************************/
  419. VOID
  420. vLoadAndConvert32BitfieldsToBGRA(
  421. PULONG pulDstAddr,
  422. PBYTE pSrcAddr,
  423. LONG SrcX,
  424. LONG SrcCx,
  425. PVOID pDibInfo
  426. )
  427. {
  428. PULONG pulSrc = (PULONG)pSrcAddr + SrcX;
  429. PULONG pulEnd = pulSrc + SrcCx;
  430. while (pulSrc != pulEnd)
  431. {
  432. ULONG ulTmp;
  433. ulTmp = *pulSrc;
  434. //ulTmp = ppal.ulBitfieldToRGB(ulTmp);
  435. *pulDstAddr = ulTmp;
  436. pulSrc++;
  437. pulDstAddr++;
  438. }
  439. }
  440. //
  441. //
  442. // STORE ROUTINES
  443. // convert BGRA to RGB332, look up in table
  444. //
  445. //#define PALETTE_MATCH(pixIn,ppalInfo) \
  446. //{ \
  447. // pixIn.ul = ppalInfo->pxlate332[ \
  448. // ((pixIn.pix.r & 0xe0)) | \
  449. // ((pixIn.pix.g & 0xe0) >> 3) | \
  450. // ((pixIn.pix.b & 0xc0) >> 6)]; \
  451. //} \
  452. /**************************************************************************\
  453. * vConvertAndSaveBGRATo8
  454. *
  455. *
  456. * Arguments:
  457. *
  458. *
  459. *
  460. * Return Value:
  461. *
  462. *
  463. *
  464. * History:
  465. *
  466. * 1/22/1997 Mark Enstrom [marke]
  467. *
  468. \**************************************************************************/
  469. VOID
  470. vConvertAndSaveBGRAToDest(
  471. PBYTE pDst,
  472. PULONG pulSrc,
  473. LONG cx,
  474. LONG DstX,
  475. LONG y,
  476. PVOID pvdibInfoDst,
  477. PBYTE pWriteMask,
  478. HDC hdc32
  479. )
  480. {
  481. PDIBINFO pDibInfo = (PDIBINFO)pvdibInfoDst;
  482. BitBlt(pDibInfo->hdc,
  483. pDibInfo->rclBoundsTrim.left,
  484. pDibInfo->rclBoundsTrim.top + y,
  485. pDibInfo->rclBoundsTrim.right - pDibInfo->rclBoundsTrim.left,
  486. 1,
  487. hdc32,
  488. 0,
  489. 0,
  490. SRCCOPY);
  491. }
  492. /**************************************************************************\
  493. * vConvertAndSaveBGRAToRGB16_565
  494. *
  495. *
  496. * Arguments:
  497. *
  498. *
  499. *
  500. * Return Value:
  501. *
  502. *
  503. *
  504. * History:
  505. *
  506. * 1/22/1997 Mark Enstrom [marke]
  507. *
  508. \**************************************************************************/
  509. VOID
  510. vConvertAndSaveBGRAToRGB16_565(
  511. PBYTE pjDst,
  512. PULONG pulSrc,
  513. LONG cx,
  514. LONG DstX,
  515. LONG y,
  516. PVOID pvdibInfoDst,
  517. PBYTE pWriteMask,
  518. HDC hdc32
  519. )
  520. {
  521. PUSHORT pusDst = (PUSHORT)pjDst + DstX;
  522. PUSHORT pusEnd = pusDst + cx;
  523. while (pusDst != pusEnd)
  524. {
  525. ALPHAPIX pixIn;
  526. ALPHAPIX pixOut;
  527. pixIn.ul = *pulSrc;
  528. pixOut.ul = ((pixIn.pix.r & 0xf8) << 8) |
  529. ((pixIn.pix.g & 0xfc) << 3) |
  530. ((pixIn.pix.b & 0xf8) >> 3);
  531. *pusDst = (USHORT)pixOut.ul;
  532. pulSrc++;
  533. pusDst++;
  534. }
  535. }
  536. /**************************************************************************\
  537. * vConvertAndSaveBGRAToRGB16_555
  538. *
  539. *
  540. * Arguments:
  541. *
  542. *
  543. *
  544. * Return Value:
  545. *
  546. *
  547. *
  548. * History:
  549. *
  550. * 1/22/1997 Mark Enstrom [marke]
  551. *
  552. \**************************************************************************/
  553. VOID
  554. vConvertAndSaveBGRAToRGB16_555(
  555. PBYTE pjDst,
  556. PULONG pulSrc,
  557. LONG cx,
  558. LONG DstX,
  559. LONG y,
  560. PVOID pvdibInfoDst,
  561. PBYTE pWriteMask,
  562. HDC hdc32
  563. )
  564. {
  565. PUSHORT pusDst = (PUSHORT)pjDst + DstX;
  566. PUSHORT pusEnd = pusDst + cx;
  567. while (pusDst != pusEnd)
  568. {
  569. ALPHAPIX pixIn;
  570. ALPHAPIX pixOut;
  571. pixIn.ul = *pulSrc;
  572. pixOut.ul = ((pixIn.pix.r & 0xf8) << 7) |
  573. ((pixIn.pix.g & 0xf8) << 2) |
  574. ((pixIn.pix.b & 0xf8) >> 3);
  575. *pusDst = (USHORT)pixOut.ul;
  576. pulSrc++;
  577. pusDst++;
  578. }
  579. }
  580. /**************************************************************************\
  581. * vConvertAndSaveBGRAToRGB24
  582. *
  583. *
  584. * Arguments:
  585. *
  586. *
  587. *
  588. * Return Value:
  589. *
  590. *
  591. *
  592. * History:
  593. *
  594. * 1/22/1997 Mark Enstrom [marke]
  595. *
  596. \**************************************************************************/
  597. VOID
  598. vConvertAndSaveBGRAToRGB24(
  599. PBYTE pDst,
  600. PULONG pulSrc,
  601. LONG cx,
  602. LONG DstX,
  603. LONG y,
  604. PVOID pvdibInfoDst,
  605. PBYTE pWriteMask,
  606. HDC hdc32
  607. )
  608. {
  609. PBYTE pjDst = (PBYTE)pDst + (3 * DstX);
  610. PBYTE pjEnd = pjDst + (3 * cx);
  611. while (pjDst != pjEnd)
  612. {
  613. ALPHAPIX pixIn;
  614. pixIn.ul = *pulSrc;
  615. *pjDst = pixIn.pix.b;
  616. *(pjDst+1) = pixIn.pix.g;
  617. *(pjDst+2) = pixIn.pix.r;
  618. pulSrc++;
  619. pjDst+=3;
  620. }
  621. }
  622. /**************************************************************************\
  623. * vConvertAndSaveBGRAToRGB32
  624. *
  625. *
  626. * Arguments:
  627. *
  628. *
  629. *
  630. * Return Value:
  631. *
  632. *
  633. *
  634. * History:
  635. *
  636. * 1/22/1997 Mark Enstrom [marke]
  637. *
  638. \**************************************************************************/
  639. VOID
  640. vConvertAndSaveBGRAToRGB32(
  641. PBYTE pjDst,
  642. PULONG pulSrc,
  643. LONG cx,
  644. LONG DstX,
  645. LONG y,
  646. PVOID pvdibInfoDst,
  647. PBYTE pWriteMask,
  648. HDC hdc32
  649. )
  650. {
  651. PULONG pulDst = (PULONG)pjDst + DstX;
  652. PULONG pulEnd = pulDst + cx;
  653. while (pulDst != pulEnd)
  654. {
  655. ALPHAPIX pixIn;
  656. ALPHAPIX pixOut;
  657. pixIn.ul = *pulSrc;
  658. pixOut.pix.r = pixIn.pix.b;
  659. pixOut.pix.g = pixIn.pix.g;
  660. pixOut.pix.b = pixIn.pix.r;
  661. pixOut.pix.a = 0;
  662. *pulDst = pixOut.ul;
  663. pulSrc++;
  664. pulDst++;
  665. }
  666. }
  667. #endif