aboutsummaryrefslogtreecommitdiffstats
path: root/w3mimg/fb/fb_gdkpixbuf.c
diff options
context:
space:
mode:
authorFumitoshi UKAI <ukai@debian.or.jp>2002-07-22 16:17:32 +0000
committerFumitoshi UKAI <ukai@debian.or.jp>2002-07-22 16:17:32 +0000
commit9f103b13bb3c46be9a9e017547c193f75876e24e (patch)
tree73c933927f290d578e4fc672605111319a5985cb /w3mimg/fb/fb_gdkpixbuf.c
parent[w3m-dev 03278] Compile error on mipsel linux (glibc-2.0.6) (diff)
downloadw3m-9f103b13bb3c46be9a9e017547c193f75876e24e.tar.gz
w3m-9f103b13bb3c46be9a9e017547c193f75876e24e.zip
[w3m-dev 03279] w3m-img for framebuffer update
http://homepage3.nifty.com/slokar/fb/w3mfb.patch.gz * w3mimg/fb/readme.txt: update * w3mimg/fb/fb.c: update * w3mimg/fb/fb.h: update * w3mimg/fb/fb_gdkpixbuf.c: update * w3mimg/fb/fb_img.c: update * w3mimg/fb/fb_img.h: update * w3mimg/fb/fb_imlib2.c: update * w3mimg/fb/fb_w3mimg.c: update * w3mimg/fb/fb_gdkpixbuf.h: deleted * w3mimg/fb/fb_imlib2.h: deleted * w3mimg/w3mimg.h (w3mimg_op): add get_image_size() * w3mimg/x11/x11_w3mimg.c: update * w3mimgdisplay.c (main): use get_image_size() * w3mimgsize.c (main): use get_image_size() From: Hiroyuki Ito <hito@crl.go.jp>
Diffstat (limited to 'w3mimg/fb/fb_gdkpixbuf.c')
-rw-r--r--w3mimg/fb/fb_gdkpixbuf.c174
1 files changed, 80 insertions, 94 deletions
diff --git a/w3mimg/fb/fb_gdkpixbuf.c b/w3mimg/fb/fb_gdkpixbuf.c
index 46a0bf6..003096a 100644
--- a/w3mimg/fb/fb_gdkpixbuf.c
+++ b/w3mimg/fb/fb_gdkpixbuf.c
@@ -1,137 +1,123 @@
-/* $Id: fb_gdkpixbuf.c,v 1.5 2002/07/18 15:12:06 ukai Exp $ */
+/* $Id: fb_gdkpixbuf.c,v 1.6 2002/07/22 16:17:32 ukai Exp $ */
/**************************************************************************
- fb_gdkpixbuf.c 0.2 Copyright (C) 2002, hito
+ fb_gdkpixbuf.c 0.3 Copyright (C) 2002, hito
**************************************************************************/
+#include <gdk-pixbuf/gdk-pixbuf.h>
#include "fb.h"
#include "fb_img.h"
-static void set_prm(IMAGE * img);
+static void draw(FB_IMAGE * img, GdkPixbuf * pixbuf);
+static GdkPixbuf *resize_image(GdkPixbuf * pixbuf, int width, int height);
-IMAGE *
-fb_load_image(char *filename, int w, int h)
+int
+get_image_size(char *filename, int *w, int *h)
{
GdkPixbuf *pixbuf;
- IMAGE *img;
if (filename == NULL)
- return NULL;
-
- img = malloc(sizeof(*img));
- if (img == NULL)
- return NULL;
+ return 1;
pixbuf = gdk_pixbuf_new_from_file(filename);
- if (pixbuf == NULL) {
- free(img);
- return NULL;
- }
-
- img->pixbuf = pixbuf;
- set_prm(img);
-
- fb_resize_image(img, w, h);
-
- return img;
-}
-
-int
-fb_draw_image(IMAGE * img, int x, int y, int sx, int sy, int width, int height)
-{
- int i, j, r, g, b, offset, bpp;
-
- if (img == NULL)
+ if (pixbuf == NULL)
return 1;
- bpp = img->rowstride / img->width;
- for (j = sy; j < sy + height && j < img->height; j++) {
- offset = j * img->rowstride + bpp * sx;
- for (i = sx; i < sx + width && i < img->width; i++, offset += bpp) {
- r = img->pixels[offset];
- g = img->pixels[offset + 1];
- b = img->pixels[offset + 2];
- if (img->alpha && img->pixels[offset + 3] == 0)
- fb_pset(i + x - sx, j + y - sy, bg_r, bg_g, bg_b);
- else
- fb_pset(i + x - sx, j + y - sy, r, g, b);
- }
- }
+ *w = gdk_pixbuf_get_width(pixbuf);
+ *h = gdk_pixbuf_get_height(pixbuf);
+
+ gdk_pixbuf_finalize(pixbuf);
return 0;
}
-int
-fb_resize_image(IMAGE * img, int width, int height)
+FB_IMAGE *
+fb_image_load(char *filename, int w, int h)
{
GdkPixbuf *pixbuf;
- if (width < 1 || height < 1 || img == NULL)
- return 1;
+ FB_IMAGE *img;
- if (width == img->width && height == img->height)
- return 0;
+ if (filename == NULL)
+ return NULL;
- pixbuf =
- gdk_pixbuf_scale_simple(img->pixbuf, width, height, GDK_INTERP_HYPER);
+ pixbuf = gdk_pixbuf_new_from_file(filename);
if (pixbuf == NULL)
- return 1;
- gdk_pixbuf_finalize(img->pixbuf);
+ return NULL;
- img->pixbuf = pixbuf;
- set_prm(img);
- return 0;
+ pixbuf = resize_image(pixbuf, w, h);
+ if (pixbuf == NULL)
+ return NULL;
+
+ w = gdk_pixbuf_get_width(pixbuf);
+ h = gdk_pixbuf_get_height(pixbuf);
+
+ img = fb_image_new(w, h);
+
+ if (img == NULL) {
+ gdk_pixbuf_finalize(pixbuf);
+ return NULL;
+ }
+
+ draw(img, pixbuf);
+
+ gdk_pixbuf_finalize(pixbuf);
+
+ return img;
}
void
-fb_free_image(IMAGE * img)
+draw(FB_IMAGE * img, GdkPixbuf * pixbuf)
{
- if (img == NULL)
+ int i, j, r, g, b, offset, bpp, rowstride;
+ guchar *pixels;
+ gboolean alpha;
+
+ if (img == NULL || pixbuf == NULL)
return;
- gdk_pixbuf_finalize(img->pixbuf);
- free(img);
+ rowstride = gdk_pixbuf_get_rowstride(pixbuf);
+ pixels = gdk_pixbuf_get_pixels(pixbuf);
+ alpha = gdk_pixbuf_get_has_alpha(pixbuf);
+
+ bpp = rowstride / img->width;
+ for (j = 0; j < img->height; j++) {
+ offset = j * rowstride;
+ for (i = 0; i < img->width; i++, offset += bpp) {
+ r = pixels[offset];
+ g = pixels[offset + 1];
+ b = pixels[offset + 2];
+ if (alpha && pixels[offset + 3] == 0)
+ fb_image_pset(img, i, j, bg_r, bg_g, bg_b);
+ else
+ fb_image_pset(img, i, j, r, g, b);
+ }
+ }
+ return;
}
-IMAGE *
-fb_dup_image(IMAGE * img)
+static GdkPixbuf *
+resize_image(GdkPixbuf * pixbuf, int width, int height)
{
- GdkPixbuf *pixbuf;
- IMAGE *new_img;
+ GdkPixbuf * resized_pixbuf;
+ int w, h;
- if (img == NULL)
+ if (pixbuf == NULL)
return NULL;
- new_img = malloc(sizeof(*img));
- if (new_img == NULL)
- return NULL;
+ w = gdk_pixbuf_get_width(pixbuf);
+ h = gdk_pixbuf_get_height(pixbuf);
- pixbuf = gdk_pixbuf_copy(img->pixbuf);
- if (pixbuf == NULL) {
- free(new_img);
- return NULL;
- }
+ if (width < 1 || height < 1)
+ return pixbuf;
- new_img->pixbuf = pixbuf;
- set_prm(new_img);
- return new_img;
-}
+ if (w == width && h == height)
+ return pixbuf;
-int
-fb_rotate_image(IMAGE * img, int angle)
-{
- return 1;
-}
+ resized_pixbuf =
+ gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_HYPER);
-static void
-set_prm(IMAGE * img)
-{
- GdkPixbuf *pixbuf;
+ gdk_pixbuf_finalize(pixbuf);
- if (img == NULL)
- return;
- pixbuf = img->pixbuf;
+ if (resized_pixbuf == NULL)
+ return NULL;
- img->pixels = gdk_pixbuf_get_pixels(pixbuf);
- img->width = gdk_pixbuf_get_width(pixbuf);
- img->height = gdk_pixbuf_get_height(pixbuf);
- img->alpha = gdk_pixbuf_get_has_alpha(pixbuf);
- img->rowstride = gdk_pixbuf_get_rowstride(pixbuf);
+ return resized_pixbuf;
}