|
27 | 27 | #include <mutex> |
28 | 28 | #include <chrono> |
29 | 29 | #include <thread> |
| 30 | +#include <filesystem> |
30 | 31 |
|
31 | 32 | std::mutex mtx; // mutex for critical section |
32 | 33 |
|
@@ -152,34 +153,52 @@ namespace o2 |
152 | 153 | if (not setInTick()) { |
153 | 154 | return; |
154 | 155 | } |
155 | | - UInt_t width = 2 * 1920; |
156 | | - UInt_t height = 2 * 1080; |
| 156 | + UInt_t width = 3840; |
| 157 | + UInt_t height = 2160; |
| 158 | + UInt_t font_size = 30; |
| 159 | + UInt_t text_leading = 40; |
| 160 | + const char* fontColor = "#FFFFFF"; |
| 161 | + const char* backgroundColor = "#19324b"; |
| 162 | + const char* outDirectory = "Screenshots"; |
157 | 163 |
|
158 | 164 | std::string runString = "Run:"; |
159 | 165 | std::string timestampString = "Timestamp:"; |
160 | 166 | std::string collidingsystemString = "Colliding system:"; |
161 | 167 | std::string energyString = "Energy:"; |
162 | 168 |
|
| 169 | + std::time_t time = std::time(nullptr); |
| 170 | + char time_str[100]; |
| 171 | + std::strftime(time_str, sizeof(time_str), "%Y_%m_%d_%H_%M_%S", std::localtime(&time)); |
| 172 | + |
| 173 | + std::ostringstream filepath; |
| 174 | + filepath << outDirectory << "/Screenshot_" << time_str << ".png"; |
| 175 | + |
163 | 176 | TASImage image(width, height); |
164 | 177 |
|
| 178 | + image.FillRectangle(backgroundColor, 0, 0, width, height); |
| 179 | + |
165 | 180 | TImage* view3dImage = MultiView::getInstance()->getView(MultiView::EViews::View3d)->GetGLViewer()->GetPictureUsingBB(); |
166 | | - view3dImage->Scale(width * 0.66, height); |
167 | | - view3dImage->CopyArea(&image, 0, 0, view3dImage->GetWidth(), view3dImage->GetHeight(), 0, 0); |
| 181 | + view3dImage->Scale(width * 0.65, height * 0.95); |
| 182 | + CopyImage(&image, (TASImage*)view3dImage, width * 0.015, height * 0.025, 0, 0, view3dImage->GetWidth(), view3dImage->GetHeight()); |
168 | 183 |
|
169 | 184 | TImage* viewRphiImage = MultiView::getInstance()->getView(MultiView::EViews::ViewRphi)->GetGLViewer()->GetPictureUsingBB(); |
170 | | - viewRphiImage->Scale(width * 0.33, height * 0.5); |
171 | | - viewRphiImage->CopyArea(&image, 0, 0, viewRphiImage->GetWidth(), viewRphiImage->GetHeight(), width * 0.66, 0); |
| 185 | + viewRphiImage->Scale(width * 0.3, height * 0.45); |
| 186 | + CopyImage(&image, (TASImage*)viewRphiImage, width * 0.68, height * 0.025, 0, 0, viewRphiImage->GetWidth(), viewRphiImage->GetHeight()); |
172 | 187 |
|
173 | 188 | TImage* viewZrhoImage = MultiView::getInstance()->getView(MultiView::EViews::ViewZrho)->GetGLViewer()->GetPictureUsingBB(); |
174 | | - viewZrhoImage->Scale(width * 0.33, height * 0.5); |
175 | | - viewZrhoImage->CopyArea(&image, 0, 0, viewZrhoImage->GetWidth(), viewZrhoImage->GetHeight(), width * 0.66, height * 0.5); |
| 189 | + viewZrhoImage->Scale(width * 0.3, height * 0.45); |
| 190 | + CopyImage(&image, (TASImage*)viewZrhoImage, width * 0.68, height * 0.525, 0, 0, viewZrhoImage->GetWidth(), viewZrhoImage->GetHeight()); |
176 | 191 |
|
177 | | - image.DrawText(10, 1000, runString.c_str(), 24, "#FFFFFF"); |
178 | | - image.DrawText(10, 1020, timestampString.c_str(), 24, "#FFFFFF"); |
179 | | - image.DrawText(10, 1040, collidingsystemString.c_str(), 24, "#FFFFFF"); |
180 | | - image.DrawText(10, 1060, energyString.c_str(), 24, "#FFFFFF"); |
| 192 | + image.DrawText(10, height - 4 * text_leading, runString.c_str(), font_size, fontColor); |
| 193 | + image.DrawText(10, height - 3 * text_leading, timestampString.c_str(), font_size, fontColor); |
| 194 | + image.DrawText(10, height - 2 * text_leading, collidingsystemString.c_str(), font_size, fontColor); |
| 195 | + image.DrawText(10, height - 1 * text_leading, energyString.c_str(), font_size, fontColor); |
| 196 | + |
| 197 | + if (!std::filesystem::is_directory(outDirectory)) { |
| 198 | + std::filesystem::create_directory(outDirectory); |
| 199 | + } |
| 200 | + image.WriteImage(filepath.str().c_str(), TImage::kPng); |
181 | 201 |
|
182 | | - image.WriteImage("Screenshot.png", TImage::kPng); |
183 | 202 | clearInTick(); |
184 | 203 | } |
185 | 204 |
|
@@ -275,5 +294,60 @@ namespace o2 |
275 | 294 | exit(0); |
276 | 295 | } |
277 | 296 |
|
| 297 | + bool EventManagerFrame::CopyImage(TASImage* dst, TASImage* src, Int_t x_dst, Int_t y_dst, Int_t x_src, Int_t y_src, |
| 298 | + UInt_t w_src, UInt_t h_src) |
| 299 | + { |
| 300 | + |
| 301 | + if (!dst) { |
| 302 | + return false; |
| 303 | + } |
| 304 | + if (!src) { |
| 305 | + return false; |
| 306 | + } |
| 307 | + |
| 308 | + int x = 0; |
| 309 | + int y = 0; |
| 310 | + int idx_src = 0; |
| 311 | + int idx_dst = 0; |
| 312 | + x_src = x_src < 0 ? 0 : x_src; |
| 313 | + y_src = y_src < 0 ? 0 : y_src; |
| 314 | + |
| 315 | + if ((x_src >= (int)src->GetWidth()) || (y_src >= (int)src->GetHeight())) { |
| 316 | + return false; |
| 317 | + } |
| 318 | + |
| 319 | + w_src = x_src + w_src > src->GetWidth() ? src->GetWidth() - x_src : w_src; |
| 320 | + h_src = y_src + h_src > src->GetHeight() ? src->GetHeight() - y_src : h_src; |
| 321 | + UInt_t yy = (y_src + y) * src->GetWidth(); |
| 322 | + |
| 323 | + src->BeginPaint(false); |
| 324 | + dst->BeginPaint(false); |
| 325 | + |
| 326 | + UInt_t* dst_image_array = dst->GetArgbArray(); |
| 327 | + UInt_t* src_image_array = src->GetArgbArray(); |
| 328 | + |
| 329 | + if (!dst_image_array || !src_image_array) { |
| 330 | + return false; |
| 331 | + } |
| 332 | + |
| 333 | + for (y = 0; y < (int)h_src; y++) { |
| 334 | + for (x = 0; x < (int)w_src; x++) { |
| 335 | + |
| 336 | + idx_src = yy + x + x_src; |
| 337 | + idx_dst = (y_dst + y) * dst->GetWidth() + x + x_dst; |
| 338 | + |
| 339 | + if ((x + x_dst < 0) || (y_dst + y < 0) || |
| 340 | + (x + x_dst >= (int)dst->GetWidth()) || (y + y_dst >= (int)dst->GetHeight())) { |
| 341 | + continue; |
| 342 | + } |
| 343 | + |
| 344 | + dst_image_array[idx_dst] = src_image_array[idx_src]; |
| 345 | + } |
| 346 | + yy += src->GetWidth(); |
| 347 | + } |
| 348 | + |
| 349 | + return true; |
| 350 | + } |
| 351 | + |
278 | 352 | } // namespace event_visualisation |
279 | 353 | } |
0 commit comments