This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project gfxprim.git.
The branch, master has been updated via 2671d7bde14699b65a50897b4c55d16bebe5ff4e (commit) via dd486975a6c4d41191bed65d3d5d1488747d9817 (commit) from 29623bb8c09cbd6659a28bbe84f2a6cdf154c434 (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- http://repo.or.cz/w/gfxprim.git/commit/2671d7bde14699b65a50897b4c55d16bebe5f...
commit 2671d7bde14699b65a50897b4c55d16bebe5ff4e Author: Cyril Hrubis metan@ucw.cz Date: Wed Apr 24 00:20:04 2013 +0200
spiv: image_list: Add more functionality.
* Add lazy counters, so that we can tell total number of images in the arg list, including directories
* Add functions to move to the start/end of directory and arg list
* Add functions to return current position in list.
* Make use of the functionality in spiv
TODO: Fix help and write docs.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/demos/spiv/image_list.c b/demos/spiv/image_list.c index d015a21..042ef4b 100644 --- a/demos/spiv/image_list.c +++ b/demos/spiv/image_list.c @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2013 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
@@ -38,6 +38,8 @@ struct image_list { const char **args; unsigned int cur_arg; unsigned int max_arg; + /* counters for files in corresponding arg */ + int *arg_file_counts;
/* path to the currently loaded image */ char path[1024]; @@ -85,8 +87,10 @@ static void try_load_dir(struct image_list *self) return; }
- if (!(sb.st_mode & S_IFDIR)) + if (!(sb.st_mode & S_IFDIR)) { + self->arg_file_counts[self->cur_arg] = 1; return; + }
GP_DEBUG(1, "Loading directory '%s' content.", path);
@@ -96,6 +100,11 @@ static void try_load_dir(struct image_list *self) GP_WARN("Failed to scandir '%s': %s", path, strerror(errno)); return; } + + if (self->arg_file_counts[self->cur_arg] != ret) { + GP_DEBUG(1, "Updating arg counter to %i", ret); + self->arg_file_counts[self->cur_arg] = ret; + }
if (ret == 0) { GP_DEBUG(1, "There are no files in '%s'", path); @@ -167,17 +176,81 @@ static void prev_img(struct image_list *self) self->path_loaded = 0; }
+/* + * Sets current image, if we are in directory. + */ +static void set_dir_cur_img(struct image_list *self, int img) +{ + if (!self->in_dir) { + GP_BUG("Not in directory at %s", + self->args[self->cur_arg]); + return; + } + + if (img < 0 || img >= self->max_file) { + GP_BUG("Invalid image index %i", img); + return; + } + + /* allready there */ + if (self->cur_file == img) + return; + + self->cur_file = img; + self->path_loaded = 0; +} + +/* + * Returns current argument from arg list we are in. + * + * Either it's image file or directory. + */ +static const char *cur_arg(struct image_list *self) +{ + return self->args[self->cur_arg]; +} + +/* + * Sets current argument from arg list. + */ +static void set_cur_arg(struct image_list *self, int arg) +{ + if (arg < 0 || arg >= (int)self->max_arg) { + GP_BUG("Invalid argument index %i", arg); + return; + } + + if (self->in_dir) { + if ((int)self->cur_arg != arg) { + exit_dir(self); + self->cur_arg = arg; + self->path_loaded = 0; + try_load_dir(self); + } else { + set_dir_cur_img(self, 0); + } + return; + } + + if ((int)self->cur_arg == arg) + return; + + self->cur_arg = arg; + self->path_loaded = 0; + + try_load_dir(self); +} + static void load_path(struct image_list *self) { if (self->in_dir) { //TODO: eliminate double / snprintf(self->path, sizeof(self->path), "%s/%s", - self->args[self->cur_arg], - self->dir_files[self->cur_file]->d_name); + cur_arg(self), + self->dir_files[self->cur_file]->d_name);
} else { - snprintf(self->path, sizeof(self->path), "%s", - self->args[self->cur_arg]); + snprintf(self->path, sizeof(self->path), "%s", cur_arg(self)); }
self->path_loaded = 1; @@ -198,16 +271,128 @@ const char *image_list_move(struct image_list *self, int direction) return image_list_img_path(self); }
+const char *image_list_dir_move(struct image_list *self, int direction) +{ + if (!self->in_dir) { + GP_DEBUG(2, "Not in directory"); + return image_list_move(self, direction); + } + + if (direction > 0) { + if (self->cur_file == self->max_file - 1) { + GP_DEBUG(2, "Moving after dir '%s'", cur_arg(self)); + next_img(self); + } else { + GP_DEBUG(2, "Moving to last image in dir '%s'", + cur_arg(self)); + set_dir_cur_img(self, self->max_file - 1); + } + } else { + if (self->cur_file == 0) { + GP_DEBUG(2, "Moving before dir '%s'", cur_arg(self)); + prev_img(self); + } else { + GP_DEBUG(2, "Moving to first image in dir '%s'", + cur_arg(self)); + set_dir_cur_img(self, 0); + } + } + + return image_list_img_path(self); +} + +const char *image_list_first(struct image_list *self) +{ + GP_DEBUG(2, "Moving to the first image in the list"); + + set_cur_arg(self, 0); + + if (self->in_dir) + set_dir_cur_img(self, 0); + + return image_list_img_path(self); +} + +const char *image_list_last(struct image_list *self) +{ + GP_DEBUG(2, "Moving to the last image in the list"); + + set_cur_arg(self, self->max_arg - 1); + + if (self->in_dir) + set_dir_cur_img(self, self->max_file - 1); + + return image_list_img_path(self); +} + +static unsigned int count_img_to(struct image_list *self, unsigned int arg_to) +{ + unsigned int cur_arg = self->cur_arg; + unsigned int cur_file = self->cur_file; + unsigned int count = 0, i; + + for (i = 0; i < arg_to; i++) { + /* cache number of images in arg */ + if (self->arg_file_counts[i] == -1) + set_cur_arg(self, i); + + /* + * if the counter is still at -1 + * directory couldn't be loaded + */ + if (self->arg_file_counts[i] != -1) + count += self->arg_file_counts[i]; + } + + /* restore the original position */ + set_cur_arg(self, cur_arg); + + if (self->in_dir) + set_dir_cur_img(self, cur_file); + + return count; +} + +unsigned int image_list_count(struct image_list *self) +{ + return count_img_to(self, self->max_arg); +} + +unsigned int image_list_pos(struct image_list *self) +{ + return count_img_to(self, self->cur_arg) + self->cur_file; +} + +unsigned int image_list_dir_count(struct image_list *self) +{ + if (!self->in_dir) + return 1; + + return self->max_file; +} + +unsigned int image_list_dir_pos(struct image_list *self) +{ + if (!self->in_dir) + return 1; + + return self->cur_file; +} + struct image_list *image_list_create(const char *args[]) { struct image_list *self; + size_t file_count_size; + unsigned int i;
GP_DEBUG(1, "Creating image list"); self = malloc(sizeof(struct image_list));
- if (self == NULL) + if (self == NULL) { + GP_WARN("Malloc failed"); return NULL; + }
self->args = args; self->cur_arg = 0; @@ -220,6 +405,18 @@ struct image_list *image_list_create(const char *args[]) self->max_arg = 0; while (args[++self->max_arg] != NULL);
+ file_count_size = self->max_arg * sizeof(int); + self->arg_file_counts = malloc(file_count_size); + + if (self->arg_file_counts == NULL) { + GP_WARN("Malloc failed"); + free(self); + return NULL; + } + + for (i = 0; i < self->max_arg; i++) + self->arg_file_counts[i] = -1; + try_load_dir(self);
return self; diff --git a/demos/spiv/image_list.h b/demos/spiv/image_list.h index e7b299a..17f21d0 100644 --- a/demos/spiv/image_list.h +++ b/demos/spiv/image_list.h @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2013 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
@@ -47,4 +47,43 @@ const char *image_list_img_path(struct image_list *self); */ const char *image_list_move(struct image_list *self, int direction);
+/* + * If we are in directory: + * if direction > 0: move to its end and if allready there, to the next arg + * if direction < 0: move to its begining and if allready there, to the previous arg + * + * If we aren't in directory move by one in corresponding direction. + */ +const char *image_list_dir_move(struct image_list *self, int direction); + +/* + * Move to the first image in the list. + */ +const char *image_list_first(struct image_list *self); + +/* + * Move to the last image in the list. + */ +const char *image_list_last(struct image_list *self); + +/* + * Counts images int the list. + */ +unsigned int image_list_count(struct image_list *self); + +/* + * Returns current position in list, i.e. number between 0 and count - 1. + */ +unsigned int image_list_pos(struct image_list *self); + +/* + * Returns numbe of images in current dir or 1 if current arg is file. + */ +unsigned int image_list_dir_count(struct image_list *self); + +/* + * Returns current position in current dir or 1 if current arg is file. + */ +unsigned int image_list_dir_pos(struct image_list *self); + #endif /* __IMAGE_LIST_H__ */ diff --git a/demos/spiv/spiv.c b/demos/spiv/spiv.c index e08de82..8b94b99 100644 --- a/demos/spiv/spiv.c +++ b/demos/spiv/spiv.c @@ -100,6 +100,9 @@ struct loader_params { /* caches for loaded images */ struct image_cache *img_resized_cache; struct image_cache *img_orig_cache; + + /* image list structure */ + struct image_list *img_list; };
static int image_loader_callback(GP_ProgressCallback *self) @@ -361,6 +364,26 @@ static void update_display(struct loader_params *params, GP_Context *img) params->use_low_pass && params->rat < 1 ? "Gaussian LP + " : "", GP_InterpolationTypeName(params->resampling_method));
+ unsigned int count = image_list_count(params->img_list); + unsigned int pos = image_list_pos(params->img_list) + 1; + + GP_Print(context, NULL, 11, 19 + 4 * th, GP_ALIGN_RIGHT|GP_VALIGN_BOTTOM, + black_pixel, white_pixel, "%u of %u", pos, count); + + GP_Print(context, NULL, 10, 18 + 4 * th, GP_ALIGN_RIGHT|GP_VALIGN_BOTTOM, + white_pixel, black_pixel, "%u of %u", pos, count); + + unsigned int dir_count = image_list_dir_count(params->img_list); + unsigned int dir_pos = image_list_dir_pos(params->img_list) + 1; + + if (dir_count > 1 && dir_count != count) { + GP_Print(context, NULL, 11, 21 + 5 * th, GP_ALIGN_RIGHT|GP_VALIGN_BOTTOM, + black_pixel, white_pixel, "%u of %u in directory", dir_pos, dir_count); + + GP_Print(context, NULL, 10, 20 + 5 * th, GP_ALIGN_RIGHT|GP_VALIGN_BOTTOM, + white_pixel, black_pixel, "%u of %u in directory", dir_pos, dir_count); + } + GP_BackendFlip(backend); }
@@ -859,6 +882,7 @@ int main(int argc, char *argv[]) GP_BackendFlip(backend);
struct image_list *list = image_list_create((const char**)argv + optind); + params.img_list = list;
params.show_progress_once = 1; show_image(¶ms, image_list_img_path(list)); @@ -983,11 +1007,19 @@ int main(int argc, char *argv[]) break; case GP_KEY_PAGE_UP: params.show_progress_once = 1; - show_image(¶ms, image_list_move(list, 10)); + show_image(¶ms, image_list_dir_move(list, -1)); break; case GP_KEY_PAGE_DOWN: params.show_progress_once = 1; - show_image(¶ms, image_list_move(list, -10)); + show_image(¶ms, image_list_dir_move(list, 1)); + break; + case GP_KEY_HOME: + params.show_progress_once = 1; + show_image(¶ms, image_list_first(list)); + break; + case GP_KEY_END: + params.show_progress_once = 1; + show_image(¶ms, image_list_last(list)); break; case GP_KEY_RIGHT: if (shift_flag) @@ -1017,12 +1049,18 @@ int main(int argc, char *argv[]) next: case GP_KEY_SPACE: params.show_progress_once = 1; - show_image(¶ms, image_list_move(list, 1)); + if (shift_flag) + show_image(¶ms, image_list_move(list, 10)); + else + show_image(¶ms, image_list_move(list, 1)); break; prev: case GP_KEY_BACKSPACE: params.show_progress_once = 1; - show_image(¶ms, image_list_move(list, -1)); + if (shift_flag) + show_image(¶ms, image_list_move(list, -10)); + else + show_image(¶ms, image_list_move(list, -1)); break; case GP_KEY_1: resize_backend(¶ms, 1, shift_flag);
http://repo.or.cz/w/gfxprim.git/commit/dd486975a6c4d41191bed65d3d5d1488747d9...
commit dd486975a6c4d41191bed65d3d5d1488747d9817 Author: Cyril Hrubis metan@ucw.cz Date: Tue Apr 23 21:30:51 2013 +0200
tests: loaders: PNG: Return SKIPPED on ENOSYS.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/tests/loaders/PNG.c b/tests/loaders/PNG.c index fce0193..d4901ca 100644 --- a/tests/loaders/PNG.c +++ b/tests/loaders/PNG.c @@ -83,7 +83,7 @@ static int test_save_PNG(GP_PixelType pixel_type) case ENOSYS: tst_msg("Not Implemented"); GP_ContextFree(ctx); - return TST_SUCCESS; + return TST_SKIPPED; default: tst_msg("Failed and errno is not ENOSYS (%i)", errno); GP_ContextFree(ctx);
-----------------------------------------------------------------------
Summary of changes: demos/spiv/image_list.c | 211 +++++++++++++++++++++++++++++++++++++++++++++-- demos/spiv/image_list.h | 41 +++++++++- demos/spiv/spiv.c | 46 +++++++++- tests/loaders/PNG.c | 2 +- 4 files changed, 287 insertions(+), 13 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos@gmail.com if you want to unsubscribe, or site admin admin@repo.or.cz if you receive no reply.