From 8e0c1b89fa3cd3141af50281ef8438c51d4a4b28 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 | 24 ++++++++++++------------ 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, 22 insertions(+), 22 deletions(-) diff --git a/src/CacheDisk.cpp b/src/CacheDisk.cpp index c8eb5d8d6..23985ea69 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::make_shared(image->convertToFormat(QImage::Format_ARGB32_Premultiplied)); + image = std::make_shared(image->convertToFormat(QImage::Format_RGBA8888_Premultiplied)); // Create frame object auto frame = std::make_shared(); diff --git a/src/FFmpegReader.cpp b/src/FFmpegReader.cpp index 2e8260c5b..2fedd9558 100644 --- a/src/FFmpegReader.cpp +++ b/src/FFmpegReader.cpp @@ -1342,7 +1342,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, @@ -1352,7 +1352,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 5c233aa27..103338278 100644 --- a/src/Frame.cpp +++ b/src/Frame.cpp @@ -221,7 +221,7 @@ std::shared_ptr Frame::GetWaveform(int width, int height, int Red, int G } // Create blank image - wave_image = std::make_shared(total_width, total_height, QImage::Format_ARGB32_Premultiplied); + wave_image = std::make_shared(total_width, total_height, QImage::Format_RGBA8888_Premultiplied); wave_image->fill(QColor(0,0,0,0)); // Load QPainter with wave_image device @@ -252,7 +252,7 @@ std::shared_ptr Frame::GetWaveform(int width, int height, int Red, int G else { // No audio samples present - wave_image = std::make_shared(width, height, QImage::Format_ARGB32_Premultiplied); + wave_image = std::make_shared(width, height, QImage::Format_RGBA8888_Premultiplied); wave_image->fill(QColor(QString::fromStdString("#000000"))); } @@ -613,7 +613,7 @@ void Frame::Thumbnail(std::string path, int new_width, int new_height, std::stri // Create blank thumbnail image & fill background color auto thumbnail = std::make_shared( - new_width, new_height, QImage::Format_ARGB32_Premultiplied); + new_width, new_height, QImage::Format_RGBA8888_Premultiplied); thumbnail->fill(QColor(QString::fromStdString(background_color))); // Create painter @@ -675,7 +675,7 @@ void Frame::Thumbnail(std::string path, int new_width, int new_height, std::stri // Set pixel format overlay = std::make_shared( - overlay->convertToFormat(QImage::Format_ARGB32_Premultiplied)); + overlay->convertToFormat(QImage::Format_RGBA8888_Premultiplied)); // Resize to fit overlay = std::make_shared(overlay->scaled( @@ -695,7 +695,7 @@ void Frame::Thumbnail(std::string path, int new_width, int new_height, std::stri // Set pixel format mask = std::make_shared( - mask->convertToFormat(QImage::Format_ARGB32_Premultiplied)); + mask->convertToFormat(QImage::Format_RGBA8888_Premultiplied)); // Resize to fit mask = std::make_shared(mask->scaled( @@ -752,7 +752,7 @@ void Frame::AddColor(int new_width, int new_height, std::string new_color) const GenericScopedLock lock(addingImageSection); #pragma omp critical (AddImage) { - image = std::make_shared(new_width, new_height, QImage::Format_ARGB32_Premultiplied); + image = std::make_shared(new_width, new_height, QImage::Format_RGBA8888_Premultiplied); // Fill with solid color image->fill(QColor(QString::fromStdString(color))); @@ -804,9 +804,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(); @@ -835,8 +835,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::make_shared(new_image->convertToFormat(QImage::Format_ARGB32_Premultiplied)); + else if (new_image->format() != QImage::Format_RGBA8888_Premultiplied) { + new_image = std::make_shared(new_image->convertToFormat(QImage::Format_RGBA8888_Premultiplied)); } } if (ret) { @@ -977,7 +977,7 @@ void Frame::AddMagickImage(std::shared_ptr new_image) // Create QImage of frame data image = std::make_shared( - qbuffer, width, height, width * BPP, QImage::Format_ARGB32_Premultiplied, + qbuffer, width, height, width * BPP, QImage::Format_RGBA8888_Premultiplied, (QImageCleanupFunction) &cleanUpBuffer, (void*) qbuffer); // Update height and width diff --git a/src/QtHtmlReader.cpp b/src/QtHtmlReader.cpp index 4da756ffb..a93fdd219 100644 --- a/src/QtHtmlReader.cpp +++ b/src/QtHtmlReader.cpp @@ -62,7 +62,7 @@ void QtHtmlReader::Open() if (!is_open) { // create image - image = std::make_shared(width, height, QImage::Format_ARGB32_Premultiplied); + image = std::make_shared(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 b22ef22b8..6ec600c46 100644 --- a/src/QtImageReader.cpp +++ b/src/QtImageReader.cpp @@ -76,7 +76,7 @@ void QtImageReader::Open() if (renderer.isValid()) { image = std::make_shared( - renderer.defaultSize(), QImage::Format_ARGB32_Premultiplied); + renderer.defaultSize(), QImage::Format_RGBA8888_Premultiplied); image->fill(Qt::transparent); QPainter p(image.get()); @@ -232,7 +232,7 @@ std::shared_ptr QtImageReader::GetFrame(int64_t requested_frame) // Create empty QImage cached_image = std::make_shared( QSize(svg_size.width(), svg_size.height()), - QImage::Format_ARGB32_Premultiplied); + QImage::Format_RGBA8888_Premultiplied); cached_image->fill(Qt::transparent); // Render SVG into QImage diff --git a/src/QtTextReader.cpp b/src/QtTextReader.cpp index 0bb1d7418..cbab42df9 100644 --- a/src/QtTextReader.cpp +++ b/src/QtTextReader.cpp @@ -67,7 +67,7 @@ void QtTextReader::Open() if (!is_open) { // create image - image = std::make_shared(width, height, QImage::Format_ARGB32_Premultiplied); + image = std::make_shared(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 d0dd8dbff..42898054f 100644 --- a/src/effects/Bars.cpp +++ b/src/effects/Bars.cpp @@ -69,7 +69,7 @@ std::shared_ptr Bars::GetFrame(std::shared_ptr frame, int64_t fram // Get bar color (and create small color image) auto tempColor = std::make_shared( - frame_image->width(), 1, QImage::Format_ARGB32_Premultiplied); + 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 aa587a02a..6813cf809 100644 --- a/src/effects/Crop.cpp +++ b/src/effects/Crop.cpp @@ -69,7 +69,7 @@ std::shared_ptr Crop::GetFrame(std::shared_ptr frame, int64_t fram // Get transparent color (and create small transparent image) auto tempColor = std::make_shared( - frame_image->width(), 1, QImage::Format_ARGB32_Premultiplied); + 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 16c104c02..71373080b 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)