From 659ebc7d07a8f6045ba5443141b44277d7257cec Mon Sep 17 00:00:00 2001 From: "chunmao.guo" Date: Sat, 12 Oct 2024 11:33:52 +0800 Subject: [PATCH] FIX: reset decode buffer zero when scale width changed Change-Id: Iaa2f99111dd5f7228b7b25e1be0a8cbdbfe982a6 Jira: STUDIO-8422 --- src/slic3r/GUI/AVVideoDecoder.cpp | 14 ++++++++++++-- src/slic3r/GUI/AVVideoDecoder.hpp | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/slic3r/GUI/AVVideoDecoder.cpp b/src/slic3r/GUI/AVVideoDecoder.cpp index a56579cca..184804054 100644 --- a/src/slic3r/GUI/AVVideoDecoder.cpp +++ b/src/slic3r/GUI/AVVideoDecoder.cpp @@ -76,8 +76,13 @@ bool AVVideoDecoder::toWxImage(wxImage &image, wxSize const &size2) if (!size1.IsFullySpecified()) size1 = {frame_->width, frame_->height }; auto size = size1; - if (size.GetWidth() & 0x0f) + if (size.GetWidth() & 0x0f) { size.SetWidth((size.GetWidth() & ~0x0f) + 0x10); + if (size.GetWidth() != width_) { + std::fill(bits_.begin(), bits_.end(), 0); + width_ = size.GetWidth(); + } + } AVPixelFormat wxFmt = AV_PIX_FMT_RGB24; sws_ctx_ = sws_getCachedContext(sws_ctx_, frame_->width, frame_->height, AVPixelFormat(frame_->format), @@ -112,8 +117,13 @@ bool AVVideoDecoder::toWxBitmap(wxBitmap &bitmap, wxSize const &size2) if (!size1.IsFullySpecified()) size1 = {frame_->width, frame_->height }; auto size = size1; - if (size.GetWidth() & 0x0f) + if (size.GetWidth() & 0x0f) { size.SetWidth((size.GetWidth() & ~0x0f) + 0x10); + if (size.GetWidth() != width_) { + std::fill(bits_.begin(), bits_.end(), 0); + width_ = size.GetWidth(); + } + } AVPixelFormat wxFmt = AV_PIX_FMT_RGB32; sws_ctx_ = sws_getCachedContext(sws_ctx_, frame_->width, frame_->height, AVPixelFormat(frame_->format), diff --git a/src/slic3r/GUI/AVVideoDecoder.hpp b/src/slic3r/GUI/AVVideoDecoder.hpp index 99a7349e5..239352aea 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; + int width_ { 0 }; // scale result width std::vector bits_; };