summaryrefslogtreecommitdiff
path: root/src/jpeg-utils.cpp
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@users.sourceforge.net>2010-10-30 13:05:15 +0200
committerTomas Bzatek <tbzatek@users.sourceforge.net>2010-10-30 13:05:15 +0200
commitcd37dc9ed94f0fa8738396c9a18a0c398f52694c (patch)
treeb65ded7111fa1be16fd7b96a3fa0ebcc7ed903fe /src/jpeg-utils.cpp
parent256bfcfc07364abe2bdc106f61ba4c02116cb4d5 (diff)
downloadcataract-cd37dc9ed94f0fa8738396c9a18a0c398f52694c.tar.xz
Don't resize an image if it fits in desired size
Diffstat (limited to 'src/jpeg-utils.cpp')
-rw-r--r--src/jpeg-utils.cpp39
1 files changed, 22 insertions, 17 deletions
diff --git a/src/jpeg-utils.cpp b/src/jpeg-utils.cpp
index a63afdd..3ec547c 100644
--- a/src/jpeg-utils.cpp
+++ b/src/jpeg-utils.cpp
@@ -231,7 +231,7 @@ free_exif_data (TExifData *data)
*/
gboolean
resize_image (const gchar *src, const gchar *dst,
- int size_x, int size_y,
+ unsigned long size_x, unsigned long size_y,
int quality,
gboolean thumbnail,
ThumbnailSquareType squared_thumbnail_type)
@@ -259,23 +259,28 @@ resize_image (const gchar *src, const gchar *dst,
if (status == MagickFalse)
ThrowWandException (magick_wand);
- /* Process thumbnail if required */
- if (thumbnail) {
- switch (squared_thumbnail_type) {
- case THUMBNAIL_SQUARE_TYPE_SIMPLE:
- w = MagickGetImageWidth (magick_wand);
- h = MagickGetImageHeight (magick_wand);
- amount = MAX (w, h) * SQUARED_SIMPLE_SHAVE_AMOUNT / 100;
- amount = MIN (w - 2*amount, h - 2*amount);
- MagickCropImage (magick_wand, amount, amount, (w - amount) / 2, (h - amount) / 2);
- break;
- default:
- break;
- }
- MagickThumbnailImage (magick_wand, size_x, size_y);
+
+ /* Don't resize if smaller than desired size */
+ if (MagickGetImageWidth (magick_wand) > size_x || MagickGetImageHeight (magick_wand) > size_y) {
+ /* Process thumbnail if required */
+ if (thumbnail) {
+ switch (squared_thumbnail_type) {
+ case THUMBNAIL_SQUARE_TYPE_SIMPLE:
+ w = MagickGetImageWidth (magick_wand);
+ h = MagickGetImageHeight (magick_wand);
+ amount = MAX (w, h) * SQUARED_SIMPLE_SHAVE_AMOUNT / 100;
+ amount = MIN (w - 2*amount, h - 2*amount);
+ MagickCropImage (magick_wand, amount, amount, (w - amount) / 2, (h - amount) / 2);
+ break;
+ default:
+ break;
+ }
+ MagickThumbnailImage (magick_wand, size_x, size_y);
+ }
+ else
+ MagickResizeImage (magick_wand, size_x, size_y, LanczosFilter, 1.0);
}
- else
- MagickResizeImage (magick_wand, size_x, size_y, LanczosFilter, 1.0);
+
MagickSetImageCompressionQuality (magick_wand, quality);
/* Write the image and destroy it. */