summaryrefslogtreecommitdiff
path: root/src/generators.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/generators.c')
-rw-r--r--src/generators.c104
1 files changed, 44 insertions, 60 deletions
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) &&