UnPackerILBMCMAP
Synopsis
colorTable, nColors = UnPackerILBMCMAP(data, dest)
A0 D0 A0 A1C Prototype
There is no direct C prototype exported for this function. It is called internally from assembly.
Description
Unpacks an ILBM CMAP (color map) chunk from IFF data into an Amiga-format color table. The function uses FindAIFFChunk() to locate the “CMAP” chunk within the IFF data, then converts the 24-bit RGB triplets (8 bits per component) into the Amiga 12-bit color format (4 bits per component) used by the OCS/ECS chipset.
If a destination buffer is provided in A1, the color data is written there. If A1 is NULL, the function allocates memory for the color table automatically using exec.library/AllocMem().
The conversion is performed within a Forbid()/Permit() pair to ensure atomicity.
Inputs
- data (A0) — Pointer to the beginning of the IFF data in memory (can include the FORM header).
- dest (A1) — Pointer to a destination buffer for the color table, or NULL to have the function allocate one.
Result
- colorTable (A0) — Pointer to the color table (either the provided buffer or the newly allocated one).
- nColors (D0) — Number of colors in the color table.
- If the CMAP chunk is not found, the function returns with the zero flag set.
Notes
When the function allocates memory for the color table (when dest is NULL), the caller is responsible for freeing it. Each color entry occupies one WORD (2 bytes) in the resulting table, in the 12-bit Amiga RGB4 format ($0RGB).
See Also
- FindAIFFChunk
- UnPackerILBMBODY
graphics.library/LoadRGB4()
Implementation
The original 68020 assembly implementation:
; Rel.2.3 - 12 Oct 1991 --- UnPackerILBMCMAP()
_LVOUnPackerILBMCMAP
movem.l d1-d7/a1-a6,-(sp)
lea "CMAP",a2
move.l a2,d0
jsr _LVOFindAIFFChunk
beq.s UnPackCMAP_Exit
move.l a1,a2 ; save dest buf
lea 8(a0),a3 ; save source data
move.l d1,d0
moveq #3,d1
divu d1,d0 ; nColors
add.w d0,d0 ; double for word, nbyte to alloc
moveq #0,d7
move.w d0,d7 ; Dbf
move.l a1,d6 ; Alloc ColorTable?
bne.s UnPackCMAP_NoAlloc
moveq #1,d1
move.l ab_ExecBase(a6),a6
jsr _LVOAllocMem(a6)
tst.l d0
beq.s UnPackCMAP_Exit
move.l d0,a2
UnPackCMAP_NoAlloc
jsr _LVOForbid(a6)
move.l d7,d6
subq.l #1,d7 ; Align dbf
movem.w ClearRegs,d0-d2
move.l a2,a1
UnPackCMAP_Loop
move.b (a3)+,d0
asl.w #4,d0
move.b (a3)+,d1
move.b (a3)+,d2
asr.w #4,d2
or.w d0,d1
or.w d1,d2
move.w d2,(a1)+
movem.w ClearRegs,d0-d2
dbf d7,UnPackCMAP_Loop
jsr _LVOPermit(a6)
move.l a2,a0 ; ColorTable
move.l d6,d0 ; ncolors
UnPackCMAP_Exit
movem.l (sp)+,d1-d7/a1-a6
rts