home *** CD-ROM | disk | FTP | other *** search
- ;Copyright 1990 by John Wiley & Sons, Inc.
- ; All Rights Reserved.
- ;
- ; Video Compression Routine callable from Turbo C
- ;
- ; written by Craig A. Lindley
- ; last update: 05/22/89
- ;
- ;
- _TEXT segment byte public 'CODE'
- DGROUP group _DATA,_BSS
- assume cs:_TEXT,ds:DGROUP,ss:DGROUP
- _TEXT ends
-
- _DATA segment word public 'DATA'
- ;
- _DATA ends
-
- _BSS segment word public 'BSS'
- ;
- _BSS ends
- ;
- ;
- _TEXT segment byte public 'CODE'
- ;
- ;Scan Line Compression
- ;
- ; Procedure _Pack
- ;
- ; This procedure compresses a video line into RLL encoding. Specifically,
- ; the RLL encoding used by PCX graphics files. In this encoding, a repeat
- ; byte sequence is compressed into a repeat count followed by the byte
- ; to be repeated. A maximum repeat of 63 is all that is allowed because a
- ; repeat count byte is identified by having its most significant two bits
- ; set high. This also means that any single char with a value above 0BFH
- ; also will be encoded as a repeat count (C1) followed by the bytes value so
- ; the bytes value will not be misinterpreted as a repeat count.
- ;
- ; CALL: callable from C.
- ; PROTOTYPE: unsigned Pack (BYTE far *, BYTE far *, unsigned Count)
- ; INPUT: all parameters passed to this function are on the stack. The
- ; stack should contain the following: Count at [bp+12], Output buf seg
- ; at [bp+10], Output buf offset at [bp+8], Input buf seg at [bp+6]
- ; and the Input buf offset at [bp+4].
- ; OUTPUT: the number of bytes in the packed output buffer returned in ax.
- ; USES: ax,bx,cx,dx,es,si,di registers
- ;
- Public _Pack
- ;
- _Pack proc near
- ;
- push bp
- mov bp,sp
- push si
- push di
- ;
- mov si,[bp+4] ;load parms from the stack
- mov ds,[bp+6] ;ptr to buffer to pack
- mov di,[bp+8]
- mov es,[bp+10] ;ptr to packed buffer
- mov dx,[bp+12] ;size of buffer to pack
- ;
- ;when we get here the actual RLL encoding is performed
- ;
- cld ;move ptrs forward in memory
- pack1: lodsb ;get byte from input buffer
- mov bl,al ;save in bl
- mov cx,1 ;char rep count is 1
- dec dx ;dec # of input bytes to process
- ;
- pack2: cmp dx,0 ;all input bytes compressed ?
- je pack3 ;jump if so
- cmp cx,63 ;at max block size ?
- je pack3 ;jump if so
- cmp bl,[si] ;look at next byte
- jne pack3 ;jump if not same
- inc si ;bump input ptr to next byte
- dec dx ;now one less
- inc cx ;byte same so bump rep count
- jmp short pack2 ;try for another match
- ;
- ;we are now ready to place compressed items in the output buffer
- ;
- pack3: cmp cx,1 ;rep count > 1 ?
- ja pack5 ;jump if so
- cmp al,0BFH ;char > BFH ?
- ja pack5 ;jump if so
- ;
- ;when we get here we have a single byte to place in the output buffer with
- ;a value less than C0H.
- ;
- pack4: stosb ;put byte in output buffer
- cmp dx,0 ;any more input chars ?
- jne pack1 ;if so go back and start over
- jmp short pack6 ;get ready to exit if no more
- ;
- ;when we get here, we must process a repeat count followed by a repeat byte
- ;
- pack5: push ax ;save rep byte
- mov al,cl ;rep count to al
- or al,0C0H ;set the 2 msbits
- stosb ;store rep count in output buffer
- pop ax ;get byte back
- jmp short pack4 ;now output the byte
- ;
- ;we're done and ready to exit
- ;
- pack6: mov ax,di ;get output ptr
- sub ax,[bp+8] ;calc # of bytes in output buf
- pop di ;restore regs and exit
- pop si
- pop bp
- ret
- ;
- _Pack endp
- ;
- _TEXT ends
- end