commit 0aeefc3c4250409c7428eeae444f6a753c470e40
parent 3a88a4183f03ee06cde7da8f2b95c5fdaf5c99c0
Author: Nils Durner <durner@gnunet.org>
Date: Sun, 25 Jun 2006 01:32:01 +0000
improve thumbnail quality
Diffstat:
1 file changed, 19 insertions(+), 11 deletions(-)
diff --git a/src/plugins/thumbnailextractorqt.cc b/src/plugins/thumbnailextractorqt.cc
@@ -192,20 +192,28 @@ struct EXTRACTOR_Keywords * libextractor_thumbnailqt_extract(const char * filena
height = 1;
if (width == 0)
width = 1;
+
+ /* Resize image */
+ QImage thumb = img->convertToFormat(colors);
+ delete img;
- if (height > THUMBSIZE) {
- width = width * THUMBSIZE / height;
- height = THUMBSIZE;
- }
- if (width > THUMBSIZE) {
- height = height * THUMBSIZE / width;
- width = THUMBSIZE;
+ while(true)
+ {
+ width /= 2;
+ if (width < THUMBSIZE)
+ width = THUMBSIZE;
+
+ height /= 2;
+ if (height < THUMBSIZE)
+ height = THUMBSIZE;
+
+ thumb = thumb.scaled(width, height, Qt::KeepAspectRatio,
+ Qt::SmoothTransformation);
+
+ if (width == THUMBSIZE && height == THUMBSIZE)
+ break;
}
- QImage thumb = img->scaled(width, height, Qt::KeepAspectRatio,
- Qt::SmoothTransformation).convertToFormat(colors);
- delete img;
-
buffer.setBuffer(&bytes);
buffer.open(QIODevice::WriteOnly);
thumb.save(&buffer, "PNG");