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
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
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
00075
00076
00077
00078
00079
00080
00081
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
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
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];
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
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
00252
00253 fAttImage = attImage;
00254 }
00255
00256
00257 void TPaletteEditor::CloseWindow()
00258 {
00259
00260
00261 fAttImage->EditorClosed();
00262 }
00263
00264
00265
00266 TImagePalette::TImagePalette()
00267 {
00268
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
00282
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
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
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
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
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
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
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
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
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
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
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
00501
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
00519
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
00531
00532
00533
00534
00535
00536
00537
00538
00539
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
00554
00555 delete fPaletteEditor;
00556 }
00557
00558
00559 void TAttImage::Copy(TAttImage &attimage) const
00560 {
00561
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
00573
00574
00575
00576
00577
00578
00579 fImageQuality = kImgPoor;
00580 fImageCompression = 0;
00581 fConstRatio = kTRUE;
00582
00583
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
00615
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
00632
00633
00634
00635
00636 fConstRatio = constRatio;
00637 }
00638
00639
00640 void TAttImage::SetPalette(const TImagePalette *palette)
00641 {
00642
00643
00644
00645 if (palette)
00646 fPalette = *palette;
00647 else {
00648
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
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 }