Skip to content
Browse files

High-quality prescale panzoom image to max size needed.

Then use lower quality QPainter transform scaling for remaining scales.
This should be faster and results in higher quality zoom overall.
  • Loading branch information...
1 parent b1be540 commit 127f374e3c4c32976dedeee632644e0aea4c7f98 @rectalogic committed Mar 28, 2012
Showing with 7 additions and 13 deletions.
  1. +7 −13 mlt/panzoom_producer.cpp
View
20 mlt/panzoom_producer.cpp
@@ -84,9 +84,6 @@ static QImage* getPrescaledSourceImage(mlt_producer producer, mlt_geometry geome
QSize imageSize(image->size());
if (maxSize.width() < imageSize.width() && maxSize.height() < imageSize.height())
*image = image->scaled(maxSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
- // Image smooth scaling is more efficient for RGB32
- if (image->format() != QImage::Format_RGB32)
- *image = image->convertToFormat(QImage::Format_RGB32);
}
else {
mlt_log(MLT_PRODUCER_SERVICE(producer), MLT_LOG_ERROR,
@@ -137,23 +134,20 @@ static int producerGetImage(mlt_frame frame, uint8_t **buffer, mlt_image_format
item.x += (item.w - scaleHeight * image->width()) / 2.0;
else if (scaleHeight > scaleWidth)
item.y += (item.h - scaleWidth * image->height()) / 2.0;
- QPointF offset(item.x, item.y);
-
- QImage scaledImage;
- if (scale != 1.0)
- scaledImage = image->scaled(scale * image->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
- else
- scaledImage = *image;
QImage targetImage(static_cast<uchar*>(*buffer), *width, *height, *width * 3, QImage::Format_RGB888);
+ QTransform tx(QTransform::fromTranslate(item.x, item.y).scale(scale, scale));
+
// Clear buffer if image doesn't fill it
- QRectF imageRect(offset, scaledImage.size());
- if (!imageRect.contains(targetImage.rect()))
+ QRect rect(tx.mapRect(image->rect()));
+ if (!rect.contains(targetImage.rect()))
memset(*buffer, 0, size);
QPainter painter(&targetImage);
- painter.drawImage(offset, scaledImage);
+ painter.setTransform(tx);
+ painter.setRenderHint(QPainter::SmoothPixmapTransform);
+ painter.drawImage(QPointF(0, 0), *image);
return error;
}

0 comments on commit 127f374

Please sign in to comment.
Something went wrong with that request. Please try again.