diff --git a/graf2d/asimage/inc/TASImage.h b/graf2d/asimage/inc/TASImage.h index a93f5c1298899..d38433a2b0457 100644 --- a/graf2d/asimage/inc/TASImage.h +++ b/graf2d/asimage/inc/TASImage.h @@ -89,7 +89,7 @@ class TASImage : public TImage { TASImage &operator=(const TASImage &img); ~TASImage() override; - TObject *Clone(const char *newname) const override; + TObject *Clone(const char *newname = "") const override; void SetEditable(Bool_t on = kTRUE) override { fEditable = on; } //*TOGGLE* Bool_t IsEditable() const override { return fEditable; } diff --git a/graf2d/asimage/src/TASImage.cxx b/graf2d/asimage/src/TASImage.cxx index d86a915f9e8e7..efaaea8eeb6e5 100644 --- a/graf2d/asimage/src/TASImage.cxx +++ b/graf2d/asimage/src/TASImage.cxx @@ -297,7 +297,7 @@ TASImage::TASImage(const TASImage &img) : TImage(img) if (img.IsValid()) { fImage = clone_asimage(img.fImage, SCL_DO_ALL); - fScaledImage = fScaledImage ? (TASImage*)img.fScaledImage->Clone("") : nullptr; + fScaledImage = fScaledImage ? static_cast(img.fScaledImage->Clone()) : nullptr; fGrayImage = fGrayImage ? clone_asimage(img.fGrayImage, SCL_DO_ALL) : nullptr; if (img.fImage->alt.vector) { @@ -327,7 +327,7 @@ TASImage &TASImage::operator=(const TASImage &img) DestroyImage(); delete fScaledImage; fImage = clone_asimage(img.fImage, SCL_DO_ALL); - fScaledImage = fScaledImage ? (TASImage*)img.fScaledImage->Clone("") : nullptr; + fScaledImage = fScaledImage ? static_cast(img.fScaledImage->Clone()) : nullptr; fGrayImage = fGrayImage ? clone_asimage(img.fGrayImage, SCL_DO_ALL) : nullptr; if (img.fImage->alt.vector) { @@ -336,7 +336,7 @@ TASImage &TASImage::operator=(const TASImage &img) memcpy(fImage->alt.vector, img.fImage->alt.vector, size); } - fScaledImage = img.fScaledImage ? (TASImage*)img.fScaledImage->Clone("") : nullptr; + fScaledImage = img.fScaledImage ? static_cast(img.fScaledImage->Clone()) : nullptr; fZoomUpdate = kNoZoom; fZoomOffX = img.fZoomOffX; fZoomOffY = img.fZoomOffY; @@ -2788,7 +2788,7 @@ TObject *TASImage::Clone(const char *newname) const return nullptr; } - TASImage *im = (TASImage*)TImage::Create(); + TASImage *im = static_cast(TImage::Create()); if (!im) { Warning("Clone", "Failed to create image"); @@ -2805,7 +2805,7 @@ TObject *TASImage::Clone(const char *newname) const im->fZoomWidth = fZoomWidth; im->fZoomHeight = fZoomHeight; im->fZoomUpdate = fZoomUpdate; - im->fScaledImage = fScaledImage ? (TASImage*)fScaledImage->Clone("") : nullptr; + im->fScaledImage = fScaledImage ? static_cast(fScaledImage->Clone()) : nullptr; if (fImage->alt.argb32) { UInt_t sz = fImage->width * fImage->height; @@ -6739,34 +6739,24 @@ void TASImage::SavePrimitive(std::ostream &out, Option_t * /*= ""*/) { char *buf = nullptr; int sz; - - if (GetWidth() > 500) { // workaround CINT limitations - UInt_t w = 500; - Double_t scale = 500./GetWidth(); - UInt_t h = TMath::Nint(GetHeight()*scale); - Scale(w, h); - } - GetImageBuffer(&buf, &sz, TImage::kXpm); TString str = buf; free(buf); - TString name = GetName(); - name.ReplaceAll(".", "_"); + str.ReplaceAll("static", "const"); static int ii = 0; - ii++; - str.ReplaceAll("static", "const"); - TString xpm = "xpm_"; - xpm += name; - xpm += ii; + TString xpm = TString::Format("asimage_xpm_%d", ii++); str.ReplaceAll("asxpm", xpm.Data()); - out << std::endl << str << std::endl << std::endl; - - out << " TImage *"; - out << xpm << "_img = TImage::Create();" << std::endl; - out << " " << xpm << "_img->SetImageBuffer( (char **)" << xpm << ", TImage::kXpm);" << std::endl; - out << " " << xpm << "_img->Draw();" << std::endl; + out << "\n" << str << "\n\n"; + + out << " "; + if (!gROOT->ClassSaved(TImage::Class())) + out << TImage::Class()->GetName() << " *"; + out << "asimage = TImage::Create();\n"; + out << " asimage->SetImageBuffer( (char **)" << xpm << ", TImage::kXpm);\n"; + SaveImageAttributes(out, "asimage"); + out << " asimage->Draw();\n"; } //////////////////////////////////////////////////////////////////////////////// diff --git a/graf2d/graf/inc/TAttImage.h b/graf2d/graf/inc/TAttImage.h index d15cd2a30b19f..62ffa35264555 100644 --- a/graf2d/graf/inc/TAttImage.h +++ b/graf2d/graf/inc/TAttImage.h @@ -89,7 +89,7 @@ class TAttImage { virtual void ResetAttImage(Option_t *option=""); virtual void SaveImageAttributes(std::ostream &out, const char *name, - EImageQuality qualdef = kImgDefault, + EImageQuality qualdef = kImgPoor, UInt_t comprdef = 0, Bool_t constRatiodef = kTRUE); virtual void SetConstRatio(Bool_t constRatio = kTRUE); // *TOGGLE* diff --git a/graf2d/graf/inc/TImage.h b/graf2d/graf/inc/TImage.h index d5d388872a7e3..c23854b106da4 100644 --- a/graf2d/graf/inc/TImage.h +++ b/graf2d/graf/inc/TImage.h @@ -108,7 +108,7 @@ friend TImage operator/(const TImage &i1, const TImage &s2); ~TImage() override { } // Cloning - TObject *Clone(const char *) const override { return nullptr; } + TObject *Clone(const char * = "") const override { return nullptr; } // Input / output virtual void ReadImage(const char * /*file*/, EImageFileTypes /*type*/ = TImage::kUnknown) {} diff --git a/graf2d/graf/src/TAttImage.cxx b/graf2d/graf/src/TAttImage.cxx index 4c3c964f1f6c5..dce33c34a4bdd 100644 --- a/graf2d/graf/src/TAttImage.cxx +++ b/graf2d/graf/src/TAttImage.cxx @@ -610,14 +610,20 @@ void TAttImage::SaveImageAttributes(std::ostream &out, const char *name, UInt_t comprdef, Bool_t constRatiodef) { if (fImageQuality != qualdef) { - out<<" "<SetImageQuality("<SetImageCompression("<SetConstRatio("<SetImageQuality(TAttImage::"; + switch (fImageQuality) { + case kImgPoor: out << "kImgPoor"; break; + case kImgFast: out << "kImgFast"; break; + case kImgGood: out << "kImgGood"; break; + case kImgBest: out << "kImgBest"; break; + default: out << "kImgDefault"; + } + out << ");\n"; } + if (fImageCompression != comprdef) + out << " " << name << "->SetImageCompression(" << fImageCompression << ");\n"; + if (fConstRatio != constRatiodef) + out << " " << name << "->SetConstRatio(" << (fConstRatio ? "kTRUE" : "kFALSE") << ");\n"; } //////////////////////////////////////////////////////////////////////////////// diff --git a/test/stressGraphics.cxx b/test/stressGraphics.cxx index 3efe06d1d5b80..e2a9aeeb054c9 100644 --- a/test/stressGraphics.cxx +++ b/test/stressGraphics.cxx @@ -3640,28 +3640,30 @@ void timage() { TCanvas *C = StartTest(800,800); - TImage *img = TImage::Open("$(ROOTSYS)/tutorials/visualisation/image/rose512.jpg"); + TString fname = gROOT->GetTutorialDir(); + fname.Append("/visualisation/image/rose512.jpg"); + TImage *img = TImage::Open(fname); if (!img) { printf("Could not create an image... exit\n"); return; } - TImage *i1 = TImage::Open("$(ROOTSYS)/tutorials/visualisation/image/rose512.jpg"); + auto i1 = (TImage *) img->Clone(); i1->SetConstRatio(kFALSE); i1->Flip(90); - TImage *i2 = TImage::Open("$(ROOTSYS)/tutorials/visualisation/image/rose512.jpg"); + auto i2 = (TImage *) img->Clone(); i2->SetConstRatio(kFALSE); i2->Flip(180); - TImage *i3 = TImage::Open("$(ROOTSYS)/tutorials/visualisation/image/rose512.jpg"); + auto i3 = (TImage *) img->Clone(); i3->SetConstRatio(kFALSE); i3->Flip(270); - TImage *i4 = TImage::Open("$(ROOTSYS)/tutorials/visualisation/image/rose512.jpg"); - i4->SetConstRatio(kFALSE); - i4->Mirror(kTRUE); + + img->SetConstRatio(kFALSE); + img->Mirror(kTRUE); float d = 0.40; TPad *p1 = new TPad("i1", "i1", 0.05, 0.55, 0.05+d*i1->GetWidth()/i1->GetHeight(), 0.95); TPad *p2 = new TPad("i2", "i2", 0.55, 0.55, 0.95, 0.55+d*i2->GetHeight()/i2->GetWidth()); TPad *p3 = new TPad("i3", "i3", 0.55, 0.05, 0.55+d*i3->GetWidth()/i3->GetHeight(), 0.45); - TPad *p4 = new TPad("i4", "i4", 0.05, 0.05, 0.45, 0.05+d*i4->GetHeight()/i4->GetWidth()); + TPad *p4 = new TPad("i4", "i4", 0.05, 0.05, 0.45, 0.05+d*img->GetHeight()/img->GetWidth()); p1->Draw(); p1->cd(); i1->Draw(); @@ -3676,7 +3678,7 @@ void timage() C->cd(); p4->Draw(); p4->cd(); - i4->Draw(); + img->Draw(); C->cd(); TestReport(C, "timage", "TImage"); @@ -4371,16 +4373,19 @@ void stressGraphics(Int_t verbose = 0, Bool_t generate = kFALSE, Bool_t keep_fil // only in batch web mode use gWebMode = gROOT->IsWebDisplay(); - // Check if $ROOTSYS/tutorials/hsimple.root exists - gHsimple = TFile::Open("$(ROOTSYS)/tutorials/hsimple.root"); + // Check if hsimple.root exists + + TString dir = gROOT->GetTutorialDir(); + + gHsimple = TFile::Open(dir + "/hsimple.root"); if (!gHsimple) { gHsimple = TFile::Open("hsimple.root"); if (!gHsimple) { - printf("Create $(ROOTSYS)/tutorials/hsimple.root\n"); - gROOT->Macro("$(ROOTSYS)/tutorials/hsimple.C"); - gHsimple = TFile::Open("$(ROOTSYS)/tutorials/hsimple.root"); + printf("Create hsimple.root\n"); + gROOT->Macro(dir + "/hsimple.C"); + gHsimple = TFile::Open("hsimple.root"); if (!gHsimple) { - printf("Could not create $(ROOTSYS)/tutorials/hsimple.root\n"); + printf("Could not create hsimple.root\n"); return; } } @@ -4389,10 +4394,10 @@ void stressGraphics(Int_t verbose = 0, Bool_t generate = kFALSE, Bool_t keep_fil // Check if cernstaff.root exists gCernstaff = TFile::Open("cernstaff.root"); if (!gCernstaff) { - gCernstaff = TFile::Open("$(ROOTSYS)/tutorials/io/tree/cernstaff.root"); + gCernstaff = TFile::Open(dir + "/io/tree/cernstaff.root"); if (!gCernstaff) { printf("Create ./cernstaff.root\n"); - gROOT->Macro("$(ROOTSYS)/tutorials/io/tree/tree500_cernbuild.C(0,0)"); + gROOT->Macro(dir + "/io/tree/tree500_cernbuild.C(0,0)"); gCernstaff = TFile::Open("cernstaff.root"); if (!gCernstaff) { printf("Could not create ./cernstaff.root\n"); diff --git a/tutorials/visualisation/image/img2pad.C b/tutorials/visualisation/image/img2pad.C index bad80ffa1954c..651909ee7e6b6 100644 --- a/tutorials/visualisation/image/img2pad.C +++ b/tutorials/visualisation/image/img2pad.C @@ -10,11 +10,15 @@ void img2pad() { - TImage *img = TImage::Open("$ROOTSYS/tutorials/visualisation/image/rose512.jpg"); + TString fname = gROOT->GetTutorialDir(); + fname.Append("/visualisation/image/rose512.jpg"); + TImage *img = TImage::Open(fname); + if (!img) { printf("Could not create an image... exit\n"); return; } + img->SetConstRatio(kFALSE); img->Draw("N"); @@ -26,16 +30,16 @@ void img2pad() /*img->Draw("T100,100,#556655");*/ /*img->Draw("T100,100");*/ - TImage *i1 = TImage::Open("$ROOTSYS/tutorials/visualisation/image/rose512.jpg"); + TImage *i1 = TImage::Open(fname); i1->SetConstRatio(kFALSE); i1->Flip(90); - TImage *i2 = TImage::Open("$ROOTSYS/tutorials/visualisation/image/rose512.jpg"); + TImage *i2 = TImage::Open(fname); i2->SetConstRatio(kFALSE); i2->Flip(180); - TImage *i3 = TImage::Open("$ROOTSYS/tutorials/visualisation/image/rose512.jpg"); + TImage *i3 = TImage::Open(fname); i3->SetConstRatio(kFALSE); i3->Flip(270); - TImage *i4 = TImage::Open("$ROOTSYS/tutorials/visualisation/image/rose512.jpg"); + TImage *i4 = TImage::Open(fname); i4->SetConstRatio(kFALSE); i4->Mirror(kTRUE);