changeset 601:8863d23cea4b openvg

Load images with Imlib2. Image loader, now, use Imlib2 to load images into ARGB 32bits pixels. It can load png, jpg, bmp, tiff, ...., etc.
author Thinker K.F. Li <thinker@branda.to>
date Fri, 02 Jul 2010 11:59:17 +0800
parents 20b396c09c23
children ac2e6468a22a
files configure.ac examples/menu/filebrowser.c src/Makefile.am src/img_ldr.c
diffstat 4 files changed, 28 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/configure.ac	Thu Jul 01 16:39:59 2010 +0800
+++ b/configure.ac	Fri Jul 02 11:59:17 2010 +0800
@@ -139,6 +139,7 @@
 PKG_CHECK_MODULES([cairo], [cairo >= 1.6], , AC_MSG_ERROR([cairo >= 1.6 not found]))
 PKG_CHECK_MODULES([pangocairo], [pangocairo >= 1.0], , AC_MSG_ERROR([pangocairo >= 1.0 not found]))
 [fi]
+PKG_CHECK_MODULES([imlib2], [imlib2 >= 1.4.1], , AC_MSG_ERROR([imlib2 >= 1.4.1 not found]))
 
 AC_CONFIG_FILES([Makefile
                  libmbfly.pc
--- a/examples/menu/filebrowser.c	Thu Jul 01 16:39:59 2010 +0800
+++ b/examples/menu/filebrowser.c	Fri Jul 02 11:59:17 2010 +0800
@@ -112,7 +112,8 @@
 
     printf("check %s\n",s);
 
-    if (endWith(s,".png")) {
+    if (endWith(s,".png") || endWith(s, ".jpg") ||
+	endWith(s, ".PNG") || endWith(s, ".JPG")) {
     	    snprintf(path,1024,"%s%s", data->curDir,data->titles[select]);
 	    mypreview(data,path);
     }
--- a/src/Makefile.am	Thu Jul 01 16:39:59 2010 +0800
+++ b/src/Makefile.am	Fri Jul 02 11:59:17 2010 +0800
@@ -23,6 +23,8 @@
 	shape_rect.c shift.c subtree_free.c timer.c 			\
 	timertool.c tools.c visibility.c prop.c sprite.c	\
 	mouse.c shape_image.c img_ldr.c $(MBAF_SOURCES)
+libmbfly_la_CPPFLAGS = @imlib2_CFLAGS@
+libmbfly_la_LDFLAGS = @imlib2_LIBS@
 
 if SH_TEXT
 libmbfly_la_SOURCES += shape_text.c
@@ -39,8 +41,8 @@
 if CAIRO_GRAPH_ENGINE
 libmbfly_la_SOURCES += graph_engine_cairo.c
 
-libmbfly_la_CPPFLAGS = @cairo_CFLAGS@ @pangocairo_CFLAGS@
-libmbfly_la_LDFLAGS = @cairo_LIBS@ @pangocairo_LIBS@
+libmbfly_la_CPPFLAGS += @cairo_CFLAGS@ @pangocairo_CFLAGS@
+libmbfly_la_LDFLAGS += @cairo_LIBS@ @pangocairo_LIBS@
 endif
 
 if SKIA_GRAPH_ENGINE
--- a/src/img_ldr.c	Thu Jul 01 16:39:59 2010 +0800
+++ b/src/img_ldr.c	Fri Jul 02 11:59:17 2010 +0800
@@ -1,5 +1,6 @@
 #include <stdio.h>
 #include <string.h>
+#include <Imlib2.h>
 #include "mb_graph_engine.h"
 #include "mb_tools.h"
 #include "mb_paint.h"
@@ -16,7 +17,7 @@
 
 struct _simple_mb_img_data {
     mb_img_data_t img;
-    mbe_surface_t *surf;
+    Imlib_Image img_hdl;
 };
 typedef struct _simple_mb_img_data simple_mb_img_data_t;
 
@@ -26,7 +27,9 @@
 mb_img_data_t *simple_mb_img_ldr_load(mb_img_ldr_t *ldr, const char *img_id) {
     simple_mb_img_ldr_t *sldr = (simple_mb_img_ldr_t *)ldr;
     simple_mb_img_data_t *img;
-    mbe_surface_t *surf;
+    Imlib_Image img_hdl;
+    int w, h;
+    void *data;
     char *fname;
     int sz;
 
@@ -36,22 +39,26 @@
     strcpy(fname, sldr->repo);
     strcat(fname, img_id);
     
-    surf = mbe_image_surface_create_from_png(fname);
-    if(surf == NULL)
+    img_hdl = imlib_load_image(fname);
+    if(!img_hdl)
 	return NULL;
+    imlib_context_set_image(img_hdl);
+    w = imlib_image_get_width();
+    h = imlib_image_get_height();
+    data = imlib_image_get_data_for_reading_only();
 
     img = O_ALLOC(simple_mb_img_data_t);
     if(img == NULL) {
-	mbe_surface_destroy(surf);
+	imlib_free_image();
 	return NULL;
     }
-    img->img.content = mbe_image_surface_get_data(surf);
-    img->img.w = mbe_image_surface_get_width(surf);
-    img->img.h = mbe_image_surface_get_height(surf);
-    img->img.stride = mbe_image_surface_get_stride(surf);
-    img->img.fmt = mbe_image_surface_get_format(surf);
+    img->img.content = data;
+    img->img.w = w;
+    img->img.h = h;
+    img->img.stride = w * 4;
+    img->img.fmt = MB_IFMT_ARGB32;
     img->img.free = simple_mb_img_ldr_img_free;
-    img->surf = surf;
+    img->img_hdl = img_hdl;
 
     return (mb_img_data_t *)img;
 }
@@ -59,7 +66,9 @@
 static
 void simple_mb_img_ldr_img_free(mb_img_data_t *img) {
     simple_mb_img_data_t *simg = (simple_mb_img_data_t *)img;
-    mbe_surface_destroy((mbe_surface_t *)simg->surf);
+
+    imlib_context_set_image(simg->img_hdl);
+    imlib_free_image();
     free(img);
 }