Source code of Windows XP (NT5)
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.

377 lines
8.2 KiB

  1. // gdisemu.cpp : Defines the entry point for the DLL application.
  2. //
  3. #include "stdafx.h"
  4. #include "gdisemu.h"
  5. // This is an example of an exported variable
  6. //GDISEMU_API int nGdisemu=0;
  7. int StreamCopyTile(
  8. HDC hdcTarget,
  9. HDC hdcSource,
  10. DS_COPYTILE * cmd)
  11. {
  12. RECTL * dstRect = &cmd->rclDst;
  13. RECTL * srcRect = &cmd->rclSrc;
  14. POINTL * tileOrigin = &cmd->ptlOrigin;
  15. // brain dead for now
  16. LONG tileWidth = srcRect->right - srcRect->left;
  17. LONG tileHeight = srcRect->bottom - srcRect->top;
  18. LONG y = dstRect->top;
  19. LONG yEnd = dstRect->bottom;
  20. LONG xEnd = dstRect->right;
  21. if(tileWidth <= 0 || tileHeight <= 0)
  22. return FALSE;
  23. if(tileOrigin->x >= tileWidth || tileOrigin->y >= tileHeight)
  24. return FALSE;
  25. LONG sy = tileOrigin->y;
  26. while(y < yEnd)
  27. {
  28. LONG dy = yEnd - y;
  29. if(dy > (tileHeight - sy)) dy = (tileHeight - sy);
  30. LONG x = dstRect->left;
  31. LONG sx = tileOrigin->x;
  32. while(x < xEnd)
  33. {
  34. LONG dx = xEnd - x;
  35. if(dx > (tileWidth - sx)) dx = (tileWidth - sx);
  36. if(!BitBlt(hdcTarget, x, y, dx, dy, hdcSource, srcRect->left + sx, srcRect->top + sy, SRCCOPY))
  37. return FALSE;
  38. x += dx;
  39. sx = 0;
  40. }
  41. y += dy;
  42. sy = 0;
  43. }
  44. return TRUE;
  45. }
  46. int StreamTransparentTile(
  47. HDC hdcTarget,
  48. HDC hdcSource,
  49. DS_TRANSPARENTTILE * cmd)
  50. {
  51. RECTL * dstRect = &cmd->rclDst;
  52. RECTL * srcRect = &cmd->rclSrc;
  53. POINTL * tileOrigin = &cmd->ptlOrigin;
  54. // brain dead for now
  55. LONG tileWidth = srcRect->right - srcRect->left;
  56. LONG tileHeight = srcRect->bottom - srcRect->top;
  57. LONG y = dstRect->top;
  58. LONG yEnd = dstRect->bottom;
  59. LONG xEnd = dstRect->right;
  60. if(tileWidth <= 0 || tileHeight <= 0)
  61. return FALSE;
  62. if(tileOrigin->x >= tileWidth || tileOrigin->y >= tileHeight)
  63. return FALSE;
  64. LONG sy = tileOrigin->y;
  65. while(y < yEnd)
  66. {
  67. LONG dy = yEnd - y;
  68. if(dy > (tileHeight - sy)) dy = (tileHeight - sy);
  69. LONG x = dstRect->left;
  70. LONG sx = tileOrigin->x;
  71. while(x < xEnd)
  72. {
  73. LONG dx = xEnd - x;
  74. if(dx > (tileWidth - sx)) dx = (tileWidth - sx);
  75. if(!GdiTransparentBlt(hdcTarget, x, y, dx, dy, hdcSource, srcRect->left + sx, srcRect->top + sy, dx, dy, cmd->crTransparentColor))
  76. return FALSE;
  77. x += dx;
  78. sx = 0;
  79. }
  80. y += dy;
  81. sy = 0;
  82. }
  83. return TRUE;
  84. }
  85. int StreamAlphaTile(
  86. HDC hdcTarget,
  87. HDC hdcSource,
  88. DS_ALPHATILE * cmd)
  89. {
  90. RECTL * dstRect = &cmd->rclDst;
  91. RECTL * srcRect = &cmd->rclSrc;
  92. POINTL * tileOrigin = &cmd->ptlOrigin;
  93. // brain dead for now
  94. LONG tileWidth = srcRect->right - srcRect->left;
  95. LONG tileHeight = srcRect->bottom - srcRect->top;
  96. LONG y = dstRect->top;
  97. LONG yEnd = dstRect->bottom;
  98. LONG xEnd = dstRect->right;
  99. if(tileWidth <= 0 || tileHeight <= 0)
  100. return FALSE;
  101. if(tileOrigin->x >= tileWidth || tileOrigin->y >= tileHeight)
  102. return FALSE;
  103. LONG sy = tileOrigin->y;
  104. while(y < yEnd)
  105. {
  106. LONG dy = yEnd - y;
  107. if(dy > (tileHeight - sy)) dy = (tileHeight - sy);
  108. LONG x = dstRect->left;
  109. LONG sx = tileOrigin->x;
  110. while(x < xEnd)
  111. {
  112. LONG dx = xEnd - x;
  113. if(dx > (tileWidth - sx)) dx = (tileWidth - sx);
  114. if(!GdiAlphaBlend(hdcTarget, x, y, dx, dy, hdcSource, srcRect->left + sx, srcRect->top + sy, dx, dy, cmd->blendFunction))
  115. return FALSE;
  116. x += dx;
  117. sx = 0;
  118. }
  119. y += dy;
  120. sy = 0;
  121. }
  122. return TRUE;
  123. }
  124. int StreamSolidFill(
  125. HDC hdcTarget,
  126. DS_SOLIDFILL * cmd)
  127. {
  128. HBRUSH hbr = CreateSolidBrush(cmd->crSolidColor);
  129. FillRect(hdcTarget, (RECT *) &cmd->rclDst, hbr);
  130. DeleteObject(hbr);
  131. return TRUE;
  132. }
  133. int StreamStretch(
  134. HDC hdcTarget,
  135. HDC hdcSource,
  136. DS_STRETCH * cmd)
  137. {
  138. StretchBlt(hdcTarget, cmd->rclDst.left,
  139. cmd->rclDst.top,
  140. (cmd->rclDst.right - cmd->rclDst.left),
  141. (cmd->rclDst.bottom - cmd->rclDst.top),
  142. hdcSource, cmd->rclSrc.left,
  143. cmd->rclSrc.top,
  144. (cmd->rclSrc.right - cmd->rclSrc.left),
  145. (cmd->rclSrc.bottom - cmd->rclSrc.top),
  146. SRCCOPY);
  147. return TRUE;
  148. }
  149. int StreamTransparentStretch(
  150. HDC hdcTarget,
  151. HDC hdcSource,
  152. DS_TRANSPARENTSTRETCH * cmd)
  153. {
  154. GdiTransparentBlt(hdcTarget, cmd->rclDst.left,
  155. cmd->rclDst.top,
  156. (cmd->rclDst.right - cmd->rclDst.left),
  157. (cmd->rclDst.bottom - cmd->rclDst.top),
  158. hdcSource, cmd->rclSrc.left,
  159. cmd->rclSrc.top,
  160. (cmd->rclSrc.right - cmd->rclSrc.left),
  161. (cmd->rclSrc.bottom - cmd->rclSrc.top),
  162. cmd->crTransparentColor);
  163. return TRUE;
  164. }
  165. int StreamAlphaStretch(
  166. HDC hdcTarget,
  167. HDC hdcSource,
  168. DS_ALPHASTRETCH * cmd)
  169. {
  170. GdiAlphaBlend(hdcTarget, cmd->rclDst.left,
  171. cmd->rclDst.top,
  172. (cmd->rclDst.right - cmd->rclDst.left),
  173. (cmd->rclDst.bottom - cmd->rclDst.top),
  174. hdcSource, cmd->rclSrc.left,
  175. cmd->rclSrc.top,
  176. (cmd->rclSrc.right - cmd->rclSrc.left),
  177. (cmd->rclSrc.bottom - cmd->rclSrc.top),
  178. cmd->blendFunction);
  179. return TRUE;
  180. }
  181. /*GDISEMU_API*/ int DrawStream(int cjIn, void * pvIn)
  182. {
  183. HDC hdcTarget = NULL;
  184. HDC hdcSource = NULL;
  185. if(cjIn < sizeof(ULONG))
  186. return FALSE;
  187. ULONG * pul = (ULONG *) pvIn;
  188. // All streams should begin with DS_MAGIC
  189. if(*pul++ != DS_MAGIC)
  190. return FALSE;
  191. cjIn -= sizeof(ULONG);
  192. while(cjIn >= sizeof(ULONG))
  193. {
  194. ULONG command = pul[0];
  195. int commandSize;
  196. switch(command)
  197. {
  198. case DS_SETTARGETID: // set target
  199. commandSize = sizeof(DS_SETTARGET);
  200. if(cjIn < commandSize)
  201. return FALSE;
  202. hdcTarget = (HDC) pul[1];
  203. break;
  204. case DS_SETSOURCEID: // set source
  205. commandSize = sizeof(DS_SETSOURCE);
  206. if(cjIn < commandSize)
  207. return FALSE;
  208. hdcSource = (HDC) pul[1];
  209. break;
  210. case DS_SOLIDFILLID:
  211. commandSize = sizeof(DS_SOLIDFILL);
  212. if(cjIn < commandSize)
  213. return FALSE;
  214. if(!StreamSolidFill(hdcTarget, (DS_SOLIDFILL*) pul))
  215. return FALSE;
  216. break;
  217. case DS_COPYTILEID: // tile copy bits
  218. commandSize = sizeof(DS_COPYTILE);
  219. if(cjIn < commandSize)
  220. return FALSE;
  221. if(!StreamCopyTile(hdcTarget, hdcSource, (DS_COPYTILE*) pul))
  222. return FALSE;
  223. break;
  224. case DS_TRANSPARENTTILEID: // tile copy bits
  225. commandSize = sizeof(DS_TRANSPARENTTILE);
  226. if(cjIn < commandSize)
  227. return FALSE;
  228. if(!StreamTransparentTile(hdcTarget, hdcSource, (DS_TRANSPARENTTILE*) pul))
  229. return FALSE;
  230. break;
  231. case DS_ALPHATILEID: // tile copy bits
  232. commandSize = sizeof(DS_TRANSPARENTTILE);
  233. if(cjIn < commandSize)
  234. return FALSE;
  235. if(!StreamAlphaTile(hdcTarget, hdcSource, (DS_ALPHATILE*) pul))
  236. return FALSE;
  237. break;
  238. case DS_STRETCHID: // tile copy bits
  239. commandSize = sizeof(DS_STRETCH);
  240. if(cjIn < commandSize)
  241. return FALSE;
  242. if(!StreamStretch(hdcTarget, hdcSource, (DS_STRETCH*) pul))
  243. return FALSE;
  244. break;
  245. case DS_TRANSPARENTSTRETCHID: // tile copy bits
  246. commandSize = sizeof(DS_TRANSPARENTSTRETCH);
  247. if(cjIn < commandSize)
  248. return FALSE;
  249. if(!StreamTransparentStretch(hdcTarget, hdcSource, (DS_TRANSPARENTSTRETCH*) pul))
  250. return FALSE;
  251. break;
  252. case DS_ALPHASTRETCHID: // tile copy bits
  253. commandSize = sizeof(DS_ALPHASTRETCH);
  254. if(cjIn < commandSize)
  255. return FALSE;
  256. if(!StreamAlphaStretch(hdcTarget, hdcSource, (DS_ALPHASTRETCH*) pul))
  257. return FALSE;
  258. break;
  259. default:
  260. return FALSE;
  261. }
  262. cjIn -= commandSize;
  263. pul += commandSize / 4;
  264. }
  265. return TRUE;
  266. }