summaryrefslogtreecommitdiff
path: root/Source/GetColorTab.S
blob: 7512653c374f8ac1c3a718d8b5da0c132f33e240 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
**
**	$Id: GetColorTab.S,v 1.1 92/05/12 22:26:12 chris Exp $
**	$Revision: 1.1 $
**
**	$Filename: GetColorTab.S $
**	$Author: chris $
**	$Release: 19.1 $
**	$Date: 92/05/12 22:26:12 $
**
**	iff.library/IFFL_GetColorTab
**
**	COPYRIGHT (C) 1987-1992 BY CHRISTIAN A. WEBER, BRUGGERWEG 2,
**	CH-8037 ZUERICH, SWITZERLAND.  ALL RIGHTS RESERVED.  NO PART
**	OF THIS SOFTWARE MAY BE COPIED, REPRODUCED,  OR  TRANSMITTED
**	IN ANY FORM OR BY ANY MEANS,  WITHOUT THE PRIOR WRITTEN PER-
**	MISSION OF THE AUTHOR. USE AT YOUR OWN RISK.
**


		IDNT	IFFL_GetColorTab
		SECTION	text,CODE

		INCLUDE	"IFFLib.i"

		XREF	FindChunkFunc
		XDEF	GetColorTabFunc


******* iff.library/IFFL_GetColorTab ****************************************
*
*    NAME
*	IFFL_GetColorTab -- find a CMAP and convert it to a ColorTable
*
*    SYNOPSIS
*	count = IFFL_GetColorTab( iff, colortable )
*	D0                        A1   A0
*
*	LONG IFFFL_GetColorTab( IFF_HANDLE, UWORD * )
*
*    FUNCTION
*	Searches the CMAP chunk of an IFF file and converts it, if it's
*	there, to an Amiga color table structure. This colortable can
*	directly be used as a parameter for the LoadRGB4() function.
*
*    INPUTS
*	iff        - IFF file handle, from IFFL_OpenIFF()
*	colortable - Pointer to a block of memory which must be large
*	             enough to hold the colortable (2 bytes per color).
*	             Must be WORD aligned.
*
*    RESULT
*	Number of colors actually found, or zero if the file has no
*	CMAP chunk
*
*    SEE ALSO
*	IFFL_FindChunk(), IFFL_GetBMHD()
*
*****************************************************************************

GetColorTabFunc:
		movem.l	d2-d5/a2,-(SP)
		movea.l	a0,a2			; Ziel-Adresse

		move.l	#'CMAP',d0
		bsr	FindChunkFunc
	;;	tst.l	d0
		beq.s	99$			; nicht gefunden --->
		movea.l	d0,a0

		addq.l	#4,a0			; Chunk-Namen überlesen
		move.l	(a0)+,d4		; Chunk-size
		divs	#3,d4			; Anzahl Farben
		ext.l	d4			; für D0
		move.l	d4,d0			; Resultat: Anzahl Farben

		moveq	#256-$f0,d5		; Color-Maske $f0
		neg.b	d5			; Toebes-Optimierlung
		bra.s	1$			; Für dbf

.Loop:		move.b	(a0)+,d1		; rot
		and.w	d5,d1			; Nur Bits 7-4 benützen
		move.b	(a0)+,d2		; grün
		and.w	d5,d2			; Nur Bits 7-4 benützen
		move.b	(a0)+,d3		; blau
		and.w	d5,d3			; Nur Bits 7-4 benützen
		lsl.w	#4,d1			; rot  << 4
		lsr.w	#4,d3			; blau >> 4
		or.w	d2,d1
		or.w	d3,d1
		move.w	d1,(a2)+		; in Farbtabelle eintragen
1$:		dbf	d4,.Loop
99$:
		movem.l	(SP)+,d2-d5/a2
		rts

		END