home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0040 - 0049 / ibm0040-0049 / ibm0040.tar / ibm0040 / IMGPROC.ZIP / C6PCX.ZIP / COMPRESS.ASM next >
Encoding:
Assembly Source File  |  1990-10-11  |  3.4 KB  |  119 lines

  1. ;Copyright 1990 by John Wiley & Sons, Inc.
  2. ;          All Rights Reserved.
  3. ;
  4. ; Video Compression Routine callable from Turbo C
  5. ;
  6. ; written by Craig A. Lindley
  7. ; last update: 05/22/89
  8. ;
  9. ;
  10. _TEXT    segment    byte public 'CODE'
  11.       DGROUP    group    _DATA,_BSS
  12.       assume    cs:_TEXT,ds:DGROUP,ss:DGROUP
  13. _TEXT    ends
  14.  
  15. _DATA    segment word public 'DATA'
  16. ;
  17. _DATA    ends
  18.  
  19. _BSS    segment word public 'BSS'
  20. ;
  21. _BSS    ends
  22. ;
  23. ;
  24. _TEXT    segment    byte public 'CODE'
  25. ;
  26. ;Scan Line Compression
  27. ;
  28. ; Procedure _Pack
  29. ;
  30. ; This procedure compresses a video line into RLL encoding. Specifically,
  31. ; the RLL encoding used by PCX graphics files. In this encoding, a repeat
  32. ; byte sequence is compressed into a repeat count followed by the byte
  33. ; to be repeated. A maximum repeat of 63 is all that is allowed because a
  34. ; repeat count byte is identified by having its most significant two bits
  35. ; set high. This also means that any single char with a value above 0BFH
  36. ; also will be encoded as a repeat count (C1) followed by the bytes value so
  37. ; the bytes value will not be misinterpreted as a repeat count.
  38. ;
  39. ; CALL:   callable from C.
  40. ; PROTOTYPE: unsigned Pack (BYTE far *, BYTE far *, unsigned Count)
  41. ; INPUT:  all parameters passed to this function are on the stack. The
  42. ;         stack should contain the following: Count at [bp+12], Output buf seg
  43. ;         at [bp+10], Output buf offset at [bp+8], Input buf seg at [bp+6]
  44. ;         and the Input buf offset at [bp+4].
  45. ; OUTPUT: the number of bytes in the packed output buffer returned in ax.
  46. ; USES:   ax,bx,cx,dx,es,si,di registers
  47. ;
  48.     Public _Pack
  49. ;
  50. _Pack     proc    near
  51. ;
  52.     push    bp
  53.     mov    bp,sp
  54.     push    si
  55.     push    di
  56. ;
  57.     mov    si,[bp+4]        ;load parms from the stack
  58.     mov    ds,[bp+6]        ;ptr to buffer to pack
  59.     mov    di,[bp+8]
  60.     mov    es,[bp+10]        ;ptr to packed buffer
  61.     mov    dx,[bp+12]        ;size of buffer to pack
  62. ;
  63. ;when we get here the actual RLL encoding is performed
  64. ;
  65.     cld                ;move ptrs forward in memory
  66. pack1:    lodsb                ;get byte from input buffer
  67.     mov    bl,al            ;save in bl
  68.     mov    cx,1            ;char rep count is 1
  69.     dec    dx            ;dec # of input bytes to process
  70. ;
  71. pack2:    cmp    dx,0            ;all input bytes compressed ?
  72.     je    pack3            ;jump if so
  73.     cmp    cx,63            ;at max block size ?
  74.     je    pack3            ;jump if so
  75.     cmp    bl,[si]            ;look at next byte
  76.     jne    pack3            ;jump if not same
  77.     inc    si            ;bump input ptr to next byte
  78.     dec    dx            ;now one less
  79.     inc    cx            ;byte same so bump rep count
  80.     jmp    short pack2        ;try for another match
  81. ;
  82. ;we are now ready to place compressed items in the output buffer
  83. ;
  84. pack3:    cmp    cx,1            ;rep count > 1 ?
  85.     ja    pack5            ;jump if so
  86.     cmp    al,0BFH            ;char > BFH ?
  87.     ja    pack5            ;jump if so
  88. ;
  89. ;when we get here we have a single byte to place in the output buffer with
  90. ;a value less than C0H.
  91. ;
  92. pack4:    stosb                ;put byte in output buffer
  93.     cmp    dx,0            ;any more input chars ?
  94.     jne    pack1            ;if so go back and start over
  95.     jmp    short pack6        ;get ready to exit if no more
  96. ;
  97. ;when we get here, we must process a repeat count followed by a repeat byte
  98. ;
  99. pack5:    push    ax            ;save rep byte
  100.     mov    al,cl            ;rep count to al
  101.     or    al,0C0H            ;set the 2 msbits
  102.     stosb                ;store rep count in output buffer
  103.     pop    ax            ;get byte back
  104.     jmp    short pack4        ;now output the byte
  105. ;
  106. ;we're done and ready to exit
  107. ;
  108. pack6:    mov    ax,di            ;get output ptr
  109.     sub    ax,[bp+8]        ;calc # of bytes in output buf
  110.     pop    di            ;restore regs and exit
  111.     pop    si
  112.     pop    bp
  113.     ret
  114. ;
  115. _Pack    endp
  116. ;
  117. _TEXT    ends
  118.     end
  119.