@@ -218,42 +218,40 @@ std::shared_ptr<Frame> QtImageReader::GetFrame(int64_t requested_frame)
218218
219219 // Scale image smaller (or use a previous scaled image)
220220 if (!cached_image || (max_size.width () != max_width || max_size.height () != max_height)) {
221+
222+ bool rendered = false ;
221223#if USE_RESVG == 1
222224 // If defined and found in CMake, utilize the libresvg for parsing
223225 // SVG files and rasterizing them to QImages.
224226 // Only use resvg for files ending in '.svg' or '.svgz'
225227 if (path.toLower ().endsWith (" .svg" ) || path.toLower ().endsWith (" .svgz" )) {
228+
226229 ResvgRenderer renderer (path);
227230 if (renderer.isValid ()) {
228231 // Scale SVG size to keep aspect ratio, and fill the max_size as best as possible
229232 QSize svg_size (renderer.defaultSize ().width (), renderer.defaultSize ().height ());
230233 svg_size.scale (max_width, max_height, Qt::KeepAspectRatio);
231234
232235 // Create empty QImage
233- cached_image = std::shared_ptr<QImage>(new QImage (QSize (svg_size.width (), svg_size.height ()), QImage::Format_RGBA8888 ));
236+ cached_image = std::shared_ptr<QImage>(new QImage (QSize (svg_size.width (), svg_size.height ()), QImage::Format_ARGB32_Premultiplied ));
234237 cached_image->fill (Qt::transparent);
235238
236239 // Render SVG into QImage
237240 QPainter p (cached_image.get ());
238241 renderer.render (&p);
239242 p.end ();
240- } else {
241- // Resize current rasterized SVG (since we failed to parse original SVG file with resvg)
242- cached_image = std::shared_ptr<QImage>(new QImage (image->scaled (max_width, max_height, Qt::KeepAspectRatio, Qt::SmoothTransformation)));
243- cached_image = std::shared_ptr<QImage>(new QImage (cached_image->convertToFormat (QImage::Format_RGBA8888)));
243+ rendered = true ;
244244 }
245- } else {
245+ }
246+ #endif
247+
248+ if (!rendered) {
246249 // We need to resize the original image to a smaller image (for performance reasons)
247250 // Only do this once, to prevent tons of unneeded scaling operations
248251 cached_image = std::shared_ptr<QImage>(new QImage (image->scaled (max_width, max_height, Qt::KeepAspectRatio, Qt::SmoothTransformation)));
249- cached_image = std::shared_ptr<QImage>(new QImage (cached_image->convertToFormat (QImage::Format_RGBA8888)));
250252 }
251- #else
252- // We need to resize the original image to a smaller image (for performance reasons)
253- // Only do this once, to prevent tons of unneeded scaling operations
254- cached_image = std::shared_ptr<QImage>(new QImage (image->scaled (max_width, max_height, Qt::KeepAspectRatio, Qt::SmoothTransformation)));
253+
255254 cached_image = std::shared_ptr<QImage>(new QImage (cached_image->convertToFormat (QImage::Format_RGBA8888)));
256- #endif
257255
258256 // Set max size (to later determine if max_size is changed)
259257 max_size.setWidth (max_width);
0 commit comments