Handle 180 degrees image rotation

This commit is contained in:
Bastien Dejean 2013-06-23 16:02:26 +02:00 committed by Bert Münnich
parent 68ff9d71f1
commit 7e51c35801
7 changed files with 34 additions and 26 deletions

View File

@ -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

View File

@ -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;
}
}

View File

@ -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: */

15
image.c
View File

@ -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);
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;
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)

View File

@ -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*);

3
sxiv.1
View File

@ -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 \\\\

View File

@ -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