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.

643 lines
22 KiB

  1. /*
  2. ** Copyright (c) 1991 Microsoft Corporation
  3. */
  4. //===========================================================================
  5. // FILE RPLNEE.C
  6. //
  7. // MODULE Host Resource Executor
  8. //
  9. // PURPOSE Using Bresenham run slice algorithm to
  10. // draw single pixel line.
  11. //
  12. // DESCRIBED IN Resource Executor design spec.
  13. //
  14. // The drawing sectors are also described in the following diagram.
  15. // Y is shown increasing down the page as do the printer physical
  16. // coordinates. The program code handles separately sectors 0/7, 6/1, 5/2
  17. // and 4/3.
  18. //
  19. //
  20. // | x x
  21. // | x
  22. // | x x
  23. // | x
  24. // | 0 x 1 x
  25. // | x
  26. // | x x
  27. // | x
  28. // | x x
  29. // | x 2
  30. // | x x x
  31. // | x x
  32. // | x x x
  33. // | x x
  34. // | x x x
  35. // | x x
  36. // |x x x 3
  37. // | x x
  38. // |x x
  39. // |------------------- --> X
  40. // |x x
  41. // | x x
  42. // |x x x 4
  43. // | x x
  44. // | x x x
  45. // | x x
  46. // | x x x
  47. // | x x
  48. // | x x x
  49. // | x 5
  50. // | x x
  51. // | x
  52. // | x x
  53. // | x
  54. // | 7 x 6 x
  55. // | x
  56. // | x x
  57. // | x
  58. // | x x
  59. //
  60. //
  61. // |
  62. // |
  63. // \|/
  64. //
  65. // Y
  66. //
  67. //
  68. // MNEMONICS n/a
  69. //
  70. // HISTORY 1/17/92 dstseng created
  71. //
  72. //===========================================================================
  73. // include file
  74. #include <windows.h>
  75. #include "constant.h"
  76. #include "frame.h" // driver header file, resource block format
  77. #include "jtypes.h" // type definition used in cartridge
  78. #include "jres.h" // cartridge resource data type definition
  79. #include "hretype.h" // define data structure used by hre.c and rpgen.c
  80. #include "rplnee.h"
  81. static
  82. void ShortSlice07(RP_SLICE_DESC FAR* line,
  83. drawInfoStructType FAR *drawInfo,
  84. uint16 firstOrLast);
  85. static
  86. void ShortSlice16(RP_SLICE_DESC FAR* line,
  87. drawInfoStructType FAR *drawInfo,
  88. uint16 firstOrLast);
  89. static
  90. void ShortSlice25(RP_SLICE_DESC FAR* line,
  91. drawInfoStructType FAR *drawInfo,
  92. uint16 firstOrLast);
  93. static
  94. void DisplaySlice34(RP_SLICE_DESC FAR* line,
  95. drawInfoStructType FAR *drawInfo,
  96. uint16 firstOrLast);
  97. //---------------------------------------------------------------------------
  98. UINT //always return 0 to upper level
  99. RP_LineEE_Draw
  100. (
  101. RP_SLICE_DESC FAR FAR* line, /* output slice form of line */
  102. LPBITMAP lpbm
  103. )
  104. // PURPOSE input RP_SLICE_DESC is prepared by RP_SliceLine
  105. // according to different sector (0-7),
  106. // this routine will call different functions
  107. // to draw the slices with the length recorded
  108. // in FAR* line.
  109. //
  110. //
  111. // ASSUMPTIONS & ASSERTIONS None.
  112. //
  113. // INTERNAL STRUCTURES RP_SLICE_DESC is defined in hretype.h
  114. //
  115. // UNRESOLVED ISSUES programmer development notes
  116. //---------------------------------------------------------------------------
  117. {
  118. uint16 func;
  119. /* Get function address according to drawing & skipping direction */
  120. func = (line->s_dx_draw << 3) + (line->s_dy_draw << 2) +
  121. (line->s_dx_skip << 1) + line->s_dy_skip + 2;
  122. /* Call corresponding function to render line */
  123. (*sector_function[func])(line, lpbm);
  124. return(0);
  125. }
  126. //---------------------------------------------------------------------------
  127. static void
  128. Sector07
  129. (
  130. RP_SLICE_DESC FAR* line, /* output slice form of line */
  131. LPBITMAP lpbm
  132. )
  133. // PURPOSE input RP_SLICE_DESC is prepared by RP_SliceLine
  134. // prepare drawinfo and call ShortSlice07()
  135. // to draw the line located in sector 0/7
  136. // dy/dx > 2
  137. //
  138. //
  139. // ASSUMPTIONS & ASSERTIONS None.
  140. //
  141. // INTERNAL STRUCTURES RP_SLICE_DESC is defined in hretype.h
  142. // drawInfoStructType is defined in rplnee.h
  143. //
  144. // UNRESOLVED ISSUES programmer development notes
  145. //---------------------------------------------------------------------------
  146. {
  147. uint16 func;
  148. uint16 bitShift;
  149. drawInfoStructType drawInfo;
  150. drawInfo.bytePosition = (uint16 FAR *)((UINT_PTR)lpbm->bmBits +
  151. line->us_y1 * lpbm->bmWidthBytes);
  152. drawInfo.bytePosition += line->us_x1 >> 4;
  153. func = (line->s_dx_draw << 3) + (line->s_dy_draw << 2) +
  154. (line->s_dx_skip << 1) + line->s_dy_skip + 2;
  155. if (func == SECTOR0)
  156. drawInfo.nextY = -1 * lpbm->bmWidthBytes; /* sector 0 */
  157. else
  158. drawInfo.nextY = lpbm->bmWidthBytes; /* sector 7 */
  159. bitShift = line->us_x1 & 0x000F;
  160. drawInfo.bitPosition = 0x8000 >> bitShift;
  161. /* Now rendering the first slice */
  162. if (line->us_first > 0) {
  163. ShortSlice07(line, &drawInfo, FIRST);
  164. }
  165. /* Rendering intermediate slices */
  166. if (line->us_n_slices > 0) {
  167. ShortSlice07(line, &drawInfo, (uint16)0);
  168. }
  169. /* Now rendering the last slice */
  170. if (line->us_last > 0) {
  171. ShortSlice07(line, &drawInfo, LAST);
  172. }
  173. return;
  174. }
  175. //---------------------------------------------------------------------------
  176. static void
  177. Sector16
  178. (
  179. RP_SLICE_DESC FAR* line, /* output slice form of line */
  180. LPBITMAP lpbm
  181. )
  182. // PURPOSE input RP_SLICE_DESC is prepared by RP_SliceLine
  183. // prepare drawinfo and call ShortSlice16()
  184. // to draw the line located in sector 1/6
  185. // 2 > dy/dx > 1
  186. //
  187. //
  188. // ASSUMPTIONS & ASSERTIONS None.
  189. //
  190. // INTERNAL STRUCTURES RP_SLICE_DESC is defined in hretype.h
  191. // drawInfoStructType is defined in rplnee.h
  192. //
  193. // UNRESOLVED ISSUES programmer development notes
  194. //---------------------------------------------------------------------------
  195. {
  196. uint16 func;
  197. uint16 bitShift;
  198. drawInfoStructType drawInfo;
  199. drawInfo.bytePosition = (uint16 FAR *)((UINT_PTR)lpbm->bmBits +
  200. line->us_y1 * lpbm->bmWidthBytes);
  201. drawInfo.bytePosition += line->us_x1 >> 4;
  202. func = (line->s_dx_draw << 3) + (line->s_dy_draw << 2) +
  203. (line->s_dx_skip << 1) + line->s_dy_skip + 2;
  204. if (func == SECTOR1)
  205. drawInfo.nextY = -1 * lpbm->bmWidthBytes; /* sector 1 */
  206. else
  207. drawInfo.nextY = lpbm->bmWidthBytes; /* sector 6 */
  208. bitShift = line->us_x1 & 0x000F;
  209. drawInfo.bitPosition = 0x8000 >> bitShift;
  210. /* Now rendering the first slice */
  211. if (line->us_first > 0) {
  212. ShortSlice16(line, &drawInfo, FIRST);
  213. }
  214. /* Rendering intermediate slices */
  215. if (line->us_n_slices > 0) {
  216. ShortSlice16(line, &drawInfo, (uint16)0);
  217. }
  218. /* Now rendering the last slice */
  219. if (line->us_last > 0) {
  220. ShortSlice16(line, &drawInfo, LAST);
  221. }
  222. return;
  223. }
  224. //---------------------------------------------------------------------------
  225. static void
  226. Sector25
  227. (
  228. RP_SLICE_DESC FAR* line, /* output slice form of line */
  229. LPBITMAP lpbm
  230. )
  231. // PURPOSE input RP_SLICE_DESC is prepared by RP_SliceLine
  232. // prepare drawinfo and call ShortSlice25()
  233. // to draw the line located in sector 2/5
  234. // 1 < dx/dy < 2
  235. //
  236. //
  237. // ASSUMPTIONS & ASSERTIONS None.
  238. //
  239. // INTERNAL STRUCTURES RP_SLICE_DESC is defined in hretype.h
  240. // drawInfoStructType is defined in rplnee.h
  241. //
  242. // UNRESOLVED ISSUES programmer development notes
  243. //---------------------------------------------------------------------------
  244. {
  245. uint16 func;
  246. uint16 bitShift;
  247. drawInfoStructType drawInfo;
  248. drawInfo.bytePosition = (uint16 FAR *)((UINT_PTR)lpbm->bmBits +
  249. line->us_y1 * lpbm->bmWidthBytes);
  250. drawInfo.bytePosition += line->us_x1 >> 4;
  251. func = (line->s_dx_draw << 3) + (line->s_dy_draw << 2) +
  252. (line->s_dx_skip << 1) + line->s_dy_skip + 2;
  253. if (func == SECTOR2)
  254. drawInfo.nextY = -1 * lpbm->bmWidthBytes; /* sector 2 */
  255. else
  256. drawInfo.nextY = lpbm->bmWidthBytes; /* sector 5 */
  257. bitShift = line->us_x1 & 0x000F;
  258. drawInfo.bitPosition = 0x8000 >> bitShift;
  259. /* Now rendering the first slice */
  260. if (line->us_first > 0) {
  261. ShortSlice25(line, &drawInfo, FIRST);
  262. }
  263. /* Rendering intermediate slices */
  264. if (line->us_n_slices > 0) {
  265. ShortSlice25(line, &drawInfo, (uint16)0);
  266. }
  267. /* Now rendering the last slice */
  268. if (line->us_last > 0) {
  269. ShortSlice25(line, &drawInfo, LAST);
  270. }
  271. return;
  272. }
  273. //---------------------------------------------------------------------------
  274. static void
  275. Sector34
  276. (
  277. RP_SLICE_DESC FAR* line, /* output slice form of line */
  278. LPBITMAP lpbm
  279. )
  280. // PURPOSE input RP_SLICE_DESC is prepared by RP_SliceLine
  281. // prepare drawinfo and call DisplaySlice34()
  282. // to draw the line located in sector 3/4
  283. // dx/dy > 2
  284. //
  285. //
  286. // ASSUMPTIONS & ASSERTIONS None.
  287. //
  288. // INTERNAL STRUCTURES RP_SLICE_DESC is defined in hretype.h
  289. // drawInfoStructType is defined in rplnee.h
  290. //
  291. // UNRESOLVED ISSUES programmer development notes
  292. //---------------------------------------------------------------------------
  293. {
  294. uint16 func;
  295. uint16 bitShift;
  296. drawInfoStructType drawInfo;
  297. drawInfo.bytePosition = (uint16 FAR *)((UINT_PTR)lpbm->bmBits +
  298. line->us_y1 * lpbm->bmWidthBytes);
  299. drawInfo.bytePosition += line->us_x1 >> 4;
  300. func = (line->s_dx_draw << 3) + (line->s_dy_draw << 2) +
  301. (line->s_dx_skip << 1) + line->s_dy_skip + 2;
  302. if (func == SECTOR3)
  303. drawInfo.nextY = -1 * lpbm->bmWidthBytes; /* sector 3 */
  304. else
  305. drawInfo.nextY = lpbm->bmWidthBytes; /* sector 4 */
  306. bitShift = line->us_x1 & 0x000F;
  307. drawInfo.bitPosition = bitShift;
  308. /* Now rendering the first slice */
  309. if (line->us_first > 0) {
  310. DisplaySlice34(line, &drawInfo, FIRST);
  311. }
  312. /* Rendering intermediate slices */
  313. if (line->us_n_slices > 0) {
  314. DisplaySlice34(line, &drawInfo, 0);
  315. }
  316. /* Now rendering the last slice */
  317. if (line->us_last > 0) {
  318. DisplaySlice34(line, &drawInfo, LAST);
  319. }
  320. return;
  321. }
  322. //---------------------------------------------------------------------------
  323. static void
  324. ShortSlice07
  325. (
  326. RP_SLICE_DESC FAR* line, /* output slice form of line */
  327. drawInfoStructType FAR *drawInfo, // position to put pixel on it
  328. uint16 firstOrLast // is this first/last slice?
  329. )
  330. // PURPOSE drawing the line located in sector 0/7
  331. // dy/dx > 2
  332. //
  333. //
  334. // ASSUMPTIONS & ASSERTIONS None.
  335. //
  336. // INTERNAL STRUCTURES RP_SLICE_DESC is defined in hretype.h
  337. // drawInfoStructType is defined in rplnee.h
  338. //
  339. // UNRESOLVED ISSUES programmer development notes
  340. //---------------------------------------------------------------------------
  341. {
  342. uint16 loop1st, loop2nd, loop3rd;
  343. int32 ddaValue, ddaDiff;
  344. uint16 i, j;
  345. if (firstOrLast) {
  346. if (firstOrLast == FIRST)
  347. loop1st = line->us_first;
  348. else
  349. loop1st = line->us_last;
  350. loop2nd = 1;
  351. loop3rd = 0;
  352. ddaValue = -1;
  353. ddaDiff = 0;
  354. } else {
  355. loop1st = line->us_small;
  356. loop2nd = line->us_n_slices & 0x03;
  357. loop3rd = line->us_n_slices >> 2;
  358. ddaValue = line->s_dis - line->s_dis_sm;
  359. ddaDiff = line->s_dis_lg - line->s_dis_sm;
  360. }
  361. for (i = 0; i <= loop3rd; i++) {
  362. while(loop2nd--) {
  363. if (firstOrLast)
  364. ddaValue += 0;
  365. else
  366. ddaValue += line->s_dis_sm;
  367. if (ddaValue >= 0) {
  368. ddaValue += ddaDiff;
  369. *drawInfo->bytePosition |=
  370. (drawInfo->bitPosition >> 8) | (drawInfo->bitPosition << 8);
  371. drawInfo->bytePosition += drawInfo->nextY >> 1;
  372. }
  373. for (j = 0; j < loop1st; j++) {
  374. *drawInfo->bytePosition |=
  375. (drawInfo->bitPosition >> 8) | (drawInfo->bitPosition << 8);
  376. drawInfo->bytePosition += drawInfo->nextY >> 1;
  377. }
  378. if ((drawInfo->bitPosition >>= 1) == 0) {
  379. drawInfo->bytePosition++;
  380. drawInfo->bitPosition = 0x8000;
  381. }
  382. }
  383. loop2nd = 4;
  384. }
  385. return;
  386. }
  387. //---------------------------------------------------------------------------
  388. static void
  389. ShortSlice16
  390. (
  391. RP_SLICE_DESC FAR* line, /* output slice form of line */
  392. drawInfoStructType FAR *drawInfo, // position to put pixel on it
  393. uint16 firstOrLast // is this first/last slice?
  394. )
  395. // PURPOSE drawing the line located in sector 1/6
  396. // 2> dy/dx > 1
  397. //
  398. //
  399. // ASSUMPTIONS & ASSERTIONS None.
  400. //
  401. // INTERNAL STRUCTURES RP_SLICE_DESC is defined in hretype.h
  402. // drawInfoStructType is defined in rplnee.h
  403. //
  404. // UNRESOLVED ISSUES programmer development notes
  405. //---------------------------------------------------------------------------
  406. {
  407. uint16 loop1st, loop2nd, loop3rd;
  408. int32 ddaValue, ddaDiff;
  409. uint16 i, j;
  410. if (firstOrLast) {
  411. if (firstOrLast == FIRST)
  412. loop1st = line->us_first;
  413. else
  414. loop1st = line->us_last;
  415. loop2nd = 1;
  416. loop3rd = 0;
  417. ddaValue = -1;
  418. ddaDiff = 0;
  419. } else {
  420. loop1st = line->us_small;
  421. loop2nd = line->us_n_slices & 0x03;
  422. loop3rd = line->us_n_slices >> 2;
  423. ddaValue = line->s_dis - line->s_dis_sm;
  424. ddaDiff = line->s_dis_lg - line->s_dis_sm;
  425. }
  426. for (i = 0; i <= loop3rd; i++) {
  427. while(loop2nd--) {
  428. if (firstOrLast)
  429. ddaValue += 0;
  430. else
  431. ddaValue += line->s_dis_sm;
  432. if (ddaValue >= 0) {
  433. ddaValue += ddaDiff;
  434. *drawInfo->bytePosition |=
  435. (drawInfo->bitPosition >> 8) | (drawInfo->bitPosition << 8);
  436. drawInfo->bytePosition += drawInfo->nextY >> 1;
  437. if ((drawInfo->bitPosition >>= 1) == 0) {
  438. drawInfo->bytePosition++;
  439. drawInfo->bitPosition = 0x8000;
  440. }
  441. }
  442. for (j = 0; j < loop1st; j++) {
  443. *drawInfo->bytePosition |=
  444. (drawInfo->bitPosition >> 8) | (drawInfo->bitPosition << 8);
  445. drawInfo->bytePosition += drawInfo->nextY >> 1;
  446. if ((drawInfo->bitPosition >>= 1) == 0) {
  447. drawInfo->bytePosition++;
  448. drawInfo->bitPosition = 0x8000;
  449. }
  450. }
  451. /* Adjust skip direction by backword 1 bit */
  452. if ((drawInfo->bitPosition <<= 1) == 0) {
  453. drawInfo->bytePosition--;
  454. drawInfo->bitPosition = 0x0001;
  455. }
  456. }
  457. loop2nd = 4;
  458. }
  459. return;
  460. }
  461. //---------------------------------------------------------------------------
  462. static void
  463. ShortSlice25
  464. (
  465. RP_SLICE_DESC FAR* line, /* output slice form of line */
  466. drawInfoStructType FAR *drawInfo, // position to put pixel on it
  467. uint16 firstOrLast // is this first/last slice?
  468. )
  469. // PURPOSE drawing the line located in sector 2/5
  470. // 2> dx/dy > 1
  471. //
  472. //
  473. // ASSUMPTIONS & ASSERTIONS None.
  474. //
  475. // INTERNAL STRUCTURES RP_SLICE_DESC is defined in hretype.h
  476. // drawInfoStructType is defined in rplnee.h
  477. //
  478. // UNRESOLVED ISSUES programmer development notes
  479. //---------------------------------------------------------------------------
  480. {
  481. uint16 loop1st, loop2nd, loop3rd;
  482. int32 ddaValue, ddaDiff;
  483. uint16 i, j;
  484. if (firstOrLast) {
  485. if (firstOrLast == FIRST)
  486. loop1st = line->us_first;
  487. else
  488. loop1st = line->us_last;
  489. loop2nd = 1;
  490. loop3rd = 0;
  491. ddaValue = -1;
  492. ddaDiff = 0;
  493. } else {
  494. loop1st = line->us_small;
  495. loop2nd = line->us_n_slices & 0x03;
  496. loop3rd = line->us_n_slices >> 2;
  497. ddaValue = line->s_dis - line->s_dis_sm;
  498. ddaDiff = line->s_dis_lg - line->s_dis_sm;
  499. }
  500. for (i = 0; i <= loop3rd; i++) {
  501. while(loop2nd--) {
  502. if (firstOrLast)
  503. ddaValue += 0;
  504. else
  505. ddaValue += line->s_dis_sm;
  506. if (ddaValue >= 0) {
  507. ddaValue += ddaDiff;
  508. *drawInfo->bytePosition |=
  509. (drawInfo->bitPosition >> 8) | (drawInfo->bitPosition << 8);
  510. drawInfo->bytePosition += drawInfo->nextY >> 1;
  511. if ((drawInfo->bitPosition >>= 1) == 0) {
  512. drawInfo->bytePosition++;
  513. drawInfo->bitPosition = 0x8000;
  514. }
  515. }
  516. for (j = 0; j < loop1st; j++) {
  517. *drawInfo->bytePosition |=
  518. (drawInfo->bitPosition >> 8) | (drawInfo->bitPosition << 8);
  519. drawInfo->bytePosition += drawInfo->nextY >> 1;
  520. if ((drawInfo->bitPosition >>= 1) == 0) {
  521. drawInfo->bytePosition++;
  522. drawInfo->bitPosition = 0x8000;
  523. }
  524. }
  525. /* Adjust skip direction by backword 1 column */
  526. drawInfo->bytePosition -= drawInfo->nextY >> 1;
  527. }
  528. loop2nd = 4;
  529. }
  530. return;
  531. }
  532. //---------------------------------------------------------------------------
  533. static void
  534. DisplaySlice34
  535. (
  536. RP_SLICE_DESC FAR* line, /* output slice form of line */
  537. drawInfoStructType FAR *drawInfo, // position to put pixel on it
  538. uint16 firstOrLast // is this first/last slice?
  539. )
  540. // PURPOSE drawing the line located in sector 3/4
  541. // dx/dy > 2
  542. //
  543. //
  544. // ASSUMPTIONS & ASSERTIONS None.
  545. //
  546. // INTERNAL STRUCTURES RP_SLICE_DESC is defined in hretype.h
  547. // drawInfoStructType is defined in rplnee.h
  548. //
  549. // UNRESOLVED ISSUES programmer development notes
  550. //---------------------------------------------------------------------------
  551. {
  552. uint16 nSlice, sliceLength;
  553. uint16 wordNumber, lShiftInLastWord;
  554. int32 ddaValue, ddaDiff;
  555. uint16 i;
  556. uint16 tmp;
  557. if (firstOrLast) {
  558. nSlice = 1;
  559. ddaValue = -1;
  560. ddaDiff = 0;
  561. } else {
  562. nSlice = line->us_n_slices;
  563. ddaValue = line->s_dis - line->s_dis_sm;
  564. ddaDiff = (line->s_dis_lg - line->s_dis_sm);
  565. }
  566. while (nSlice--) {
  567. if (!firstOrLast) {
  568. sliceLength = line->us_small;
  569. ddaValue += line->s_dis_sm;
  570. } else if (firstOrLast == FIRST) {
  571. sliceLength = line->us_first;
  572. ddaValue += 0;
  573. } else {
  574. sliceLength = line->us_last;
  575. ddaValue += 0;
  576. }
  577. if (ddaValue >= 0) {
  578. ddaValue += ddaDiff;
  579. sliceLength += 1;
  580. }
  581. wordNumber = (drawInfo->bitPosition + sliceLength) >> 4;
  582. lShiftInLastWord = 16 -
  583. ((drawInfo->bitPosition + sliceLength) & 0x0F);
  584. if (!wordNumber) { /* slice < 16 bits */
  585. /*
  586. *drawInfo->bytePosition |=
  587. ((uint16)ALLONE >> drawInfo->bitPosition) << lShiftInLastWord;
  588. */
  589. tmp = (uint16)ALLONE >> (16 - sliceLength);
  590. tmp <<= lShiftInLastWord;
  591. *drawInfo->bytePosition |= (tmp >> 8) | (tmp << 8);
  592. } else {
  593. tmp = (uint16)ALLONE >> drawInfo->bitPosition;
  594. *drawInfo->bytePosition++ |= (tmp >> 8) | (tmp << 8);
  595. for (i = 1; i < wordNumber; i++) {
  596. *drawInfo->bytePosition++ = (uint16)ALLONE;
  597. }
  598. if (lShiftInLastWord != 16) {
  599. tmp = (uint16)ALLONE << lShiftInLastWord;
  600. *drawInfo->bytePosition |= (tmp >> 8) | (tmp << 8);
  601. }
  602. }
  603. /* Adjust skip direction by backword 1 column */
  604. drawInfo->bytePosition += drawInfo->nextY >> 1;
  605. drawInfo->bitPosition += sliceLength;
  606. wordNumber = drawInfo->bitPosition >> 4;
  607. if (wordNumber) {
  608. drawInfo->bitPosition &= 0x0F;
  609. }
  610. }
  611. return;
  612. }