@@ -1445,7 +1445,7 @@ bool Gui::TypeInfoComparator::operator()(const std::type_index& a,
14451445#endif
14461446}
14471447
1448- void Gui::gifStart (const std::string& filename)
1448+ int Gui::gifStart (const std::string& filename)
14491449{
14501450 if (!enabled ()) {
14511451 logger_->error (utl::GUI, 49 , " Cannot generate GIF without GUI enabled" );
@@ -1455,24 +1455,29 @@ void Gui::gifStart(const std::string& filename)
14551455 logger_->error (utl::GUI, 81 , " Filename is required to save a GIF." );
14561456 }
14571457
1458- gif_ = std::make_unique<GIF>();
1459- gif_->filename = filename;
1460- gif_->writer = nullptr ;
1458+ auto gif = std::make_unique<GIF>();
1459+ gif->filename = filename;
1460+ gifs_.emplace_back (std::move (gif));
1461+ return gifs_.size () - 1 ;
14611462}
14621463
1463- void Gui::gifAddFrame (const odb::Rect& region,
1464+ void Gui::gifAddFrame (const int key,
1465+ const odb::Rect& region,
14641466 int width_px,
14651467 double dbu_per_pixel,
14661468 std::optional<int > delay)
14671469{
1468- if (gif_ == nullptr ) {
1470+ if (key >= gifs_. size () || gifs_[key] == nullptr ) {
14691471 logger_->warn (utl::GUI, 51 , " GIF not active" );
14701472 return ;
14711473 }
14721474
14731475 if (db_ == nullptr ) {
14741476 logger_->error (utl::GUI, 50 , " No design loaded." );
14751477 }
1478+
1479+ auto & gif = gifs_[key];
1480+
14761481 odb::Rect save_region = region;
14771482 const bool use_die_area = region.dx () == 0 || region.dy () == 0 ;
14781483 const bool is_offscreen
@@ -1504,64 +1509,65 @@ void Gui::gifAddFrame(const odb::Rect& region,
15041509 QImage img = main_window->getLayoutViewer ()->createImage (
15051510 save_region, width_px, dbu_per_pixel);
15061511
1507- if (gif_ ->writer == nullptr ) {
1508- gif_ ->writer = std::make_unique<GifWriter>();
1509- gif_ ->width = img.width ();
1510- gif_ ->height = img.height ();
1511- GifBegin (gif_ ->writer .get (),
1512- gif_ ->filename .c_str (),
1513- gif_ ->width ,
1514- gif_ ->height ,
1512+ if (gif ->writer == nullptr ) {
1513+ gif ->writer = std::make_unique<GifWriter>();
1514+ gif ->width = img.width ();
1515+ gif ->height = img.height ();
1516+ GifBegin (gif ->writer .get (),
1517+ gif ->filename .c_str (),
1518+ gif ->width ,
1519+ gif ->height ,
15151520 delay.value_or (kDefaultGifDelay ));
15161521 } else {
15171522 // scale IMG if not matched
1518- img = img.scaled (gif_ ->width , gif_ ->height , Qt::KeepAspectRatio);
1523+ img = img.scaled (gif ->width , gif ->height , Qt::KeepAspectRatio);
15191524 }
15201525
1521- std::vector<uint8_t > frame (gif_ ->width * gif_ ->height * 4 , 0 );
1526+ std::vector<uint8_t > frame (gif ->width * gif ->height * 4 , 0 );
15221527 for (int x = 0 ; x < img.width (); x++) {
1523- if (x >= gif_ ->width ) {
1528+ if (x >= gif ->width ) {
15241529 continue ;
15251530 }
15261531 for (int y = 0 ; y < img.height (); y++) {
1527- if (y >= gif_ ->height ) {
1532+ if (y >= gif ->height ) {
15281533 continue ;
15291534 }
15301535
15311536 const QRgb pixel = img.pixel (x, y);
1532- const int frame_offset = (y * gif_ ->width + x) * 4 ;
1537+ const int frame_offset = (y * gif ->width + x) * 4 ;
15331538 frame[frame_offset + 0 ] = qRed (pixel);
15341539 frame[frame_offset + 1 ] = qGreen (pixel);
15351540 frame[frame_offset + 2 ] = qBlue (pixel);
15361541 frame[frame_offset + 3 ] = qAlpha (pixel);
15371542 }
15381543 }
15391544
1540- GifWriteFrame (gif_ ->writer .get (),
1545+ GifWriteFrame (gif ->writer .get (),
15411546 frame.data (),
1542- gif_ ->width ,
1543- gif_ ->height ,
1547+ gif ->width ,
1548+ gif ->height ,
15441549 delay.value_or (kDefaultGifDelay ));
15451550}
15461551
1547- void Gui::gifEnd ()
1552+ void Gui::gifEnd (const int key )
15481553{
1549- if (gif_ == nullptr ) {
1554+ if (key >= gifs_. size () || gifs_[key] == nullptr ) {
15501555 logger_->warn (utl::GUI, 58 , " GIF not active" );
15511556 return ;
15521557 }
15531558
1554- if (gif_->writer == nullptr ) {
1559+ auto & gif = gifs_[key];
1560+ if (gif->writer == nullptr ) {
15551561 logger_->warn (utl::GUI,
15561562 107 ,
15571563 " Nothing to save to {}. No frames added to gif." ,
1558- gif_ ->filename );
1559- gif_ = nullptr ;
1564+ gif ->filename );
1565+ gif = nullptr ;
15601566 return ;
15611567 }
15621568
1563- GifEnd (gif_ ->writer .get ());
1564- gif_ = nullptr ;
1569+ GifEnd (gif ->writer .get ());
1570+ gifs_[key] = nullptr ;
15651571}
15661572
15671573class SafeApplication : public QApplication
0 commit comments