[w3m-dev 04096] w3m-img gtk2
Fumitoshi UKAI <[email protected]>
| Newsgroups | gmane.comp.web.w3m.devel |
|---|---|
| Organization | Debian JP Project |
| Message-ID | <[email protected]> |
w3m-img gtk2
?
--- w3m-0.5.1.orig/acinclude.m4
+++ w3m-0.5.1/acinclude.m4
@@ -573,6 +573,7 @@
INSTALL_W3MIMGDISPLAY='${INSTALL_PROGRAM}'
AC_DEFINE(INSTALL_W3MIMGDISPLAY, $INSTALL_W3MIMGDISPLAY)
AC_SUBST(USE_GDKPIXBUF)
+ AC_SUBST(USE_GTK2)
AC_SUBST(USE_IMLIB)
AC_SUBST(USE_IMLIB2)
AC_SUBST(IMGTARGETS)
@@ -618,16 +619,17 @@
AC_ARG_WITH(imagelib,
[ --with-imagelib=IMAGELIBS image library
IMAGELIBS may be space separeted list of:
- gdk-pixbuf imlib imlib2],,
+ gtk2 gdk-pixbuf imlib imlib2],,
[with_imagelib="yes"])
if test x"$with_imagelib" = xyes; then
- with_imagelib="gdk-pixbuf imlib imlib2"
+ with_imagelib="gtk2 gdk-pixbuf imlib imlib2"
fi
AC_MSG_RESULT($with_imagelib)
with_imlib=no
with_imlib2=no
with_gdkpixbuf=no
+ with_gtk2=no
for imagelib in $with_imagelib
do
case "$imagelib" in
@@ -646,15 +648,31 @@
if test x"$GDKPIXBUF_CONFIG" = x; then
GDKPIXBUF_CONFIG=gdk-pixbuf-config
fi;;
+ gtk2)
+ with_gtk2="yes"
+ if test x"$PKG_CONFIG" = x; then
+ PKG_CONFIG=pkg-config
+ else
+ PKG_CONFIG=:
+ fi;;
esac
done
IMGTARGETS=""
- if test x"$with_gdkpixbuf" = xyes; then
+ if test x"$with_gtk2" = xyes; then
AC_W3M_CHECK_VER([GdkPixbuf],
+ [`$PKG_CONFIG --modversion gdk-pixbuf-2.0 2>/dev/null`],
+ 2, 0, 0,
+ [have_gdkpixbuf="yes"; have_gtk2="yes"],
+ [have_gdkpixbuf="no"; have_gtk2="no"])
+ fi
+ if test x"$with_gdkpixbuf" = xyes; then
+ if test x"$have_gdkpixbuf" = xno; then
+ AC_W3M_CHECK_VER([GdkPixbuf],
[`$GDKPIXBUF_CONFIG --version 2>/dev/null`],
0, 16, 0,
[have_gdkpixbuf="yes"],
[have_gdkpixbuf="no"])
+ fi
fi
if test x"$with_imlib" = xyes; then
AC_W3M_CHECK_VER([Imlib],
@@ -671,46 +689,64 @@
[have_imlib2="no"])
fi
if test x"$x11" = xyes; then
- if test x"$have_gdkpixbuf" = xyes; then
+ if test x"$have_gtk2" = xyes; then
AC_DEFINE(USE_W3MIMG_X11)
+ IMGOBJS="$IMGOBJS x11/x11_w3mimg.o"
+ IMGTARGETS="x11"
AC_DEFINE(USE_GDKPIXBUF)
+ AC_DEFINE(USE_GTK2)
+ IMGX11CFLAGS="`${PKG_CONFIG} --cflags gdk-pixbuf-2.0 gdk-pixbuf-xlib-2.0 gtk+-2.0`"
+ IMGX11LDFLAGS="`${PKG_CONFIG} --libs gdk-pixbuf-2.0 gdk-pixbuf-xlib-2.0 gtk+-2.0`"
+ elif test x"$have_gdkpixbuf" = xyes; then
+ AC_DEFINE(USE_W3MIMG_X11)
IMGOBJS="$IMGOBJS x11/x11_w3mimg.o"
+ IMGTARGETS="x11"
+ AC_DEFINE(USE_GDKPIXBUF)
IMGX11CFLAGS="`${GDKPIXBUF_CONFIG} --cflags`"
IMGX11LDFLAGS="`${GDKPIXBUF_CONFIG} --libs` -lgdk_pixbuf_xlib"
- IMGTARGETS="x11"
elif test x"$have_imlib" = xyes; then
AC_DEFINE(USE_W3MIMG_X11)
- AC_DEFINE(USE_IMLIB)
IMGOBJS="$IMGOBJS x11/x11_w3mimg.o"
+ IMGTARGETS="x11"
+ AC_DEFINE(USE_IMLIB)
IMGX11CFLAGS="`${IMLIB_CONFIG} --cflags`"
IMGX11LDFLAGS="`${IMLIB_CONFIG} --libs`"
IMGTARGETS="x11"
elif test x"$have_imlib2" = xyes; then
AC_DEFINE(USE_W3MIMG_X11)
- AC_DEFINE(USE_IMLIB2)
IMGOBJS="$IMGOBJS x11/x11_w3mimg.o"
+ IMGTARGETS="x11"
+ AC_DEFINE(USE_IMLIB2)
IMGX11CFLAGS="`${IMLIB2_CONFIG} --cflags`"
IMGX11LDFLAGS="`${IMLIB2_CONFIG} --libs`"
- IMGTARGETS="x11"
else
AC_MSG_WARN([unable to build w3mimgdisplay with X11 support])
fi
fi
if test x"$fb" = xyes; then
- if test x"$have_gdkpixbuf" = xyes; then
+ if test x"$have_gtk2" = xyes; then
AC_DEFINE(USE_W3MIMG_FB)
+ IMGOBJS="$IMGOBJS fb/fb_w3mimg.o fb/fb.o fb/fb_img.o"
+ IMGTARGETS="${IMGTARGETS} fb"
AC_DEFINE(USE_GDKPIXBUF)
+ AC_DEFINE(USE_GTK2)
+ IMGFBCFLAGS="`${PKG_CONFIG} --cflags gdk-pixbuf-2.0 gtk+-2.0`"
+ IMGFBLDFLAGS="`${PKG_CONFIG} --libs gdk-pixbuf-2.0 gtk+-2.0`"
+ elif test x"$have_gdkpixbuf" = xyes; then
+ AC_DEFINE(USE_W3MIMG_FB)
IMGOBJS="$IMGOBJS fb/fb_w3mimg.o fb/fb.o fb/fb_img.o"
+ IMGTARGETS="${IMGTARGETS} fb"
+ AC_DEFINE(USE_GDKPIXBUF)
IMGFBCFLAGS="`${GDKPIXBUF_CONFIG} --cflags`"
IMGFBLDFLAGS="`${GDKPIXBUF_CONFIG} --libs`"
- IMGTARGETS="${IMGTARGETS} fb"
elif test x"$have_imlib2" = xyes; then
AC_DEFINE(USE_W3MIMG_FB)
+ IMGOBJS="$IMGOBJS fb/fb_w3mimg.o fb/fb.o fb/fb_img.o"
+ IMGTARGETS="${IMGTARGETS} fb"
AC_DEFINE(USE_IMLIB2)
IMGOBJS="$IMGOBJS fb/fb_w3mimg.o fb/fb.o fb/fb_img.o"
IMGFBCFLAGS="`${IMLIB2_CONFIG} --cflags`"
IMGFBLDFLAGS="`${IMLIB2_CONFIG} --libs`"
- IMGTARGETS="${IMGTARGETS} fb"
else
AC_MSG_WARN([unable to build w3mimgdisplay with FB support])
fi
--- w3m-0.5.1.orig/config.h.in
+++ w3m-0.5.1/config.h.in
@@ -72,6 +72,7 @@
#undef W3MIMGDISPLAY_SETUID
#undef USE_IMLIB
#undef USE_GDKPIXBUF
+#undef USE_GTK2
#undef USE_IMLIB2
#undef USE_XFACE
#undef USE_DICT
--- w3m-0.5.1.orig/w3mimg/fb/fb_gdkpixbuf.c
+++ w3m-0.5.1/w3mimg/fb/fb_gdkpixbuf.c
@@ -3,6 +3,11 @@
fb_gdkpixbuf.c 0.3 Copyright (C) 2002, hito
**************************************************************************/
+#include "config.h"
+#if defined(USE_GTK2)
+#include <glib-object.h>
+#include <gdk/gdk.h>
+#endif
#include <gdk-pixbuf/gdk-pixbuf.h>
#include "fb.h"
#include "fb_img.h"
@@ -11,7 +16,33 @@
GdkPixbuf * pixbuf);
static GdkPixbuf *resize_image(GdkPixbuf * pixbuf, int width, int height);
-static void
+#if defined(USE_GTK2)
+static int
+get_animation_size(GdkPixbufAnimation * animation, int *w, int *h, int *delay)
+{
+ GdkPixbufAnimationIter *iter;
+ int iw, ih, n, i, d = -1;
+
+ iter = gdk_pixbuf_animation_get_iter(animation, NULL);
+ *w = gdk_pixbuf_animation_get_width(animation);
+ *h = gdk_pixbuf_animation_get_height(animation);
+ for (i = 1;
+ gdk_pixbuf_animation_iter_on_currently_loading_frame(iter) != TRUE;
+ i++) {
+ int tmp;
+ tmp = gdk_pixbuf_animation_iter_get_delay_time(iter);
+ if (tmp > d)
+ d = tmp;
+ gdk_pixbuf_animation_iter_advance(iter, NULL);
+ }
+ if (delay)
+ *delay = d;
+ n = i;
+ g_object_unref(G_OBJECT(iter));
+ return n;
+}
+#else
+static int
get_animation_size(GdkPixbufAnimation * animation, int *w, int *h, int *delay)
{
GList *frames;
@@ -42,6 +73,16 @@
}
if (delay)
*delay = d;
+ return n;
+}
+#endif
+
+void
+fb_image_init()
+{
+#if defined(USE_GTK2)
+ g_type_init();
+#endif
}
int
@@ -50,11 +91,19 @@
GdkPixbufAnimation *animation;
if (filename == NULL)
return 1;
+#if defined(USE_GTK2)
+ animation = gdk_pixbuf_animation_new_from_file(filename, NULL);
+#else
animation = gdk_pixbuf_animation_new_from_file(filename);
+#endif
if (animation == NULL)
return 1;
get_animation_size(animation, w, h, NULL);
+#if defined(USE_GTK2)
+ g_object_unref(G_OBJECT(animation));
+#else
gdk_pixbuf_animation_unref(animation);
+#endif
return 0;
}
@@ -62,19 +111,25 @@
fb_image_load(char *filename, int w, int h, int max_anim)
{
GdkPixbufAnimation *animation;
+#if defined(USE_GTK2)
+ GdkPixbufAnimationIter *iter;
+#else
GList *frames;
+#endif
double ratio_w, ratio_h;
int n, i, j, fw, fh, frame_num, delay;
FB_IMAGE **fb_frame = NULL, *tmp_image = NULL;
if (filename == NULL)
return NULL;
+#if defined(USE_GTK2)
+ animation = gdk_pixbuf_animation_new_from_file(filename, NULL);
+#else
animation = gdk_pixbuf_animation_new_from_file(filename);
+#endif
if (animation == NULL)
return NULL;
- frames = gdk_pixbuf_animation_get_frames(animation);
- get_animation_size(animation, &fw, &fh, &delay);
- frame_num = n = gdk_pixbuf_animation_get_num_frames(animation);
+ frame_num = n = get_animation_size(animation, &fw, &fh, &delay);
if (delay <= 0)
max_anim = -1;
if (max_anim < 0) {
@@ -108,6 +163,46 @@
fb_image_fill(tmp_image, bg_r, bg_g, bg_b);
}
+#if defined(USE_GTK2)
+ iter = gdk_pixbuf_animation_get_iter(animation, NULL);
+
+ for (j = 0; j < n; j++) {
+ GdkPixbuf *org_pixbuf, *pixbuf;
+ int width, height;
+
+ if (max_anim < 0) {
+ i = (j - n + frame_num > 0) ? (j - n + frame_num) : 0;
+ }
+ else {
+ i = j;
+ }
+
+ if (gdk_pixbuf_animation_iter_on_currently_loading_frame(iter)) {
+ g_object_unref(G_OBJECT(iter));
+ iter = gdk_pixbuf_animation_get_iter(animation, NULL);
+ }
+ org_pixbuf = gdk_pixbuf_animation_iter_get_pixbuf(iter);
+ width = gdk_pixbuf_get_width(org_pixbuf);
+ height = gdk_pixbuf_get_height(org_pixbuf);
+ if (width == fw && height == fh) {
+ pixbuf = resize_image(org_pixbuf, w, h);
+ } else {
+ pixbuf = resize_image(org_pixbuf, width * ratio_w, height * ratio_h);
+ }
+ width = gdk_pixbuf_get_width(pixbuf);
+ height = gdk_pixbuf_get_height(pixbuf);
+
+ fb_frame[i]->delay = gdk_pixbuf_animation_iter_get_delay_time(iter);
+ fb_image_copy(fb_frame[i], tmp_image);
+ draw(fb_frame[i], !i, 0, 0, width, height, pixbuf);
+ fb_image_copy(tmp_image, fb_frame[0]); /* ??? default */
+ if (org_pixbuf != pixbuf)
+ g_object_unref(G_OBJECT(pixbuf));
+ gdk_pixbuf_animation_iter_advance(iter, NULL);
+ }
+#else
+ frames = gdk_pixbuf_animation_get_frames(animation);
+
for (j = 0; j < n; j++) {
GdkPixbufFrame *frame;
GdkPixbuf *org_pixbuf, *pixbuf;
@@ -157,10 +252,15 @@
if (org_pixbuf != pixbuf)
gdk_pixbuf_finalize(pixbuf);
}
+#endif
END:
if (tmp_image)
fb_image_free(tmp_image);
+#if defined(USE_GTK2)
+ g_object_unref(G_OBJECT(animation));
+#else
gdk_pixbuf_animation_unref(animation);
+#endif
return fb_frame;
}
static void
--- w3m-0.5.1.orig/w3mimg/fb/fb_img.h
+++ w3m-0.5.1/w3mimg/fb/fb_img.h
@@ -3,6 +3,7 @@
#define fb_img_header
#include "fb.h"
+void fb_image_init();
FB_IMAGE **fb_image_load(char *filename, int w, int h, int n);
void fb_image_set_bg(int r, int g, int b);
int fb_image_clear(int x, int y, int w, int h);
--- w3m-0.5.1.orig/w3mimg/fb/fb_imlib2.c
+++ w3m-0.5.1/w3mimg/fb/fb_imlib2.c
@@ -11,6 +11,12 @@
static void draw(FB_IMAGE * img, Imlib_Image image);
static Imlib_Image resize_image(Imlib_Image image, int width, int height);
+void
+fb_image_init()
+{
+ return;
+}
+
int
get_image_size(char *filename, int *w, int *h)
{
--- w3m-0.5.1.orig/w3mimg/fb/fb_w3mimg.c
+++ w3m-0.5.1/w3mimg/fb/fb_w3mimg.c
@@ -17,6 +17,7 @@
{
if (self == NULL)
return 0;
+ /* XXX */
return 1;
}
@@ -195,6 +196,9 @@
wop->free_image = w3mfb_free_image;
wop->get_image_size = w3mfb_get_image_size;
+ /* XXX */
+ fb_image_init();
+
return wop;
error:
free(wop);
--- w3m-0.5.1.orig/w3mimg/x11/x11_w3mimg.c
+++ w3m-0.5.1/w3mimg/x11/x11_w3mimg.c
@@ -1,6 +1,7 @@
/* $Id: x11_w3mimg.c,v 1.25 2003/07/13 16:19:10 ukai Exp $ */
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <ctype.h>
#include "config.h"
@@ -11,7 +12,13 @@
#include <X11/Xutil.h>
#include <Imlib2.h>
#elif defined(USE_GDKPIXBUF)
+#if defined(USE_GTK2)
+#include <glib-object.h>
+#include <gdk/gdk.h>
+#include <gdk-pixbuf-xlib/gdk-pixbuf-xlib.h>
+#else
#include <gdk-pixbuf/gdk-pixbuf-xlib.h>
+#endif
#else
#error no Imlib and GdkPixbuf support
#endif
@@ -42,7 +49,33 @@
Pixmap *pixmap;
};
-static void
+#if defined(USE_GTK2)
+static int
+get_animation_size(GdkPixbufAnimation * animation, int *w, int *h, int *delay)
+{
+ GdkPixbufAnimationIter *iter;
+ int n, i, d = -1;
+
+ iter = gdk_pixbuf_animation_get_iter(animation, NULL);
+ *w = gdk_pixbuf_animation_get_width(animation);
+ *h = gdk_pixbuf_animation_get_height(animation);
+ for (i = 1;
+ gdk_pixbuf_animation_iter_on_currently_loading_frame(iter) != TRUE;
+ i++) {
+ int tmp;
+ tmp = gdk_pixbuf_animation_iter_get_delay_time(iter);
+ if (tmp > d)
+ d = tmp;
+ gdk_pixbuf_animation_iter_advance(iter, NULL);
+ }
+ if (delay)
+ *delay = d;
+ g_object_unref(G_OBJECT(iter));
+ n = i;
+ return n;
+}
+#else
+static int
get_animation_size(GdkPixbufAnimation * animation, int *w, int *h, int *delay)
{
GList *frames;
@@ -74,7 +107,7 @@
if (delay)
*delay = d;
}
-
+#endif
#endif
static int
@@ -94,6 +127,9 @@
}
#elif defined(USE_GDKPIXBUF)
if (!xi->init_flag) {
+#if defined(USE_GTK2)
+ g_type_init();
+#endif
gdk_pixbuf_xlib_init(xi->display, 0);
xi->init_flag = TRUE;
}
@@ -290,11 +326,15 @@
Imlib_Image im;
#elif defined(USE_GDKPIXBUF)
GdkPixbufAnimation *animation;
- GList *frames;
- int i, j, iw, ih, n, frame_num, delay, max_anim;
+ int i, j, iw, ih, n, frame_num, delay = -1, max_anim;
double ratio_w, ratio_h;
struct x11_image *ximg;
Pixmap tmp_pixmap;
+#if defined(USE_GTK2)
+ GdkPixbufAnimationIter *iter;
+#else
+ GList *frames;
+#endif
#endif
if (self == NULL)
@@ -342,13 +382,14 @@
imlib_free_image();
#elif defined(USE_GDKPIXBUF)
max_anim = self->max_anim;
+#if defined(USE_GTK2)
+ animation = gdk_pixbuf_animation_new_from_file(fname, NULL);
+#else
animation = gdk_pixbuf_animation_new_from_file(fname);
+#endif
if (!animation)
return 0;
- frames = gdk_pixbuf_animation_get_frames(animation);
- frame_num = n = gdk_pixbuf_animation_get_num_frames(animation);
-
- get_animation_size(animation, &iw, &ih, &delay);
+ frame_num = n = get_animation_size(animation, &iw, &ih, &delay);
if (delay <= 0)
max_anim = -1;
@@ -370,17 +411,83 @@
}
tmp_pixmap = XCreatePixmap(xi->display, xi->parent, w, h,
DefaultDepth(xi->display, 0));
+ XSetForeground(xi->display, xi->imageGC, xi->background_pixel);
XFillRectangle(xi->display, (Pixmap) tmp_pixmap, xi->imageGC, 0, 0, w, h);
if (!tmp_pixmap) {
+#if defined(USE_GTK2)
+ g_object_unref(G_OBJECT(animation));
+#else
gdk_pixbuf_animation_unref(animation);
+#endif
return 0;
}
ximg = x11_img_new(xi, w, h, frame_num);
if (!ximg) {
XFreePixmap(xi->display, tmp_pixmap);
+#if defined(USE_GTK2)
+ g_object_unref(G_OBJECT(animation));
+#else
gdk_pixbuf_animation_unref(animation);
+#endif
return 0;
}
+#if defined(USE_GTK2)
+ iter = gdk_pixbuf_animation_get_iter(animation, NULL);
+
+ for (j = 0; j < n; j++) {
+ GdkPixbuf *org_pixbuf, *pixbuf;
+ int width, height, ofstx = 0, ofsty = 0;
+
+ if (max_anim < 0) {
+ i = (j - n + frame_num > 0) ? (j - n + frame_num) : 0;
+ }
+ else {
+ i = j;
+ }
+
+ if (gdk_pixbuf_animation_iter_on_currently_loading_frame(iter)) {
+ g_object_unref(G_OBJECT(iter));
+ iter = gdk_pixbuf_animation_get_iter(animation, NULL);
+ }
+ org_pixbuf = gdk_pixbuf_animation_iter_get_pixbuf(iter);
+ delay = gdk_pixbuf_animation_iter_get_delay_time(iter);
+ width = gdk_pixbuf_get_width(org_pixbuf);
+ height = gdk_pixbuf_get_height(org_pixbuf);
+
+ if (width == w && height == h) {
+ pixbuf = resize_image(org_pixbuf, w, h);
+ }
+ else {
+ pixbuf =
+ resize_image(org_pixbuf, width * ratio_w, height * ratio_h);
+ }
+ width = gdk_pixbuf_get_width(pixbuf);
+ height = gdk_pixbuf_get_height(pixbuf);
+
+ if (delay > ximg->delay)
+ ximg->delay = delay;
+
+ XCopyArea(xi->display, tmp_pixmap, ximg->pixmap[i],
+ xi->imageGC, 0, 0, w, h, 0, 0);
+ gdk_pixbuf_xlib_render_to_drawable_alpha(pixbuf,
+ (Drawable) ximg->pixmap[i], 0,
+ 0, ofstx, ofsty, width,
+ height,
+ GDK_PIXBUF_ALPHA_BILEVEL, 1,
+ XLIB_RGB_DITHER_NORMAL, 0, 0);
+ /* XXX */
+ XCopyArea(xi->display, ximg->pixmap[0], tmp_pixmap,
+ xi->imageGC, 0, 0, w, h, 0, 0);
+ if (org_pixbuf != pixbuf)
+ g_object_unref(G_OBJECT(pixbuf));
+ gdk_pixbuf_animation_iter_advance(iter, NULL);
+ }
+ XFreePixmap(xi->display, tmp_pixmap);
+ g_object_unref(G_OBJECT(animation));
+
+#else
+ frames = gdk_pixbuf_animation_get_frames(animation);
+
for (j = 0; j < n; j++) {
GdkPixbufFrame *frame;
GdkPixbuf *org_pixbuf, *pixbuf;
@@ -448,6 +555,7 @@
}
XFreePixmap(xi->display, tmp_pixmap);
gdk_pixbuf_animation_unref(animation);
+#endif
img->pixmap = ximg;
#endif
@@ -577,13 +685,21 @@
*h = imlib_image_get_height();
imlib_free_image();
#elif defined(USE_GDKPIXBUF)
+#if defined(USE_GTK2)
+ animation = gdk_pixbuf_animation_new_from_file(fname, NULL);
+#else
animation = gdk_pixbuf_animation_new_from_file(fname);
+#endif
if (!animation)
return 0;
get_animation_size(animation, w, h, NULL);
+#if defined(USE_GTK2)
+ g_object_unref(G_OBJECT(animation));
+#else
gdk_pixbuf_animation_unref(animation);
#endif
+#endif
return 1;
}
--