commit 61ab30ba3d0f60c79076d4ae2c5ed5adfa7fbe05
parent 389eb8a47891ab0534e1bfe187b2d925267f6692
Author: ukai <ukai>
Date: Mon, 22 Jul 2002 16:17:32 +0000
[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:
15 files changed, 394 insertions(+), 326 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -1,3 +1,22 @@
+2002-07-23 Hiroyuki Ito <hito@crl.go.jp>
+
+ * [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()
+
2002-07-19 Hideyuki SHIRAI <shirai@rdmg.mgcs.mei.co.jp>
* [w3m-dev 03277] compile error on Solaris7
diff --git a/w3mimg/fb/fb.c b/w3mimg/fb/fb.c
@@ -1,6 +1,6 @@
/* $Id$ */
/**************************************************************************
- fb.c 0.2 Copyright (C) 2002, hito
+ fb.c 0.3 Copyright (C) 2002, hito
**************************************************************************/
#include <stdio.h>
@@ -21,6 +21,8 @@
#define FALSE 0
#define TRUE 1
+#define IMAGE_SIZE_MAX 10000
+
static struct fb_cmap *fb_cmap_create(struct fb_fix_screeninfo *,
struct fb_var_screeninfo *);
static void fb_cmap_destroy(struct fb_cmap *cmap);
@@ -34,6 +36,7 @@ static struct fb_var_screeninfo vscinfo;
static struct fb_cmap *cmap = NULL;
static int is_open = FALSE;
static int fbfp = -1;
+static size_t pixel_size = 0;
static unsigned char *buf = NULL;
int
@@ -75,51 +78,6 @@ fb_open(void)
goto ERR_END;
}
-#if 0
- if (fscinfo.visual == FB_VISUAL_PSEUDOCOLOR) {
- printf("FB_VISUAL_PSEUDOCOLOR\n");
- if (vscinfo.bits_per_pixel != 8) {
- fprintf(stderr, "未対応フレームバッファ\n");
- goto ERR_END;
- }
-
- if (fb_cmap_get(fbfp, cmap)) {
- fprintf(stderr, "カラーマップ獲得失敗\n");
- // fb_cmap_destroy(cmap);
- goto ERR_END;
- }
- // fb_cmap_disp(cmap);
-
- if (cmap->len < (LINUX_LOGO_COLORS + LOGO_COLOR_OFFSET)) {
- fprintf(stderr, "色の割付領域が不足しています\n");
- goto ERR_END;
- }
-
- cmap->start = LOGO_COLOR_OFFSET;
- cmap->len = LINUX_LOGO_COLORS;
-
- for (lp = 0; lp < LINUX_LOGO_COLORS; lp++) {
- if (cmap->red) {
- *(cmap->red + lp) =
- (linux_logo_red[lp] << CHAR_BIT) + linux_logo_red[lp];
- }
- if (cmap->green) {
- *(cmap->green + lp) =
- (linux_logo_green[lp] << CHAR_BIT) + linux_logo_green[lp];
- }
- if (cmap->blue) {
- *(cmap->blue + lp) =
- (linux_logo_blue[lp] << CHAR_BIT) + linux_logo_blue[lp];
- }
- }
- if (fb_cmap_set(fbfp, cmap)) {
- fb_cmap_destroy(cmap);
- fprintf(stderr, "カラーマップ獲得失敗\n");
- goto ERR_END;
- }
- }
-#endif
-
if (!(fscinfo.visual == FB_VISUAL_TRUECOLOR &&
(vscinfo.bits_per_pixel == 15 ||
vscinfo.bits_per_pixel == 16 ||
@@ -128,6 +86,8 @@ fb_open(void)
goto ERR_END;
}
+ pixel_size = (vscinfo.bits_per_pixel + 7) / CHAR_BIT;
+
is_open = TRUE;
return 0;
@@ -158,20 +118,150 @@ fb_close(void)
is_open = FALSE;
}
+FB_IMAGE *
+fb_image_new(int width, int height)
+{
+ FB_IMAGE *image;
+
+ if (is_open != TRUE)
+ return NULL;
+
+ if (width > IMAGE_SIZE_MAX || height > IMAGE_SIZE_MAX)
+ return NULL;
+
+ image = malloc(sizeof(*image));
+ if (image == NULL)
+ return NULL;
+
+ image->data = malloc(width * height * pixel_size);
+ if (image->data == NULL) {
+ free(image);
+ return NULL;
+ }
+
+ image->width = width;
+ image->height = height;
+ image->rowstride = width * pixel_size;
+ image->len = width * height * pixel_size;
+
+ return image;
+}
+
+void
+fb_image_free(FB_IMAGE * image)
+{
+ if (image == NULL)
+ return;
+
+ if (image->data != NULL)
+ free(image->data);
+
+ free(image);
+}
+
+void
+fb_image_pset(FB_IMAGE * image, int x, int y, int r, int g, int b)
+{
+ unsigned long work;
+ int offset;
+
+ if (image == NULL || is_open != TRUE || x >= image->width
+ || y >= image->height)
+ return;
+
+ offset = image->rowstride * y + pixel_size * x;
+
+ work = ((r >> (CHAR_BIT - vscinfo.red.length)) << vscinfo.red.
+ offset) +
+ ((g >> (CHAR_BIT - vscinfo.green.length)) << vscinfo.green.
+ offset) +
+ ((b >> (CHAR_BIT - vscinfo.blue.length)) << vscinfo.blue.offset);
+
+ memcpy(image->data + offset, &work, pixel_size);
+}
+
+int
+fb_image_draw(FB_IMAGE * image, int x, int y, int sx, int sy, int width,
+ int height)
+{
+ int i, offset_fb, offset_img;
+
+ if (image == NULL || is_open != TRUE ||
+ sx > image->width || sy > image->height ||
+ x > fb_width() || y > fb_height())
+ return 1;
+
+ if (x + width > fb_width())
+ width = fb_width() - x;
+
+ if (y + height > fb_height())
+ height = fb_height() - y;
+
+ offset_fb = fscinfo.line_length * y + pixel_size * x;
+ offset_img = image->rowstride * sy + pixel_size * sx;
+ for (i = 0; i < height; i++) {
+ memcpy(buf + offset_fb, image->data + offset_img, pixel_size * width);
+ offset_fb += fscinfo.line_length;
+ offset_img += image->rowstride;
+ }
+
+ return 0;
+}
+
+void
+fb_image_rotete(FB_IMAGE * image, int direction)
+{
+ unsigned char *src, *dest, *tmp;
+ int x, y, i, ofst;
+
+ if (image == NULL)
+ return;
+
+ tmp = malloc(image->len);
+ if (tmp == NULL)
+ return;
+
+ src = image->data;
+ dest = tmp;
+
+ if (direction) {
+ int ofst2 = image->rowstride * (image->height - 1);
+ for (x = 0; x < image->rowstride; x += pixel_size) {
+ ofst = ofst2 + x;
+ for (y = image->height - 1; y >= 0; y--) {
+ memcpy(dest, src + ofst, pixel_size);
+ dest += pixel_size;
+ ofst -= image->rowstride;
+ }
+ }
+ } else {
+ for (x = image->rowstride - pixel_size; x >= 0; x -= pixel_size) {
+ ofst = x;
+ for (y = 0; y < image->height; y++) {
+ memcpy(dest, src + ofst, pixel_size);
+ dest += pixel_size;
+ ofst += image->rowstride;
+ }
+ }
+ }
+ memcpy(src, tmp, image->len);
+ i = image->width;
+ image->width = image->height;
+ image->height = i;
+ image->rowstride = image->width * pixel_size;
+ free(tmp);
+}
+
void
fb_pset(int x, int y, int r, int g, int b)
{
unsigned long work;
int offset;
- static size_t size = 0;
if (is_open != TRUE || x >= vscinfo.xres || y >= vscinfo.yres)
return;
- if (size == 0)
- size = (vscinfo.bits_per_pixel + 7) / CHAR_BIT;
-
- offset = fscinfo.line_length * y + size * x;
+ offset = fscinfo.line_length * y + pixel_size * x;
if (offset >= fscinfo.smem_len)
return;
@@ -180,7 +270,7 @@ fb_pset(int x, int y, int r, int g, int b)
((r >> (CHAR_BIT - vscinfo.red.length)) << vscinfo.red.offset) +
((g >> (CHAR_BIT - vscinfo.green.length)) << vscinfo.green.offset) +
((b >> (CHAR_BIT - vscinfo.blue.length)) << vscinfo.blue.offset);
- memcpy(buf + offset, &work, size);
+ memcpy(buf + offset, &work, pixel_size);
}
int
@@ -188,19 +278,16 @@ fb_get_color(int x, int y, int *r, int *g, int *b)
{
unsigned long work = 0;
int offset;
- static size_t size = 0;
if (is_open != TRUE || x >= vscinfo.xres || y >= vscinfo.yres)
return 1;
- if (size == 0)
- size = (vscinfo.bits_per_pixel + 7) / CHAR_BIT;
+ offset = fscinfo.line_length * y + pixel_size * x;
- offset = fscinfo.line_length * y + size * x;
if (offset >= fscinfo.smem_len)
return 1;
- memcpy(&work, buf + offset, size);
+ memcpy(&work, buf + offset, pixel_size);
*r = ((work >> vscinfo.red.
offset) & (0x000000ff >> (CHAR_BIT - vscinfo.red.length)))
diff --git a/w3mimg/fb/fb.h b/w3mimg/fb/fb.h
@@ -3,15 +3,29 @@
#define fb_header
#include <linux/fb.h>
-int fb_open(void);
+typedef struct{
+ unsigned char *data;
+ int width;
+ int height;
+ int rowstride;
+ int len;
+} FB_IMAGE;
+
+FB_IMAGE *fb_image_new(int width, int height);
+void fb_image_pset(FB_IMAGE *image, int x, int y, int r, int g, int b);
+int fb_image_draw(FB_IMAGE *image, int x, int y, int sx, int sy, int width, int height);
+void fb_image_free(FB_IMAGE *image);
+void fb_image_rotete(FB_IMAGE *image, int direction);
+
+int fb_open(void);
void fb_close(void);
void fb_pset(int x, int y, int r, int g, int b);
+int fb_get_color(int x, int y, int *r, int *g, int *b);
void fb_clear(void);
int fb_width(void);
int fb_height(void);
void fb_cmap_disp(void);
void fb_fscrn_disp(void);
void fb_vscrn_disp(void);
-int fb_get_color(int x, int y, int *r, int *g, int *b);
#endif
diff --git a/w3mimg/fb/fb_gdkpixbuf.c b/w3mimg/fb/fb_gdkpixbuf.c
@@ -1,137 +1,123 @@
/* $Id$ */
/**************************************************************************
- 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;
}
diff --git a/w3mimg/fb/fb_gdkpixbuf.h b/w3mimg/fb/fb_gdkpixbuf.h
@@ -1,16 +0,0 @@
-/* $Id$ */
-#ifndef fb_gdkpixbuf_header
-#define fb_gdkpixbuf_header
-
-#include <gdk-pixbuf/gdk-pixbuf.h>
-
-typedef struct {
- int width;
- int height;
- int rowstride;
- int alpha;
- GdkPixbuf *pixbuf;
- guchar *pixels;
-} IMAGE;
-
-#endif
diff --git a/w3mimg/fb/fb_img.c b/w3mimg/fb/fb_img.c
@@ -18,13 +18,13 @@ static int bg_r = 0, bg_g = 0, bg_b = 0;
#endif
int
-fb_draw_image_simple(IMAGE * img, int x, int y)
+fb_image_draw_simple(FB_IMAGE * img, int x, int y)
{
- return fb_draw_image(img, x, y, 0, 0, img->width, img->height);
+ return fb_image_draw(img, x, y, 0, 0, img->width, img->height);
}
void
-fb_set_bg(int r, int g, int b)
+fb_image_set_bg(int r, int g, int b)
{
bg_r = r;
bg_g = g;
diff --git a/w3mimg/fb/fb_img.h b/w3mimg/fb/fb_img.h
@@ -1,24 +1,11 @@
/* $Id$ */
#ifndef fb_img_header
#define fb_img_header
-#include "config.h"
+#include "fb.h"
-#if defined(USE_IMLIB2)
-#include "w3mimg/fb/fb_imlib2.h"
-#elif defined(USE_GDKPIXBUF)
-#include "w3mimg/fb/fb_gdkpixbuf.h"
-#else
-#error no Imlib2 and GdkPixbuf support
-#endif
-
-IMAGE *fb_load_image(char *filename, int w, int h);
-int fb_draw_image(IMAGE * img, int x, int y, int sx, int sy, int width,
- int height);
-int fb_draw_image_simple(IMAGE * img, int x, int y);
-int fb_resize_image(IMAGE * img, int width, int height);
-void fb_free_image(IMAGE * img);
-void fb_set_bg(int r, int g, int b);
-IMAGE *fb_dup_image(IMAGE * img);
-int fb_rotate_image(IMAGE * img, int angle);
+FB_IMAGE *fb_image_load(char *filename, int w, int h);
+int fb_image_draw_simple(FB_IMAGE * img, int x, int y);
+void fb_image_set_bg(int r, int g, int b);
+int get_image_size(char *filename, int *w, int *h);
#endif
diff --git a/w3mimg/fb/fb_imlib2.c b/w3mimg/fb/fb_imlib2.c
@@ -1,162 +1,124 @@
/* $Id$ */
/**************************************************************************
- 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;
}
diff --git a/w3mimg/fb/fb_imlib2.h b/w3mimg/fb/fb_imlib2.h
@@ -1,15 +0,0 @@
-/* $Id$ */
-#ifndef fb_imlib2_header
-#define fb_imlib2_header
-
-#include <X11/Xlib.h>
-#include <Imlib2.h>
-
-typedef struct {
- int width;
- int height;
- Imlib_Image image;
- DATA32 *data;
-} IMAGE;
-
-#endif
diff --git a/w3mimg/fb/fb_w3mimg.c b/w3mimg/fb/fb_w3mimg.c
@@ -39,7 +39,7 @@ w3mfb_set_background(w3mimg_op *self, char *background)
if (background) {
int r, g, b;
if (sscanf(background, "#%02x%02x%02x", &r, &g, &b) == 3)
- fb_set_bg(r, g, b);
+ fb_image_set_bg(r, g, b);
}
}
@@ -58,11 +58,11 @@ w3mfb_close(w3mimg_op *self)
static int
w3mfb_load_image(w3mimg_op *self, W3MImage *img, char *fname, int w, int h)
{
- IMAGE *im;
+ FB_IMAGE *im;
if (self == NULL)
return 0;
- im = fb_load_image(fname, w, h);
+ im = fb_image_load(fname, w, h);
if (!im)
return 0;
img->pixmap = im;
@@ -79,7 +79,7 @@ w3mfb_show_image(w3mimg_op *self, W3MImage *img, int sx, int sy,
if (self == NULL)
return 0;
- fb_draw_image((IMAGE *)img->pixmap,
+ fb_image_draw((FB_IMAGE *)img->pixmap,
x + self->offset_x, y + self->offset_y,
sx, sy,
(sw ? sw : img->width),
@@ -93,13 +93,27 @@ w3mfb_free_image(w3mimg_op *self, W3MImage *img)
if (self == NULL)
return;
if (img && img->pixmap) {
- fb_free_image((IMAGE *)img->pixmap);
+ fb_image_free((FB_IMAGE *)img->pixmap);
img->pixmap = NULL;
img->width = 0;
img->height = 0;
}
}
+static int
+w3mfb_get_image_size(w3mimg_op *self, W3MImage *img,
+ char *fname, int *w, int *h)
+{
+ int i;
+
+ if (self == NULL)
+ return 0;
+ i = get_image_size(fname, w, h);
+ if (i)
+ return 0;
+ return 1;
+}
+
w3mimg_op *
w3mimg_fbopen()
{
@@ -125,6 +139,7 @@ w3mimg_fbopen()
wop->load_image = w3mfb_load_image;
wop->show_image = w3mfb_show_image;
wop->free_image = w3mfb_free_image;
+ wop->get_image_size = w3mfb_get_image_size;
return wop;
error:
diff --git a/w3mimg/fb/readme.txt b/w3mimg/fb/readme.txt
@@ -63,6 +63,10 @@ original readme.txt
・2002/07/07 ImageMagick 版動作確認
・2002/07/10 GdkPixbuf 版動作確認
・2002/07/11 Imlib2 版動作確認
+ ・2002/07/15 Version 0.1
+ 公開
+ ・2002/07/22 Version 0.2
+ 描画の高速化
■連絡先
ZXB01226@nifty.com
diff --git a/w3mimg/w3mimg.h b/w3mimg/w3mimg.h
@@ -29,6 +29,8 @@ typedef struct _w3mimg_op {
int (*show_image) (struct _w3mimg_op * self, W3MImage * img,
int sx, int sy, int sw, int sh, int x, int y);
void (*free_image) (struct _w3mimg_op * self, W3MImage * img);
+ int (*get_image_size) (struct _w3mimg_op * self, W3MImage * img,
+ char *fname, int *w, int *h);
} w3mimg_op;
#ifdef USE_W3MIMG_X11
diff --git a/w3mimg/x11/x11_w3mimg.c b/w3mimg/x11/x11_w3mimg.c
@@ -194,6 +194,27 @@ x11_free_image(w3mimg_op * self, W3MImage * img)
}
}
+static int
+x11_get_image_size(w3mimg_op * self, W3MImage * img, char *fname, int *w, int *h)
+{
+ struct x11_info *xi;
+ ImlibImage *im;
+
+ if (self == NULL)
+ return 0;
+ xi = (struct x11_info *)self->priv;
+ if (xi == NULL)
+ return 0;
+
+ im = Imlib_load_image(xi->id, fname);
+ if (!im)
+ return 0;
+
+ *w = im->rgb_width;
+ *h = im->rgb_height;
+ Imlib_kill_image(xi->id, im);
+ return 1;
+}
/* *INDENT-OFF* */
/*
@@ -319,6 +340,7 @@ w3mimg_x11open()
wop->load_image = x11_load_image;
wop->show_image = x11_show_image;
wop->free_image = x11_free_image;
+ wop->get_image_size = x11_get_image_size;
return wop;
error:
diff --git a/w3mimgdisplay.c b/w3mimgdisplay.c
@@ -99,10 +99,10 @@ main(int argc, char **argv)
case '5':
if (w_op->init(w_op)) {
W3MImage img;
- if (w_op->load_image(w_op, &img, &buf[2], 0, 0)) {
- fprintf(stdout, "%d %d\n", img.width, img.height);
+ int w, h;
+ if (w_op->get_image_size(w_op, &img, &buf[2], &w, &h)) {
+ fprintf(stdout, "%d %d\n", w, h);
fflush(stdout);
- w_op->free_image(w_op, &img);
}
}
break;
diff --git a/w3mimgsize.c b/w3mimgsize.c
@@ -10,6 +10,7 @@ main(int argc, char **argv)
{
w3mimg_op *w_op = NULL;
W3MImage img;
+ int w, h;
fclose(stderr);
if (argc < 2)
@@ -21,8 +22,8 @@ main(int argc, char **argv)
if (!w_op->init(w_op))
exit(1);
- if (!w_op->load_image(w_op, &img, argv[1], -1, -1))
+ if (!w_op->get_image_size(w_op, &img, argv[1], &w, &h))
exit(1);
- printf("%d %d\n", img.width, img.height);
+ printf("%d %d\n", w, h);
exit(0);
}