00001
00002
00003
00004 #ifndef _XVSEGMENTATION_ICC_
00005 #define _XVSEGMENTATION_ICC_
00006
00007 #include <cstdlib>
00008 #include <limits.h>
00009
00010 template <class T, class Y>
00011 class ScalarTable : public LookupTable<T, Y>{
00012
00013 protected:
00014
00015 virtual Y computePixelValue(T pixel) = 0;
00016
00017 public:
00018
00019 ScalarTable() : LookupTable<T, Y>() {}
00020
00021 void buildTable(){
00022
00023 T max = (T)USHRT_MAX;
00024 table = new Y[max + 1];
00025
00026 T pixel;
00027
00028 for(pixel = 0; pixel <= max; pixel++){
00029
00030 table[pixel] = computePixelValue(pixel);
00031 if(pixel == max) break;
00032 }
00033 };
00034
00035 inline Y & operator [] (const u_char pixel){
00036 return table[pixel];
00037 };
00038
00039 inline Y & operator [] (const u_short pixel){
00040 return table[pixel];
00041 };
00042 };
00043
00044 template <class T, class Y>
00045 class RGBTable : public LookupTable<T, Y>{
00046
00047 protected:
00048
00049 virtual Y computePixelValue(T pixel) = 0;
00050
00051 public:
00052
00053 RGBTable() : LookupTable<T, Y>() {}
00054
00055 void buildTable(){
00056
00057 if(table) delete table;
00058 T max = {255, 255, 255};
00059 int num_bits;
00060
00061 switch(max.g){
00062
00063 case 31:
00064 num_bits = 15;
00065 break;
00066 case 63:
00067 num_bits = 16;
00068 break;
00069 case 255:
00070 num_bits = 16;
00071 }
00072
00073 table = new Y[1 << num_bits];
00074
00075 T pixel;
00076
00077 int add = 1, addG = 1;
00078 if(max.r > 31){
00079 add = 8;
00080 addG = 4;
00081 max.r = 248;
00082 max.g = 252;
00083 max.b = 248;
00084 }
00085 pixel.r = pixel.b = pixel.g = 0;
00086
00087 for(pixel.r = 0; pixel.r <= max.r; pixel.r += add){
00088 for(pixel.g = 0; pixel.g <= max.g; pixel.g += addG){
00089 for(pixel.b = 0; pixel.b <= max.b; pixel.b += add){
00090 (*this)[pixel] = this->computePixelValue(pixel);
00091 if(pixel.b == max.b) break;
00092 }
00093 if(pixel.g == max.g) break;
00094 }
00095 if(pixel.r == max.r) break;
00096 }
00097 };
00098
00099 inline Y & operator [] (const XV_RGB15 pixel){
00100 return table[*((u_short *) & pixel)];
00101 };
00102
00103 inline Y & operator [] (const XV_RGB16 pixel){
00104 return table[*((u_short *) & pixel)];
00105 };
00106
00107 inline Y & operator [] (const XV_RGB24 pixel){
00108 return table[((pixel.r & 0xf8) << 8) | ((pixel.g & 0xfc) << 3) | (pixel.b >> 3)];
00109 };
00110
00111 inline Y & operator [] (const XV_RGBA32 pixel){
00112 return table[((pixel.r & 0xf8) << 8) | ((pixel.g & 0xfc) << 3) | (pixel.b >> 3)];
00113 }
00114 };
00115
00116 #endif