**
**     $VER: DecomPic.a V1.00 (24-06-95)
**
**     Author:  Gerben Venekamp
**     Updates: 24-06-95  Version 1.00     Initial Module
**
**  DecomPic.a decompresses, if necessary, an ILBM Picture.
**


		XDEF	_DecompressPic
		
		INCLUDE	"include:exec/macros.i"
		INCLUDE	"include:datatypes/pictureclass.i"
		INCLUDE	"include:intuition/screens.i"
		
		SECTION	Decomp,code
****
*
*  pre:  A0 -> Pointer to BodyData.
*        A1 -> Pointer to BitMapHeader.
*        A2 -> Pointer to Screen structure.
*        A3 -> Pointer to allocated memory to store bitplane addresses.
*  post: None.
*
****
_DecompressPic
		move.l	a4,-(SP)		  We Need to keep this one!
		lea	(sc_ViewPort,a2),a4
		move.l	(vp_RasInfo,a4),a4
		move.l	(ri_BitMap,a4),a4   Get BitMap Structure.
HardStop
		CLEAR	D6
		move.w	(bm_BytesPerRow,a4),d6
		lea	(bm_Planes,a4),a4   Get BitMap Addresses.
		move.l	a3,a5
		CLEAR	D1
		move.b	(bmh_Depth,a1),d1
		subq.w	#1,d1
		move.w	d1,d7		  For later use.
CopyBitplaneAddresses
		move.l	(a4)+,(a5)+
		dbf	d1,CopyBitplaneAddresses
		
		cmp.b	#cmpNone,(bmh_Compression,a1)
		beq.s	Do_cmpNone
		cmp.b	#cmpByteRun1,(bmh_Compression,a1)
		beq.s	Do_cmpByteRun1
; What should we do if None of the above compression types have
; been selected?
		move.l	(SP)+,a4		Get that one back!
		
		rts

Do_cmpNone
		move.l	(SP)+,a4		Get that one back!
		rts
		
Do_cmpByteRun1
		move.w	(bmh_Height,a1),d5
		move.w	(bmh_Width,a1),d2
		add.w	#15,d2
		lsr.w	#4,d2
		add.w	d2,d2
		
		subq.w	#1,d5
FinishAll
		move.l	a3,a4
		move.w	d7,d4
FinishRaster
		move.l	(a4),a5
		add.l	d6,(a4)+
		
		move.w	d2,d3
FinishPlane
		move.b	(a0)+,d0
		ext.w	d0		Make Signed Word.
		bmi.s	Decompress
		
		sub.w	d0,d3		Result is bytes to do.
		subq.w	#1,d3		A little correction.
copy_1
		move.b	(a0)+,(a5)+	Litteral copy
		nop
		nop
		nop
		dbf	d0,copy_1

		tst.w	d3		0 bytes to do?
		bne.s	FinishPlane	No
		
		nop
		nop
		nop
		dbf	d4,FinishRaster
		
		nop
		nop
		nop
		dbf	d5,FinishAll

		move.l	(SP)+,a4		Get that one back!
		rts
		
Decompress
		neg.w	d0
		move.b	(a0)+,d1
		sub.w	d0,d3		Result is bytes to do.
		subq.w	#1,d3		A little correction.
copy_2
		move.b	d1,(a5)+
		nop
		nop
		nop
		dbf	d0,copy_2
		
		tst.w	d3
		bne.s	FinishPlane
		
		nop
		nop
		nop
		dbf	d4,FinishRaster
		
		nop
		nop
		nop
		dbf	d5,FinishAll
		
		move.l	(SP)+,a4		Get that one back!
		rts
		