diff --git a/src/slic3r/GUI/AVVideoDecoder.cpp b/src/slic3r/GUI/AVVideoDecoder.cpp index cb9ed33a2a..599b883818 100644 --- a/src/slic3r/GUI/AVVideoDecoder.cpp +++ b/src/slic3r/GUI/AVVideoDecoder.cpp @@ -81,17 +81,16 @@ bool AVVideoDecoder::toWxImage(wxImage &image, wxSize const &size2) size.GetWidth(), size.GetHeight(), wxFmt, SWS_POINT, // SWS_FAST_BILINEAR //SWS_BICUBIC nullptr, nullptr, nullptr); - uint8_t *data = (uint8_t*)malloc(size.GetWidth() * size.GetHeight() * 3); - if (data == nullptr) - return false; - uint8_t * datas[] = {data }; - int strides[] = {size.GetWidth() * 3}; + int length = size.GetWidth() * size.GetHeight() * 3; + if (bits_.size() < length) + bits_.resize(length); + uint8_t * datas[] = { bits_.data() }; + int strides[] = { size.GetWidth() * 3 }; int result_h = sws_scale(sws_ctx_, frame_->data, frame_->linesize, 0, frame_->height, datas, strides); if (result_h != size.GetHeight()) { - delete[] data; return false; } - image = wxImage(size.GetWidth(), size.GetHeight(), data); + image = wxImage(size.GetWidth(), size.GetHeight(), bits_.data()); return true; } @@ -111,16 +110,15 @@ bool AVVideoDecoder::toWxBitmap(wxBitmap &bitmap, wxSize const &size2) size.GetWidth(), size.GetHeight(), wxFmt, SWS_POINT, // SWS_FAST_BILINEAR //SWS_BICUBIC nullptr, nullptr, nullptr); - uint8_t *data = (uint8_t*)malloc(size.GetWidth() * size.GetHeight() * 4); - if (data == nullptr) - return false; - uint8_t *datas[] = {data}; - int strides[] = {size.GetWidth() * 4}; + int length = size.GetWidth() * size.GetHeight() * 4; + if (bits_.size() < length) + bits_.resize(length); + uint8_t *datas[] = { bits_.data() }; + int strides[] = { size.GetWidth() * 4 }; int result_h = sws_scale(sws_ctx_, frame_->data, frame_->linesize, 0, frame_->height, datas, strides); if (result_h != size.GetHeight()) { - delete[] data; return false; } - bitmap = wxBitmap((char *) data, size.GetWidth(), size.GetHeight(), 32); + bitmap = wxBitmap((char const *) bits_.data(), size.GetWidth(), size.GetHeight(), 32); return true; } diff --git a/src/slic3r/GUI/AVVideoDecoder.hpp b/src/slic3r/GUI/AVVideoDecoder.hpp index 7c6e5e7e79..a32241a62c 100644 --- a/src/slic3r/GUI/AVVideoDecoder.hpp +++ b/src/slic3r/GUI/AVVideoDecoder.hpp @@ -34,6 +34,7 @@ private: AVFrame * frame_ = nullptr; SwsContext * sws_ctx_ = nullptr; bool got_frame_ = false; + std::vector bits_; }; #endif // AVVIDEODECODER_HPP diff --git a/src/slic3r/GUI/wxMediaCtrl3.cpp b/src/slic3r/GUI/wxMediaCtrl3.cpp index ca371314da..e326485bfe 100644 --- a/src/slic3r/GUI/wxMediaCtrl3.cpp +++ b/src/slic3r/GUI/wxMediaCtrl3.cpp @@ -27,7 +27,7 @@ wxMediaCtrl3::wxMediaCtrl3(wxWindow *parent) , BambuLib(StaticBambuLib::get(this)) , m_thread([this] { PlayThread(); }) { - SetBackgroundColour(*wxBLACK); + SetBackgroundColour("#000001ff"); } wxMediaCtrl3::~wxMediaCtrl3()