Krolyxon
Commit f795273

Branches

Refs →

nsxivf795273

Apply flip & rotation on all frames of a multi-frame image; fixes issue #121

Author
Bert Münnich
Date
2014-01-09 00:01 +0100
Committer
Bert Münnich · 2014-01-09 00:30 +0100
Parent
e82397d
Commit
f795273b650a4df39dca693f30c3650ec1d3393f

+30 −11

3 files changed

  1. M image.c +23 −9
  2. M image.h +3 −0
  3. M types.h +4 −2
M image.c View
@@ -337,6 +337,8 @@ bool img_load(img_t *img, const fileinfo_t *file)
337337
338338 img->w = imlib_image_get_width();
339339 img->h = imlib_image_get_height();
340+ img->flip = FLIP_NONE;
341+ img->rotation = DEGREE_0;
340342 img->scalemode = options->scalemode;
341343 img->re = false;
342344 img->checkpan = false;
@@ -689,10 +691,14 @@ bool img_pan_edge(img_t *img, direction_t dir)
689691 void img_rotate(img_t *img, degree_t d)
690692 {
691693 int ox, oy, tmp;
694+ bool reapply = d == -1;
692695
693696 if (img == NULL || img->im == NULL || img->win == NULL)
694697 return;
695698
699+ if (reapply)
700+ d = img->rotation;
701+
696702 imlib_context_set_image(img->im);
697703 imlib_image_orientate(d);
698704
@@ -708,25 +714,29 @@ void img_rotate(img_t *img, degree_t d)
708714 img->h = tmp;
709715 img->checkpan = true;
710716 }
711−
717+ if (!reapply)
718+ img->rotation = (img->rotation + d) % 4;
712719 img->dirty = true;
713720 }
714721
715722 void img_flip(img_t *img, flipdir_t d)
716723 {
724+ bool reapply = d == -1;
725+
717726 if (img == NULL || img->im == NULL)
718727 return;
719728
729+ if (reapply)
730+ d = img->flip;
731+
720732 imlib_context_set_image(img->im);
721733
722− switch (d) {
723− case FLIP_HORIZONTAL:
724− imlib_image_flip_horizontal();
725− break;
726− case FLIP_VERTICAL:
727− imlib_image_flip_vertical();
728− break;
729− }
734+ if (d & FLIP_HORIZONTAL)
735+ imlib_image_flip_horizontal();
736+ if (d & FLIP_VERTICAL)
737+ imlib_image_flip_vertical();
738+ if (!reapply)
739+ img->flip ^= d;
730740 img->dirty = true;
731741 }
732742
@@ -785,6 +795,10 @@ bool img_frame_goto(img_t *img, int n)
785795 img->checkpan = true;
786796 img->dirty = true;
787797
798+ if (img->flip != FLIP_NONE)
799+ img_flip(img, -1);
800+ if (img->rotation != DEGREE_0)
801+ img_rotate(img, -1);
788802 return true;
789803 }
790804
M image.h View
@@ -57,6 +57,9 @@ typedef struct {
5757 bool aa;
5858 bool alpha;
5959
60+ flipdir_t flip;
61+ degree_t rotation;
62+
6063 Imlib_Color_Modifier cmod;
6164 int gamma;
6265
M types.h View
@@ -39,14 +39,16 @@ typedef enum {
3939 } direction_t;
4040
4141 typedef enum {
42+ DEGREE_0 = 0,
4243 DEGREE_90 = 1,
4344 DEGREE_180 = 2,
4445 DEGREE_270 = 3
4546 } degree_t;
4647
4748 typedef enum {
48− FLIP_HORIZONTAL,
49− FLIP_VERTICAL
49+ FLIP_NONE = 0,
50+ FLIP_HORIZONTAL = 1,
51+ FLIP_VERTICAL = 2
5052 } flipdir_t;
5153
5254 typedef enum {