Virtual U.org
Get Personal Training on VU Today
    
Top shadow
 
 register/help
User Name:

Password:

OCOLTBL.H Source File
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

OCOLTBL.H

Go to the documentation of this file.
00001 // Filename    : OCOLTBL.H
00002 // Description : Header file for color remap table ColorTable
00003 
00004 #ifndef __OCOLTBL_H
00005 #define __OCOLTBL_H
00006 
00007 typedef unsigned char BYTE;
00008 typedef unsigned short WORD;
00009 
00010 #define MAX_COLOUR_TABLE_SIZE 0x100
00011 
00012 // ---------- define RGBColor --------//
00015 struct RGBColor {
00016     BYTE  red;
00017     BYTE  green;
00018     BYTE  blue;
00019 
00020     RGBColor() {}
00021     RGBColor(BYTE r, BYTE g, BYTE b) : red(r), green(g), blue(b) {}
00022 };
00023 
00024 // ---------- define HSVColor --------//
00027 struct HSVColor {
00028     double hue;
00029     double saturation;
00030     double brightness;
00031 
00032     HSVColor() {}
00033     HSVColor(double h, double s, double v) : hue(h), saturation(s), brightness(v) {}
00034 };
00035 
00036 // ---------- define struct PalDesc ---------//
00038 struct PalDesc {
00039     BYTE *pal;
00040     int pal_pitch;                                  // 3 for RGB, or sizeof(PALETTEENTRY)
00041     int pal_size;                                   // number of color
00042     int bit_width;                                  // 8 for 8-bit, 6 for 6-bit
00043     BYTE *reserved_color;
00044     int reserved_count;
00045 
00046     PalDesc(void *palPtr, int pitch, int size, int bitWidth, BYTE *rPtr =(unsigned char*)0, int rCount=0):
00047         pal((BYTE *)palPtr), pal_pitch(pitch), pal_size(size), bit_width(bitWidth),
00048         reserved_color(rPtr), reserved_count(rCount) {}
00049 
00050     BYTE  normalize(BYTE c)       { return bit_width==8 ? c : (c<<(8-bit_width))+ (1<<(7-bit_width)); }
00051     BYTE  red(int n)              { return normalize(pal[pal_pitch*n]); }
00052     BYTE  green(int n)            { return normalize(pal[pal_pitch*n+1]); }
00053     BYTE  blue(int n)             { return normalize(pal[pal_pitch*n+2]); }
00054     RGBColor get_rgb(int n)     { return RGBColor(red(n), green(n), blue(n)); }
00055     int is_reserved(BYTE c, int &reservedIndex) {
00056         if( reserved_color && reservedIndex < reserved_count &&
00057             c == reserved_color[reservedIndex]) {
00058             reservedIndex ++;
00059             return 1;
00060         }
00061         return 0;
00062     }
00063 };
00064 
00065 // ----------- define class ColorTable ---------//
00066 
00067 class File;
00068 
00070 class ColorTable {
00071 private:
00072     WORD *remap_table;
00073     WORD **remap_table_array;
00074 
00075 public:
00076     int abs_scale;
00077     int table_size;
00078     static BYTE identity_table[MAX_COLOUR_TABLE_SIZE];
00079 
00080 public:
00081     ColorTable();
00082     ColorTable(int absScale, int tableSize, WORD *customTable);
00083     ColorTable(const ColorTable &);
00084     ~ColorTable();
00085     void  init();
00086     void  init(int absScale, int tableSize, WORD *customTable);
00087     void  deinit();
00088     ColorTable& operator=(const ColorTable &);
00089 
00090     static RGBColor bright_func( RGBColor, int, int);
00091 
00092     // pass ColorTable::bright_func as the argument fp for brightness table
00093     void  generate_table(int absScale, PalDesc &palD, RGBColor (*fp)(RGBColor, int, int));
00094     void  generate_table_fast(int absScale, PalDesc &palD, RGBColor (*fp)(RGBColor, int, int));
00095     void  generate_table(PalDesc &sPalD, PalDesc &palD);
00096     WORD *get_table(int scale=0);
00097     WORD **get_table_array(int scale=0) { return remap_table_array + scale + abs_scale; }
00098     void  patch_table(BYTE from, WORD to);
00099 
00100     int write_file(File *);
00101     int read_file(File *);
00102 
00103 private:
00104     void  create_table_array();
00105 
00106     static int  color_dist(RGBColor, RGBColor);
00107     static int  color_dist_hsv(RGBColor, RGBColor);
00108     static HSVColor rgb2hsv(RGBColor &);
00109     static RGBColor hsv2rgb(HSVColor &);
00110 };
00111 #endif

Generated on Fri Aug 23 01:37:18 2002 for VirtualU by doxygen1.2.17