aboutsummaryrefslogtreecommitdiffstats
path: root/w3mimg/fb/fb_imlib2.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_imlib2.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 '')
-rw-r--r--w3mimg/fb/fb_imlib2.c188
1 files changed, 75 insertions, 113 deletions
diff --git a/w3mimg/fb/fb_imlib2.c b/w3mimg/fb/fb_imlib2.c
index 3041594..44633a3 100644
--- a/w3mimg/fb/fb_imlib2.c
+++ b/w3mimg/fb/fb_imlib2.c
@@ -1,162 +1,124 @@
-/* $Id: fb_imlib2.c,v 1.5 2002/07/18 15:14:21 ukai Exp $ */
+/* $Id: fb_imlib2.c,v 1.6 2002/07/22 16:17:32 ukai Exp $ */
/**************************************************************************
- fb_imlib2.c 0.2 Copyright (C) 2002, hito
+ fb_imlib2.c 0.3 Copyright (C) 2002, hito
**************************************************************************/
+#include <X11/Xlib.h>
+#include <Imlib2.h>
#include "fb.h"
#include "fb_img.h"
-static void set_prm(IMAGE * img);
+static void draw(FB_IMAGE * img, Imlib_Image image);
+static Imlib_Image resize_image(Imlib_Image image, int width, int height);
-IMAGE *
-fb_load_image(char *filename, int w, int h)
+int
+get_image_size(char *filename, int *w, int *h)
{
Imlib_Image image;
- IMAGE *img;
if (filename == NULL)
- return NULL;
-
- img = malloc(sizeof(*img));
- if (img == NULL)
- return NULL;
+ return 1;
image = imlib_load_image(filename);
- if (image == NULL) {
- free(img);
- return NULL;
- }
-
- imlib_context_set_image(image);
-
- img->image = image;
- 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, a = 0, offset;
-
- if (img == NULL)
+ if (image == NULL)
return 1;
- for (j = sy; j < sy + height && j < img->height; j++) {
- offset = j * img->width;
- for (i = sx; i < sx + width && i < img->width; i++) {
- a = (img->data[offset + i] >> 24) & 0x000000ff;
- r = (img->data[offset + i] >> 16) & 0x000000ff;
- g = (img->data[offset + i] >> 8) & 0x000000ff;
- b = (img->data[offset + i]) & 0x000000ff;
+ imlib_context_set_image(image);
+ *w = imlib_image_get_width();
+ *h = imlib_image_get_height();
+ imlib_free_image();
- if (a == 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)
+FB_IMAGE *
+fb_image_load(char *filename, int w, int h)
{
Imlib_Image image;
+ FB_IMAGE *img;
- if (width < 1 || height < 1 || img == NULL)
- return 1;
+ if (filename == NULL)
+ return NULL;
- if (width == img->width && height == img->height)
- return 0;
+ image = imlib_load_image(filename);
+ if (image == NULL)
+ return NULL;
- image =
- imlib_create_cropped_scaled_image(0, 0, img->width, img->height, width,
- height);
+ image = resize_image(image, w, h);
if (image == NULL)
- return 1;
+ return NULL;
- imlib_context_set_image(img->image);
- imlib_free_image();
+ imlib_context_set_image(image);
- img->image = image;
- set_prm(img);
- return 0;
-}
+ w = imlib_image_get_width();
+ h = imlib_image_get_height();
-void
-fb_free_image(IMAGE * img)
-{
- if (img == NULL)
- return;
+ img = fb_image_new(w, h);
+
+ if (img == NULL) {
+ imlib_free_image();
+ return NULL;
+ }
+
+ draw(img, image);
- imlib_context_set_image(img->image);
imlib_free_image();
- free(img);
+
+ return img;
}
-IMAGE *
-fb_dup_image(IMAGE * img)
+static void
+draw(FB_IMAGE * img, Imlib_Image image)
{
- Imlib_Image image;
- IMAGE *new_img;
+ int i, j, r, g, b, a = 0, offset;
+ DATA32 *data;
if (img == NULL)
- return NULL;
+ return;
- new_img = malloc(sizeof(*img));
- if (new_img == NULL)
- return NULL;
+ imlib_context_set_image(image);
+ data = imlib_image_get_data_for_reading_only();
- imlib_context_set_image(img->image);
- image = imlib_clone_image();
+ for (j = 0; j < img->height; j++) {
+ offset = img->width * j;
+ for (i = 0; i < img->width; i++) {
+ a = (data[offset + i] >> 24) & 0x000000ff;
+ r = (data[offset + i] >> 16) & 0x000000ff;
+ g = (data[offset + i] >> 8) & 0x000000ff;
+ b = (data[offset + i]) & 0x000000ff;
- if (image == NULL) {
- free(new_img);
- return NULL;
+ if (a == 0)
+ fb_image_pset(img, i, j, bg_r, bg_g, bg_b);
+ else
+ fb_image_pset(img, i, j, r, g, b);
+ }
}
-
- new_img->image = image;
- set_prm(new_img);
- return new_img;
+ return;
}
-int
-fb_rotate_image(IMAGE * img, int angle)
+static Imlib_Image
+resize_image(Imlib_Image image, int width, int height)
{
- int orientation;
+ Imlib_Image resized_image;
+ int w, h;
- if (img == NULL)
- return 1;
+ if (image == NULL)
+ return NULL;
- imlib_context_set_image(img->image);
+ imlib_context_set_image(image);
+ w = imlib_image_get_width();
+ h = imlib_image_get_height();
- if (angle == 90) {
- orientation = 1;
- }
- else if (angle == -90) {
- orientation = 3;
- }
- else {
- return 1;
- }
+ if (width < 1 || height < 1)
+ return image;
- imlib_image_orientate(orientation);
- set_prm(img);
- return 0;
-}
+ if (w == width && h == height)
+ return image;
-static void
-set_prm(IMAGE * img)
-{
- if (img == NULL)
- return;
+ resized_image =
+ imlib_create_cropped_scaled_image(0, 0, w, h, width, height);
+
+ imlib_free_image();
- imlib_context_set_image(img->image);
- img->data = imlib_image_get_data_for_reading_only();
- img->width = imlib_image_get_width();
- img->height = imlib_image_get_height();
+ return resized_image;
}