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) --- gallery-utils.c | 9 ++++--- generators.c | 50 +++++++++++++++++++++----------------- sample/src/setup.xml | 2 ++ setup.c | 3 +++ setup.h | 2 ++ templates/scripts-general.js | 6 +++++ templates/template-view_photo.tmpl | 2 +- 7 files changed, 47 insertions(+), 27 deletions(-) diff --git a/gallery-utils.c b/gallery-utils.c index a11273b..9642116 100644 --- a/gallery-utils.c +++ b/gallery-utils.c @@ -68,8 +68,7 @@ str_replace (char **dst, const char *search, const char *replace, const char *ex /* TODO: add range checking */ - if (strstr (*dst, search) == NULL || strlen (*dst) == 0 || - strlen (search) == 0 || strlen (replace) == 0) + if (strstr (*dst, search) == NULL || strlen (*dst) == 0 || strlen (search) == 0) return; i = 0; @@ -84,8 +83,10 @@ str_replace (char **dst, const char *search, const char *replace, const char *ex } /* copy replace string instead */ - memcpy (&d[i], replace, strlen (replace)); - i += strlen (replace); + if (strlen (replace) > 0) { + memcpy (&d[i], replace, strlen (replace)); + i += strlen (replace); + } src = found + strlen (search); } 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; } diff --git a/sample/src/setup.xml b/sample/src/setup.xml index f9cb460..af2bd9e 100644 --- a/sample/src/setup.xml +++ b/sample/src/setup.xml @@ -26,6 +26,8 @@ quality="95" /> + + diff --git a/setup.c b/setup.c index a266e99..8df399c 100644 --- a/setup.c +++ b/setup.c @@ -80,6 +80,7 @@ gboolean parse_setup_xml (const char *filename, TGallerySetup *setup) { TXMLFile *xml; + char *s; xml = xml_parser_load (filename); if (xml == NULL) @@ -112,6 +113,8 @@ parse_setup_xml (const char *filename, TGallerySetup *setup) setup->meta_author = xml_file_get_node_value (xml, "/gallery_setup/meta/author/text()"); setup->meta_description = xml_file_get_node_value (xml, "/gallery_setup/meta/description/text()"); setup->meta_keywords = xml_file_get_node_value (xml, "/gallery_setup/meta/keywords/text()"); + s = xml_file_get_node_attribute (xml, "/gallery_setup/images/preload", "value"); + setup->preload = s ? strcasecmp (s, "yes") == 0 : TRUE; /* default to TRUE */ xml_parser_close (xml); diff --git a/setup.h b/setup.h index bb988aa..9ddae04 100644 --- a/setup.h +++ b/setup.h @@ -53,6 +53,8 @@ typedef struct { unsigned long preview_portrait_height; char *border_style; + + gboolean preload; } TGallerySetup; diff --git a/templates/scripts-general.js b/templates/scripts-general.js index df53bfc..c371bfa 100644 --- a/templates/scripts-general.js +++ b/templates/scripts-general.js @@ -13,3 +13,9 @@ function set_exif_table_visibility (visible) { document.getElementById('exif_table').style.display = visible == "yes" ? 'block' : 'none'; document.getElementById('exif_line').style.display = visible == "yes" ? 'none' : 'block'; } + +function preload_image (src) { + img = new Image(); + img.src = src; +} + diff --git a/templates/template-view_photo.tmpl b/templates/template-view_photo.tmpl index 7185492..dafff32 100644 --- a/templates/template-view_photo.tmpl +++ b/templates/template-view_photo.tmpl @@ -8,7 +8,7 @@ - + -- cgit v1.2.3