33 #include "RConfigure.h"
36 # define X_DISPLAY_MISSING 1
40 #include "Windows4root.h"
44 # include <afterbase.h>
46 # include <win32/config.h>
47 # include <win32/afterbase.h>
49 # include <afterimage.h>
55 static const char *gFileTypes[] = {
56 "ROOT palette file",
"*.pal.root",
57 "ASCII palette file",
"*.pal.txt",
61 static UShort_t gRedRainbow[12] = {
62 0x0000, 0x7000, 0x0000, 0x0000, 0x0000,
63 0xffff, 0xffff, 0x7000, 0x8000, 0xffff
65 static UShort_t gGreenRainbow[12] = {
66 0x0000, 0x0000, 0x0000, 0xffff, 0xffff,
67 0xffff, 0x0000, 0x0000, 0x8000, 0xffff
69 static UShort_t gBlueRainbow[12] = {
70 0x0000, 0x7000, 0xffff, 0xffff, 0x0000,
71 0x0000, 0x0000, 0x0000, 0xa000, 0xffff
75 ClassImp(TASPaletteEditor);
81 TASPaletteEditor::TASPaletteEditor(TAttImage *attImage, UInt_t w, UInt_t h)
82 : TPaletteEditor(attImage, w, h), TGMainFrame(0, w, h)
84 SetLayoutManager(
new TGXYLayout(
this));
91 fPaletteList =
new TList;
92 fPaletteList->SetOwner();
94 fPalette =
new TImagePalette(attImage->GetPalette());
95 fPaletteList->Add(fPalette);
100 button =
new TGTextButton(
this,
"&Apply", 1);
101 button->SetToolTipText(
"Apply the palette to the image");
102 AddFrame(button,
new TGXYLayoutHints(70, 1, 8, 1.8));
104 button =
new TGTextButton(
this,
"&Ok", 2);
105 button->SetToolTipText(
"Same as Apply and Cancel button");
106 AddFrame(button,
new TGXYLayoutHints(70, 3, 8, 1.8));
108 button =
new TGTextButton(
this,
"&Cancel", 3);
109 button->SetToolTipText(
"Close this window");
110 AddFrame(button,
new TGXYLayoutHints(70, 5, 8, 1.8));
112 button =
new TGTextButton(
this,
"&Save", 4);
113 button->SetToolTipText(
"Save the palette in a ROOT or an ASCII file");
114 AddFrame(button,
new TGXYLayoutHints(70, 7.5, 8, 1.8));
116 button =
new TGTextButton(
this,
"O&pen", 5);
117 button->SetToolTipText(
"Read a palette from a ROOT or an ASCII file");
118 AddFrame(button,
new TGXYLayoutHints(70, 9.5, 8, 1.8));
120 button =
new TGTextButton(
this,
"&New", 6);
121 button->SetToolTipText(
"Create a new palette (not yet implemented)");
122 button->SetState(kButtonDisabled);
123 AddFrame(button,
new TGXYLayoutHints(70, 12, 8, 1.8));
125 button =
new TGTextButton(
this,
"&Edit", 7);
126 button->SetToolTipText(
"Edit a palette (not yet implemented)");
127 button->SetState(kButtonDisabled);
128 AddFrame(button,
new TGXYLayoutHints(70, 14, 8, 1.8));
130 fAutoUpdate =
new TGCheckButton(
this,
"Auto Update", 13);
131 fAutoUpdate->SetToolTipText(
"Automatic update of the image (without Apply button)");
132 AddFrame(fAutoUpdate,
new TGXYLayoutHints(50, 1, 20, 1.8));
134 fUnDoButton =
new TGTextButton(
this,
"&Undo", 20);
135 fUnDoButton->SetToolTipText(
"Undo the last modification (repeatable)");
136 AddFrame(fUnDoButton,
new TGXYLayoutHints(50, 3, 8, 1.8));
138 fReDoButton =
new TGTextButton(
this,
"&Redo", 21);
139 fReDoButton->SetToolTipText(
"Undo the last undo operation (repeatable)");
140 AddFrame(fReDoButton,
new TGXYLayoutHints(60, 3, 8, 1.8));
142 button =
new TGTextButton(
this,
"&Log", 8);
143 button->SetToolTipText(
"Apply a log operation to the anchor points of the palette");
144 AddFrame(button,
new TGXYLayoutHints(50, 15, 8, 1.8));
146 button =
new TGTextButton(
this,
"E&xp", 9);
147 button->SetToolTipText(
"Apply a exp operation to the anchor points of the palette");
148 AddFrame(button,
new TGXYLayoutHints(50, 17, 8, 1.8));
150 button =
new TGTextButton(
this,
"L&in", 10);
151 button->SetToolTipText(
"Make the distance of all anchor points constant");
152 AddFrame(button,
new TGXYLayoutHints(50, 19, 8, 1.8));
154 button =
new TGTextButton(
this,
"In&vert", 11);
155 button->SetToolTipText(
"Invert the order of the colors");
156 AddFrame(button,
new TGXYLayoutHints(60, 17, 8, 1.8));
158 fStepButton =
new TGCheckButton(
this,
"Step", 12);
159 fStepButton->SetToolTipText(
"Apply a step function to the palette");
160 AddFrame(fStepButton,
new TGXYLayoutHints(60, 19, 8, 1.8));
163 TGGroupFrame *rampFrame =
new TGGroupFrame(
this,
"Ramps");
164 rampFrame->SetLayoutManager(
new TGXYLayout(rampFrame));
165 AddFrame(rampFrame,
new TGXYLayoutHints(50, 8.5, 14, 6,
166 TGXYLayoutHints::kLRubberX | TGXYLayoutHints::kLRubberY |
167 TGXYLayoutHints::kLRubberH | TGXYLayoutHints::kLRubberW));
169 fRamps[0] =
new TGRadioButton(rampFrame,
"1", 1);
170 fRamps[0]->SetToolTipText(
"Repeat the palette once");
171 rampFrame->AddFrame(fRamps[0],
new TGXYLayoutHints(2, 1.4, 5, 1.8));
173 fRamps[1] =
new TGRadioButton(rampFrame,
"2", 2);
174 fRamps[1]->SetToolTipText(
"Repeat the palette twice");
175 rampFrame->AddFrame(fRamps[1],
new TGXYLayoutHints(2, 3.3, 5, 1.8));
177 fRamps[2] =
new TGRadioButton(rampFrame,
"4", 4);
178 fRamps[2]->SetToolTipText(
"Repeat the palette four times");
179 rampFrame->AddFrame(fRamps[2],
new TGXYLayoutHints(8, 3.3, 5, 1.8));
181 fRamps[0]->Associate(
this);
182 fRamps[1]->Associate(
this);
183 fRamps[2]->Associate(
this);
186 fHistCanvas =
new TRootEmbeddedCanvas(
"data hist",
this, 300, 50);
187 AddFrame(fHistCanvas,
new TGXYLayoutHints(1, 1, 48, 20,
188 TGXYLayoutHints::kLRubberW | TGXYLayoutHints::kLRubberH));
190 const ASImage *image = ((TASImage*)attImage)->GetImage();
191 if (image && image->alt.vector) {
193 Double_t *data = image->alt.vector;
194 Int_t numPixel = image->width * image->height;
195 Int_t numBins = numPixel / 20;
196 numBins = (numBins < 10) ? 10 : (numBins > 200) ? 200 : numBins;
199 fMinValue = fMaxValue = *image->alt.vector;
200 for (pixel = 1; pixel < numPixel; pixel++) {
201 if (fMinValue > *(data + pixel)) fMinValue = *(data + pixel);
202 if (fMaxValue < *(data + pixel)) fMaxValue = *(data + pixel);
205 fHisto =
new TH1D(
"Statistics",
"Pixel histogram of unzoomed image ",
206 numBins, fMinValue, fMaxValue);
207 for (pixel = 0; pixel < numPixel; pixel++)
208 fHisto->Fill(*(data + pixel));
210 fHisto->Draw(
"HIST");
211 fHisto->GetXaxis()->SetLabelFont(63);
212 fHisto->GetXaxis()->SetLabelSize(10);
213 fHisto->GetYaxis()->SetLabelFont(63);
214 fHisto->GetYaxis()->SetLabelSize(10);
216 fLimitLine[0] =
new LimitLine(fMinValue + fPalette->fPoints[1] * (fMaxValue - fMinValue),
217 0, fHisto->GetMaximum(),
this);
218 fLimitLine[0]->Draw();
219 fLimitLine[1] =
new LimitLine(fMinValue + fPalette->fPoints[fPalette->fNumPoints - 2] *
220 (fMaxValue - fMinValue), 0, fHisto->GetMaximum(),
this);
221 fLimitLine[1]->Draw();
225 fComboBox =
new TGComboBox(
this, 100);
226 AddFrame(fComboBox,
new TGXYLayoutHints(50, 6, 14, 2));
228 fComboBox->AddEntry(
"Rainbow", 0);
229 fComboBox->AddEntry(
"Grey", 1);
230 fComboBox->AddEntry(
"Hot", 2);
231 fComboBox->AddEntry(
"Cold", 3);
232 fComboBox->AddEntry(
"Bowlerhat", 4);
233 fComboBox->AddEntry(
"", 5);
237 fPaletteCanvas =
new TRootEmbeddedCanvas(
"palette",
this, 300, 50);
238 AddFrame(fPaletteCanvas,
new TGXYLayoutHints(1, 22, 78, 2.5,
239 TGXYLayoutHints::kLRubberW | TGXYLayoutHints::kLRubberY));
241 fPaintPalette =
new PaintPalette(&fPalette, attImage);
242 fPaintPalette->Draw();
247 SetWindowName(
"Palette Editor");
248 SetIconName(
"Palette Editor");
252 UpdateScreen(kFALSE);
258 TASPaletteEditor::~TASPaletteEditor()
265 while ((ptr = (TGFrameElement *) next())) {
274 delete fPaintPalette;
275 delete fLimitLine[0];
276 delete fLimitLine[1];
283 void TASPaletteEditor::CloseWindow()
285 TPaletteEditor::CloseWindow();
292 Bool_t TASPaletteEditor::ProcessMessage(Long_t msg, Long_t param1, Long_t param2)
294 switch (GET_MSG(msg)) {
297 switch (GET_SUBMSG(msg)) {
303 case kCM_RADIOBUTTON:
307 case kCM_CHECKBUTTON:
316 fAttImage->SetPalette(fPalette);
317 fImagePad->Modified();
322 fAttImage->SetPalette(fPalette);
323 fImagePad->Modified();
358 fPalette = (TImagePalette*)(fPaletteList->Before(fPalette));
359 if (fAutoUpdate->GetState() == kButtonDown) {
360 fAttImage->SetPalette(fPalette);
361 fImagePad->Modified();
364 if (fPalette) UpdateScreen(kTRUE);
368 fPalette = (TImagePalette*)(fPaletteList->After(fPalette));
369 if (fAutoUpdate->GetState() == kButtonDown) {
370 fAttImage->SetPalette(fPalette);
371 fImagePad->Modified();
374 if (fPalette) UpdateScreen(kTRUE);
395 void TASPaletteEditor::InsertNewPalette(TImagePalette *newPalette)
400 while ((obj = fPaletteList->After(fPalette)) != 0)
401 delete fPaletteList->Remove(obj);
404 fPaletteList->Add(newPalette);
405 fPalette = newPalette;
408 if (fAutoUpdate->GetState() == kButtonDown) {
409 fAttImage->SetPalette(fPalette);
410 fImagePad->Modified();
419 void TASPaletteEditor::Save()
422 fi.fFileTypes = gFileTypes;
423 static Bool_t overwr = kFALSE;
424 fi.fOverwrite = overwr;
426 new TGFileDialog(gClient->GetRoot(),
this, kFDSave, &fi);
427 overwr = fi.fOverwrite;
428 if (fi.fFilename == 0)
431 if (strcmp(
".pal.txt", fi.fFilename + strlen(fi.fFilename) - 8) == 0) {
433 FILE *fl = fopen(fi.fFilename,
"w");
435 fprintf(fl,
"%u\n", fPalette->fNumPoints);
436 for (Int_t pt = 0; pt < Int_t(fPalette->fNumPoints); pt++)
437 fprintf(fl,
"%10.9f %04hx %04hx %04hx %04hx\n",
438 fPalette->fPoints[pt],
439 fPalette->fColorRed[pt],
440 fPalette->fColorGreen[pt],
441 fPalette->fColorBlue[pt],
442 fPalette->fColorAlpha[pt] );
447 if (strcmp(
".pal.root", fi.fFilename + strlen(fi.fFilename) - 9) != 0)
448 snprintf(fn,512,
"%s%s", fi.fFilename,
".pal.root");
450 strlcpy(fn, fi.fFilename,512);
452 gROOT->ProcessLine(Form(
"gROOT->SaveObjectAs((TASPaletteEditor*)0x%lx,\"%s\",\"%s\");",(ULong_t)
this,fn,
"q"));
460 void TASPaletteEditor::Open()
463 fi.fFileTypes = gFileTypes;
465 new TGFileDialog(gClient->GetRoot(),
this, kFDOpen, &fi);
466 if (fi.fFilename == 0)
469 TImagePalette *newPalette;
471 if (strcmp(
".pal.txt", fi.fFilename + strlen(fi.fFilename) - 8) == 0) {
472 FILE *fl = fopen(fi.fFilename,
"r");
476 if (fscanf(fl,
"%u\n", &numPoints)) {;}
477 newPalette =
new TImagePalette(numPoints);
478 for (Int_t pt = 0; pt < Int_t(numPoints); pt++)
480 if (fscanf(fl,
"%lf %hx %hx %hx %hx\n",
481 newPalette->fPoints + pt,
482 newPalette->fColorRed + pt,
483 newPalette->fColorGreen + pt,
484 newPalette->fColorBlue + pt,
485 newPalette->fColorAlpha + pt )) {;}
490 if (strcmp(
".pal.root", fi.fFilename + strlen(fi.fFilename) - 9) != 0)
491 snprintf(fn,512,
"%s%s", fi.fFilename,
".pal.root");
493 strlcpy(fn, fi.fFilename,512);
494 TDirectory *dirsav = gDirectory;
496 TFile *fsave =
new TFile(fn,
"READ");
497 if (!fsave->IsOpen()) {
502 newPalette = (TImagePalette*)fsave->Get(
"TImagePalette");
504 if (dirsav) dirsav->cd();
509 InsertNewPalette(newPalette);
512 fComboBox->Select(5);
519 void TASPaletteEditor::UpdateScreen(Bool_t histoUpdate)
522 fPaletteCanvas->GetCanvas()->Modified();
523 fPaletteCanvas->GetCanvas()->Update();
527 Double_t xPos = fMinValue + fPalette->fPoints[1] * (fMaxValue - fMinValue);
528 fLimitLine[0]->SetX1(xPos);
529 fLimitLine[0]->SetX2(xPos);
531 xPos = fMinValue + fPalette->fPoints[fPalette->fNumPoints - 2] * (fMaxValue - fMinValue);
532 fLimitLine[1]->SetX1(xPos);
533 fLimitLine[1]->SetX2(xPos);
535 fHistCanvas->GetCanvas()->Modified();
536 fHistCanvas->GetCanvas()->Update();
540 fUnDoButton->SetState(fPalette == fPaletteList->First() ? kButtonDisabled : kButtonUp);
541 fReDoButton->SetState(fPalette == fPaletteList->Last() ? kButtonDisabled : kButtonUp);
544 EButtonState step = kButtonDown;
547 for (pt = 2; pt < Int_t(fPalette->fNumPoints - 2); pt += 2)
548 if (TMath::Abs(fPalette->fPoints[pt] - fPalette->fPoints[pt + 1]) > 0.0001 ||
549 fPalette->fColorRed[pt] != fPalette->fColorRed[pt-1] ||
550 fPalette->fColorGreen[pt] != fPalette->fColorGreen[pt-1] ||
551 fPalette->fColorBlue[pt] != fPalette->fColorBlue[pt-1])
553 fStepButton->SetState(step);
557 Int_t off = (fPalette->fNumPoints - 2) / 4;
558 for (pt = 0; pt < Int_t(fPalette->fNumPoints - 2) / 4 * 3; pt++)
559 if (fPalette->fColorRed[pt + 1] != fPalette->fColorRed[pt + 1 + off] ||
560 fPalette->fColorGreen[pt + 1] != fPalette->fColorGreen[pt + 1 + off] ||
561 fPalette->fColorBlue[pt + 1] != fPalette->fColorBlue[pt + 1 + off] ||
562 fPalette->fColorAlpha[pt + 1] != fPalette->fColorAlpha[pt + 1 + off]) {
567 off = (fPalette->fNumPoints - 2) / 2;
568 for (pt = 0; pt < Int_t(fPalette->fNumPoints - 2) / 2; pt++)
569 if (fPalette->fColorRed[pt + 1] != fPalette->fColorRed[pt + 1 + off] ||
570 fPalette->fColorGreen[pt + 1] != fPalette->fColorGreen[pt + 1 + off] ||
571 fPalette->fColorBlue[pt + 1] != fPalette->fColorBlue[pt + 1 + off] ||
572 fPalette->fColorAlpha[pt + 1] != fPalette->fColorAlpha[pt + 1 + off]) {
577 fRamps[0]->SetState(fRampFactor == 1 ? kButtonDown : kButtonUp);
578 fRamps[1]->SetState(fRampFactor == 2 ? kButtonDown : kButtonUp);
579 fRamps[2]->SetState(fRampFactor == 4 ? kButtonDown : kButtonUp);
586 void TASPaletteEditor::LogPalette()
588 TImagePalette *newPalette =
new TImagePalette(*fPalette);
590 Double_t delta = fPalette->fPoints[fPalette->fNumPoints-2] - fPalette->fPoints[1];
592 for (Int_t pt = 2; pt < Int_t(fPalette->fNumPoints - 2); pt++)
593 newPalette->fPoints[pt] = fPalette->fPoints[1] +
594 TMath::Log(fPalette->fPoints[pt] - fPalette->fPoints[1] + 1) /
595 TMath::Log(delta + 1) * delta;
597 InsertNewPalette(newPalette);
598 UpdateScreen(kFALSE);
605 void TASPaletteEditor::ExpPalette()
607 TImagePalette *newPalette =
new TImagePalette(*fPalette);
609 Double_t delta = fPalette->fPoints[fPalette->fNumPoints-2] - fPalette->fPoints[1];
611 for (Int_t pt = 2; pt < Int_t(fPalette->fNumPoints - 2); pt++)
612 newPalette->fPoints[pt] = fPalette->fPoints[1] +
613 TMath::Exp((fPalette->fPoints[pt] - fPalette->fPoints[1]) *
614 TMath::Log(delta + 1) / delta) - 1;
616 InsertNewPalette(newPalette);
617 UpdateScreen(kFALSE);
624 void TASPaletteEditor::LinPalette()
626 TImagePalette *newPalette =
new TImagePalette(*fPalette);
628 Double_t delta = fPalette->fPoints[fPalette->fNumPoints-2] - fPalette->fPoints[1];
629 if (fStepButton->GetState() == kButtonUp) {
630 for (Int_t pt = 2; pt < Int_t(fPalette->fNumPoints - 2); pt++)
631 newPalette->fPoints[pt] = fPalette->fPoints[1] +
632 delta * (pt - 1) / (fPalette->fNumPoints - 3);
634 for (Int_t pt = 0; pt < Int_t(fPalette->fNumPoints - 4); pt += 2) {
635 newPalette->fPoints[pt + 3] = fPalette->fPoints[1] + delta * (pt + 2) /
636 (fPalette->fNumPoints - 2) ;
637 newPalette->fPoints[pt + 2] = newPalette->fPoints[pt + 3];
641 InsertNewPalette(newPalette);
642 UpdateScreen(kFALSE);
649 void TASPaletteEditor::InvertPalette()
651 TImagePalette *newPalette =
new TImagePalette(*fPalette);
654 for (pt = 0; pt < Int_t(fPalette->fNumPoints); pt++) {
655 newPalette->fColorRed[pt] = fPalette->fColorRed[fPalette->fNumPoints - 1 - pt];
656 newPalette->fColorGreen[pt] = fPalette->fColorGreen[fPalette->fNumPoints - 1 - pt];
657 newPalette->fColorBlue[pt] = fPalette->fColorBlue[fPalette->fNumPoints - 1 - pt];
658 newPalette->fColorAlpha[pt] = fPalette->fColorAlpha[fPalette->fNumPoints - 1 - pt];
661 for (pt = 2; pt < Int_t(fPalette->fNumPoints - 2); pt++)
662 newPalette->fPoints[pt] = fPalette->fPoints[1] +
663 fPalette->fPoints[fPalette->fNumPoints - 2] -
664 fPalette->fPoints[fPalette->fNumPoints - 1 - pt];
666 InsertNewPalette(newPalette);
667 UpdateScreen(kFALSE);
674 void TASPaletteEditor::NewPalette(Long_t
id)
679 TImagePalette *newPalette;
681 Double_t delta = fPalette->fPoints[fPalette->fNumPoints-2] - fPalette->fPoints[1];
684 numPt =
id == 0 ? 12 : 13;
685 newPalette =
new TImagePalette(numPt);
687 for (pt = 1; pt < Int_t(numPt - 1); pt++) {
688 newPalette->fPoints[pt] = fPalette->fPoints[1] + (pt - 1) * delta / (numPt - 3);
689 newPalette->fColorAlpha[pt] = 0xffff;
694 memcpy(newPalette->fColorRed + 1, gRedRainbow, 12 *
sizeof(UShort_t));
695 memcpy(newPalette->fColorGreen + 1, gGreenRainbow, 12 *
sizeof(UShort_t));
696 memcpy(newPalette->fColorBlue + 1, gBlueRainbow, 12 *
sizeof(UShort_t));
700 for (pt = 1; pt < Int_t(numPt - 1); pt++) {
701 newPalette->fColorRed[pt] = 0xffff * (pt - 1) / (numPt - 3);
702 newPalette->fColorGreen[pt] = 0xffff * (pt - 1) / (numPt - 3);
703 newPalette->fColorBlue[pt] = 0xffff * (pt - 1) / (numPt - 3);
708 for (pt = 1; pt < Int_t(numPt - 1) / 2; pt++) {
709 newPalette->fColorRed[pt] = 0xffff * (pt - 1) / ((numPt - 3) / 2);
710 newPalette->fColorGreen[pt] = 0;
711 newPalette->fColorBlue[pt] = 0;
714 for (; pt < Int_t(numPt - 1); pt++) {
715 newPalette->fColorRed[pt] = 0xffff;
716 newPalette->fColorGreen[pt] = 0xffff * (pt - (numPt - 1) / 2) / ((numPt - 3) / 2);
717 newPalette->fColorBlue[pt] = 0xffff * (pt - (numPt - 1) / 2) / ((numPt - 3) / 2);
722 for (pt = 1; pt < Int_t(numPt - 1) / 2; pt++) {
723 newPalette->fColorRed[pt] = 0;
724 newPalette->fColorGreen[pt] = 0;
725 newPalette->fColorBlue[pt] = 0xffff * (pt - 1) / ((numPt - 3) / 2);
728 for (; pt < Int_t(numPt - 1); pt++) {
729 newPalette->fColorRed[pt] = 0xffff * (pt - (numPt - 1) / 2) / ((numPt - 3) / 2);
730 newPalette->fColorGreen[pt] = 0xffff * (pt - (numPt - 1) / 2) / ((numPt - 3) / 2);
731 newPalette->fColorBlue[pt] = 0xffff;
736 for (pt = 1; pt < Int_t(numPt + 1) / 2; pt++) {
737 newPalette->fColorRed[pt] = newPalette->fColorRed[numPt - pt - 1]
738 = 0xffff * (pt - 1) / ((numPt - 3) / 2);
739 newPalette->fColorGreen[pt] = newPalette->fColorGreen[numPt - pt - 1]
740 = 0xffff * (pt - 1) / ((numPt - 3) / 2);
741 newPalette->fColorBlue[pt] = newPalette->fColorBlue[numPt - pt - 1]
742 = 0xffff * (pt - 1) / ((numPt - 3) / 2);
747 newPalette->fPoints[0] = 0;
748 newPalette->fColorRed[0] = newPalette->fColorRed[1];
749 newPalette->fColorGreen[0] = newPalette->fColorGreen[1];
750 newPalette->fColorBlue[0] = newPalette->fColorBlue[1];
751 newPalette->fColorAlpha[0] = newPalette->fColorAlpha[1];
753 newPalette->fPoints[newPalette->fNumPoints-1] = 1.0;
754 newPalette->fColorRed[newPalette->fNumPoints-1] = newPalette->fColorRed[newPalette->fNumPoints-2];
755 newPalette->fColorGreen[newPalette->fNumPoints-1] = newPalette->fColorGreen[newPalette->fNumPoints-2];
756 newPalette->fColorBlue[newPalette->fNumPoints-1] = newPalette->fColorBlue[newPalette->fNumPoints-2];
757 newPalette->fColorAlpha[newPalette->fNumPoints-1] = newPalette->fColorAlpha[newPalette->fNumPoints-2];
759 InsertNewPalette(newPalette);
760 UpdateScreen(kFALSE);
767 void TASPaletteEditor::SetStep()
769 TImagePalette *newPalette;
771 if (fStepButton->GetState() == kButtonDown) {
773 newPalette =
new TImagePalette(fPalette->fNumPoints * 2 - 2);
774 Double_t fkt = (Double_t)(fPalette->fNumPoints - 3) / (fPalette->fNumPoints - 2);
775 for (Int_t pt = 1; pt < Int_t(fPalette->fNumPoints - 1); pt++) {
776 newPalette->fPoints[pt * 2 - 1] = fPalette->fPoints[1] + (fPalette->fPoints[pt] - fPalette->fPoints[1]) * fkt;
777 newPalette->fPoints[pt * 2] = fPalette->fPoints[1] + (fPalette->fPoints[pt + 1] - fPalette->fPoints[1]) * fkt;
778 newPalette->fColorRed[pt * 2 - 1] = newPalette->fColorRed[pt * 2] = fPalette->fColorRed[pt];
779 newPalette->fColorGreen[pt * 2 - 1] = newPalette->fColorGreen[pt * 2] = fPalette->fColorGreen[pt];
780 newPalette->fColorBlue[pt * 2 - 1] = newPalette->fColorBlue[pt * 2] = fPalette->fColorBlue[pt];
781 newPalette->fColorAlpha[pt * 2 - 1] = newPalette->fColorAlpha[pt * 2] = fPalette->fColorAlpha[pt];
785 newPalette =
new TImagePalette(fPalette->fNumPoints / 2 + 1);
786 Double_t fkt = (Double_t) (fPalette->fPoints[fPalette->fNumPoints - 2] - fPalette->fPoints[1]) /
787 (fPalette->fPoints[fPalette->fNumPoints - 3] - fPalette->fPoints[1]);
788 for (Int_t pt = 1; pt < Int_t(newPalette->fNumPoints - 1); pt++) {
789 newPalette->fPoints[pt] = fPalette->fPoints[pt * 2 -1] * fkt;
790 newPalette->fColorRed[pt] = fPalette->fColorRed[pt * 2 - 1];
791 newPalette->fColorGreen[pt] = fPalette->fColorGreen[pt * 2 - 1];
792 newPalette->fColorBlue[pt] = fPalette->fColorBlue[pt * 2 - 1];
793 newPalette->fColorAlpha[pt] = fPalette->fColorAlpha[pt * 2 - 1];
797 newPalette->fPoints[0] = fPalette->fPoints[0];
798 newPalette->fColorRed[0] = fPalette->fColorRed[0];
799 newPalette->fColorGreen[0] = fPalette->fColorGreen[0];
800 newPalette->fColorBlue[0] = fPalette->fColorBlue[0];
801 newPalette->fColorAlpha[0] = fPalette->fColorAlpha[0];
803 newPalette->fPoints[newPalette->fNumPoints-2] = fPalette->fPoints[fPalette->fNumPoints-2];
804 newPalette->fPoints[newPalette->fNumPoints-1] = fPalette->fPoints[fPalette->fNumPoints-1];
805 newPalette->fColorRed[newPalette->fNumPoints-1] = fPalette->fColorRed[fPalette->fNumPoints-1];
806 newPalette->fColorGreen[newPalette->fNumPoints-1] = fPalette->fColorGreen[fPalette->fNumPoints-1];
807 newPalette->fColorBlue[newPalette->fNumPoints-1] = fPalette->fColorBlue[fPalette->fNumPoints-1];
808 newPalette->fColorAlpha[newPalette->fNumPoints-1] = fPalette->fColorAlpha[fPalette->fNumPoints-1];
810 InsertNewPalette(newPalette);
811 UpdateScreen(kFALSE);
818 void TASPaletteEditor::SetRamp(Long_t ramp)
820 if (ramp == fRampFactor)
823 Int_t ptPerRamp = (fPalette->fNumPoints - 2) / fRampFactor;
824 TImagePalette *newPalette =
new TImagePalette(ptPerRamp * ramp + 2);
826 Double_t delta = fPalette->fPoints[fPalette->fNumPoints-2] - fPalette->fPoints[1];
827 for (Int_t rp = 0; rp < ramp; rp++) {
828 for (Int_t pt = 0; pt < ptPerRamp; pt++) {
829 newPalette->fPoints[1 + pt + rp * ptPerRamp] = fPalette->fPoints[1] +
831 (fPalette->fPoints[1+pt] - fPalette->fPoints[1]) * fRampFactor / ramp;
832 newPalette->fColorRed [1 + pt + rp * ptPerRamp] = fPalette->fColorRed [1 + pt];
833 newPalette->fColorGreen[1 + pt + rp * ptPerRamp] = fPalette->fColorGreen[1 + pt];
834 newPalette->fColorBlue [1 + pt + rp * ptPerRamp] = fPalette->fColorBlue [1 + pt];
835 newPalette->fColorAlpha[1 + pt + rp * ptPerRamp] = fPalette->fColorAlpha[1 + pt];
839 newPalette->fPoints[0] = fPalette->fPoints[0];
840 newPalette->fColorRed[0] = fPalette->fColorRed[0];
841 newPalette->fColorGreen[0] = fPalette->fColorGreen[0];
842 newPalette->fColorBlue[0] = fPalette->fColorBlue[0];
843 newPalette->fColorAlpha[0] = fPalette->fColorAlpha[0];
845 newPalette->fPoints[newPalette->fNumPoints-2] = fPalette->fPoints[fPalette->fNumPoints-2];
846 newPalette->fPoints[newPalette->fNumPoints-1] = fPalette->fPoints[fPalette->fNumPoints-1];
847 newPalette->fColorRed[newPalette->fNumPoints-1] = fPalette->fColorRed[fPalette->fNumPoints-1];
848 newPalette->fColorGreen[newPalette->fNumPoints-1] = fPalette->fColorGreen[fPalette->fNumPoints-1];
849 newPalette->fColorBlue[newPalette->fNumPoints-1] = fPalette->fColorBlue[fPalette->fNumPoints-1];
850 newPalette->fColorAlpha[newPalette->fNumPoints-1] = fPalette->fColorAlpha[fPalette->fNumPoints-1];
852 InsertNewPalette(newPalette);
853 UpdateScreen(kFALSE);
861 void TASPaletteEditor::UpdateRange()
863 if (fMaxValue == fMinValue)
866 TImagePalette *newPalette =
new TImagePalette(*fPalette);
868 Double_t l0 = fLimitLine[0]->GetX1();
869 Double_t l1 = fLimitLine[1]->GetX1();
870 l0 = (l0 < fMinValue) ? fMinValue : ((l0 > fMaxValue) ? fMaxValue : l0);
871 l1 = (l1 < fMinValue) ? fMinValue : ((l1 > fMaxValue) ? fMaxValue : l1);
878 Double_t oldDelta = fPalette->fPoints[fPalette->fNumPoints - 2] - fPalette->fPoints[1];
879 Double_t newDelta = (l1 - l0) / (fMaxValue - fMinValue);
880 Double_t newOff = (l0 - fMinValue) / (fMaxValue - fMinValue);
882 if (newDelta < 0.001 || oldDelta < 0.001)
885 for (Int_t pt = 1; pt < Int_t(fPalette->fNumPoints - 1); pt++)
886 newPalette->fPoints[pt] = newOff +
887 (fPalette->fPoints[pt] - fPalette->fPoints[1]) * newDelta / oldDelta;
889 InsertNewPalette(newPalette);
890 UpdateScreen(kFALSE);
896 void TASPaletteEditor::PaintPalette::Paint(Option_t *)
899 Int_t to_w = TMath::Abs(gPad->XtoPixel(gPad->GetX2()) -
900 gPad->XtoPixel(gPad->GetX1()));
901 Int_t to_h = TMath::Abs(gPad->YtoPixel(gPad->GetY2()) -
902 gPad->YtoPixel(gPad->GetY1()));
906 grad.npoints = (*fPalette)->fNumPoints - 2;
907 grad.type = GRADIENT_Left2Right;
908 grad.color =
new ARGB32[grad.npoints];
909 grad.offset =
new double[grad.npoints];
910 for (Int_t pt = 0; pt < grad.npoints; pt++) {
911 grad.offset[pt] = ((*fPalette)->fPoints[pt + 1] - (*fPalette)->fPoints[1]) /
912 ((*fPalette)->fPoints[(*fPalette)->fNumPoints - 2] - (*fPalette)->fPoints[1]);
913 grad.color[pt] = (((ARGB32)((*fPalette)->fColorBlue[pt + 1] & 0xff00)) >> 8) |
914 (((ARGB32)((*fPalette)->fColorGreen[pt + 1] & 0xff00)) ) |
915 (((ARGB32)((*fPalette)->fColorRed[pt + 1] & 0xff00)) << 8) |
916 (((ARGB32)((*fPalette)->fColorAlpha[pt + 1] & 0xff00)) << 16);
919 ASImage * grad_im = make_gradient((ASVisual*)TASImage::GetVisual(), &grad , to_w, to_h,
920 SCL_DO_COLOR, ASA_ARGB32, 0,
921 fAttImage->GetImageQuality());
922 delete [] grad.color;
923 delete [] grad.offset;
925 Window_t wid = (Window_t)gVirtualX->GetWindowID(gPad->GetPixmapID());
926 TASImage::Image2Drawable(grad_im, wid, 0, 0);
927 destroy_asimage(&grad_im);
933 TASPaletteEditor::LimitLine::LimitLine(Coord_t x, Coord_t y1, Coord_t y2,
934 TASPaletteEditor *gui)
935 : TLine(x, y1, x, y2)
945 void TASPaletteEditor::LimitLine::Paint(Option_t *option)
947 fY1 = gPad->GetUymin();
948 fY2 = gPad->GetUymax();
950 TLine::Paint(option);
955 void TASPaletteEditor::LimitLine::ExecuteEvent(Int_t event,
964 gPad->SetCursor(kMove);
968 gVirtualX->SetLineColor(-1);
970 oldX = gPad->XtoAbsPixel(fX1);
974 gVirtualX->DrawLine(oldX, gPad->YtoPixel(fY1), oldX, gPad->YtoPixel(fY2));
976 gVirtualX->DrawLine(oldX, gPad->YtoPixel(fY1), oldX, gPad->YtoPixel(fY2));
981 gVirtualX->SetLineColor(-1);
983 fX1 = fX2 = gPad->AbsPixeltoX(oldX);
985 gPad->Modified(kTRUE);