Apply flip & rotation on all frames of a multi-frame image; fixes issue #121
This commit is contained in:
		
							parent
							
								
									e82397db15
								
							
						
					
					
						commit
						f795273b65
					
				
							
								
								
									
										32
									
								
								image.c
									
									
									
									
									
								
							
							
						
						
									
										32
									
								
								image.c
									
									
									
									
									
								
							| @ -337,6 +337,8 @@ bool img_load(img_t *img, const fileinfo_t *file) | |||||||
| 
 | 
 | ||||||
| 	img->w = imlib_image_get_width(); | 	img->w = imlib_image_get_width(); | ||||||
| 	img->h = imlib_image_get_height(); | 	img->h = imlib_image_get_height(); | ||||||
|  | 	img->flip = FLIP_NONE; | ||||||
|  | 	img->rotation = DEGREE_0; | ||||||
| 	img->scalemode = options->scalemode; | 	img->scalemode = options->scalemode; | ||||||
| 	img->re = false; | 	img->re = false; | ||||||
| 	img->checkpan = false; | 	img->checkpan = false; | ||||||
| @ -689,10 +691,14 @@ bool img_pan_edge(img_t *img, direction_t dir) | |||||||
| void img_rotate(img_t *img, degree_t d) | void img_rotate(img_t *img, degree_t d) | ||||||
| { | { | ||||||
| 	int ox, oy, tmp; | 	int ox, oy, tmp; | ||||||
|  | 	bool reapply = d == -1; | ||||||
| 
 | 
 | ||||||
| 	if (img == NULL || img->im == NULL || img->win == NULL) | 	if (img == NULL || img->im == NULL || img->win == NULL) | ||||||
| 		return; | 		return; | ||||||
| 
 | 
 | ||||||
|  | 	if (reapply) | ||||||
|  | 		d = img->rotation; | ||||||
|  | 
 | ||||||
| 	imlib_context_set_image(img->im); | 	imlib_context_set_image(img->im); | ||||||
| 	imlib_image_orientate(d); | 	imlib_image_orientate(d); | ||||||
| 
 | 
 | ||||||
| @ -708,25 +714,29 @@ void img_rotate(img_t *img, degree_t d) | |||||||
| 		img->h = tmp; | 		img->h = tmp; | ||||||
| 		img->checkpan = true; | 		img->checkpan = true; | ||||||
| 	} | 	} | ||||||
| 
 | 	if (!reapply) | ||||||
|  | 		img->rotation = (img->rotation + d) % 4; | ||||||
| 	img->dirty = true; | 	img->dirty = true; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void img_flip(img_t *img, flipdir_t d) | void img_flip(img_t *img, flipdir_t d) | ||||||
| { | { | ||||||
|  | 	bool reapply = d == -1; | ||||||
|  | 
 | ||||||
| 	if (img == NULL || img->im == NULL) | 	if (img == NULL || img->im == NULL) | ||||||
| 		return; | 		return; | ||||||
| 
 | 
 | ||||||
|  | 	if (reapply) | ||||||
|  | 		d = img->flip; | ||||||
|  | 
 | ||||||
| 	imlib_context_set_image(img->im); | 	imlib_context_set_image(img->im); | ||||||
| 
 | 
 | ||||||
| 	switch (d) { | 	if (d & FLIP_HORIZONTAL) | ||||||
| 		case FLIP_HORIZONTAL: | 		imlib_image_flip_horizontal(); | ||||||
| 			imlib_image_flip_horizontal(); | 	if (d & FLIP_VERTICAL) | ||||||
| 			break; | 		imlib_image_flip_vertical(); | ||||||
| 		case FLIP_VERTICAL: | 	if (!reapply) | ||||||
| 			imlib_image_flip_vertical(); | 		img->flip ^= d; | ||||||
| 			break; |  | ||||||
| 	} |  | ||||||
| 	img->dirty = true; | 	img->dirty = true; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -785,6 +795,10 @@ bool img_frame_goto(img_t *img, int n) | |||||||
| 	img->checkpan = true; | 	img->checkpan = true; | ||||||
| 	img->dirty = true; | 	img->dirty = true; | ||||||
| 
 | 
 | ||||||
|  | 	if (img->flip != FLIP_NONE) | ||||||
|  | 		img_flip(img, -1); | ||||||
|  | 	if (img->rotation != DEGREE_0) | ||||||
|  | 		img_rotate(img, -1); | ||||||
| 	return true; | 	return true; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
							
								
								
									
										3
									
								
								image.h
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								image.h
									
									
									
									
									
								
							| @ -57,6 +57,9 @@ typedef struct { | |||||||
| 	bool aa; | 	bool aa; | ||||||
| 	bool alpha; | 	bool alpha; | ||||||
| 
 | 
 | ||||||
|  | 	flipdir_t flip; | ||||||
|  | 	degree_t rotation; | ||||||
|  | 
 | ||||||
| 	Imlib_Color_Modifier cmod; | 	Imlib_Color_Modifier cmod; | ||||||
| 	int gamma; | 	int gamma; | ||||||
| 
 | 
 | ||||||
|  | |||||||
							
								
								
									
										6
									
								
								types.h
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								types.h
									
									
									
									
									
								
							| @ -39,14 +39,16 @@ typedef enum { | |||||||
| } direction_t; | } direction_t; | ||||||
| 
 | 
 | ||||||
| typedef enum { | typedef enum { | ||||||
|  | 	DEGREE_0   = 0, | ||||||
| 	DEGREE_90  = 1, | 	DEGREE_90  = 1, | ||||||
| 	DEGREE_180 = 2, | 	DEGREE_180 = 2, | ||||||
| 	DEGREE_270 = 3 | 	DEGREE_270 = 3 | ||||||
| } degree_t; | } degree_t; | ||||||
| 
 | 
 | ||||||
| typedef enum { | typedef enum { | ||||||
| 	FLIP_HORIZONTAL, | 	FLIP_NONE       = 0, | ||||||
| 	FLIP_VERTICAL | 	FLIP_HORIZONTAL = 1, | ||||||
|  | 	FLIP_VERTICAL   = 2 | ||||||
| } flipdir_t; | } flipdir_t; | ||||||
| 
 | 
 | ||||||
| typedef enum { | typedef enum { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Bert Münnich
						Bert Münnich