summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sample/src/setup.xml6
-rw-r--r--src/cgg.c2
-rw-r--r--src/generators.c104
-rw-r--r--src/job-manager.c4
-rw-r--r--src/jpeg-utils.cpp50
-rw-r--r--src/jpeg-utils.h2
-rw-r--r--src/setup.c136
-rw-r--r--src/setup.h18
-rw-r--r--templates/default.xml9
9 files changed, 184 insertions, 147 deletions
diff --git a/sample/src/setup.xml b/sample/src/setup.xml
index 327659d..6487f60 100644
--- a/sample/src/setup.xml
+++ b/sample/src/setup.xml
@@ -40,12 +40,6 @@
<!-- - override with <fullsize/> for album or for separate image -->
<!-- <nofullsize /> -->
- <!-- Make thumbnails squared, crop in different ways: -->
- <!-- none - no squared thumbnails, retain previous behaviour (default) -->
- <!-- simple - crop from center, shave 5% from borders -->
- <!-- ... more to come! (looking for a fast and clever algorithm) -->
- <squared_thumbnails type="none" />
-
<!-- autorotate input images according to EXIF information, unless -->
<!-- provided in the album source file (copy mode) (default = yes) -->
<autorotate value="yes" />
diff --git a/src/cgg.c b/src/cgg.c
index ea493ac..be882b1 100644
--- a/src/cgg.c
+++ b/src/cgg.c
@@ -168,7 +168,7 @@ main (int argc, char* argv[])
}
}
- if (! validate_design_setup (setup->design))
+ if (! validate_design_setup (setup))
return -7;
templates_basedir = find_design_directory (setup);
diff --git a/src/generators.c b/src/generators.c
index a2f7a65..3d04ad6 100644
--- a/src/generators.c
+++ b/src/generators.c
@@ -44,21 +44,6 @@
#define BUFFER_SIZE 65536 /* line cannot be longer than this */
-static TImageSize *
-find_image_size_for_name (TGallerySetup *setup, const gchar *name)
-{
- GList *l;
- TImageSize *image_size;
-
- for (l = g_list_first (setup->design->image_sizes); l; l = g_list_next (l)) {
- image_size = l->data;
- g_assert (image_size != NULL);
- if (g_ascii_strcasecmp (name, image_size->name) == 0)
- return image_size;
- }
- return NULL;
-}
-
static void
get_image_paths (TGallerySetup *setup,
@@ -72,7 +57,6 @@ get_image_paths (TGallerySetup *setup,
gchar **page_img_dst)
{
gboolean nofullsize;
- gboolean is_thumbnail;
gboolean is_preview;
gboolean is_original;
gchar *s1, *s2, *s3;
@@ -87,23 +71,23 @@ get_image_paths (TGallerySetup *setup,
*page_img_dst = NULL;
preview_image_size = NULL;
- /* ignore combinations that are not valid */
nofullsize = IS_NOFULLSIZE (item, items, setup);
- is_thumbnail = g_ascii_strcasecmp ("thumbnail", image_size->name) == 0;
is_preview = g_ascii_strcasecmp ("preview", image_size->name) == 0;
is_original = g_ascii_strcasecmp ("original", image_size->name) == 0;
- if ((items->type == GALLERY_TYPE_INDEX && ! is_thumbnail) ||
- (is_thumbnail && item->hidden) ||
- (is_thumbnail && items->type == GALLERY_TYPE_INDEX && (item->thumbnail == NULL || strlen (item->thumbnail) == 0)))
+
+ /* ignore combinations that are not valid */
+ if ((items->type == GALLERY_TYPE_INDEX && ! image_size->is_thumbnail) ||
+ (image_size->is_thumbnail && item->hidden) ||
+ (image_size->is_thumbnail && items->type == GALLERY_TYPE_INDEX && (item->thumbnail == NULL || strlen (item->thumbnail) == 0)))
return;
/* nofullsize specified, fall back to preview if available */
if (is_original && nofullsize)
- preview_image_size = find_image_size_for_name (setup, "preview");
+ preview_image_size = lookup_image_size_for_name (setup, "preview");
target_image_dir = g_strdup_printf ("%s%s", TARGET_IMAGE_DIR_PREFIX, preview_image_size ? preview_image_size->name : image_size->name);
/* Thumbnail special case */
- if (is_thumbnail) {
+ if (image_size->is_thumbnail) {
s1 = NULL;
if (items->type == GALLERY_TYPE_INDEX) {
s1 = item->thumbnail;
@@ -152,7 +136,8 @@ metadata_apply_overrides (ExifData *exif_data,
TGallerySetup *setup,
TPathInfo *path_info,
TAlbum *items,
- TIndexItem *item)
+ TIndexItem *item,
+ TImageSize *image_size)
{
g_return_if_fail (exif_data != NULL);
@@ -170,8 +155,7 @@ metadata_apply_overrides (ExifData *exif_data,
if (setup->write_supplied_exif && item->metadata_external_exif)
exif_data->external_exif_data = g_path_is_absolute (item->metadata_external_exif) ? g_strdup (item->metadata_external_exif) : g_build_filename (path_info->src_dir, item->metadata_external_exif, NULL);
- exif_data->squared_thumbnail_type = setup->squared_thumbnail_type;
-
+ exif_data->squared_thumbnail = image_size->is_thumbnail && image_size->squared_thumb;
exif_data->thumbnail_crop_hint = get_prop_int (items, item, PROP_THUMB_CROP_HINT, CROP_HINT_UNDEFINED);
}
@@ -188,7 +172,6 @@ generate_image (TGallerySetup *setup,
gboolean query_update)
{
gboolean res;
- gboolean is_thumbnail;
gboolean is_preview;
gboolean is_original;
gchar *img_src;
@@ -206,7 +189,6 @@ generate_image (TGallerySetup *setup,
image_size = l->data;
/* TODO: this is too specific */
- is_thumbnail = g_ascii_strcasecmp ("thumbnail", image_size->name) == 0;
is_preview = g_ascii_strcasecmp ("preview", image_size->name) == 0;
is_original = g_ascii_strcasecmp ("original", image_size->name) == 0;
@@ -224,13 +206,13 @@ generate_image (TGallerySetup *setup,
}
exif_data = exif_data_new_empty ();
- metadata_apply_overrides (exif_data, setup, path_info, items, item);
+ metadata_apply_overrides (exif_data, setup, path_info, items, item, image_size);
/* Do something when required */
res = res || needs_update (img_src, img_dst);
if (! query_update) {
/* Copy the source file */
- if (image_size->no_resize && ((is_preview && item->preview) || is_original)) {
+ if (! image_size->is_thumbnail && image_size->no_resize && ((is_preview && item->preview) || is_original)) {
if (! copy_file (img_src, img_dst))
log_error (" Error copying image %s to %s\n", img_src, img_dst);
}
@@ -240,32 +222,33 @@ generate_image (TGallerySetup *setup,
if (img_w > 0 && img_h > 0) {
stats_images_inc ();
- /* Only the "preview" size is affected by deprecated item and album overrides */
- if (is_preview) {
- tmpw = get_prop_int (items, item, PROP_WIDTH, img_w);
- tmph = get_prop_int (items, item, PROP_HEIGHT, img_h);
- calculate_sizes (tmpw, tmph, &img_w, &img_h);
- }
- if (is_thumbnail && setup->squared_thumbnail_type != THUMBNAIL_SQUARE_TYPE_NONE)
- tmpw = tmph = image_size->square_size;
- else
- /* Calculate sizes */
- if (img_w > img_h) {
- tmpw = image_size->landscape_width;
- tmph = image_size->landscape_height;
+ if (image_size->is_thumbnail && image_size->squared_thumb)
+ img_w = img_h = image_size->square_size;
+ else {
+ /* Only the "preview" size is affected by deprecated item and album overrides */
if (is_preview) {
- tmpw = get_prop_int (items, item, PROP_LANDSCAPE_W, tmpw);
- tmph = get_prop_int (items, item, PROP_LANDSCAPE_H, tmph);
+ tmpw = get_prop_int (items, item, PROP_WIDTH, img_w);
+ tmph = get_prop_int (items, item, PROP_HEIGHT, img_h);
+ calculate_sizes (tmpw, tmph, &img_w, &img_h);
}
- } else {
- tmpw = image_size->portrait_width;
- tmph = image_size->portrait_height;
- if (is_preview) {
- tmpw = get_prop_int (items, item, PROP_PORTRAIT_W, tmpw);
- tmph = get_prop_int (items, item, PROP_PORTRAIT_H, tmph);
+ /* Calculate sizes */
+ if (img_w > img_h) {
+ tmpw = image_size->landscape_width;
+ tmph = image_size->landscape_height;
+ if (is_preview) {
+ tmpw = get_prop_int (items, item, PROP_LANDSCAPE_W, tmpw);
+ tmph = get_prop_int (items, item, PROP_LANDSCAPE_H, tmph);
+ }
+ } else {
+ tmpw = image_size->portrait_width;
+ tmph = image_size->portrait_height;
+ if (is_preview) {
+ tmpw = get_prop_int (items, item, PROP_PORTRAIT_W, tmpw);
+ tmph = get_prop_int (items, item, PROP_PORTRAIT_H, tmph);
+ }
}
+ calculate_sizes (tmpw, tmph, &img_w, &img_h);
}
- calculate_sizes (tmpw, tmph, &img_w, &img_h);
/* Calculate quality */
if (is_preview)
quality = get_prop_int (items, item, PROP_QUALITY, image_size->quality);
@@ -273,14 +256,14 @@ generate_image (TGallerySetup *setup,
quality = image_size->quality;
/* Perform resize and strip */
- if (! resize_image (img_src, img_dst, img_w, img_h, quality, is_thumbnail, setup->autorotate, exif_data))
+ if (! resize_image (img_src, img_dst, img_w, img_h, quality, image_size->is_thumbnail, setup->autorotate, exif_data))
log_error (" Error resizing image %s\n", img_src);
} else {
log_error ("generate_image: image %s sizes are %lux%lu\n", img_src, img_w, img_h);
}
}
}
- if (! is_thumbnail) {
+ if (! image_size->is_thumbnail) {
modify_exif (img_dst, exif_data, setup->erase_exif_thumbnail, setup->strip_xmp);
}
@@ -491,8 +474,9 @@ write_html_album (TGallerySetup *setup,
/* Theming */
/* TODO: "image_size" will be used for album themes showing pictures inpage */
- image_size = find_image_size_for_name (setup, theme->album_image_size);
- thumb_image_size = find_image_size_for_name (setup, "thumbnail");
+ image_size = lookup_image_size_for_name (setup, theme->album_image_size);
+ thumb_image_size = lookup_image_size_for_name (setup, items->type == GALLERY_TYPE_ALBUM ? theme->album_thumb_size : theme->index_thumb_size);
+ g_assert (thumb_image_size != NULL);
/* Setup block parser */
block_parser_register_key (block_parser, "IMG_LIST", "IMG_LIST");
@@ -554,7 +538,7 @@ write_html_album (TGallerySetup *setup,
if (s2 != NULL)
get_image_sizes (s2, &img_thumb_w, &img_thumb_h, setup->autorotate);
- if (setup->squared_thumbnail_type != THUMBNAIL_SQUARE_TYPE_NONE || img_thumb_w == img_thumb_h)
+ if (thumb_image_size->squared_thumb || img_thumb_w == img_thumb_h)
s1 = "IMG_LIST_SQUARED";
else
s1 = (img_thumb_h > img_thumb_w) ? "IMG_LIST_PORTRAIT" : "IMG_LIST_LANDSCAPE";
@@ -783,9 +767,9 @@ write_html_image (TGallerySetup *setup,
/* If currently processed picture size is original, disable fullsize tags */
theme_size_is_original = g_ascii_strcasecmp (theme->picture_image_size, "original") == 0;
/* Original size is needed for several things, like EXIF and IPTC metadata */
- image_size = find_image_size_for_name (setup, "original");
+ image_size = lookup_image_size_for_name (setup, "original");
get_image_paths (setup, parent_items, item, item_index, path_info, image_size, &img_orig_src, &img_orig_dst, &img_orig_dst_page);
- image_size = find_image_size_for_name (setup, theme->picture_image_size);
+ image_size = lookup_image_size_for_name (setup, theme->picture_image_size);
get_image_paths (setup, parent_items, item, item_index, path_info, image_size, NULL, &img_dst, &img_dst_page);
imgname = g_path_get_basename (img_dst);
if (next_item && setup->preload)
@@ -819,7 +803,7 @@ write_html_image (TGallerySetup *setup,
*/
}
if (exif != NULL)
- metadata_apply_overrides (exif, setup, path_info, parent_items, item);
+ metadata_apply_overrides (exif, setup, path_info, parent_items, item, image_size);
/* Test for basic EXIF keys presence */
if (exif != NULL && exif_has_key (exif, EXIF_APERTURE) &&
exif_has_key (exif, EXIF_FOCAL_LENGTH) &&
diff --git a/src/job-manager.c b/src/job-manager.c
index fd41550..1bf9c5c 100644
--- a/src/job-manager.c
+++ b/src/job-manager.c
@@ -301,8 +301,8 @@ build_tree (TGallerySetup *setup,
for (l = g_list_first (setup->design->image_sizes); l; l = g_list_next (l)) {
image_size = l->data;
g_assert (image_size != NULL);
- /* We don't allow having single pictures in index pages at the moment, might change in the future */
- if (items->type != GALLERY_TYPE_INDEX || g_ascii_strcasecmp (image_size->name, "thumbnail") == 0) {
+ /* We don't allow having pictures in index pages at the moment, might change in the future */
+ if (items->type != GALLERY_TYPE_INDEX || image_size->is_thumbnail) {
s1 = g_strdup_printf ("%s%s", TARGET_IMAGE_DIR_PREFIX, image_size->name);
s2 = g_build_path (G_DIR_SEPARATOR_S, path_info->dest_dir, s1, NULL);
g_free (s1);
diff --git a/src/jpeg-utils.cpp b/src/jpeg-utils.cpp
index 5c0269a..a552e69 100644
--- a/src/jpeg-utils.cpp
+++ b/src/jpeg-utils.cpp
@@ -481,33 +481,29 @@ resize_image (const gchar *src, const gchar *dst,
{
/* Process thumbnail if required */
if (thumbnail) {
- switch (exif->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);
- switch (exif->thumbnail_crop_hint) {
- case CROP_HINT_UNDEFINED:
- case CROP_HINT_CENTER:
- MagickCropImage (magick_wand, amount, amount, (w - amount) / 2, (h - amount) / 2);
- break;
- case CROP_HINT_LEFT:
- MagickCropImage (magick_wand, amount, amount, 0, (h - amount) / 2);
- break;
- case CROP_HINT_RIGHT:
- MagickCropImage (magick_wand, amount, amount, w - amount, (h - amount) / 2);
- break;
- case CROP_HINT_TOP:
- MagickCropImage (magick_wand, amount, amount, (w - amount) / 2, 0);
- break;
- case CROP_HINT_BOTTOM:
- MagickCropImage (magick_wand, amount, amount, (w - amount) / 2, h - amount);
- break;
- }
- break;
- default:
- break;
+ if (exif->squared_thumbnail) {
+ 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);
+ switch (exif->thumbnail_crop_hint) {
+ case CROP_HINT_UNDEFINED:
+ case CROP_HINT_CENTER:
+ MagickCropImage (magick_wand, amount, amount, (w - amount) / 2, (h - amount) / 2);
+ break;
+ case CROP_HINT_LEFT:
+ MagickCropImage (magick_wand, amount, amount, 0, (h - amount) / 2);
+ break;
+ case CROP_HINT_RIGHT:
+ MagickCropImage (magick_wand, amount, amount, w - amount, (h - amount) / 2);
+ break;
+ case CROP_HINT_TOP:
+ MagickCropImage (magick_wand, amount, amount, (w - amount) / 2, 0);
+ break;
+ case CROP_HINT_BOTTOM:
+ MagickCropImage (magick_wand, amount, amount, (w - amount) / 2, h - amount);
+ break;
+ }
}
MagickThumbnailImage (magick_wand, size_x, size_y);
/* FIXME: this strips image ICC profile, should do proper conversion first */
diff --git a/src/jpeg-utils.h b/src/jpeg-utils.h
index 6b92b3d..3700d66 100644
--- a/src/jpeg-utils.h
+++ b/src/jpeg-utils.h
@@ -57,7 +57,7 @@ typedef struct {
double override_aperture;
double override_focal_length;
gchar *external_exif_data;
- ThumbnailSquareType squared_thumbnail_type;
+ gboolean squared_thumbnail;
TCropHint thumbnail_crop_hint;
} ExifData;
diff --git a/src/setup.c b/src/setup.c
index e0741c5..637a1b3 100644
--- a/src/setup.c
+++ b/src/setup.c
@@ -82,7 +82,6 @@ TGallerySetup *
parse_setup_xml (const gchar *filename)
{
TXMLFile *xml;
- gchar *s;
TGallerySetup *setup;
xml = xml_parser_load (filename);
@@ -106,13 +105,6 @@ parse_setup_xml (const gchar *filename)
setup->nofullsize = xml_file_get_node_present (xml, "/gallery_setup/images/nofullsize");
setup->autorotate = xml_file_get_node_attribute_boolean_with_default (xml, "/gallery_setup/images/autorotate", "value", TRUE);
- s = xml_file_get_node_attribute (xml, "/gallery_setup/images/squared_thumbnails", "type");
- if (s && g_ascii_strcasecmp (s, "simple") == 0)
- setup->squared_thumbnail_type = THUMBNAIL_SQUARE_TYPE_SIMPLE;
- else
- setup->squared_thumbnail_type = THUMBNAIL_SQUARE_TYPE_NONE;
- g_free (s);
-
/* meta section */
setup->meta_author = xml_file_get_node_value (xml, "/gallery_setup/meta/author/text()");
setup->meta_author_email = xml_file_get_node_value (xml, "/gallery_setup/meta/author_email/text()");
@@ -184,11 +176,33 @@ parse_design_setup_xml (const gchar *filename)
/* image_sizes section */
count = xml_file_node_get_children_count (xml, "/design_setup/image_sizes/size");
for (i = 0; i < count; i++) {
+ s = g_strdup_printf ("/design_setup/image_sizes/size[%d]", i + 1);
+ s2 = xml_file_get_node_attribute (xml, s, "name");
+ if (s2 == NULL || strlen (s2) == 0) {
+ fprintf (stderr, "design setup error: image size #%d defined with no name, ignoring\n", i + 1);
+ g_free (s);
+ g_free (s2);
+ continue;
+ }
+
image_size = g_malloc0 (sizeof (TImageSize));
design->image_sizes = g_list_append (design->image_sizes, image_size);
- s = g_strdup_printf ("/design_setup/image_sizes/size[%d]", i + 1);
- image_size->name = xml_file_get_node_attribute (xml, s, "name");
+ image_size->name = s2;
+ s2 = xml_file_get_node_attribute (xml, s, "type");
+ if (s2 && g_ascii_strcasecmp (s2, "thumbnail") == 0)
+ image_size->is_thumbnail = TRUE;
+ g_free (s2);
+ if (image_size->is_thumbnail) {
+ s2 = xml_file_get_node_attribute (xml, s, "style");
+ if (s2 && g_ascii_strcasecmp (s2, "squared") == 0)
+ image_size->squared_thumb = TRUE;
+ g_free (s2);
+ }
+ g_free (s);
+
+ s = g_strdup_printf ("/design_setup/image_sizes/size[%d]/no_resize", i + 1);
+ image_size->no_resize = xml_file_get_node_present (xml, s);
g_free (s);
s = g_strdup_printf ("/design_setup/image_sizes/size[%d]/landscape", i + 1);
@@ -231,6 +245,9 @@ parse_design_setup_xml (const gchar *filename)
s = g_strdup_printf ("/design_setup/theme[%d]/index/target_filename/text()", i + 1);
theme->index_filename = xml_file_get_node_value_with_default (xml, s, DEFAULT_INDEX_FILENAME);
g_free (s);
+ s = g_strdup_printf ("/design_setup/theme[%d]/index/thumbnail_size/text()", i + 1);
+ theme->index_thumb_size = xml_file_get_node_value (xml, s);
+ g_free (s);
s = g_strdup_printf ("/design_setup/theme[%d]/album/template/text()", i + 1);
theme->album_template = xml_file_get_node_value (xml, s);
@@ -241,6 +258,9 @@ parse_design_setup_xml (const gchar *filename)
s = g_strdup_printf ("/design_setup/theme[%d]/album/picture_size/text()", i + 1);
theme->album_image_size = xml_file_get_node_value (xml, s);
g_free (s);
+ s = g_strdup_printf ("/design_setup/theme[%d]/album/thumbnail_size/text()", i + 1);
+ theme->album_thumb_size = xml_file_get_node_value (xml, s);
+ g_free (s);
s = g_strdup_printf ("/design_setup/theme[%d]/album/protected_thumbnail/text()", i + 1);
theme->album_protected_thumbnail = xml_file_get_node_value (xml, s);
g_free (s);
@@ -292,6 +312,7 @@ makeup_legacy_design (const gchar *filename)
TGalleryDesign *design;
TImageSize *image_size;
TGalleryDesignTheme *theme;
+ gboolean squared_thumbs;
int i;
const gchar * image_sizes[3] = { "thumbnail", "preview", "original" };
@@ -307,6 +328,12 @@ makeup_legacy_design (const gchar *filename)
g_free (s);
}
+ squared_thumbs = FALSE;
+ s = xml_file_get_node_attribute (xml, "/gallery_setup/images/squared_thumbnails", "type");
+ if (s && g_ascii_strcasecmp (s, "simple") == 0)
+ squared_thumbs = TRUE;
+ g_free (s);
+
/* image_sizes section */
for (i = 0; i < G_N_ELEMENTS (image_sizes); i++) {
image_size = g_malloc0 (sizeof (TImageSize));
@@ -318,7 +345,9 @@ makeup_legacy_design (const gchar *filename)
image_size->portrait_height = xml_file_get_node_attribute_long_with_default (xml, s, "portrait_h", 0);
image_size->square_size = xml_file_get_node_attribute_long_with_default (xml, s, "square", 0);
image_size->quality = xml_file_get_node_attribute_long_with_default (xml, s, "quality", -1);
- image_size->no_resize = (i == G_N_ELEMENTS (image_sizes) - 1);
+ image_size->no_resize = (i != 0);
+ image_size->is_thumbnail = (i == 0);
+ image_size->squared_thumb = (i == 0) && squared_thumbs;
g_free (s);
design->image_sizes = g_list_append (design->image_sizes, image_size);
}
@@ -333,6 +362,7 @@ makeup_legacy_design (const gchar *filename)
theme->index_template = g_strdup ("template_index.html");
}
theme->index_filename = xml_file_get_node_value_with_default (xml, "/gallery_setup/templates/index_file/text()", DEFAULT_INDEX_FILENAME);
+ theme->index_thumb_size = g_strdup (image_sizes[0]);
theme->album_template = xml_file_get_node_value (xml, "/gallery_setup/templates/album/text()");
if (g_strcmp0 (theme->album_template, "template-album.tmpl") == 0) {
@@ -341,6 +371,7 @@ makeup_legacy_design (const gchar *filename)
}
theme->album_filename = xml_file_get_node_value_with_default (xml, "/gallery_setup/templates/index_file/text()", DEFAULT_INDEX_FILENAME);
theme->album_image_size = g_strdup (image_sizes[1]);
+ theme->album_thumb_size = g_strdup (image_sizes[0]);
theme->album_protected_thumbnail = NULL;
theme->picture_template = xml_file_get_node_value (xml, "/gallery_setup/templates/photo/text()");
@@ -365,69 +396,68 @@ makeup_legacy_design (const gchar *filename)
return design;
}
-
-static gboolean
-lookup_image_size (TGalleryDesign *design, const gchar *image_size_name)
+/*
+ * lookup_image_size_for_name: looks up an image size record for given image size name
+ */
+TImageSize *
+lookup_image_size_for_name (TGallerySetup *setup, const gchar *name)
{
GList *l;
TImageSize *image_size;
- g_return_val_if_fail (image_size_name != NULL, FALSE);
- g_return_val_if_fail (strlen (image_size_name) > 0, FALSE);
-
- for (l = g_list_first (design->image_sizes); l; l = g_list_next (l)) {
+ for (l = g_list_first (setup->design->image_sizes); l; l = g_list_next (l)) {
image_size = l->data;
g_assert (image_size != NULL);
- if (image_size->name == NULL || strlen (image_size->name) == 0) {
- fprintf (stderr, "design validation warning: image size %p defined with no name\n", image_size);
- continue;
- }
- if (image_size->landscape_width <= 0 || image_size->landscape_height <= 0 ||
- image_size->portrait_width <= 0 || image_size->portrait_height <= 0) {
- fprintf (stderr, "design validation warning: image size %s defined with zero sized element\n", image_size->name);
- continue;
- }
- if (g_ascii_strcasecmp (image_size_name, image_size->name) == 0)
- return TRUE;
+ if (g_ascii_strcasecmp (name, image_size->name) == 0)
+ return image_size;
}
-
- return FALSE;
+ return NULL;
}
/*
* validate_design_setup: validate design.xml file setup
*/
gboolean
-validate_design_setup (TGalleryDesign *design)
+validate_design_setup (TGallerySetup *setup)
{
GList *l;
+ TImageSize *image_size;
TGalleryDesignTheme *theme;
/* check for version match */
- if (! SETUP_IS_NATIVE (design)) {
+ if (! SETUP_IS_NATIVE (setup->design)) {
fprintf (stderr, "design validation error: version mismatch\n");
return FALSE;
}
/* validate sizes */
- if (g_list_length (design->image_sizes) == 0) {
+ if (g_list_length (setup->design->image_sizes) == 0) {
fprintf (stderr, "design validation error: no image size defined\n");
return FALSE;
}
- if (! lookup_image_size (design, "original")) {
- fprintf (stderr, "design validation error: mandatory \"original\" image size not defined\n");
- return FALSE;
+ if (lookup_image_size_for_name (setup, "original") == NULL) {
+ fprintf (stderr, "design validation error: mandatory \"original\" image size not defined\n");
+ return FALSE;
+ }
+ for (l = g_list_first (setup->design->image_sizes); l; l = g_list_next (l)) {
+ image_size = l->data;
+ g_assert (image_size != NULL);
+ if (image_size->landscape_width <= 0 || image_size->landscape_height <= 0 ||
+ image_size->portrait_width <= 0 || image_size->portrait_height <= 0) {
+ fprintf (stderr, "design validation warning: image size %s defined with zero sized element\n", image_size->name);
+ continue;
}
+ }
/* validate themes */
- if (g_list_length (design->themes) == 0) {
+ if (g_list_length (setup->design->themes) == 0) {
fprintf (stderr, "design validation error: no theme defined\n");
return FALSE;
}
- for (l = g_list_first (design->themes); l; l = g_list_next (l)) {
+ for (l = g_list_first (setup->design->themes); l; l = g_list_next (l)) {
theme = l->data;
g_assert (theme != NULL);
- if (theme->album_image_size && ! lookup_image_size (design, theme->album_image_size)) {
+ if (theme->album_image_size && lookup_image_size_for_name (setup, theme->album_image_size) == NULL) {
fprintf (stderr, "design validation error: theme-defined image size '%s' not found\n", theme->album_image_size);
return FALSE;
}
@@ -435,10 +465,32 @@ validate_design_setup (TGalleryDesign *design)
fprintf (stderr, "design validation error: theme does not define mandatory picture size argument\n");
return FALSE;
}
- if (! lookup_image_size (design, theme->picture_image_size)) {
+ if (lookup_image_size_for_name (setup, theme->picture_image_size) == NULL) {
fprintf (stderr, "design validation error: theme-defined image size '%s' not found\n", theme->picture_image_size);
return FALSE;
}
+ if (theme->album_thumb_size) {
+ image_size = lookup_image_size_for_name (setup, theme->album_thumb_size);
+ if (image_size == NULL) {
+ fprintf (stderr, "design validation error: referenced thumbnail image size '%s' not found\n", theme->album_thumb_size);
+ return FALSE;
+ }
+ if (! image_size->is_thumbnail) {
+ fprintf (stderr, "design validation error: referenced thumbnail image size '%s' is not of type \"thumbnail\"\n", theme->album_thumb_size);
+ return FALSE;
+ }
+ }
+ if (theme->index_thumb_size) {
+ image_size = lookup_image_size_for_name (setup, theme->index_thumb_size);
+ if (image_size == NULL) {
+ fprintf (stderr, "design validation error: referenced thumbnail image size '%s' not found\n", theme->index_thumb_size);
+ return FALSE;
+ }
+ if (! image_size->is_thumbnail) {
+ fprintf (stderr, "design validation error: referenced thumbnail image size '%s' is not of type \"thumbnail\"\n", theme->index_thumb_size);
+ return FALSE;
+ }
+ }
}
return TRUE;
@@ -525,9 +577,11 @@ free_design_theme_data (TGalleryDesignTheme *theme)
if (theme) {
g_free (theme->index_template);
g_free (theme->index_filename);
+ g_free (theme->index_thumb_size);
g_free (theme->album_template);
g_free (theme->album_filename);
g_free (theme->album_image_size);
+ g_free (theme->album_thumb_size);
g_free (theme->album_protected_thumbnail);
g_free (theme->picture_template);
g_free (theme->picture_filename);
diff --git a/src/setup.h b/src/setup.h
index 9e8f9dd..64351f3 100644
--- a/src/setup.h
+++ b/src/setup.h
@@ -35,12 +35,6 @@ G_BEGIN_DECLS
/* forward declaration */
typedef struct TGalleryDesign TGalleryDesign;
-typedef enum {
- THUMBNAIL_SQUARE_TYPE_NONE,
- THUMBNAIL_SQUARE_TYPE_SIMPLE
-} ThumbnailSquareType;
-
-
/* Global gallery setup */
typedef struct {
gboolean verbose;
@@ -63,7 +57,6 @@ typedef struct {
gboolean strip_xmp;
gboolean write_supplied_exif;
gboolean nofullsize;
- ThumbnailSquareType squared_thumbnail_type;
gboolean autorotate;
/* meta section */
@@ -96,6 +89,7 @@ typedef struct {
typedef struct {
gchar *name;
+ gboolean is_thumbnail;
int landscape_width;
int landscape_height;
int portrait_width;
@@ -103,15 +97,18 @@ typedef struct {
int square_size;
int quality;
gboolean no_resize;
+ gboolean squared_thumb;
} TImageSize;
typedef struct {
gboolean enabled;
gchar *index_template;
gchar *index_filename;
+ gchar *index_thumb_size;
gchar *album_template;
gchar *album_filename;
gchar *album_image_size;
+ gchar *album_thumb_size;
gchar *album_protected_thumbnail;
gchar *picture_template;
gchar *picture_filename;
@@ -153,9 +150,14 @@ TGalleryDesign * parse_design_setup_xml (const gchar *filename);
TGalleryDesign * makeup_legacy_design (const gchar *filename);
/*
+ * lookup_image_size_for_name: looks up an image size record for given image size name
+ */
+TImageSize * lookup_image_size_for_name (TGallerySetup *setup, const gchar *name);
+
+/*
* validate_design_setup: validate design.xml file setup
*/
-gboolean validate_design_setup (TGalleryDesign *design);
+gboolean validate_design_setup (TGallerySetup *setup);
/*
* free_setup_data: free allocated setup data
diff --git a/templates/default.xml b/templates/default.xml
index 318531c..9197519 100644
--- a/templates/default.xml
+++ b/templates/default.xml
@@ -45,7 +45,10 @@
<!-- Thumbnail section is mandatory. -->
<!-- Corresponds with optional <item thumbnail> tag in album source file.
Note that thumbnail images are always resized even for custom supplied files. -->
- <size name="thumbnail">
+ <!-- The "type" attribute has to be set to "thumbnail" to be treated as such.
+ An optional "style" attribute set to "squared" indicates the need of squared
+ thumbnails as opposed to original aspect ratio. -->
+ <size name="thumbnail" type="thumbnail" style="normal">
<landscape w="180" h="120" />
<portrait w="120" h="180" />
<square size="180" />
@@ -74,6 +77,8 @@
<index>
<template>template_index.html</template>
<target_filename>index.html</target_filename>
+ <!-- specify thumbnail image size to be used here. -->
+ <thumbnail_size>thumbnail</thumbnail_size>
</index>
<!-- This is mandatory. -->
@@ -82,6 +87,8 @@
<target_filename>index.html</target_filename>
<!-- which picture size to use for XXX tags (TODO) -->
<picture_size>preview</picture_size>
+ <!-- thumbnail_size is optional when thumbnails are not used on album pages -->
+ <thumbnail_size>thumbnail</thumbnail_size>
<!-- In case of a protected album, show special thumbnail (must be included
in supplemental_files). Comment out to use real thumbnail -->
<protected_thumbnail>emblems-readonly_120.png</protected_thumbnail>