QtPCColorTable.h

Go to the documentation of this file.
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() {
00032                         return True;
00033                 }
00034 
00035                 virtual Bool resize(uInt /*nReds*/, uInt /*nGreens*/, uInt /*nBlues*/) {
00036                         return False;
00037                 }
00038 
00039                 virtual void nColors(uInt &n1, uInt &n2, uInt &n3) const {
00040                         n1 = 256;
00041                         n2 = 256;
00042                         n3 = 256;
00043                 }
00044 
00045                 virtual uInt depth() const {
00046                         return 32;
00047                 }
00048                 // The non-indexed 'true' color depth that Qt supports, and
00049                 // the number of bits in a Qrgb.  This includes room for the
00050                 // alpha channel (yay).  FYI, component byte order in Qrgb
00051                 // (most- to least-significant) is A-R-G-B.
00052 
00053                 virtual Display::ColorModel colorModel() const {
00054                         return Display::Index;
00055                 }
00056 
00057 
00058 # define MAX_QTPCCT_SIZE 5000u
00059                 // maximum color slots this colortable can hold (distributed
00060                 // among its colormaps).  Could be expanded a lot, but it's
00061                 // probably unnecessary.
00062 
00063 # define INITIAL_QTPCCT_SIZE 256u
00064                 // Initial size of the colortable.
00065 
00066                 virtual uInt nColors() const {
00067                         return size_;
00068                 }
00069                 // Current number of slots usable by colormaps.
00070                 // can be expanded at runtime up to MAX_QTPCCT_SIZE.
00071 
00072                 virtual uInt nSpareColors() const {
00073                         return MAX_QTPCCT_SIZE - size_;
00074                 }
00075 
00076                 virtual Bool resize(uInt newSize);
00077 
00078                 // Called by corresp. ColormapManager to actually fill color slots
00079                 // for the Colormaps.  r,g,b ahould be in range [0,1].
00080                 virtual Bool installRGBColors(const Vector<Float> & r,
00081                                               const Vector<Float> & g,
00082                                               const Vector<Float> & b,
00083                                               const Vector<Float> & alpha,
00084                                               uInt offset = 0);
00085 
00086                 // Translate Array of colormap indices into graphics platform's colors.
00087 
00088                 //# The version actually used...
00089                 virtual void mapToColor(const Colormap * map,
00090                                         Array<uInt> & outArray,
00091                                         const Array<uInt> & inArray,
00092                                         Bool rangeCheck = True) const;
00093 
00094 
00095                 //# The one of these really needed when/if non-Index (3-channel)
00096                 //  ColorModels are implemented for QtPixelCanvas.
00097                 virtual void mapToColor3(Array<uLong> & /*out*/,
00098                                          const Array<uInt> & /*chan1in*/,
00099                                          const Array<uInt> & /*chan2in*/,
00100                                          const Array<uInt> & /*chan3in*/) {  }
00101 
00102 
00103                 //# irrelevant, unused versions:
00104                 virtual void mapToColor(const Colormap * /*map*/,
00105                                         Array<uChar> & /*outArray*/,
00106                                         const Array<uChar> & /*inArray*/,
00107                                         Bool /*rangeCheck*/ = True) const {  }
00108 
00109                 virtual void mapToColor(const Colormap * /*map*/,
00110                                         Array<uShort> & /*outArray*/,
00111                                         const Array<uShort> & /*inArray*/,
00112                                         Bool /*rangeCheck*/ = True) const {  }
00113 
00114                 virtual void mapToColor(const Colormap * /*map*/,
00115                                         Array<uLong> & /*outArray*/,
00116                                         const Array<uLong> & /*inArray*/,
00117                                         Bool /*rangeCheck*/ = True) const {  }
00118 
00119                 virtual void mapToColor(const Colormap * /*map*/,
00120                                         Array<uChar> & /*inOutArray*/,
00121                                         Bool /*rangeCheck*/ = True) const {  }
00122 
00123                 virtual void mapToColor(const Colormap * /*map*/,
00124                                         Array<uShort> & /*inOutArray*/,
00125                                         Bool /*rangeCheck*/ = True) const {  }
00126 
00127                 virtual void mapToColor(const Colormap * /*map*/,
00128                                         Array<uInt> & /*inOutArray*/,
00129                                         Bool /*rangeCheck*/ = True) const {  }
00130 
00131                 virtual void mapToColor(const Colormap * /*map*/,
00132                                         Array<uLong> & /*inOutArray*/,
00133                                         Bool /*rangeCheck*/ = True) const {  }
00134 
00135                 virtual void mapToColor3(Array<uLong> & /*out*/,
00136                                          const Array<Float> & /*chan1in*/,
00137                                          const Array<Float> & /*chan2in*/,
00138                                          const Array<Float> & /*chan3in*/) {  }
00139                 virtual void mapToColor3(Array<uLong> & /*out*/,
00140                                          const Array<Double> & /*chan1in*/,
00141                                          const Array<Double> & /*chan2in*/,
00142                                          const Array<Double> & /*chan3in*/) {  }
00143 
00144                 virtual void mapToColor3(Array<uLong> & /*out*/,
00145                                          const Array<uShort> & /*chan1in*/,
00146                                          const Array<uShort> & /*chan2in*/,
00147                                          const Array<uShort> & /*chan3in*/) {  }
00148 
00149                 virtual Bool colorSpaceMap(Display::ColorModel,
00150                                            const Array<Float> & /*chan1in*/,
00151                                            const Array<Float> & /*chan2in*/,
00152                                            const Array<Float> & /*chan3in*/,
00153                                            Array<Float> & /*chan1out*/,
00154                                            Array<Float> & /*chan2out*/,
00155                                            Array<Float> & /*chan3out*/) {
00156                         return False;
00157                 }
00158                 // (could move X11 version down to base class and use
00159                 // that -- it has no X11 dependencies...)
00160 
00161         protected:
00162 
00163                 Int clrByte(Float f) {
00164                         return Int(min( max(0.f,f)*256.f, 255.f ));
00165                 }
00166                 // translate color component in the range [0., 1.]
00167                 // to clrByte, with 0 <= clrByte < 256
00168 
00169         private:
00170 
00171                 Vector<uInt> maps_;
00172                 // actual storage for the color slots.
00173                 uInt size_;
00174                 // Current size of the colortable; number of slots usable by colormaps.
00175                 // can be expanded at runtime, up to MAX_QTPCCT_SIZE.
00176 
00177 
00178         };
00179 
00180 
00181 }
00182 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1