20 #include "RConfigure.h"
23 # define X_DISPLAY_MISSING 1
24 # define popen_flags "r"
26 # include "Windows4root.h"
27 # define popen_flags "rb"
29 # include <X11/Xlib.h>
30 # define popen_flags "r"
34 # include <afterbase.h>
36 # include <win32/config.h>
37 # include <win32/afterbase.h>
38 # define X_DISPLAY_MISSING 1
43 ClassImp(TASPluginGS);
48 TASPluginGS::TASPluginGS(
const char *ext) : TASImagePlugin(ext)
51 fInterpreter = gSystem->Which(gSystem->Getenv(
"PATH"),
"gs", kExecutePermission);
53 fInterpreter = gSystem->Which(gSystem->Getenv(
"PATH"),
"gswin32c.exe", kExecutePermission);
56 delete [] fInterpreter;
57 fInterpreter = StrDup(
"gswin32c.exe");
65 TASPluginGS::~TASPluginGS()
67 delete [] fInterpreter;
74 ASImage *TASPluginGS::File2ASImage(
const char *filename)
77 Warning(
"File2ASImage",
"GhostScript is not available");
81 if (gSystem->AccessPathName(filename)) {
82 Warning(
"File2ASImage",
"input file %s is not accessible", filename);
86 TString ext = (strrchr(filename,
'.') + 1);
96 FILE *fd = fopen(filename,
"r");
98 Warning(
"File2ASImage",
"input file %s is not readable", filename);
104 TString line = fgets(buf, 128, fd);
105 if (line.IsNull() || !line.BeginsWith(
"%"))
break;
107 if (line.BeginsWith(
"%%BoundingBox:")) {
109 line = line(14, line.Length());
110 sscanf(line.Data(),
"%d %d %d %d", &lx, &ly, &ux, &uy);
111 width = TMath::Abs(ux - lx);
112 height = TMath::Abs(uy - ly);
121 TString cmd = fInterpreter;
123 cmd += Form(
" -g%dx%d", width, height);
125 cmd +=
" -dSAFER -dBATCH -dNOPAUSE -dQUIET -sDEVICE=png16m -dGraphicsAlphaBits=4 -sOutputFile=- ";
127 FILE *in = gSystem->OpenPipe(cmd.Data(), popen_flags);
133 const UInt_t kBuffLength = 32768;
134 static char buf[kBuffLength];
138 Long_t r = fread(&buf, 1, kBuffLength, in);
139 raw.Append((
const char*)&buf, r);
142 gSystem->ClosePipe(in);
144 ASImageImportParams params;
146 params.width = width;
147 params.height = height;
148 params.filter = SCL_DO_ALL;
150 params.gamma_table = 0;
151 params.compression = 0;
152 params.format = ASA_ASImage;
153 params.search_path = 0;
156 ASImage *ret = PNGBuff2ASimage((CARD8 *)raw.Data(), ¶ms);