Converting RGB8888 to ARGB32_Premultiplied (for performance reasons)

This commit is contained in:
Jonathan Thomas
2020-10-13 18:18:10 -05:00
parent 91945f03dc
commit 94059828d5
9 changed files with 22 additions and 27 deletions

View File

@@ -231,7 +231,7 @@ std::shared_ptr<QImage> Frame::GetWaveform(int width, int height, int Red, int G
}
// Create blank image
wave_image = std::shared_ptr<QImage>(new QImage(total_width, total_height, QImage::Format_RGBA8888));
wave_image = std::shared_ptr<QImage>(new QImage(total_width, total_height, QImage::Format_ARGB32_Premultiplied));
wave_image->fill(QColor(0,0,0,0));
// Load QPainter with wave_image device
@@ -262,7 +262,7 @@ std::shared_ptr<QImage> Frame::GetWaveform(int width, int height, int Red, int G
else
{
// No audio samples present
wave_image = std::shared_ptr<QImage>(new QImage(width, height, QImage::Format_RGBA8888));
wave_image = std::shared_ptr<QImage>(new QImage(width, height, QImage::Format_ARGB32_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<QImage> thumbnail = std::shared_ptr<QImage>(new QImage(new_width, new_height, QImage::Format_RGBA8888));
std::shared_ptr<QImage> thumbnail = std::shared_ptr<QImage>(new QImage(new_width, new_height, QImage::Format_ARGB32_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<QImage>(new QImage(overlay->convertToFormat(QImage::Format_RGBA8888)));
overlay = std::shared_ptr<QImage>(new QImage(overlay->convertToFormat(QImage::Format_ARGB32_Premultiplied)));
// Resize to fit
overlay = std::shared_ptr<QImage>(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<QImage>(new QImage(mask->convertToFormat(QImage::Format_RGBA8888)));
mask = std::shared_ptr<QImage>(new QImage(mask->convertToFormat(QImage::Format_ARGB32_Premultiplied)));
// Resize to fit
mask = std::shared_ptr<QImage>(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<juce::CriticalSection> lock(addingImageSection);
#pragma omp critical (AddImage)
{
image = std::shared_ptr<QImage>(new QImage(new_width, new_height, QImage::Format_RGBA8888));
image = std::shared_ptr<QImage>(new QImage(new_width, new_height, QImage::Format_ARGB32_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<QImage>(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_RGBA8888)
*image = image->convertToFormat(QImage::Format_RGBA8888);
if (image->format() != QImage::Format_ARGB32_Premultiplied)
*image = image->convertToFormat(QImage::Format_ARGB32_Premultiplied);
// Update height and width
width = image->width();
@@ -798,9 +798,9 @@ void Frame::AddImage(std::shared_ptr<QImage> new_image)
{
image = new_image;
// Always convert to RGBA8888 (if different)
if (image->format() != QImage::Format_RGBA8888)
*image = image->convertToFormat(QImage::Format_RGBA8888);
// Always convert to Format_ARGB32_Premultiplied (if different)
if (image->format() != QImage::Format_ARGB32_Premultiplied)
*image = image->convertToFormat(QImage::Format_ARGB32_Premultiplied);
// Update height and width
width = image->width();
@@ -830,8 +830,8 @@ void Frame::AddImage(std::shared_ptr<QImage> new_image, bool only_odd_lines)
if (image == new_image || image->size() != new_image->size()) {
ret = true;
}
else if (new_image->format() != image->format()) {
new_image = std::shared_ptr<QImage>(new QImage(new_image->convertToFormat(image->format())));
else if (new_image->format() != QImage::Format_ARGB32_Premultiplied) {
new_image = std::shared_ptr<QImage>(new QImage(new_image->convertToFormat(QImage::Format_ARGB32_Premultiplied)));
}
}
if (ret) {
@@ -970,7 +970,7 @@ void Frame::AddMagickImage(std::shared_ptr<Magick::Image> 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<QImage>(new QImage(qbuffer, width, height, width * BPP, QImage::Format_RGBA8888, (QImageCleanupFunction) &cleanUpBuffer, (void*) qbuffer));
image = std::shared_ptr<QImage>(new QImage(qbuffer, width, height, width * BPP, QImage::Format_ARGB32_Premultiplied, (QImageCleanupFunction) &cleanUpBuffer, (void*) qbuffer));
// Update height and width
width = image->width();