TAttImage.cxx

Go to the documentation of this file.
00001 // @(#)root/graf:$Id: TAttImage.cxx 31637 2009-12-08 10:41:23Z couet $
00002 // Author: Reiner Rohlfs   24/03/02
00003 
00004 /*************************************************************************
00005  * Copyright (C) 2001-2001, Rene Brun, Fons Rademakers and Reiner Rohlfs *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 //////////////////////////////////////////////////////////////////////////
00013 //                                                                      //
00014 //  TAttImage                                                           //
00015 //                                                                      //
00016 //  Image attributes are:                                               //
00017 //    Image Quality (see EImageQuality for the list of qualities)       //
00018 //    Compression defines the compression rate of the color data in the //
00019 //                internal image structure. Speed and memory depends    //
00020 //                on this rate, but not the image display itself        //
00021 //                0: no compression;  100: max compression              //
00022 //    Radio Flag: kTRUE  the x/y radio of the displayed image is always //
00023 //                       identical to the original image                //
00024 //                kFALSE the x and y size of the displayed image depends//
00025 //                       on the size of the pad                         //
00026 //    Palette:    Defines the conversion from a pixel value to the      //
00027 //                screen color                                          //
00028 //                                                                      //
00029 //  This class is used (in general by secondary inheritance)            //
00030 //  by some other classes (image display).                              //
00031 //                                                                      //
00032 //                                                                      //
00033 //  TImagePalette                                                       //
00034 //                                                                      //
00035 //  A class to define a conversion from pixel values to pixel color.    //
00036 //  A Palette is defined by some anchor points. Each anchor point has   //
00037 //  a value between 0 and 1 and a color. An image has to be normalized  //
00038 //  and the values between the anchor points are interpolated.          //
00039 //  All member variables are public and can be directly manipulated.    //
00040 //  In most cases the default operator will be used to create a         //
00041 //  TImagePalette. In this case the member arrays have to be allocated  //
00042 //  by an application and will be deleted in the destructor of this     //
00043 //  class.                                                              //
00044 //                                                                      //
00045 //  We provide few predifined palettes:                                 //
00046 //                                                                      //
00047 //    o gHistImagePalette - palette used in TH2::Draw("col")            //
00048 //                                                                      //
00049 //    o gWebImagePalette                                                //
00050 //       The web palette is a set of 216 colors that will not dither or //
00051 //       shift on PCs or Macs. Browsers use this built-in palette when  //
00052 //       they need to render colors on monitors with only 256 colors    //
00053 //       (also called 8-bit color monitors).                            //
00054 //       The 6x6x6 web palette provides very quick color index lookup   //
00055 //       and can be used for good quality convertion of images into     //
00056 //       2-D histograms.                                                //
00057 //                                                                      //
00058 //    o  TImagePalette(Int_t ncolors, Int_t *colors)                    //
00059 //        if ncolors <= 0 a default palette (see below) of 50 colors    //
00060 //        is defined.                                                   //
00061 //                                                                      //   
00062 //        if ncolors == 1 && colors == 0, then                          //
00063 //        a Pretty Palette with a Spectrum Violet->Red is created.      //
00064 //                                                                      //
00065 //        if ncolors > 50 and colors=0, the DeepSea palette is used.    //
00066 //         (see TStyle::CreateGradientColorTable for more details)      //
00067 //                                                                      //
00068 //        if ncolors > 0 and colors = 0, the default palette is used    //
00069 //        with a maximum of ncolors.                                    //
00070 //                                                                      //
00071 // The default palette defines:                                         //
00072 //   index 0->9   : grey colors from light to dark grey                 //
00073 //   index 10->19 : "brown" colors                                      //
00074 //   index 20->29 : "blueish" colors                                    //
00075 //   index 30->39 : "redish" colors                                     //
00076 //   index 40->49 : basic colors                                        //
00077 //                                                                      //
00078 //                                                                      //
00079 //  TPaletteEditor                                                      //
00080 //                                                                      //
00081 //  This class provides a way to edit the palette via a GUI.            //
00082 //                                                                      //
00083 //////////////////////////////////////////////////////////////////////////
00084 
00085 #include "TAttImage.h"
00086 #include "TROOT.h"
00087 #include "TPluginManager.h"
00088 #include "Riostream.h"
00089 #include "TColor.h"
00090 #include "TMath.h"
00091 
00092 
00093 ClassImp(TPaletteEditor)
00094 ClassImp(TAttImage)
00095 ClassImp(TImagePalette)
00096 
00097 
00098 // definition of a default palette
00099 const Int_t kNUM_DEFAULT_COLORS = 12;
00100 static UShort_t gAlphaDefault[kNUM_DEFAULT_COLORS] = {
00101    0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
00102    0xffff, 0xffff, 0xffff, 0xffff
00103 };
00104 
00105 static UShort_t gRedDefault[kNUM_DEFAULT_COLORS] = {
00106    0x0000, 0x0000, 0x7000, 0x0000, 0x0000, 0x0000, 0xffff, 0xffff,
00107    0x7000, 0x8000, 0xffff, 0xffff
00108 };
00109 
00110 static UShort_t gGreenDefault[kNUM_DEFAULT_COLORS] = {
00111    0x0000, 0x0000, 0x0000, 0x0000, 0xffff, 0xffff, 0xffff, 0x0000,
00112    0x0000, 0x8000, 0xffff, 0xffff
00113 };
00114 
00115 static UShort_t gBlueDefault[kNUM_DEFAULT_COLORS] = {
00116    0x0000, 0x0000, 0x7000, 0xffff, 0xffff, 0x0000, 0x0000, 0x0000,
00117    0x0000, 0xa000, 0xffff, 0xffff
00118 };
00119 
00120 
00121 //////////////////////////// Web Palette ////////////////////////////////////
00122 static UShort_t gWebBase[6] = { 0, 51, 102, 153, 204, 255 };
00123 
00124 class TWebPalette : public TImagePalette {
00125 
00126 private:
00127    Int_t fCLUT[6][6][6];   // Color LookUp Table
00128 
00129 public:
00130    TWebPalette() : TImagePalette() {
00131       int i = 0;
00132       fNumPoints = 216;
00133       fPoints = new Double_t[216];
00134       fColorRed = new UShort_t[216];
00135       fColorBlue = new UShort_t[216];
00136       fColorGreen = new UShort_t[216];
00137       fColorAlpha = new UShort_t[216];
00138 
00139       for (i = 0; i < 214; i++) {
00140          fPoints[i + 1]  =  (double)i/213;
00141       }
00142       fPoints[0] = 0;
00143       fPoints[215] = 1;
00144 
00145       i = 0;
00146       for (int r = 0; r < 6; r++) {
00147          for (int g = 0; g < 6; g++) {
00148             for (int b = 0; b < 6; b++) {
00149                fColorRed[i] = gWebBase[r] << 8;
00150                fColorGreen[i] = gWebBase[g] << 8;
00151                fColorBlue[i] = gWebBase[b] << 8;
00152                fColorAlpha[i] = 0xffff;
00153                fCLUT[r][g][b] = i;
00154                i++;
00155             }
00156          }
00157       }
00158    }
00159 
00160    Int_t FindColor(UShort_t r, UShort_t g, UShort_t b) {
00161       Int_t ri = TMath:: BinarySearch(6, (const Short_t*)gWebBase, (Short_t)r);
00162       Int_t gi = TMath:: BinarySearch(6, (const Short_t*)gWebBase, (Short_t)g);
00163       Int_t bi = TMath:: BinarySearch(6, (const Short_t*)gWebBase, (Short_t)b);
00164       return fCLUT[ri][gi][bi];
00165    }
00166 
00167    Int_t *GetRootColors() {
00168       static Int_t *gRootColors = 0;
00169       if (gRootColors) return gRootColors;
00170 
00171       gRootColors = new Int_t[216];
00172 
00173       int i = 0;
00174       for (int r = 0; r < 6; r++) {
00175          for (int g = 0; g < 6; g++) {
00176             for (int b = 0; b < 6; b++) {
00177                gRootColors[i] = TColor::GetColor(gWebBase[r], gWebBase[g], gWebBase[b]);
00178                i++;
00179             }
00180          }
00181       }
00182       return gRootColors;
00183    }
00184 };
00185 
00186 TImagePalette *gWebImagePalette = new TWebPalette();
00187 
00188 
00189 ////////////////////////////// Hist Palette ////////////////////////////////////
00190 static Double_t gDefHistP[50] =  {
00191       0.00,0.02,0.04,0.06,0.08,0.10,0.12,0.14,0.16,0.18,0.20,0.22,0.24,0.26,
00192       0.28,0.30,0.32,0.34,0.36,0.38,0.40,0.42,0.44,0.46,0.48,0.50,0.52,0.54,
00193       0.56,0.58,0.60,0.62,0.64,0.66,0.68,0.70,0.72,0.74,0.76,0.78,0.80,0.82,
00194       0.84,0.86,0.88,0.90,0.92,0.94,0.96,0.98 };
00195 
00196 static UShort_t gDefHistR[50] = {
00197       242,229,204,178,153,127,102,76,192,204,204,193,186,178,183,173,155,135,
00198       175,132,89,137,130,173,122, 117,104,109,124,127,170,89,211,221,188,198,
00199       191,170,165,147,206,211,255,0,255,255,0,0,53,0 };
00200 
00201 static UShort_t gDefHistG[50] = {
00202       242,229,204,178,153,127,102,76,182,198,198,191,181,165,163,153,142,102,
00203       206,193,211,168,158,188,142,137,130,122,153,127,165,84,206,186,158,153,
00204       130,142,119,104,94,89,0,255,0,255,0,255,53,0 };
00205 
00206 static UShort_t gDefHistB[50] = {
00207       242,229,204,178,153,127,102,76,172,170,170,168,163,150,155,140,130,86,
00208       198,163,84,160,140,198,153,145,150,132,209,155,191,216,135,135,130,124,
00209       119,147,122,112,96,84,0,255,255,0,255,0,53,0 };
00210 
00211 static UShort_t gDefHistA[50] = {
00212       255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
00213       255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
00214       255,255,255,255,255,255,255,255,255,255,255,255,255,255 };
00215 
00216 static Int_t gDefHistRoot[50] = {
00217       19,18,17,16,15,14,13,12,11,20,21,22,23,24,25,26,27,28,29,30, 8,
00218       31,32,33,34,35,36,37,38,39,40, 9, 41,42,43,44,45,47,48,49,46,50, 2,
00219       7, 6, 5, 4, 3, 112,1};
00220 
00221 
00222 class TDefHistImagePalette : public TImagePalette {
00223 
00224 public:
00225    TDefHistImagePalette() : TImagePalette() {
00226       fNumPoints = 50;
00227       fPoints = gDefHistP;
00228       fColorRed = gDefHistR;
00229       fColorGreen = gDefHistG;
00230       fColorBlue = gDefHistB;
00231       fColorAlpha = gDefHistA;
00232 
00233       for (int i = 0; i<50; i++) {
00234          fColorRed[i] = fColorRed[i] << 8;
00235          fColorGreen[i] = fColorGreen[i] << 8;
00236          fColorBlue[i] = fColorBlue[i] << 8;
00237          fColorAlpha[i] = fColorAlpha[i] << 8;
00238       }
00239    }
00240 
00241    Int_t *GetRootColors() { return gDefHistRoot; }
00242 };
00243 
00244 TImagePalette *gHistImagePalette = new TDefHistImagePalette();
00245 
00246 
00247 ///////////////////////////////////////////////////////////////////////////////
00248 //______________________________________________________________________________
00249 TPaletteEditor::TPaletteEditor(TAttImage *attImage, UInt_t, UInt_t)
00250 {
00251    // Constructor.
00252 
00253    fAttImage = attImage;
00254 }
00255 
00256 //______________________________________________________________________________
00257 void TPaletteEditor::CloseWindow()
00258 {
00259    // Closes the window and deletes itself.
00260 
00261    fAttImage->EditorClosed();
00262 }
00263 
00264 
00265 //______________________________________________________________________________
00266 TImagePalette::TImagePalette()
00267 {
00268    // Default constructor, sets all pointers to 0.
00269 
00270    fNumPoints     = 0;
00271    fPoints        = 0;
00272    fColorRed      = 0;
00273    fColorGreen    = 0;
00274    fColorBlue     = 0;
00275    fColorAlpha    = 0;
00276 }
00277 
00278 //______________________________________________________________________________
00279 TImagePalette::TImagePalette(UInt_t numPoints)
00280 {
00281    // Constructor for a palette with numPoints anchor points.
00282    // It allocates the memory but does not set any colors.
00283 
00284    fNumPoints  = numPoints;
00285    fPoints     = new Double_t[fNumPoints];
00286    fColorRed   = new UShort_t[fNumPoints];
00287    fColorGreen = new UShort_t[fNumPoints];
00288    fColorBlue  = new UShort_t[fNumPoints];
00289    fColorAlpha = new UShort_t[fNumPoints];
00290 }
00291 
00292 //______________________________________________________________________________
00293 TImagePalette::TImagePalette(const TImagePalette &palette) : TObject(palette)
00294 {
00295    // Copy constructor.
00296 
00297    fNumPoints = palette.fNumPoints;
00298 
00299    fPoints = new Double_t[fNumPoints];
00300    memcpy(fPoints, palette.fPoints, fNumPoints * sizeof(Double_t));
00301 
00302    fColorRed   = new UShort_t[fNumPoints];
00303    fColorGreen = new UShort_t[fNumPoints];
00304    fColorBlue  = new UShort_t[fNumPoints];
00305    fColorAlpha = new UShort_t[fNumPoints];
00306    memcpy(fColorRed,   palette.fColorRed,   fNumPoints * sizeof(UShort_t));
00307    memcpy(fColorGreen, palette.fColorGreen, fNumPoints * sizeof(UShort_t));
00308    memcpy(fColorBlue,  palette.fColorBlue,  fNumPoints * sizeof(UShort_t));
00309    memcpy(fColorAlpha, palette.fColorAlpha, fNumPoints * sizeof(UShort_t));
00310 }
00311 
00312 //______________________________________________________________________________
00313 TImagePalette::TImagePalette(Int_t ncolors, Int_t *colors)
00314 {
00315    // Creates palette in the same way as TStyle::SetPalette
00316 
00317    fNumPoints  = 0;
00318    fPoints     = 0;
00319    fColorRed   = 0;
00320    fColorGreen = 0;
00321    fColorBlue  = 0;
00322    fColorAlpha = 0;
00323 
00324    Int_t i;
00325    static Int_t palette[50] = {19,18,17,16,15,14,13,12,11,20,
00326                         21,22,23,24,25,26,27,28,29,30, 8,
00327                         31,32,33,34,35,36,37,38,39,40, 9,
00328                         41,42,43,44,45,47,48,49,46,50, 2,
00329                          7, 6, 5, 4, 3, 112,1};
00330    TColor *col = 0;
00331    Float_t step = 0;
00332    // set default palette (pad type)
00333    if (ncolors <= 0) {
00334       ncolors = 50;
00335       fNumPoints  = ncolors;
00336       step = 1./fNumPoints;
00337       fPoints     = new Double_t[fNumPoints];
00338       fColorRed   = new UShort_t[fNumPoints];
00339       fColorGreen = new UShort_t[fNumPoints];
00340       fColorBlue  = new UShort_t[fNumPoints];
00341       fColorAlpha = new UShort_t[fNumPoints];
00342       for (i=0;i<ncolors;i++) {
00343          col = gROOT->GetColor(palette[i]);
00344          fPoints[i] = i*step;
00345          fColorRed[i] = UShort_t(col->GetRed()*255)  << 8;
00346          fColorGreen[i] = UShort_t(col->GetGreen()*255) << 8;
00347          fColorBlue[i] = UShort_t(col->GetBlue()*255) << 8;
00348          fColorAlpha[i] = 65280;
00349       }
00350       return;
00351    }
00352 
00353    // set Pretty Palette Spectrum Violet->Red
00354    if (ncolors == 1 && colors == 0) {
00355       ncolors = 50;
00356       fNumPoints  = ncolors;
00357       step = 1./fNumPoints;
00358       fPoints     = new Double_t[fNumPoints];
00359       fColorRed   = new UShort_t[fNumPoints];
00360       fColorGreen = new UShort_t[fNumPoints];
00361       fColorBlue  = new UShort_t[fNumPoints];
00362       fColorAlpha = new UShort_t[fNumPoints];
00363 
00364       // 0 point is white
00365       fPoints[0] = 0;
00366       fColorRed[0] = 255 << 8;
00367       fColorGreen[0] = 255 << 8;
00368       fColorBlue[0] = 255 << 8;
00369       fColorAlpha[0] = 0;
00370 
00371       for (i=1;i<ncolors;i++) {
00372          col = gROOT->GetColor(51+i);
00373          fPoints[i] = i*step;
00374          fColorRed[i] = UShort_t(col->GetRed()*255) << 8;
00375          fColorGreen[i] = UShort_t(col->GetGreen()*255) << 8;
00376          fColorBlue[i] = UShort_t(col->GetBlue()*255) << 8;
00377          fColorAlpha[i] = 65280;
00378       }
00379       return;
00380    }
00381 
00382    // set DeepSea palette
00383    if (colors == 0 && ncolors > 50) {
00384       static const Int_t nRGBs = 5;
00385       static Float_t stops[nRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
00386       static Float_t red[nRGBs] = { 0.00, 0.09, 0.18, 0.09, 0.00 };
00387       static Float_t green[nRGBs] = { 0.01, 0.02, 0.39, 0.68, 0.97 };
00388       static Float_t blue[nRGBs] = { 0.17, 0.39, 0.62, 0.79, 0.97 };
00389       fNumPoints = nRGBs;
00390       fPoints     = new Double_t[fNumPoints];
00391       fColorRed   = new UShort_t[fNumPoints];
00392       fColorGreen = new UShort_t[fNumPoints];
00393       fColorBlue  = new UShort_t[fNumPoints];
00394       fColorAlpha = new UShort_t[fNumPoints];
00395       for (i=0;i<(int)fNumPoints;i++) {
00396          fPoints[i] = stops[i];
00397          fColorRed[i] = UShort_t(red[i]*255) << 8;
00398          fColorGreen[i] = UShort_t(green[i]*255) << 8;
00399          fColorBlue[i] = UShort_t(blue[i]*255) << 8;
00400          fColorAlpha[i] = 65280;   
00401       }
00402       return;
00403    }
00404 
00405    // set user defined palette
00406    if (colors)  {
00407       fNumPoints  = ncolors;
00408       step = 1./fNumPoints;
00409       fPoints     = new Double_t[fNumPoints];
00410       fColorRed   = new UShort_t[fNumPoints];
00411       fColorGreen = new UShort_t[fNumPoints];
00412       fColorBlue  = new UShort_t[fNumPoints];
00413       fColorAlpha = new UShort_t[fNumPoints];
00414       for (i=0;i<ncolors;i++) {
00415          fPoints[i] = i*step;
00416          col = gROOT->GetColor(colors[i]);
00417          if (col) {
00418             fColorRed[i] = UShort_t(col->GetRed()*255) << 8;
00419             fColorGreen[i] = UShort_t(col->GetGreen()*255) << 8;
00420             fColorBlue[i] = UShort_t(col->GetBlue()*255) << 8;
00421             fColorAlpha[i] = 65280;
00422          } else {
00423             fColorRed[i] = 0;
00424             fColorGreen[i] = 0;
00425             fColorBlue[i] = 0;
00426             fColorAlpha[i] = 0;
00427          }
00428       }
00429    }
00430 }
00431 
00432 //______________________________________________________________________________
00433 TImagePalette::~TImagePalette()
00434 {
00435    // Destructor.
00436 
00437    delete [] fPoints;
00438    delete [] fColorRed;
00439    delete [] fColorGreen;
00440    delete [] fColorBlue;
00441    delete [] fColorAlpha;
00442 }
00443 
00444 //______________________________________________________________________________
00445 TImagePalette &TImagePalette::operator=(const TImagePalette &palette)
00446 {
00447    // Assignment operator.
00448 
00449    if (this != &palette) {
00450       fNumPoints = palette.fNumPoints;
00451 
00452       delete [] fPoints;
00453       fPoints = new Double_t[fNumPoints];
00454       memcpy(fPoints, palette.fPoints, fNumPoints * sizeof(Double_t));
00455 
00456       delete [] fColorRed;
00457       fColorRed = new UShort_t[fNumPoints];
00458       memcpy(fColorRed, palette.fColorRed, fNumPoints * sizeof(UShort_t));
00459 
00460       delete [] fColorGreen;
00461       fColorGreen = new UShort_t[fNumPoints];
00462       memcpy(fColorGreen, palette.fColorGreen, fNumPoints * sizeof(UShort_t));
00463 
00464       delete [] fColorBlue;
00465       fColorBlue = new UShort_t[fNumPoints];
00466       memcpy(fColorBlue, palette.fColorBlue, fNumPoints * sizeof(UShort_t));
00467 
00468       delete [] fColorAlpha;
00469       fColorAlpha = new UShort_t[fNumPoints];
00470       memcpy(fColorAlpha, palette.fColorAlpha, fNumPoints * sizeof(UShort_t));
00471    }
00472 
00473    return *this;
00474 }
00475 
00476 //______________________________________________________________________________
00477 Int_t TImagePalette::FindColor(UShort_t r, UShort_t g, UShort_t b)
00478 {
00479    // returns an index of the closest color
00480 
00481    Int_t ret = 0;
00482    UInt_t d = 10000;
00483    UInt_t min = 10000;
00484 
00485    for (UInt_t i = 0; i < fNumPoints; i++) {
00486       d = TMath::Abs(r - ((fColorRed[i] & 0xff00) >> 8)) +
00487           TMath::Abs(g - ((fColorGreen[i] & 0xff00) >> 8)) +
00488           TMath::Abs(b - ((fColorBlue[i] & 0xff00) >> 8));
00489       if (d < min) {
00490          min = d;
00491          ret = i;
00492       }
00493    }
00494    return ret;
00495 }
00496 
00497 //______________________________________________________________________________
00498 Int_t *TImagePalette::GetRootColors()
00499 {
00500    // Returns a list of ROOT colors. Could be used to set histogram palette.
00501    // See also http://root.cern.ch/root/htmldoc/TStyle.html#TStyle:SetPalette
00502 
00503    static Int_t *gRootColors = 0;
00504    if (gRootColors) return gRootColors;
00505 
00506    gRootColors = new Int_t[fNumPoints];
00507 
00508    for (UInt_t i = 0; i < fNumPoints; i++) {
00509       gRootColors[i] = TColor::GetColor(fColorRed[i], fColorGreen[i], fColorBlue[i]);
00510    }
00511    return gRootColors;
00512 }
00513 
00514 
00515 //______________________________________________________________________________
00516 TAttImage::TAttImage()
00517 {
00518    // TAttImage default constructor.
00519    // Calls ResetAttImage to set the attributes to a default state.
00520 
00521    ResetAttImage();
00522    fPaletteEditor = 0;
00523    fPaletteEnabled = kTRUE;
00524 }
00525 
00526 //______________________________________________________________________________
00527 TAttImage::TAttImage(EImageQuality lquality, UInt_t lcompression,
00528                      Bool_t constRatio)
00529 {
00530    // TAttImage normal constructor.
00531    // Image attributes are taken from the argument list
00532    //    qualtity     : must be one of EImageQuality (kImgDefault is same as
00533    //                   kImgGood in the current implementation)
00534    //    lcompression : defines the compression rate of the color data in the
00535    //                   image. Speed and memory depends on this rate, but not
00536    //                   the image display itself
00537    //                   0: no compression;  100: max compression
00538    //    constRatio   : keeps the aspect ratio of the image constant on the
00539    //                   screen (in pixel units)
00540 
00541    ResetAttImage();
00542 
00543    fImageQuality = lquality;
00544    fImageCompression = (lcompression > 100) ? 100 : lcompression;
00545    fConstRatio = constRatio;
00546    fPaletteEditor = 0;
00547    fPaletteEnabled = kTRUE;
00548 }
00549 
00550 //______________________________________________________________________________
00551 TAttImage::~TAttImage()
00552 {
00553    // TAttImage destructor.
00554 
00555    delete fPaletteEditor;
00556 }
00557 
00558 //______________________________________________________________________________
00559 void TAttImage::Copy(TAttImage &attimage) const
00560 {
00561    // Copy this image attributes to a new attimage.
00562 
00563    attimage.fImageQuality     = fImageQuality;
00564    attimage.fImageCompression = fImageCompression;
00565    attimage.fConstRatio       = fConstRatio;
00566    attimage.fPalette          = fPalette;
00567 }
00568 
00569 //______________________________________________________________________________
00570 void TAttImage::ResetAttImage(Option_t *)
00571 {
00572    // Reset this image attributes to default values.
00573    // Default values are:
00574    //    quality:     kImgPoor, (no smoothing while the image is zoomed)
00575    //    compression: 0 (no compression)
00576    //    constRatio:  kTRUE
00577    //    palette:     a default rainbow palette
00578 
00579    fImageQuality      = kImgPoor;
00580    fImageCompression  = 0;
00581    fConstRatio        = kTRUE;
00582 
00583    // set the default palette
00584    delete [] fPalette.fPoints;
00585    delete [] fPalette.fColorRed;
00586    delete [] fPalette.fColorGreen;
00587    delete [] fPalette.fColorBlue;
00588    delete [] fPalette.fColorAlpha;
00589 
00590    fPalette.fNumPoints = kNUM_DEFAULT_COLORS;
00591 
00592    fPalette.fColorRed    = new UShort_t [kNUM_DEFAULT_COLORS];
00593    fPalette.fColorGreen  = new UShort_t [kNUM_DEFAULT_COLORS];
00594    fPalette.fColorBlue   = new UShort_t [kNUM_DEFAULT_COLORS];
00595    fPalette.fColorAlpha  = new UShort_t [kNUM_DEFAULT_COLORS];
00596    fPalette.fPoints      = new Double_t [kNUM_DEFAULT_COLORS];
00597 
00598    memcpy(fPalette.fColorRed,   gRedDefault,   kNUM_DEFAULT_COLORS * sizeof(UShort_t));
00599    memcpy(fPalette.fColorGreen, gGreenDefault, kNUM_DEFAULT_COLORS * sizeof(UShort_t));
00600    memcpy(fPalette.fColorBlue,  gBlueDefault,  kNUM_DEFAULT_COLORS * sizeof(UShort_t));
00601    memcpy(fPalette.fColorAlpha, gAlphaDefault, kNUM_DEFAULT_COLORS * sizeof(UShort_t));
00602 
00603    for (Int_t point = 0; point < kNUM_DEFAULT_COLORS - 2; point++)
00604       fPalette.fPoints[point + 1]  =  (double)point / (kNUM_DEFAULT_COLORS - 3);
00605    fPalette.fPoints[0] = 0;
00606    fPalette.fPoints[kNUM_DEFAULT_COLORS - 1] = 1;
00607 }
00608 
00609 //______________________________________________________________________________
00610 void TAttImage::SaveImageAttributes(ostream &out, const char *name,
00611                                     EImageQuality qualdef,
00612                                     UInt_t comprdef, Bool_t constRatiodef)
00613 {
00614    // Save image attributes as C++ statement(s) on output stream, but
00615    // not the palette.
00616 
00617    if (fImageQuality != qualdef) {
00618       out<<"   "<<name<<"->SetImageQuality("<<fImageQuality<<");"<<endl;
00619    }
00620    if (fImageCompression != comprdef) {
00621       out<<"   "<<name<<"->SetImageCompression("<<fImageCompression<<");"<<endl;
00622    }
00623    if (fConstRatio != constRatiodef) {
00624       out<<"   "<<name<<"->SetConstRatio("<<fConstRatio<<");"<<endl;
00625    }
00626 }
00627 
00628 //______________________________________________________________________________
00629 void TAttImage::SetConstRatio(Bool_t constRatio)
00630 {
00631    // Set (constRatio = kTRUE) or unset (constRadio = kFALSE) the ratio flag.
00632    // The aspect ratio of the image on the screen is constant if the ratio
00633    // flag is set. That means one image pixel is allways a square on the screen
00634    // independent of the pad size and of the size of the zoomed area.
00635 
00636    fConstRatio = constRatio;
00637 }
00638 
00639 //______________________________________________________________________________
00640 void TAttImage::SetPalette(const TImagePalette *palette)
00641 {
00642    // Set a new palette for the image. If palette == 0 a default
00643    // rainbow color palette is used.
00644 
00645    if (palette)
00646       fPalette = *palette;
00647    else {
00648       // set default palette
00649 
00650       delete [] fPalette.fPoints;
00651       delete [] fPalette.fColorRed;
00652       delete [] fPalette.fColorGreen;
00653       delete [] fPalette.fColorBlue;
00654       delete [] fPalette.fColorAlpha;
00655 
00656       fPalette.fNumPoints = kNUM_DEFAULT_COLORS;
00657 
00658       fPalette.fColorRed    = new UShort_t [kNUM_DEFAULT_COLORS];
00659       fPalette.fColorGreen  = new UShort_t [kNUM_DEFAULT_COLORS];
00660       fPalette.fColorBlue   = new UShort_t [kNUM_DEFAULT_COLORS];
00661       fPalette.fColorAlpha  = new UShort_t [kNUM_DEFAULT_COLORS];
00662       fPalette.fPoints      = new Double_t [kNUM_DEFAULT_COLORS];
00663 
00664       memcpy(fPalette.fColorRed,   gRedDefault,   kNUM_DEFAULT_COLORS * sizeof(UShort_t));
00665       memcpy(fPalette.fColorGreen, gGreenDefault, kNUM_DEFAULT_COLORS * sizeof(UShort_t));
00666       memcpy(fPalette.fColorBlue,  gBlueDefault,  kNUM_DEFAULT_COLORS * sizeof(UShort_t));
00667       memcpy(fPalette.fColorAlpha, gAlphaDefault, kNUM_DEFAULT_COLORS * sizeof(UShort_t));
00668 
00669       for (Int_t point = 0; point < kNUM_DEFAULT_COLORS - 2; point++)
00670          fPalette.fPoints[point + 1]  =  (double)point / (kNUM_DEFAULT_COLORS - 3);
00671       fPalette.fPoints[0] = 0;
00672       fPalette.fPoints[kNUM_DEFAULT_COLORS - 1] = 1;
00673    }
00674 }
00675 
00676 //______________________________________________________________________________
00677 void TAttImage::StartPaletteEditor()
00678 {
00679    // Opens a GUI to edit the color palette.
00680 
00681    if (fPaletteEditor == 0) {
00682       TPluginHandler *h;
00683 
00684       if ((h = gROOT->GetPluginManager()->FindHandler("TPaletteEditor"))) {
00685          if (h->LoadPlugin() == -1)
00686             return;
00687          fPaletteEditor = (TPaletteEditor *) h->ExecPlugin(3, this, 80, 25);
00688       }
00689    }
00690 }

Generated on Tue Jul 5 14:14:27 2011 for ROOT_528-00b_version by  doxygen 1.5.1