Krolyxon
Commit 2a2f030

Branches

Refs →

nsxiv2a2f030

Basic image loading

Author
Bert
Date
2011-01-18 17:20 +0100
Parent
7121e7b
Commit
2a2f0307c1e313dde979de2086d93971c57d342b

+35 −1

4 files changed

  1. M app.c +8 −0
  2. M app.h +2 −0
  3. M image.c +18 −1
  4. M image.h +7 −0
M app.c View
@@ -40,8 +40,16 @@ void app_init(app_t *app) {
4040 }
4141
4242 void app_run(app_t *app) {
43+ app_load_image(app);
4344 event_loop(app);
4445 }
4546
4647 void app_quit(app_t *app) {
4748 }
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+}
M app.h View
@@ -34,4 +34,6 @@ void app_init(app_t*);
3434 void app_run(app_t*);
3535 void app_quit(app_t*);
3636
37+void app_load_image(app_t*);
38+
3739 #endif /* APP_H */
M image.c View
@@ -16,7 +16,8 @@
1616 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1717 */
1818
19−#include <Imlib2.h>
19+#include <stdlib.h>
20+#include <stdio.h>
2021
2122 #include "sxiv.h"
2223 #include "image.h"
@@ -30,3 +31,19 @@ void imlib_init(win_t *win) {
3031 imlib_context_set_colormap(win->env.cmap);
3132 imlib_context_set_drawable(win->xwin);
3233 }
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+}
M image.h View
@@ -19,6 +19,8 @@
1919 #ifndef IMAGE_H
2020 #define IMAGE_H
2121
22+#include <Imlib2.h>
23+
2224 #include "window.h"
2325
2426 typedef enum scalemode_e {
@@ -34,8 +36,13 @@ typedef struct img_s {
3436 int h;
3537 int x;
3638 int y;
39+
40+ Imlib_Image *im;
3741 } img_t;
3842
3943 void imlib_init(win_t*);
4044
45+void img_load(img_t*, char*);
46+void img_display(img_t*, win_t*);
47+
4148 #endif /* IMAGE_H */