summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2011-08-09 14:08:12 +0200
committerDaniel Friesel <derf@finalrewind.org>2011-08-09 14:11:57 +0200
commit5a280fd5b65957720f9811d292086dd54c4015f8 (patch)
tree80e2293f99f7bf9a605ee76fed1b7ef2eb303b0d /src
parent30735df15977b8b497de70af72cccd4ee726342a (diff)
parentc78cee50a4c33e2286ad7ffe9f28e0fc4ef3bd89 (diff)
Merge patch by livibetter: Add flip and mirror in-place edit actions (closes #53)
Diffstat (limited to 'src')
-rw-r--r--src/feh.h7
-rw-r--r--src/imlib.c45
-rw-r--r--src/keyevents.c14
-rw-r--r--src/menu.c2
-rw-r--r--src/options.h2
5 files changed, 51 insertions, 19 deletions
diff --git a/src/feh.h b/src/feh.h
index 63aeef6..7b46a25 100644
--- a/src/feh.h
+++ b/src/feh.h
@@ -98,6 +98,9 @@ enum slide_change { SLIDE_NEXT, SLIDE_PREV, SLIDE_RAND, SLIDE_FIRST, SLIDE_LAST,
SLIDE_JUMP_BACK
};
+#define INPLACE_EDIT_FLIP -1
+#define INPLACE_EDIT_MIRROR -2
+
typedef void (*sighandler_t) (int);
int feh_main_iteration(int block);
@@ -142,8 +145,8 @@ 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 slideshow_save_image(winwidget win);
-void feh_edit_inplace_orient(winwidget w, int orientation);
-void feh_edit_inplace_lossless_rotate(winwidget w, int orientation);
+void feh_edit_inplace(winwidget w, int orientation);
+void feh_edit_inplace_lossless(winwidget w, int orientation);
gib_list *feh_wrap_string(char *text, int wrap_width, Imlib_Font fn, gib_style * style);
char *build_caption_filename(feh_file * file, short create_dir);
gib_list *feh_list_jump(gib_list * root, gib_list * l, int direction, int num);
diff --git a/src/imlib.c b/src/imlib.c
index 2b6f200..e27db57 100644
--- a/src/imlib.c
+++ b/src/imlib.c
@@ -786,7 +786,7 @@ void feh_display_status(char stat)
return;
}
-void feh_edit_inplace_orient(winwidget w, int orientation)
+void feh_edit_inplace(winwidget w, int op)
{
int ret;
Imlib_Image old;
@@ -794,14 +794,21 @@ void feh_edit_inplace_orient(winwidget w, int orientation)
return;
if (!strcmp(gib_imlib_image_format(w->im), "jpeg")) {
- feh_edit_inplace_lossless_rotate(w, orientation);
+ feh_edit_inplace_lossless(w, op);
feh_reload_image(w, 1, 1);
return;
}
ret = feh_load_image(&old, FEH_FILE(w->file->data));
if (ret) {
- gib_imlib_image_orientate(old, orientation);
+ if (op == INPLACE_EDIT_FLIP) {
+ imlib_context_set_image(old);
+ imlib_image_flip_vertical();
+ } else if (op == INPLACE_EDIT_MIRROR) {
+ imlib_context_set_image(old);
+ imlib_image_flip_horizontal();
+ } else
+ gib_imlib_image_orientate(old, op);
gib_imlib_save_image(old, FEH_FILE(w->file->data)->filename);
gib_imlib_free_image(old);
feh_reload_image(w, 1, 1);
@@ -910,37 +917,47 @@ gib_list *feh_wrap_string(char *text, int wrap_width, Imlib_Font fn, gib_style *
return lines;
}
-void feh_edit_inplace_lossless_rotate(winwidget w, int orientation)
+void feh_edit_inplace_lossless(winwidget w, int op)
{
char *filename = FEH_FILE(w->file->data)->filename;
- char rotate_str[4];
int len = strlen(filename) + 1;
char *file_str = emalloc(len);
- int rotatearg = 90 * orientation;
int pid, status;
+ char op_name[] = "rotate"; /* message */
+ char op_op[] = "-rotate"; /* jpegtran option */
+ char op_value[] = "horizontal"; /* jpegtran option's value */
+
+ if (op == INPLACE_EDIT_FLIP) {
+ sprintf(op_name, "flip");
+ sprintf(op_op, "-flip");
+ sprintf(op_value, "vertical");
+ } else if (op == INPLACE_EDIT_MIRROR) {
+ sprintf(op_name, "mirror");
+ sprintf(op_op, "-flip");
+ } else
+ snprintf(op_value, 4, "%d", 90 * op);
- snprintf(rotate_str, 4, "%d", rotatearg);
snprintf(file_str, len, "%s", filename);
if ((pid = fork()) < 0) {
- im_weprintf(w, "lossless rotate: fork failed:");
+ im_weprintf(w, "lossless %s: fork failed:", op_name);
return;
} else if (pid == 0) {
- execlp("jpegtran", "jpegtran", "-copy", "all", "-rotate",
- rotate_str, "-outfile", file_str, file_str, NULL);
+ execlp("jpegtran", "jpegtran", "-copy", "all", op_op, op_value,
+ "-outfile", file_str, file_str, NULL);
- im_weprintf(w, "lossless rotate: Is 'jpegtran' installed? Failed to exec:");
+ im_weprintf(w, "lossless %s: Is 'jpegtran' installed? Failed to exec:", op_name);
return;
} else {
waitpid(pid, &status, 0);
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
im_weprintf(w,
- "lossless rotate: Got exitcode %d from jpegtran."
+ "lossless %s: Got exitcode %d from jpegtran."
" Commandline was: "
- "jpegtran -copy all -rotate %s -outfile %s %s",
- status >> 8, rotate_str, file_str, file_str);
+ "jpegtran -copy all %s %s -outfile %s %s",
+ op_name, status >> 8, op_op, op_value, file_str, file_str);
return;
}
}
diff --git a/src/keyevents.c b/src/keyevents.c
index 526e0ac..7c14e14 100644
--- a/src/keyevents.c
+++ b/src/keyevents.c
@@ -290,6 +290,10 @@ void init_keyevents(void) {
cur_kb = &keys.orient_1;
else if (!strcmp(action, "orient_3"))
cur_kb = &keys.orient_3;
+ else if (!strcmp(action, "flip"))
+ cur_kb = &keys.flip;
+ else if (!strcmp(action, "mirror"))
+ cur_kb = &keys.mirror;
else if (!strcmp(action, "reload_minus"))
cur_kb = &keys.reload_minus;
else if (!strcmp(action, "reload_plus"))
@@ -645,10 +649,16 @@ void feh_event_handle_keypress(XEvent * ev)
winwidget_destroy(winwid);
}
else if (feh_is_kp(&keys.orient_1, keysym, state)) {
- feh_edit_inplace_orient(winwid, 1);
+ feh_edit_inplace(winwid, 1);
}
else if (feh_is_kp(&keys.orient_3, keysym, state)) {
- feh_edit_inplace_orient(winwid, 3);
+ feh_edit_inplace(winwid, 3);
+ }
+ else if (feh_is_kp(&keys.flip, keysym, state)) {
+ feh_edit_inplace(winwid, INPLACE_EDIT_FLIP);
+ }
+ else if (feh_is_kp(&keys.mirror, keysym, state)) {
+ feh_edit_inplace(winwid, INPLACE_EDIT_MIRROR);
}
else if (feh_is_kp(&keys.toggle_fullscreen, keysym, state)) {
#ifdef HAVE_LIBXINERAMA
diff --git a/src/menu.c b/src/menu.c
index fe58760..ef30d03 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -1351,7 +1351,7 @@ void feh_menu_cb(feh_menu * m, feh_menu_item * i, int action, void *data)
winwidget_size_to_image(m->fehwin);
break;
case CB_EDIT_ROTATE:
- feh_edit_inplace_orient(m->fehwin, (int) data);
+ feh_edit_inplace(m->fehwin, (int) data);
break;
case CB_SAVE_IMAGE:
slideshow_save_image(m->fehwin);
diff --git a/src/options.h b/src/options.h
index 3c62441..bfcb94c 100644
--- a/src/options.h
+++ b/src/options.h
@@ -194,6 +194,8 @@ struct __fehkb {
struct __fehkey close;
struct __fehkey orient_1;
struct __fehkey orient_3;
+ struct __fehkey flip;
+ struct __fehkey mirror;
struct __fehkey toggle_fullscreen;
struct __fehkey reload_minus;
struct __fehkey reload_plus;