Dali : Color -- C API

[ Header Files | Types | Constants | Color Conversion | ColorHashTable Allocations | ColorHashTable Queries | VpTree Primitives | Color Quantization | Internal API | See Also ]

Header Files

#include <dvmcolor.h>

Type Definitions

UnpackColor

Structure UnpackColor stores an (r, g, b) tuple, with a extra tag. This structure is used as part of ColorHashTables.

    typedef struct UnpackColor {
        unsigned char tag;
        unsigned char r;
        unsigned char g;
        unsigned char b;
    } UnpackColor;
  
tag
An extra 8 bits of data that can be used by the programmer. In the hash table, tag is used to indicate if an entry in the table is empty or not.
r
Red value of pixel (0..255)
g
Green value of pixel (0..255)
b
Blue value of pixel (0..255)

Color

A color can have three components (r, g, b) that can be accessed individually or can be retrieved in packed format (a 4 byte integer). This provides an efficient way to copy, compare and initialize colors. This structure is used as part of ColorHashTables.

    typedef union Color {
        UnpackColor unpack;
        int pack;
    } Color;
  
unpack
Unpacked version of the (r, g, b) value. Each color can be accessed individually.
pack
Packed version of the (r, g, b) value.

ColorHashEntry

ColorHashEntry is the type of an entry in ColorHashTable. It contains a Color (r,g,b) as the key, and an integer value.

   typedef struct ColorHashEntry {
       Color color;
       int value;   
   } ColorHashEntry;
  
color
The key of this hash table entry.
value
The value of this hash table entry.

ColorHashTable

A ColorHashTable is an open-addressing hash table that maps colors to values. ColorHashTables are generally used as caches in Dali. That is, when a color is mapped to a value (e.g., when converting an image to a colormapped image in GIF encoding), the mapping can be stored in a ColorHashTable so the next mapping can be done very quickly.

    typedef struct ColorHashTable {
        int size;
        int numOfEntry;
        ColorHashEntry *table;
    } ColorHashTable;
  
size
The number of buckets in the hash table.
numOfEntry
The number of elements inserted into the hash table.
table
A pointer to the table of entries.

VpNode

A VpNode is a node in the VP (Vintage Point) tree data structure. The actual tree is just an array with 256 VpNodes. For a brief description of the data structure, see the overview of color package.

    typedef struct VpNode {
        unsigned char index;
        unsigned char left;
        unsigned char right;
        float ll, lu, rl, ru, mu;
    } VpNode;
  
index
index to image maps. It specifies the node color of this node.
left
a "pointer" to the left subtree, in the form of an index to the VpTree array.
right
a "pointer" to the right subtree, in the form of an index to the VpTree array.
ll,lu,rl,ru
ll and lu are lower bound and upper bound of distance between the node color and all colors in the left subtree. Similarly, rl and ru are for the right subtree.
mu
the "radius" of this node. Every color with distance more than mu will goes to right subtree, otherwise it goes to the left subtree.

VpTree

A VpTree is a pointer the a root of a VP (Vintage Point) tree data structure, which is implemented as an array of 256 VpNode. In Dali, VpTrees are used to quickly find the closest color in a colormap to a given R,G,B color.

    typedef struct VpNode *VpTree;
  

Constants

Return Code

Return code from various color hash table primitives.

    #define DVM_COLOR_HASH_TABLE_OK 0
    #define DVM_COLOR_HASH_TABLE_FULL -1
    #define DVM_COLOR_NOT_FOUND -2
  

Operators

Color Conversion

void RgbToY(ByteImage *r, ByteImage *g, ByteImage *b, ByteImage *y)

void RgbToYuv444(ByteImage *r, ByteImage *g, ByteImage *b, ByteImage *y, ByteImage *u, ByteImage *v)
void YuvToRgb444(ByteImage *y, ByteImage *u, ByteImage *v, ByteImage *r, ByteImage *g, ByteImage *b)

void RgbToYuv422(ByteImage *r, ByteImage *g, ByteImage *b, ByteImage *y, ByteImage *u, ByteImage *v)
void YuvToRgb422(ByteImage *y, ByteImage *u, ByteImage *v, ByteImage *r, ByteImage *g, ByteImage *b)

void RgbToYuv411(ByteImage *r, ByteImage *g, ByteImage *b, ByteImage *y, ByteImage *u, ByteImage *v)
void YuvToRgb411(ByteImage *y, ByteImage *u, ByteImage *v, ByteImage *r, ByteImage *g, ByteImage *b)

void RgbToYuv420(ByteImage *r, ByteImage *g, ByteImage *b, ByteImage *y, ByteImage *u, ByteImage *v)
void YuvToRgb420(ByteImage *y, ByteImage *u, ByteImage *v, ByteImage *r, ByteImage *g, ByteImage *b)


ColorHashTable Allocations

ColorHashTable* ColorHashTableNew(int bits)

void ColorHashTableClear(ColorHashTable *table)


ColorHashTable Queries

void ColorHashTableFree(ColorHashTable *table)

#define ColorHashTableGetSize(x) (x)->size

#define ColorHashTableGetNumOfEntry(x) (x)->numOfEntry


VpTree Primitives

VpNode* VpTreeNew( );

void VpTreeInit(ImageMap *rmap, ImageMap *gmap, ImageMap *bmap, VpNode *tree);

void VpTreeFree(VpNode *tree);


Color Quantization

void RgbTo256(ByteImage *r, ByteImage *g, ByteImage *b, ColorHashTable *table, ImageMap *rmap, ImageMap *gmap, ImageMap *bmap)

void RgbQuantWithHashTable(ByteImage *r, ByteImage *g, ByteImage *b, ColorHashTable *table, ImageMap *rmap, ImageMap *gmap, ImageMap *bmap, ByteImage *out)

void RgbQuantWithVpTree(ByteImage *r, ByteImage *g, ByteImage *b, VpNode *tree, ColorHashTable *table, ImageMap *rmap, ImageMap *gmap, ImageMap *bmap, ByteImage *out)


Internal API

ColorHashTableAdd(ColorHashTable *table, unsigned char r, unsigned char g, unsigned char b, int v)

ColorHashTableAddAt(ColorHashTable *table, int index, unsigned char r, unsigned char g, unsigned char b, int value)

ColorHashTableFind(ColorHashTable *table, unsigned char r, unsigned char g, unsigned char b, int *i, int *v)

ColorHashTableSet(ColorHashTable *table, index, int value)

ColorHashTablePackSelf (ColorHashTable *table)

VpTreeFind (VpTree tree, ImageMap *rmap, ImageMap *gmap, ImageMap *bmap, unsigned char r, unsigned char g, unsigned char b)


See Also

ByteImage , ImageMap


Last updated : Saturday, November 14, 1998, 07:50 PM