A89: 8-bit RLE decompression routine


[Prev][Next][Index][Thread]

A89: 8-bit RLE decompression routine




I noticed someone looking for an 8-bit RLE decompression routine for use
with Image Studio's RLE compression option - so I took a look at the z80
version and ported it over to 68k.  This will work on any 68k calc. . . any
questions or anyone that wants an example program - or if your email program
deletes those leading spaces - email me off the list.

    -Scott

;=========================================================================
; RLE picture display routine
; Decodes 8-bit RLE compressed images
;
; written by Scott Noveck <scott@acz.org>
; based on algorithm by David Phillips
; last update: 10/17/99
;
; input: a0 = RLE encoded picture, a1 = where to display (BSS recommended)
;  Adjust the WIDTH/HEIGHT equates and SAVEFLAG below
; output: decompressed picture
; destroys: d0-d2/a0-a1 if SAVEFLAG is off, nothing if SAVEFLAG is on
; current size: 15 bytes if SAVEFLAG is off, 19 bytes if SAVEFLAG is on
;=========================================================================

SAVEFLAG set  0
;If 1, no registers destoryed.  Otherwise, destroys d0-d2/a0-a1

HEIGHT  equ  [height]
WIDTH  equ  [width]
;WIDTH MUST BE DIVISIBLE BY 8! If not, the image will _NOT_ decompress
properly!

LENGTH  equ  ((WIDTH/8)*HEIGHT)-1

DispRLE:
  ifeq SAVEFLAG-1
 movem.l d0-d2/a0-a1,-(a7) ;if SAVEFLAG set then save copy of registers
  endif
 move.l #LENGTH,d0  ;decompress into (LENGTH+1) bytes - d0 is now the
counter
\DispRLEL:
 move.b (a0)+,d1  ;get next byte
 cmp.b #$91,d1   ;is it a run?
 beq \DispRLERun  ;if so, decode it
 move.b d1,(a1)+  ;otherwise, copy the byte
\DispRLEC:
 dbra.l d0,\DispRLEL  ;if counter != -1, repeat
  ifeq SAVEFLAG-1
 movem.l (a7)+,d0-d2/a0-a1 ;if SAVEFLAG set then restore copy of registers
  endif
 rts    ;otherwise, we're done =)
\DispRLERun:
 move.b (a0)+,d1  ;get run value
 move.b (a0)+,d2  ;get run length
\DispRLERunL:
 move.b d1,(a1)+  ;copy the byte
 subq.b #1,d0   ;decrease counter
 subq.b #1,d2   ;decrease run length remaining
 bne \DispRLERunL  ;if we're not done then loop
 bra \DispRLEC   ;otherwise, check to see if we should continue
decompression