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.

403 lines
9.5 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: image .c *
  3. * *
  4. * Client side stubs for Alpha, Transparent and GradientFill *
  5. * *
  6. * Created: 05-Jun-1997 *
  7. * Author: Mark Enstrom [marke] *
  8. * *
  9. * Copyright (c) 1991-1999 Microsoft Corporation *
  10. \**************************************************************************/
  11. #include "precomp.h"
  12. #pragma hdrstop
  13. /******************************Public*Routine******************************\
  14. * GdiAlphaBlend
  15. *
  16. * DC to DC alpha blt
  17. *
  18. * Arguments:
  19. *
  20. * hdcDst - dst dc
  21. * DstX - dst x origin
  22. * DstY - dst y origin
  23. * DstCx - dst width
  24. * DstCy - dst height
  25. * hdcSrc - src dc
  26. * SrcX - src x origin
  27. * SrcY - src y origin
  28. * SrcCx - src width
  29. * SrcCy - src height
  30. * BlendFunction - blend function
  31. *
  32. * Return Value:
  33. *
  34. * Status
  35. *
  36. * History:
  37. *
  38. * 12/3/1996 Mark Enstrom [marke]
  39. *
  40. \**************************************************************************/
  41. BOOL
  42. GdiAlphaBlend(
  43. HDC hdcDest,
  44. int DstX,
  45. int DstY,
  46. int DstCx,
  47. int DstCy,
  48. HDC hdcSrc,
  49. int SrcX,
  50. int SrcY,
  51. int SrcCx,
  52. int SrcCy,
  53. BLENDFUNCTION BlendFunction
  54. )
  55. {
  56. BOOL bRet = FALSE;
  57. BLENDULONG Blend;
  58. FIXUP_HANDLE(hdcDest);
  59. FIXUP_HANDLE(hdcSrc);
  60. Blend.Blend = BlendFunction;
  61. //
  62. // check for metafile
  63. //
  64. if (!hdcSrc || IS_METADC16_TYPE(hdcSrc))
  65. return(bRet);
  66. if (IS_ALTDC_TYPE(hdcDest))
  67. {
  68. PLDC pldc;
  69. if (IS_METADC16_TYPE(hdcDest))
  70. return(bRet);
  71. DC_PLDC(hdcDest,pldc,bRet);
  72. if (pldc->iType == LO_METADC)
  73. {
  74. if (!MF_AnyBitBlt(hdcDest,
  75. DstX,
  76. DstY,
  77. DstCx,
  78. DstCy,
  79. (LPPOINT)NULL,
  80. hdcSrc,
  81. SrcX,
  82. SrcY,
  83. SrcCx,
  84. SrcCy,
  85. (HBITMAP)NULL,
  86. 0,
  87. 0,
  88. Blend.ul,
  89. EMR_ALPHABLEND))
  90. {
  91. return(bRet);
  92. }
  93. }
  94. if (pldc->fl & LDC_SAP_CALLBACK)
  95. {
  96. vSAPCallback(pldc);
  97. }
  98. if (pldc->fl & LDC_DOC_CANCELLED)
  99. {
  100. return(bRet);
  101. }
  102. if (pldc->fl & LDC_CALL_STARTPAGE)
  103. {
  104. StartPage(hdcDest);
  105. }
  106. }
  107. RESETUSERPOLLCOUNT();
  108. //
  109. // call kernel to draw
  110. //
  111. bRet = NtGdiAlphaBlend(
  112. hdcDest,
  113. DstX,
  114. DstY,
  115. DstCx,
  116. DstCy,
  117. (HDC)hdcSrc,
  118. SrcX,
  119. SrcY,
  120. SrcCx,
  121. SrcCy,
  122. BlendFunction,
  123. NULL
  124. );
  125. return(bRet);
  126. }
  127. /******************************Public*Routine******************************\
  128. * GdiGradientFill
  129. *
  130. * metafile or call kernel
  131. *
  132. * Arguments:
  133. *
  134. * hdc - hdc
  135. * pVertex - pointer to vertex array
  136. * nVertex - number of elements in vertex array
  137. * pMesh - pointer to mesh array
  138. * nCount - number of elements in mesh array
  139. * ulMode - drawing mode
  140. *
  141. * Return Value:
  142. *
  143. * status
  144. *
  145. * History:
  146. *
  147. * 12/3/1996 Mark Enstrom [marke]
  148. *
  149. \**************************************************************************/
  150. BOOL
  151. GdiGradientFill(
  152. HDC hdc,
  153. PTRIVERTEX pVertex,
  154. ULONG nVertex,
  155. PVOID pMesh,
  156. ULONG nCount,
  157. ULONG ulMode
  158. )
  159. {
  160. BOOL bRet = TRUE;
  161. PTRIVERTEX pTempVertex = pVertex;
  162. PDC_ATTR pdcattr;
  163. FIXUP_HANDLE(hdc);
  164. PSHARED_GET_VALIDATE(pdcattr,hdc,DC_TYPE);
  165. if (pdcattr)
  166. {
  167. //
  168. // NT metafile
  169. //
  170. if (IS_ALTDC_TYPE(hdc))
  171. {
  172. PLDC pldc;
  173. if (IS_METADC16_TYPE(hdc))
  174. return(bRet);
  175. DC_PLDC(hdc,pldc,bRet);
  176. if (pldc->iType == LO_METADC)
  177. {
  178. bRet = MF_GradientFill(hdc,pVertex,nVertex,pMesh,nCount,ulMode);
  179. if (!bRet)
  180. {
  181. return(bRet);
  182. }
  183. }
  184. if (pldc->fl & LDC_SAP_CALLBACK)
  185. {
  186. vSAPCallback(pldc);
  187. }
  188. if (pldc->fl & LDC_DOC_CANCELLED)
  189. {
  190. return(bRet);
  191. }
  192. if (pldc->fl & LDC_CALL_STARTPAGE)
  193. {
  194. StartPage(hdc);
  195. }
  196. }
  197. RESETUSERPOLLCOUNT();
  198. //
  199. // if icm is on, tanslate vertex array
  200. //
  201. if (
  202. (IS_ICM_INSIDEDC(pdcattr->lIcmMode)) &&
  203. (pVertex != NULL) &&
  204. (nVertex > 0) &&
  205. (nVertex < 0x80000000)
  206. )
  207. {
  208. pTempVertex = (PTRIVERTEX)LOCALALLOC(nVertex * sizeof(TRIVERTEX));
  209. if (pTempVertex != NULL)
  210. {
  211. //
  212. // copy to new vertex array
  213. //
  214. memcpy(pTempVertex,pVertex,nVertex * sizeof(TRIVERTEX));
  215. bRet = IcmTranslateTRIVERTEX(hdc,pdcattr,pTempVertex,nVertex);
  216. }
  217. else
  218. {
  219. bRet = FALSE;
  220. GdiSetLastError(ERROR_NOT_ENOUGH_MEMORY);
  221. }
  222. }
  223. if (bRet)
  224. {
  225. //
  226. // call kernel to draw
  227. //
  228. bRet = NtGdiGradientFill(hdc,
  229. pTempVertex,
  230. nVertex,
  231. pMesh,
  232. nCount,
  233. ulMode
  234. );
  235. }
  236. //
  237. // free temp buffer
  238. //
  239. if (pTempVertex != pVertex)
  240. {
  241. LOCALFREE(pTempVertex);
  242. }
  243. }
  244. else
  245. {
  246. bRet = FALSE;
  247. GdiSetLastError(ERROR_INVALID_PARAMETER);
  248. }
  249. return(bRet);
  250. }
  251. /******************************Public*Routine******************************\
  252. * GdiTransparentBlt
  253. *
  254. *
  255. * Arguments:
  256. *
  257. *
  258. *
  259. * Return Value:
  260. *
  261. *
  262. *
  263. * History:
  264. *
  265. * 12/3/1996 Lingyun Wang
  266. *
  267. \**************************************************************************/
  268. BOOL
  269. GdiTransparentBlt(
  270. HDC hdcDest,
  271. int DstX,
  272. int DstY,
  273. int DstCx,
  274. int DstCy,
  275. HDC hSrc,
  276. int SrcX,
  277. int SrcY,
  278. int SrcCx,
  279. int SrcCy,
  280. UINT Color
  281. )
  282. {
  283. BOOL bRet = FALSE;
  284. PDC_ATTR pdca;
  285. if ((DstCx <= 0) || (DstCy <= 0) || (SrcCx <= 0) || (SrcCy <= 0))
  286. {
  287. return (FALSE);
  288. }
  289. FIXUP_HANDLE(hdcDest);
  290. FIXUP_HANDLE(hSrc);
  291. if (!hSrc || IS_METADC16_TYPE(hSrc))
  292. return(bRet);
  293. if (IS_ALTDC_TYPE(hdcDest))
  294. {
  295. PLDC pldc;
  296. if (IS_METADC16_TYPE(hdcDest))
  297. return(bRet);
  298. DC_PLDC(hdcDest,pldc,bRet);
  299. if (pldc->iType == LO_METADC)
  300. {
  301. if (!MF_AnyBitBlt(hdcDest,
  302. DstX,
  303. DstY,
  304. DstCx,
  305. DstCy,
  306. (LPPOINT)NULL,
  307. hSrc,
  308. SrcX,
  309. SrcY,
  310. SrcCx,
  311. SrcCy,
  312. (HBITMAP)NULL,
  313. 0,
  314. 0,
  315. Color,
  316. EMR_TRANSPARENTBLT))
  317. {
  318. return(bRet);
  319. }
  320. }
  321. if (pldc->fl & LDC_SAP_CALLBACK)
  322. {
  323. vSAPCallback(pldc);
  324. }
  325. if (pldc->fl & LDC_DOC_CANCELLED)
  326. {
  327. return(bRet);
  328. }
  329. if (pldc->fl & LDC_CALL_STARTPAGE)
  330. {
  331. StartPage(hdcDest);
  332. }
  333. }
  334. RESETUSERPOLLCOUNT();
  335. bRet = NtGdiTransparentBlt(
  336. hdcDest,
  337. DstX,
  338. DstY,
  339. DstCx,
  340. DstCy,
  341. hSrc,
  342. SrcX,
  343. SrcY,
  344. SrcCx,
  345. SrcCy,
  346. Color);
  347. return(bRet);
  348. }