home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Multimedia Jumpstart 1.1a / CD_ROM.BIN / develpmt / source / rleapp / rlea.asm < prev    next >
Assembly Source File  |  1992-09-12  |  8KB  |  299 lines

  1.      page    ,132
  2. ;-----------------------------Module-Header-----------------------------;
  3. ; Module Name:  RLEA.ASM - helper routines for RLE stuff
  4. ;
  5. ; Exported Functions:   none
  6. ;
  7. ; Public Functions:     DecodeRle386
  8. ;
  9. ; Public Data:          none
  10. ;
  11. ; General Description:
  12. ;
  13. ; Restrictions:
  14. ;
  15. ;-----------------------------------------------------------------------;
  16.  
  17. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  18. ;
  19. ; (C) Copyright Microsoft Corp. 1991.  All rights reserved.
  20. ;
  21. ; You have a royalty-free right to use, modify, reproduce and 
  22. ; distribute the Sample Files (and/or any modified version) in 
  23. ; any way you find useful, provided that you agree that 
  24. ; Microsoft has no warranty obligations or liability for any 
  25. ; Sample Application Files which are modified. 
  26. ;
  27. ; Unless you got this from the MM Sys BBS, it may not be the most
  28. ; current version.  We are continually improving our samples and
  29. ; their documentation.  Call the BBS at 206 936-4082.
  30. ;
  31. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  32.  
  33.         .xlist
  34.     include cmacros.inc
  35.         include windows.inc
  36.         .list
  37.  
  38. RLE_ESCAPE  equ 0
  39. RLE_EOL     equ 0
  40. RLE_EOF     equ 1
  41. RLE_JMP     equ 2
  42.  
  43. ; The following structure should be used to access high and low
  44. ; words of a DWORD.  This means that "word ptr foo[2]" -> "foo.hi".
  45.  
  46. LONG    struc
  47. lo    dw    ?
  48. hi    dw    ?
  49. LONG    ends
  50.  
  51. FARPOINTER    struc
  52. off    dw    ?
  53. sel    dw    ?
  54. FARPOINTER      ends
  55.  
  56. wptr    equ     <word ptr>
  57. bptr    equ     <byte ptr>
  58.  
  59. min_ax  macro   REG
  60.         sub     ax,REG
  61.     cwd
  62.     and    ax,dx
  63.         add     ax,REG
  64.     endm
  65.  
  66. max_ax  macro   REG
  67.         sub     ax,REG
  68.     cwd
  69.     not    dx
  70.         and     ax,dx
  71.         add     ax,REG
  72.     endm
  73.  
  74. ; -------------------------------------------------------
  75. ;        DATA SEGMENT DECLARATIONS
  76. ; -------------------------------------------------------
  77.  
  78. sBegin  Data
  79.  
  80. sEnd  Data
  81.  
  82. ; -------------------------------------------------------
  83. ;               CODE SEGMENT DECLARATIONS
  84. ; -------------------------------------------------------
  85.  
  86. ifndef SEGNAME
  87.     SEGNAME equ <_TEXT>
  88. endif
  89.  
  90. createSeg %SEGNAME, CodeSeg, word, public, CODE
  91. .386
  92.  
  93. sBegin  CodeSeg
  94.         assumes cs,CodeSeg
  95.         assumes ds,nothing
  96.         assumes es,nothing
  97.  
  98. ;---------------------------Public-Routine------------------------------;
  99. ; DecodeRle386
  100. ;
  101. ; Entry:
  102. ;       lpbi            bitmap info
  103. ;       pb              destination DIB
  104. ;    pbRle        RLE bits
  105. ;
  106. ; Returns:
  107. ;    None
  108. ; Error Returns:
  109. ;    None
  110. ; Registers Preserved:
  111. ;    DS,SI,DI,SS,BP
  112. ; Registers Destroyed:
  113. ;    all
  114. ; Calls:
  115. ;    nothing
  116. ;-----------------------------------------------------------------------;
  117.         assumes ds,nothing
  118.     assumes es,nothing
  119.  
  120. ;---------------------------Macro---------------------------------------;
  121. ; ReadRLE
  122. ;
  123. ;   read a WORD from rle data
  124. ;
  125. ; Entry:
  126. ;    DS:ESI --> rle data
  127. ; Returns:
  128. ;    AX - word at DS:[ESI]
  129. ;    DS:ESI advanced
  130. ;-----------------------------------------------------------------------;
  131. ReadRLE macro
  132.     lods    wptr ds:[esi]
  133.         endm
  134.  
  135. ;---------------------------Public-Routine------------------------------;
  136. ; DecodeRle386
  137. ;
  138. ;   copy a rle bitmap to a DIB
  139. ;
  140. ; Entry:
  141. ;       pBits       - pointer to rle bits
  142. ; Returns:
  143. ;       none
  144. ; Error Returns:
  145. ;    None
  146. ; Registers Preserved:
  147. ;       BP,DS,SI,DI
  148. ; Registers Destroyed:
  149. ;       AX,BX,CX,DX,FLAGS
  150. ; Calls:
  151. ;    INT 10h
  152. ;-----------------------------------------------------------------------;
  153.     assumes ds,nothing
  154.         assumes es,nothing
  155.  
  156. cProc    DecodeRle386, <FAR, PASCAL, PUBLIC>, <ds>
  157.     ParmD    lpbi
  158.     ParmD    pDest
  159.     ParmD    pBits
  160. cBegin
  161.     push    edi
  162.     push    esi
  163.  
  164.         xor     edi,edi
  165.         xor     esi,esi
  166.         xor     eax,eax
  167.         xor     ecx,ecx
  168.  
  169.     lds    si,lpbi
  170.  
  171.     mov    ax,wptr [si].biWidth
  172.     add    ax,3
  173.     and    ax,not 3
  174.     movzx    ebx,ax            ; ebx is next_scan
  175.  
  176.     les    di,pDest
  177.         lds     si,pBits
  178.         assumes ds,nothing
  179.  
  180. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  181. ; Start of RLE decoding
  182. ;
  183. ;   DS:SI   --> RLE bits
  184. ;   ES:DI   --> screen output (points to start of scan)
  185. ;
  186. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  187. RleBltStart:
  188.     mov    edx,edi         ; save start of scan
  189.  
  190. RleBltNext:
  191.         ReadRLE                     ; al=count ah=color
  192.  
  193.         or      al,al               ; is it a escape?
  194.         jz      RleBltEscape
  195.  
  196. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  197. ; We have found a encoded run (al != 0)
  198. ;
  199. ;   al - run length
  200. ;   ah - run color
  201. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  202. RleBltEncodedRun:
  203.         mov     cl,al
  204.     mov    al,ah
  205.  
  206.     shr    cx,1
  207.     rep    stos wptr es:[edi]
  208.     adc    cl,cl
  209.     rep    stos bptr es:[edi]
  210.  
  211.         jmp     short RleBltNext
  212.  
  213. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  214. ; We have found a RLE escape code (al=0)
  215. ; Possibilities are:
  216. ;       . End of Line            -  ah = 0
  217. ;       . End of RLE             -  ah = 1
  218. ;       . Delta                  -  ah = 2
  219. ;       . Unencoded run          -  ah = 3 or more
  220. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  221. RleBltEscape:
  222.         cmp     ah,al
  223.         je      RleBltEOL
  224.  
  225.         inc     al
  226.         cmp     ah,al
  227.         je      RleBltEOF
  228.  
  229.         inc     al
  230.         cmp     ah,al
  231.         je      RleBltDelta
  232.         errn$   RleBltUnencodedRun
  233.  
  234. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  235. ; We have found a un-encoded run (ah >= 3)
  236. ;
  237. ;   ah          is pixel count
  238. ;   DS:SI   --> pixels
  239. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  240. RleBltUnencodedRun:
  241.     mov    cl,ah
  242.  
  243.     shr    cx,1
  244.     rep    movs wptr es:[edi], wptr ds:[esi]
  245.     adc    cl,cl
  246.         rep     movs bptr es:[edi], bptr ds:[esi]
  247.  
  248.     inc    esi              ; !!! re-align source
  249.     and    si,not 1
  250.     jmp    short RleBltNext
  251.  
  252. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  253. ; We have found a delta jump, the next two bytes contain the jump values
  254. ; note the the jump values are unsigned bytes, x first then y
  255. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  256. RleBltDelta:
  257.         ReadRLE                     ; al = deltaX, ah = deltaY
  258.  
  259.         or      ah,ah
  260.         jnz     RleBltDeltaXY
  261.  
  262. RleBltDeltaX:
  263.     add    edi,eax
  264.         jmp     short RleBltNext
  265.  
  266. RleBltDeltaXY:
  267.         add     edi,ebx
  268.         add     edx,ebx
  269.         dec     ah
  270.         jnz     RleBltDeltaXY
  271.  
  272.     add    edi,eax
  273.         jmp     short RleBltNext
  274.  
  275. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  276. ; We have found a end of line marker, point ES:DI to the begining of the
  277. ; next scan
  278. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  279. RleBltEOL:
  280.         mov     edi,edx             ; go back to start of scan
  281.         add     edi,ebx             ; advance to next scan
  282.         jmp     short RleBltStart   ; go get some more
  283.  
  284. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  285. ; We have found a end of rle marker, clean up and exit.
  286. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  287. RleBltEOF:
  288.         errn$   RleBltExit
  289.  
  290. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;
  291. RleBltExit:
  292.     pop    esi
  293.     pop    edi
  294. cEnd
  295.  
  296. sEnd
  297.  
  298. end
  299.