@@ -167,23 +167,34 @@ namespace o2
167167 char time_str[100 ];
168168 std::strftime (time_str, sizeof (time_str), " %Y_%m_%d_%H_%M_%S" , std::localtime (&time));
169169
170+ TASImage* scaledImage;
171+
170172 std::ostringstream filepath;
171173 filepath << outDirectory << " /Screenshot_" << time_str << " .png" ;
172174
173175 TASImage image (width, height);
174176 image.FillRectangle (backgroundColor, 0 , 0 , width, height);
175177
176178 TImage* view3dImage = MultiView::getInstance ()->getView (MultiView::EViews::View3d)->GetGLViewer ()->GetPictureUsingBB ();
177- view3dImage->Scale (width * 0.65 , height * 0.95 );
178- CopyImage (&image, (TASImage*)view3dImage, width * 0.015 , height * 0.025 , 0 , 0 , view3dImage->GetWidth (), view3dImage->GetHeight ());
179+ scaledImage = ScaleImage ((TASImage*)view3dImage, width * 0.65 , height * 0.95 );
180+ if (scaledImage) {
181+ CopyImage (&image, scaledImage, width * 0.015 , height * 0.025 , 0 , 0 , scaledImage->GetWidth (), scaledImage->GetHeight ());
182+ delete scaledImage;
183+ }
179184
180185 TImage* viewRphiImage = MultiView::getInstance ()->getView (MultiView::EViews::ViewRphi)->GetGLViewer ()->GetPictureUsingBB ();
181- viewRphiImage->Scale (width * 0.3 , height * 0.45 );
182- CopyImage (&image, (TASImage*)viewRphiImage, width * 0.68 , height * 0.025 , 0 , 0 , viewRphiImage->GetWidth (), viewRphiImage->GetHeight ());
186+ scaledImage = ScaleImage ((TASImage*)viewRphiImage, width * 0.3 , height * 0.45 );
187+ if (scaledImage) {
188+ CopyImage (&image, scaledImage, width * 0.68 , height * 0.025 , 0 , 0 , scaledImage->GetWidth (), scaledImage->GetHeight ());
189+ delete scaledImage;
190+ }
183191
184192 TImage* viewZrhoImage = MultiView::getInstance ()->getView (MultiView::EViews::ViewZrho)->GetGLViewer ()->GetPictureUsingBB ();
185- viewZrhoImage->Scale (width * 0.3 , height * 0.45 );
186- CopyImage (&image, (TASImage*)viewZrhoImage, width * 0.68 , height * 0.525 , 0 , 0 , viewZrhoImage->GetWidth (), viewZrhoImage->GetHeight ());
193+ scaledImage = ScaleImage ((TASImage*)viewZrhoImage, width * 0.3 , height * 0.45 );
194+ if (scaledImage) {
195+ CopyImage (&image, scaledImage, width * 0.68 , height * 0.525 , 0 , 0 , scaledImage->GetWidth (), scaledImage->GetHeight ());
196+ delete scaledImage;
197+ }
187198
188199 bool logo = true ;
189200 if (logo) {
@@ -226,7 +237,17 @@ namespace o2
226237
227238 image.BeginPaint ();
228239 for (int i = 0 ; i < 4 ; i++) {
229- lines.push_back (" " );
240+ lines.push_back (" " ); // make sure that at least 4 lines are exising
241+ }
242+ if (!this ->mEventManager ->getDataSource ()->getCollisionTime ().empty ()) {
243+ char buff[100 ];
244+ snprintf (buff, sizeof (buff), " Run number: %d" , (int )this ->mEventManager ->getDataSource ()->getRunNumber ());
245+ lines[0 ] = buff;
246+ snprintf (buff, sizeof (buff), " Date: %s" , this ->mEventManager ->getDataSource ()->getCollisionTime ().c_str ());
247+ lines[1 ] = buff;
248+ }
249+
250+ for (int i = 0 ; i < 4 ; i++) {
230251 image.DrawText (textX, textY + i * textLineHeight, lines[i].c_str (), fontSize, " #BBBBBB" , " FreeSansBold.otf" );
231252 }
232253 image.EndPaint ();
@@ -409,5 +430,41 @@ namespace o2
409430 return true ;
410431 }
411432
433+ TASImage* EventManagerFrame::ScaleImage (TASImage* image, UInt_t desiredWidth, UInt_t desiredHeight)
434+ {
435+ if (!image) {
436+ return nullptr ;
437+ }
438+ if (desiredWidth == 0 || desiredHeight == 0 ) {
439+ return nullptr ;
440+ }
441+
442+ const char * backgroundColor = " #000000" ;
443+
444+ UInt_t scaleWidth = desiredWidth;
445+ UInt_t scaleHeight = desiredHeight;
446+ UInt_t offsetWidth = 0 ;
447+ UInt_t offsetHeight = 0 ;
448+
449+ float aspectRatio = (float )image->GetWidth () / (float )image->GetHeight ();
450+
451+ if (desiredWidth >= aspectRatio * desiredHeight) {
452+ scaleWidth = (UInt_t)(aspectRatio * desiredHeight);
453+ offsetWidth = (desiredWidth - scaleWidth) / 2 .0f ;
454+ } else {
455+ scaleHeight = (UInt_t)((1 .0f / aspectRatio) * desiredWidth);
456+ offsetHeight = (desiredHeight - scaleHeight) / 2 .0f ;
457+ }
458+
459+ TASImage* scaledImage = new TASImage (desiredWidth, desiredHeight);
460+ scaledImage->FillRectangle (backgroundColor, 0 , 0 , desiredWidth, desiredHeight);
461+
462+ image->Scale (scaleWidth, scaleHeight);
463+
464+ CopyImage (scaledImage, image, offsetWidth, offsetHeight, 0 , 0 , scaleWidth, scaleHeight);
465+
466+ return scaledImage;
467+ }
468+
412469 } // namespace event_visualisation
413470}
0 commit comments