summaryrefslogtreecommitdiff
path: root/src/jpeg-utils.cpp
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@users.sourceforge.net>2015-01-04 23:01:42 +0100
committerTomas Bzatek <tbzatek@users.sourceforge.net>2015-01-04 23:01:42 +0100
commit248a9af6ad668b6f09f79dda548721756fe11d79 (patch)
tree6ace053a06d55935e6ff2ba1bf571ab5d6fa7c61 /src/jpeg-utils.cpp
parentcd4658f7154fbfa58c09c101b9753ef85a62620d (diff)
downloadcataract-248a9af6ad668b6f09f79dda548721756fe11d79.tar.xz
Introduce new "fixed" thumbnail crop mode
This mode retains given aspect ratio and crops the area from inside of the source image.
Diffstat (limited to 'src/jpeg-utils.cpp')
-rw-r--r--src/jpeg-utils.cpp40
1 files changed, 29 insertions, 11 deletions
diff --git a/src/jpeg-utils.cpp b/src/jpeg-utils.cpp
index a552e69..e714778 100644
--- a/src/jpeg-utils.cpp
+++ b/src/jpeg-utils.cpp
@@ -458,9 +458,9 @@ resize_image (const gchar *src, const gchar *dst,
{
MagickWand *magick_wand;
ExceptionType severity;
- unsigned long w;
- unsigned long h;
- unsigned long amount;
+ unsigned long w, h;
+ unsigned long new_w, new_h;
+ double source_aspect, target_aspect;
gchar *description;
/* Read an image. */
@@ -481,27 +481,45 @@ resize_image (const gchar *src, const gchar *dst,
{
/* Process thumbnail if required */
if (thumbnail) {
- if (exif->squared_thumbnail) {
+ if (exif->thumbnail_crop_style != CROP_STYLE_NORMAL) {
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);
+ new_w = w;
+ new_h = h;
+ if (exif->thumbnail_crop_style == CROP_STYLE_SQUARED) {
+ new_w = MAX (w, h) * CROP_SIMPLE_SHAVE_AMOUNT / 100;
+ new_w = MIN (w - 2*new_w, h - 2*new_w);
+ new_h = new_w;
+ }
+ if (exif->thumbnail_crop_style == CROP_STYLE_FIXED) {
+ source_aspect = (double) w / (double) h;
+ target_aspect = (double) size_x / (double) size_y;
+ if (target_aspect >= source_aspect) {
+ new_w = w;
+ new_h = (int) ((double) w / target_aspect);
+ } else {
+ new_w = (int) ((double) h * target_aspect);
+ new_h = h;
+ }
+ new_w = (int) ((double) new_w * (double) (100 - CROP_SIMPLE_SHAVE_AMOUNT) / 100);
+ new_h = (int) ((double) new_h * (double) (100 - CROP_SIMPLE_SHAVE_AMOUNT) / 100);
+ }
switch (exif->thumbnail_crop_hint) {
case CROP_HINT_UNDEFINED:
case CROP_HINT_CENTER:
- MagickCropImage (magick_wand, amount, amount, (w - amount) / 2, (h - amount) / 2);
+ MagickCropImage (magick_wand, new_w, new_h, (w - new_w) / 2, (h - new_h) / 2);
break;
case CROP_HINT_LEFT:
- MagickCropImage (magick_wand, amount, amount, 0, (h - amount) / 2);
+ MagickCropImage (magick_wand, new_w, new_h, 0, (h - new_h) / 2);
break;
case CROP_HINT_RIGHT:
- MagickCropImage (magick_wand, amount, amount, w - amount, (h - amount) / 2);
+ MagickCropImage (magick_wand, new_w, new_h, w - new_w, (h - new_h) / 2);
break;
case CROP_HINT_TOP:
- MagickCropImage (magick_wand, amount, amount, (w - amount) / 2, 0);
+ MagickCropImage (magick_wand, new_w, new_h, (w - new_w) / 2, 0);
break;
case CROP_HINT_BOTTOM:
- MagickCropImage (magick_wand, amount, amount, (w - amount) / 2, h - amount);
+ MagickCropImage (magick_wand, new_w, new_h, (w - new_w) / 2, h - new_h);
break;
}
}