diff options
author | Fumitoshi UKAI <ukai@debian.or.jp> | 2002-07-17 20:58:48 +0000 |
---|---|---|
committer | Fumitoshi UKAI <ukai@debian.or.jp> | 2002-07-17 20:58:48 +0000 |
commit | a12c96b4923d05b04f4bd9351028e444be58c7cb (patch) | |
tree | 9afc10209e987b339e4bbc846b72591e51616b36 /w3mimg/fb/fb_gdkpixbuf.c | |
parent | [w3m-dev 03263] fix lastA segfault (diff) | |
download | w3m-a12c96b4923d05b04f4bd9351028e444be58c7cb.tar.gz w3m-a12c96b4923d05b04f4bd9351028e444be58c7cb.zip |
merge w3m-img for framebuffer support
* w3mimg/w3mimg.h: created
* w3mimg/x11/x11_w3mimg.c: created
* w3mimg/fb/fb_w3mimg.c: created
* w3mimgsize.c w3mimgdisplay.c: modified
* configure: modified
* XMakefile: modified
* config.h.dist: updated
From: Fumitoshi UKAI <ukai@debian.or.jp>
w3m-img for framebuffer support
* http://homepage3.nifty.com/slokar/fb/
* w3mimg/fb/fb.c w3mimg/fb/fb.h
w3mimg/fb/fb_img.c w3mimg/fb/fb_img.h
w3mimg/fb/fb_gdkpixbuf.c w3mimg/fb/fb_gdkpixbuf.h
w3mimg/fb/fb_imlib2.c w3mimg/fb/fb_imlib.h
w3mimg/fb/readme.txt w3mimg/fb/license.txt: added
From: Hiroshi Kawashima <kei@sm.sony.co.jp>
Diffstat (limited to 'w3mimg/fb/fb_gdkpixbuf.c')
-rw-r--r-- | w3mimg/fb/fb_gdkpixbuf.c | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/w3mimg/fb/fb_gdkpixbuf.c b/w3mimg/fb/fb_gdkpixbuf.c new file mode 100644 index 0000000..8a505ce --- /dev/null +++ b/w3mimg/fb/fb_gdkpixbuf.c @@ -0,0 +1,128 @@ +/************************************************************************** + fb_gdkpixbuf.c 0.2 Copyright (C) 2002, hito + **************************************************************************/ + +#include "fb.h" +#include "fb_img.h" + +static void set_prm(IMAGE *img); + +IMAGE *fb_load_image(char *filename, int w, int h) +{ + GdkPixbuf *pixbuf; + IMAGE *img; + + if(filename == NULL) + return NULL; + + img = malloc(sizeof(*img)); + if(img == NULL) + return NULL; + + 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) + 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); + } + } + return 0; +} + +int fb_resize_image(IMAGE *img, int width, int height) +{ + GdkPixbuf *pixbuf; + if(width < 1 || height < 1 || img == NULL) + return 1; + + if(width == img->width && height == img->height) + return 0; + + pixbuf = gdk_pixbuf_scale_simple(img->pixbuf, width, height, GDK_INTERP_HYPER); + if(pixbuf == NULL) + return 1; + gdk_pixbuf_finalize(img->pixbuf); + + img->pixbuf = pixbuf; + set_prm(img); + return 0; +} + +void fb_free_image(IMAGE *img) +{ + if(img == NULL) + return; + + gdk_pixbuf_finalize(img->pixbuf); + free(img); +} + +IMAGE *fb_dup_image(IMAGE *img) +{ + GdkPixbuf *pixbuf; + IMAGE *new_img; + + if(img == NULL) + return NULL; + + new_img = malloc(sizeof(*img)); + if(new_img == NULL) + return NULL; + + pixbuf = gdk_pixbuf_copy(img->pixbuf); + if(pixbuf == NULL){ + free(new_img); + return NULL; + } + + new_img->pixbuf = pixbuf; + set_prm(new_img); + return new_img; +} + +int fb_rotate_image(IMAGE *img, int angle) +{ + return 1; +} + +static void set_prm(IMAGE *img) +{ + GdkPixbuf *pixbuf; + + if(img == NULL) + return; + pixbuf = img->pixbuf; + + 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); +} |