Skip to content

Commit

Permalink
Converting RGB8888 to ARGB32_Premultiplied (for performance reasons)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonoomph authored and ferdnyc committed Oct 19, 2020
1 parent ab49162 commit 096c2c4
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/CacheDisk.cpp
Expand Up @@ -235,7 +235,7 @@ std::shared_ptr<Frame> CacheDisk::GetFrame(int64_t frame_number)
image->load(frame_path);

// Set pixel formatimage->
image = std::make_shared<QImage>(image->convertToFormat(QImage::Format_RGBA8888));
image = std::make_shared<QImage>(image->convertToFormat(QImage::Format_ARGB32_Premultiplied));

// Create frame object
auto frame = std::make_shared<Frame>();
Expand Down
4 changes: 2 additions & 2 deletions src/FFmpegReader.cpp
Expand Up @@ -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, PIX_FMT_RGBA, scale_mode, NULL, NULL, NULL);
height, AV_PIX_FMT_RGB32, scale_mode, NULL, NULL, NULL);

// Resize / Convert to RGB
sws_scale(img_convert_ctx, my_frame->data, my_frame->linesize, 0,
Expand All @@ -1352,7 +1352,7 @@ void FFmpegReader::ProcessVideoPacket(int64_t requested_frame) {
std::shared_ptr<Frame> f = CreateFrame(current_frame);

// Add Image data to frame
f->AddImage(width, height, 4, QImage::Format_RGBA8888, buffer);
f->AddImage(width, height, 4, QImage::Format_ARGB32_Premultiplied, buffer);

// Update working cache
working_cache.Add(f);
Expand Down
26 changes: 12 additions & 14 deletions src/Frame.cpp
Expand Up @@ -221,8 +221,7 @@ std::shared_ptr<QImage> Frame::GetWaveform(int width, int height, int Red, int G
}

// Create blank image
wave_image = std::make_shared<QImage>(
total_width, total_height, QImage::Format_RGBA8888);
wave_image = std::make_shared<QImage>(total_width, total_height, QImage::Format_ARGB32_Premultiplied);
wave_image->fill(QColor(0,0,0,0));

// Load QPainter with wave_image device
Expand Down Expand Up @@ -253,7 +252,7 @@ std::shared_ptr<QImage> Frame::GetWaveform(int width, int height, int Red, int G
else
{
// No audio samples present
wave_image = std::make_shared<QImage>(width, height, QImage::Format_RGBA8888);
wave_image = std::make_shared<QImage>(width, height, QImage::Format_ARGB32_Premultiplied);
wave_image->fill(QColor(QString::fromStdString("#000000")));
}

Expand Down Expand Up @@ -614,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<QImage>(
new_width, new_height, QImage::Format_RGBA8888);
new_width, new_height, QImage::Format_ARGB32_Premultiplied);
thumbnail->fill(QColor(QString::fromStdString(background_color)));

// Create painter
Expand Down Expand Up @@ -676,7 +675,7 @@ void Frame::Thumbnail(std::string path, int new_width, int new_height, std::stri

// Set pixel format
overlay = std::make_shared<QImage>(
overlay->convertToFormat(QImage::Format_RGBA8888));
overlay->convertToFormat(QImage::Format_ARGB32_Premultiplied));

// Resize to fit
overlay = std::make_shared<QImage>(overlay->scaled(
Expand All @@ -696,7 +695,7 @@ void Frame::Thumbnail(std::string path, int new_width, int new_height, std::stri

// Set pixel format
mask = std::make_shared<QImage>(
mask->convertToFormat(QImage::Format_RGBA8888));
mask->convertToFormat(QImage::Format_ARGB32_Premultiplied));

// Resize to fit
mask = std::make_shared<QImage>(mask->scaled(
Expand Down Expand Up @@ -753,7 +752,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::make_shared<QImage>(new_width, new_height, QImage::Format_RGBA8888);
image = std::make_shared<QImage>(new_width, new_height, QImage::Format_ARGB32_Premultiplied);

// Fill with solid color
image->fill(QColor(QString::fromStdString(color)));
Expand Down Expand Up @@ -805,9 +804,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();
Expand Down Expand Up @@ -836,9 +835,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::make_shared<QImage>(
new_image->convertToFormat(image->format()));
else if (new_image->format() != QImage::Format_ARGB32_Premultiplied) {
new_image = std::make_shared<QImage>(new_image->convertToFormat(QImage::Format_ARGB32_Premultiplied));
}
}
if (ret) {
Expand Down Expand Up @@ -979,7 +977,7 @@ void Frame::AddMagickImage(std::shared_ptr<Magick::Image> new_image)

// Create QImage of frame data
image = std::make_shared<QImage>(
qbuffer, width, height, width * BPP, QImage::Format_RGBA8888,
qbuffer, width, height, width * BPP, QImage::Format_ARGB32_Premultiplied,
(QImageCleanupFunction) &cleanUpBuffer, (void*) qbuffer);

// Update height and width
Expand Down
2 changes: 1 addition & 1 deletion src/QtHtmlReader.cpp
Expand Up @@ -62,7 +62,7 @@ void QtHtmlReader::Open()
if (!is_open)
{
// create image
image = std::make_shared<QImage>(width, height, QImage::Format_RGBA8888);
image = std::make_shared<QImage>(width, height, QImage::Format_ARGB32_Premultiplied);
image->fill(QColor(background_color.c_str()));

//start painting
Expand Down
7 changes: 0 additions & 7 deletions src/QtImageReader.cpp
Expand Up @@ -98,10 +98,6 @@ void QtImageReader::Open()
throw InvalidFile("File could not be opened.", path.toStdString());
}

// Convert to proper format
image = std::make_shared<QImage>(
image->convertToFormat(QImage::Format_RGBA8888));

// Update image properties
info.has_audio = false;
info.has_video = true;
Expand Down Expand Up @@ -255,9 +251,6 @@ std::shared_ptr<Frame> QtImageReader::GetFrame(int64_t requested_frame)
max_width, max_height, Qt::KeepAspectRatio, Qt::SmoothTransformation));
}

cached_image = std::make_shared<QImage>(
cached_image->convertToFormat(QImage::Format_RGBA8888));

// Set max size (to later determine if max_size is changed)
max_size.setWidth(max_width);
max_size.setHeight(max_height);
Expand Down
2 changes: 1 addition & 1 deletion src/QtTextReader.cpp
Expand Up @@ -67,7 +67,7 @@ void QtTextReader::Open()
if (!is_open)
{
// create image
image = std::make_shared<QImage>(width, height, QImage::Format_RGBA8888);
image = std::make_shared<QImage>(width, height, QImage::Format_ARGB32_Premultiplied);
image->fill(QColor(background_color.c_str()));

QPainter painter;
Expand Down
2 changes: 1 addition & 1 deletion src/effects/Bars.cpp
Expand Up @@ -69,7 +69,7 @@ std::shared_ptr<Frame> Bars::GetFrame(std::shared_ptr<Frame> frame, int64_t fram

// Get bar color (and create small color image)
auto tempColor = std::make_shared<QImage>(
frame_image->width(), 1, QImage::Format_RGBA8888);
frame_image->width(), 1, QImage::Format_ARGB32_Premultiplied);
tempColor->fill(QColor(QString::fromStdString(color.GetColorHex(frame_number))));

// Get current keyframe values
Expand Down
2 changes: 1 addition & 1 deletion src/effects/Crop.cpp
Expand Up @@ -69,7 +69,7 @@ std::shared_ptr<Frame> Crop::GetFrame(std::shared_ptr<Frame> frame, int64_t fram

// Get transparent color (and create small transparent image)
auto tempColor = std::make_shared<QImage>(
frame_image->width(), 1, QImage::Format_RGBA8888);
frame_image->width(), 1, QImage::Format_ARGB32_Premultiplied);
tempColor->fill(QColor(QString::fromStdString("transparent")));

// Get current keyframe values
Expand Down
2 changes: 1 addition & 1 deletion src/effects/Deinterlace.cpp
Expand Up @@ -73,7 +73,7 @@ std::shared_ptr<Frame> Deinterlace::GetFrame(std::shared_ptr<Frame> frame, int64
const unsigned char* pixels = image->bits();

// Create a smaller, new image
QImage deinterlaced_image(image->width(), image->height() / 2, QImage::Format_RGBA8888);
QImage deinterlaced_image(image->width(), image->height() / 2, QImage::Format_ARGB32_Premultiplied);
const unsigned char* deinterlaced_pixels = deinterlaced_image.bits();

// Loop through the scanlines of the image (even or odd)
Expand Down

0 comments on commit 096c2c4

Please sign in to comment.