[comp.sys.amiga.tech] default bit ordering in deep

carolyn@cbmvax.commodore.com (Carolyn Scheppner - CATS) (05/30/90)

This has been in AmigaMail, but I was asked to post it also....


             Default Bit Ordering in the Storage of Deep ILBMs
             =================================================

Background
==========

   When storing deep images as ILBMs (such as images with 8 bits each 
of R,G, and B), the bits for each pixel represent an absolute RGB value 
for that pixel rather than an index into a limited color map.  
The order for saving the bits is critical since a deep ILBM would not 
contain the usual CMAP of RGB values (such a CMAP would be too large 
and redundant).

   To interpret these "deep" ILBMs, it is necessary to have a standard
order in which the bits of the R, G, and B values will be stored.  
A number of different orderings have already been used in deep ILBMs, 
so it was necessary to us chose one of these orderings as a standard.


The Standard
============

   The following ASDG bit ordering has been chosen as the default 
bit ordering for deep ILBMs.  This ordering is saved by the ASDG
color scanner, read by the associated ASDG software, and read by
Active Circuits image management and Targa transfer software.
Several other developers agreed upon this default bit ordering:

Default standard deep ILBM bit ordering:
saved first -------------------------------------------------> saved last
R0 R1 R2 R3 R4 R5 R6 R7  G0 G1 G2 G3 G4 G5 G6 G7  B0 B1 B2 B3 B4 B5 B6 B7


   One other existing deep bit ordering is that of NewTek, saved by
Video Toaster, and read by Digipaint III.  Unfortunately, other developers
saving and reading deep ILBMs did not agree with this format.  However,
since you may want to parse or convert it, the NewTek format is as follows:

NewTek deep ILBM bit ordering:
saved first ------------------------------------------------------> saved last
R7 G7 B7  R6 G6 B6  R5 G5 B5  R4 G4 B4  R3 G3 B3  R2 G2 B2  R1 G1 B1  R0 G0 B0



The CLUT Chunk
==============

   The CLUT (Color Look-Up Table) chunk proposed by Justin McCormick
may also be found in deep ILBMs.  ASDG may use multiple CLUT chunks 
(one each for R, G, and B) to store color modification information.

-------------------------------------------------------------------------------
"CLUT" IFF 8-Bit Color Look Up Table

Date:	July 2, 1989
From:	Justin V. McCormick
Status:	Public Proposal
Supporting Software:  FG 2.0 by Justin V. McCormick for PP&S


Introduction:

  This memo describes the IFF supplement for the new chunk "CLUT".

Description:

  A CLUT (Color Look Up Table) is a special purpose data module
containing table with 256 8-bit entries.  Entries in this table
can be used directly as a translation for one 8-bit value to
another.

Purpose:

  To store 8-bit data look up tables in a simple format for
later retrieval.  These tables are used to translate or bias
8-bit intensity, contrast, saturation, hue, color registers, or
other similar data in a reproducable manner.

Specifications:

/* Here is the IFF chunk ID macro for a CLUT chunk */
#define ID_CLUT MakeID('C','L','U','T')

/*
 * Defines for different flavors of 8-bit CLUTs.
 */
#define CLUT_MONO	0L	/* A Monochrome, contrast or intensity LUT */
#define CLUT_RED	1L	/* A LUT for reds 		*/
#define CLUT_GREEN	2L	/* A LUT for greens 		*/
#define CLUT_BLUE	3L	/* A LUT for blues 		*/
#define CLUT_HUE	4L	/* A LUT for hues 		*/
#define CLUT_SAT	5L	/* A LUT for saturations 	*/
#define CLUT_UNUSED6	6L	/* How about a Signed Data flag */
#define CLUT_UNUSED7	7L	/* Or an Assumed Negative flag	*/

/* All types > 7 are reserved until formally claimed */
#define CLUT_RESERVED_BITS 0xfffffff8L

/* The struct for Color Look-Up-Tables of all types */
typedef struct
{
  ULONG type;		/* See above type defines */
  ULONG res0;		/* RESERVED FOR FUTURE EXPANSION */
  UBYTE lut[256];	/* The 256 byte look up table */
} ColorLUT;


CLUT Example:

  Normally, the CLUT chunk will appear after the BMHD of an FORM
ILBM before the BODY chunk, in the same "section" as CMAPs are
normally found.  However, a FORM may contain only CLUTs with no
other supporting information.

  As a general guideline, it is desirable to group all CLUTs
together in a form without other chunk types between them.
If you were using CLUTs to store RGB intensity corrections, you
would write three CLUTs in a row, R, G, then B.

  Here is a box diagram for a 320x200x8 image stored as an IFF ILBM
with a single CLUT chunk for intensity mapping:

      	+-----------------------------------+   
      	|'FORM'		64284		    |     FORM 64284 ILBM
      	+-----------------------------------+   
      	|'ILBM'				    |     
      	+-----------------------------------+   
      	| +-------------------------------+ |   
      	| | 'BMHD'	20		  | |     .BMHD 20
      	| | 320, 200, 0, 0, 8, 0, 0, ...  | |   
      	| | ------------------------------+ |   
      	| | 'CLUT'	264	          | |     .CLUT 264
      	| | 0, 0, 0; 32, 0, 0; 64,0,0; .. | |   
      	| +-------------------------------+ |   
      	| +-------------------------------+ |   
      	| |'BODY'		64000     | |     .BODY 64000
      	| |0, 0, 0, ...			  | |   
      	| +-------------------------------+ |   
      	+-----------------------------------+   


Design Notes:
-------------

  I have deliberately kept this chunk simple (KISS) to
facilitate implementation.  In particular, no provision is made
for expansion to 16-bit or 32-bit tables.  My reasoning is that
a 16-bit table can have 64K entries, and thus would benefit from
data compression.  My suggestion would be to propose another
chunk or FORM type better suited for large tables rather than
small ones like CLUT.

-------------------------------------------------------------------------------
-- 
==========================================================================
  Carolyn Scheppner -- CATS  Commodore Amiga Technical Support
  PHONE 215-431-9180   UUCP  ...{uunet,allegra,rutgers}!cbmvax!carolyn 

 Programmers do it a little bit better.
==========================================================================