From 6bd7fb72353a7f113739790228c4fed50e0cb22e Mon Sep 17 00:00:00 2001 From: Jonathan Thomas Date: Wed, 14 Oct 2020 03:06:30 -0500 Subject: [PATCH] Replacing ARGB32_Premultiplied with Format_RGBA8888_Premultiplied, which still seems to benefit from performance, but keeps the byte order the same as before. win win --- src/CacheDisk.cpp | 2 +- src/FFmpegReader.cpp | 4 ++-- src/Frame.cpp | 28 ++++++++++++++-------------- src/QtHtmlReader.cpp | 2 +- src/QtImageReader.cpp | 4 ++-- src/QtTextReader.cpp | 2 +- src/effects/Bars.cpp | 2 +- src/effects/Crop.cpp | 2 +- src/effects/Deinterlace.cpp | 2 +- 9 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/CacheDisk.cpp b/src/CacheDisk.cpp index 789ab25ce..e4ef4c9d3 100644 --- a/src/CacheDisk.cpp +++ b/src/CacheDisk.cpp @@ -235,7 +235,7 @@ std::shared_ptr CacheDisk::GetFrame(int64_t frame_number) image->load(frame_path); // Set pixel formatimage-> - image = std::shared_ptr(new QImage(image->convertToFormat(QImage::Format_ARGB32_Premultiplied))); + image = std::shared_ptr(new QImage(image->convertToFormat(QImage::Format_RGBA8888_Premultiplied))); // Create frame object std::shared_ptr frame(new Frame()); diff --git a/src/FFmpegReader.cpp b/src/FFmpegReader.cpp index d336654a3..19bca924b 100644 --- a/src/FFmpegReader.cpp +++ b/src/FFmpegReader.cpp @@ -1363,7 +1363,7 @@ void FFmpegReader::ProcessVideoPacket(int64_t requested_frame) { scale_mode = SWS_BICUBIC; } SwsContext *img_convert_ctx = sws_getContext(info.width, info.height, AV_GET_CODEC_PIXEL_FORMAT(pStream, pCodecCtx), width, - height, AV_PIX_FMT_RGB32, scale_mode, NULL, NULL, NULL); + height, PIX_FMT_RGBA, scale_mode, NULL, NULL, NULL); // Resize / Convert to RGB sws_scale(img_convert_ctx, my_frame->data, my_frame->linesize, 0, @@ -1373,7 +1373,7 @@ void FFmpegReader::ProcessVideoPacket(int64_t requested_frame) { std::shared_ptr f = CreateFrame(current_frame); // Add Image data to frame - f->AddImage(width, height, 4, QImage::Format_ARGB32_Premultiplied, buffer); + f->AddImage(width, height, 4, QImage::Format_RGBA8888_Premultiplied, buffer); // Update working cache working_cache.Add(f); diff --git a/src/Frame.cpp b/src/Frame.cpp index 805192924..dcd26dd8e 100644 --- a/src/Frame.cpp +++ b/src/Frame.cpp @@ -231,7 +231,7 @@ std::shared_ptr Frame::GetWaveform(int width, int height, int Red, int G } // Create blank image - wave_image = std::shared_ptr(new QImage(total_width, total_height, QImage::Format_ARGB32_Premultiplied)); + wave_image = std::shared_ptr(new QImage(total_width, total_height, QImage::Format_RGBA8888_Premultiplied)); wave_image->fill(QColor(0,0,0,0)); // Load QPainter with wave_image device @@ -262,7 +262,7 @@ std::shared_ptr Frame::GetWaveform(int width, int height, int Red, int G else { // No audio samples present - wave_image = std::shared_ptr(new QImage(width, height, QImage::Format_ARGB32_Premultiplied)); + wave_image = std::shared_ptr(new QImage(width, height, QImage::Format_RGBA8888_Premultiplied)); wave_image->fill(QColor(QString::fromStdString("#000000"))); } @@ -618,7 +618,7 @@ void Frame::Thumbnail(std::string path, int new_width, int new_height, std::stri std::string background_color, bool ignore_aspect, std::string format, int quality, float rotate) { // Create blank thumbnail image & fill background color - std::shared_ptr thumbnail = std::shared_ptr(new QImage(new_width, new_height, QImage::Format_ARGB32_Premultiplied)); + std::shared_ptr thumbnail = std::shared_ptr(new QImage(new_width, new_height, QImage::Format_RGBA8888_Premultiplied)); thumbnail->fill(QColor(QString::fromStdString(background_color))); // Create painter @@ -673,7 +673,7 @@ void Frame::Thumbnail(std::string path, int new_width, int new_height, std::stri overlay->load(QString::fromStdString(overlay_path)); // Set pixel format - overlay = std::shared_ptr(new QImage(overlay->convertToFormat(QImage::Format_ARGB32_Premultiplied))); + overlay = std::shared_ptr(new QImage(overlay->convertToFormat(QImage::Format_RGBA8888_Premultiplied))); // Resize to fit overlay = std::shared_ptr(new QImage(overlay->scaled(new_width, new_height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation))); @@ -691,7 +691,7 @@ void Frame::Thumbnail(std::string path, int new_width, int new_height, std::stri mask->load(QString::fromStdString(mask_path)); // Set pixel format - mask = std::shared_ptr(new QImage(mask->convertToFormat(QImage::Format_ARGB32_Premultiplied))); + mask = std::shared_ptr(new QImage(mask->convertToFormat(QImage::Format_RGBA8888_Premultiplied))); // Resize to fit mask = std::shared_ptr(new QImage(mask->scaled(new_width, new_height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation))); @@ -747,7 +747,7 @@ void Frame::AddColor(int new_width, int new_height, std::string new_color) const GenericScopedLock lock(addingImageSection); #pragma omp critical (AddImage) { - image = std::shared_ptr(new QImage(new_width, new_height, QImage::Format_ARGB32_Premultiplied)); + image = std::shared_ptr(new QImage(new_width, new_height, QImage::Format_RGBA8888_Premultiplied)); // Fill with solid color image->fill(QColor(QString::fromStdString(color))); @@ -775,8 +775,8 @@ void Frame::AddImage(int new_width, int new_height, int bytes_per_pixel, QImage: image = std::shared_ptr(new QImage(qbuffer, new_width, new_height, new_width * bytes_per_pixel, type, (QImageCleanupFunction) &openshot::Frame::cleanUpBuffer, (void*) qbuffer)); // Always convert to RGBA8888 (if different) - if (image->format() != QImage::Format_ARGB32_Premultiplied) - *image = image->convertToFormat(QImage::Format_ARGB32_Premultiplied); + if (image->format() != QImage::Format_RGBA8888_Premultiplied) + *image = image->convertToFormat(QImage::Format_RGBA8888_Premultiplied); // Update height and width width = image->width(); @@ -798,9 +798,9 @@ void Frame::AddImage(std::shared_ptr new_image) { image = new_image; - // Always convert to Format_ARGB32_Premultiplied (if different) - if (image->format() != QImage::Format_ARGB32_Premultiplied) - *image = image->convertToFormat(QImage::Format_ARGB32_Premultiplied); + // Always convert to Format_RGBA8888_Premultiplied (if different) + if (image->format() != QImage::Format_RGBA8888_Premultiplied) + *image = image->convertToFormat(QImage::Format_RGBA8888_Premultiplied); // Update height and width width = image->width(); @@ -830,8 +830,8 @@ void Frame::AddImage(std::shared_ptr new_image, bool only_odd_lines) if (image == new_image || image->size() != new_image->size()) { ret = true; } - else if (new_image->format() != QImage::Format_ARGB32_Premultiplied) { - new_image = std::shared_ptr(new QImage(new_image->convertToFormat(QImage::Format_ARGB32_Premultiplied))); + else if (new_image->format() != QImage::Format_RGBA8888_Premultiplied) { + new_image = std::shared_ptr(new QImage(new_image->convertToFormat(QImage::Format_RGBA8888_Premultiplied))); } } if (ret) { @@ -970,7 +970,7 @@ void Frame::AddMagickImage(std::shared_ptr new_image) MagickCore::ExportImagePixels(new_image->constImage(), 0, 0, new_image->columns(), new_image->rows(), "RGBA", Magick::CharPixel, buffer, &exception); // Create QImage of frame data - image = std::shared_ptr(new QImage(qbuffer, width, height, width * BPP, QImage::Format_ARGB32_Premultiplied, (QImageCleanupFunction) &cleanUpBuffer, (void*) qbuffer)); + image = std::shared_ptr(new QImage(qbuffer, width, height, width * BPP, QImage::Format_RGBA8888_Premultiplied, (QImageCleanupFunction) &cleanUpBuffer, (void*) qbuffer)); // Update height and width width = image->width(); diff --git a/src/QtHtmlReader.cpp b/src/QtHtmlReader.cpp index 776fb1425..e27f1c0f0 100644 --- a/src/QtHtmlReader.cpp +++ b/src/QtHtmlReader.cpp @@ -62,7 +62,7 @@ void QtHtmlReader::Open() if (!is_open) { // create image - image = std::shared_ptr(new QImage(width, height, QImage::Format_ARGB32_Premultiplied)); + image = std::shared_ptr(new QImage(width, height, QImage::Format_RGBA8888_Premultiplied)); image->fill(QColor(background_color.c_str())); //start painting diff --git a/src/QtImageReader.cpp b/src/QtImageReader.cpp index 0f3e789b3..0f4fdc38a 100644 --- a/src/QtImageReader.cpp +++ b/src/QtImageReader.cpp @@ -82,7 +82,7 @@ void QtImageReader::Open() ResvgRenderer renderer(path); if (renderer.isValid()) { - image = std::shared_ptr(new QImage(renderer.defaultSize(), QImage::Format_ARGB32_Premultiplied)); + image = std::shared_ptr(new QImage(renderer.defaultSize(), QImage::Format_RGBA8888_Premultiplied)); image->fill(Qt::transparent); QPainter p(image.get()); @@ -236,7 +236,7 @@ std::shared_ptr QtImageReader::GetFrame(int64_t requested_frame) svg_size.scale(max_width, max_height, Qt::KeepAspectRatio); // Create empty QImage - cached_image = std::shared_ptr(new QImage(QSize(svg_size.width(), svg_size.height()), QImage::Format_ARGB32_Premultiplied)); + cached_image = std::shared_ptr(new QImage(QSize(svg_size.width(), svg_size.height()), QImage::Format_RGBA8888_Premultiplied)); cached_image->fill(Qt::transparent); // Render SVG into QImage diff --git a/src/QtTextReader.cpp b/src/QtTextReader.cpp index 9a048feb8..4764cd0de 100644 --- a/src/QtTextReader.cpp +++ b/src/QtTextReader.cpp @@ -67,7 +67,7 @@ void QtTextReader::Open() if (!is_open) { // create image - image = std::shared_ptr(new QImage(width, height, QImage::Format_ARGB32_Premultiplied)); + image = std::shared_ptr(new QImage(width, height, QImage::Format_RGBA8888_Premultiplied)); image->fill(QColor(background_color.c_str())); QPainter painter; diff --git a/src/effects/Bars.cpp b/src/effects/Bars.cpp index 14064a71a..7180bdcdb 100644 --- a/src/effects/Bars.cpp +++ b/src/effects/Bars.cpp @@ -68,7 +68,7 @@ std::shared_ptr Bars::GetFrame(std::shared_ptr frame, int64_t fram std::shared_ptr frame_image = frame->GetImage(); // Get bar color (and create small color image) - std::shared_ptr tempColor = std::shared_ptr(new QImage(frame_image->width(), 1, QImage::Format_ARGB32_Premultiplied)); + std::shared_ptr tempColor = std::shared_ptr(new QImage(frame_image->width(), 1, QImage::Format_RGBA8888_Premultiplied)); tempColor->fill(QColor(QString::fromStdString(color.GetColorHex(frame_number)))); // Get current keyframe values diff --git a/src/effects/Crop.cpp b/src/effects/Crop.cpp index 5ef7f7e68..170f6fa53 100644 --- a/src/effects/Crop.cpp +++ b/src/effects/Crop.cpp @@ -68,7 +68,7 @@ std::shared_ptr Crop::GetFrame(std::shared_ptr frame, int64_t fram std::shared_ptr frame_image = frame->GetImage(); // Get transparent color (and create small transparent image) - std::shared_ptr tempColor = std::shared_ptr(new QImage(frame_image->width(), 1, QImage::Format_ARGB32_Premultiplied)); + std::shared_ptr tempColor = std::shared_ptr(new QImage(frame_image->width(), 1, QImage::Format_RGBA8888_Premultiplied)); tempColor->fill(QColor(QString::fromStdString("transparent"))); // Get current keyframe values diff --git a/src/effects/Deinterlace.cpp b/src/effects/Deinterlace.cpp index c9b8e17e3..24402288d 100644 --- a/src/effects/Deinterlace.cpp +++ b/src/effects/Deinterlace.cpp @@ -73,7 +73,7 @@ std::shared_ptr Deinterlace::GetFrame(std::shared_ptr frame, int64 const unsigned char* pixels = image->bits(); // Create a smaller, new image - QImage deinterlaced_image(image->width(), image->height() / 2, QImage::Format_ARGB32_Premultiplied); + QImage deinterlaced_image(image->width(), image->height() / 2, QImage::Format_RGBA8888_Premultiplied); const unsigned char* deinterlaced_pixels = deinterlaced_image.bits(); // Loop through the scanlines of the image (even or odd)