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.

1035 lines
26 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: image.hxx *
  3. * *
  4. * Definitions needed for client side objects. *
  5. * *
  6. * Copyright (c) 1993-1999 Microsoft Corporation *
  7. \**************************************************************************/
  8. extern HBITMAP hbmDefault;
  9. #define MAX_INT 0x7fffffff;
  10. #define MIN_INT 0x80000000;
  11. typedef HRESULT (WINAPI *PFN_GETSURFACEFROMDC)(HDC, LPDIRECTDRAWSURFACE *,
  12. HDC *);
  13. typedef HRESULT (WINAPI *PFN_GETSURFACEDESC)(LPDIRECTDRAWSURFACE);
  14. typedef BOOL FNTRANSBLT(
  15. HDC hdcDest,
  16. int DstX,
  17. int DstY,
  18. int DstCx,
  19. int DstCy,
  20. HDC hSrc,
  21. int SrcX,
  22. int SrcY,
  23. int SrcCx,
  24. int SrcCy,
  25. UINT Color
  26. );
  27. typedef FNTRANSBLT *PFNTRANSBLT;
  28. typedef BOOL FNTRANSDIB(
  29. HDC hdcDest,
  30. int DstX,
  31. int DstY,
  32. int DstCx,
  33. int DstCy,
  34. CONST VOID *lpBits,
  35. CONST BITMAPINFO *lpBitsInfo,
  36. UINT iUsage,
  37. int SrcX,
  38. int SrcY,
  39. int SrcCx,
  40. int SrcCy,
  41. UINT Color
  42. );
  43. typedef FNTRANSDIB *PFNTRANSDIB;
  44. typedef BOOL FNGRFILL(
  45. HDC hdc,
  46. PTRIVERTEX pVertex,
  47. ULONG nVertex,
  48. PVOID pMesh,
  49. ULONG nMesh,
  50. ULONG ulMode
  51. );
  52. typedef FNGRFILL *PFNGRFILL;
  53. typedef BOOL FNALPHABLEND(
  54. HDC hdcDest,
  55. int DstX,
  56. int DstY,
  57. int DstCx,
  58. int DstCy,
  59. HDC hSrc,
  60. int SrcX,
  61. int SrcY,
  62. int SrcCx,
  63. int SrcCy,
  64. BLENDFUNCTION BlendFunction
  65. );
  66. typedef FNALPHABLEND *PFNALPHABLEND;
  67. typedef BOOL FNALPHADIB(
  68. HDC hdcDest,
  69. int DstX,
  70. int DstY,
  71. int DstCx,
  72. int DstCy,
  73. CONST VOID *lpBits,
  74. CONST BITMAPINFO *lpBitsInfo,
  75. UINT iUsage,
  76. int SrcX,
  77. int SrcY,
  78. int SrcCx,
  79. int SrcCy,
  80. BLENDFUNCTION BlendFunction
  81. );
  82. typedef FNALPHADIB *PFNALPHADIB;
  83. extern PFNALPHABLEND gpfnAlphaBlend;
  84. extern PFNALPHADIB gpfnAlphaDIB;
  85. //
  86. //
  87. //
  88. #define MIN(A,B) ((A) < (B) ? (A) : (B))
  89. #define MAX(A,B) ((A) > (B) ? (A) : (B))
  90. #define ABS(X) (((X) < 0 ) ? -(X) : (X))
  91. /**************************************************************************\
  92. *
  93. * rgb555,rgb565 convert r,g,b bytes to ushort
  94. *
  95. * Arguments:
  96. *
  97. *
  98. *
  99. * Return Value:
  100. *
  101. *
  102. *
  103. * History:
  104. *
  105. * 1/31/1997 Mark Enstrom [marke]
  106. *
  107. \**************************************************************************/
  108. #define rgb555(r,g,b) (((WORD)(r) << 10) | ((WORD)(g) << 5) | (WORD)(b))
  109. #define rgb565(r,g,b) (((WORD)(r) << 11) | ((WORD)(g) << 5) | (WORD)(b))
  110. extern ULONG gulDither32[];
  111. /**************************************************************************\
  112. *
  113. * TRIEDGE
  114. *
  115. * triangle mesh structure to hold all endpoint and color info
  116. *
  117. *
  118. * History:
  119. *
  120. * 2/11/1997 Mark Enstrom [marke]
  121. *
  122. \**************************************************************************/
  123. typedef struct _TRIEDGE
  124. {
  125. LONG xLeft;
  126. LONG xRight;
  127. LONGLONG llRed;
  128. LONGLONG llGreen;
  129. LONGLONG llBlue;
  130. LONGLONG llAlpha;
  131. }TRIEDGE,*PTRIEDGE;
  132. /**************************************************************************\
  133. * TRIANGLEDATA
  134. *
  135. *
  136. * span and color gradient information for gradient fill triangles
  137. *
  138. *
  139. * History:
  140. *
  141. * 2/11/1997 Mark Enstrom [marke]
  142. *
  143. \**************************************************************************/
  144. typedef struct _TRIANGLEDATA
  145. {
  146. RECTL rcl;
  147. LONGLONG lldRdX;
  148. LONGLONG lldGdX;
  149. LONGLONG lldBdX;
  150. LONGLONG lldAdX;
  151. LONGLONG lldRdY;
  152. LONGLONG lldGdY;
  153. LONGLONG lldBdY;
  154. LONGLONG lldAdY;
  155. LONGLONG llRA;
  156. LONGLONG llGA;
  157. LONGLONG llBA;
  158. LONGLONG llAA;
  159. LONG y0;
  160. LONG y1;
  161. LONGLONG Area;
  162. POINTL ptDitherOrg;
  163. POINTL ptColorCalcOrg;
  164. LONG DrawMode;
  165. TRIEDGE TriEdge[1];
  166. }TRIANGLEDATA,*PTRIANGLEDATA;
  167. /**************************************************************************\
  168. * GRADIENTRECTDATA
  169. *
  170. *
  171. * color gradient information for gradient fill rectangles
  172. *
  173. *
  174. * History:
  175. *
  176. * 2/11/1997 Mark Enstrom [marke]
  177. *
  178. \**************************************************************************/
  179. typedef struct _GRADIENTRECTDATA
  180. {
  181. RECTL rclClip;
  182. RECTL rclGradient;
  183. POINTL ptDraw;
  184. SIZEL szDraw;
  185. ULONGLONG llRed;
  186. ULONGLONG llGreen;
  187. ULONGLONG llBlue;
  188. ULONGLONG llAlpha;
  189. LONGLONG lldRdY;
  190. LONGLONG lldGdY;
  191. LONGLONG lldBdY;
  192. LONGLONG lldAdY;
  193. LONGLONG lldRdX;
  194. LONGLONG lldGdX;
  195. LONGLONG lldBdX;
  196. LONGLONG lldAdX;
  197. POINTL ptDitherOrg;
  198. ULONG ulMode;
  199. LONG xScanAdjust;
  200. LONG yScanAdjust;
  201. }GRADIENTRECTDATA,*PGRADIENTRECTDATA;
  202. /**************************************************************************\
  203. * COLOR_INTERP
  204. *
  205. * Color interpolation is done in fixed point 8.56 (tri) or 8.48 (rect)
  206. * This union makes it faster to get int pixel.
  207. *
  208. \**************************************************************************/
  209. typedef union _COLOR_INTERP
  210. {
  211. ULONGLONG ullColor;
  212. ULONG ul[2];
  213. BYTE b[8];
  214. }COLOR_INTERP,*PCOLOR_INTERP;
  215. /**************************************************************************\
  216. * GRADSTRUCT
  217. *
  218. *
  219. * Fields
  220. *
  221. *
  222. *
  223. *
  224. \**************************************************************************/
  225. typedef struct _GRADSTRUCT {
  226. LONG x1;
  227. LONG x2;
  228. LONG y1;
  229. LONG y2;
  230. LONG m;
  231. LONG d;
  232. LONGLONG Q;
  233. LONGLONG R;
  234. } GRADSTRUCT;
  235. //
  236. // constant in triangle color gradient calc
  237. //
  238. #define TWO_TO_THE_48TH 0x0001000000000000
  239. //
  240. // maximum edge of triangle before it must be split
  241. //
  242. // 2^16
  243. //
  244. #define MAX_EDGE_LENGTH 16384
  245. /**************************************************************************\
  246. *
  247. * TRIDDA
  248. *
  249. * Triangle DDA information for calculating and running line dda
  250. *
  251. * History:
  252. *
  253. * 2/11/1997 Mark Enstrom [marke]
  254. *
  255. \**************************************************************************/
  256. typedef struct _TRIDDA
  257. {
  258. LONG M0; // Initial X Device space
  259. LONG N0; // Initial Y Device spave
  260. LONG dM; // Delta X
  261. LONG dN; // Delta Y
  262. LONGLONG C; // Initial Error Constant
  263. LONG dL; // Interger component of delta X
  264. LONG dR; // Remainder component of delta X
  265. LONG R; // Remainder
  266. LONG Rb; // Remainder used to compare with 0
  267. LONG L; // Temp
  268. LONG j; // Temp
  269. LONG Linc; // X inc (pos or neg)
  270. LONG yIndex; // Current index into line array
  271. LONG NumScanLines; // Number of scan lines to run
  272. LONG t0; // place holder
  273. LONGLONG llRed; // Current Color
  274. LONGLONG llGreen; // Current Color
  275. LONGLONG llBlue; // Current Color
  276. LONGLONG llAlpha; // Current Color
  277. LONGLONG lldxyRed; // Combined integer change for step in x and y
  278. LONGLONG lldxyGreen; // Combined integer change for step in x and y
  279. LONGLONG lldxyBlue; // Combined integer change for step in x and y
  280. LONGLONG lldxyAlpha; // Combined integer change for step in x and y
  281. }TRIDDA,*PTRIDDA;
  282. VOID
  283. ImgFillMemoryULONG(
  284. PBYTE pDst,
  285. ULONG ulPat,
  286. ULONG cxBytes
  287. );
  288. VOID Dprintf( LPSTR szFmt, ... );
  289. inline
  290. VOID
  291. vHorizontalLine(
  292. PTRIVERTEX pv1,
  293. PTRIVERTEX pv2,
  294. PTRIANGLEDATA ptData,
  295. PTRIDDA ptridda
  296. );
  297. VOID
  298. vLeftEdgeDDA(
  299. PTRIANGLEDATA ptData,
  300. PTRIDDA ptridda
  301. );
  302. VOID
  303. vRightEdgeDDA(
  304. PTRIANGLEDATA ptData,
  305. PTRIDDA ptridda
  306. );
  307. BOOL
  308. bGetRectRegionFromDC(
  309. HDC hdc,
  310. PRECTL prclClip
  311. );
  312. //
  313. // Alpha Blending
  314. //
  315. //
  316. //
  317. typedef struct _PIXEL32
  318. {
  319. BYTE b;
  320. BYTE g;
  321. BYTE r;
  322. BYTE a;
  323. }PIXEL32,*PPIXEL32;
  324. typedef union _ALPHAPIX
  325. {
  326. PIXEL32 pix;
  327. RGBQUAD rgb;
  328. ULONG ul;
  329. } ALPHAPIX,*PALPHAPIX;
  330. typedef union _PAL_ULONG
  331. {
  332. PALETTEENTRY pal;
  333. ULONG ul;
  334. } PAL_ULONG;
  335. #define XPAL_BGRA 0x00000001
  336. #define XPAL_RGB32 0x00000002
  337. #define XPAL_BGR32 0x00000004
  338. #define XPAL_RGB24 0x00000008
  339. #define XPAL_RGB16_565 0x00000010
  340. #define XPAL_RGB16_555 0x00000020
  341. #define XPAL_HALFTONE 0x00000040
  342. #define XPAL_1PAL 0x00000080
  343. #define XPAL_4PAL 0x00000100
  344. #define XPAL_8PAL 0x00000200
  345. #define XPAL_BITFIELDS 0x00000400
  346. /**************************************************************************\
  347. *
  348. * structure PALINFO
  349. *
  350. * Arguments:
  351. *
  352. *
  353. *
  354. * Return Value:
  355. *
  356. *
  357. *
  358. * History:
  359. *
  360. * 12/10/1996 Mark Enstrom [marke]
  361. *
  362. \**************************************************************************/
  363. typedef struct _PALINFO
  364. {
  365. PBITMAPINFO pBitmapInfo;
  366. PBYTE pxlate332;
  367. ULONG flPal;
  368. PBITMAPINFO pbmi32;
  369. HDC hdcSrc;
  370. HDC hdcDst;
  371. LONG DstX;
  372. LONG DstY;
  373. LONG DstCX;
  374. LONG DstCY;
  375. }PALINFO,*PPALINFO;
  376. //
  377. // alpha blending call data
  378. //
  379. VOID
  380. vPixelBlendOrDissolveOver(
  381. ALPHAPIX *ppixDst,
  382. ALPHAPIX *ppixSrc,
  383. LONG cx,
  384. BLENDFUNCTION BlendFunction,
  385. PBYTE pwrMask
  386. );
  387. VOID
  388. vPixelBlend(
  389. ALPHAPIX *ppixDst,
  390. ALPHAPIX *ppixSrc,
  391. LONG cx,
  392. BLENDFUNCTION BlendFunction,
  393. PBYTE pwrMask
  394. );
  395. VOID
  396. vPixelBlend16_555(
  397. ALPHAPIX *ppixDst,
  398. ALPHAPIX *ppixSrc,
  399. LONG cx,
  400. BLENDFUNCTION BlendFunction,
  401. PBYTE pwrMask
  402. );
  403. VOID
  404. vPixelBlend16_565(
  405. ALPHAPIX *ppixDst,
  406. ALPHAPIX *ppixSrc,
  407. LONG cx,
  408. BLENDFUNCTION BlendFunction,
  409. PBYTE pwrMask
  410. );
  411. VOID
  412. vPixelBlend24(
  413. ALPHAPIX *ppixDst,
  414. ALPHAPIX *ppixSrc,
  415. LONG cx,
  416. BLENDFUNCTION BlendFunction,
  417. PBYTE pwrMask
  418. );
  419. VOID
  420. vPixelOver(
  421. ALPHAPIX *ppixDst,
  422. ALPHAPIX *ppixSrc,
  423. LONG cx,
  424. BLENDFUNCTION BlendFunction,
  425. PBYTE pwrMask
  426. );
  427. VOID mmxPixelOver(ALPHAPIX *,ALPHAPIX *,LONG,BLENDFUNCTION,PBYTE);
  428. VOID mmxPixelBlendOrDissolveOver(ALPHAPIX *,ALPHAPIX *,LONG,BLENDFUNCTION,PBYTE);
  429. VOID mmxPixelBlend24(PALPHAPIX,PALPHAPIX,LONG,BLENDFUNCTION,PBYTE);
  430. VOID mmxPixelBlend16_555(PALPHAPIX,PALPHAPIX,LONG,BLENDFUNCTION,PBYTE);
  431. VOID mmxPixelBlend16_565(PALPHAPIX,PALPHAPIX,LONG,BLENDFUNCTION,PBYTE);
  432. extern BOOL gbMMX;
  433. BOOL
  434. bIsMMXProcessor(VOID);
  435. typedef VOID (*PFN_GENERALBLEND)(PALPHAPIX,PALPHAPIX,LONG,BLENDFUNCTION,PBYTE);
  436. typedef VOID (*PFN_PIXLOAD_AND_CONVERT)(PULONG,PBYTE,LONG,LONG,PVOID);
  437. typedef VOID (*PFN_PIXCONVERT_AND_STORE)(PBYTE,PULONG,LONG,LONG,LONG,PVOID,PBYTE,HDC);
  438. typedef struct _ALPHA_DISPATCH_FORMAT
  439. {
  440. ULONG ulDstBitsPerPixel;
  441. ULONG ulSrcBitsPerPixel;
  442. PFN_PIXLOAD_AND_CONVERT pfnLoadSrcAndConvert;
  443. PFN_PIXLOAD_AND_CONVERT pfnLoadDstAndConvert;
  444. PFN_PIXCONVERT_AND_STORE pfnConvertAndStore;
  445. PFN_GENERALBLEND pfnGeneralBlend;
  446. BLENDFUNCTION BlendFunction;
  447. BOOL bUseMMX;
  448. }ALPHA_DISPATCH_FORMAT,*PALPHA_DISPATCH_FORMAT;
  449. //
  450. // palinfo routines
  451. //
  452. BOOL inline bIsBGRA(ULONG flPal) { return (flPal & XPAL_BGRA);}
  453. BOOL inline bIsRGB32(ULONG flPal) { return (flPal & XPAL_RGB32);}
  454. BOOL inline bIsBGR32(ULONG flPal) { return (flPal & XPAL_BGR32);}
  455. BOOL inline bIsRGB24(ULONG flPal) { return (flPal & XPAL_RGB24);}
  456. BOOL inline bIsRGB16_565(ULONG flPal) { return (flPal & XPAL_RGB16_565);}
  457. BOOL inline bIsRGB16_555(ULONG flPal) { return (flPal & XPAL_RGB16_555);}
  458. BOOL inline bIsHalftone(ULONG flPal) { return (flPal & XPAL_HALFTONE);}
  459. ULONG inline flRed(PPALINFO ppalInfo)
  460. {
  461. if (ppalInfo->pBitmapInfo->bmiHeader.biCompression == BI_BITFIELDS)
  462. {
  463. ALPHAPIX pix;
  464. pix.rgb = ppalInfo->pBitmapInfo->bmiColors[0];
  465. return(pix.ul);
  466. }
  467. return(0);
  468. }
  469. ULONG inline flGreen(PPALINFO ppalInfo)
  470. {
  471. if (ppalInfo->pBitmapInfo->bmiHeader.biCompression == BI_BITFIELDS)
  472. {
  473. ALPHAPIX pix;
  474. pix.rgb = ppalInfo->pBitmapInfo->bmiColors[1];
  475. return(pix.ul);
  476. }
  477. return(0);
  478. }
  479. ULONG inline flBlue(PPALINFO ppalInfo)
  480. {
  481. if (ppalInfo->pBitmapInfo->bmiHeader.biCompression == BI_BITFIELDS)
  482. {
  483. ALPHAPIX pix;
  484. pix.rgb = ppalInfo->pBitmapInfo->bmiColors[2];
  485. return(pix.ul);
  486. }
  487. return(0);
  488. }
  489. VOID vLoadAndConvert1ToBGRA(PULONG,PBYTE,LONG,LONG,PVOID);
  490. VOID vLoadAndConvert4ToBGRA(PULONG,PBYTE,LONG,LONG,PVOID);
  491. VOID vLoadAndConvert8ToBGRA(PULONG,PBYTE,LONG,LONG,PVOID);
  492. VOID vLoadAndConvertRGB16_555ToBGRA(PULONG,PBYTE,LONG,LONG,PVOID);
  493. VOID vLoadAndConvertRGB16_565ToBGRA(PULONG,PBYTE,LONG,LONG,PVOID);
  494. VOID vLoadAndConvert16BitfieldsToBGRA(PULONG,PBYTE,LONG,LONG,PVOID);
  495. VOID vLoadAndConvertRGB24ToBGRA(PULONG,PBYTE,LONG,LONG,PVOID);
  496. VOID vLoadAndConvertRGB32ToBGRA(PULONG,PBYTE,LONG,LONG,PVOID);
  497. VOID vLoadAndConvert32BitfieldsToBGRA(PULONG,PBYTE,LONG,LONG,PVOID);
  498. VOID vConvertAndSaveBGRAToRGB32(PBYTE,PULONG,LONG,LONG,LONG,PVOID,PBYTE,HDC);
  499. VOID vConvertAndSaveBGRAToRGB24(PBYTE,PULONG,LONG,LONG,LONG,PVOID,PBYTE,HDC);
  500. VOID vConvertAndSaveBGRAToRGB16_565(PBYTE,PULONG,LONG,LONG,LONG,PVOID,PBYTE,HDC);
  501. VOID vConvertAndSaveBGRAToRGB16_555(PBYTE,PULONG,LONG,LONG,LONG,PVOID,PBYTE,HDC);
  502. VOID vConvertAndSaveBGRATo8(PBYTE,PULONG,LONG,LONG,LONG,PVOID,PBYTE,HDC);
  503. VOID vConvertAndSaveBGRATo4(PBYTE,PULONG,LONG,LONG,LONG,PVOID,PBYTE,HDC);
  504. VOID vConvertAndSaveBGRATo1(PBYTE,PULONG,LONG,LONG,LONG,PVOID,PBYTE,HDC);
  505. VOID vConvertAndSaveBGRAToDest(PBYTE,PULONG,LONG,LONG,LONG,PVOID,PBYTE,HDC);
  506. BOOL bInitializePALINFO(PPALINFO);
  507. VOID vCleanupPALINFO(PPALINFO);
  508. /**************************************************************************\
  509. * DIBINFO
  510. *
  511. * keep track of temp DIB information
  512. *
  513. * elements:
  514. *
  515. *
  516. * History:
  517. *
  518. *
  519. \**************************************************************************/
  520. typedef struct _DIBINFO
  521. {
  522. HDC hdc; // hdc handle
  523. HBITMAP hDIB; // bitmap handle if a temp DIBsection is used
  524. RECTL rclBounds; // API bounding rect in device space
  525. RECTL rclBoundsTrim; // API bounding rect trimmed to DIB
  526. RECTL rclClipDC; // clip rect associated with input DC
  527. RECTL rclDIB; // DIB boundary in device space, drawing is done to this
  528. POINTL ptlGradOffset; // offset to apply to all GradientFill coords
  529. PBITMAPINFO pbmi; // pointer to bitmapinfo struct of the DIBsection
  530. PVOID pvBits; // pointer to the bit values
  531. PVOID pvBase; // starting point of the bits (pvScan0)
  532. LONG stride; // number of bytes to the next scan
  533. UINT iUsage; // DIB_RGB_COLORS or DIB_PAL_COLORS
  534. INT Mapmode; // mapmode in the dc
  535. POINT ViewportOrg; // viewport org in the dc
  536. POINT WindowOrg; // windowOrg in the dc
  537. SIZE ViewportExt;
  538. SIZE WindowExt;
  539. LPDIRECTDRAWSURFACE pdds; // pointer to directdraw surface if directdraw hdc
  540. DDSURFACEDESC ddsd; // pointer to ddraw surface desc if ddraw hdc
  541. ULONG flag; // misc flags
  542. } DIBINFO, *PDIBINFO;
  543. // flag in DIBINFO
  544. #define PRINTER_DC 0x00000001
  545. #define SOURCE_TRAN 0
  546. #define SOURCE_ALPHA 1
  547. #define SOURCE_GRADIENT_RECT 2
  548. #define SOURCE_GRADIENT_TRI 4
  549. //
  550. // global memory DC
  551. //
  552. #define SCAN_LINE_DC_WIDTH 1280
  553. HDC
  554. hdcAllocateScanLineDC(
  555. LONG width,
  556. PULONG *pulScanLine
  557. );
  558. VOID
  559. vFreeScanLineDC(
  560. HDC hdcFree
  561. );
  562. BOOL
  563. bInitAlpha();
  564. VOID
  565. CleanupGlobals();
  566. //
  567. // return codes for scanlineblend
  568. //
  569. #define ALPHA_COMPLETE 0
  570. #define ALPHA_SEND_TEMP 1
  571. #define ALPHA_FAIL 2
  572. ULONG
  573. AlphaScanLineBlend(
  574. PBYTE pDst,
  575. PRECTL pDstRect,
  576. ULONG DeltaDst,
  577. PBYTE pSrc,
  578. ULONG DeltaSrc,
  579. PPOINTL pptlSrc,
  580. PALPHA_DISPATCH_FORMAT pAlphaDispatch,
  581. PDIBINFO pdibInfoDst,
  582. PDIBINFO pdibInfoSrc
  583. );
  584. VOID vCopyBitmapInfo (
  585. PBITMAPINFO pbmiTo,
  586. PBITMAPINFO pbmiFrom
  587. );
  588. BOOL GetCompatibleDIBInfo(
  589. HBITMAP hbm,
  590. PVOID *ppvBase,
  591. LONG *plStride);
  592. BOOL bSameDIBformat (
  593. PBITMAPINFO pbmiDst,
  594. PBITMAPINFO pbmiSrc
  595. );
  596. BOOL bSetupBitmapInfos(
  597. PDIBINFO pDibInfoDst,
  598. PDIBINFO pDibInfoSrc
  599. );
  600. BOOL
  601. bDIBGetSrcDIBits (
  602. PDIBINFO pDibInfoDst,
  603. PDIBINFO pDibInfoSrc,
  604. FLONG flSourceMode,
  605. ULONG TransColor
  606. );
  607. BOOL
  608. bDIBInitDIBINFO (
  609. PBITMAPINFO p,
  610. CONST VOID * pvBits,
  611. int x,
  612. int y,
  613. int cx,
  614. int cy,
  615. PDIBINFO pDibInfo
  616. );
  617. BOOL
  618. bGetSrcDIBits(
  619. PDIBINFO pDibInfoDst,
  620. PDIBINFO pDibInfoSrc,
  621. FLONG flCopyMode,
  622. ULONG TranColor
  623. );
  624. BOOL
  625. bInitDIBINFO(
  626. HDC hdc,
  627. int x,
  628. int y,
  629. int cx,
  630. int cy,
  631. PDIBINFO pDibInfo
  632. );
  633. BOOL
  634. bSendDIBINFO(
  635. HDC hdcDst,
  636. PDIBINFO pDibInfo
  637. );
  638. VOID
  639. vCleanupDIBINFO(
  640. PDIBINFO pDibInfo
  641. );
  642. BOOL
  643. bGetDstDIBits(
  644. PDIBINFO pDibInfo,
  645. BOOL *pbReadable,
  646. FLONG flCopyMode
  647. );
  648. //
  649. // gradient fill
  650. //
  651. /**************************************************************************\
  652. * GRAD_PALETTE_MATCH
  653. *
  654. *
  655. * Arguments:
  656. *
  657. * palIndex - return palette index
  658. * pxlate - rgb332 to palette index table
  659. * r,g,b - byte colors
  660. *
  661. * Return Value:
  662. *
  663. *
  664. *
  665. * History:
  666. *
  667. * 3/3/1997 Mark Enstrom [marke]
  668. *
  669. \**************************************************************************/
  670. #define GRAD_PALETTE_MATCH(palIndex,pxlate,r,g,b) \
  671. \
  672. palIndex = pxlate[((r & 0xe0)) | \
  673. ((g & 0xe0) >> 3) | \
  674. ((b & 0xc0) >> 6)]; \
  675. \
  676. /**************************************************************************\
  677. *
  678. * Dither information for 8bpp. This is customized for dithering to
  679. * the halftone palette [6,6,6] color cube, and default palette.
  680. *
  681. * History:
  682. *
  683. * 2/24/1997 Mark Enstrom [marke]
  684. *
  685. \**************************************************************************/
  686. #define DITHER_8_MASK_Y 0x0F
  687. #define DITHER_8_MASK_X 0x0F
  688. extern BYTE gDitherMatrix16x16Halftone[];
  689. extern BYTE gDitherMatrix16x16Default[];
  690. extern BYTE HalftoneSaturationTable[];
  691. extern BYTE DefaultSaturationTable[];
  692. extern BYTE IdentitySaturationTable[];
  693. #define SWAP_VERTEX(pv0,pv1,pvt) \
  694. { \
  695. pvt = pv0; \
  696. pv0 = pv1; \
  697. pv1 = pvt; \
  698. }
  699. BOOL
  700. bCalculateTriangle(
  701. PTRIVERTEX pv0,
  702. PTRIVERTEX pv1,
  703. PTRIVERTEX pv2,
  704. PTRIANGLEDATA ptData
  705. );
  706. VOID vFillTriDIB32BGRA(PDIBINFO,PTRIANGLEDATA);
  707. VOID vFillTriDIB32RGB(PDIBINFO,PTRIANGLEDATA);
  708. VOID vFillTriDIB24RGB(PDIBINFO,PTRIANGLEDATA);
  709. VOID vFillTriDIB16_565(PDIBINFO,PTRIANGLEDATA);
  710. VOID vFillTriDIB16_555(PDIBINFO,PTRIANGLEDATA);
  711. VOID vFillTriDIBUnreadable(PDIBINFO,PTRIANGLEDATA);
  712. VOID vFillGRectDIB32BGRA(PDIBINFO,PGRADIENTRECTDATA);
  713. VOID vFillGRectDIB32RGB(PDIBINFO,PGRADIENTRECTDATA);
  714. VOID vFillGRectDIB24RGB(PDIBINFO,PGRADIENTRECTDATA);
  715. VOID vFillGRectDIB16_565(PDIBINFO,PGRADIENTRECTDATA);
  716. VOID vFillGRectDIB16_555(PDIBINFO,PGRADIENTRECTDATA);
  717. VOID vFillGRectDIB32Direct(PDIBINFO,PGRADIENTRECTDATA);
  718. typedef VOID (*PFN_TRIFILL)(PDIBINFO,PTRIANGLEDATA);
  719. typedef VOID (*PFN_GRADRECT)(PDIBINFO,PGRADIENTRECTDATA);
  720. PFN_TRIFILL
  721. pfnTriangleFillFunction(
  722. PDIBINFO pDibInfo,
  723. BOOL bUnreadable
  724. );
  725. PFN_GRADRECT
  726. pfnGradientRectFillFunction(
  727. PDIBINFO pDibInfo
  728. );
  729. //
  730. // gradient fill rect
  731. //
  732. BOOL bSplitTriangle(PTRIVERTEX,PULONG,PGRADIENT_TRIANGLE,PULONG,PULONG);
  733. BOOL bCalculateAndDrawTriangle(PDIBINFO,PTRIVERTEX,PTRIVERTEX,PTRIVERTEX,PTRIANGLEDATA,PFN_TRIFILL);
  734. BOOL bTriangleNeedsSplit(PTRIVERTEX,PTRIVERTEX,PTRIVERTEX);
  735. BOOL bIsTriangleInBounds(PTRIVERTEX,PTRIVERTEX,PTRIVERTEX,PTRIANGLEDATA);
  736. BOOL DIBGradientRect(HDC,PTRIVERTEX,ULONG,PGRADIENT_RECT,ULONG,ULONG,PRECTL,PDIBINFO,PPOINTL);
  737. LONGLONG MDiv64(LONGLONG,LONGLONG,LONGLONG);
  738. BOOL bDoGradient(LONGLONG *,LONGLONG *,LONGLONG *,LONG,LONG,LONG,GRADSTRUCT *);
  739. //
  740. // alpha
  741. //
  742. BOOL
  743. bInitAlpha();
  744. extern PBYTE pAlphaMulTable;
  745. #define INT_MULT(a,b,t) \
  746. t = ((a)*(b)) + 0x80; \
  747. t = ((((t) >> 8) + t) >> 8);
  748. #define INT_LERP(a,s,d,t) \
  749. INT_MULT((a),((s)-(d)),t); \
  750. t = t + (d);
  751. #define INT_PRELERP(a,s,d,t) \
  752. INT_MULT((a),(d),t); \
  753. t = (s) + (d) - t;
  754. #if DBG
  755. extern ULONG DbgAlpha;
  756. #define ALPHAMSG(level,s) \
  757. if (DbgAlpha >= level) \
  758. { \
  759. DbgPrint("%s\n",s); \
  760. }
  761. #else
  762. #define ALPHAMSG(level,s)
  763. #endif
  764. //
  765. //
  766. // routines to create compatible DIB/DC
  767. //
  768. //
  769. static
  770. UINT
  771. MyGetSystemPaletteEntries(HDC hdc, UINT iStartIndex, UINT nEntries,LPPALETTEENTRY lppe);
  772. static
  773. BOOL
  774. bFillColorTable(HDC hdc, HPALETTE hpal, BITMAPINFO *pbmi);
  775. static BOOL
  776. bFillColorTable(HDC hdc, HPALETTE hpal, BITMAPINFO *pbmi);
  777. static BOOL
  778. bFillBitmapInfoDirect(HDC hdc, HPALETTE hpal, BITMAPINFO *pbmi);
  779. static BOOL
  780. bFillBitmapInfoMemory(HDC hdc, HPALETTE hpal, BITMAPINFO *pbmi);
  781. HBITMAP APIENTRY
  782. CreateCompatibleDIB(
  783. HDC hdc,
  784. ULONG ulWidth,
  785. ULONG ulHeight,
  786. PVOID *ppvBits,
  787. BITMAPINFO *pbmi);
  788. VOID CreateTempDIBSections (HDC,HDC,ULONG,ULONG,PVOID *,PVOID *,HBITMAP *,HBITMAP *,PBITMAPINFO);
  789. extern PFNGRFILL gpfnGradientFill;
  790. BOOL
  791. WinAlphaBlend(
  792. HDC hdcDst,
  793. int DstX,
  794. int DstY,
  795. int DstCx,
  796. int DstCy,
  797. HDC hdcSrc,
  798. int SrcX,
  799. int SrcY,
  800. int SrcCx,
  801. int SrcCy,
  802. BLENDFUNCTION BlendFunction
  803. );
  804. BOOL
  805. WinAlphaDIBBlend(
  806. HDC hdcDst,
  807. int DstX,
  808. int DstY,
  809. int DstCx,
  810. int DstCy,
  811. CONST VOID *lpBits,
  812. CONST BITMAPINFO *lpBitsInfo,
  813. UINT iUsage,
  814. int SrcX,
  815. int SrcY,
  816. int SrcCx,
  817. int SrcCy,
  818. BLENDFUNCTION BlendFunction
  819. );
  820. BOOL
  821. WinGradientFill(
  822. HDC hdc,
  823. PTRIVERTEX pLogVertex,
  824. ULONG nVertex,
  825. PVOID pMesh,
  826. ULONG nMesh,
  827. ULONG ulMode
  828. );
  829. BOOL
  830. WinTransparentDIBits(
  831. HDC hdcDst,
  832. int xDst,
  833. int yDst,
  834. int cxDst,
  835. int cyDst,
  836. CONST VOID * lpBits,
  837. CONST BITMAPINFO *lpBitsInfo,
  838. UINT iUsage,
  839. int xSrc,
  840. int ySrc,
  841. int cxSrc,
  842. int cySrc,
  843. UINT TransColor
  844. );
  845. BOOL
  846. WinTransparentBlt(
  847. HDC hdcDst,
  848. int xDst,
  849. int yDst,
  850. int cxDst,
  851. int cyDst,
  852. HDC hdcSrc,
  853. int xSrc,
  854. int ySrc,
  855. int cxSrc,
  856. int cySrc,
  857. UINT TransColor
  858. );
  859. //
  860. // memory allocation
  861. //
  862. #if !(_WIN32_WINNT >= 0x500)
  863. #define LOCALALLOC(size) LocalAlloc(LMEM_FIXED,size)
  864. #define LOCALFREE(pv) LocalFree(pv)
  865. #else
  866. #define LOCALALLOC(size) RtlAllocateHeap(RtlProcessHeap(),0,size)
  867. #define LOCALFREE(pv) (void)RtlFreeHeap(RtlProcessHeap(),0,pv)
  868. #endif