21 #include "TGLIncludes.h"
50 std::unique_lock<std::mutex> lk(
m_moo);
78 std::unique_lock<std::mutex> lko(
m_moo);
80 m_thr =
new std::thread([=]() {
82 std::unique_lock<std::mutex> lk(
m_moo);
87 std::unique_lock<std::mutex> lk(
m_moo);
94 if (
m_name.EndsWith(
".jpg")) {
110 TGCompositeFrame* cf = GetGUICompositeFrame();
115 cf->AddFrame(fGLViewerFrame,
new TGLayoutHints(kLHintsNormal | kLHintsExpandX | kLHintsExpandY));
117 fGLViewerFrame->MapWindow();
119 if (fEveFrame ==
nullptr)
126 static const TString eh(
"FWTEveViewer::CaptureAndSaveImage");
128 TGLFBO* fbo =
nullptr;
134 if (fbo ==
nullptr) {
135 ::Error(eh,
"Returned FBO is 0.");
136 m_prom = std::promise<int>();
138 return m_prom.get_future();
142 if (fbo->GetIsRescaled()) {
143 ww = TMath::Nint(fbo->GetW() * fbo->GetWScale());
144 hh = TMath::Nint(fbo->GetH() * fbo->GetHScale());
150 fbo->SetAsReadBuffer();
152 size_t bufsize = 3 * ww *
hh;
157 glPixelStorei(GL_PACK_ALIGNMENT, 1);
158 glReadPixels(0, 0, ww,
hh, GL_RGB, GL_UNSIGNED_BYTE, &
m_imgBuffer[0]);
160 if (
m_thr ==
nullptr)
164 std::unique_lock<std::mutex> lk(
m_moo);
166 m_prom = std::promise<int>();
174 return m_prom.get_future();
195 png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
nullptr,
nullptr,
nullptr);
196 if (png_ptr ==
nullptr) {
197 printf(
"Error creating png write struct\n");
202 info_ptr = png_create_info_struct(png_ptr);
203 if (info_ptr ==
nullptr) {
204 printf(
"Error creating png info struct\n");
205 png_destroy_write_struct(&png_ptr, &info_ptr);
218 FILE*
fp = fopen(
file,
"w");
220 png_init_io(png_ptr,
fp);
223 png_set_IHDR(png_ptr,
230 PNG_COMPRESSION_TYPE_BASE,
231 PNG_FILTER_TYPE_BASE);
246 png_write_info(png_ptr, info_ptr);
248 std::vector<UChar_t*>
rows(
hh);
251 for (
int i = 0;
i <
hh;
i++,
j--) {
257 png_write_image(png_ptr, &
rows[0]);
260 png_write_end(png_ptr, info_ptr);
263 png_destroy_write_struct(&png_ptr, &info_ptr);
271 struct jpeg_compress_struct JpegInfo;
272 struct jpeg_error_mgr
Error;
274 JpegInfo.err = jpeg_std_error(&
Error);
277 jpeg_create_compress(&JpegInfo);
279 FILE*
fp = fopen(
file,
"w");
280 jpeg_stdio_dest(&JpegInfo,
fp);
282 JpegInfo.image_width = ww;
283 JpegInfo.image_height =
hh;
284 JpegInfo.input_components = 3;
285 JpegInfo.in_color_space = JCS_RGB;
287 jpeg_set_defaults(&JpegInfo);
289 JpegInfo.write_JFIF_header =
TRUE;
295 jpeg_start_compress(&JpegInfo,
TRUE);
297 std::vector<UChar_t*>
rows(
hh);
300 for (
int i = 0;
i <
hh;
i++,
j--) {
305 jpeg_write_scanlines(&JpegInfo, &
rows[0],
hh);
308 jpeg_finish_compress(&JpegInfo);
313 jpeg_destroy_compress(&JpegInfo);