Skip to content

Commit a004c57

Browse files
committed
Use CellArrayPng for SVG output in TASImage
One converts image to PNG and then paint it as base64
1 parent e409362 commit a004c57

File tree

1 file changed

+66
-33
lines changed

1 file changed

+66
-33
lines changed

graf2d/asimage/src/TASImage.cxx

Lines changed: 66 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,7 @@ void TASImage::Image2Drawable(ASImage *im, Drawable_t wid, Int_t x, Int_t y,
13371337
if (gc) gVirtualX->ChangeGC(gc, &gv);
13381338
}
13391339

1340+
13401341
////////////////////////////////////////////////////////////////////////////////
13411342
/// Draw image on the drawable wid (pixmap, window) at x,y position.
13421343
///
@@ -1562,6 +1563,9 @@ void TASImage::Paint(Option_t *option)
15621563

15631564
// loop over pixmap and draw image to PostScript
15641565
if (gVirtualPS) {
1566+
1567+
Bool_t paint_as_png = kFALSE;
1568+
15651569
if (gVirtualPS->InheritsFrom("TImageDump")) { // PostScript is asimage
15661570
TImage *dump = (TImage *)gVirtualPS->GetStream();
15671571
if (!dump) return;
@@ -1589,23 +1593,12 @@ void TASImage::Paint(Option_t *option)
15891593
Warning("Paint", "PDF not implemented yet");
15901594
return;
15911595
} else if (gVirtualPS->InheritsFrom("TSVG")) {
1592-
Warning("Paint", "SVG not implemented yet");
1593-
return;
1596+
paint_as_png = kTRUE;
15941597
}
15951598

1596-
// get special color cell to be reused during image printing
1597-
TObjArray *colors = (TObjArray*) gROOT->GetListOfColors();
1598-
TColor *color = nullptr;
1599-
// Look for color by name
1600-
if ((color = (TColor*)colors->FindObject("Image_PS")) == nullptr)
1601-
color = new TColor(colors->GetEntries(), 1., 1., 1., "Image_PS");
1602-
1603-
gVirtualPS->SetFillColor(color->GetNumber());
1604-
gVirtualPS->SetFillStyle(1001);
1605-
16061599
Double_t dx = gPad->GetX2()-gPad->GetX1();
16071600
Double_t dy = gPad->GetY2()-gPad->GetY1();
1608-
Double_t x1,x2,y1,y2;
1601+
Double_t x1, x2, y1, y2;
16091602

16101603
if (expand) {
16111604
x1 = gPad->GetX1();
@@ -1619,19 +1612,44 @@ void TASImage::Paint(Option_t *option)
16191612
y2 = y1+(dy*(1-gPad->GetTopMargin()-gPad->GetBottomMargin()))/image->height;
16201613
}
16211614

1615+
// get special color cell to be reused during image printing
1616+
TObjArray *colors = (TObjArray*) gROOT->GetListOfColors();
1617+
TColor *color = nullptr;
1618+
// Look for color by name
1619+
if ((color = (TColor*)colors->FindObject("Image_PS")) == nullptr)
1620+
color = new TColor(colors->GetEntries(), 1., 1., 1., "Image_PS");
1621+
1622+
gVirtualPS->SetFillColor(color->GetNumber());
1623+
gVirtualPS->SetFillStyle(1001);
1624+
16221625
gVirtualPS->CellArrayBegin(image->width, image->height, x1, x2, y1, y2);
16231626

1624-
ASImageDecoder *imdec = start_image_decoding(fgVisual, image, SCL_DO_ALL,
1625-
0, 0, image->width, image->height, nullptr);
1626-
if (!imdec) return;
1627-
for (Int_t yt = 0; yt < (Int_t)image->height; yt++) {
1628-
imdec->decode_image_scanline(imdec);
1629-
for (Int_t xt = 0; xt < (Int_t)image->width; xt++)
1630-
gVirtualPS->CellArrayFill(imdec->buffer.red[xt],
1631-
imdec->buffer.green[xt],
1632-
imdec->buffer.blue[xt]);
1627+
if (paint_as_png) {
1628+
char *buffer = nullptr;
1629+
int size = 0;
1630+
ASImageExportParams params;
1631+
params.png.type = ASIT_Png;
1632+
params.png.flags = EXPORT_ALPHA;
1633+
params.png.compression = GetImageCompression();
1634+
if (!params.png.compression)
1635+
params.png.compression = -1;
1636+
if (ASImage2PNGBuff(image, (CARD8 **)&buffer, &size, &params)) {
1637+
gVirtualPS->CellArrayPng(buffer, size);
1638+
free(buffer);
1639+
}
1640+
} else {
1641+
auto imdec = start_image_decoding(fgVisual, image, SCL_DO_ALL,
1642+
0, 0, image->width, image->height, nullptr);
1643+
if (imdec)
1644+
for (Int_t yt = 0; yt < (Int_t)image->height; yt++) {
1645+
imdec->decode_image_scanline(imdec);
1646+
for (Int_t xt = 0; xt < (Int_t)image->width; xt++)
1647+
gVirtualPS->CellArrayFill(imdec->buffer.red[xt],
1648+
imdec->buffer.green[xt],
1649+
imdec->buffer.blue[xt]);
1650+
}
1651+
stop_image_decoding(&imdec);
16331652
}
1634-
stop_image_decoding(&imdec);
16351653
gVirtualPS->CellArrayEnd();
16361654

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

1648-
imdec = start_image_decoding(fgVisual, grad_im, SCL_DO_ALL,
1649-
0, 0, grad_im->width, grad_im->height, nullptr);
1650-
if (imdec) {
1651-
for (Int_t yt = 0; yt < (Int_t)grad_im->height; yt++) {
1652-
imdec->decode_image_scanline(imdec);
1653-
for (Int_t xt = 0; xt < (Int_t)grad_im->width; xt++)
1654-
gVirtualPS->CellArrayFill(imdec->buffer.red[xt],
1655-
imdec->buffer.green[xt],
1656-
imdec->buffer.blue[xt]);
1666+
if (paint_as_png) {
1667+
char *buffer = nullptr;
1668+
int size = 0;
1669+
ASImageExportParams params;
1670+
params.png.type = ASIT_Png;
1671+
params.png.flags = EXPORT_ALPHA;
1672+
params.png.compression = GetImageCompression();
1673+
if (!params.png.compression)
1674+
params.png.compression = -1;
1675+
1676+
if (ASImage2PNGBuff(grad_im, (CARD8 **)&buffer, &size, &params)) {
1677+
gVirtualPS->CellArrayPng(buffer, size);
1678+
free(buffer);
16571679
}
1680+
} else {
1681+
auto imdec = start_image_decoding(fgVisual, grad_im, SCL_DO_ALL,
1682+
0, 0, grad_im->width, grad_im->height, nullptr);
1683+
if (imdec)
1684+
for (Int_t yt = 0; yt < (Int_t)grad_im->height; yt++) {
1685+
imdec->decode_image_scanline(imdec);
1686+
for (Int_t xt = 0; xt < (Int_t)grad_im->width; xt++)
1687+
gVirtualPS->CellArrayFill(imdec->buffer.red[xt],
1688+
imdec->buffer.green[xt],
1689+
imdec->buffer.blue[xt]);
1690+
}
1691+
stop_image_decoding(&imdec);
16581692
}
1659-
stop_image_decoding(&imdec);
16601693
gVirtualPS->CellArrayEnd();
16611694

16621695
// values of palette

0 commit comments

Comments
 (0)