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.

473 lines
13 KiB

  1. #include "precomp.hxx"
  2. static const BYTE bTopMask[8] = {0x00, 0x80, 0xC0, 0xE0,
  3. 0xF0, 0xF8, 0xFC, 0xFE};
  4. static const BYTE bBottomMask[8] = {0xFF, 0x7F, 0x3F, 0x1F,
  5. 0x0F, 0x07, 0x03, 0x01};
  6. static const BYTE bSelectMask[8] = {0x80, 0x40, 0x20, 0x10,
  7. 0x08, 0x04, 0x02, 0x01};
  8. void Blt01to01_NoTrans_Hcopy_SRCCOPY_Vcopy(
  9. BYTE* pbSrcScanLine,
  10. int iSrcBitOffset,
  11. int iSrcScanStride,
  12. BYTE* pbDstScanLine,
  13. int iDstBitOffset,
  14. int iDstScanStride,
  15. int iNumDstCols,
  16. int iNumDstRows)
  17. {
  18. BYTE *pbSrc,
  19. *pbDst,
  20. *pbEndDst;
  21. int iDstStartPixels,
  22. iDstFullBytes,
  23. iDstEndPixels,
  24. iRelBitOffset,
  25. iCompRelBitOffset;
  26. // compute how many pixels in the dst scanline are hanging off into a
  27. // byte that's not completely on the dst scanline, how many full bytes
  28. // are on the dst scanline, and how many pixels hang off the other end
  29. if (iDstBitOffset == 0) {
  30. iDstStartPixels = 0;
  31. iDstFullBytes = iNumDstCols / 8;
  32. iDstEndPixels = iNumDstCols % 8;
  33. } else {
  34. iDstStartPixels = 8 - iDstBitOffset;
  35. iDstFullBytes = (iNumDstCols - iDstStartPixels) / 8;
  36. iDstEndPixels = (iNumDstCols - iDstStartPixels) % 8;
  37. }
  38. iRelBitOffset = abs(iSrcBitOffset - iDstBitOffset);
  39. iCompRelBitOffset = 8 - iRelBitOffset;
  40. for (int i = 0; i < iNumDstRows; i++) {
  41. // set pointers to first bytes on src and dst scanlines
  42. pbSrc = pbSrcScanLine;
  43. pbDst = pbDstScanLine;
  44. // take care of first few dst pixels that are hanging off in a byte
  45. // that's not completely on the scanline
  46. if (iDstStartPixels) {
  47. if (iNumDstCols >= iDstStartPixels) {
  48. if (iSrcBitOffset > iDstBitOffset) {
  49. *pbDst++ = (((*pbSrc << iRelBitOffset) |
  50. (*(pbSrc + 1) >> iCompRelBitOffset)) &
  51. bBottomMask[iDstBitOffset]) |
  52. (*pbDst & ~bBottomMask[iDstBitOffset]);
  53. pbSrc++;
  54. } else {
  55. *pbDst++ = ((*pbSrc >> iRelBitOffset) &
  56. bBottomMask[iDstBitOffset]) |
  57. (*pbDst & ~bBottomMask[iDstBitOffset]);
  58. }
  59. } else {
  60. if (iSrcBitOffset > iDstBitOffset) {
  61. *pbDst++ = (((*pbSrc << iRelBitOffset) |
  62. (*(pbSrc + 1) >> iCompRelBitOffset)) &
  63. bBottomMask[iDstBitOffset] &
  64. bTopMask[iSrcBitOffset + iNumDstCols]) |
  65. (*pbDst & ~(bBottomMask[iDstBitOffset] &
  66. bTopMask[iSrcBitOffset + iNumDstCols]));
  67. pbSrc++;
  68. } else {
  69. *pbDst++ = ((*pbSrc >> iRelBitOffset) &
  70. bBottomMask[iDstBitOffset] &
  71. bTopMask[iSrcBitOffset + iNumDstCols]) |
  72. (*pbDst & ~(bBottomMask[iDstBitOffset] &
  73. bTopMask[iSrcBitOffset + iNumDstCols]));
  74. }
  75. }
  76. }
  77. // take care of pixels that fall on bytes that are entirely
  78. // within the dst scanline
  79. pbEndDst = pbDst + iDstFullBytes;
  80. for (; pbDst != pbEndDst; pbDst++) {
  81. *pbDst = (*pbSrc << iRelBitOffset) |
  82. (*(pbSrc + 1) >> iCompRelBitOffset);
  83. pbSrc++;
  84. }
  85. // take care of pixels hanging off the end into a byte not
  86. // entirely in the scanline
  87. *pbDst = ((*pbSrc << iRelBitOffset) & bTopMask[iDstEndPixels]) |
  88. (*pbDst & ~bTopMask[iDstEndPixels]);
  89. // advance to next scanline
  90. pbSrcScanLine += iSrcScanStride;
  91. pbDstScanLine += iDstScanStride;
  92. }
  93. }
  94. void Blt01to01_NoTrans_Hcopy_SRCCOPY_NoVcopy(
  95. BYTE* pbSrcScanLine,
  96. int iSrcBitOffset,
  97. int iSrcScanStride,
  98. int iNumSrcRows,
  99. BYTE* pbDstScanLine,
  100. int iDstBitOffset,
  101. int iDstScanStride,
  102. int iNumDstCols,
  103. int iNumDstRows)
  104. {
  105. BYTE *pbSrc,
  106. *pbDst,
  107. *pbEndDst;
  108. int iDstStartPixels,
  109. iDstFullBytes,
  110. iDstEndPixels,
  111. iRelBitOffset,
  112. iCompRelBitOffset,
  113. iVertError = 0,
  114. iVertAdvanceError,
  115. iSrcScanAdvance;
  116. // compute advance and error terms for stepping
  117. // vertically through the src bitmap
  118. if (iNumSrcRows < iNumDstRows) {
  119. iSrcScanAdvance = 0;
  120. iVertAdvanceError = iNumSrcRows;
  121. } else {
  122. iSrcScanAdvance = iSrcScanStride * (iNumSrcRows / iNumDstRows);
  123. iVertAdvanceError = iNumSrcRows % iNumDstRows;
  124. }
  125. // compute how many pixels in the dst scanline are hanging off into a
  126. // byte that's not completely on the dst scanline, how many full bytes
  127. // are on the dst scanline, and how many pixels hang off the other end
  128. if (iDstBitOffset == 0) {
  129. iDstStartPixels = 0;
  130. iDstFullBytes = iNumDstCols / 8;
  131. iDstEndPixels = iNumDstCols % 8;
  132. } else {
  133. iDstStartPixels = 8 - iDstBitOffset;
  134. iDstFullBytes = (iNumDstCols - iDstStartPixels) / 8;
  135. iDstEndPixels = (iNumDstCols - iDstStartPixels) % 8;
  136. }
  137. iRelBitOffset = abs(iSrcBitOffset - iDstBitOffset);
  138. iCompRelBitOffset = 8 - iRelBitOffset;
  139. for (int i = 0; i < iNumDstRows; i++) {
  140. pbSrc = pbSrcScanLine;
  141. pbDst = pbDstScanLine;
  142. // take care of first few dst pixels that are hanging off in a byte
  143. // that's not completely on the scanline
  144. if (iDstStartPixels) {
  145. if (iNumDstCols >= iDstStartPixels) {
  146. if (iSrcBitOffset > iDstBitOffset) {
  147. *pbDst++ = (((*pbSrc << iRelBitOffset) |
  148. (*(pbSrc + 1) >> iCompRelBitOffset)) &
  149. bBottomMask[iDstBitOffset]) |
  150. (*pbDst & ~bBottomMask[iDstBitOffset]);
  151. pbSrc++;
  152. } else {
  153. *pbDst++ = ((*pbSrc >> iRelBitOffset) &
  154. bBottomMask[iDstBitOffset]) |
  155. (*pbDst & ~bBottomMask[iDstBitOffset]);
  156. }
  157. } else {
  158. if (iSrcBitOffset > iDstBitOffset) {
  159. *pbDst++ = (((*pbSrc << iRelBitOffset) |
  160. (*(pbSrc + 1) >> iCompRelBitOffset)) &
  161. bBottomMask[iDstBitOffset] &
  162. bTopMask[iSrcBitOffset + iNumDstCols]) |
  163. (*pbDst & ~(bBottomMask[iDstBitOffset] &
  164. bTopMask[iSrcBitOffset + iNumDstCols]));
  165. pbSrc++;
  166. } else {
  167. *pbDst++ = ((*pbSrc >> iRelBitOffset) &
  168. bBottomMask[iDstBitOffset] &
  169. bTopMask[iSrcBitOffset + iNumDstCols]) |
  170. (*pbDst & ~(bBottomMask[iDstBitOffset] &
  171. bTopMask[iSrcBitOffset + iNumDstCols]));
  172. }
  173. }
  174. }
  175. // take care of pixels that fall on bytes that are entirely
  176. // within the dst scanline
  177. pbEndDst = pbDst + iDstFullBytes;
  178. for (; pbDst != pbEndDst; pbDst++) {
  179. *pbDst = (*pbSrc << iRelBitOffset) |
  180. (*(pbSrc + 1) >> iCompRelBitOffset);
  181. pbSrc++;
  182. }
  183. // take care of pixels hanging off the end into a byte not
  184. // entirely in the scanline
  185. *pbDst = ((*pbSrc << iRelBitOffset) & bTopMask[iDstEndPixels]) |
  186. (*pbDst & ~bTopMask[iDstEndPixels]);
  187. // advance to next scanline
  188. pbSrcScanLine += iSrcScanAdvance;
  189. pbDstScanLine += iDstScanStride;
  190. // update and check vertical stepping error,
  191. // adjust src scanline pointer if necessary
  192. iVertError += iVertAdvanceError;
  193. if (iVertError >= iNumDstRows) {
  194. pbSrcScanLine += iSrcScanStride;
  195. iVertError -= iNumDstRows;
  196. }
  197. }
  198. }
  199. void Blt01to01_NoTrans_NoHcopy_SRCCOPY(
  200. BYTE* pbSrcScanLine,
  201. int iSrcBitOffset,
  202. int iSrcScanStride,
  203. int iNumSrcCols,
  204. int iNumSrcRows,
  205. BYTE* pbDstScanLine,
  206. int iDstBitOffset,
  207. int iDstScanStride,
  208. int iNumDstCols,
  209. int iNumDstRows,
  210. int iHorizMirror)
  211. {
  212. BYTE *pbSrc,
  213. *pbDst,
  214. bDstVal;
  215. int iSrcPixel,
  216. iDstPixel,
  217. iVertError = 0,
  218. iVertAdvanceError,
  219. iSrcScanAdvance,
  220. iHorizError,
  221. iHorizAdvanceError,
  222. iSrcByteAdvance,
  223. iSrcBitAdvance;
  224. // compute advance and error terms for stepping
  225. // vertically through the src bitmap
  226. if (iNumSrcRows < iNumDstRows) {
  227. iSrcScanAdvance = 0;
  228. iVertAdvanceError = iNumSrcRows;
  229. } else {
  230. iSrcScanAdvance = iSrcScanStride * (iNumSrcRows / iNumDstRows);
  231. iVertAdvanceError = iNumSrcRows % iNumDstRows;
  232. }
  233. // compute advance and error terms for stepping
  234. // horizontally through src bitmap
  235. if (iNumSrcCols < iNumDstCols) {
  236. iSrcByteAdvance = 0;
  237. iSrcBitAdvance = 0;
  238. iHorizAdvanceError = iNumSrcCols;
  239. } else {
  240. iSrcByteAdvance = (iNumSrcCols / iNumDstCols) / 8;
  241. iSrcBitAdvance = (iNumSrcCols / iNumDstCols) % 8;
  242. iHorizAdvanceError = iNumSrcCols % iNumDstCols;
  243. }
  244. for (int i = 0; i < iNumDstRows; i++) {
  245. // set pointers to the beginning of src and dst scanlines,
  246. // clear horizontal stepping error accumulator
  247. pbSrc = pbSrcScanLine;
  248. iSrcPixel = iSrcBitOffset;
  249. pbDst = pbDstScanLine;
  250. iDstPixel = iDstBitOffset;
  251. iHorizError = 0;
  252. bDstVal = *pbDst;
  253. for (int j = 0; j < iNumDstCols; j++) {
  254. // get value of src pixel, put it in dst byte
  255. if (*pbSrc & bSelectMask[iSrcPixel]) {
  256. bDstVal |= bSelectMask[iDstPixel];
  257. } else {
  258. bDstVal &= ~bSelectMask[iDstPixel];
  259. }
  260. // advance to next src pixel
  261. pbSrc += iSrcByteAdvance;
  262. iSrcPixel += iSrcBitAdvance;
  263. if (iSrcPixel > 7) {
  264. pbSrc++;
  265. iSrcPixel -= 8;
  266. }
  267. // advance to next dst pixel
  268. // if we hit byte boundary, write
  269. // full one and get new one
  270. iDstPixel += iHorizMirror;
  271. if (iDstPixel < 0) {
  272. *pbDst-- = bDstVal;
  273. bDstVal = *pbDst;
  274. iDstPixel = 7;
  275. } else if (iDstPixel > 7) {
  276. *pbDst++ = bDstVal;
  277. bDstVal = *pbDst;
  278. iDstPixel = 0;
  279. }
  280. // update and check horizontal stepping error,
  281. // adjust src pixel pointer if necessary
  282. iHorizError += iHorizAdvanceError;
  283. if (iHorizError >= iNumDstCols) {
  284. if (++iSrcPixel > 7) {
  285. pbSrc++;
  286. iSrcPixel = 0;
  287. }
  288. iHorizError -= iNumDstCols;
  289. }
  290. }
  291. // write last byte to dst scanline
  292. *pbDst = bDstVal;
  293. // advance to next scanline
  294. pbSrcScanLine += iSrcScanAdvance;
  295. pbDstScanLine += iDstScanStride;
  296. // update and check vertical stepping error,
  297. // adjust src scanline pointer if necessary
  298. iVertError += iVertAdvanceError;
  299. if (iVertError >= iNumDstRows) {
  300. pbSrcScanLine += iSrcScanStride;
  301. iVertError -= iNumDstRows;
  302. }
  303. }
  304. }
  305. void Blt01to01_Trans_NoHcopy_SRCCOPY(
  306. BYTE* pbSrcScanLine,
  307. int iSrcBitOffset,
  308. int iSrcScanStride,
  309. int iNumSrcCols,
  310. int iNumSrcRows,
  311. BYTE* pbDstScanLine,
  312. int iDstBitOffset,
  313. int iDstScanStride,
  314. int iNumDstCols,
  315. int iNumDstRows,
  316. int iHorizMirror,
  317. BYTE bTransparentIndex)
  318. {
  319. BYTE *pbSrc,
  320. *pbDst,
  321. bDstVal,
  322. bTransparentTest;
  323. int iSrcPixel,
  324. iDstPixel,
  325. iVertError = 0,
  326. iVertAdvanceError,
  327. iSrcScanAdvance,
  328. iHorizError,
  329. iHorizAdvanceError,
  330. iSrcByteAdvance,
  331. iSrcBitAdvance;
  332. // compute advance and error terms for stepping
  333. // vertically through the src bitmap
  334. if (iNumSrcRows < iNumDstRows) {
  335. iSrcScanAdvance = 0;
  336. iVertAdvanceError = iNumSrcRows;
  337. } else {
  338. iSrcScanAdvance = iSrcScanStride * (iNumSrcRows / iNumDstRows);
  339. iVertAdvanceError = iNumSrcRows % iNumDstRows;
  340. }
  341. // compute advance and error terms for stepping
  342. // horizontally through src bitmap
  343. if (iNumSrcCols < iNumDstCols) {
  344. iSrcByteAdvance = 0;
  345. iSrcBitAdvance = 0;
  346. iHorizAdvanceError = iNumSrcCols;
  347. } else {
  348. iSrcByteAdvance = (iNumSrcCols / iNumDstCols) / 8;
  349. iSrcBitAdvance = (iNumSrcCols / iNumDstCols) % 8;
  350. iHorizAdvanceError = iNumSrcCols % iNumDstCols;
  351. }
  352. // create transparent color testing mask
  353. if (bTransparentIndex) {
  354. bTransparentTest = 0xFF;
  355. } else {
  356. bTransparentTest = 0;
  357. }
  358. for (int i = 0; i < iNumDstRows; i++) {
  359. // set pointers to the beginning of src and dst scanlines,
  360. // clear horizontal stepping error accumulator
  361. pbSrc = pbSrcScanLine;
  362. iSrcPixel = iSrcBitOffset;
  363. pbDst = pbDstScanLine;
  364. iDstPixel = iDstBitOffset;
  365. iHorizError = 0;
  366. bDstVal = *pbDst;
  367. for (int j = 0; j < iNumDstCols; j++) {
  368. // get value of src pixel, put it in dst byte
  369. if ((*pbSrc ^ bTransparentTest) & bSelectMask[iSrcPixel]) {
  370. if (*pbSrc & bSelectMask[iSrcPixel]) {
  371. bDstVal |= bSelectMask[iDstPixel];
  372. } else {
  373. bDstVal &= ~bSelectMask[iDstPixel];
  374. }
  375. }
  376. // advance to next src pixel
  377. pbSrc += iSrcByteAdvance;
  378. iSrcPixel += iSrcBitAdvance;
  379. if (iSrcPixel > 7) {
  380. pbSrc++;
  381. iSrcPixel -= 8;
  382. }
  383. // advance to next dst pixel
  384. // if we hit byte boundary, write
  385. // full one and get new one
  386. iDstPixel += iHorizMirror;
  387. if (iDstPixel < 0) {
  388. *pbDst-- = bDstVal;
  389. bDstVal = *pbDst;
  390. iDstPixel = 7;
  391. } else if (iDstPixel > 7) {
  392. *pbDst++ = bDstVal;
  393. bDstVal = *pbDst;
  394. iDstPixel = 0;
  395. }
  396. // update and check horizontal stepping error,
  397. // adjust src pixel pointer if necessary
  398. iHorizError += iHorizAdvanceError;
  399. if (iHorizError >= iNumDstCols) {
  400. if (++iSrcPixel > 7) {
  401. pbSrc++;
  402. iSrcPixel = 0;
  403. }
  404. iHorizError -= iNumDstCols;
  405. }
  406. }
  407. // write last byte to dst scanline
  408. *pbDst = bDstVal;
  409. // advance to next scanline
  410. pbSrcScanLine += iSrcScanAdvance;
  411. pbDstScanLine += iDstScanStride;
  412. // update and check vertical stepping error,
  413. // adjust src scanline pointer if necessary
  414. iVertError += iVertAdvanceError;
  415. if (iVertError >= iNumDstRows) {
  416. pbSrcScanLine += iSrcScanStride;
  417. iVertError -= iNumDstRows;
  418. }
  419. }
  420. }