Basic image loading
This commit is contained in:
		
							parent
							
								
									7121e7b468
								
							
						
					
					
						commit
						2a2f0307c1
					
				
							
								
								
									
										8
									
								
								app.c
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								app.c
									
									
									
									
									
								
							| @ -40,8 +40,16 @@ void app_init(app_t *app) { | ||||
| } | ||||
| 
 | ||||
| void app_run(app_t *app) { | ||||
| 	app_load_image(app); | ||||
| 	event_loop(app); | ||||
| } | ||||
| 
 | ||||
| void app_quit(app_t *app) { | ||||
| } | ||||
| 
 | ||||
| void app_load_image(app_t *app) { | ||||
| 	if (!app || app->fileidx >= app->filecnt || !app->filenames) | ||||
| 		return; | ||||
| 
 | ||||
| 	img_load(&app->img, app->filenames[app->fileidx]); | ||||
| } | ||||
|  | ||||
							
								
								
									
										2
									
								
								app.h
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								app.h
									
									
									
									
									
								
							| @ -34,4 +34,6 @@ void app_init(app_t*); | ||||
| void app_run(app_t*); | ||||
| void app_quit(app_t*); | ||||
| 
 | ||||
| void app_load_image(app_t*); | ||||
| 
 | ||||
| #endif /* APP_H */ | ||||
|  | ||||
							
								
								
									
										19
									
								
								image.c
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								image.c
									
									
									
									
									
								
							| @ -16,7 +16,8 @@ | ||||
|  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||||
|  */ | ||||
| 
 | ||||
| #include <Imlib2.h> | ||||
| #include <stdlib.h> | ||||
| #include <stdio.h> | ||||
| 
 | ||||
| #include "sxiv.h" | ||||
| #include "image.h" | ||||
| @ -30,3 +31,19 @@ void imlib_init(win_t *win) { | ||||
| 	imlib_context_set_colormap(win->env.cmap); | ||||
| 	imlib_context_set_drawable(win->xwin); | ||||
| } | ||||
| 
 | ||||
| void img_load(img_t *img, char *filename) { | ||||
| 	if (!img || !filename) | ||||
| 		return; | ||||
| 
 | ||||
| 	if (imlib_context_get_image()) | ||||
| 		imlib_free_image(); | ||||
| 
 | ||||
| 	if (!(img->im = imlib_load_image(filename))) | ||||
| 		FATAL("could not open image: %s", filename); | ||||
| 	 | ||||
| 	imlib_context_set_image(img->im); | ||||
| 	 | ||||
| 	img->w = imlib_image_get_width(); | ||||
| 	img->h = imlib_image_get_height(); | ||||
| } | ||||
|  | ||||
							
								
								
									
										7
									
								
								image.h
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								image.h
									
									
									
									
									
								
							| @ -19,6 +19,8 @@ | ||||
| #ifndef IMAGE_H | ||||
| #define IMAGE_H | ||||
| 
 | ||||
| #include <Imlib2.h> | ||||
| 
 | ||||
| #include "window.h" | ||||
| 
 | ||||
| typedef enum scalemode_e { | ||||
| @ -34,8 +36,13 @@ typedef struct img_s { | ||||
| 	int h; | ||||
| 	int x; | ||||
| 	int y; | ||||
| 
 | ||||
| 	Imlib_Image *im; | ||||
| } img_t; | ||||
| 
 | ||||
| void imlib_init(win_t*); | ||||
| 
 | ||||
| void img_load(img_t*, char*); | ||||
| void img_display(img_t*, win_t*); | ||||
| 
 | ||||
| #endif /* IMAGE_H */ | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Bert
						Bert