Krolyxon
Commit 7e51c35

Branches

Refs →

nsxiv7e51c35

Handle 180 degrees image rotation

Author
Bastien Dejean
Date
2013-06-23 16:02 +0200
Committer
Bert Münnich · 2013-08-10 15:33 +0200
Parent
68ff9d7
Commit
7e51c35801f9921685c3acf0d1d17d9370ae4d59

+34 −26

7 files changed

  1. M README.md +1 −0
  2. M commands.c +8 −5
  3. M config.def.h +7 −2
  4. M image.c +9 −16
  5. M image.h +0 −3
  6. M sxiv.1 +3 −0
  7. M types.h +6 −0
M README.md View
@@ -136,6 +136,7 @@ of small previews is displayed, making it easy to choose an image to open.
136136 (also with Ctrl-arrow keys)
137137
138138 <,> Rotate image (counter-)clockwise by 90 degrees
139+ ? Rotate image by 180 degrees
139140 \,| Flip image horizontally/vertically
140141
141142 a Toggle anti-aliasing
M commands.c View
@@ -397,14 +397,17 @@ bool i_fit_to_img(arg_t a)
397397
398398 bool i_rotate(arg_t a)
399399 {
400− direction_t dir = (direction_t) a;
400+ rotate_t rot = (rotate_t) a;
401401
402402 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);
405408 return true;
406− } else if (dir == DIR_RIGHT) {
407− img_rotate_right(&img);
409+ } else if (rot == ROTATE_180) {
410+ img_rotate(&img, 2);
408411 return true;
409412 }
410413 }
M config.def.h View
@@ -114,8 +114,9 @@ static const keymap_t keys[] = {
114114 { false, XK_E, i_fit_to_win, (arg_t) SCALE_HEIGHT },
115115 { false, XK_W, i_fit_to_img, (arg_t) None },
116116
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 },
119120
120121 { false, XK_backslash, i_flip, (arg_t) FLIP_HORIZONTAL },
121122 { false, XK_bar, i_flip, (arg_t) FLIP_VERTICAL },
@@ -131,10 +132,14 @@ static const keymap_t keys[] = {
131132 "mogrify -rotate -90 \"$SXIV_IMG\"" },
132133 { true, XK_greater, it_shell_cmd, (arg_t) \
133134 "mogrify -rotate +90 \"$SXIV_IMG\"" },
135+ { true, XK_question, it_shell_cmd, (arg_t) \
136+ "mogrify -rotate 180 \"$SXIV_IMG\"" },
134137 { true, XK_comma, it_shell_cmd, (arg_t) \
135138 "jpegtran -rotate 270 -copy all -outfile \"$SXIV_IMG\" \"$SXIV_IMG\"" },
136139 { true, XK_period, it_shell_cmd, (arg_t) \
137140 "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\"" },
138143 };
139144
140145 /* mouse button mappings for image mode: */
M image.c View
@@ -663,29 +663,22 @@ void img_rotate(img_t *img, int d)
663663 oy = d == 3 ? img->y : win->h - img->y - img->h * img->zoom;
664664
665665 imlib_context_set_image(img->im);
666+ /* rotates by `90 * d` degrees in the clockwise direction */
666667 imlib_image_orientate(d);
667668
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;
670672
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+ }
674678
675− img->checkpan = true;
676679 img->dirty = true;
677680 }
678681
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−
689682 void img_flip(img_t *img, flipdir_t d)
690683 {
691684 if (img == NULL || img->im == NULL)
M image.h View
@@ -77,9 +77,6 @@ bool img_pan(img_t*, direction_t, int);
7777 bool img_pan_edge(img_t*, direction_t);
7878
7979 void img_rotate(img_t*, int);
80−void img_rotate_left(img_t*);
81−void img_rotate_right(img_t*);
82−
8380 void img_flip(img_t*, flipdir_t);
8481
8582 void img_toggle_antialias(img_t*);
M sxiv.1 View
@@ -261,6 +261,9 @@ Rotate image counter-clockwise by 90 degrees.
261261 .TP
262262 .B >
263263 Rotate image clockwise by 90 degrees.
264+.TP
265+.B ?
266+Rotate image by 180 degrees.
264267 .SS Flip
265268 .TP
266269 .B \\\\
M types.h View
@@ -38,6 +38,12 @@ typedef enum {
3838 DIR_DOWN
3939 } direction_t;
4040
41+typedef enum {
42+ ROTATE_90,
43+ ROTATE_270,
44+ ROTATE_180
45+} rotate_t;
46+
4147 typedef enum {
4248 FLIP_HORIZONTAL,
4349 FLIP_VERTICAL