nsxiv2a2f030
Basic image loading
+35 −1
4 files changed
| @@ -40,8 +40,16 @@ void app_init(app_t *app) { | |||
| 40 | 40 | } | |
| 41 | 41 | ||
| 42 | 42 | void app_run(app_t *app) { | |
| 43 | + | app_load_image(app); | |
| 43 | 44 | event_loop(app); | |
| 44 | 45 | } | |
| 45 | 46 | ||
| 46 | 47 | void app_quit(app_t *app) { | |
| 47 | 48 | } | |
| 49 | + | ||
| 50 | + | void app_load_image(app_t *app) { | |
| 51 | + | if (!app || app->fileidx >= app->filecnt || !app->filenames) | |
| 52 | + | return; | |
| 53 | + | ||
| 54 | + | img_load(&app->img, app->filenames[app->fileidx]); | |
| 55 | + | } | |
| @@ -34,4 +34,6 @@ void app_init(app_t*); | |||
| 34 | 34 | void app_run(app_t*); | |
| 35 | 35 | void app_quit(app_t*); | |
| 36 | 36 | ||
| 37 | + | void app_load_image(app_t*); | |
| 38 | + | ||
| 37 | 39 | #endif /* APP_H */ | |
| @@ -16,7 +16,8 @@ | |||
| 16 | 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
| 17 | 17 | */ | |
| 18 | 18 | ||
| 19 | − | #include <Imlib2.h> | |
| 19 | + | #include <stdlib.h> | |
| 20 | + | #include <stdio.h> | |
| 20 | 21 | ||
| 21 | 22 | #include "sxiv.h" | |
| 22 | 23 | #include "image.h" | |
| @@ -30,3 +31,19 @@ void imlib_init(win_t *win) { | |||
| 30 | 31 | imlib_context_set_colormap(win->env.cmap); | |
| 31 | 32 | imlib_context_set_drawable(win->xwin); | |
| 32 | 33 | } | |
| 34 | + | ||
| 35 | + | void img_load(img_t *img, char *filename) { | |
| 36 | + | if (!img || !filename) | |
| 37 | + | return; | |
| 38 | + | ||
| 39 | + | if (imlib_context_get_image()) | |
| 40 | + | imlib_free_image(); | |
| 41 | + | ||
| 42 | + | if (!(img->im = imlib_load_image(filename))) | |
| 43 | + | FATAL("could not open image: %s", filename); | |
| 44 | + | ||
| 45 | + | imlib_context_set_image(img->im); | |
| 46 | + | ||
| 47 | + | img->w = imlib_image_get_width(); | |
| 48 | + | img->h = imlib_image_get_height(); | |
| 49 | + | } | |
| @@ -19,6 +19,8 @@ | |||
| 19 | 19 | #ifndef IMAGE_H | |
| 20 | 20 | #define IMAGE_H | |
| 21 | 21 | ||
| 22 | + | #include <Imlib2.h> | |
| 23 | + | ||
| 22 | 24 | #include "window.h" | |
| 23 | 25 | ||
| 24 | 26 | typedef enum scalemode_e { | |
| @@ -34,8 +36,13 @@ typedef struct img_s { | |||
| 34 | 36 | int h; | |
| 35 | 37 | int x; | |
| 36 | 38 | int y; | |
| 39 | + | ||
| 40 | + | Imlib_Image *im; | |
| 37 | 41 | } img_t; | |
| 38 | 42 | ||
| 39 | 43 | void imlib_init(win_t*); | |
| 40 | 44 | ||
| 45 | + | void img_load(img_t*, char*); | |
| 46 | + | void img_display(img_t*, win_t*); | |
| 47 | + | ||
| 41 | 48 | #endif /* IMAGE_H */ | |