From 7e51c35801f9921685c3acf0d1d17d9370ae4d59 Mon Sep 17 00:00:00 2001 From: Bastien Dejean Date: Sun, 23 Jun 2013 16:02:26 +0200 Subject: [PATCH] Handle 180 degrees image rotation --- README.md | 1 + commands.c | 13 ++++++++----- config.def.h | 9 +++++++-- image.c | 25 +++++++++---------------- image.h | 3 --- sxiv.1 | 3 +++ types.h | 6 ++++++ 7 files changed, 34 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 0520496..0280c0f 100644 --- a/README.md +++ b/README.md @@ -136,6 +136,7 @@ of small previews is displayed, making it easy to choose an image to open. (also with Ctrl-arrow keys) <,> Rotate image (counter-)clockwise by 90 degrees + ? Rotate image by 180 degrees \,| Flip image horizontally/vertically a Toggle anti-aliasing diff --git a/commands.c b/commands.c index 0ab1944..ae8dac2 100644 --- a/commands.c +++ b/commands.c @@ -397,14 +397,17 @@ bool i_fit_to_img(arg_t a) bool i_rotate(arg_t a) { - direction_t dir = (direction_t) a; + rotate_t rot = (rotate_t) a; if (mode == MODE_IMAGE) { - if (dir == DIR_LEFT) { - img_rotate_left(&img); + if (rot == ROTATE_90) { + img_rotate(&img, 1); return true; - } else if (dir == DIR_RIGHT) { - img_rotate_right(&img); + } else if (rot == ROTATE_270) { + img_rotate(&img, 3); + return true; + } else if (rot == ROTATE_180) { + img_rotate(&img, 2); return true; } } diff --git a/config.def.h b/config.def.h index cd89b5f..7a50cf6 100644 --- a/config.def.h +++ b/config.def.h @@ -114,8 +114,9 @@ static const keymap_t keys[] = { { false, XK_E, i_fit_to_win, (arg_t) SCALE_HEIGHT }, { false, XK_W, i_fit_to_img, (arg_t) None }, - { false, XK_less, i_rotate, (arg_t) DIR_LEFT }, - { false, XK_greater, i_rotate, (arg_t) DIR_RIGHT }, + { false, XK_less, i_rotate, (arg_t) ROTATE_270 }, + { false, XK_greater, i_rotate, (arg_t) ROTATE_90 }, + { false, XK_question, i_rotate, (arg_t) ROTATE_180 }, { false, XK_backslash, i_flip, (arg_t) FLIP_HORIZONTAL }, { false, XK_bar, i_flip, (arg_t) FLIP_VERTICAL }, @@ -131,10 +132,14 @@ static const keymap_t keys[] = { "mogrify -rotate -90 \"$SXIV_IMG\"" }, { true, XK_greater, it_shell_cmd, (arg_t) \ "mogrify -rotate +90 \"$SXIV_IMG\"" }, + { true, XK_question, it_shell_cmd, (arg_t) \ + "mogrify -rotate 180 \"$SXIV_IMG\"" }, { true, XK_comma, it_shell_cmd, (arg_t) \ "jpegtran -rotate 270 -copy all -outfile \"$SXIV_IMG\" \"$SXIV_IMG\"" }, { true, XK_period, it_shell_cmd, (arg_t) \ "jpegtran -rotate 90 -copy all -outfile \"$SXIV_IMG\" \"$SXIV_IMG\"" }, + { true, XK_slash, it_shell_cmd, (arg_t) \ + "jpegtran -rotate 180 -copy all -outfile \"$SXIV_IMG\" \"$SXIV_IMG\"" }, }; /* mouse button mappings for image mode: */ diff --git a/image.c b/image.c index 3230880..b2ac293 100644 --- a/image.c +++ b/image.c @@ -663,29 +663,22 @@ void img_rotate(img_t *img, int d) oy = d == 3 ? img->y : win->h - img->y - img->h * img->zoom; imlib_context_set_image(img->im); + /* rotates by `90 * d` degrees in the clockwise direction */ imlib_image_orientate(d); - img->x = oy + (win->w - win->h) / 2; - img->y = ox + (win->h - win->w) / 2; + if (d == 1 || d == 3) { + img->x = oy + (win->w - win->h) / 2; + img->y = ox + (win->h - win->w) / 2; - tmp = img->w; - img->w = img->h; - img->h = tmp; + tmp = img->w; + img->w = img->h; + img->h = tmp; + img->checkpan = true; + } - img->checkpan = true; img->dirty = true; } -void img_rotate_left(img_t *img) -{ - img_rotate(img, 3); -} - -void img_rotate_right(img_t *img) -{ - img_rotate(img, 1); -} - void img_flip(img_t *img, flipdir_t d) { if (img == NULL || img->im == NULL) diff --git a/image.h b/image.h index dbb249e..7e90163 100644 --- a/image.h +++ b/image.h @@ -77,9 +77,6 @@ bool img_pan(img_t*, direction_t, int); bool img_pan_edge(img_t*, direction_t); void img_rotate(img_t*, int); -void img_rotate_left(img_t*); -void img_rotate_right(img_t*); - void img_flip(img_t*, flipdir_t); void img_toggle_antialias(img_t*); diff --git a/sxiv.1 b/sxiv.1 index 85872e3..8072e4b 100644 --- a/sxiv.1 +++ b/sxiv.1 @@ -261,6 +261,9 @@ Rotate image counter-clockwise by 90 degrees. .TP .B > Rotate image clockwise by 90 degrees. +.TP +.B ? +Rotate image by 180 degrees. .SS Flip .TP .B \\\\ diff --git a/types.h b/types.h index 1b15c73..2427626 100644 --- a/types.h +++ b/types.h @@ -38,6 +38,12 @@ typedef enum { DIR_DOWN } direction_t; +typedef enum { + ROTATE_90, + ROTATE_270, + ROTATE_180 +} rotate_t; + typedef enum { FLIP_HORIZONTAL, FLIP_VERTICAL