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.

538 lines
14 KiB

  1. title mapa.asm
  2. page ,132
  3. ?PLM=1 ; PASCAL Calling convention is DEFAULT
  4. ?WIN=0 ; Windows calling convention
  5. .xlist
  6. include cmacro32.inc
  7. include windows.inc
  8. .list
  9. ; -------------------------------------------------------
  10. ; DATA SEGMENT DECLARATIONS
  11. ; -------------------------------------------------------
  12. ifndef SEGNAME
  13. SEGNAME equ <_TEXT>
  14. endif
  15. createSeg %SEGNAME, CodeSeg, word, public, CODE
  16. sBegin CodeSeg
  17. .386
  18. assumes cs,CodeSeg
  19. assumes ds,nothing
  20. assumes es,nothing
  21. ;--------------------------------------------------------------------------;
  22. ;
  23. ; STOSB32 - store a byte, every four times doing a STOSD
  24. ;
  25. ;--------------------------------------------------------------------------;
  26. STOSB32_N = 0
  27. STOSB32 macro
  28. ror eax,8 ; rotate pixel (al) into eax
  29. STOSB32_N = STOSB32_N + 1
  30. if (STOSB32_N mod 4) eq 0
  31. ;; stos dword ptr es:[edi]
  32. mov dword ptr es:[edi], eax
  33. add edi,4
  34. endif
  35. endm
  36. ;--------------------------------------------------------------------------;
  37. ;
  38. ; LODSB32 - get a byte, every four times doing a LODSD
  39. ;
  40. ;--------------------------------------------------------------------------;
  41. LODSB32_N = 0
  42. LODSB32 macro
  43. if (LODSB32_N mod 4) eq 0
  44. ;; lods dword ptr ds:[esi]
  45. mov eax,dword ptr ds:[esi]
  46. add esi,4
  47. else
  48. ror eax,8
  49. endif
  50. LODSB32_N = LODSB32_N + 1
  51. endm
  52. ;--------------------------------------------------------------------------;
  53. ;
  54. ; MAP16
  55. ;
  56. ;--------------------------------------------------------------------------;
  57. MAP16 macro n
  58. if n and 1
  59. shr ebx,16 ; get pel from last time
  60. else
  61. mov ebx, dword ptr ds:[esi] ; grab two pels
  62. add esi,4
  63. endif
  64. ;
  65. ; BX contains 5:5:5 RGB convert it to a 8:8:8 RGB
  66. ;
  67. mov al,bl
  68. shl al,3
  69. STOSB32
  70. shr bx,2
  71. mov al,bl
  72. and al,0F8h
  73. STOSB32
  74. mov al,bh
  75. shl al,3
  76. STOSB32
  77. endm
  78. ;--------------------------------------------------------------------------;
  79. ;
  80. ; Map16to24()
  81. ;
  82. ; Entry:
  83. ; Stack based parameters as described below.
  84. ;
  85. ; Returns:
  86. ; none
  87. ;
  88. ; Registers Preserved:
  89. ; DS,ES,ESI,EDI,EBP
  90. ;
  91. ;--------------------------------------------------------------------------;
  92. assumes ds,Data
  93. assumes es,nothing
  94. cProc Map16to24,<FAR,PUBLIC,PASCAL>,<>
  95. parmD biDst ;--> BITMAPINFO of dest
  96. parmD lpDst ;--> to destination bits
  97. parmW DstX ;Destination origin - x coordinate
  98. parmW DstY ;Destination origin - y coordinate
  99. parmW DstXE ;x extent of the BLT
  100. parmW DstYE ;y extent of the BLT
  101. parmD biSrc ;--> BITMAPINFO of source
  102. parmD lpSrc ;--> to source bits
  103. parmW SrcX ;Source origin - x coordinate
  104. parmW SrcY ;Source origin - y coordinate
  105. parmD lpDitherTable ;not used
  106. localD SrcWidth ;width of source in bytes
  107. localD DstWidth ;width of dest in bytes
  108. localD SrcInc
  109. localD DstInc
  110. cBegin
  111. push esi
  112. push edi
  113. push ds
  114. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ;
  115. ; align everything on four pixel boundries, we realy should
  116. ; not do this but should handle the general case instead,
  117. ; but hey we are hackers.
  118. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ;
  119. and DstXE, not 011b
  120. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ;
  121. mov eax,16 ; source 16
  122. mov ebx,24 ; dest 24
  123. call map_init ; init all the frame variables
  124. jc Map16to24Exit
  125. movzx eax, DstXE ; inner loop expanded by 4
  126. shr eax, 2
  127. jz Map16to24Exit
  128. mov DstXE,ax
  129. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ;
  130. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ;
  131. align 4
  132. Outer16to24Loop:
  133. movzx ecx,DstXE
  134. align 4
  135. Inner16to24Loop:
  136. MAP16 0
  137. MAP16 1
  138. MAP16 2
  139. MAP16 3
  140. dec ecx
  141. jnz Inner16to24Loop
  142. add edi, DstInc
  143. add esi, SrcInc
  144. dec DstYE
  145. jnz Outer16to24Loop
  146. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ;
  147. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ;
  148. Map16to24Exit:
  149. pop ds
  150. pop edi
  151. pop esi
  152. cEnd
  153. ;--------------------------------------------------------------------------;
  154. ;
  155. ; Map32to24()
  156. ;
  157. ; Entry:
  158. ; Stack based parameters as described below.
  159. ;
  160. ; Returns:
  161. ; none
  162. ;
  163. ; Registers Preserved:
  164. ; DS,ES,ESI,EDI,EBP
  165. ;
  166. ;--------------------------------------------------------------------------;
  167. assumes ds,Data
  168. assumes es,nothing
  169. cProc Map32to24,<FAR,PUBLIC,PASCAL>,<>
  170. parmD biDst ;--> BITMAPINFO of dest
  171. parmD lpDst ;--> to destination bits
  172. parmW DstX ;Destination origin - x coordinate
  173. parmW DstY ;Destination origin - y coordinate
  174. parmW DstXE ;x extent of the BLT
  175. parmW DstYE ;y extent of the BLT
  176. parmD biSrc ;--> BITMAPINFO of source
  177. parmD lpSrc ;--> to source bits
  178. parmW SrcX ;Source origin - x coordinate
  179. parmW SrcY ;Source origin - y coordinate
  180. parmD lpDitherTable ;not used
  181. localD SrcWidth ;width of source in bytes
  182. localD DstWidth ;width of dest in bytes
  183. localD SrcInc
  184. localD DstInc
  185. localW OriginalDstXE
  186. cBegin
  187. push esi
  188. push edi
  189. push ds
  190. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ;
  191. ; align everything on four pixel boundries, we realy should
  192. ; not do this but should handle the general case instead,
  193. ; but hey we are hackers.
  194. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ;
  195. mov ax, DstXE
  196. mov OriginalDstXE, ax
  197. mov bx, ax
  198. add ax, 011b
  199. and ax, not 011b
  200. mov DstXE, ax
  201. and bx, 011b
  202. jz short @f
  203. dec DstYE ; if the width isn't a multiple of 4, special-
  204. ; case the last line.
  205. @@:
  206. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ;
  207. mov eax,32 ; source 32
  208. mov ebx,24 ; dest 24
  209. call map_init ; init all the frame variables
  210. jc Map32to24Exit
  211. movzx eax, DstXE ; inner loop expanded by 4
  212. shr eax, 2
  213. jz short Map32to24Exit
  214. mov DstXE,ax
  215. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ;
  216. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ;
  217. align 4
  218. Outer32to24Loop:
  219. movzx ecx,DstXE
  220. align 4
  221. Inner32to24Loop:
  222. mov eax,[esi] ; eax = XRGB
  223. mov ebx,[esi+4] ; ebx = xrgb
  224. shl eax,8 ; eax = RGB0
  225. shrd eax,ebx,8 ; eax = bRGB
  226. mov es:[edi],eax ; store pels
  227. shl ebx,8 ; ebx = rgb0
  228. mov eax,[esi+8] ; eax = XRGB
  229. shrd ebx,eax,16 ; ebx = GBrg
  230. mov es:[edi+4],ebx ; store pels
  231. shl eax,8 ; eax = RGB0
  232. mov ebx,[esi+12] ; ebx = xrgb
  233. shrd eax,ebx,24 ; eax = rgbR
  234. mov es:[edi+8],eax ; store pels
  235. add esi,16
  236. add edi,12
  237. dec ecx
  238. jnz Inner32to24Loop
  239. add edi, DstInc
  240. add esi, SrcInc
  241. dec DstYE
  242. jnz Outer32to24Loop
  243. ; done, but might have to do one more scan line
  244. mov ax, OriginalDstXE
  245. and ax, 011b
  246. jz short Map32to24Exit
  247. movzx ecx,OriginalDstXE
  248. align 4
  249. @@: ; one more scan line to do....
  250. mov eax,[esi] ; eax = XRGB
  251. shl eax,8 ; eax = RGB0
  252. mov es:[edi], ah
  253. shr eax,16 ; eax = 00RG
  254. mov es:[edi+1], ax
  255. add esi,4
  256. add edi,3
  257. dec ecx
  258. jnz @b
  259. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ;
  260. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ;
  261. Map32to24Exit:
  262. pop ds
  263. pop edi
  264. pop esi
  265. cEnd
  266. ;--------------------------------------------------------------------------;
  267. ;
  268. ; map_init
  269. ;
  270. ; init local frame vars for mapDIB
  271. ;
  272. ; ENTRY:
  273. ; AX - source bpp
  274. ; BX - dest bpp
  275. ; ss:bp --> mapdib frame
  276. ;
  277. ; EXIT:
  278. ; DS:ESI --> source DIB start x,y
  279. ; ES:EDI --> dest DIB start x,y
  280. ;
  281. ;--------------------------------------------------------------------------;
  282. map_init_error:
  283. stc
  284. ret
  285. map_init proc near
  286. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ;
  287. ; validate the DIBs
  288. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ;
  289. xor edi,edi
  290. xor esi,esi
  291. lds si, biSrc
  292. les di, biDst
  293. movzx ecx, es:[di].biBitCount ; dest must be right
  294. cmp cx, bx
  295. jne map_init_error
  296. mov cx, [si].biBitCount ; source must be 16
  297. cmp cx, ax
  298. jne map_init_error
  299. map_init_bit_depth_ok:
  300. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ;
  301. ;
  302. ; Set up the initial source pointer
  303. ;
  304. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ;
  305. mov eax,[si].biWidth
  306. mul ecx
  307. add eax,31
  308. and eax,not 31
  309. shr eax,3
  310. mov SrcWidth,eax
  311. mov SrcInc,eax
  312. lds si,lpSrc
  313. movzx edx,SrcY
  314. mul edx
  315. add esi,eax
  316. movzx eax,SrcX
  317. mul ecx
  318. shr eax,3
  319. add esi,eax
  320. movzx eax, DstXE ; SrcInc = SrcWidth - DstXE*bits/8
  321. mul ecx
  322. shr eax, 3
  323. sub SrcInc, eax
  324. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ;
  325. ;
  326. ; Set up the initial dest pointer
  327. ;
  328. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ;
  329. movzx ecx, es:[di].biBitCount
  330. mov eax,es:[di].biWidth
  331. mul ecx
  332. add eax,31
  333. and eax,not 31
  334. shr eax,3
  335. mov DstWidth,eax
  336. mov DstInc,eax
  337. les di,lpDst
  338. movzx edx,DstY
  339. mul edx
  340. add edi,eax
  341. movzx eax,DstX
  342. mul ecx
  343. shr eax,3
  344. add edi,eax
  345. movzx eax, DstXE ; DstInc = DstWidth - DstXE*bits/8
  346. mul ecx
  347. shr eax, 3
  348. sub DstInc, eax
  349. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ;
  350. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ;
  351. map_init_exit:
  352. clc
  353. ret
  354. map_init endp
  355. ;--------------------------------------------------------------------------;
  356. ;
  357. ; HugeToFlat
  358. ;
  359. ; map a bunch of bitmap bits in "huge" format to "flat" format
  360. ;
  361. ; this code only works for bitmaps <= 128k
  362. ;
  363. ; Entry:
  364. ; Stack based parameters as described below.
  365. ;
  366. ; Returns:
  367. ; none
  368. ;
  369. ; Registers Preserved:
  370. ; DS,ES,ESI,EDI,EBP
  371. ;
  372. ;--------------------------------------------------------------------------;
  373. assumes ds,nothing
  374. assumes es,nothing
  375. cProc HugeToFlat,<FAR,PUBLIC,PASCAL>,<>
  376. parmD lpBits ;--> bits
  377. parmD cbBits ;count of bits.
  378. parmD FillBytes ;the fill bytes
  379. cBegin
  380. push esi
  381. push edi
  382. push ds
  383. mov ax,word ptr lpBits[2]
  384. mov ds,ax
  385. mov es,ax
  386. mov eax,FillBytes
  387. mov ecx,cbBits
  388. add ecx,eax
  389. mov esi,00010000h
  390. sub ecx,esi
  391. mov edi,esi
  392. sub edi,eax
  393. shr ecx,2
  394. rep movsd
  395. pop ds
  396. pop edi
  397. pop esi
  398. cEnd
  399. ;--------------------------------------------------------------------------;
  400. ;
  401. ; FlatToHuge
  402. ;
  403. ; map a bunch of bitmap bits in "flat" format to "huge" format
  404. ;
  405. ; this code only works for bitmaps <= 128k
  406. ;
  407. ; Entry:
  408. ; Stack based parameters as described below.
  409. ;
  410. ; Returns:
  411. ; none
  412. ;
  413. ; Registers Preserved:
  414. ; DS,ES,ESI,EDI,EBP
  415. ;
  416. ;--------------------------------------------------------------------------;
  417. assumes ds,Data
  418. assumes es,nothing
  419. cProc FlatToHuge,<FAR,PUBLIC,PASCAL>,<>
  420. parmD lpBits ;--> bits
  421. parmD cbBits ;count of bits.
  422. parmD FillBytes ;the fill bytes
  423. cBegin
  424. push esi
  425. push edi
  426. push ds
  427. mov ax,word ptr lpBits[2]
  428. mov ds,ax
  429. mov es,ax
  430. mov eax,FillBytes
  431. mov ecx,cbBits
  432. add ecx,eax
  433. mov edi,ecx
  434. sub edi,4
  435. mov esi,edi
  436. sub esi,FillBytes
  437. sub ecx,00010000h
  438. std
  439. shr ecx,2
  440. rep movsd
  441. cld
  442. pop ds
  443. pop edi
  444. pop esi
  445. cEnd
  446. sEnd CodeSeg
  447. end