From 3462576fd6bc883c41042fb7ae93ebabb12718d8 Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Sun, 10 Aug 2008 14:30:23 +0200 Subject: Support for different preview image borders Strip trailing whitespaces --- cgg.c | 54 ++--- config.h | 6 +- gallery-utils.c | 94 ++++---- gallery-utils.h | 24 +- generators.c | 378 ++++++++++++++++---------------- generators.h | 40 ++-- items.c | 77 ++++--- items.h | 22 +- jpeg-utils.cpp | 198 ++++++++--------- jpeg-utils.h | 44 ++-- sample/src/CIAF_1/img_6802e.jpg | 1 + sample/src/CIAF_1/img_6802f.jpg | 1 + sample/src/CIAF_1/index.xml | 14 ++ sample/src/CIAF_1/preview/img_6802d.jpg | 1 + sample/src/CIAF_1/preview/img_6802e.jpg | 1 + sample/src/CIAF_1/preview/img_6802f.jpg | 1 + sample/src/setup.xml | 4 +- setup.c | 112 +++++----- setup.h | 28 +-- templates/styles.css | 50 +++-- templates/template-view_photo.tmpl | 2 +- xml-parser.c | 76 +++---- xml-parser.h | 20 +- 23 files changed, 659 insertions(+), 589 deletions(-) create mode 120000 sample/src/CIAF_1/img_6802e.jpg create mode 120000 sample/src/CIAF_1/img_6802f.jpg create mode 120000 sample/src/CIAF_1/preview/img_6802d.jpg create mode 120000 sample/src/CIAF_1/preview/img_6802e.jpg create mode 120000 sample/src/CIAF_1/preview/img_6802f.jpg diff --git a/cgg.c b/cgg.c index 690c919..086f003 100644 --- a/cgg.c +++ b/cgg.c @@ -1,16 +1,16 @@ /* Cataract - Static web photo gallery generator * Copyright (C) 2008 Tomas Bzatek - * + * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -38,16 +38,16 @@ /* - * parse_cmd: parse commandline and fill global variable parameters - */ -gboolean + * parse_cmd: parse commandline and fill global variable parameters + */ +gboolean parse_cmd (int argc, char* argv[], char **source_dir, char **dst_dir, gboolean *verbose) { static gboolean _verbose = FALSE; static gchar *_source_dir = NULL; static gchar *_dst_dir = NULL; - static GOptionEntry entries[] = + static GOptionEntry entries[] = { { "verbose", 'v', 0, G_OPTION_ARG_NONE, &_verbose, "Be verbose", NULL }, { "source", 's', 0, G_OPTION_ARG_STRING, &_source_dir, "Specifies path to source structure", NULL }, @@ -58,11 +58,11 @@ parse_cmd (int argc, char* argv[], char **source_dir, char **dst_dir, gboolean * GError *error = NULL; GOptionContext *context; char *s1; - + g_set_prgname ("cgg"); - + context = g_option_context_new ("- web gallery generator"); - s1 = g_strdup_printf ("cgg v%s [%s] Copyright (c) 2008 Tomas Bzatek", APP_VERSION, APP_BUILD_DATE); + s1 = g_strdup_printf ("cgg v%s [%s] Copyright (c) 2008 Tomas Bzatek", APP_VERSION, APP_BUILD_DATE); g_option_context_set_summary (context, s1); g_free (s1); g_option_context_add_main_entries (context, entries, NULL); @@ -84,7 +84,7 @@ parse_cmd (int argc, char* argv[], char **source_dir, char **dst_dir, gboolean * return FALSE; } g_option_context_free (context); - + *source_dir = _source_dir; *dst_dir = _dst_dir; *verbose = _verbose; @@ -94,63 +94,63 @@ parse_cmd (int argc, char* argv[], char **source_dir, char **dst_dir, gboolean * -int +int main(int argc, char* argv[]) { char *source_dir; char *dst_dir; gboolean verbose; TGallerySetup *setup; - + /* * this initialize the library and check potential ABI mismatches * between the version it was compiled for and the actual shared * library used. */ - LIBXML_TEST_VERSION; + LIBXML_TEST_VERSION; source_dir = NULL; dst_dir = NULL; setup = malloc(sizeof(TGallerySetup)); - + /* Parse commandline */ if (! parse_cmd (argc, argv, &source_dir, &dst_dir, &verbose)) return -1; - + if ((! source_dir) || (access (source_dir, R_OK))) { fprintf (stderr, "error: source directory must be specified and pointing to valid structure\n"); return -4; - } + } if (! dst_dir) { fprintf (stderr, "error: target directory must be specified\n"); return -5; } - + /* Read gallery settings */ if (! find_setup_xml (setup)) { fprintf (stderr, "error: could not parse gallery settings file\n"); - return -2; - } + return -2; + } setup->real_templates_dir = find_templates_directory (setup); if (setup->real_templates_dir == NULL) { fprintf (stderr, "error: could not determine templates directory\n"); - return -3; - } - - + return -3; + } + + /* Start building the gallery tree */ setup->verbose = verbose; build_tree (setup, source_dir, dst_dir, NULL); - + /* Cleanup function for the XML library. */ xmlCleanupParser(); - + free (source_dir); free (dst_dir); free_setup_data (setup); - + return (0); } diff --git a/config.h b/config.h index 21ac1cd..3ce3d89 100644 --- a/config.h +++ b/config.h @@ -1,16 +1,16 @@ /* Cataract - Static web photo gallery generator * Copyright (C) 2008 Tomas Bzatek - * + * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/gallery-utils.c b/gallery-utils.c index ce80a4f..9253f51 100644 --- a/gallery-utils.c +++ b/gallery-utils.c @@ -1,16 +1,16 @@ /* Cataract - Static web photo gallery generator * Copyright (C) 2008 Tomas Bzatek - * + * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -31,7 +31,7 @@ strstr_exclude (const char *haystack, const char *needle, const char *exclude_wh char *found; src = haystack; - + while (src && strstr (src, needle)) { found = strstr (src, needle); @@ -49,42 +49,42 @@ strstr_exclude (const char *haystack, const char *needle, const char *exclude_wh /* * str_replace: replace substring 'search' with a 'replace' string - * - multiple occurences of the string are replaced + * - multiple occurrences of the string are replaced * - specify 'exclude_when' if you want to skip replace when a string found at the place of 'search' - * - reallocates the original string - */ -void + * - reallocates the original string + */ +void str_replace (char **dst, const char *search, const char *replace, const char *exclude_when) { - #define REPLACE_MAX_LENGTH 32768 + #define REPLACE_MAX_LENGTH 32768 static char d[REPLACE_MAX_LENGTH]; char *src; char *found; int i; - + /* TODO: add range checking */ - - if (strstr (*dst, search) == NULL || strlen (*dst) == 0 || + + if (strstr (*dst, search) == NULL || strlen (*dst) == 0 || strlen (search) == 0 || strlen (replace) == 0) return; - + i = 0; src = *dst; while (strstr_exclude (src, search, exclude_when)) { found = strstr_exclude (src, search, exclude_when); - + /* copy the data between search string */ if (found > src) { memcpy (&d[i], src, found - src); i += found - src; } - + /* copy replace string instead */ memcpy (&d[i], replace, strlen (replace)); i += strlen (replace); src = found + strlen (search); } - + /* copy the rest */ if (src) { memcpy (&d[i], src, strlen (src)); @@ -92,7 +92,7 @@ str_replace (char **dst, const char *search, const char *replace, const char *ex } d[i] = 0x0; - + #ifdef __DEBUG_ALL__ printf ("str_replace('%s', '%s') = '%s' --> '%s'\n", search, replace, *dst, &d[0]); #endif @@ -104,71 +104,71 @@ str_replace (char **dst, const char *search, const char *replace, const char *ex /* - * copy_file: copy file from src to dst - */ -gboolean + * copy_file: copy file from src to dst + */ +gboolean copy_file (const char *src, const char *dst) { #define BUFFER_SIZE 65536 - + FILE *fin; FILE *fout; void *buffer; int size_r; - + fin = fopen (src, "r"); if (fin == NULL) { fprintf (stderr, "copy_file: error reading file \"%s\": %s\n", src, strerror (errno)); - return FALSE; + return FALSE; } - + fout = fopen (dst, "w"); if (fout == NULL) { fprintf (stderr, "copy_file: error writing to file \"%s\": %s\n", dst, strerror (errno)); fclose (fin); - return FALSE; + return FALSE; } - + buffer = malloc (BUFFER_SIZE); memset (buffer, 0, BUFFER_SIZE); size_r = BUFFER_SIZE; - + while ((! feof (fin)) && (size_r == BUFFER_SIZE)) { size_r = fread (buffer, 1, BUFFER_SIZE, fin); fwrite (buffer, 1, size_r, fout); } - - fclose (fout); + + fclose (fout); fclose (fin); free (buffer); - - return TRUE; + + return TRUE; } /* * make_string: make string of 'substr' substrings - * - returns newly allocated string - */ + * - returns newly allocated string + */ char * make_string (const char* substr, const int count) { int i; char *s; - + s = malloc (strlen (substr) * count + 1); for (i = 0; i < count; i++) memcpy (s + (strlen (substr) * i), substr, strlen (substr)); - s[strlen (substr) * count] = 0; - return s; + s[strlen (substr) * count] = 0; + return s; } /* * fix_entities: replace all invalid & entities with & - * - returns newly allocated string + * - returns newly allocated string */ -void +void fix_entities (char **str) { static char d[REPLACE_MAX_LENGTH]; @@ -176,12 +176,12 @@ fix_entities (char **str) char *found; char *scan; int i; - + /* TODO: add range checking */ - + if (! *str || strstr (*str, "&") == NULL) return; - + i = 0; src = *str; while (strstr (src, "&")) { @@ -190,17 +190,17 @@ fix_entities (char **str) /* copy the data between search string */ memcpy (&d[i], src, found - src + 1); i += found - src + 1; - + /* scroll to next whitespace */ scan = found + 1; while (scan && ( - (*scan >= 0x41 && *scan <= 0x5a) || (*scan >= 0x61 && *scan <= 0x7a) || /* A-Z, a-z */ + (*scan >= 0x41 && *scan <= 0x5a) || (*scan >= 0x61 && *scan <= 0x7a) || /* A-Z, a-z */ (*scan >= 0x30 && *scan <= 0x39) || (*scan == 0x23) /* 0-9, # */ )) scan++; - + if (scan && (*scan == 0x3b)) { - /* this is semi-colon, correctly closed entity */ + /* this is semicolon, correctly closed entity */ /* -- ignore */ } else { @@ -210,7 +210,7 @@ fix_entities (char **str) } src = found + 1; } - + /* copy the rest */ if (src) { memcpy (&d[i], src, strlen (src)); @@ -218,7 +218,7 @@ fix_entities (char **str) } d[i] = 0x0; - + #ifdef __DEBUG_ALL__ printf ("fix_entities: '%s' --> '%s'\n", *str, &d[0]); #endif diff --git a/gallery-utils.h b/gallery-utils.h index 95dbcff..dd97663 100644 --- a/gallery-utils.h +++ b/gallery-utils.h @@ -1,16 +1,16 @@ /* Cataract - Static web photo gallery generator * Copyright (C) 2008 Tomas Bzatek - * + * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -25,23 +25,23 @@ * str_replace: replace substring 'search' with a 'replace' string * - multiple occurences of the string are replaced * - specify 'exclude_when' if you want to skip replace when a string found at the place of 'search' - * - reallocates the original string - */ + * - reallocates the original string + */ void str_replace (char **dst, const char *search, const char *replace, const char *exclude_when); /* - * copy_file: copy file from src to dst - */ + * copy_file: copy file from src to dst + */ gboolean copy_file (const char *src, const char *dst); /* - * make_string: make string of 'substr' substrings - * - returns newly allocated string - */ + * make_string: make string of 'substr' substrings + * - returns newly allocated string + */ char *make_string (const char* substr, const int count); /* * fix_entities: replace all invalid & entities with & - * - returns newly allocated string + * - returns newly allocated string */ -void fix_entities (char **str); \ No newline at end of file +void fix_entities (char **str); diff --git a/generators.c b/generators.c index 18fa25f..210bdb0 100644 --- a/generators.c +++ b/generators.c @@ -1,16 +1,16 @@ /* Cataract - Static web photo gallery generator * Copyright (C) 2008 Tomas Bzatek - * + * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -46,27 +46,27 @@ generate_image (TGallerySetup *setup, char *thumb_dst; char *big_dst; char *big_src; - char *orig_dst; + char *orig_dst; char *img_src_full; char *s1, *s2; int bigq; - - *img_src = item->thumbnail; - if (items->type == GALLERY_TYPE_INDEX) + + *img_src = item->thumbnail; + if (items->type == GALLERY_TYPE_INDEX) *img_src = item->thumbnail; - else + else if (items->type == GALLERY_TYPE_ALBUM) *img_src = (item->path == NULL && item->preview) ? item->preview : item->path; - + img_src_full = g_strconcat (items->base_dir, "/", *img_src, NULL); get_image_sizes (img_src_full, img_w, img_h); if ((img_w > 0) && (img_h > 0)) { new_w = *img_w; new_h = *img_h; - - + + /* Generate thumbnail */ s1 = g_path_get_dirname (dst); s2 = g_path_get_basename (*img_src); @@ -75,19 +75,19 @@ generate_image (TGallerySetup *setup, g_free (s2); if (setup->verbose) printf (" Generating thumbnail of '%s' ...", *img_src); - if ((*img_w / *img_h) >= 1) + if ((*img_w / *img_h) >= 1) calculate_sizes (setup->thumbnail_landscape_width, setup->thumbnail_landscape_height, &new_w, &new_h); - else + else calculate_sizes (setup->thumbnail_portrait_width, setup->thumbnail_portrait_height, &new_w, &new_h); if (! resize_image (img_src_full, thumb_dst, new_w, new_h, setup->thumbnail_quality)) fprintf (stderr, "write_html_index: error resizing thumbnail %s\n", img_src_full); - else + else if (setup->verbose) printf (" done.\n"); g_free (thumb_dst); - + /* Generate/copy preview and original image */ - if (items->type == GALLERY_TYPE_ALBUM) + if (items->type == GALLERY_TYPE_ALBUM) { s1 = g_path_get_dirname (dst); s2 = g_path_get_basename (*img_src); @@ -96,11 +96,11 @@ generate_image (TGallerySetup *setup, g_free (s2); if (item->preview == NULL) { - /* No preview image supplied, generate it from original */ + /* No preview image supplied, generate it from original */ bigq = setup->preview_quality; - if ((items->quality > 0) && (items->quality <= 100)) + if ((items->quality > 0) && (items->quality <= 100)) bigq = items->quality; - if ((item->quality > 0) && (item->quality <= 100)) + if ((item->quality > 0) && (item->quality <= 100)) bigq = item->quality; new_w = *img_w; new_h = *img_h; @@ -108,7 +108,7 @@ generate_image (TGallerySetup *setup, if (setup->verbose) printf (" Generating preview of '%s' ...", *img_src); if ((item->width > 0) && (item->height > 0)) { calculate_sizes (item->width, item->height, &new_w, &new_h); - } else { + } else { if ((*img_w / *img_h) >= 1) { if ((items->landscape_width > 0) && (items->landscape_height > 0)) @@ -124,10 +124,10 @@ generate_image (TGallerySetup *setup, calculate_sizes (setup->preview_portrait_width, setup->preview_portrait_height, &new_w, &new_h); } } - + if (! resize_image (img_src_full, big_dst, new_w, new_h, bigq)) fprintf (stderr, "write_html_index: error resizing big image %s\n", img_src_full); - else + else if (setup->verbose) printf (" done.\n"); } else @@ -137,13 +137,13 @@ generate_image (TGallerySetup *setup, if (setup->verbose) printf (" Copying preview image '%s' ...", *img_src); if (! copy_file (big_src, big_dst)) fprintf (stderr, "write_html_index: error copying preview image %s\n", big_src); - else + else if (setup->verbose) printf (" done.\n"); g_free (big_src); } g_free (big_dst); - if (! item->nofullsize) + if (! item->nofullsize) { s1 = g_path_get_dirname(dst); orig_dst = g_strconcat (s1, "/", IMG_ORIG_DIR, "/", *img_src, NULL); @@ -155,22 +155,22 @@ generate_image (TGallerySetup *setup, if (setup->verbose) printf(" done.\n"); g_free (orig_dst); } - } + } } - g_free (img_src_full); + g_free (img_src_full); } /* * write_html_album: process album and index template files - * + * * template_src = template file of the album/index * dst = save generated file as * items = array of items in the album/index * - */ -gboolean + */ +gboolean write_html_album (TGallerySetup *setup, const char *template_src, const char *dst, @@ -180,12 +180,12 @@ write_html_album (TGallerySetup *setup, FILE *fin; FILE *fout; char *buffer; - char *buf_img_list_landscape; + char *buf_img_list_landscape; char *buf_img_list_portrait; char *buf_go_up_string; - gboolean in_img_list; - gboolean in_img_list_landscape; - gboolean in_img_list_portrait; + gboolean in_img_list; + gboolean in_img_list_landscape; + gboolean in_img_list_portrait; gboolean in_go_up_string; char *b; char *s1, *s2, *s3, *s4; @@ -196,32 +196,32 @@ write_html_album (TGallerySetup *setup, int i; unsigned long img_w, img_h; const char *img_src; - - + + fin = fopen (template_src, "r"); if (fin == NULL) { fprintf (stderr, "write_html_index: error reading file \"%s\": %s\n", template_src, strerror (errno)); - return FALSE; + return FALSE; } fout = fopen (dst, "w"); if (fout == NULL) { fprintf (stderr, "write_html_index: error writing to file \"%s\": %s\n", dst, strerror (errno)); fclose (fin); - return FALSE; + return FALSE; } - + buffer = malloc (BUFFER_SIZE); - buf_img_list_landscape = malloc (BUFFER_SIZE); + buf_img_list_landscape = malloc (BUFFER_SIZE); buf_img_list_portrait = malloc (BUFFER_SIZE); buf_go_up_string = malloc (BUFFER_SIZE); - in_img_list = FALSE; - in_img_list_landscape = FALSE; - in_img_list_portrait = FALSE; + in_img_list = FALSE; + in_img_list_landscape = FALSE; + in_img_list_portrait = FALSE; in_go_up_string = FALSE; res = TRUE; - + /* Read through the template and replace placeholders with real data */ - while (! feof (fin)) + while (! feof (fin)) { memset (buffer, 0, BUFFER_SIZE); if (! fgets (buffer, BUFFER_SIZE, fin)) @@ -229,28 +229,28 @@ write_html_album (TGallerySetup *setup, if (buffer == NULL) continue; b = strdup (buffer); - - + + /* Block placeholders */ if (in_img_list && (strstr (buffer, ""))) { in_img_list_landscape = TRUE; free (b); - continue; + continue; } if (in_img_list && (strstr (buffer, ""))) { in_img_list_landscape = FALSE; free (b); - continue; + continue; } if (in_img_list && (strstr (buffer, ""))) { in_img_list_portrait = TRUE; free (b); - continue; + continue; } if (in_img_list && (strstr (buffer, ""))) { in_img_list_portrait = FALSE; free (b); - continue; + continue; } if (in_img_list && in_img_list_landscape) { buf_img_list_landscape = strncat (buf_img_list_landscape, b, BUFFER_SIZE - strlen (buf_img_list_landscape) - 2); @@ -272,7 +272,7 @@ write_html_album (TGallerySetup *setup, if (in_go_up_string && (strstr (buffer, ""))) { in_go_up_string = FALSE; free (b); - /* print the "Go Up" string if not toplevel */ + /* print the "Go Up" string if not toplevel */ if (items->parent_index) b = strdup (buf_go_up_string); else continue; @@ -283,8 +283,8 @@ write_html_album (TGallerySetup *setup, continue; } - - /* Simple placeholders */ + + /* Simple placeholders */ if (strstr (b, "") && items->ID) { s1 = g_strdup (items->ID); fix_entities (&s1); @@ -310,10 +310,10 @@ write_html_album (TGallerySetup *setup, g_free (s1); } if (strstr (b, "")) { - s1 = g_strdup_printf ("%d", items->items->len); + s1 = g_strdup_printf ("%d", items->items->len); str_replace (&b, "", s1, NULL); g_free (s1); - } + } if (strstr (b, "")) { s1 = g_strdup (items->ID); fix_entities (&s1); @@ -329,11 +329,11 @@ write_html_album (TGallerySetup *setup, g_free (s4); s1 = s2; parent = parent->parent_index; - level++; + level++; } str_replace (&b, "", s1, NULL); g_free (s1); - } + } /* Image list, nested placeholders */ if (strstr (buffer, "")) { @@ -350,15 +350,15 @@ write_html_album (TGallerySetup *setup, in_img_list = FALSE; in_img_list_landscape = FALSE; in_img_list_portrait = FALSE; - + /* Now we have all block placeholders read, generate the items: */ - for (i = 0; i < items->items->len; i++) + for (i = 0; i < items->items->len; i++) { item = g_ptr_array_index (items->items, i); if (item == NULL) { - fprintf (stderr, "write_html_index: error getting item %d\n", i); + fprintf (stderr, "write_html_index: error getting item %d\n", i); free (b); - continue; + continue; } /* Generate the images (preview, original, thumbnail) */ @@ -368,11 +368,11 @@ write_html_album (TGallerySetup *setup, generate_image (setup, items, item, dst, &img_w, &img_h, &img_src); /* Process HTML box code */ - if ((img_w / img_h) >= 1) + if ((img_w / img_h) >= 1) s1 = strdup (buf_img_list_landscape); - else + else s1 = strdup (buf_img_list_portrait); - + if (strstr (s1, "")) { s2 = g_strconcat (item->path, "/index.html", NULL); str_replace (&s1, "", s2, NULL); @@ -401,10 +401,10 @@ write_html_album (TGallerySetup *setup, str_replace (&s1, "", s2, NULL); g_free (s2); g_free (s3); - } + } if (strstr (s1, "")) { s3 = g_path_get_basename (img_src); - s2 = g_strconcat (THUMBNAIL_DIR, "/", s3, NULL); + s2 = g_strconcat (THUMBNAIL_DIR, "/", s3, NULL); str_replace (&s1, "", s2, NULL); g_free (s2); g_free (s3); @@ -412,10 +412,10 @@ write_html_album (TGallerySetup *setup, if (strstr (s1, "")) str_replace (&s1, "", img_src, NULL); - + #ifdef __DEBUG_ALL__ printf("***** %s ******\n", s1); - #endif + #endif if (! fputs (s1, fout)) { fprintf (stderr, "write_html_index: error writing to file \"%s\": %s\n", dst, strerror (errno)); res = FALSE; @@ -437,34 +437,34 @@ write_html_album (TGallerySetup *setup, } free (b); } - + fclose (fout); fclose (fin); free (buffer); - free (buf_img_list_landscape); + free (buf_img_list_landscape); free (buf_img_list_portrait); free (buf_go_up_string); - return res; + return res; } /* * write_html_image: process single image template file - * + * * template_src = template file of the album/index * original_img = source image file (original full-size) to get EXIF data from * dst = save generated file as * item = data for the current item * parent_items = array of items in the album, to determine our position and make links to previous/next image - * - */ -gboolean -write_html_image (TGallerySetup *setup, - const char *template_src, - const char *original_img, - const char *dst, - TIndexItem *item, + * + */ +gboolean +write_html_image (TGallerySetup *setup, + const char *template_src, + const char *original_img, + const char *dst, + TIndexItem *item, TAlbum *parent_items) { #define BUFFER_SIZE 65536 @@ -487,41 +487,41 @@ write_html_image (TGallerySetup *setup, char *b; gboolean res; int level; - - + + fin = fopen (template_src, "r"); if (fin == NULL) { fprintf (stderr, "write_html_image: error reading file \"%s\": %s\n", template_src, strerror (errno)); - return FALSE; + return FALSE; } fout = fopen (dst, "w"); if (fout == NULL) { fprintf (stderr, "write_html_image: error writing to file \"%s\": %s\n", dst, strerror (errno)); fclose (fin); - return FALSE; + return FALSE; } - + 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); + 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) + if (! item->nofullsize) get_image_sizes (orig_dst, &img_orig_w, &img_orig_h); - + /* Get our index in the album */ item_index = 0; for (i = 0; i < parent_items->items->len; i++) @@ -529,45 +529,45 @@ write_html_image (TGallerySetup *setup, item_index = i + 1; break; } - + /* Get previous and next items */ previous_item = NULL; next_item = NULL; - if (item_index > 1) - previous_item = g_ptr_array_index (parent_items->items, item_index - 2); - if (item_index < parent_items->items->len) + if (item_index > 1) + previous_item = g_ptr_array_index (parent_items->items, item_index - 2); + if (item_index < parent_items->items->len) next_item = g_ptr_array_index (parent_items->items, item_index); - + /* Read through the template and replace placeholders with real data */ while (! feof (fin)) { - memset (buffer, 0, BUFFER_SIZE); - if (! fgets (buffer, BUFFER_SIZE, fin)) + memset (buffer, 0, BUFFER_SIZE); + if (! fgets (buffer, BUFFER_SIZE, fin)) break; b = strdup (buffer); - + /* Block placeholders */ if (strstr (buffer, "")) { in_img_fullsize_link = TRUE; free (b); - continue; + continue; } if (strstr (buffer, "")) { in_img_fullsize_link = FALSE; free (b); if (! item->nofullsize) b = strdup (buf_img_fullsize_link); - else continue; + else continue; } if (in_img_fullsize_link) { buf_img_fullsize_link = strncat (buf_img_fullsize_link, b, BUFFER_SIZE - strlen (buf_img_fullsize_link) - 2); free (b); - continue; + continue; } - - /* Simple placeholders */ + + /* Simple placeholders */ if (strstr (b, "")) str_replace (&b, "", imgname, NULL); if (strstr (b, "") && item->title) { @@ -583,15 +583,15 @@ write_html_image (TGallerySetup *setup, g_free (s1); } if (strstr (b, "")) { - s1 = g_strdup_printf ("%d", parent_items->items->len); + s1 = g_strdup_printf ("%d", parent_items->items->len); str_replace (&b, "", s1, NULL); g_free (s1); - } + } if (strstr (b, "")) { - s1 = g_strdup_printf ("%d", item_index); + s1 = g_strdup_printf ("%d", item_index); str_replace(&b, "", s1, NULL); g_free (s1); - } + } if (strstr (b, "")) { // s1 = g_strconcat (item->title, " (", imgname, ")", NULL); s1 = g_strdup (imgname); @@ -607,82 +607,92 @@ write_html_image (TGallerySetup *setup, g_free (s4); s1 = s2; parent = parent->parent_index; - level++; + level++; } str_replace (&b, "", s1, NULL); g_free (s1); - } + } if (strstr (b, "")) { s1 = g_strconcat (IMG_BIG_DIR, "/", imgname, NULL); str_replace (&b, "", s1, NULL); g_free (s1); } - if (strstr(b, "")) { + if (strstr (b, "")) { s1 = g_strconcat (IMG_ORIG_DIR, "/", imgname, NULL); str_replace (&b, "", s1, NULL); g_free (s1); } - if (strstr(b, "")) { - s1 = g_strdup_printf ("%lu", img_big_w); + if (strstr (b, "")) { + s1 = g_strdup_printf ("%lu", img_big_w); str_replace (&b, "", s1, NULL); g_free (s1); } - if (strstr(b, "")) { - s1 = g_strdup_printf ("%lu", img_big_h); + if (strstr (b, "")) { + s1 = g_strdup_printf ("%lu", img_big_h); str_replace (&b, "", s1, NULL); g_free (s1); } - if (strstr(b, "")) { - s1 = g_strdup_printf ("%lu", img_orig_w); + if (strstr (b, "")) { + s1 = g_strdup_printf ("%lu", img_orig_w); str_replace (&b, "", s1, NULL); g_free (s1); } - if (strstr(b, "")) { - s1 = g_strdup_printf ("%lu", img_orig_h); + if (strstr (b, "")) { + s1 = g_strdup_printf ("%lu", img_orig_h); str_replace (&b, "", s1, NULL); g_free (s1); } + if (strstr (b, "")) { + s1 = item->border_style; + if (s1 == NULL) + s1 = parent_items->border_style; + if (s1 == NULL) + s1 = setup->border_style; + if (s1 == NULL) + s1 = "border_single"; + str_replace (&b, "", s1, NULL); + } if (strstr (b, "")) { - if (exif->iso) + if (exif->iso) str_replace (&b, "", exif->iso, NULL); - else + else str_replace (&b, "", "??", NULL); - } + } if (strstr (b, "")) { - if (exif->exposure) + if (exif->exposure) str_replace (&b, "", exif->exposure, NULL); - else + else str_replace (&b, "", "??", NULL); } if (strstr (b, "")) { - if (exif->aperture) + if (exif->aperture) str_replace (&b, "", exif->aperture, NULL); - else + else str_replace (&b, "", "??", NULL); } if (strstr (b, "")) { - if (exif->focal_length) + if (exif->focal_length) str_replace (&b, "", exif->focal_length, NULL); - else + else str_replace (&b, "", "??", NULL); } if (strstr (b, "")) { - if (exif->flash) + if (exif->flash) str_replace (&b, "", exif->flash, NULL); - else + else str_replace (&b, "", "??", NULL); } if (strstr (b, "")) { - if (exif->datetime) + if (exif->datetime) str_replace (&b, "", exif->datetime, NULL); - else + else str_replace (&b, "", "??", NULL); } if (strstr (b, "")) { - if (exif->camera_model) + if (exif->camera_model) str_replace (&b, "", exif->camera_model, NULL); - else + else str_replace (&b, "", "??", NULL); } if (strstr (b, "")) { @@ -691,7 +701,7 @@ write_html_image (TGallerySetup *setup, str_replace (&b, "", s1, NULL); g_free (s1); } - else + else str_replace (&b, "", "", NULL); } @@ -703,9 +713,9 @@ write_html_image (TGallerySetup *setup, g_free (s1); g_free (s2); } - else + else str_replace (&b, "", "index.html", NULL); - } + } if (strstr(b, "")) { if (previous_item) { s2 = (previous_item->path == NULL && previous_item->preview) ? g_path_get_basename (previous_item->preview) : g_strdup (previous_item->path); @@ -714,9 +724,9 @@ write_html_image (TGallerySetup *setup, g_free (s1); g_free (s2); } - else + else str_replace (&b, "", "index.html", NULL); - } + } if (strstr (b, "")) { s1 = g_strdup (setup->footer); @@ -733,8 +743,8 @@ write_html_image (TGallerySetup *setup, } free (b); } - - fclose (fout); + + fclose (fout); fclose (fin); free (buffer); free (big_dst); @@ -748,16 +758,16 @@ write_html_image (TGallerySetup *setup, /* * build_tree: generate complete gallery tree based on source xml files - * + * * src_tree = source directory of the items * dst_dir = destination of the generated items - * parent_index = parent album to determine our descent in the tree - * - */ -gboolean -build_tree (TGallerySetup *setup, - const char *src_tree, - const char *dst_dir, + * parent_index = parent album to determine our descent in the tree + * + */ +gboolean +build_tree (TGallerySetup *setup, + const char *src_tree, + const char *dst_dir, TAlbum *parent_index) { char *idx_file; @@ -771,13 +781,13 @@ build_tree (TGallerySetup *setup, char *imgname; gboolean res; int i; - - printf ("*** Entering directory '%s'\n", src_tree); + + printf ("*** Entering directory '%s'\n", src_tree); #ifdef __DEBUG_ALL__ printf ("setup->real_templates_dir = %s\n", setup->real_templates_dir); #endif - /* Check access permissions */ + /* Check access permissions */ if (access (src_tree, R_OK | X_OK)) { fprintf (stderr, "error accessing source directory: %s\n", strerror (errno)); return FALSE; @@ -787,7 +797,7 @@ build_tree (TGallerySetup *setup, fprintf (stderr, "error creating destination directory: %s\n", strerror (errno)); return FALSE; } - } + } /* Check the index file */ idx_file = g_strconcat (src_tree, "/index.xml", NULL); @@ -796,7 +806,7 @@ build_tree (TGallerySetup *setup, g_free (idx_file); return FALSE; } - + /* Read the index file and fill items array */ items = malloc (sizeof (TAlbum)); if (! parse_album_xml (idx_file, items)) { @@ -808,7 +818,7 @@ build_tree (TGallerySetup *setup, g_free (idx_file); items->parent_index = parent_index; - + /* Copy support files */ if (setup->verbose) printf ("Writing '%s' ...", setup->styles); s1 = g_strconcat (setup->real_templates_dir, "/", setup->styles, NULL); @@ -817,33 +827,33 @@ build_tree (TGallerySetup *setup, g_free (s1); g_free (s2); if (setup->verbose) printf (" done.\n"); - + if (setup->verbose) printf ("Writing '%s' ...", setup->scripts); s1 = g_strconcat (setup->real_templates_dir, "/", setup->scripts, NULL); - s2 = g_strconcat (dst_dir, "/", setup->scripts, NULL); + s2 = g_strconcat (dst_dir, "/", setup->scripts, NULL); copy_file (s1, s2); g_free (s1); g_free (s2); - if (setup->verbose) printf (" done.\n"); + if (setup->verbose) printf (" done.\n"); + - /* Prepare target thumbnail directory */ - thumb_dir = g_strconcat (dst_dir, "/", THUMBNAIL_DIR, NULL); + thumb_dir = g_strconcat (dst_dir, "/", THUMBNAIL_DIR, NULL); if (access (thumb_dir, R_OK | W_OK | X_OK)) if (mkdir (thumb_dir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) { fprintf (stderr, "error making target thumbnail directory: %s\n", strerror (errno)); g_free (thumb_dir); free_album_data (items); - return FALSE; + return FALSE; } g_free (thumb_dir); - + /* Prepare target preview and orig directories */ - if (items->type == GALLERY_TYPE_ALBUM) + if (items->type == GALLERY_TYPE_ALBUM) { - res = TRUE; - img_big_dir = g_strconcat (dst_dir, "/", IMG_BIG_DIR, NULL); - img_orig_dir = g_strconcat (dst_dir, "/", IMG_ORIG_DIR, NULL); + res = TRUE; + img_big_dir = g_strconcat (dst_dir, "/", IMG_BIG_DIR, NULL); + img_orig_dir = g_strconcat (dst_dir, "/", IMG_ORIG_DIR, NULL); if (access (img_big_dir, R_OK | W_OK | X_OK)) if (mkdir (img_big_dir, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) { fprintf (stderr, "error making target preview directory: %s\n", strerror (errno)); @@ -862,18 +872,18 @@ build_tree (TGallerySetup *setup, } } - + /* Start generating items */ - if (items->type == GALLERY_TYPE_INDEX) + if (items->type == GALLERY_TYPE_INDEX) template = g_strconcat ("/", setup->template_index, NULL); - else - if (items->type == GALLERY_TYPE_ALBUM) + else + if (items->type == GALLERY_TYPE_ALBUM) template = g_strconcat ("/", setup->template_album, NULL); if (setup->verbose) printf ("Writing 'index.html' ...\n"); s1 = g_strconcat (setup->real_templates_dir, template, NULL); s2 = g_strconcat (dst_dir, "/index.html", NULL); - res = write_html_album (setup, s1, s2, items); + res = write_html_album (setup, s1, s2, items); g_free (s1); g_free (s2); g_free (template); @@ -884,16 +894,16 @@ build_tree (TGallerySetup *setup, } if (setup->verbose) printf (" done.\n"); - + /* Recurse to sub-albums (in case of album index) */ - if (items->type == GALLERY_TYPE_INDEX) + if (items->type == GALLERY_TYPE_INDEX) { if (items->items->len > 0) { for (i = 0; i < items->items->len; i++) { item = g_ptr_array_index (items->items, i); if (item == NULL) { - fprintf (stderr, "build_tree: error getting item %d\n", i); - continue; + fprintf (stderr, "build_tree: error getting item %d\n", i); + continue; } s1 = g_strconcat (src_tree, "/", item->path, "/", NULL); s2 = g_strconcat (dst_dir, "/", item->path, "/", NULL); @@ -901,20 +911,20 @@ build_tree (TGallerySetup *setup, g_free (s1); g_free (s2); } - } + } } - + /* Generate separate image pages (in case of album) */ - if (items->type == GALLERY_TYPE_ALBUM) + if (items->type == GALLERY_TYPE_ALBUM) { if (items->items->len > 0) { - for (i = 0; i < items->items->len; i++) { + for (i = 0; i < items->items->len; i++) { item = g_ptr_array_index (items->items, i); if (item == NULL) { - fprintf (stderr, "build_tree: error getting item %d\n", i); - continue; + fprintf (stderr, "build_tree: error getting item %d\n", i); + continue; } - imgname = (item->path == NULL && item->preview) ? g_path_get_basename (item->preview) : g_strdup (item->path); + imgname = (item->path == NULL && item->preview) ? g_path_get_basename (item->preview) : g_strdup (item->path); if (setup->verbose) printf ("Writing '%s.html' ...", imgname); s1 = g_strconcat (setup->real_templates_dir, "/", setup->template_photo, NULL); s2 = g_strconcat (items->base_dir, "/", (item->path == NULL && item->preview) ? item->preview : item->path, NULL); @@ -924,14 +934,14 @@ build_tree (TGallerySetup *setup, g_free (s2); g_free (s3); g_free (imgname); - if (! res ) continue; - if (setup->verbose) printf (" done.\n"); - } + if (! res ) continue; + if (setup->verbose) printf (" done.\n"); + } } } printf ("*** Leaving directory '%s'\n", src_tree); free_album_data (items); - return TRUE; + return TRUE; } diff --git a/generators.h b/generators.h index 9dc9446..c87e8a3 100644 --- a/generators.h +++ b/generators.h @@ -1,16 +1,16 @@ /* Cataract - Static web photo gallery generator * Copyright (C) 2008 Tomas Bzatek - * + * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -21,12 +21,12 @@ /* * write_html_album: process album and index template files - * + * * template_src = template file of the album/index * dst = save generated file as * items = array of items in the album/index * - */ + */ gboolean write_html_album (TGallerySetup *setup, const char *template_src, const char *dst, @@ -34,31 +34,31 @@ gboolean write_html_album (TGallerySetup *setup, /* * write_html_image: process single image template file - * + * * template_src = template file of the album/index * original_img = source image file (original full-size) to get EXIF data from * dst = save generated file as * item = data for the current item * parent_items = array of items in the album, to determine our position and make links to previous/next image - * - */ -gboolean write_html_image (TGallerySetup *setup, - const char *template_src, - const char *original_img, - const char *dst, - TIndexItem *item, + * + */ +gboolean write_html_image (TGallerySetup *setup, + const char *template_src, + const char *original_img, + const char *dst, + TIndexItem *item, TAlbum *parent_items); /* * build_tree: generate complete gallery tree based on source xml files - * + * * src_tree = source directory of the items * dst_dir = destination of the generated items - * parent_index = parent album to determine our descent in the tree - * - */ -gboolean build_tree (TGallerySetup *setup, - const char *src_tree, - const char *dst_dir, + * parent_index = parent album to determine our descent in the tree + * + */ +gboolean build_tree (TGallerySetup *setup, + const char *src_tree, + const char *dst_dir, TAlbum *parent_index); diff --git a/items.c b/items.c index 2c7b094..91eee63 100644 --- a/items.c +++ b/items.c @@ -1,16 +1,16 @@ /* Cataract - Static web photo gallery generator * Copyright (C) 2008 Tomas Bzatek - * + * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -30,9 +30,9 @@ /* - * parse_album_xml: XML parser for gallery index.xml files - */ -gboolean + * parse_album_xml: XML parser for gallery index.xml files + */ +gboolean parse_album_xml (const char *filename, TAlbum *index) { TXMLFile *xml; @@ -41,13 +41,13 @@ parse_album_xml (const char *filename, TAlbum *index) int i; char *s; TIndexItem *item; - + xml = xml_parser_load (filename); if (xml == NULL) return FALSE; - + /* Initialize data struct */ - if (index == NULL) + if (index == NULL) index = malloc (sizeof (TAlbum)); memset (index, 0, sizeof (TAlbum)); @@ -60,7 +60,7 @@ parse_album_xml (const char *filename, TAlbum *index) #endif if (strcmp (gallery_type, "index") == 0) index->type = GALLERY_TYPE_INDEX; - else + else if (strcmp (gallery_type, "album") == 0) index->type = GALLERY_TYPE_ALBUM; else { @@ -68,67 +68,70 @@ parse_album_xml (const char *filename, TAlbum *index) free (index); return FALSE; } - + /* Section General */ index->ID = xml_file_get_node_value (xml, "/gallery/general/ID/text()"); index->title = xml_file_get_node_value (xml, "/gallery/general/title/text()"); index->desc = xml_file_get_node_value (xml, "/gallery/general/description/text()"); - + index->quality = xml_file_get_node_attribute_long (xml, "/gallery/general/images", "quality", -1); index->landscape_width = xml_file_get_node_attribute_long (xml, "/gallery/general/images", "landscape_w", 0); index->landscape_height = xml_file_get_node_attribute_long (xml, "/gallery/general/images", "landscape_h", 0); index->portrait_width = xml_file_get_node_attribute_long (xml, "/gallery/general/images", "portrait_w", 0); index->portrait_height = xml_file_get_node_attribute_long (xml, "/gallery/general/images", "portrait_h", 0); + index->border_style = xml_file_get_node_attribute (xml, "/gallery/general/border", "style"); + /* Section Items */ count = xml_file_node_get_children_count (xml, "/gallery/items/item"); index->items = g_ptr_array_new(); - + for (i = 0; i < count; i++) { item = malloc (sizeof (TIndexItem)); memset (item, 0, sizeof (TIndexItem)); s = g_strdup_printf ("/gallery/items/item[%d]", i + 1); - if (index->type == GALLERY_TYPE_INDEX) + if (index->type == GALLERY_TYPE_INDEX) item->path = xml_file_get_node_attribute (xml, s, "path"); - else + else item->path = xml_file_get_node_attribute (xml, s, "src"); item->preview = xml_file_get_node_attribute (xml, s, "preview"); item->quality = xml_file_get_node_attribute_long (xml, s, "quality", -1); item->width = xml_file_get_node_attribute_long (xml, s, "width", 0); item->height = xml_file_get_node_attribute_long (xml, s, "height", 0); + item->border_style = xml_file_get_node_attribute (xml, s, "border"); g_free (s); s = g_strdup_printf ("/gallery/items/item[%d]/title/text()", i + 1); item->title = xml_file_get_node_value (xml, s); g_free (s); - + s = g_strdup_printf ("/gallery/items/item[%d]/title_description/text()", i + 1); item->title_description = xml_file_get_node_value (xml, s); g_free (s); - + s = g_strdup_printf ("/gallery/items/item[%d]/thumbnail", i + 1); item->thumbnail = xml_file_get_node_attribute (xml, s, "src"); g_free (s); - + s = g_strdup_printf ("/gallery/items/item[%d]/nofullsize", i + 1); item->nofullsize = (xml_file_get_node_present (xml, s) || item->path == NULL); g_free (s); - if (item->path || item->preview) + if (item->path || item->preview) { - g_ptr_array_add (index->items, item); - } + g_ptr_array_add (index->items, item); + } else { fprintf (stderr, "%s: No image src specified, skipping!\n", filename); free (item); } } - + xml_parser_close (xml); - + /* Print the items */ #ifdef __DEBUG_ALL__ printf ("ID = '%s'\ntitle = '%s'\ndescription = '%s'\n", index->ID, index->title, index->desc); @@ -138,18 +141,18 @@ parse_album_xml (const char *filename, TAlbum *index) i, item->path, item->title, item->title_description, item->thumbnail); } #endif - return TRUE; + return TRUE; } /* * free_album_data: free allocated album data */ -void +void free_album_data (TAlbum *album) { if (album) { - if (album->ID) + if (album->ID) free (album->ID); if (album->title) free (album->title); @@ -157,12 +160,14 @@ free_album_data (TAlbum *album) free (album->desc); if (album->base_dir) free (album->base_dir); - + if (album->border_style) + free (album->border_style); + if (album->items) { if (album->items->len > 0) { TIndexItem *item; int i; - + for (i = 0; i < album->items->len; i++) { item = g_ptr_array_index (album->items, i); if (item != NULL) { @@ -176,31 +181,33 @@ free_album_data (TAlbum *album) free (item->thumbnail); if (item->preview) free (item->preview); + if (item->border_style) + free (item->border_style); free (item); } } } - g_ptr_array_free (album->items, TRUE); + g_ptr_array_free (album->items, TRUE); } free (album); - album = NULL; + album = NULL; } } /* - * get_gallery_objects_count: retrieve number of items in specified album - */ -int + * get_gallery_objects_count: retrieve number of items in specified album + */ +int get_album_objects_count (const char *filename) { TXMLFile *xml; int count; - + xml = xml_parser_load (filename); if (xml == NULL) return 0; - + count = xml_file_node_get_children_count (xml, "/gallery/items/item"); xml_parser_close (xml); diff --git a/items.h b/items.h index b89728c..c6143ca 100644 --- a/items.h +++ b/items.h @@ -1,22 +1,22 @@ /* Cataract - Static web photo gallery generator * Copyright (C) 2008 Tomas Bzatek - * + * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef __ITEMS_H__ -#define __ITEMS_H__ +#ifndef __ITEMS_H__ +#define __ITEMS_H__ #include @@ -25,7 +25,7 @@ typedef enum { GALLERY_TYPE_INDEX = 1 << 0, GALLERY_TYPE_ALBUM = 1 << 1 -} TGalleryType; +} TGalleryType; typedef struct { TGalleryType type; @@ -40,6 +40,7 @@ typedef struct { unsigned long landscape_height; unsigned long portrait_width; unsigned long portrait_height; + char *border_style; } TAlbum; typedef struct { @@ -52,13 +53,14 @@ typedef struct { unsigned long width; unsigned long height; gboolean nofullsize; + char *border_style; } TIndexItem; /* - * parse_album_xml: XML parser for gallery index.xml files - */ + * parse_album_xml: XML parser for gallery index.xml files + */ gboolean parse_album_xml (const char *filename, TAlbum *index); /* @@ -67,8 +69,8 @@ gboolean parse_album_xml (const char *filename, TAlbum *index); void free_album_data (TAlbum *index); /* - * get_album_objects_count: retrieve number of items in specified album - */ + * get_album_objects_count: retrieve number of items in specified album + */ int get_album_objects_count (const char *filename); diff --git a/jpeg-utils.cpp b/jpeg-utils.cpp index 973b448..5c50914 100644 --- a/jpeg-utils.cpp +++ b/jpeg-utils.cpp @@ -1,16 +1,16 @@ /* Cataract - Static web photo gallery generator * Copyright (C) 2008 Tomas Bzatek - * + * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -29,17 +29,17 @@ /* - * get_exif: retrieve EXIF informations from a JPEG image - */ -int + * get_exif: retrieve EXIF informations from a JPEG image + */ +int get_exif (const char *filename, TExifData **exif_data) { TExifData *data; - + data = (TExifData*) malloc (sizeof (TExifData)); memset (data, 0, sizeof (TExifData)); *exif_data = data; - + try { Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(filename); @@ -56,7 +56,7 @@ get_exif (const char *filename, TExifData **exif_data) } catch (...) { } /* EXIF::Camera model */ - try { + try { const char *val = exifData["Exif.Image.Model"].toString().c_str(); if (val && strlen(val) > 0) data->camera_model = strdup (val); @@ -72,12 +72,12 @@ get_exif (const char *filename, TExifData **exif_data) try { val = exifData["Exif.Image.DateTime"].toString().c_str(); } catch (...) { } - + if (val && strlen(val) > 0) { static struct tm tt; static char conv[1024]; - - if (sscanf (val, "%d:%d:%d %d:%d:%d", &tt.tm_year, &tt.tm_mon, &tt.tm_mday, &tt.tm_hour, &tt.tm_min, &tt.tm_sec) == 6) + + if (sscanf (val, "%d:%d:%d %d:%d:%d", &tt.tm_year, &tt.tm_mon, &tt.tm_mday, &tt.tm_hour, &tt.tm_min, &tt.tm_sec) == 6) { tt.tm_year -= 1900; tt.tm_mon--; @@ -95,15 +95,15 @@ get_exif (const char *filename, TExifData **exif_data) data->exposure = g_strdup_printf ("1/%.0f s", 1/val); else data->exposure = g_strdup_printf ("%.1f s", val); - } + } } catch (...) { } /* EXIF::Flash */ try { - long int val = exifData["Exif.Photo.Flash"].toLong(); + long int val = exifData["Exif.Photo.Flash"].toLong(); if ((val > 0) && ((val & 1) == 1)) data->flash = strdup ((char *) "Flash fired"); - else + else data->flash = strdup ((char *) "--"); } catch (...) { } @@ -122,27 +122,27 @@ get_exif (const char *filename, TExifData **exif_data) } catch (...) { } /* EXIF::Software */ - try { + try { data->exif_software = strdup (exifData["Exif.Image.Software"].toString().c_str()); } catch (...) { } - + /* EXIF::Image description */ - try { + try { data->exif_imgdesc = strdup (exifData["Exif.Image.ImageDescription"].toString().c_str()); } catch (...) { } - + /* EXIF::Artist */ - try { + try { data->exif_artist = strdup (exifData["Exif.Image.Artist"].toString().c_str()); } catch (...) { } - + /* EXIF::Copyright */ - try { + try { data->exif_copyright = strdup (exifData["Exif.Image.Copyright"].toString().c_str()); } catch (...) { } - + /* EXIF::User comment */ - try { + try { data->exif_usercomment = strdup (exifData["Exif.Photo.UserComment"].toString().c_str()); } catch (...) { } } @@ -150,45 +150,45 @@ get_exif (const char *filename, TExifData **exif_data) Exiv2::IptcData &iptcData = image->iptcData(); if (! iptcData.empty()) { /* IPTC::Object name */ - try { + try { data->iptc_objectname = strdup (iptcData["Iptc.Application2.ObjectName"].toString().c_str()); } catch (...) { } /* IPTC::Copyright */ - try { + try { data->iptc_copyright = strdup (iptcData["Iptc.Application2.Copyright"].toString().c_str()); } catch (...) { } /* IPTC::Credit */ - try { + try { data->iptc_credit = strdup (iptcData["Iptc.Application2.Credit"].toString().c_str()); } catch (...) { } /* IPTC::Caption */ - try { + try { data->iptc_caption = strdup (iptcData["Iptc.Application2.Caption"].toString().c_str()); } catch (...) { } /* IPTC::Author */ - try { + try { data->iptc_author = strdup (iptcData["Iptc.Application2.Byline"].toString().c_str()); } catch (...) { } } - + } - catch (Exiv2::AnyError& e) + catch (Exiv2::AnyError& e) { fprintf (stderr, "get_exif: Caught Exiv2 exception: '%s'\n", e.what()); return -1; } - + /* Read the JPEG comment */ MagickBooleanType status; MagickWand *magick_wand; char *comment; MagickWandGenesis(); - magick_wand = NewMagickWand(); + magick_wand = NewMagickWand(); status = MagickPingImage (magick_wand, filename); if (status == MagickTrue) { comment = MagickGetImageProperty(magick_wand, "comment"); @@ -198,8 +198,8 @@ get_exif (const char *filename, TExifData **exif_data) } magick_wand = DestroyMagickWand (magick_wand); MagickWandTerminus(); - - + + #ifdef __DEBUG_ALL__ printf("EXIF_TAG_DATE_TIME = '%s'\n", data->datetime); printf("EXIF_TAG_MODEL = '%s'\n", data->camera_model); @@ -220,72 +220,72 @@ get_exif (const char *filename, TExifData **exif_data) printf("Iptc.Application2.Caption = '%s'\n", data->iptc_caption); printf("Iptc.Application2.Byline = '%s'\n", data->iptc_author); printf("JPEG comment = '%s'\n", data->jpeg_comment); -#endif +#endif - return 0; + return 0; } /* - * free_exif_struct: free allocated structure - */ -void + * free_exif_struct: free allocated structure + */ +void free_exif_data (TExifData *data) { if (data) { - if (data->aperture) - free (data->aperture); - if (data->camera_model) - free (data->camera_model); - if (data->datetime) - free (data->datetime); - if (data->exposure) - free (data->exposure); - if (data->flash) - free (data->flash); - if (data->focal_length) - free (data->focal_length); - if (data->focal_length_35mm) - free (data->focal_length_35mm); - if (data->iso) + if (data->aperture) + free (data->aperture); + if (data->camera_model) + free (data->camera_model); + if (data->datetime) + free (data->datetime); + if (data->exposure) + free (data->exposure); + if (data->flash) + free (data->flash); + if (data->focal_length) + free (data->focal_length); + if (data->focal_length_35mm) + free (data->focal_length_35mm); + if (data->iso) free (data->iso); - if (data->exif_software) + if (data->exif_software) free (data->exif_software); - if (data->exif_imgdesc) + if (data->exif_imgdesc) free (data->exif_imgdesc); - if (data->exif_artist) + if (data->exif_artist) free (data->exif_artist); - if (data->exif_copyright) + if (data->exif_copyright) free (data->exif_copyright); - if (data->exif_usercomment) + if (data->exif_usercomment) free (data->exif_usercomment); - - if (data->iptc_objectname) + + if (data->iptc_objectname) free (data->iptc_objectname); - if (data->iptc_copyright) + if (data->iptc_copyright) free (data->iptc_copyright); - if (data->iptc_credit) + if (data->iptc_credit) free (data->iptc_credit); - if (data->iptc_caption) + if (data->iptc_caption) free (data->iptc_caption); - if (data->iptc_author) + if (data->iptc_author) free (data->iptc_author); - - if (data->jpeg_comment) + + if (data->jpeg_comment) free (data->jpeg_comment); - + free (data); data = NULL; - } + } } /* - * resize_image: resize image pointed by src and save result to dst - */ -gboolean -resize_image (const char *src, const char *dst, - int size_x, int size_y, + * resize_image: resize image pointed by src and save result to dst + */ +gboolean +resize_image (const char *src, const char *dst, + int size_x, int size_y, int quality) { #define ThrowWandException(wand) \ @@ -298,19 +298,19 @@ resize_image (const char *src, const char *dst, description = (char*) MagickRelinquishMemory (description); \ return FALSE; \ } - + MagickBooleanType status; MagickWand *magick_wand; - + /* Read an image. */ MagickWandGenesis(); - magick_wand = NewMagickWand(); + magick_wand = NewMagickWand(); status = MagickReadImage (magick_wand, src); if (status == MagickFalse) ThrowWandException (magick_wand); MagickResizeImage (magick_wand, size_x, size_y, LanczosFilter, 1.0); MagickSetImageCompressionQuality (magick_wand, quality); - + /* Write the image and destroy it. */ status = MagickWriteImage (magick_wand, dst); if (status == MagickFalse) @@ -323,10 +323,10 @@ resize_image (const char *src, const char *dst, /* - * get_image_sizes: retrieve image dimensions - */ -void -get_image_sizes (const char *img, + * get_image_sizes: retrieve image dimensions + */ +void +get_image_sizes (const char *img, unsigned long *width, unsigned long *height) { #define xThrowWandException(wand) \ @@ -339,49 +339,49 @@ get_image_sizes (const char *img, description = (char*) MagickRelinquishMemory(description); \ return; \ } - + MagickBooleanType status; MagickWand *magick_wand; *width = -1; - *height = -1; + *height = -1; /* Read an image. */ MagickWandGenesis(); - magick_wand = NewMagickWand(); + magick_wand = NewMagickWand(); status = MagickPingImage (magick_wand, img); - if (status == MagickFalse) + if (status == MagickFalse) xThrowWandException (magick_wand); *width = MagickGetImageWidth (magick_wand); *height = MagickGetImageHeight (magick_wand); - + magick_wand = DestroyMagickWand (magick_wand); MagickWandTerminus(); } /* - * calculate_sizes: calculate maximal image sizes within specified limits keeping aspect ratio - */ -void -calculate_sizes (const unsigned long max_width, const unsigned long max_height, + * calculate_sizes: calculate maximal image sizes within specified limits keeping aspect ratio + */ +void +calculate_sizes (const unsigned long max_width, const unsigned long max_height, unsigned long *width, unsigned long *height) { - if ((max_width > *width) && (max_height > *height)) + if ((max_width > *width) && (max_height > *height)) return; - + double max_ratio = (double) max_width / (double) max_height; double real_ratio = (double) *width / (double) *height; - + if ((*width > *height) && (max_ratio <= real_ratio)) { - *height = max_width / real_ratio; + *height = max_width / real_ratio; *width = max_width; } else - { + { *width = max_height * real_ratio; - *height = max_height; + *height = max_height; } -} +} diff --git a/jpeg-utils.h b/jpeg-utils.h index 4c47d3c..e5e39de 100644 --- a/jpeg-utils.h +++ b/jpeg-utils.h @@ -1,16 +1,16 @@ /* Cataract - Static web photo gallery generator * Copyright (C) 2008 Tomas Bzatek - * + * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -23,7 +23,7 @@ #include -/* TODO: we want to have numerical values here at some point in the future */ +/* TODO: we want to have numerical values here at some point in the future */ typedef struct { char *datetime; char *camera_model; @@ -33,55 +33,55 @@ typedef struct { char *aperture; char *exposure; char *flash; - + char *exif_software; char *exif_imgdesc; char *exif_artist; char *exif_copyright; char *exif_usercomment; - + char *iptc_objectname; char *iptc_copyright; char *iptc_credit; char *iptc_caption; char *iptc_author; - + char *jpeg_comment; } TExifData; /* - * get_exif: retrieve EXIF info from a JPEG image - */ + * get_exif: retrieve EXIF info from a JPEG image + */ int get_exif (const char *filename, TExifData **exif_data); /* - * free_exif_struct: free allocated structure - */ + * free_exif_struct: free allocated structure + */ void free_exif_data (TExifData *data); /* - * resize_image: resize image pointed by src and save result to dst - */ -gboolean resize_image (const char *src, const char *dst, - int size_x, int size_y, + * resize_image: resize image pointed by src and save result to dst + */ +gboolean resize_image (const char *src, const char *dst, + int size_x, int size_y, int quality); /* - * get_image_sizes: retrieve image dimensions - */ -void get_image_sizes (const char *img, + * get_image_sizes: retrieve image dimensions + */ +void get_image_sizes (const char *img, unsigned long *width, unsigned long *height); /* - * calculate_sizes: calculate maximal image sizes within specified limits keeping aspect ratio - */ -void calculate_sizes (const unsigned long max_width, const unsigned long max_height, + * calculate_sizes: calculate maximal image sizes within specified limits keeping aspect ratio + */ +void calculate_sizes (const unsigned long max_width, const unsigned long max_height, unsigned long *width, unsigned long *height); #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/sample/src/CIAF_1/img_6802e.jpg b/sample/src/CIAF_1/img_6802e.jpg new file mode 120000 index 0000000..d6b7d1d --- /dev/null +++ b/sample/src/CIAF_1/img_6802e.jpg @@ -0,0 +1 @@ +img_6802.jpg \ No newline at end of file diff --git a/sample/src/CIAF_1/img_6802f.jpg b/sample/src/CIAF_1/img_6802f.jpg new file mode 120000 index 0000000..d6b7d1d --- /dev/null +++ b/sample/src/CIAF_1/img_6802f.jpg @@ -0,0 +1 @@ +img_6802.jpg \ No newline at end of file diff --git a/sample/src/CIAF_1/index.xml b/sample/src/CIAF_1/index.xml index 788fc95..fe98cc2 100644 --- a/sample/src/CIAF_1/index.xml +++ b/sample/src/CIAF_1/index.xml @@ -6,10 +6,14 @@ mezinárodní letiště Brno - Tuřany
http://www.airshow.cz/18-CZ-CIAF-07-Home.html
+

+ This album sets border style "border_none" for preview images. ]]>
+ + @@ -54,5 +58,15 @@ links etc...]]> + + White frame + This particular image overrides both global and album border styles. + + + + Black frame + This particular image overrides both global and album border styles. + + diff --git a/sample/src/CIAF_1/preview/img_6802d.jpg b/sample/src/CIAF_1/preview/img_6802d.jpg new file mode 120000 index 0000000..d6b7d1d --- /dev/null +++ b/sample/src/CIAF_1/preview/img_6802d.jpg @@ -0,0 +1 @@ +img_6802.jpg \ No newline at end of file diff --git a/sample/src/CIAF_1/preview/img_6802e.jpg b/sample/src/CIAF_1/preview/img_6802e.jpg new file mode 120000 index 0000000..d6b7d1d --- /dev/null +++ b/sample/src/CIAF_1/preview/img_6802e.jpg @@ -0,0 +1 @@ +img_6802.jpg \ No newline at end of file diff --git a/sample/src/CIAF_1/preview/img_6802f.jpg b/sample/src/CIAF_1/preview/img_6802f.jpg new file mode 120000 index 0000000..d6b7d1d --- /dev/null +++ b/sample/src/CIAF_1/preview/img_6802f.jpg @@ -0,0 +1 @@ +img_6802.jpg \ No newline at end of file diff --git a/sample/src/setup.xml b/sample/src/setup.xml index ae92918..8f4b632 100644 --- a/sample/src/setup.xml +++ b/sample/src/setup.xml @@ -20,10 +20,12 @@ + quality="80" /> + +