summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@users.sourceforge.net>2016-10-04 21:54:28 +0200
committerTomas Bzatek <tbzatek@users.sourceforge.net>2016-10-04 21:54:28 +0200
commitd982fa6f55588ada8e5dd1bcb680ac817fcc5de4 (patch)
tree0de45bd9219c49ccd77d4cb6cdae0d55a78a582b /src
parentddd9556689af055355a07cf2766fe95eaed4e38e (diff)
downloadcataract-d982fa6f55588ada8e5dd1bcb680ac817fcc5de4.tar.xz
items: Add option to shave image borders
A workaround for badly exported images that contain some garbage at the borders. The amount specifies how many pixels should be shaved from all borders (i.e. amount of 2 results in 4x4 pixels loss). Applicable for particular items or whole album (<general> section) with the following syntax: <shave amount="1" />
Diffstat (limited to 'src')
-rw-r--r--src/generators.c2
-rw-r--r--src/items.c5
-rw-r--r--src/items.h1
-rw-r--r--src/jpeg-utils.cpp6
-rw-r--r--src/jpeg-utils.h1
5 files changed, 14 insertions, 1 deletions
diff --git a/src/generators.c b/src/generators.c
index d6984be..5094086 100644
--- a/src/generators.c
+++ b/src/generators.c
@@ -318,6 +318,8 @@ metadata_apply_overrides (ExifData *exif_data,
exif_data->thumbnail_crop_style = image_size->is_thumbnail ? image_size->thumb_crop_style : CROP_STYLE_NORMAL;
exif_data->thumbnail_crop_hint = get_prop_int (items, item, PROP_THUMB_CROP_HINT, CROP_HINT_UNDEFINED);
+
+ exif_data->shave_amount = get_prop_int (items, item, PROP_SHAVE_AMOUNT, 0);
}
static char *
diff --git a/src/items.c b/src/items.c
index 0ddc3b1..7fed640 100644
--- a/src/items.c
+++ b/src/items.c
@@ -164,6 +164,7 @@ parse_album_xml (TGallerySetup *setup, const gchar *filename, TPathInfo *path_in
}
prop_xml_attr (index->properties, PROP_BORDER_STYLE, xml, "/gallery/general/border", "style");
+ prop_xml_attr_long (index->properties, PROP_SHAVE_AMOUNT, xml, "/gallery/general/shave", "amount");
index->meta_author = xml_file_get_node_value (xml, "/gallery/general/meta/author/text()");
index->meta_description = xml_file_get_node_value (xml, "/gallery/general/meta/description/text()");
index->meta_keywords = xml_file_get_node_value (xml, "/gallery/general/meta/keywords/text()");
@@ -276,6 +277,10 @@ parse_album_xml (TGallerySetup *setup, const gchar *filename, TPathInfo *path_in
}
g_free (s);
+ s = g_strdup_printf ("/gallery/items/*[%d]/shave", i + 1);
+ prop_xml_attr_long (item->properties, PROP_SHAVE_AMOUNT, xml, s, "amount");
+ g_free (s);
+
s = g_strdup_printf ("/gallery/items/*[%d]/title/text()", i + 1);
item->title = xml_file_get_node_value (xml, s);
g_free (s);
diff --git a/src/items.h b/src/items.h
index 24a521f..2eaf7fb 100644
--- a/src/items.h
+++ b/src/items.h
@@ -93,6 +93,7 @@ typedef struct {
typedef enum {
PROP_BORDER_STYLE,
+ PROP_SHAVE_AMOUNT,
PROP_THUMB_CROP_HINT,
PROP_METADATA_TZ_SHIFT, /* minutes */
PROP_METADATA_OVERRIDE_DATETIME,
diff --git a/src/jpeg-utils.cpp b/src/jpeg-utils.cpp
index d7134c2..e9e1e65 100644
--- a/src/jpeg-utils.cpp
+++ b/src/jpeg-utils.cpp
@@ -540,8 +540,12 @@ resize_image (const gchar *src, const gchar *dst,
autorotate_image (magick_wand);
/* Don't resize if smaller than desired size */
- if (hidpi_strict_dimensions || MagickGetImageWidth (magick_wand) > size_x || MagickGetImageHeight (magick_wand) > size_y)
+ if (hidpi_strict_dimensions || MagickGetImageWidth (magick_wand) > size_x || MagickGetImageHeight (magick_wand) > size_y || exif->shave_amount > 0)
{
+ /* Shave borders if requested */
+ if (exif->shave_amount > 0)
+ MagickShaveImage (magick_wand, exif->shave_amount, exif->shave_amount);
+
/* Prepare image before resizing */
if (thumbnail) {
if (exif->thumbnail_crop_style != CROP_STYLE_NORMAL) {
diff --git a/src/jpeg-utils.h b/src/jpeg-utils.h
index d0664c9..b4ead79 100644
--- a/src/jpeg-utils.h
+++ b/src/jpeg-utils.h
@@ -60,6 +60,7 @@ typedef struct {
gchar *external_exif_data;
TCropStyle thumbnail_crop_style;
TCropHint thumbnail_crop_hint;
+ int shave_amount;
} ExifData;