Skip to content
Open
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
1 change: 1 addition & 0 deletions core/base/inc/TVirtualPS.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class TVirtualPS : public TNamed, public TAttLine, public TAttFill, public TAttM
virtual ~TVirtualPS();
virtual void CellArrayBegin(Int_t W, Int_t H, Double_t x1, Double_t x2, Double_t y1, Double_t y2) = 0;
virtual void CellArrayFill(Int_t r, Int_t g, Int_t b) = 0;
virtual void CellArrayPng(char * /* buffer */, int /* size */) {}
virtual void CellArrayEnd() = 0;
virtual void Close(Option_t *opt="") = 0;
virtual void DrawBox(Double_t x1, Double_t y1,Double_t x2, Double_t y2) = 0;
Expand Down
93 changes: 60 additions & 33 deletions graf2d/asimage/src/TASImage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1337,6 +1337,7 @@ void TASImage::Image2Drawable(ASImage *im, Drawable_t wid, Int_t x, Int_t y,
if (gc) gVirtualX->ChangeGC(gc, &gv);
}


////////////////////////////////////////////////////////////////////////////////
/// Draw image on the drawable wid (pixmap, window) at x,y position.
///
Expand Down Expand Up @@ -1562,6 +1563,9 @@ void TASImage::Paint(Option_t *option)

// loop over pixmap and draw image to PostScript
if (gVirtualPS) {

Bool_t paint_as_png = kFALSE;

if (gVirtualPS->InheritsFrom("TImageDump")) { // PostScript is asimage
TImage *dump = (TImage *)gVirtualPS->GetStream();
if (!dump) return;
Expand Down Expand Up @@ -1589,23 +1593,12 @@ void TASImage::Paint(Option_t *option)
Warning("Paint", "PDF not implemented yet");
return;
} else if (gVirtualPS->InheritsFrom("TSVG")) {
Warning("Paint", "SVG not implemented yet");
return;
paint_as_png = kTRUE;
}

// get special color cell to be reused during image printing
TObjArray *colors = (TObjArray*) gROOT->GetListOfColors();
TColor *color = nullptr;
// Look for color by name
if ((color = (TColor*)colors->FindObject("Image_PS")) == nullptr)
color = new TColor(colors->GetEntries(), 1., 1., 1., "Image_PS");

gVirtualPS->SetFillColor(color->GetNumber());
gVirtualPS->SetFillStyle(1001);

Double_t dx = gPad->GetX2()-gPad->GetX1();
Double_t dy = gPad->GetY2()-gPad->GetY1();
Double_t x1,x2,y1,y2;
Double_t x1, x2, y1, y2;

if (expand) {
x1 = gPad->GetX1();
Expand All @@ -1619,19 +1612,38 @@ void TASImage::Paint(Option_t *option)
y2 = y1+(dy*(1-gPad->GetTopMargin()-gPad->GetBottomMargin()))/image->height;
}

// get special color cell to be reused during image printing
gVirtualPS->SetFillColor(TColor::GetColor((Float_t) 1., (Float_t) 1., (Float_t) 1.));
gVirtualPS->SetFillStyle(1001);

gVirtualPS->CellArrayBegin(image->width, image->height, x1, x2, y1, y2);

ASImageDecoder *imdec = start_image_decoding(fgVisual, image, SCL_DO_ALL,
0, 0, image->width, image->height, nullptr);
if (!imdec) return;
for (Int_t yt = 0; yt < (Int_t)image->height; yt++) {
imdec->decode_image_scanline(imdec);
for (Int_t xt = 0; xt < (Int_t)image->width; xt++)
gVirtualPS->CellArrayFill(imdec->buffer.red[xt],
imdec->buffer.green[xt],
imdec->buffer.blue[xt]);
if (paint_as_png) {
char *buffer = nullptr;
int size = 0;
ASImageExportParams params;
params.png.type = ASIT_Png;
params.png.flags = EXPORT_ALPHA;
params.png.compression = GetImageCompression();
if (!params.png.compression)
params.png.compression = -1;
if (ASImage2PNGBuff(image, (CARD8 **)&buffer, &size, &params)) {
gVirtualPS->CellArrayPng(buffer, size);
free(buffer);
}
} else {
auto imdec = start_image_decoding(fgVisual, image, SCL_DO_ALL,
0, 0, image->width, image->height, nullptr);
if (imdec)
for (Int_t yt = 0; yt < (Int_t)image->height; yt++) {
imdec->decode_image_scanline(imdec);
for (Int_t xt = 0; xt < (Int_t)image->width; xt++)
gVirtualPS->CellArrayFill(imdec->buffer.red[xt],
imdec->buffer.green[xt],
imdec->buffer.blue[xt]);
}
stop_image_decoding(&imdec);
}
stop_image_decoding(&imdec);
gVirtualPS->CellArrayEnd();

// print the color bar
Expand All @@ -1645,18 +1657,33 @@ void TASImage::Paint(Option_t *option)
gVirtualPS->CellArrayBegin(grad_im->width, grad_im->height,
x1, x2, y1, y2);

imdec = start_image_decoding(fgVisual, grad_im, SCL_DO_ALL,
0, 0, grad_im->width, grad_im->height, nullptr);
if (imdec) {
for (Int_t yt = 0; yt < (Int_t)grad_im->height; yt++) {
imdec->decode_image_scanline(imdec);
for (Int_t xt = 0; xt < (Int_t)grad_im->width; xt++)
gVirtualPS->CellArrayFill(imdec->buffer.red[xt],
imdec->buffer.green[xt],
imdec->buffer.blue[xt]);
if (paint_as_png) {
char *buffer = nullptr;
int size = 0;
ASImageExportParams params;
params.png.type = ASIT_Png;
params.png.flags = EXPORT_ALPHA;
params.png.compression = GetImageCompression();
if (!params.png.compression)
params.png.compression = -1;

if (ASImage2PNGBuff(grad_im, (CARD8 **)&buffer, &size, &params)) {
gVirtualPS->CellArrayPng(buffer, size);
free(buffer);
}
} else {
auto imdec = start_image_decoding(fgVisual, grad_im, SCL_DO_ALL,
0, 0, grad_im->width, grad_im->height, nullptr);
if (imdec)
for (Int_t yt = 0; yt < (Int_t)grad_im->height; yt++) {
imdec->decode_image_scanline(imdec);
for (Int_t xt = 0; xt < (Int_t)grad_im->width; xt++)
gVirtualPS->CellArrayFill(imdec->buffer.red[xt],
imdec->buffer.green[xt],
imdec->buffer.blue[xt]);
}
stop_image_decoding(&imdec);
}
stop_image_decoding(&imdec);
gVirtualPS->CellArrayEnd();

// values of palette
Expand Down
1 change: 1 addition & 0 deletions graf2d/postscript/inc/TSVG.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class TSVG : public TVirtualPS {

void CellArrayBegin(Int_t W, Int_t H, Double_t x1, Double_t x2, Double_t y1, Double_t y2) override;
void CellArrayFill(Int_t r, Int_t g, Int_t b) override;
void CellArrayPng(char *buffer, int size) override;
void CellArrayEnd() override;
void Close(Option_t *opt="") override;
Double_t CMtoSVG(Double_t u) { return 0.5 + 72*u/2.54; }
Expand Down
75 changes: 50 additions & 25 deletions graf2d/postscript/src/TSVG.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "TROOT.h"
#include "TDatime.h"
#include "TBase64.h"
#include "TColor.h"
#include "TVirtualPad.h"
#include "TPoints.h"
Expand Down Expand Up @@ -944,6 +945,55 @@ void TSVG::DrawPS(Int_t nn, Double_t *xw, Double_t *yw)
PrintFast(2,"/>");
}

////////////////////////////////////////////////////////////////////////////////
/// Begin the Cell Array painting

void TSVG::CellArrayBegin(Int_t width, Int_t height, Double_t x1, Double_t x2, Double_t y1, Double_t y2)
{
Double_t svgx1 = XtoSVG(x1);
Double_t svgx2 = XtoSVG(x1 + (x2 - x1) * width);
Double_t svgy1 = YtoSVG(y1);
Double_t svgy2 = YtoSVG(y1 - (y2 - y1) * height);

PrintStr("@<g transform=\"translate(");
WriteReal(svgx1, kFALSE);
WriteReal(svgy1, kTRUE);
PrintStr(") scale(");
WriteReal((svgx2 - svgx1) / width, kFALSE);
WriteReal((svgy2 - svgy1) / height, kTRUE);
PrintStr(")\">@");
PrintStr(TString::Format("<image width=\"%d\" height=\"%d\" href=\"data:image/png;base64,", width, height));
}

////////////////////////////////////////////////////////////////////////////////
/// Paint the Cell Array as single pixel

void TSVG::CellArrayFill(Int_t, Int_t, Int_t)
{
Warning("CellArrayFill", "not implemented");
}

////////////////////////////////////////////////////////////////////////////////
/// Paint the Cell Array as png image
/// Disabled in compact mode to avoid creation of large SVG files

void TSVG::CellArrayPng(char *buffer, int size)
{
if (!fCompact) {
TString base64 = TBase64::Encode(reinterpret_cast<char *>(buffer), size);
PrintFast(base64.Length(), base64.Data());
}
}

////////////////////////////////////////////////////////////////////////////////
/// End the Cell Array painting

void TSVG::CellArrayEnd()
{
PrintStr("\"></image>@");
PrintStr("</g>@");
}

////////////////////////////////////////////////////////////////////////////////
/// Initialize the SVG file. The main task of the function is to output the
/// SVG header file which consist in `<title>`, `<desc>` and `<defs>`. The
Expand Down Expand Up @@ -1508,31 +1558,6 @@ Double_t TSVG::YtoSVG(Double_t y)
return fYsizeSVG-VtoSVG(v);
}

////////////////////////////////////////////////////////////////////////////////
/// Begin the Cell Array painting

void TSVG::CellArrayBegin(Int_t, Int_t, Double_t, Double_t, Double_t,
Double_t)
{
Warning("TSVG::CellArrayBegin", "not yet implemented");
}

////////////////////////////////////////////////////////////////////////////////
/// Paint the Cell Array

void TSVG::CellArrayFill(Int_t, Int_t, Int_t)
{
Warning("TSVG::CellArrayFill", "not yet implemented");
}

////////////////////////////////////////////////////////////////////////////////
/// End the Cell Array painting

void TSVG::CellArrayEnd()
{
Warning("TSVG::CellArrayEnd", "not yet implemented");
}

////////////////////////////////////////////////////////////////////////////////
/// Not needed in SVG case

Expand Down
15 changes: 14 additions & 1 deletion test/svg_ref/timage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading