22 #include "TGLIncludes.h" 54 std::unique_lock<std::mutex> lk(
m_moo);
83 std::unique_lock<std::mutex> lko(
m_moo);
85 m_thr =
new std::thread([=]() {
86 { std::unique_lock<std::mutex> lk(
m_moo);
m_cnd.notify_one(); }
90 std::unique_lock<std::mutex> lk(
m_moo);
98 if (
m_name.EndsWith(
".jpg"))
118 TGCompositeFrame* cf = GetGUICompositeFrame();
123 cf->AddFrame(fGLViewerFrame,
new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY));
125 fGLViewerFrame->MapWindow();
127 if (fEveFrame ==
nullptr)
136 static const TString eh(
"FWTEveViewer::CaptureAndSaveImage");
138 TGLFBO *fbo =
nullptr;
146 ::Error(eh,
"Returned FBO is 0.");
147 m_prom = std::promise<int>();
149 return m_prom.get_future();
153 if (fbo->GetIsRescaled())
155 ww = TMath::Nint(fbo->GetW() * fbo->GetWScale());
156 hh = TMath::Nint(fbo->GetH() * fbo->GetHScale());
164 fbo->SetAsReadBuffer();
166 size_t bufsize = 3 * ww * hh;
172 glPixelStorei(GL_PACK_ALIGNMENT, 1);
173 glReadPixels(0, 0, ww, hh, GL_RGB, GL_UNSIGNED_BYTE, &
m_imgBuffer[0]);
178 std::unique_lock<std::mutex> lk(
m_moo);
180 m_prom = std::promise<int>();
188 return m_prom.get_future();
210 png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
nullptr,
nullptr,
nullptr);
211 if (png_ptr ==
nullptr) {
212 printf(
"Error creating png write struct\n");
217 info_ptr = png_create_info_struct(png_ptr);
218 if (info_ptr ==
nullptr) {
219 printf(
"Error creating png info struct\n");
220 png_destroy_write_struct(&png_ptr, &info_ptr);
233 FILE *fp = fopen(file,
"w");
235 png_init_io(png_ptr, fp);
239 png_set_IHDR(png_ptr, info_ptr, ww, hh, 8, PNG_COLOR_TYPE_RGB,
240 PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
255 png_write_info(png_ptr, info_ptr);
257 std::vector<UChar_t*>
rows(hh);
260 for (
int i = 0;
i < hh;
i++, j--) {
261 rows[
i] = xx + j * ww * 3;
266 png_write_image(png_ptr, &rows[0]);
269 png_write_end(png_ptr, info_ptr);
272 png_destroy_write_struct(&png_ptr, &info_ptr);
281 struct jpeg_compress_struct JpegInfo;
282 struct jpeg_error_mgr Error;
284 JpegInfo.err = jpeg_std_error(&Error);
287 jpeg_create_compress(&JpegInfo);
289 FILE *fp = fopen(file,
"w");
290 jpeg_stdio_dest(&JpegInfo, fp);
292 JpegInfo.image_width = ww;
293 JpegInfo.image_height = hh;
294 JpegInfo.input_components = 3;
295 JpegInfo.in_color_space = JCS_RGB;
297 jpeg_set_defaults(&JpegInfo);
299 JpegInfo.write_JFIF_header =
TRUE;
305 jpeg_start_compress(&JpegInfo,
TRUE);
307 std::vector<UChar_t*>
rows(hh);
310 for (
int i = 0;
i < hh;
i++, j--) {
311 rows[
i] = xx + j * ww * 3;
315 jpeg_write_scanlines(&JpegInfo, &rows[0], hh);
318 jpeg_finish_compress(&JpegInfo);
323 jpeg_destroy_compress(&JpegInfo);
TGLFBO * MakeFboHeight(Int_t height, Bool_t pixel_object_scale=kTRUE)
std::condition_variable m_cnd
std::vector< unsigned char > m_imgBuffer
FWTEveViewer(const char *n="FWTEveViewer", const char *t="")
std::promise< int > m_prom
static bool SaveJpg(const TString &file, UChar_t *xx, int ww, int hh)
std::future< int > CaptureAndSaveImage(const TString &file, int height=-1)
FWTGLViewer * m_fwGlViewer
static bool SavePng(const TString &file, UChar_t *xx, int ww, int hh)
FWTGLViewer * SpawnFWTGLViewer()
void spawn_image_thread()