From 9d50015682975f1f70e22b4814fe7bf200c60679 Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Sun, 28 Dec 2008 19:37:44 +0100 Subject: Preload next image (active by default) --- generators.c | 50 ++++++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 22 deletions(-) (limited to 'generators.c') diff --git a/generators.c b/generators.c index 59c28c3..28a6770 100644 --- a/generators.c +++ b/generators.c @@ -448,7 +448,6 @@ write_html_album (TGallerySetup *setup, case INDEX_ITEM_TYPE_PICTURE: generate_image (setup, items, item, dst, &img_w, &img_h, &img_src, &thumb); /* Skip HTML code generation if it's a hidden item */ - g_print ("item->hidden = %d\n", item->hidden); if (! item->hidden) { if (img_w == 0 || img_h == 0 || (img_w / img_h) >= 1) s1 = strdup (buf_img_list_landscape); @@ -583,7 +582,7 @@ write_html_image (TGallerySetup *setup, TAlbum *parent; int i; char *s1, *s2, *s3, *s4; - char *imgname; + char *imgname, *preload_imgname; char *b; gboolean res; int level; @@ -602,25 +601,7 @@ write_html_image (TGallerySetup *setup, } buffer = malloc (BUFFER_SIZE); - s1 = g_path_get_dirname (dst); - imgname = (item->path == NULL && item->preview) ? g_path_get_basename (item->preview) : g_strdup (item->path); - big_dst = g_strconcat (s1, "/", IMG_BIG_DIR, "/", imgname, NULL); - orig_dst = g_strconcat (s1, "/", IMG_ORIG_DIR, "/", imgname, NULL); - g_free (s1); - buf_img_fullsize_link = malloc (BUFFER_SIZE); - memset (buf_img_fullsize_link, 0, BUFFER_SIZE); - in_img_fullsize_link = FALSE; - res = TRUE; - - - /* Get EXIF data from the original image */ - if (get_exif (original_img, &exif)) - fprintf (stderr, "write_html_image: error getting exif data from file \"%s\"\n", orig_dst); - - /* Retrieve image sizes of preview and original image */ - get_image_sizes (big_dst, &img_big_w, &img_big_h); - if (! item->nofullsize) - get_image_sizes (orig_dst, &img_orig_w, &img_orig_h); + preload_imgname = NULL; /* Get our index in the album */ item_index = 0; @@ -639,7 +620,6 @@ write_html_image (TGallerySetup *setup, /* Get previous and next items */ previous_item = NULL; next_item = NULL; - for (i = item_index - 2; i >= 0 && (previous_item == NULL || previous_item->type != INDEX_ITEM_TYPE_PICTURE); i--) previous_item = g_ptr_array_index (parent_items->items, i); if (previous_item && previous_item->type != INDEX_ITEM_TYPE_PICTURE) @@ -649,6 +629,28 @@ write_html_image (TGallerySetup *setup, if (next_item && next_item->type != INDEX_ITEM_TYPE_PICTURE) next_item = NULL; + /* Paths setup */ + s1 = g_path_get_dirname (dst); + imgname = (item->path == NULL && item->preview) ? g_path_get_basename (item->preview) : g_strdup (item->path); + if (next_item && setup->preload) + preload_imgname = g_strconcat (IMG_BIG_DIR, "/", (next_item->path == NULL && next_item->preview) ? g_path_get_basename (next_item->preview) : g_strdup (next_item->path), NULL); + big_dst = g_strconcat (s1, "/", IMG_BIG_DIR, "/", imgname, NULL); + orig_dst = g_strconcat (s1, "/", IMG_ORIG_DIR, "/", imgname, NULL); + g_free (s1); + buf_img_fullsize_link = malloc (BUFFER_SIZE); + memset (buf_img_fullsize_link, 0, BUFFER_SIZE); + in_img_fullsize_link = FALSE; + res = TRUE; + + /* Get EXIF data from the original image */ + if (get_exif (original_img, &exif)) + fprintf (stderr, "write_html_image: error getting exif data from file \"%s\"\n", orig_dst); + + /* Retrieve image sizes of preview and original image */ + get_image_sizes (big_dst, &img_big_w, &img_big_h); + if (! item->nofullsize) + get_image_sizes (orig_dst, &img_orig_w, &img_orig_h); + /* Read through the template and replace placeholders with real data */ while (! feof (fin)) { @@ -763,6 +765,8 @@ write_html_image (TGallerySetup *setup, s1 = "border_single"; str_replace (&b, "", s1, NULL); } + if (strstr (b, "$(IMG_SRC_PRELOAD)")) + str_replace (&b, "$(IMG_SRC_PRELOAD)", preload_imgname ? preload_imgname : "", NULL); if (strstr (b, "")) { if (exif->iso) @@ -882,6 +886,8 @@ write_html_image (TGallerySetup *setup, free (orig_dst); free (buf_img_fullsize_link); g_free (imgname); + if (preload_imgname) + g_free (preload_imgname); free_exif_data (exif); return res; } -- cgit v1.2.3