00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef TRIALDISPLAY_GLPIXELCANVASCOLORTABLE_H
00029 #define TRIALDISPLAY_GLPIXELCANVASCOLORTABLE_H
00030
00031 #include <casa/aips.h>
00032 #include <graphics/X11/X11Util.h>
00033
00034 #include <graphics/X11/X_enter.h>
00035 #include <X11/Xlib.h>
00036 #include <X11/Xutil.h>
00037 #include <graphics/X11/X_exit.h>
00038
00039 #include <casa/Arrays/Vector.h>
00040 #include <display/Display/DisplayEnums.h>
00041 #include <display/Display/PixelCanvasColorTable.h>
00042
00043
00044 namespace casa {
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 class GLVColorTableEntry {
00075 public:
00076 GLVColorTableEntry();
00077
00078 void operator=(const GLVColorTableEntry &);
00079
00080
00081 void put(const float red, const float green, const float blue) {
00082 red_ = red;
00083 green_ = green;
00084 blue_ = blue;
00085 }
00086
00087 void get(float &red, float &green, float &blue)const {
00088 red = red_;
00089 green = green_;
00090 blue = blue_;
00091 }
00092
00093 uInt getIndex()const {
00094 return index_;
00095 }
00096 void setIndex(const uInt i) {
00097 index_ = i;
00098 }
00099
00100 uLong getPixel()const {
00101 return pixel_;
00102 }
00103 void setPixel(const unsigned long p) {
00104 pixel_ = p;
00105 }
00106
00107 friend ostream &operator<<(ostream &s, const GLVColorTableEntry &x);
00108
00109 private:
00110 uInt index_;
00111 uLong pixel_;
00112 float red_, green_, blue_;
00113 };
00114
00115 class GLPixelCanvasColorTable : public PixelCanvasColorTable {
00116 public:
00117
00118
00119 GLPixelCanvasColorTable();
00120
00121 ~GLPixelCanvasColorTable();
00122
00123 GLPixelCanvasColorTable(::XDisplay *dpy,
00124 Display::ColorModel mapType = Display::RGB,
00125 Float percent=90.0,
00126 XVisualInfo *visInfo=NULL);
00127
00128
00129
00130 Bool allocCells(uInt nCells);
00131
00132
00133 Bool deallocCells();
00134
00135
00136 Bool allocColorCube();
00137
00138 Bool allocColorCube(uInt n1, uInt n2, uInt n3);
00139
00140 Bool allocColorCubeMinMax(uInt n1min, uInt n2min, uInt n3min,
00141 uInt n1max, uInt n2max, uInt n3max);
00142
00143 void copyColorCube(const GLPixelCanvasColorTable & mapRef);
00144
00145 void fillColorCubeRGB();
00146 enum FILLMODE {FILLRGB, FILLRBG, FILLGRB, FILLGBR, FILLBRG, FILLBGR};
00147 static void colorFillRGB(
00148 Vector<Float> &r, Vector<Float> &g, Vector<Float> &b,
00149 uInt nr, uInt ng, uInt nb,
00150 FILLMODE mode = FILLRGB);
00151
00152 static void colorFillRGB(
00153 Vector<Float> &r, Vector<Float> &g, Vector<Float> &b,
00154 uInt ncolors, FILLMODE mode= FILLRGB);
00155
00156 void fillColorCubeHSV();
00157
00158
00159
00160
00161
00162 void mapToColor3(Array<uLong> & out,
00163 const Array<Float> & chan1in,
00164 const Array<Float> & chan2in,
00165 const Array<Float> & chan3in);
00166 void mapToColor3(Array<uLong> & out,
00167 const Array<Double> & chan1in,
00168 const Array<Double> & chan2in,
00169 const Array<Double> & chan3in);
00170
00171
00172
00173
00174
00175
00176 void mapToColor3(Array<uLong> & out,
00177 const Array<uShort> & chan1in,
00178 const Array<uShort> & chan2in,
00179 const Array<uShort> & chan3in);
00180 void mapToColor3(Array<uLong> & out,
00181 const Array<uInt> & chan1in,
00182 const Array<uInt> & chan2in,
00183 const Array<uInt> & chan3in);
00184
00185
00186
00187
00188
00189
00190
00191 Bool colorSpaceMap(Display::ColorModel,
00192 const Array<Float> & chan1in,
00193 const Array<Float> & chan2in,
00194 const Array<Float> & chan3in,
00195 Array<Float> & chan1out,
00196 Array<Float> & chan2out,
00197 Array<Float> & chan3out);
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207 void mapToColor(const Colormap * map, Array<uChar> & outArray,
00208 const Array<uChar> & inArray, Bool rangeCheck = True) const;
00209 void mapToColor(const Colormap * map, Array<uShort> & outArray,
00210 const Array<uShort> & inArray, Bool rangeCheck = True) const;
00211 void mapToColor(const Colormap * map, Array<uInt> & outArray,
00212 const Array<uInt> & inArray, Bool rangeCheck = True) const;
00213 void mapToColor(const Colormap * map, Array<uLong> & outArray,
00214 const Array<uLong> & inArray, Bool rangeCheck = True) const;
00215
00216
00217
00218
00219
00220 void mapToColor(const Colormap * map, Array<uChar> & inOutArray,
00221 Bool rangeCheck = True) const;
00222 void mapToColor(const Colormap * map, Array<uShort> & inOutArray,
00223 Bool rangeCheck = True) const;
00224 void mapToColor(const Colormap * map, Array<uInt> & inOutArray,
00225 Bool rangeCheck = True) const;
00226 void mapToColor(const Colormap * map, Array<uLong> & inOutArray,
00227 Bool rangeCheck = True) const;
00228
00229
00230
00231 friend ostream & operator << (ostream & os, const GLPixelCanvasColorTable & pcc);
00232
00233
00234 virtual Bool staticSize() {
00235 return (readOnly_ && decomposedIndex_);
00236 }
00237
00238
00239
00240 Bool resize(uInt newSize);
00241 Bool resize(uInt nReds, uInt nGreens, uInt nBlues);
00242
00243
00244
00245
00246
00247
00248 Bool installRGBColors(const Vector<Float> & r, const Vector<Float> & g,
00249 const Vector<Float> & b, uInt offset = 0);
00250
00251
00252 uInt nColors() const;
00253
00254
00255
00256 virtual void nColors(uInt &n1, uInt &n2, uInt &n3) const;
00257
00258
00259 uInt depth() const;
00260
00261
00262 uInt nSpareColors() const;
00263
00264
00265 ::XDisplay * display() const;
00266
00267 Screen * screen() const;
00268
00269 Visual * visual() const;
00270
00271 XVisualInfo *visualInfo() const {
00272 return visualInfo_;
00273 }
00274
00275 XColormap xcmap() const;
00276
00277
00278 Bool indexMode() const {
00279 return (colorModel_ == Display::Index);
00280 }
00281
00282 Bool rgbMode() const {
00283 return (colorModel_ == Display::RGB);
00284 }
00285
00286 Bool hsvMode() const {
00287 return (colorModel_ == Display::HSV);
00288 }
00289
00290
00291 Bool rigid() const {
00292 return rigid_;
00293 }
00294
00295
00296 Display::ColorModel colorModel() const {
00297 return colorModel_;
00298 }
00299 Bool readOnly()const {
00300 return readOnly_;
00301 }
00302 Bool decomposedIndex()const {
00303 return decomposedIndex_;
00304 }
00305
00306 uInt QueryColorsAvailable(const Bool contig)const;
00307 virtual uInt QueryHWColorsAvailable(const Bool contig)const;
00308
00309 Bool virtualToPhysical(const unsigned long vindex,
00310 unsigned long &pindex)const;
00311
00312
00313 void storeColor(const uInt index,
00314 const float r, const float g, const float b);
00315
00316
00317
00318 void pixelToComponents(const uLong pixel, Float &r, Float &g, Float &b);
00319
00320 static XVisualInfo *getVisualInfo(::XDisplay *dpy,
00321 const Display::ColorModel colormodel);
00322
00323 void indexToRGB(const uInt index, float &r, float &g, float &b);
00324 private:
00325
00326
00327
00328 Bool isPow2(uInt n, uInt & log2n);
00329
00330
00331 void setupColorCube(uLong n1, uLong n2, uLong n3,
00332 uLong n1m, uLong n2m, uLong n3m);
00333
00334 void setupStandardMapping(const XStandardColormap * mapInfo);
00335
00336 Bool initVisual(XVisualInfo *vi=NULL);
00337
00338 ::XDisplay * display_;
00339
00340 Screen * screen_;
00341
00342 Visual * visual_;
00343 XVisualInfo *visualInfo_;
00344
00345 XColormap xcmap_;
00346
00347
00348 uInt depth_;
00349
00350 uInt nColors_;
00351
00352
00353 uLong * colors_;
00354 uShort vcmapLength_;
00355
00356 GLVColorTableEntry *vcmap_;
00357
00358
00359
00360
00361
00362 Bool rigid_;
00364
00365 Bool readOnly_;
00366
00367 Bool decomposedIndex_;
00368 void checkVisual();
00369
00370
00371 virtual void storeHWColor(const uLong pindex,
00372 const float r, const float g, const float b);
00373
00374
00375 unsigned short red_shift_, green_shift_, blue_shift_;
00376 unsigned short red_max_, green_max_, blue_max_;
00377 unsigned long red_mask_, green_mask_, blue_mask_;
00378
00379 void HSV2RGB(const uLong H, const uLong S, const uLong V,
00380 uLong &R, uLong &G, uLong &B);
00381 uInt HSV2Index(float h, float s, float v);
00382
00384
00385
00386
00387
00388
00389 Bool pow2Mapping_;
00390
00391
00392
00393
00394 Display::ColorModel colorModel_;
00395
00396
00397
00398
00399
00400 uLong baseColor_;
00401
00402
00403
00404
00405
00406
00407
00408 uInt n1_;
00409 uInt n2_;
00410 uInt n3_;
00411
00412 uInt n1Mult_;
00413 uInt n2Mult_;
00414 uInt n3Mult_;
00415
00416
00417
00418
00419
00420
00421
00422 uInt n1Shift_;
00423 uInt n2Shift_;
00424 uInt n3Shift_;
00425
00426 };
00427
00428
00429 }
00430 #ifndef AIPS_NO_TEMPLATE_SRC
00431 #include <display/Display/GLPCColTblTemplates.tcc>
00432 #endif
00433 #endif