nsxiv7e51c35
Handle 180 degrees image rotation
+34 −26
7 files changed
- M README.md +1 −0
- M commands.c +8 −5
- M config.def.h +7 −2
- M image.c +9 −16
- M image.h +0 −3
- M sxiv.1 +3 −0
- M types.h +6 −0
| @@ -136,6 +136,7 @@ of small previews is displayed, making it easy to choose an image to open. | |||
| 136 | 136 | (also with Ctrl-arrow keys) | |
| 137 | 137 | ||
| 138 | 138 | <,> Rotate image (counter-)clockwise by 90 degrees | |
| 139 | + | ? Rotate image by 180 degrees | |
| 139 | 140 | \,| Flip image horizontally/vertically | |
| 140 | 141 | ||
| 141 | 142 | a Toggle anti-aliasing | |
| @@ -397,14 +397,17 @@ bool i_fit_to_img(arg_t a) | |||
| 397 | 397 | ||
| 398 | 398 | bool i_rotate(arg_t a) | |
| 399 | 399 | { | |
| 400 | − | direction_t dir = (direction_t) a; | |
| 400 | + | rotate_t rot = (rotate_t) a; | |
| 401 | 401 | ||
| 402 | 402 | if (mode == MODE_IMAGE) { | |
| 403 | − | if (dir == DIR_LEFT) { | |
| 404 | − | img_rotate_left(&img); | |
| 403 | + | if (rot == ROTATE_90) { | |
| 404 | + | img_rotate(&img, 1); | |
| 405 | + | return true; | |
| 406 | + | } else if (rot == ROTATE_270) { | |
| 407 | + | img_rotate(&img, 3); | |
| 405 | 408 | return true; | |
| 406 | − | } else if (dir == DIR_RIGHT) { | |
| 407 | − | img_rotate_right(&img); | |
| 409 | + | } else if (rot == ROTATE_180) { | |
| 410 | + | img_rotate(&img, 2); | |
| 408 | 411 | return true; | |
| 409 | 412 | } | |
| 410 | 413 | } | |
| @@ -114,8 +114,9 @@ static const keymap_t keys[] = { | |||
| 114 | 114 | { false, XK_E, i_fit_to_win, (arg_t) SCALE_HEIGHT }, | |
| 115 | 115 | { false, XK_W, i_fit_to_img, (arg_t) None }, | |
| 116 | 116 | ||
| 117 | − | { false, XK_less, i_rotate, (arg_t) DIR_LEFT }, | |
| 118 | − | { false, XK_greater, i_rotate, (arg_t) DIR_RIGHT }, | |
| 117 | + | { false, XK_less, i_rotate, (arg_t) ROTATE_270 }, | |
| 118 | + | { false, XK_greater, i_rotate, (arg_t) ROTATE_90 }, | |
| 119 | + | { false, XK_question, i_rotate, (arg_t) ROTATE_180 }, | |
| 119 | 120 | ||
| 120 | 121 | { false, XK_backslash, i_flip, (arg_t) FLIP_HORIZONTAL }, | |
| 121 | 122 | { false, XK_bar, i_flip, (arg_t) FLIP_VERTICAL }, | |
| @@ -131,10 +132,14 @@ static const keymap_t keys[] = { | |||
| 131 | 132 | "mogrify -rotate -90 \"$SXIV_IMG\"" }, | |
| 132 | 133 | { true, XK_greater, it_shell_cmd, (arg_t) \ | |
| 133 | 134 | "mogrify -rotate +90 \"$SXIV_IMG\"" }, | |
| 135 | + | { true, XK_question, it_shell_cmd, (arg_t) \ | |
| 136 | + | "mogrify -rotate 180 \"$SXIV_IMG\"" }, | |
| 134 | 137 | { true, XK_comma, it_shell_cmd, (arg_t) \ | |
| 135 | 138 | "jpegtran -rotate 270 -copy all -outfile \"$SXIV_IMG\" \"$SXIV_IMG\"" }, | |
| 136 | 139 | { true, XK_period, it_shell_cmd, (arg_t) \ | |
| 137 | 140 | "jpegtran -rotate 90 -copy all -outfile \"$SXIV_IMG\" \"$SXIV_IMG\"" }, | |
| 141 | + | { true, XK_slash, it_shell_cmd, (arg_t) \ | |
| 142 | + | "jpegtran -rotate 180 -copy all -outfile \"$SXIV_IMG\" \"$SXIV_IMG\"" }, | |
| 138 | 143 | }; | |
| 139 | 144 | ||
| 140 | 145 | /* mouse button mappings for image mode: */ | |
| @@ -663,29 +663,22 @@ void img_rotate(img_t *img, int d) | |||
| 663 | 663 | oy = d == 3 ? img->y : win->h - img->y - img->h * img->zoom; | |
| 664 | 664 | ||
| 665 | 665 | imlib_context_set_image(img->im); | |
| 666 | + | /* rotates by `90 * d` degrees in the clockwise direction */ | |
| 666 | 667 | imlib_image_orientate(d); | |
| 667 | 668 | ||
| 668 | − | img->x = oy + (win->w - win->h) / 2; | |
| 669 | − | img->y = ox + (win->h - win->w) / 2; | |
| 669 | + | if (d == 1 || d == 3) { | |
| 670 | + | img->x = oy + (win->w - win->h) / 2; | |
| 671 | + | img->y = ox + (win->h - win->w) / 2; | |
| 670 | 672 | ||
| 671 | − | tmp = img->w; | |
| 672 | − | img->w = img->h; | |
| 673 | − | img->h = tmp; | |
| 673 | + | tmp = img->w; | |
| 674 | + | img->w = img->h; | |
| 675 | + | img->h = tmp; | |
| 676 | + | img->checkpan = true; | |
| 677 | + | } | |
| 674 | 678 | ||
| 675 | − | img->checkpan = true; | |
| 676 | 679 | img->dirty = true; | |
| 677 | 680 | } | |
| 678 | 681 | ||
| 679 | − | void img_rotate_left(img_t *img) | |
| 680 | − | { | |
| 681 | − | img_rotate(img, 3); | |
| 682 | − | } | |
| 683 | − | ||
| 684 | − | void img_rotate_right(img_t *img) | |
| 685 | − | { | |
| 686 | − | img_rotate(img, 1); | |
| 687 | − | } | |
| 688 | − | ||
| 689 | 682 | void img_flip(img_t *img, flipdir_t d) | |
| 690 | 683 | { | |
| 691 | 684 | if (img == NULL || img->im == NULL) | |
| @@ -77,9 +77,6 @@ bool img_pan(img_t*, direction_t, int); | |||
| 77 | 77 | bool img_pan_edge(img_t*, direction_t); | |
| 78 | 78 | ||
| 79 | 79 | void img_rotate(img_t*, int); | |
| 80 | − | void img_rotate_left(img_t*); | |
| 81 | − | void img_rotate_right(img_t*); | |
| 82 | − | ||
| 83 | 80 | void img_flip(img_t*, flipdir_t); | |
| 84 | 81 | ||
| 85 | 82 | void img_toggle_antialias(img_t*); | |
| @@ -261,6 +261,9 @@ Rotate image counter-clockwise by 90 degrees. | |||
| 261 | 261 | .TP | |
| 262 | 262 | .B > | |
| 263 | 263 | Rotate image clockwise by 90 degrees. | |
| 264 | + | .TP | |
| 265 | + | .B ? | |
| 266 | + | Rotate image by 180 degrees. | |
| 264 | 267 | .SS Flip | |
| 265 | 268 | .TP | |
| 266 | 269 | .B \\\\ | |
| @@ -38,6 +38,12 @@ typedef enum { | |||
| 38 | 38 | DIR_DOWN | |
| 39 | 39 | } direction_t; | |
| 40 | 40 | ||
| 41 | + | typedef enum { | |
| 42 | + | ROTATE_90, | |
| 43 | + | ROTATE_270, | |
| 44 | + | ROTATE_180 | |
| 45 | + | } rotate_t; | |
| 46 | + | ||
| 41 | 47 | typedef enum { | |
| 42 | 48 | FLIP_HORIZONTAL, | |
| 43 | 49 | FLIP_VERTICAL | |