From 40334d2dec0545100edcca403d50ad6b1b015a9a Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Sat, 25 Apr 2009 15:39:55 +0200 Subject: Update mode By doing update, cgg will check the output structure for missing files and re-generate them as necessary. The decision whether an item (file, picture, album) needs to be updated is done by comparing timestamps (mtime specifically). Due to that reason it's important to keep this fact in mind when replacing single image which carries older timestamp than other files. Either don't use the update mode or 'touch' that new file. Changes made to any XML file will result in whole album re-generation (excluding subalbums). --- src/generators.c | 165 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 89 insertions(+), 76 deletions(-) (limited to 'src/generators.c') diff --git a/src/generators.c b/src/generators.c index 0a21b7e..c094e32 100644 --- a/src/generators.c +++ b/src/generators.c @@ -38,12 +38,13 @@ /* * generate_image: generate needed image sizes */ -void +gboolean generate_image (TGallerySetup *setup, TAlbum *items, TIndexItem *item, unsigned int item_index, - const char *dst_dir) + const char *dst_dir, + gboolean update_when_necessary) { unsigned long new_w, new_h; unsigned long thumb_w, thumb_h; @@ -55,16 +56,18 @@ generate_image (TGallerySetup *setup, char *thumb_src_full; char *s1; int bigq; + gboolean res; item->gen_img_src = NULL; item->gen_thumb = NULL; thumb_src_full = NULL; img_src_full = NULL; + orig_dst = NULL; if (items->type == GALLERY_TYPE_INDEX) { if (item->thumbnail == NULL || strlen (item->thumbnail) == 0) - return; + return FALSE; img_src_full = g_strconcat (items->base_dir, "/", item->thumbnail, NULL); thumb_src_full = g_strconcat (items->base_dir, "/", item->thumbnail, NULL); item->gen_img_src = g_path_get_basename (item->thumbnail); @@ -84,89 +87,99 @@ generate_image (TGallerySetup *setup, g_free (s1); } - get_image_sizes (img_src_full, &new_w, &new_h); - - if ((new_w > 0) && (new_h > 0)) { - stats_images_inc (); - item->gen_portrait = (new_w / new_h) < 1; - - /* Generate thumbnail */ - g_assert (thumb_src_full != NULL); - get_image_sizes (thumb_src_full, &thumb_w, &thumb_h); - thumb_dst = g_strconcat (dst_dir, "/", setup->thumbnail_dir, "/", item->gen_thumb, NULL); - - if ((thumb_w > 0) && (thumb_h > 0)) { - if (! item->gen_portrait) - calculate_sizes (setup->thumbnail_landscape_width, setup->thumbnail_landscape_height, &thumb_w, &thumb_h); - else - calculate_sizes (setup->thumbnail_portrait_width, setup->thumbnail_portrait_height, &thumb_w, &thumb_h); - if (! resize_image (thumb_src_full, thumb_dst, thumb_w, thumb_h, setup->thumbnail_quality, TRUE)) - log_error ("generate_image: error resizing thumbnail %s\n", thumb_src_full); - else - g_free (thumb_dst); - } else - log_error ("generate_image: thumbnail %s sizes are %lux%lu\n", thumb_src_full, thumb_w, thumb_h); - - - /* Generate/copy preview and original image */ - if (items->type == GALLERY_TYPE_ALBUM) - { - big_dst = g_strconcat (dst_dir, "/", setup->img_big_dir, "/", item->gen_img_src, NULL); - if (item->preview == NULL) { - /* No preview image supplied, generate it from original */ - bigq = setup->preview_quality; - if ((items->quality > 0) && (items->quality <= 100)) - bigq = items->quality; - if ((item->quality > 0) && (item->quality <= 100)) - bigq = item->quality; - - if ((item->width > 0) && (item->height > 0)) { - calculate_sizes (item->width, item->height, &new_w, &new_h); - } else { - if (! item->gen_portrait) - { - if ((items->landscape_width > 0) && (items->landscape_height > 0)) - calculate_sizes (items->landscape_width, items->landscape_height, &new_w, &new_h); - else - calculate_sizes (setup->preview_landscape_width, setup->preview_landscape_height, &new_w, &new_h); - } - else - { - if ((items->portrait_width > 0) && (items->portrait_height > 0)) - calculate_sizes (items->portrait_width, items->portrait_height, &new_w, &new_h); + /* Make paths */ + thumb_dst = g_strconcat (dst_dir, "/", setup->thumbnail_dir, "/", item->gen_thumb, NULL); + big_dst = g_strconcat (dst_dir, "/", setup->img_big_dir, "/", item->gen_img_src, NULL); + if (item->force_fullsize || (items->fullsize && ! item->force_nofullsize) || + (! item->force_nofullsize && ! items->nofullsize && ! setup->nofullsize)) + orig_dst = g_strconcat (dst_dir, "/", setup->img_orig_dir, "/", item->gen_img_src, NULL); + res = (! update_when_necessary) || needs_update (thumb_src_full, thumb_dst) || + (items->type == GALLERY_TYPE_ALBUM && (needs_update (img_src_full, big_dst) || (orig_dst && needs_update (img_src_full, orig_dst)))); + + /* Do something when necessary */ + if (res) { + get_image_sizes (img_src_full, &new_w, &new_h); + + if ((new_w > 0) && (new_h > 0)) { + stats_images_inc (); + item->gen_portrait = (new_w / new_h) < 1; + + /* Generate thumbnail */ + g_assert (thumb_src_full != NULL); + get_image_sizes (thumb_src_full, &thumb_w, &thumb_h); + + if ((thumb_w > 0) && (thumb_h > 0)) { + if (! item->gen_portrait) + calculate_sizes (setup->thumbnail_landscape_width, setup->thumbnail_landscape_height, &thumb_w, &thumb_h); + else + calculate_sizes (setup->thumbnail_portrait_width, setup->thumbnail_portrait_height, &thumb_w, &thumb_h); + if (! resize_image (thumb_src_full, thumb_dst, thumb_w, thumb_h, setup->thumbnail_quality, TRUE)) + log_error ("generate_image: error resizing thumbnail %s\n", thumb_src_full); + } else + log_error ("generate_image: thumbnail %s sizes are %lux%lu\n", thumb_src_full, thumb_w, thumb_h); + + + /* Generate/copy preview image */ + if (items->type == GALLERY_TYPE_ALBUM) { + if (item->preview == NULL) { + /* No preview image supplied, generate it from original */ + bigq = setup->preview_quality; + if ((items->quality > 0) && (items->quality <= 100)) + bigq = items->quality; + if ((item->quality > 0) && (item->quality <= 100)) + bigq = item->quality; + + if ((item->width > 0) && (item->height > 0)) { + calculate_sizes (item->width, item->height, &new_w, &new_h); + } else { + if (! item->gen_portrait) + { + if ((items->landscape_width > 0) && (items->landscape_height > 0)) + calculate_sizes (items->landscape_width, items->landscape_height, &new_w, &new_h); + else + calculate_sizes (setup->preview_landscape_width, setup->preview_landscape_height, &new_w, &new_h); + } else - calculate_sizes (setup->preview_portrait_width, setup->preview_portrait_height, &new_w, &new_h); + { + if ((items->portrait_width > 0) && (items->portrait_height > 0)) + calculate_sizes (items->portrait_width, items->portrait_height, &new_w, &new_h); + else + calculate_sizes (setup->preview_portrait_width, setup->preview_portrait_height, &new_w, &new_h); + } } + + g_assert (img_src_full != NULL); + if (! resize_image (img_src_full, big_dst, new_w, new_h, bigq, FALSE)) + log_error ("generate_image: error resizing big image %s\n", img_src_full); + } + else + { + /* Copy the preview (big) image provided */ + big_src = g_strconcat (items->base_dir, "/", item->preview, NULL); + if (! copy_file (big_src, big_dst)) + log_error ("generate_image: error copying preview image %s\n", big_src); + g_free (big_src); } + modify_exif (big_dst, setup->erase_exif_thumbnail, setup->add_copyright); - g_assert (img_src_full != NULL); - if (! resize_image (img_src_full, big_dst, new_w, new_h, bigq, FALSE)) - log_error ("generate_image: error resizing big image %s\n", img_src_full); - } - else - { - /* Copy the preview (big) image provided */ - big_src = g_strconcat (items->base_dir, "/", item->preview, NULL); - if (! copy_file (big_src, big_dst)) - log_error ("generate_image: error copying preview image %s\n", big_src); - g_free (big_src); - } - modify_exif (big_dst, setup->erase_exif_thumbnail, setup->add_copyright); - g_free (big_dst); - if (item->force_fullsize || (items->fullsize && ! item->force_nofullsize) || - (! item->force_nofullsize && ! items->nofullsize && ! setup->nofullsize)) - { - orig_dst = g_strconcat (dst_dir, "/", setup->img_orig_dir, "/", item->gen_img_src, NULL); - if (! copy_file(img_src_full, orig_dst)) - log_error ("generate_image: error copying original image %s\n", img_src_full); - modify_exif (orig_dst, setup->erase_exif_thumbnail, setup->add_copyright); - g_free (orig_dst); + /* Generate/copy original image */ + if (orig_dst) { + if (! copy_file (img_src_full, orig_dst)) + log_error ("generate_image: error copying original image %s\n", img_src_full); + else + modify_exif (orig_dst, setup->erase_exif_thumbnail, setup->add_copyright); + } } } } g_free (img_src_full); g_free (thumb_src_full); + g_free (big_dst); + g_free (thumb_dst); + g_free (orig_dst); + + return res; } -- cgit v1.2.3