Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions graf2d/asimage/inc/TASImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,16 @@ class TASImage : public TImage {
// Utilities
UInt_t GetWidth() const override;
UInt_t GetHeight() const override;
UInt_t GetScaledWidth() const;
UInt_t GetScaledHeight() const;
UInt_t GetScaledWidth() const override;
UInt_t GetScaledHeight() const override;
Bool_t IsValid() const override { return fImage ? kTRUE : kFALSE; }
Bool_t IsGray() const override { return fIsGray; }
ASImage *GetImage() const { return fImage; }
void SetImage(ASImage *image) { DestroyImage(); fImage = image; }
TImage *GetScaledImage() const override { return fScaledImage; }
Pixmap_t GetX11Pixmap(Window_t root_window) override;
Pixmap_t GetPixmap() override;
Bool_t GetMaskBits(UInt_t &width, UInt_t &height, std::vector<char> &bits) override;
Pixmap_t GetMask() override;
TArrayL *GetPixels(Int_t x = 0, Int_t y = 0, UInt_t w = 0, UInt_t h = 0) override;
TArrayD *GetArray(UInt_t w = 0, UInt_t h = 0, TImagePalette *pal = gWebImagePalette) override;
Expand Down
95 changes: 59 additions & 36 deletions graf2d/asimage/src/TASImage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2159,75 +2159,81 @@ void TASImage::StartPaletteEditor()
TAttImage::StartPaletteEditor();
}


////////////////////////////////////////////////////////////////////////////////
/// Returns image pixmap.
/// Returns image X11 pixmap.
/// Workrs only on the platforms with support of X11
/// The pixmap must deleted by user.

Pixmap_t TASImage::GetPixmap()
Pixmap_t TASImage::GetX11Pixmap(Window_t root_window)
{
if (!InitVisual()) {
Warning("GetPixmap", "Visual not initiated");
Warning("GetX11Pixmap", "Visual not initiated");
return 0;
}

Pixmap_t ret;

ASImage *img = fScaledImage ? fScaledImage->fImage : fImage;

static int x11 = -1;
if (x11 < 0) x11 = gVirtualX->InheritsFrom("TGX11");
return (Pixmap_t)asimage2pixmap(fgVisual, root_window, img, nullptr, kTRUE);
}

if (x11) { // use builtin version
ret = (Pixmap_t)asimage2pixmap(fgVisual, gVirtualX->GetDefaultRootWindow(),
img, nullptr, kTRUE);
} else {
if (!fImage->alt.argb32) {
BeginPaint();
}
ret = gVirtualX->CreatePixmapFromData((unsigned char*)fImage->alt.argb32,
fImage->width, fImage->height);
////////////////////////////////////////////////////////////////////////////////
/// DEPRECATED. Method left for backward compatibility and will be removed in ROOT7!
/// Returns image pixmap.
/// The pixmap must deleted by user.

Pixmap_t TASImage::GetPixmap()
{
static Bool_t x11 = gVirtualX->InheritsFrom("TGX11");

if (x11)
return GetX11Pixmap(gVirtualX->GetDefaultRootWindow());

auto argb = GetArgbArray();
if (!argb) {
Error("GetPixmap", "ARGB array is not exists");
return 0;
}

return ret;
return gVirtualX->CreatePixmapFromData((unsigned char*) argb, GetScaledWidth(), GetScaledHeight());
}

////////////////////////////////////////////////////////////////////////////////
/// Returns image mask pixmap (alpha channel).
/// The pixmap must deleted by user.
/// Returns image mask bits - only alpha channel of the image.
/// Also provides width and height which is aligned to 8 bits
/// Returns kTRUE if operation was successful

Pixmap_t TASImage::GetMask()
Bool_t TASImage::GetMaskBits(UInt_t &width, UInt_t &height, std::vector<char> &bits)
{
Pixmap_t pxmap = 0;

if (!InitVisual()) {
Warning("GetMask", "Visual not initiated");
return pxmap;
Warning("GetMaskBits", "Visual not initiated");
return kFALSE;
}

ASImage *img = fScaledImage ? fScaledImage->fImage : fImage;

if (!img) {
Warning("GetMask", "No image");
return pxmap;
Warning("GetMaskBits", "No image");
return kFALSE;
}

UInt_t hh = img->height;
UInt_t ow = img->width%8;
UInt_t ww = img->width - ow + (ow ? 8 : 0);
height = img->height;
UInt_t ow = img->width % 8;
width = img->width - ow + (ow ? 8 : 0);

ASImageDecoder *imdec = start_image_decoding(fgVisual, img, SCL_DO_ALPHA,
0, 0, ww, 0, nullptr);
0, 0, width, 0, nullptr);
if (!imdec)
return pxmap;
return kFALSE;

std::vector<char> bits(ww * hh / 8); //an array of bits
bits.resize(height * width / 8); //an array of bits

UInt_t bit = 0, i = 0;
for (UInt_t y = 0; y < hh; y++) {
for (UInt_t y = 0; y < height; y++) {
imdec->decode_image_scanline(imdec);
CARD32 *a = imdec->buffer.alpha;

for (UInt_t x = 0; x < ww; x++) {
for (UInt_t x = 0; x < width; x++) {
if (a[x]) {
SETBIT(bits[i], bit);
} else {
Expand All @@ -2241,8 +2247,25 @@ Pixmap_t TASImage::GetMask()
}

stop_image_decoding(&imdec);
pxmap = gVirtualX->CreateBitmap(gVirtualX->GetDefaultRootWindow(), bits.data(), ww, hh);
return pxmap;

return kTRUE;
}

////////////////////////////////////////////////////////////////////////////////
/// DEPRECATED! Method left for backward compatibility and will be removed in ROOT7!
/// Returns image mask pixmap (alpha channel).
/// The pixmap must deleted by user.

Pixmap_t TASImage::GetMask()
{
Pixmap_t pixmap = 0;

UInt_t ww = 0, hh = 0;
std::vector<char> bits;
if (GetMaskBits(ww, hh, bits))
pixmap = gVirtualX->CreateBitmap(gVirtualX->GetDefaultRootWindow(), bits.data(), ww, hh);

return pixmap;
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
11 changes: 8 additions & 3 deletions graf2d/graf/inc/TImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "TAttImage.h"
#include "GuiTypes.h"
#include "TVectorDfwd.h"
#include <vector>

class TVirtualPad;
class TArrayD;
Expand Down Expand Up @@ -132,7 +133,7 @@ friend TImage operator/(const TImage &i1, const TImage &s2);
virtual void FromX11Window(Window_t /* win */ , Int_t /* x */, Int_t /* y */, Int_t /* width */, Int_t /* height */) {}

// Create an image from gVirtualX window. (See TASImage::FromWindow)
virtual void FromWindow(Drawable_t /*wid*/, Int_t /*x*/ = 0, Int_t /*y*/ = 0, UInt_t /*w*/ = 0, UInt_t /*h*/ = 0) {}
virtual void R__DEPRECATED(7,00, "Use TGWindow::CreateImageFromWindow instead") FromWindow(Drawable_t /*wid*/, Int_t /*x*/ = 0, Int_t /*y*/ = 0, UInt_t /*w*/ = 0, UInt_t /*h*/ = 0) {}

// Create an image from GL buffer. (See TASImage::FromGLBuffer)
virtual void R__DEPRECATED(7,00, "Use FromBitmap instead") FromGLBuffer(UChar_t * /*buf*/, UInt_t /*w*/, UInt_t /*h*/) {}
Expand Down Expand Up @@ -244,13 +245,17 @@ friend TImage operator/(const TImage &i1, const TImage &s2);

virtual UInt_t GetWidth() const { return 0; }
virtual UInt_t GetHeight() const { return 0; }
virtual UInt_t GetScaledWidth() const { return 0; }
virtual UInt_t GetScaledHeight() const { return 0; }
virtual Bool_t IsValid() const { return kTRUE; }
virtual TImage *GetScaledImage() const { return nullptr; }

virtual TArrayL *GetPixels(Int_t /*x*/= 0, Int_t /*y*/= 0, UInt_t /*w*/ = 0, UInt_t /*h*/ = 0) { return nullptr; }
virtual TArrayD *GetArray(UInt_t /*w*/ = 0, UInt_t /*h*/ = 0, TImagePalette * = gWebImagePalette) { return nullptr; }
virtual Pixmap_t GetPixmap() { return 0; }
virtual Pixmap_t GetMask() { return 0; }
virtual Pixmap_t GetX11Pixmap(Window_t /* root_window */) { return 0; }
virtual Pixmap_t R__DEPRECATED(7,00, "Use TGWindow::GetImagePixmap instead") GetPixmap() { return 0; }
virtual Bool_t GetMaskBits(UInt_t & /* width */, UInt_t & /* height */, std::vector<char> & /* bits */) { return kFALSE; }
virtual Pixmap_t R__DEPRECATED(7,00, "Use TGWindow::GetImageMask instead") GetMask() { return 0; }
virtual UInt_t *GetArgbArray() { return nullptr; }
virtual UInt_t *GetRgbaArray() { return nullptr; }
virtual Double_t *GetVecArray() { return nullptr; }
Expand Down
7 changes: 6 additions & 1 deletion gui/gui/inc/TGWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@

#include "TGObject.h"
#include "TGClient.h"
#include <memory>

class TGClient;
class TGIdleHandler;

class TImage;

class TGWindow : public TGObject {

Expand Down Expand Up @@ -125,6 +126,10 @@ friend class TGClient;

static Int_t GetCounter();

static std::unique_ptr<TImage> CreateImageFromWindow(Drawable_t wid);
static Pixmap_t GetImagePixmap(TImage *img);
static Pixmap_t GetImageMask(TImage *img);

ClassDefOverride(TGWindow, 0); // GUI Window base class
};

Expand Down
4 changes: 2 additions & 2 deletions gui/gui/src/TGButton.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1111,12 +1111,12 @@ void TGPictureButton::CreateDisabledPicture()
TString back = gEnv->GetValue("Gui.BackgroundColor", "#c0c0c0");
img2->FillRectangle(back.Data(), 0, 0, fPic->GetWidth(), fPic->GetHeight());
img->SetImage(fPic->GetPicture(), fPic->GetMask());
Pixmap_t mask = img->GetMask();
Pixmap_t mask = GetImageMask(img);
img2->Merge(img, "overlay");

TString name = "disbl_";
name += fPic->GetName();
fPicD = fClient->GetPicturePool()->GetPicture(name.Data(), img2->GetPixmap(),
fPicD = fClient->GetPicturePool()->GetPicture(name.Data(), GetImagePixmap(img2),
mask);
fOwnDisabledPic = kTRUE;
delete img;
Expand Down
4 changes: 2 additions & 2 deletions gui/gui/src/TGFSContainer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ void TGFileContainer::GetFilePictures(const TGPicture **pic,
lnk_name = ((const TGPicture *)*pic)->GetName();
lnk_name.Prepend("lnk_");
*pic = fClient->GetPicturePool()->GetPicture(lnk_name.Data(),
img1->GetPixmap(), img1->GetMask());
GetImagePixmap(img1), GetImageMask(img1));
fCleanups->Add(((TObject *)*pic));
if (img2) delete img2;
delete img1;
Expand All @@ -718,7 +718,7 @@ void TGFileContainer::GetFilePictures(const TGPicture **pic,
lnk_name = ((const TGPicture *)*lpic)->GetName();
lnk_name.Prepend("lnk_");
*lpic = fClient->GetPicturePool()->GetPicture(lnk_name.Data(),
img1->GetPixmap(), img1->GetMask());
GetImagePixmap(img1), GetImageMask(img1));
fCleanups->Add(((TObject *)*lpic));
if (img2) delete img2;
delete img1;
Expand Down
21 changes: 9 additions & 12 deletions gui/gui/src/TGFileBrowser.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1160,19 +1160,17 @@ static Bool_t IsTextFile(const char *candidate)

static const TGPicture *MakeLinkPic(const TGPicture *pic)
{
const TGPicture *merged;
TImage *img1, *img2;
if (pic) {
img1 = TImage::Create();
if (img1 == 0) return pic;
auto img1 = TImage::Create();
if (!img1) return pic;
img1->SetImage(((const TGPicture *)pic)->GetPicture(),
((const TGPicture *)pic)->GetMask());
img2 = TImage::Open("slink_t.xpm");
auto img2 = TImage::Open("slink_t.xpm");
if (img2) img1->Merge(img2);
TString lnk_name = ((const TGPicture *)pic)->GetName();
lnk_name.Prepend("lnk_");
merged = gClient->GetPicturePool()->GetPicture(lnk_name.Data(),
img1->GetPixmap(), img1->GetMask());
auto merged = gClient->GetPicturePool()->GetPicture(lnk_name.Data(),
TGWindow::GetImagePixmap(img1), TGWindow::GetImageMask(img1));
if (img2) delete img2;
delete img1;
return merged;
Expand Down Expand Up @@ -1565,9 +1563,9 @@ char *TGFileBrowser::FormatFileInfo(const char *fname, Long64_t size, Long_t mod

void TGFileBrowser::GetObjPicture(const TGPicture **pic, TObject *obj)
{
const char *clname = 0;
TClass *objClass = 0;
static TImage *im = 0;
const char *clname = nullptr;
TClass *objClass = nullptr;
static TImage *im = nullptr;
if (!im) {
im = TImage::Create();
}
Expand Down Expand Up @@ -1616,8 +1614,7 @@ void TGFileBrowser::GetObjPicture(const TGPicture **pic, TObject *obj)
if (!(*pic) && xpm) {
if (im && im->SetImageBuffer((char**)&name, TImage::kXpm)) {
im->Scale(im->GetWidth()/4, im->GetHeight()/4);
*pic = gClient->GetPicturePool()->GetPicture(iconname, im->GetPixmap(),
im->GetMask());
*pic = gClient->GetPicturePool()->GetPicture(iconname, TGWindow::GetImagePixmap(im), TGWindow::GetImageMask(im));
}
gClient->GetMimeTypeList()->AddType("[thumbnail]", iconname, iconname, iconname, "->Browse()");
return;
Expand Down
11 changes: 4 additions & 7 deletions gui/gui/src/TGFrame.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1556,8 +1556,6 @@ Bool_t TGMainFrame::SaveFrameAsCodeOrImage()

Bool_t TGMainFrame::SaveFrameAsCodeOrImage(const TString &fileName)
{
static TString dir(".");

const TString fname = gSystem->UnixPathName(fileName);
if (fname.EndsWith(".C")) {
TGMainFrame *main = (TGMainFrame*)GetMainFrame();
Expand All @@ -1580,12 +1578,11 @@ Bool_t TGMainFrame::SaveFrameAsCodeOrImage(const TString &fileName)
if (gtype != TImage::kUnknown) {
Int_t saver = gErrorIgnoreLevel;
gErrorIgnoreLevel = kFatal;
TImage *img = TImage::Create();
RaiseWindow();
img->FromWindow(GetId());
img->WriteImage(fname, gtype);
auto img = TGWindow::CreateImageFromWindow(GetId());
if (img)
img->WriteImage(fname, gtype);
gErrorIgnoreLevel = saver;
delete img;
} else {
Error("SaveFrameAsCodeOrImage", "File cannot be saved with this extension");
return kFALSE;
Expand Down Expand Up @@ -1836,7 +1833,7 @@ void TGMainFrame::SetIconPixmap(char **xpm_array)
TImage *img = TImage::Create();
if (!img) return;
img->SetImageBuffer(xpm_array, TImage::kXpm);
Pixmap_t pic = img->GetPixmap();
Pixmap_t pic = GetImagePixmap(img);
if (pic) {
gVirtualX->SetIconPixmap(fId, pic);
} else {
Expand Down
4 changes: 2 additions & 2 deletions gui/gui/src/TGIcon.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ TGIcon::TGIcon(const TGWindow *p, const char *image) : TGFrame(p, 1, 1)
fImage = TImage::Open(path);
if (fImage) {
fPic = fClient->GetPicturePool()->GetPicture(gSystem->BaseName(path),
fImage->GetPixmap(), fImage->GetMask());
GetImagePixmap(fImage), GetImageMask(fImage));
TGFrame::Resize(fImage->GetWidth(), fImage->GetHeight());
}
SetWindowName();
Expand Down Expand Up @@ -155,7 +155,7 @@ void TGIcon::Resize(UInt_t w, UInt_t h)

fImage->Scale(w - 2*border, h - 2*border);
fPic = fClient->GetPicturePool()->GetPicture(fImage->GetName(),
fImage->GetPixmap(), fImage->GetMask());
GetImagePixmap(fImage), GetImageMask(fImage));
DoRedraw();
}

Expand Down
11 changes: 3 additions & 8 deletions gui/gui/src/TGObject.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ is based on the XClass'95 code (see Copyleft in source).


#include "TGObject.h"
#include "TVirtualX.h"
#include "TGWindow.h"
#include "TImage.h"
#include "TROOT.h"

Expand All @@ -55,14 +55,9 @@ void TGObject::SaveAs(const char* filename /*= ""*/, Option_t* option /*= ""*/)
{
TImage::EImageFileTypes type = TImage::GetImageFileTypeFromFilename(filename);
if (type != TImage::kUnknown) {
WindowAttributes_t wattr;
gVirtualX->GetWindowAttributes(GetId(), wattr);
TImage* img = TImage::Create();
if (img) {
img->FromWindow(GetId(), 0, 0, wattr.fWidth, wattr.fHeight);
auto img = TGWindow::CreateImageFromWindow(GetId());
if (img)
img->WriteImage(filename, type);
delete img;
}
return;
}

Expand Down
Loading
Loading