From 31c67831736e4bde3ef0d4dedb7c11dfc6649fdf Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 12 Sep 2012 19:45:58 +0200 Subject: Proper workaround for broken gib_imlib_save_image_with_error_return --- src/imlib.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/imlib.c') diff --git a/src/imlib.c b/src/imlib.c index af7acdd..5e423f3 100644 --- a/src/imlib.c +++ b/src/imlib.c @@ -129,6 +129,32 @@ int feh_load_image_char(Imlib_Image * im, char *filename) return(i); } +/* + * XXX gib_imlib_save_image_with_error_return breaks with *.END and + * similar because it tries to set the image format, which only works + * with .end . + * So we leave that part out. + */ +void ungib_imlib_save_image_with_error_return(Imlib_Image im, char *file, + Imlib_Load_Error * error_return) +{ + char *tmp; + imlib_context_set_image(im); + tmp = strrchr(file, '.'); + if (tmp) { + char *p, *pp; + p = gib_estrdup(tmp + 1); + pp = p; + while(*pp) { + *pp = tolower(*pp); + pp++; + } + imlib_image_set_format(p); + gib_efree(p); + } + imlib_save_image_with_error_return(file, error_return); +} + int feh_load_image(Imlib_Image * im, feh_file * file) { Imlib_Load_Error err; -- cgit v1.2.3 From ed5b2d5aaf3024d23b131e008d92c7844858373c Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 12 Sep 2012 20:02:52 +0200 Subject: Fix lossless rotate error message for non-JPEG images --- ChangeLog | 1 + src/imlib.c | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'src/imlib.c') diff --git a/ChangeLog b/ChangeLog index ee6bb53..53b6457 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,7 @@ git HEAD when running feh on the current working directory, '/path/to/./image.png' was used for thumbnail name generation. Now it is always '/path/to/image.png' + * Show error message if lossless rotate / flip failed on non-JPEG image Tue, 28 Aug 2012 11:46:19 +0200 Daniel Friesel diff --git a/src/imlib.c b/src/imlib.c index 5e423f3..d89a5a4 100644 --- a/src/imlib.c +++ b/src/imlib.c @@ -1000,6 +1000,7 @@ void feh_edit_inplace(winwidget w, int op) { int ret; Imlib_Image old; + Imlib_Load_Error err; if (!w->file || !w->file->data || !FEH_FILE(w->file->data)->filename) return; @@ -1019,8 +1020,11 @@ void feh_edit_inplace(winwidget w, int op) imlib_image_flip_horizontal(); } else gib_imlib_image_orientate(old, op); - gib_imlib_save_image(old, FEH_FILE(w->file->data)->filename); + ungib_imlib_save_image_with_error_return(old, + FEH_FILE(w->file->data)->filename, &err); gib_imlib_free_image(old); + if (err) + im_weprintf(w, "Failed to save image after operation"); feh_reload_image(w, 1, 1); } else { im_weprintf(w, "failed to load image from disk to edit it in place"); -- cgit v1.2.3 From 290b5964ef857ea52d85edf846edd82392d9a716 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 12 Sep 2012 20:46:15 +0200 Subject: print imlib2 error strings when save failed --- src/feh.h | 1 + src/imlib.c | 102 ++++++++++++++++++++++++++++++-------------------------- src/index.c | 2 +- src/slideshow.c | 2 +- src/thumbnail.c | 2 +- 5 files changed, 58 insertions(+), 51 deletions(-) (limited to 'src/imlib.c') diff --git a/src/feh.h b/src/feh.h index 2202617..cd730e9 100644 --- a/src/feh.h +++ b/src/feh.h @@ -157,6 +157,7 @@ void feh_display_status(char stat); void real_loadables_mode(int loadable); void feh_reload_image(winwidget w, int resize, int force_new); void feh_filelist_image_remove(winwidget winwid, char do_delete); +void feh_imlib_print_load_error(char *file, winwidget w, Imlib_Load_Error err); void slideshow_save_image(winwidget win); void ungib_imlib_save_image_with_error_return(Imlib_Image im, char *file, Imlib_Load_Error * error_return); diff --git a/src/imlib.c b/src/imlib.c index d89a5a4..3ffc538 100644 --- a/src/imlib.c +++ b/src/imlib.c @@ -155,6 +155,57 @@ void ungib_imlib_save_image_with_error_return(Imlib_Image im, char *file, imlib_save_image_with_error_return(file, error_return); } +void feh_imlib_print_load_error(char *file, winwidget w, Imlib_Load_Error err) +{ + if (err == IMLIB_LOAD_ERROR_OUT_OF_FILE_DESCRIPTORS) + eprintf("%s - Out of file descriptors while loading", file); + else if (!opt.quiet || w) { + switch (err) { + case IMLIB_LOAD_ERROR_FILE_DOES_NOT_EXIST: + im_weprintf(w, "%s - File does not exist", file); + break; + case IMLIB_LOAD_ERROR_FILE_IS_DIRECTORY: + im_weprintf(w, "%s - Directory specified for image filename", file); + break; + case IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_READ: + im_weprintf(w, "%s - No read access", file); + break; + case IMLIB_LOAD_ERROR_UNKNOWN: + case IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT: + im_weprintf(w, "%s - No Imlib2 loader for that file format", file); + break; + case IMLIB_LOAD_ERROR_PATH_TOO_LONG: + im_weprintf(w, "%s - Path specified is too long", file); + break; + case IMLIB_LOAD_ERROR_PATH_COMPONENT_NON_EXISTANT: + im_weprintf(w, "%s - Path component does not exist", file); + break; + case IMLIB_LOAD_ERROR_PATH_COMPONENT_NOT_DIRECTORY: + im_weprintf(w, "%s - Path component is not a directory", file); + break; + case IMLIB_LOAD_ERROR_PATH_POINTS_OUTSIDE_ADDRESS_SPACE: + im_weprintf(w, "%s - Path points outside address space", file); + break; + case IMLIB_LOAD_ERROR_TOO_MANY_SYMBOLIC_LINKS: + im_weprintf(w, "%s - Too many levels of symbolic links", file); + break; + case IMLIB_LOAD_ERROR_OUT_OF_MEMORY: + im_weprintf(w, "While loading %s - Out of memory", file); + break; + case IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_WRITE: + im_weprintf(w, "%s - Cannot write to directory", file); + break; + case IMLIB_LOAD_ERROR_OUT_OF_DISK_SPACE: + im_weprintf(w, "%s - Cannot write - out of disk space", file); + break; + default: + im_weprintf(w, "While loading %s - Unknown error (%d)", + file, err); + break; + } + } +} + int feh_load_image(Imlib_Image * im, feh_file * file) { Imlib_Load_Error err; @@ -208,53 +259,7 @@ int feh_load_image(Imlib_Image * im, feh_file * file) fputs("\n", stdout); reset_output = 1; } - if (err == IMLIB_LOAD_ERROR_OUT_OF_FILE_DESCRIPTORS) - eprintf("%s - Out of file descriptors while loading", file->filename); - else if (!opt.quiet) { - switch (err) { - case IMLIB_LOAD_ERROR_FILE_DOES_NOT_EXIST: - weprintf("%s - File does not exist", file->filename); - break; - case IMLIB_LOAD_ERROR_FILE_IS_DIRECTORY: - weprintf("%s - Directory specified for image filename", file->filename); - break; - case IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_READ: - weprintf("%s - No read access", file->filename); - break; - case IMLIB_LOAD_ERROR_UNKNOWN: - case IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT: - weprintf("%s - No Imlib2 loader for that file format", file->filename); - break; - case IMLIB_LOAD_ERROR_PATH_TOO_LONG: - weprintf("%s - Path specified is too long", file->filename); - break; - case IMLIB_LOAD_ERROR_PATH_COMPONENT_NON_EXISTANT: - weprintf("%s - Path component does not exist", file->filename); - break; - case IMLIB_LOAD_ERROR_PATH_COMPONENT_NOT_DIRECTORY: - weprintf("%s - Path component is not a directory", file->filename); - break; - case IMLIB_LOAD_ERROR_PATH_POINTS_OUTSIDE_ADDRESS_SPACE: - weprintf("%s - Path points outside address space", file->filename); - break; - case IMLIB_LOAD_ERROR_TOO_MANY_SYMBOLIC_LINKS: - weprintf("%s - Too many levels of symbolic links", file->filename); - break; - case IMLIB_LOAD_ERROR_OUT_OF_MEMORY: - weprintf("While loading %s - Out of memory", file->filename); - break; - case IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_WRITE: - weprintf("%s - Cannot write to directory", file->filename); - break; - case IMLIB_LOAD_ERROR_OUT_OF_DISK_SPACE: - weprintf("%s - Cannot write - out of disk space", file->filename); - break; - default: - weprintf("While loading %s - Unknown error (%d)", - file->filename, err); - break; - } - } + feh_imlib_print_load_error(file->filename, NULL, err) D(("Load *failed*\n")); return(0); } @@ -1024,7 +1029,8 @@ void feh_edit_inplace(winwidget w, int op) FEH_FILE(w->file->data)->filename, &err); gib_imlib_free_image(old); if (err) - im_weprintf(w, "Failed to save image after operation"); + feh_imlib_print_load_error(FEH_FILE(w->file->data)->filename, + w, err); feh_reload_image(w, 1, 1); } else { im_weprintf(w, "failed to load image from disk to edit it in place"); diff --git a/src/index.c b/src/index.c index e5a93a4..5d4ed39 100644 --- a/src/index.c +++ b/src/index.c @@ -329,7 +329,7 @@ void init_index_mode(void) ungib_imlib_save_image_with_error_return(im_main, output_buf, &err); if (err) { - weprintf("Cannot save image to %s", output_buf); + feh_imlib_print_load_error(output_buf, im_main, err); } else if (opt.verbose) { int tw, th; diff --git a/src/slideshow.c b/src/slideshow.c index 2e9c417..60bd99c 100644 --- a/src/slideshow.c +++ b/src/slideshow.c @@ -597,7 +597,7 @@ void slideshow_save_image(winwidget win) ungib_imlib_save_image_with_error_return(win->im, tmpname, &err); if (err) - im_weprintf(win, "Can't save image %s:", tmpname); + feh_imlib_print_load_error(tmpname, win, err); free(tmpname); return; diff --git a/src/thumbnail.c b/src/thumbnail.c index c622b07..fbe2ce0 100644 --- a/src/thumbnail.c +++ b/src/thumbnail.c @@ -384,7 +384,7 @@ void init_thumbnail_mode(void) strncpy(output_buf, opt.output_file, 1024); ungib_imlib_save_image_with_error_return(td.im_main, output_buf, &err); if (err) { - weprintf("Cannot save image to %s", output_buf); + feh_imlib_print_load_error(output_buf, td.im_main, err); } else if (opt.verbose) { int tw, th; -- cgit v1.2.3 From 3a1b07272aeff6397f74014cdeae2c129d608a94 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 13 Sep 2012 12:05:55 +0200 Subject: Show error message if normal load failed (broken by 2.4) + update tests --- ChangeLog | 4 +++- src/imlib.c | 8 +------- test/feh.t | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) (limited to 'src/imlib.c') diff --git a/ChangeLog b/ChangeLog index 4f12946..af57063 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,4 @@ -git HEAD +Thu, 13 Sep 2012 12:00:06 +0200 Daniel Friesel * Fix freedesktop.org Thumbnail Managing Standard implementation: when running feh on the current working directory, '/path/to/./image.png' @@ -6,6 +6,8 @@ git HEAD '/path/to/image.png' * Show error message if lossless rotate / flip failed on non-JPEG image * Show error message if -O / -o failed to save image + * Show error message if load failed and magick is disabled (was broken + by feh 2.4) Tue, 28 Aug 2012 11:46:19 +0200 Daniel Friesel diff --git a/src/imlib.c b/src/imlib.c index 3ffc538..b3abc8a 100644 --- a/src/imlib.c +++ b/src/imlib.c @@ -234,10 +234,7 @@ int feh_load_image(Imlib_Image * im, feh_file * file) tmpname = feh_magick_load_image(file->filename); } - if (image_source != SRC_IMLIB) { - if (tmpname == NULL) - return 0; - + if ((image_source != SRC_IMLIB) && tmpname) { *im = imlib_load_image_with_error_return(tmpname, &err); if (im) { real_filename = file->filename; @@ -336,9 +333,6 @@ static char *feh_magick_load_image(char *filename) if (WIFSIGNALED(status)) weprintf("%s - Conversion took too long, skipping", filename); - else - weprintf("%s - No loader for that file format", - filename); } /* diff --git a/test/feh.t b/test/feh.t index 8746362..1d5576b 100644 --- a/test/feh.t +++ b/test/feh.t @@ -33,7 +33,7 @@ if (length($feh_name) == 0) { } my $re_warning = - qr{${feh_name} WARNING: test/fail/... \- No loader for that file format\n}; + qr{${feh_name} WARNING: test/fail/... \- No Imlib2 loader for that file format\n}; my $re_loadable = qr{test/ok/...}; my $re_unloadable = qr{test/fail/...}; my $re_list_action = qr{test/ok/... 16x16}; -- cgit v1.2.3 From 7979f76dcd5d5e2340956f6ec3b9009e64648fc1 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 17 Sep 2012 15:20:47 +0200 Subject: Fix EXIF orientation tag after lossless rotate --- ChangeLog | 7 +++++++ man/feh.pre | 14 +++++++++++++- src/imlib.c | 32 ++++++++++++++++++++++++++++++-- 3 files changed, 50 insertions(+), 3 deletions(-) (limited to 'src/imlib.c') diff --git a/ChangeLog b/ChangeLog index af57063..6cefc73 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +git HEAD + + * Set EXIF orientation tag to 1 ("0,0 is top left" aka normal) after + running jpegtran. Previously, when doing a lossless rotate, the image + was rotated but the corresponding EXIF tag not updated, resulting in + wrong image display in programs aware of this EXIF tag. + Thu, 13 Sep 2012 12:00:06 +0200 Daniel Friesel * Fix freedesktop.org Thumbnail Managing Standard implementation: diff --git a/man/feh.pre b/man/feh.pre index e047286..5199151 100644 --- a/man/feh.pre +++ b/man/feh.pre @@ -1106,6 +1106,16 @@ away. See .Xr jpegtran 1 for more about lossless JPEG rotation. . +.Em Note: +jpegtran does not update EXIF orientation tags. However, +.Nm +assumes that you use the feature to normalize image orientation and want it to +be displayed this way everywhere. After every rotation, it will unconditionally +set the EXIF orientation to 1 +.Pq Qq 0,0 is top left . +Should you need to reverse this, see +.Xr jpegexiforient 1 . +. .It _ Bq flip . In place editing - vertical flip @@ -1487,7 +1497,9 @@ but without the flickering. .Nm requires the .Cm jpegtran -binary +and +.Cm jpegexiforient +binaries .Pq usually distributed in Qo libjpeg-progs Qc or similar for lossless rotation. . diff --git a/src/imlib.c b/src/imlib.c index b3abc8a..f247bf7 100644 --- a/src/imlib.c +++ b/src/imlib.c @@ -1137,6 +1137,7 @@ void feh_edit_inplace_lossless(winwidget w, int op) int len = strlen(filename) + 1; char *file_str = emalloc(len); int pid, status; + int devnull = -1; char op_name[] = "rotate"; /* message */ char op_op[] = "-rotate"; /* jpegtran option */ char op_value[] = "horizontal"; /* jpegtran option's value */ @@ -1156,14 +1157,16 @@ void feh_edit_inplace_lossless(winwidget w, int op) if ((pid = fork()) < 0) { im_weprintf(w, "lossless %s: fork failed:", op_name); exit(1); - } else if (pid == 0) { + } + else if (pid == 0) { execlp("jpegtran", "jpegtran", "-copy", "all", op_op, op_value, "-outfile", file_str, file_str, NULL); im_weprintf(w, "lossless %s: Is 'jpegtran' installed? Failed to exec:", op_name); exit(1); - } else { + } + else { waitpid(pid, &status, 0); if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { @@ -1176,6 +1179,31 @@ void feh_edit_inplace_lossless(winwidget w, int op) return; } } + if ((pid = fork()) < 0) { + im_weprintf(w, "lossless %s: cannot fix rotation: fork:", op_name); + exit(1); + } + else if (pid == 0) { + + /* discard normal output */ + devnull = open("/dev/null", O_WRONLY); + dup2(devnull, 1); + + execlp("jpegexiforient", "jpegexiforient", "-1", file_str, NULL); + im_weprintf(w, "lossless %s: Failed to exec jpegexiforient:", op_name); + exit(1); + } + else { + waitpid(pid, &status, 0); + + if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { + im_weprintf(w, + "lossless %s: Got exitcode %d from jpegexiforient", + status >> 8); + free(file_str); + return; + } + } free(file_str); } -- cgit v1.2.3 From 4c8120cb44c99a6488077688647ef192d455b2e7 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Fri, 21 Sep 2012 14:57:32 +0200 Subject: imlib.c: Fix debug builds (add missing semicolon) --- src/imlib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/imlib.c') diff --git a/src/imlib.c b/src/imlib.c index f247bf7..a2bd4ac 100644 --- a/src/imlib.c +++ b/src/imlib.c @@ -256,7 +256,7 @@ int feh_load_image(Imlib_Image * im, feh_file * file) fputs("\n", stdout); reset_output = 1; } - feh_imlib_print_load_error(file->filename, NULL, err) + feh_imlib_print_load_error(file->filename, NULL, err); D(("Load *failed*\n")); return(0); } -- cgit v1.2.3 From b928208c102a1b45ef82019c6e73b2577592381e Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 27 Sep 2012 17:15:50 +0200 Subject: Fix lossless rotation if jpegexiforient is unavailable (closes #100) --- ChangeLog | 5 +++++ src/imlib.c | 7 +++---- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'src/imlib.c') diff --git a/ChangeLog b/ChangeLog index b05d7c3..6cfe1aa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu, 27 Sep 2012 16:48:48 +0200 Daniel Friesel + + * Fix segfault when doing lossless mirror/rotate and jpegexiforient is + not present + Wed, 26 Sep 2012 17:06:50 +0200 Daniel Friesel * Set EXIF orientation tag to 1 ("0,0 is top left" aka normal) after diff --git a/src/imlib.c b/src/imlib.c index a2bd4ac..e9f92ad 100644 --- a/src/imlib.c +++ b/src/imlib.c @@ -1198,10 +1198,9 @@ void feh_edit_inplace_lossless(winwidget w, int op) if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { im_weprintf(w, - "lossless %s: Got exitcode %d from jpegexiforient", - status >> 8); - free(file_str); - return; + "lossless %s: Failed to update EXIF orientation tag:" + " jpegexiforient returned %d", + op_name, status >> 8); } } free(file_str); -- cgit v1.2.3