22 #include "TGLIncludes.h"
23 #define protected public
56 std::unique_lock<std::mutex> lk(
m_moo);
85 std::unique_lock<std::mutex> lko(
m_moo);
87 m_thr =
new std::thread([=]() {
88 { std::unique_lock<std::mutex> lk(
m_moo);
m_cnd.notify_one(); }
92 std::unique_lock<std::mutex> lk(
m_moo);
100 if (
m_name.EndsWith(
".jpg"))
120 TGCompositeFrame* cf = GetGUICompositeFrame();
125 cf->AddFrame(fGLViewerFrame,
new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY));
127 fGLViewerFrame->MapWindow();
138 static const TString eh(
"FWTEveViewer::CaptureAndSaveImage");
148 ::Error(eh,
"Returned FBO is 0.");
149 m_prom = std::promise<int>();
151 return m_prom.get_future();
155 if (fbo->fIsRescaled)
157 ww = TMath::Nint(fbo->fW * fbo->fWScale);
158 hh = TMath::Nint(fbo->fH * fbo->fHScale);
166 fbo->SetAsReadBuffer();
168 size_t bufsize = 3 * ww * hh;
174 glPixelStorei(GL_PACK_ALIGNMENT, 1);
175 glReadPixels(0, 0, ww, hh, GL_RGB, GL_UNSIGNED_BYTE, &
m_imgBuffer[0]);
180 std::unique_lock<std::mutex> lk(
m_moo);
182 m_prom = std::promise<int>();
190 return m_prom.get_future();
212 png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
NULL, 0, 0);
213 if (png_ptr ==
NULL) {
214 printf(
"Error creating png write struct\n");
219 info_ptr = png_create_info_struct(png_ptr);
220 if (info_ptr ==
NULL) {
221 printf(
"Error creating png info struct\n");
222 png_destroy_write_struct(&png_ptr, &info_ptr);
235 FILE *fp = fopen(file,
"w");
237 png_init_io(png_ptr, fp);
241 png_set_IHDR(png_ptr, info_ptr, ww, hh, 8, PNG_COLOR_TYPE_RGB,
242 PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
257 png_write_info(png_ptr, info_ptr);
259 std::vector<UChar_t*>
rows(hh);
262 for (
int i = 0;
i < hh;
i++, j--) {
263 rows[
i] = xx + j * ww * 3;
268 png_write_image(png_ptr, &rows[0]);
271 png_write_end(png_ptr, info_ptr);
274 png_destroy_write_struct(&png_ptr, &info_ptr);
283 struct jpeg_compress_struct JpegInfo;
284 struct jpeg_error_mgr Error;
286 JpegInfo.err = jpeg_std_error(&Error);
289 jpeg_create_compress(&JpegInfo);
291 FILE *fp = fopen(file,
"w");
292 jpeg_stdio_dest(&JpegInfo, fp);
294 JpegInfo.image_width = ww;
295 JpegInfo.image_height = hh;
296 JpegInfo.input_components = 3;
297 JpegInfo.in_color_space = JCS_RGB;
299 jpeg_set_defaults(&JpegInfo);
301 JpegInfo.write_JFIF_header =
TRUE;
307 jpeg_start_compress(&JpegInfo,
TRUE);
309 std::vector<UChar_t*>
rows(hh);
312 for (
int i = 0;
i < hh;
i++, j--) {
313 rows[
i] = xx + j * ww * 3;
317 jpeg_write_scanlines(&JpegInfo, &rows[0], hh);
320 jpeg_finish_compress(&JpegInfo);
325 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()