[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#456128: Imlib2 patch for MagicPoint



This patch adapts MagicPoint to work with the imlib2 library.
(MagicPoint currently uses the older imlib.) As far as I can
tell this patch works fine, though I'm not a MagicPoint user myself so
I might have missed something. (This is based on Barry deFreese's
earlier work, in case you've seen that.)

The reason for this patch is that Debian is trying to remove imlib.
It has long been unmaintained, and very few programs still
use it. MagicPoint is one of the last.

I hope this reaches the mgp-users list. I tried subscribing using the
instructions on the website, but didn't get a subscription confirmation
email.

Happy New Year,
-- 
Peter De Wachter
--- a/configure.in
+++ b/configure.in
@@ -448,44 +448,44 @@
 AC_SUBST(USE_IMLIB)
 AC_MSG_CHECKING(if imlib is used)
 AC_ARG_ENABLE(imlib,
-	[  --enable-imlib          use imlib exclusively to load images.],
+	[  --enable-imlib          use imlib2 exclusively to load images.],
 	[mgp_imlib="$enableval"],
 	[mgp_imlib="yes"])
 AC_MSG_RESULT($mgp_imlib)
 if test $mgp_imlib = "yes"; then
   if type pkg-config > /dev/null 2>&1; then
-     if pkg-config imlib; then
-        LIBS="$LIBS `pkg-config --libs imlib`"
-        OPTFLAGS="$OPTFLAGS `pkg-config --cflags imlib`"
+     if pkg-config imlib2; then
+        LIBS="$LIBS `pkg-config --libs imlib2`"
+        OPTFLAGS="$OPTFLAGS `pkg-config --cflags imlib2`"
 	AC_DEFINE(USE_IMLIB)
 	USE_IMLIB=1
      fi
   else
-	AC_CHECK_LIB(Imlib, Imlib_init,
+	AC_CHECK_LIB(Imlib2, imlib_load_image,
 		[imlib_ok=yes
-		LIBS="$LIBS -lImlib"
+		LIBS="$LIBS -lImlib2"
 		AC_DEFINE(USE_IMLIB)
 		USE_IMLIB=1],
 		[], [-L$x_libraries -lX11 -lXext])
 	if test "x$imlib_ok" != "xyes"; then
-		echo 'FATAL: You need libImlib to use Imlib loading.  pass proper LIBS to configure.'
+		echo 'FATAL: You need libImlib2 to use Imlib loading.  pass proper LIBS to configure.'
 		exit 1
 	fi
 	for i in /usr/pkg /usr/local; do
-		if test -f $i/include/Imlib.h; then
+		if test -f $i/include/Imlib2.h; then
 			imlib_h_ok=yes
 			OPTFLAGS="$OPTFLAGS -I$i/include"
 			break
 		fi
 	done
-	if test -f /usr/include/Imlib.h; then
+	if test -f /usr/include/Imlib2.h; then
 		imlib_h_ok=yes
 	fi
 	if test "x$gif_h_ok" != "xyes"; then
-		AC_CHECK_HEADER(Imlib.h, imlib_h_ok=yes)
+		AC_CHECK_HEADER(Imlib2.h, imlib_h_ok=yes)
 	fi
 	if test "x$imlib_h_ok" != "xyes"; then
-		echo 'FATAL: cannot find Imlib.h.  pass proper CPPFLAGS to configure.'
+		echo 'FATAL: cannot find Imlib2.h.  pass proper CPPFLAGS to configure.'
 		exit 1
 	fi
   fi
--- a/draw.c
+++ b/draw.c
@@ -31,7 +31,7 @@
 
 #include "mgp.h"
 #ifdef USE_IMLIB
-#include <Imlib.h>
+#include <Imlib2.h>
 #endif
 
 /* state associated with the window - how should we treat this? */
@@ -83,8 +83,8 @@
 	u_int, char *));
 static int obj_new_image __P((struct render_state *, int, int, Image *, int, int));
 #ifdef USE_IMLIB
-ImlibImage *search_imdata __P((char *));
-static int obj_new_image2 __P((struct render_state *, int, int, Image *, int, int, ImlibImage *, int));
+Imlib_Image *search_imdata __P((char *));
+static int obj_new_image2 __P((struct render_state *, int, int, Image *, int, int, Imlib_Image *, int));
 #endif
 static int obj_new_icon __P((struct render_state *, int, int, u_int, u_int, u_long, u_int, XPoint *));
 static Pixel obj_image_color __P((Image *, Image *, Pixel, int *));
@@ -168,7 +168,7 @@
 static void clear_zimage __P((int));
 static void clear_region __P((int, int, int, int));
 #define ZIMAGENUM 100
-static ImlibImage *zimage[ZIMAGENUM];
+static Imlib_Image *zimage[ZIMAGENUM];
 static int zonzoom[ZIMAGENUM];
 static int zpage[ZIMAGENUM];
 static int zx[ZIMAGENUM];
@@ -1819,7 +1819,7 @@
 	int x, y;
 	Image *image;
 	int xzoom, yzoom;
-	ImlibImage *imimage;
+	Imlib_Image *imimage;
 	int zoomonclk;
 {
 	struct render_object *obj;
@@ -3212,7 +3212,7 @@
 	static char backfile[MAXPATHLEN];
 	static int backzoom, backnumcolor, backx, backy;
 #ifdef USE_IMLIB
-	ImlibImage *imimage;
+	Imlib_Image *imimage;
 #endif
 
 	if (!caching){
--- a/image/imlib_loader.c
+++ b/image/imlib_loader.c
@@ -6,13 +6,13 @@
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
 #include <X11/extensions/shape.h>
-#include <Imlib.h>
+#include <Imlib2.h>
 
 #define IMFILENUM 500
 static char imfile[IMFILENUM][1024];
-static ImlibImage *imdata[IMFILENUM];
+static Imlib_Image *imdata[IMFILENUM];
 static int imnum;
-static ImlibData *id;
+static Imlib_Context *id;
 
 int imIdent(char *fullname, char *name)
 {
@@ -23,40 +23,69 @@
 {
 	static Display *disp = NULL;
 	Image *image;
-	ImlibImage *im;
-	ImlibColor shape;
-	unsigned int w,h, size;
-	ImlibImage *search_imdata();
+	Imlib_Image *im;
+	unsigned int w,h,size,i;
+	DATA32 * argb_data;
+	byte * rgb_ptr;
+	Imlib_Image *search_imdata();
 	void regist_imdata();
 
 	if (disp == NULL) {
 		disp=XOpenDisplay(NULL);
 	}
-	if (id == NULL) id=Imlib_init(disp);
+/*	if (id == NULL) id=Imlib_init(disp); */
+/* might needs more work */
+	if (id == NULL) {
+		/* dither for non-truecolor displays */
+		imlib_context_set_dither(1);
+		imlib_context_set_display(disp);
+		imlib_context_set_visual(DefaultVisual(display, DefaultScreen(display)));
+		imlib_context_set_colormap(DefaultColormap(display, DefaultScreen(display)));
+	}
 	if ((im = search_imdata(fullname)) == NULL) {
-		im = Imlib_load_image(id, fullname);
+/*		im = Imlib_load_image(id, fullname); */
+		im = imlib_load_image(fullname);
 	}
 	if (im == NULL) {
 		return NULL;
 	}
-	w = im->rgb_width;
-	h = im->rgb_height;
-	size = w * h * 3;
+	imlib_context_set_image(im);
+	w = imlib_image_get_width();
+	h = imlib_image_get_height();
+	size = w * h;
 
 	image = newTrueImage(w, h);
-	memcpy(image->data, im->rgb_data, size);
-	
-	Imlib_get_image_shape(id, im, &shape);
 
-	/*
-	 * bug fix for transparent gif handling
-	 * suggested by Jose Geraldo Alves Brito Neto <jgabrito@iq.usp.br>
-	 */
-	if ((shape.r >=0) && (shape.g >= 0) && (shape.b >= 0))
-	  image->trans = \
-	    ((shape.r & 0xff) << 16) |
-	    ((shape.g & 0xff) <<  8) |
-	    ((shape.b & 0xff) <<  0);
+	/* Imlib2 stores images in ARGB format (32 bpp).  MagicPoint
+	 * wants RGB data (24 bpp). So we need a conversion pass. */
+	argb_data = imlib_image_get_data_for_reading_only();
+	rgb_ptr = image->data;
+	for (i = 0; i < size; ++i)
+	{
+	    if ((argb_data[i] >> 24) < 128)
+	    {
+		/* If this is a transparent pixel, we store #FE00FE. */
+		*rgb_ptr++ = 0xFE;
+		*rgb_ptr++ = 0x00;
+		*rgb_ptr++ = 0xFE;
+		/* Tell mgp we have transparent pixels. */
+		image->trans = 0xFE00FE;
+	    }
+	    else if ((argb_data[i] & 0x00FFFFFF) == 0x00FE00FE)
+	    {
+		/* If that color is actually used, we substitute something close. */
+		*rgb_ptr++ = 0xFF;
+		*rgb_ptr++ = 0x00;
+		*rgb_ptr++ = 0xFE;
+	    }
+	    else
+	    {
+		/* Otherwise, we can copy the pixel. */
+		*rgb_ptr++ = (argb_data[i] >> 16) & 0xFF; /* red */
+		*rgb_ptr++ = (argb_data[i] >> 8) & 0xFF;  /* green */
+		*rgb_ptr++ = argb_data[i] & 0xFF;	  /* blue */
+	    }
+	}
 
 	image->title = dupString(name);
 #if 0
@@ -68,7 +97,7 @@
 	return image;
 }
 
-ImlibImage *search_imdata(char *fullname)
+Imlib_Image *search_imdata(char *fullname)
 {
 	int i;
 	for (i = 0; i < imnum; i ++){
@@ -81,7 +110,7 @@
 
 void regist_imdata(fullname, im)
 	char *fullname; 
-	ImlibImage *im;
+	Imlib_Image *im;
 {
 	strcpy(imfile[imnum], fullname);	
 	imdata[imnum] = im;
@@ -89,12 +118,14 @@
 }
 
 Pixmap pixmap_fromimimage(imimage, width, height)
-	ImlibImage *imimage;
+	Imlib_Image *imimage;
 	int width, height;
 {
+	imlib_context_set_image(imimage); /* Is this needed? */
 	static Pixmap pixmap;
-	Imlib_render(id, imimage, width, height);
-	pixmap = Imlib_move_image(id, imimage);
+/*	Imlib_render(id, imimage, width, height); */
+/*	pixmap = Imlib_move_image(id, imimage); */
+	imlib_render_pixmaps_for_whole_image_at_size(&pixmap, NULL, width, height);
 
 	return pixmap;
 }
@@ -125,8 +156,8 @@
 		ppage[i] = page;
 	} else {
 		for (i = 0; i < MAXPMAP; i ++) {
-			if (ppage[i] == page){
-				Imlib_free_pixmap(id, pmap[i]);
+			if (ppage[i] == page && pmap[i] != 0){
+				imlib_free_pixmap_and_mask(pmap[i]);
 				pmap[i] = 0;
 			}
 		}
--- a/image/xloadimage.h
+++ b/image/xloadimage.h
@@ -16,7 +16,7 @@
 #include "options.h"
 
 #ifdef USE_IMLIB
-#include <Imlib.h>
+#include <Imlib2.h>
 #endif
 
 /* image name and option structure used when processing arguments
--- a/mgp.h
+++ b/mgp.h
@@ -507,7 +507,7 @@
 			float xzoom, yzoom;
 #ifdef USE_IMLIB
 			int zoomonclk;
-			ImlibImage *imimage;
+			Imlib_Image *imimage;
 #endif
 		} image;
 		struct {
--- a/configure
+++ b/configure
@@ -32,7 +32,7 @@
 ac_help="$ac_help
   --enable-gif            compile gif support in (need libungif)."
 ac_help="$ac_help
-  --enable-imlib          use imlib exclusively to load images."
+  --enable-imlib          use imlib2 exclusively to load images."
 ac_help="$ac_help
   --with-m17n-lib         use the m17n library"
 
@@ -3169,9 +3169,9 @@
 echo "$ac_t""$mgp_imlib" 1>&6
 if test $mgp_imlib = "yes"; then
   if type pkg-config > /dev/null 2>&1; then
-     if pkg-config imlib; then
-        LIBS="$LIBS `pkg-config --libs imlib`"
-        OPTFLAGS="$OPTFLAGS `pkg-config --cflags imlib`"
+     if pkg-config imlib2; then
+        LIBS="$LIBS `pkg-config --libs imlib2`"
+        OPTFLAGS="$OPTFLAGS `pkg-config --cflags imlib2`"
 	cat >> confdefs.h <<\EOF
 #define USE_IMLIB 1
 EOF
@@ -3179,24 +3179,24 @@
 	USE_IMLIB=1
      fi
   else
-	echo $ac_n "checking for Imlib_init in -lImlib""... $ac_c" 1>&6
-echo "configure:3184: checking for Imlib_init in -lImlib" >&5
-ac_lib_var=`echo Imlib'_'Imlib_init | sed 'y%./+-%__p_%'`
+	echo $ac_n "checking for imlib_load_image in -lImlib2""... $ac_c" 1>&6
+echo "configure:3184: checking for imlib_load_image in -lImlib2" >&5
+ac_lib_var=`echo Imlib2'_'imlib_load_image | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   ac_save_LIBS="$LIBS"
-LIBS="-lImlib -L$x_libraries -lX11 -lXext $LIBS"
+LIBS="-lImlib2 -L$x_libraries -lX11 -lXext $LIBS"
 cat > conftest.$ac_ext <<EOF
 #line 3192 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
     builtin and then its argument prototype would still apply.  */
-char Imlib_init();
+char imlib_load_image();
 
 int main() {
-Imlib_init()
+imlib_load_image()
 ; return 0; }
 EOF
 if { (eval echo configure:3203: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
@@ -3215,7 +3215,7 @@
 if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
   echo "$ac_t""yes" 1>&6
   imlib_ok=yes
-		LIBS="$LIBS -lImlib"
+		LIBS="$LIBS -lImlib2"
 		cat >> confdefs.h <<\EOF
 #define USE_IMLIB 1
 EOF
@@ -3226,30 +3226,30 @@
 fi
 
 	if test "x$imlib_ok" != "xyes"; then
-		echo 'FATAL: You need libImlib to use Imlib loading.  pass proper LIBS to configure.'
+		echo 'FATAL: You need libImlib2 to use Imlib loading.  pass proper LIBS to configure.'
 		exit 1
 	fi
 	for i in /usr/pkg /usr/local; do
-		if test -f $i/include/Imlib.h; then
+		if test -f $i/include/Imlib2.h; then
 			imlib_h_ok=yes
 			OPTFLAGS="$OPTFLAGS -I$i/include"
 			break
 		fi
 	done
-	if test -f /usr/include/Imlib.h; then
+	if test -f /usr/include/Imlib2.h; then
 		imlib_h_ok=yes
 	fi
 	if test "x$gif_h_ok" != "xyes"; then
-		ac_safe=`echo "Imlib.h" | sed 'y%./+-%__p_%'`
-echo $ac_n "checking for Imlib.h""... $ac_c" 1>&6
-echo "configure:3246: checking for Imlib.h" >&5
+		ac_safe=`echo "Imlib2.h" | sed 'y%./+-%__p_%'`
+echo $ac_n "checking for Imlib2.h""... $ac_c" 1>&6
+echo "configure:3246: checking for Imlib2.h" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
 #line 3251 "configure"
 #include "confdefs.h"
-#include <Imlib.h>
+#include <Imlib2.h>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
 { (eval echo configure:3256: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
@@ -3275,7 +3275,7 @@
 
 	fi
 	if test "x$imlib_h_ok" != "xyes"; then
-		echo 'FATAL: cannot find Imlib.h.  pass proper CPPFLAGS to configure.'
+		echo 'FATAL: cannot find Imlib2.h.  pass proper CPPFLAGS to configure.'
 		exit 1
 	fi
   fi

Reply to: