You've already forked libopenshot
mirror of
https://github.com/OpenShot/libopenshot.git
synced 2026-03-02 08:53:52 -08:00
Fix RESVG format in GetFrame
This commit is contained in:
@@ -218,11 +218,14 @@ std::shared_ptr<Frame> QtImageReader::GetFrame(int64_t requested_frame)
|
||||
|
||||
// Scale image smaller (or use a previous scaled image)
|
||||
if (!cached_image || (max_size.width() != max_width || max_size.height() != max_height)) {
|
||||
|
||||
bool rendered = false;
|
||||
#if USE_RESVG == 1
|
||||
// If defined and found in CMake, utilize the libresvg for parsing
|
||||
// SVG files and rasterizing them to QImages.
|
||||
// Only use resvg for files ending in '.svg' or '.svgz'
|
||||
if (path.toLower().endsWith(".svg") || path.toLower().endsWith(".svgz")) {
|
||||
|
||||
ResvgRenderer renderer(path);
|
||||
if (renderer.isValid()) {
|
||||
// Scale SVG size to keep aspect ratio, and fill the max_size as best as possible
|
||||
@@ -230,30 +233,25 @@ std::shared_ptr<Frame> QtImageReader::GetFrame(int64_t requested_frame)
|
||||
svg_size.scale(max_width, max_height, Qt::KeepAspectRatio);
|
||||
|
||||
// Create empty QImage
|
||||
cached_image = std::shared_ptr<QImage>(new QImage(QSize(svg_size.width(), svg_size.height()), QImage::Format_RGBA8888));
|
||||
cached_image = std::shared_ptr<QImage>(new QImage(QSize(svg_size.width(), svg_size.height()), QImage::Format_ARGB32_Premultiplied));
|
||||
cached_image->fill(Qt::transparent);
|
||||
|
||||
// Render SVG into QImage
|
||||
QPainter p(cached_image.get());
|
||||
renderer.render(&p);
|
||||
p.end();
|
||||
} else {
|
||||
// Resize current rasterized SVG (since we failed to parse original SVG file with resvg)
|
||||
cached_image = std::shared_ptr<QImage>(new QImage(image->scaled(max_width, max_height, Qt::KeepAspectRatio, Qt::SmoothTransformation)));
|
||||
cached_image = std::shared_ptr<QImage>(new QImage(cached_image->convertToFormat(QImage::Format_RGBA8888)));
|
||||
rendered = true;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!rendered) {
|
||||
// We need to resize the original image to a smaller image (for performance reasons)
|
||||
// Only do this once, to prevent tons of unneeded scaling operations
|
||||
cached_image = std::shared_ptr<QImage>(new QImage(image->scaled(max_width, max_height, Qt::KeepAspectRatio, Qt::SmoothTransformation)));
|
||||
cached_image = std::shared_ptr<QImage>(new QImage(cached_image->convertToFormat(QImage::Format_RGBA8888)));
|
||||
}
|
||||
#else
|
||||
// We need to resize the original image to a smaller image (for performance reasons)
|
||||
// Only do this once, to prevent tons of unneeded scaling operations
|
||||
cached_image = std::shared_ptr<QImage>(new QImage(image->scaled(max_width, max_height, Qt::KeepAspectRatio, Qt::SmoothTransformation)));
|
||||
|
||||
cached_image = std::shared_ptr<QImage>(new QImage(cached_image->convertToFormat(QImage::Format_RGBA8888)));
|
||||
#endif
|
||||
|
||||
// Set max size (to later determine if max_size is changed)
|
||||
max_size.setWidth(max_width);
|
||||
|
||||
Reference in New Issue
Block a user