casa
$Rev:20696$
|
00001 #if !defined(QTPCCOLORTABLE_H) 00002 #define QTPCCOLORTABLE_H 00003 00004 #include <vector> 00005 00006 #include <casa/aips.h> 00007 00008 #include <casa/Arrays/Vector.h> 00009 #include <casa/Arrays/Matrix.h> 00010 #include <display/Display/DisplayEnums.h> 00011 #include <display/Display/PixelCanvasColorTable.h> 00012 #include <casa/BasicMath/Math.h> 00013 00014 #include <graphics/X11/X_enter.h> 00015 #include <QtGui/QImage> 00016 #include <QtGui/QColor> 00017 #include <graphics/X11/X_exit.h> 00018 00019 namespace casa { 00020 00021 class QtPCColorTable : public PixelCanvasColorTable { 00022 00023 public: 00024 00025 QtPCColorTable(); 00026 virtual ~QtPCColorTable() { } 00027 00028 00029 //# only-vaguely-informative boilerplate... 00030 00031 virtual Bool staticSize() { return True; } 00032 00033 virtual Bool resize(uInt /*nReds*/, uInt /*nGreens*/, uInt /*nBlues*/) { return False; } 00034 00035 virtual void nColors(uInt &n1, uInt &n2, uInt &n3) const { 00036 n1 = 256; n2 = 256; n3 = 256; } 00037 00038 virtual uInt depth() const { return 32; } 00039 // The non-indexed 'true' color depth that Qt supports, and 00040 // the number of bits in a Qrgb. This includes room for the 00041 // alpha channel (yay). FYI, component byte order in Qrgb 00042 // (most- to least-significant) is A-R-G-B. 00043 00044 virtual Display::ColorModel colorModel() const{ return Display::Index; } 00045 00046 00047 # define MAX_QTPCCT_SIZE 5000u 00048 // maximum color slots this colortable can hold (distributed 00049 // among its colormaps). Could be expanded a lot, but it's 00050 // probably unnecessary. 00051 00052 # define INITIAL_QTPCCT_SIZE 256u 00053 // Initial size of the colortable. 00054 00055 virtual uInt nColors() const { return size_; } 00056 // Current number of slots usable by colormaps. 00057 // can be expanded at runtime up to MAX_QTPCCT_SIZE. 00058 00059 virtual uInt nSpareColors() const { return MAX_QTPCCT_SIZE - size_; } 00060 00061 virtual Bool resize(uInt newSize); 00062 00063 // Called by corresp. ColormapManager to actually fill color slots 00064 // for the Colormaps. r,g,b ahould be in range [0,1]. 00065 virtual Bool installRGBColors(const Vector<Float> & r, 00066 const Vector<Float> & g, 00067 const Vector<Float> & b, 00068 uInt offset = 0); 00069 00070 // Translate Array of colormap indices into graphics platform's colors. 00071 00072 //# The version actually used... 00073 virtual void mapToColor(const Colormap * map, 00074 Array<uInt> & outArray, 00075 const Array<uInt> & inArray, 00076 Bool rangeCheck = True) const; 00077 00078 00079 //# The one of these really needed when/if non-Index (3-channel) 00080 // ColorModels are implemented for QtPixelCanvas. 00081 virtual void mapToColor3(Array<uLong> & /*out*/, 00082 const Array<uInt> & /*chan1in*/, 00083 const Array<uInt> & /*chan2in*/, 00084 const Array<uInt> & /*chan3in*/) { } 00085 00086 00087 //# irrelevant, unused versions: 00088 virtual void mapToColor(const Colormap * /*map*/, 00089 Array<uChar> & /*outArray*/, 00090 const Array<uChar> & /*inArray*/, 00091 Bool /*rangeCheck*/ = True) const { } 00092 00093 virtual void mapToColor(const Colormap * /*map*/, 00094 Array<uShort> & /*outArray*/, 00095 const Array<uShort> & /*inArray*/, 00096 Bool /*rangeCheck*/ = True) const { } 00097 00098 virtual void mapToColor(const Colormap * /*map*/, 00099 Array<uLong> & /*outArray*/, 00100 const Array<uLong> & /*inArray*/, 00101 Bool /*rangeCheck*/ = True) const { } 00102 00103 virtual void mapToColor(const Colormap * /*map*/, 00104 Array<uChar> & /*inOutArray*/, 00105 Bool /*rangeCheck*/ = True) const { } 00106 00107 virtual void mapToColor(const Colormap * /*map*/, 00108 Array<uShort> & /*inOutArray*/, 00109 Bool /*rangeCheck*/ = True) const { } 00110 00111 virtual void mapToColor(const Colormap * /*map*/, 00112 Array<uInt> & /*inOutArray*/, 00113 Bool /*rangeCheck*/ = True) const { } 00114 00115 virtual void mapToColor(const Colormap * /*map*/, 00116 Array<uLong> & /*inOutArray*/, 00117 Bool /*rangeCheck*/ = True) const { } 00118 00119 virtual void mapToColor3(Array<uLong> & /*out*/, 00120 const Array<Float> & /*chan1in*/, 00121 const Array<Float> & /*chan2in*/, 00122 const Array<Float> & /*chan3in*/) { } 00123 virtual void mapToColor3(Array<uLong> & /*out*/, 00124 const Array<Double> & /*chan1in*/, 00125 const Array<Double> & /*chan2in*/, 00126 const Array<Double> & /*chan3in*/) { } 00127 00128 virtual void mapToColor3(Array<uLong> & /*out*/, 00129 const Array<uShort> & /*chan1in*/, 00130 const Array<uShort> & /*chan2in*/, 00131 const Array<uShort> & /*chan3in*/) { } 00132 00133 virtual Bool colorSpaceMap(Display::ColorModel, 00134 const Array<Float> & /*chan1in*/, 00135 const Array<Float> & /*chan2in*/, 00136 const Array<Float> & /*chan3in*/, 00137 Array<Float> & /*chan1out*/, 00138 Array<Float> & /*chan2out*/, 00139 Array<Float> & /*chan3out*/) { return False; } 00140 // (could move X11 version down to base class and use 00141 // that -- it has no X11 dependencies...) 00142 00143 protected: 00144 00145 Int clrByte(Float f) { return Int(min( max(0.f,f)*256.f, 255.f )); } 00146 // translate color component in the range [0., 1.] 00147 // to clrByte, with 0 <= clrByte < 256 00148 00149 private: 00150 00151 Vector<uInt> maps_; 00152 // actual storage for the color slots. 00153 uInt size_; 00154 // Current size of the colortable; number of slots usable by colormaps. 00155 // can be expanded at runtime, up to MAX_QTPCCT_SIZE. 00156 00157 00158 }; 00159 00160 00161 } 00162 #endif