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.

547 lines
19 KiB

  1. // Copyright (c) 1992-1993 Microsoft Corporation
  2. /*============================================================================
  3. This code module implements styled lines in the NT format.
  4. 05/29/81 v-BertD Initial code (used in RP_LineEE_Draw)
  5. 02/20/92 RodneyK Converted to Styled line code.
  6. 02/21/92 RodneyK Each bit in the Mask is used for two pixels.
  7. 03/20/92 RodneyK Converted to NT style format.
  8. 06/01/93 RajeevD Collapsed ROP handling from StyleLine* to Draw*.
  9. (Reduces code size by 8K with no loss in speed.)
  10. ============================================================================*/
  11. #include <windows.h>
  12. #include "constant.h"
  13. #include "frame.h" // driver header file, resource block format
  14. #include "jtypes.h" /* Jumbo type definitions. */
  15. #include "jres.h" // cartridge resource data type definition
  16. #include "hretype.h" /* Slice Descriptor defs. */
  17. // Table data for the predefined pen styles
  18. ULONG ulWinStyles[] =
  19. {
  20. 0x00000002, 0x00ffffff, 0x00000000, /* solid */
  21. 0x00000002, 0x00000028, 0x00000010, /* dash */ /* 28 */
  22. 0x00000002, 0x00000008, 0x00000008, /* dot */
  23. 0x00000004, 0x0000001c, 0x0000000f, 0x00000008, 0x0000000f, /* dash dot */
  24. 0x00000006, 0x0000001c, 0x0000000f, 0x00000008, 0x00000008,0x00000008, 0x0000000f,
  25. 0x00000002, 0x00000000, 0x00ffffff, /* NULL */
  26. 0x00000002, 0x00ffffff, 0x00000000 /* Inside border */
  27. };
  28. const BYTE ulStyleLookUp[7] =
  29. { 0x00, 0x03, 0x06, 0x09, 0x0e, 0x15, 0x18};
  30. const USHORT usStyleSize[7] =
  31. {0x0000, 0x0038, 0x0010, 0x0042, 0x0052, 0x0000, 0x0000 };
  32. typedef void (*ROPPROC)(LPBYTE, WORD, BYTE);
  33. //==============================================================================
  34. void DrawANDDNR (LPBYTE lpbFrame, WORD wColor, BYTE bPos)
  35. {
  36. if (~(*lpbFrame & wColor) & bPos)
  37. *lpbFrame |= bPos;
  38. else
  39. *lpbFrame &= ~bPos;
  40. }
  41. //==============================================================================
  42. void DrawANDDR (LPBYTE lpbFrame, WORD wColor, BYTE bPos)
  43. {
  44. *lpbFrame &= ~bPos;
  45. }
  46. //==============================================================================
  47. void DrawANDNDR (LPBYTE lpbFrame, WORD wColor, BYTE bPos)
  48. {
  49. if (((~*lpbFrame) & wColor) & bPos)
  50. *lpbFrame |= bPos;
  51. else
  52. *lpbFrame &= ~bPos;
  53. }
  54. //==============================================================================
  55. void DrawCOPY0 (LPBYTE lpbFrame, WORD wColor, BYTE bPos)
  56. {
  57. *lpbFrame &= ~bPos;
  58. }
  59. //==============================================================================
  60. void DrawCOPY1 (LPBYTE lpbFrame, WORD wColor, BYTE bPos)
  61. {
  62. *lpbFrame |= bPos;
  63. }
  64. //==============================================================================
  65. void DrawORDNR (LPBYTE lpbFrame, WORD wColor, BYTE bPos)
  66. {
  67. if ((~(*lpbFrame | wColor)) & bPos)
  68. *lpbFrame |= bPos;
  69. else
  70. *lpbFrame &= ~bPos;
  71. }
  72. //==============================================================================
  73. void DrawORDR (LPBYTE lpbFrame, WORD wColor, BYTE bPos)
  74. {
  75. *lpbFrame |= bPos;
  76. }
  77. //==============================================================================
  78. void DrawORNDR (LPBYTE lpbFrame, WORD wColor, BYTE bPos)
  79. {
  80. if (((~*lpbFrame) | wColor) & bPos)
  81. *lpbFrame |= bPos;
  82. else
  83. *lpbFrame &= ~bPos;
  84. }
  85. //==============================================================================
  86. void DrawXOR (LPBYTE lpbFrame, WORD wColor, BYTE bPos)
  87. {
  88. if ((~*lpbFrame) & bPos)
  89. *lpbFrame |= bPos;
  90. else
  91. *lpbFrame &= ~bPos;
  92. }
  93. //==============================================================================
  94. void StyleLine
  95. (
  96. LPRESTATE lpREState, // resource executor context
  97. RP_SLICE_DESC FAR*psdSlice, /* Line Slice descriptor */
  98. ULONG *pulStyle, /* Line style pointer */
  99. WORD wColor,
  100. ROPPROC RopProc
  101. )
  102. /*==============================================================================
  103. PURPOSE This function handle the OR Raster operations for
  104. the styled line code. It draws a line based on the
  105. Slice descriptor, current color, current ROP, and
  106. the current linestyle.
  107. The function runs through the slice and determine
  108. whether a point is to drawn or not. The raster
  109. operation is applied only the points which need to
  110. be drawn.
  111. ASSUMPTIONS & This code assumes that the slice descriptor and the
  112. ASSERTIONS pointer to the style table are valid and correct.
  113. No checks are performed to validate this data.
  114. ==============================================================================*/
  115. {
  116. LPBITMAP lpbm;
  117. register UBYTE FAR *pbFrame; /* frame pointer */
  118. SLONG lSlice_x, lSlice_y; /* Slice Run variables */
  119. SLONG lSkip_x, lSkip_y; /* Slice skip variables */
  120. register UBYTE usfPos; /* Bit in frame to modify */
  121. register SHORT i; /* Slice variable */
  122. ULONG *pulStyleTmp; /* Pointer to style data */
  123. register ULONG ulDrawCount; /* Number of pixels to draw on */
  124. ULONG ulStyleCount; /* Count of data in line style */
  125. register BYTE bDraw; /* To draw or Not to draw */
  126. pulStyleTmp = pulStyle + 1; /* Point to style data */
  127. ulDrawCount = *pulStyleTmp++; /* Get the first count */
  128. ulStyleCount = *(pulStyle) - 1; /* Pattern longs remaining */
  129. bDraw = 0xFF; /* Start by drawing */
  130. for ( i = 0 ; i < (SHORT)lpREState->usPenPhase; i++)
  131. {
  132. if(!ulDrawCount) /* Flip draw mask */
  133. {
  134. bDraw = (BYTE)~bDraw;
  135. if (!ulStyleCount--) /* recycle the pattern? */
  136. {
  137. ulStyleCount = *(pulStyle) - 1;
  138. pulStyleTmp = pulStyle + 1;
  139. }
  140. ulDrawCount = *pulStyleTmp++; /* Get next style count */
  141. }
  142. ulDrawCount--;
  143. }
  144. lpbm = lpREState->lpBandBuffer;
  145. pbFrame = (UBYTE FAR*) lpbm->bmBits;
  146. pbFrame += psdSlice->us_y1 * lpbm->bmWidthBytes;
  147. pbFrame += psdSlice->us_x1 >> 3;
  148. usfPos = (UBYTE)(0x80 >> (psdSlice->us_x1 & 0x7)); /* Calculate the bit mask */
  149. lSlice_x = psdSlice->s_dx_draw;
  150. lSlice_y = psdSlice->s_dy_draw * lpbm->bmWidthBytes;
  151. lSkip_x = psdSlice->s_dx_skip;
  152. lSkip_y = psdSlice->s_dy_skip * lpbm->bmWidthBytes;
  153. // Do the first slice...
  154. if (psdSlice->us_first)
  155. {
  156. for ( i = psdSlice->us_first ; i > 0 ; --i )
  157. {
  158. if(!ulDrawCount) /* Flip draw mask */
  159. {
  160. bDraw = (BYTE)~bDraw;
  161. if (!ulStyleCount--) /* recycle the pattern? */
  162. {
  163. ulStyleCount = *(pulStyle) - 1;
  164. pulStyleTmp = pulStyle + 1;
  165. }
  166. ulDrawCount = *pulStyleTmp++; /* Get next style count */
  167. }
  168. ulDrawCount--;
  169. if (bDraw)
  170. (*RopProc)(pbFrame, wColor, usfPos);
  171. if (lSlice_x < 0)
  172. {
  173. usfPos <<= 1;
  174. if ( usfPos == 0 ) /* Check mask underflow and adjust */
  175. {
  176. usfPos = 0x01; /* Reset the bit mask */
  177. pbFrame -= 1; /* move to next UBYTE */
  178. }
  179. }
  180. else
  181. {
  182. usfPos >>= lSlice_x;
  183. if ( usfPos == 0 ) /* Check mask underflow and adjust */
  184. {
  185. usfPos = 0x80; /* Reset the bit mask */
  186. pbFrame += 1; /* move to next UBYTE */
  187. }
  188. }
  189. pbFrame += lSlice_y; /* advance to next row */
  190. }
  191. if ( lSkip_x < 0 ) /* going to the left? */
  192. {
  193. usfPos <<= 1; /* shift the mask */
  194. if ( usfPos == 0 ) /* Check for over/under flow */
  195. {
  196. usfPos = 0x01; /* Reset Mask */
  197. pbFrame -= 1; /* point to the next UBYTE */
  198. }
  199. }
  200. else /* moving to the right */
  201. {
  202. usfPos >>= lSkip_x;
  203. if ( usfPos == 0 )
  204. {
  205. usfPos = 0x80;
  206. pbFrame += 1;
  207. }
  208. }
  209. pbFrame += lSkip_y;
  210. }
  211. // Do the intermediate slices...
  212. for ( ; psdSlice->us_n_slices > 0 ; --psdSlice->us_n_slices )
  213. {
  214. if ( psdSlice->s_dis < 0 )
  215. {
  216. i = psdSlice->us_small;
  217. psdSlice->s_dis += psdSlice->s_dis_sm;
  218. }
  219. else
  220. {
  221. i = psdSlice->us_small + 1;
  222. psdSlice->s_dis += psdSlice->s_dis_lg;
  223. }
  224. for ( ; i > 0 ; --i )
  225. {
  226. if(!ulDrawCount) /* Is it time to flip the draw state */
  227. {
  228. bDraw = (BYTE)~bDraw; /* Yes, Change it */
  229. if (!ulStyleCount--) /* Recycle pattern? */
  230. {
  231. ulStyleCount = *(pulStyle) - 1;
  232. pulStyleTmp = pulStyle + 1;
  233. }
  234. ulDrawCount = *pulStyleTmp++; /* Advance the pattern */
  235. }
  236. ulDrawCount--;
  237. if (bDraw)
  238. (*RopProc)(pbFrame, wColor, usfPos);
  239. if (lSlice_x < 0)
  240. {
  241. usfPos <<= 1;
  242. if ( usfPos == 0 ) /* Check mask underflow and adjust */
  243. {
  244. usfPos = 0x01; /* Reset the bit mask */
  245. pbFrame -= 1; /* move to next UBYTE */
  246. }
  247. }
  248. else
  249. {
  250. usfPos >>= lSlice_x;
  251. if ( usfPos == 0 ) /* Check mask underflow and adjust */
  252. {
  253. usfPos = 0x80; /* Reset the bit mask */
  254. pbFrame += 1; /* move to next UBYTE */
  255. }
  256. }
  257. pbFrame += lSlice_y;
  258. }
  259. if ( lSkip_x < 0 ) /* Check for negative movement */
  260. {
  261. usfPos <<= 1;
  262. if ( usfPos == 0 )
  263. {
  264. usfPos = 0x01;
  265. pbFrame -= 1;
  266. }
  267. }
  268. else
  269. {
  270. usfPos >>= lSkip_x; /* Do positive case */
  271. if ( usfPos == 0 )
  272. {
  273. usfPos = 0x80;
  274. pbFrame += 1;
  275. }
  276. }
  277. pbFrame += lSkip_y;
  278. }
  279. // Do the last slice...
  280. for ( i = psdSlice->us_last ; i > 0 ; --i )
  281. {
  282. if(!ulDrawCount) /* Check to see if draw status needs */
  283. { /* to be changed */
  284. bDraw = (BYTE)~bDraw;
  285. if (!ulStyleCount--)
  286. { /* update the style pointer */
  287. ulStyleCount = *(pulStyle) - 1;
  288. pulStyleTmp = pulStyle + 1;
  289. }
  290. ulDrawCount = *pulStyleTmp++;
  291. }
  292. ulDrawCount--; /* count down the style count */
  293. if (bDraw)
  294. (*RopProc)(pbFrame, wColor, usfPos);
  295. if (lSlice_x < 0)
  296. {
  297. usfPos <<= 1;
  298. if ( usfPos == 0 ) /* Check mask underflow and adjust */
  299. {
  300. usfPos = 0x01; /* Reset the bit mask */
  301. pbFrame -= 1; /* move to next UBYTE */
  302. }
  303. }
  304. else
  305. {
  306. usfPos >>= lSlice_x;
  307. if ( usfPos == 0 ) /* Check mask underflow and adjust */
  308. {
  309. usfPos = 0x80; /* Reset the bit mask */
  310. pbFrame += 1; /* move to next UBYTE */
  311. }
  312. }
  313. pbFrame += lSlice_y;
  314. }
  315. // AdjustPhase(psdSlice);
  316. {
  317. SHORT sDx, sDy;
  318. USHORT usLength;
  319. sDx = psdSlice->us_x2 - psdSlice->us_x1;
  320. sDy = psdSlice->us_y2 - psdSlice->us_y1;
  321. if (sDx < 0) sDx = -sDx;
  322. if (sDy < 0) sDy = -sDy;
  323. usLength = usStyleSize[lpREState->ubPenStyle];
  324. if (usLength != 0)
  325. {
  326. if (sDx < sDy)
  327. lpREState->usPenPhase += (USHORT)sDy + 1;
  328. else
  329. lpREState->usPenPhase += (USHORT)sDx + 1;
  330. lpREState->usPenPhase %= usLength;
  331. }
  332. }
  333. }
  334. //==============================================================================
  335. void GetTotalPixels
  336. (
  337. RP_SLICE_DESC FAR *psdSlice /* Line Slice descriptor */
  338. )
  339. //
  340. // PURPOSE Caculate how many pixel are going to be drawn.
  341. // Put the result in us_y2 = us_y1 + Total Pixels
  342. // This function is called only in JG_RP_LineSlice
  343. //
  344. // ASSUMPTIONS & This code assumes that the slice descriptor and the
  345. // ASSERTIONS pointer to the style table are valid and correct.
  346. // No checks are performed to validate this data.
  347. // If an unsupported ROP is sent ROP(0) BLACKNESS is
  348. // used.
  349. //
  350. // INTERNAL STRUCTURES No complex internal data structure are used
  351. //
  352. //--------------------------------------------------------------------------*/
  353. {
  354. USHORT usTotalPixels;
  355. SHORT sDis;
  356. SHORT i;
  357. usTotalPixels = psdSlice->us_first + psdSlice->us_last;
  358. sDis = psdSlice->s_dis;
  359. for (i = 0; i < (SHORT)psdSlice->us_n_slices; i++) {
  360. if ( sDis < 0 )
  361. {
  362. usTotalPixels += psdSlice->us_small;
  363. sDis += psdSlice->s_dis_sm;
  364. }
  365. else
  366. {
  367. usTotalPixels += psdSlice->us_small + 1;
  368. sDis += psdSlice->s_dis_lg;
  369. }
  370. }
  371. psdSlice->us_y2 = psdSlice->us_y1 + usTotalPixels - 1;
  372. return;
  373. }
  374. //==============================================================================
  375. BYTE StyleLineDraw
  376. (
  377. LPRESTATE lpREState, // resource executor context
  378. RP_SLICE_DESC FAR *psdSlice, /* Line Slice descriptor */
  379. UBYTE ubLineStyle, /* Line style pointer */
  380. SHORT sRop,
  381. SHORT usColor
  382. )
  383. /*
  384. //
  385. // PURPOSE This function calls the correct function to draw
  386. // a single pixel styled line using the correct
  387. // ROP, Linestyle, and color (pen).
  388. //
  389. // ASSUMPTIONS & This code assumes that the slice descriptor and the
  390. // ASSERTIONS pointer to the style table are valid and correct.
  391. // No checks are performed to validate this data.
  392. // If an unsupported ROP is sent ROP(0) BLACKNESS is
  393. // used.
  394. //
  395. // INTERNAL STRUCTURES No complex internal data structure are used
  396. //
  397. // UNRESOLVED ISSUES Banding problems???
  398. //
  399. // RETURNS 0 - use fast line, 1 - don't draw, 2 - style drawn
  400. //
  401. //--------------------------------------------------------------------------*/
  402. {
  403. BYTE bRetVal; /* Return value for optimizing certain cases */
  404. ULONG *pulStyle; /* Line style pointer */
  405. BYTE bSolid;
  406. if (!ubLineStyle && ((psdSlice->s_dx_draw < 0) || (psdSlice->s_dx_skip <0)))
  407. {
  408. // JG_WARNING("Neg X with Solid Line");
  409. ubLineStyle = 6; /* for style line code to do it */
  410. }
  411. if (ubLineStyle == 5)
  412. bRetVal = 1;
  413. else
  414. {
  415. /* Note style 6 will not be considered solid to simplify things */
  416. bSolid = (BYTE)(ubLineStyle == 0);
  417. pulStyle = &ulWinStyles[ulStyleLookUp[ubLineStyle]];
  418. bRetVal = 2;
  419. if (usStyleSize[ubLineStyle])
  420. lpREState->usPenPhase %= usStyleSize[ubLineStyle];
  421. switch (sRop)
  422. {
  423. case 0x00 : /* ROP BLACK */
  424. if(bSolid) bRetVal = 0;
  425. else StyleLine (lpREState, psdSlice, pulStyle, 0, DrawCOPY1);
  426. break;
  427. case 0x05 : /* DPon */
  428. StyleLine (lpREState, psdSlice, pulStyle, usColor, DrawORDNR);
  429. break;
  430. case 0x0a : /* DPna */
  431. if(!usColor) bRetVal = 1;
  432. else StyleLine (lpREState, psdSlice, pulStyle, 0, DrawANDDR);
  433. break;
  434. case 0x0f : /* Pn */
  435. if(bSolid && !usColor)
  436. bRetVal = 0;
  437. else
  438. if (usColor)
  439. StyleLine (lpREState, psdSlice, pulStyle, 0, DrawCOPY0);
  440. else
  441. StyleLine (lpREState, psdSlice, pulStyle, 0, DrawCOPY1);
  442. break;
  443. case 0x50 : /* PDna */
  444. StyleLine (lpREState, psdSlice, pulStyle, usColor, DrawANDNDR);
  445. break;
  446. case 0x55 : /* Dn */
  447. usColor = 0x0000;
  448. StyleLine (lpREState, psdSlice, pulStyle, usColor, DrawORNDR);
  449. break;
  450. case 0x5a : /* DPx */
  451. if(!usColor) bRetVal = 1;
  452. else StyleLine (lpREState, psdSlice, pulStyle, 0, DrawXOR);
  453. break;
  454. case 0x5f : /* DPan */
  455. if(bSolid && !usColor) bRetVal = 0;
  456. else StyleLine (lpREState, psdSlice, pulStyle, usColor, DrawANDDNR);
  457. break;
  458. case 0xa0 : /* DPa */
  459. if(usColor) bRetVal = 1;
  460. else StyleLine (lpREState, psdSlice, pulStyle, 0, DrawANDDR);
  461. break;
  462. case 0xa5 : /* PDxn */
  463. if(usColor) bRetVal = 1;
  464. else StyleLine (lpREState, psdSlice, pulStyle, 0, DrawXOR);
  465. break;
  466. case 0xaa : /* D */
  467. bRetVal = 1;
  468. break;
  469. case 0xaf : /* DPno */
  470. if (usColor) bRetVal = 1;
  471. else if(bSolid) bRetVal = 0;
  472. else StyleLine (lpREState, psdSlice, pulStyle, 0, DrawORDR);
  473. break;
  474. case 0xf0 : /* P */
  475. if(bSolid && usColor) bRetVal = 0;
  476. else if (usColor)
  477. StyleLine (lpREState, psdSlice, pulStyle, 0, DrawCOPY1);
  478. else
  479. StyleLine (lpREState, psdSlice, pulStyle, 0, DrawCOPY0);
  480. break;
  481. case 0xf5 : /* PDno */
  482. if(bSolid && usColor) bRetVal = 0;
  483. else StyleLine (lpREState, psdSlice, pulStyle, usColor, DrawORNDR);
  484. break;
  485. case 0xfa : /* PDo */
  486. if (!usColor) bRetVal = 1;
  487. else if(bSolid) bRetVal = 0;
  488. else StyleLine (lpREState, psdSlice, pulStyle, 0, DrawORDR);
  489. break;
  490. case 0xFF : /* WHITENESS */
  491. StyleLine (lpREState, psdSlice, pulStyle, 0, DrawCOPY0);
  492. break;
  493. default: /* BLACKNESS */
  494. if(bSolid) bRetVal = 0;
  495. else StyleLine (lpREState, psdSlice, pulStyle, 0, DrawCOPY1);
  496. }
  497. }
  498. return (bRetVal);
  499. }