Adding upstream version 0.5.2

This commit is contained in:
Tatsuya Kinoshita
2011-05-04 16:23:02 +09:00
parent 72f72d64a4
commit 6db339b3d7
72 changed files with 7191 additions and 4808 deletions

View File

@@ -1,17 +1,51 @@
/* $Id: fb_gdkpixbuf.c,v 1.16 2003/06/13 15:03:35 ukai Exp $ */
/* $Id: fb_gdkpixbuf.c,v 1.21 2004/11/08 17:14:06 ukai Exp $ */
/**************************************************************************
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"
static void draw(FB_IMAGE * img, int bg, int x, int y, int w, int h,
static void draw(FB_IMAGE * img, int x, int y, int w, int h,
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 n, i, d = -1;
GTimeVal time;
g_get_current_time(&time);
iter = gdk_pixbuf_animation_get_iter(animation, &time);
*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);
g_time_val_add(&time, tmp * 1000);
if (tmp > d)
d = tmp;
gdk_pixbuf_animation_iter_advance(iter, &time);
}
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 +76,16 @@ get_animation_size(GdkPixbufAnimation * animation, int *w, int *h, int *delay)
}
if (delay)
*delay = d;
return n;
}
#endif
void
fb_image_init()
{
#if defined(USE_GTK2)
g_type_init();
#endif
}
int
@@ -50,11 +94,19 @@ get_image_size(char *filename, int *w, int *h)
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 +114,27 @@ FB_IMAGE **
fb_image_load(char *filename, int w, int h, int max_anim)
{
GdkPixbufAnimation *animation;
#if defined(USE_GTK2)
GdkPixbufAnimationIter *iter;
GTimeVal time;
#else
int i;
GList *frames;
#endif
double ratio_w, ratio_h;
int n, i, j, fw, fh, frame_num, delay;
int n, 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 +168,34 @@ fb_image_load(char *filename, int w, int h, int max_anim)
fb_image_fill(tmp_image, bg_r, bg_g, bg_b);
}
#if defined(USE_GTK2)
g_get_current_time(&time);
iter = gdk_pixbuf_animation_get_iter(animation, &time);
if (max_anim < 0 && n > -max_anim) {
max_anim = n + max_anim;
for (j = 0; j < max_anim; j++) {
g_time_val_add(&time,
gdk_pixbuf_animation_iter_get_delay_time(iter) * 1000);
gdk_pixbuf_animation_iter_advance(iter, &time);
}
}
for (j = 0; j < n; j++) {
GdkPixbuf *org_pixbuf, *pixbuf;
org_pixbuf = gdk_pixbuf_animation_iter_get_pixbuf(iter);
pixbuf = resize_image(org_pixbuf, w, h);
fb_frame[j]->delay = gdk_pixbuf_animation_iter_get_delay_time(iter);
g_time_val_add(&time, fb_frame[j]->delay * 1000);
draw(fb_frame[j], 0, 0, w, h, pixbuf);
if (org_pixbuf != pixbuf)
g_object_unref(G_OBJECT(pixbuf));
gdk_pixbuf_animation_iter_advance(iter, &time);
}
#else
frames = gdk_pixbuf_animation_get_frames(animation);
for (j = 0; j < n; j++) {
GdkPixbufFrame *frame;
GdkPixbuf *org_pixbuf, *pixbuf;
@@ -139,13 +227,14 @@ fb_image_load(char *filename, int w, int h, int max_anim)
fb_frame[i]->delay = gdk_pixbuf_frame_get_delay_time(frame);
fb_image_copy(fb_frame[i], tmp_image);
draw(fb_frame[i], !i, ofstx, ofsty, width, height, pixbuf);
draw(fb_frame[i], ofstx, ofsty, width, height, pixbuf);
switch (gdk_pixbuf_frame_get_action(frame)) {
case GDK_PIXBUF_FRAME_RETAIN:
fb_image_copy(tmp_image, fb_frame[i]);
break;
case GDK_PIXBUF_FRAME_DISPOSE:
fb_image_fill(tmp_image, bg_r, bg_g, bg_b);
break;
case GDK_PIXBUF_FRAME_REVERT:
fb_image_copy(tmp_image, fb_frame[0]);
@@ -157,14 +246,19 @@ fb_image_load(char *filename, int w, int h, int max_anim)
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
draw(FB_IMAGE * img, int bg, int x, int y, int w, int h, GdkPixbuf * pixbuf)
draw(FB_IMAGE * img, int x, int y, int w, int h, GdkPixbuf * pixbuf)
{
int i, j, r, g, b, offset, bpp, rowstride;
guchar *pixels;

View File

@@ -1,8 +1,9 @@
/* $Id: fb_img.h,v 1.8 2003/07/09 15:07:11 ukai Exp $ */
/* $Id: fb_img.h,v 1.9 2004/08/04 17:32:28 ukai Exp $ */
#ifndef fb_img_header
#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);

View File

@@ -1,4 +1,4 @@
/* $Id: fb_imlib2.c,v 1.9 2003/03/24 15:45:59 ukai Exp $ */
/* $Id: fb_imlib2.c,v 1.10 2004/08/04 17:32:28 ukai Exp $ */
/**************************************************************************
fb_imlib2.c 0.3 Copyright (C) 2002, hito
**************************************************************************/
@@ -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)
{

View File

@@ -1,4 +1,4 @@
/* $Id: fb_w3mimg.c,v 1.13 2003/08/29 15:06:52 ukai Exp $ */
/* $Id: fb_w3mimg.c,v 1.14 2004/08/04 17:32:28 ukai Exp $ */
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
@@ -17,6 +17,7 @@ w3mfb_init(w3mimg_op * self)
{
if (self == NULL)
return 0;
/* XXX */
return 1;
}
@@ -195,6 +196,9 @@ w3mimg_fbopen()
wop->free_image = w3mfb_free_image;
wop->get_image_size = w3mfb_get_image_size;
/* XXX */
fb_image_init();
return wop;
error:
free(wop);

View File

@@ -1,6 +1,7 @@
/* $Id: x11_w3mimg.c,v 1.25 2003/07/13 16:19:10 ukai Exp $ */
/* $Id: x11_w3mimg.c,v 1.29 2004/11/08 17:14:06 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,36 @@ struct x11_image {
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;
GTimeVal time;
g_get_current_time(&time);
iter = gdk_pixbuf_animation_get_iter(animation, &time);
*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);
g_time_val_add(&time, tmp * 1000);
if (tmp > d)
d = tmp;
gdk_pixbuf_animation_iter_advance(iter, &time);
}
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;
@@ -73,8 +109,9 @@ get_animation_size(GdkPixbufAnimation * animation, int *w, int *h, int *delay)
}
if (delay)
*delay = d;
return n;
}
#endif
#endif
static int
@@ -94,6 +131,9 @@ x11_init(w3mimg_op * self)
}
#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 +330,17 @@ x11_load_image(w3mimg_op * self, W3MImage * img, char *fname, int w, int h)
Imlib_Image im;
#elif defined(USE_GDKPIXBUF)
GdkPixbufAnimation *animation;
GList *frames;
int i, j, iw, ih, n, frame_num, delay, max_anim;
int 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;
GTimeVal time;
#else
int i;
GList *frames;
#endif
#endif
if (self == NULL)
@@ -342,13 +388,14 @@ x11_load_image(w3mimg_op * self, W3MImage * img, char *fname, int w, int h)
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 +417,64 @@ x11_load_image(w3mimg_op * self, W3MImage * img, char *fname, int w, int h)
}
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)
g_get_current_time(&time);
iter = gdk_pixbuf_animation_get_iter(animation, &time);
if (max_anim < 0 && n > -max_anim) {
max_anim = n + max_anim;
for (j = 0; j < max_anim; j++) {
delay = gdk_pixbuf_animation_iter_get_delay_time(iter);
g_time_val_add(&time, delay * 1000);
gdk_pixbuf_animation_iter_advance(iter, &time);
}
}
for (j = 0; j < frame_num; j++) {
GdkPixbuf *org_pixbuf, *pixbuf;
org_pixbuf = gdk_pixbuf_animation_iter_get_pixbuf(iter);
delay = gdk_pixbuf_animation_iter_get_delay_time(iter);
pixbuf = resize_image(org_pixbuf, w, h);
if (delay > ximg->delay)
ximg->delay = delay;
gdk_pixbuf_xlib_render_to_drawable_alpha(pixbuf,
(Drawable) ximg->pixmap[j], 0,
0, 0, 0, w, h,
GDK_PIXBUF_ALPHA_BILEVEL, 1,
XLIB_RGB_DITHER_NORMAL, 0, 0);
if (org_pixbuf != pixbuf)
g_object_unref(G_OBJECT(pixbuf));
g_time_val_add(&time, delay * 1000);
gdk_pixbuf_animation_iter_advance(iter, &time);
}
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;
@@ -430,6 +524,9 @@ x11_load_image(w3mimg_op * self, W3MImage * img, char *fname, int w, int h)
xi->imageGC, 0, 0, w, h, 0, 0);
break;
case GDK_PIXBUF_FRAME_DISPOSE:
XSetForeground(xi->display, xi->imageGC, xi->background_pixel);
XFillRectangle(xi->display, tmp_pixmap, xi->imageGC,
0, 0, w, h);
break;
case GDK_PIXBUF_FRAME_REVERT:
XCopyArea(xi->display, ximg->pixmap[0], tmp_pixmap,
@@ -448,6 +545,7 @@ x11_load_image(w3mimg_op * self, W3MImage * img, char *fname, int w, int h)
}
XFreePixmap(xi->display, tmp_pixmap);
gdk_pixbuf_animation_unref(animation);
#endif
img->pixmap = ximg;
#endif
@@ -577,12 +675,20 @@ x11_get_image_size(w3mimg_op * self, W3MImage * img, char *fname, int *w,
*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;
}