rgb2c (tool command)

Converts an .rgb file to a C data structure

Syntax

rgb2c [-m name][-f fmt][-o output][-s bits][-t citype]
        [-l r,g,b][-h r,g,b][-F][-P]
        [-Q][-S smask][-X][-b][-r] infile.rgb

Description

rgb2c reads an SGI RGB image file and generates a C data structure to standard output. The input image can have from 1 to 4 planes: A 1-plane input file is assumed to be intensity only. A 2-plane input file is assumed to be intensity/alpha. A 3-plane input file is treated as RGB. A 4-plane input file is treated as RGBA.

The currently supported output formats are: Intensity (4/8 bit), Intensity/Alpha (4/8/16 bit), and RGBA (16/32 bit). Any other specified combination of type and bit size is mapped to one of these three choices.

Command Line Options

-m name
Is the name of the C data structure. The default value is "texture".

-f fmt
Specifies the format of the output. Choices are I, IA, or RGBA.

-o output
Specifies the format of output text. Choices are C for .c output, MIP for mip-mapped .c output, MIPSUPPLIED for mip-mapped .c output with the different levels supplied, or RAW for raw ASCII format. When you use MIPSUPPLIED, name the texture files name0.rgb, name1.rgb, name2.rgb, and so on where name0.rgb is the top level image and each successive image is exactly half the size (in x and y) of the preceding one.

-s bits
Specifies the bit size of the output data. Choices are 4, 8, 16, or 32.

-t citype
Specifies the type of color index. (C: color, I: intensity)

-l r,g,b
Specifies the low colors for interpolation. It defaults to 0, 0, 0.

-h r,g,b
Specifies the high colors for interpolation. It defaults to 255, 255, 255.

-F
Flips the image vertically.

-P
Toggles padding of texel rows for use with gDPLoadBlock. The default is padding on.

-Q
Quadricates (replicates each entry four times) the lookup table that is output for CI type textures. Use this option when loading TLUTs using the load_block command (as is done for version 1 of the hardware).

-S smask
Swaps 32-bit words on odd lines, toggling bit smask in texels.

-X
Adds extra padding to make all declared objects a multiple of 32 bytes long.

-b
Toggles shifting each tile by 0.5. This is necessary when MIP map levels are supplied (output type MIPSUPPLIED), when the shift has been performed, and when the lower levels were filtered. Ususlly you don't need to use this option.

-r
Excludes the raw data. This can be used when the output type is MIP or MIPSUPPLIED to avoid including extraneous data that will eat memory space. Do not use this option with C output.

Comment

rgb format

There are two rgb formats; one is a format called VERBATIM that uses raw data instead of using compressed data, the other one is RLE (Run Length Encoding) which compresses data to store them. Both formats comprise of the identical file format which has long words of 512 length in its header followed by the data.

The header is defined as an IMAGE structure in 4Dgifts/iristools/include/image.h. Each element is described below.

unsigned short imagic
Checks if the high and low byte order of a word data is correct, and is the ID indicating the format used in IRIS.

unsigned short type
Indicates the format of rgb file (number of bytes per pixel (1 or 2)) such as VERBATIM(1), VERBATIM(2), RLE(1), or RLE(2).

unsinged short dim
Indicates the dimension (1~3) of data where 1 represents one dimensional with x data, 2 represents two dimensional with x and y data, and 3 represents 3 dimensional with x, y, and z data.

unsigned short xsize
The pixel size of x on screen.

unsigned short ysize
The pixel size of y on screen.

unsigned short zsize
Number of colors used. 3 for rgb. 1 for blak and white.

unsigned long min
The minimum value for all data.

unsigned long max
The maximam value for all data.

unsigned long wastebyte
0 for VERBATIM. Number of bytes already written as the data for RLE.

char name[80]
Name of data (use isetname to change)

long colormap
Source color information that includes CM-NOMAL, CM-DITHERED, CM-SCREEN, and CM-COLORMAP.

long file
File descriptor for opening and creating a data file (temporary area).

unsigned short flags
File protection flag

short dorev
0 or 1. 1 indicates that a dat falls on the word boundary and the high and low bytes have been switched. This swaps the high and low byte order when they are handled.

short x
Area reserved to store the size of x (temporary area).

short y
Area reserved to store the size of y (temporary area).

short z
Area reserved to store the size of z (temporary area).

short cnt
It is used for file byte count (temporary area).

unsigned short *ptr
0

unsigned short *base
Pointer to a buffer to get flushed out and written to a file when the process completes (temporary area).

unsigned short *tmpbuf
Pointer used to change the format of a variable (temporary area).

unsigned long offset
Offset from the beginning of the file to the end of the header (512L).

unsigned long rleend
Number of bytes from the begining of the processed data to its end when reading/writing data is performed for RLE.

unsigned long *rowstart
Pointer to the table indicating the number of bytes from the beginning of the data to the beginning of each line of the data provided as a table right after the Header.

long *rowsize
Pointer to the table indicating the size in bytes of each line of data provided as a table after the rowstart table.

These are elements of the header. Image data comes after the header. For VERBATIM, the data is put as follows.

Rs from the all lines come first, then Gs, and finally Bs.

Compression format is used for RLE. Therefore, the byte counts (rowstart) to the beginning of each line and each size (rowsize) are placed right after the header ends. Just as VERBATIM, the order of color index takes Rs for all the lines, then Gs, and Bs followed by the compressed data.

RLE follows the rules for compression described below. If the same data continue up to 3 or more consecutive bytes, (number of data) followed by (data contents) are described. If the same data continue to less than 3 consecutive bytes or different data continue, it is described as (128 + number of data) followed by (data x), (data y)...., and (data z). For instance, the data will be compressed for the following data.

AAAABCDEEEFGGGHH
will be compressed as
4A 131BCD 3E 129F 3G 130HH

rgba format is similar to the rgb format exept a is added to the rgba format.

See Also

flt2c

Revision History

1999/04/30 Changed Format