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.

263 lines
6.8 KiB

  1. page ,132
  2. ;----------------------------Module-Header------------------------------;
  3. ; Module Name: DITHER.ASM
  4. ;
  5. ; dither a 256 color DIB down to a 16 color dib.
  6. ;
  7. ;-----------------------------------------------------------------------;
  8. ?PLM=1
  9. ?WIN=0
  10. .xlist
  11. include cmacro32.inc
  12. include windows.inc
  13. .list
  14. sBegin Data
  15. sEnd Data
  16. ; The following structure should be used to access high and low
  17. ; words of a DWORD. This means that "word ptr foo[2]" -> "foo.hi".
  18. LONG struc
  19. lo dw ?
  20. hi dw ?
  21. LONG ends
  22. FARPOINTER struc
  23. off dw ?
  24. sel dw ?
  25. FARPOINTER ends
  26. ifndef SEGNAME
  27. SEGNAME equ <_TEXT>
  28. endif
  29. createSeg %SEGNAME, CodeSeg, word, public, CODE
  30. sBegin CodeSeg
  31. .386
  32. assumes cs,CodeSeg
  33. assumes ds,nothing
  34. assumes es,nothing
  35. ;--------------------------------------------------------------------------;
  36. ;
  37. ; DITHER
  38. ;
  39. ; Entry:
  40. ; dl pixel to dither (0-256)
  41. ; bl pattern x
  42. ; ah pattern y
  43. ; fs --> 8x256x8 dither table.
  44. ;
  45. ; HIWORD(eax) = 0
  46. ; HIWORD(ebx) = 0
  47. ;
  48. ; Returns:
  49. ; dl dithered pixel (0-15) (rotated into edx)
  50. ; bl pattern x (advanced mod 8)
  51. ;
  52. ;--------------------------------------------------------------------------;
  53. DITH8 macro
  54. mov al,dl ; get pel
  55. mov dl,fs:[eax*8+ebx] ; get dithered version of the pixel.
  56. ror edx,8
  57. inc bl ; increment x
  58. and bl,07h ; mod 8
  59. endm
  60. ;--------------------------------------------------------------------------;
  61. ;
  62. ; DitherDIB()
  63. ;
  64. ; Entry:
  65. ; Stack based parameters as described below.
  66. ;
  67. ; Returns:
  68. ; none
  69. ;
  70. ; Registers Preserved:
  71. ; DS,ES,ESI,EDI,EBP
  72. ;
  73. ;--------------------------------------------------------------------------;
  74. assumes ds,nothing
  75. assumes es,nothing
  76. cProc Dither8,<FAR,PUBLIC,PASCAL>,<>
  77. parmD biDst ;--> BITMAPINFO of the dest
  78. parmD lpDst ;--> to destination bits
  79. parmW DstX ;Destination origin - x coordinate
  80. parmW DstY ;Destination origin - y coordinate
  81. parmW DstXE ;x extent of the BLT
  82. parmW DstYE ;y extent of the BLT
  83. parmD biSrc ;--> BITMAPINFO of the source
  84. parmD lpSrc ;--> to source bits
  85. parmW SrcX ;Source origin - x coordinate
  86. parmW SrcY ;Source origin - y coordinate
  87. parmD lpDitherTable ;dither table.
  88. LocalD DstWidth
  89. LocalD SrcWidth
  90. cBegin
  91. cld
  92. push esi
  93. push edi
  94. push ds
  95. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ;
  96. ; align everything on four pixel boundries, we realy should
  97. ; not do this but should handle the general case instead,
  98. ; but hey we are hackers.
  99. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ;
  100. and SrcX, not 011b ; align by four
  101. add DstXE, 3
  102. and DstXE, not 011b
  103. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ;
  104. call dither_init ; init all the frame variables
  105. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ;
  106. ; time to do the dither.
  107. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ;
  108. mov ax,DstY
  109. and ax,07h
  110. mov ah,al ; ah has the scanline mod 8
  111. movzx eax,ax
  112. movzx ebx,bx
  113. movzx ecx,cx
  114. align 4
  115. DitherOuterLoop:
  116. movzx ebx,DstX
  117. and ebx,07h
  118. movzx ecx,DstXE
  119. shr ecx,2
  120. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ;
  121. ; we have a input pixel now look up the dithered version.
  122. ;
  123. ; the dither table is a byte array like so.
  124. ;
  125. ; lpDitherTable[y % 8][pixel][x % 8]
  126. ;
  127. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ;
  128. align 4
  129. DitherInnerLoop:
  130. mov edx, dword ptr ds:[esi] ; get four input pixel(s)
  131. DITH8
  132. DITH8
  133. DITH8
  134. DITH8
  135. mov dword ptr es:[edi],edx ; write four output pixel(s)
  136. add esi,4
  137. add edi,4
  138. dec ecx
  139. jnz short DitherInnerLoop
  140. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ;
  141. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ;
  142. inc ah
  143. and ah, 07h
  144. add esi, SrcWidth
  145. add edi, DstWidth
  146. dec DstYE
  147. jnz short DitherOuterLoop
  148. xor ax,ax
  149. mov fs,ax ; to make KRNL286.EXE and DOSX happy
  150. pop ds
  151. pop edi
  152. pop esi
  153. cEnd
  154. ;--------------------------------------------------------------------------;
  155. ;
  156. ; dither_init
  157. ;
  158. ; init local frame vars for DitherDIB
  159. ;
  160. ; ENTRY:
  161. ; ss:bp --> ditherdib frame
  162. ;
  163. ; EXIT:
  164. ; DS:ESI --> source DIB start x,y
  165. ; ES:EDI --> dest DIB start x,y
  166. ; FS:EBX --> dither table
  167. ;
  168. ;--------------------------------------------------------------------------;
  169. dither_init proc near
  170. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ;
  171. ;
  172. ; Set up the initial dest pointer
  173. ;
  174. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ;
  175. lds si,biDst
  176. mov eax,[si].biWidth
  177. add eax,3
  178. and eax,not 3
  179. mov DstWidth,eax
  180. xor edi,edi
  181. les di,lpDst
  182. movzx ebx,DstX
  183. movzx edx,DstY
  184. mul edx
  185. add eax,ebx
  186. add edi,eax
  187. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ;
  188. ;
  189. ; Set up the initial source pointer
  190. ;
  191. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ;
  192. lds si,biSrc
  193. mov eax,[si].biWidth
  194. add eax,3
  195. and eax,not 3
  196. mov SrcWidth,eax
  197. xor esi,esi
  198. lds si,lpSrc
  199. movzx ebx,SrcX
  200. movzx edx,SrcY
  201. mul edx
  202. add eax,ebx
  203. add esi,eax
  204. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ;
  205. ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ;
  206. xor ebx,ebx
  207. lfs bx,lpDitherTable
  208. movzx eax,DstXE
  209. sub SrcWidth, eax
  210. movzx eax,DstXE
  211. sub DstWidth, eax
  212. ret
  213. dither_init endp
  214. sEnd CodeSeg
  215. end