From 72f72d64a422d6628c4796f5c0bf2e508f134214 Mon Sep 17 00:00:00 2001 From: Tatsuya Kinoshita Date: Wed, 4 May 2011 16:05:14 +0900 Subject: Adding upstream version 0.5.1 --- w3mimg/fb/.cvsignore | 1 + w3mimg/fb/Makefile.in | 35 +++ w3mimg/fb/fb.c | 663 +++++++++++++++++++++++++++++++++++++++++++++++ w3mimg/fb/fb.h | 34 +++ w3mimg/fb/fb_gdkpixbuf.c | 209 +++++++++++++++ w3mimg/fb/fb_img.c | 32 +++ w3mimg/fb/fb_img.h | 11 + w3mimg/fb/fb_imlib2.c | 126 +++++++++ w3mimg/fb/fb_w3mimg.c | 202 +++++++++++++++ w3mimg/fb/readme.txt | 73 ++++++ 10 files changed, 1386 insertions(+) create mode 100644 w3mimg/fb/.cvsignore create mode 100644 w3mimg/fb/Makefile.in create mode 100644 w3mimg/fb/fb.c create mode 100644 w3mimg/fb/fb.h create mode 100644 w3mimg/fb/fb_gdkpixbuf.c create mode 100644 w3mimg/fb/fb_img.c create mode 100644 w3mimg/fb/fb_img.h create mode 100644 w3mimg/fb/fb_imlib2.c create mode 100644 w3mimg/fb/fb_w3mimg.c create mode 100644 w3mimg/fb/readme.txt (limited to 'w3mimg/fb') diff --git a/w3mimg/fb/.cvsignore b/w3mimg/fb/.cvsignore new file mode 100644 index 0000000..f3c7a7c --- /dev/null +++ b/w3mimg/fb/.cvsignore @@ -0,0 +1 @@ +Makefile diff --git a/w3mimg/fb/Makefile.in b/w3mimg/fb/Makefile.in new file mode 100644 index 0000000..d3ee2e1 --- /dev/null +++ b/w3mimg/fb/Makefile.in @@ -0,0 +1,35 @@ +# +# w3mimg/fb/Makefile +# +# +@SET_MAKE@ +SHELL=@SHELL@ +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = $(srcdir):. +CFLAGS=$(OPTS) -I../.. -I$(top_srcdir) -I$(srcdir) @CFLAGS@ @CPPFLAGS@ @DEFS@ $(IMGCFLAGS) +RM=rm + +IMGCFLAGS=@IMGFBCFLAGS@ +OBJS=fb.o fb_img.o + +all: fb_w3mimg.o fb.o fb_img.o + +fb_w3mimg.o: fb_w3mimg.c + $(CC) $(CFLAGS) -c $< + +fb.o: fb.c + $(CC) $(CFLAGS) -c $< + +fb_img.o: fb_img.c fb_gdkpixbuf.c fb_imlib2.c + $(CC) $(CFLAGS) -c $< + +clean: + @-$(RM) -f *.o + +distclean: clean + -$(RM) -f Makefile + +# + + diff --git a/w3mimg/fb/fb.c b/w3mimg/fb/fb.c new file mode 100644 index 0000000..cd11128 --- /dev/null +++ b/w3mimg/fb/fb.c @@ -0,0 +1,663 @@ +/* $Id: fb.c,v 1.16 2003/07/13 16:19:10 ukai Exp $ */ +/************************************************************************** + fb.c 0.3 Copyright (C) 2002, hito + **************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "fb.h" + +#define FB_ENV "FRAMEBUFFER" +#define FB_DEFDEV "/dev/fb0" + +#define MONO_OFFSET_8BIT 0x40 +#define COLORS_MONO_8BIT 0x40 +#define MONO_MASK_8BIT 0xFC +#define MONO_SHIFT_8BIT 2 + +#define COLOR_OFFSET_8BIT 0x80 +#define COLORS_8BIT 0x80 +#define RED_MASK_8BIT 0xC0 +#define GREEN_MASK_8BIT 0xE0 +#define BLUE_MASK_8BIT 0xC0 +#define RED_SHIFT_8BIT 1 +#define GREEN_SHIFT_8BIT 3 +#define BLUE_SHIFT_8BIT 6 + +#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); +static int fb_fscrn_get(int fbfp, struct fb_fix_screeninfo *scinfo); +static void *fb_mmap(int fbfp, struct fb_fix_screeninfo *scinfo); +static int fb_munmap(void *buf, struct fb_fix_screeninfo *scinfo); +static int fb_vscrn_get(int fbfp, struct fb_var_screeninfo *scinfo); +static int fb_cmap_set(int fbfp, struct fb_cmap *cmap); +static int fb_cmap_get(int fbfp, struct fb_cmap *cmap); +static int fb_cmap_init(void); +static int fb_get_cmap_index(int r, int g, int b); +static unsigned long fb_get_packed_color(int r, int g, int b); + +static struct fb_fix_screeninfo fscinfo; +static struct fb_var_screeninfo vscinfo; +static struct fb_cmap *cmap = NULL, *cmap_org = NULL; +static int is_open = FALSE; +static int fbfp = -1; +static size_t pixel_size = 0; +static unsigned char *buf = NULL; + +int +fb_open(void) +{ + char *fbdev = { FB_DEFDEV }; + + if (is_open == TRUE) + return 1; + + if (getenv(FB_ENV)) { + fbdev = getenv(FB_ENV); + } + + if ((fbfp = open(fbdev, O_RDWR)) == -1) { + fprintf(stderr, "open %s error\n", fbdev); + goto ERR_END; + } + + if (fb_fscrn_get(fbfp, &fscinfo)) { + goto ERR_END; + } + + if (fb_vscrn_get(fbfp, &vscinfo)) { + goto ERR_END; + } + + if ((cmap = fb_cmap_create(&fscinfo, &vscinfo)) == (struct fb_cmap *)-1) { + goto ERR_END; + } + + if (!(buf = fb_mmap(fbfp, &fscinfo))) { + fprintf(stderr, "Can't allocate memory.\n"); + goto ERR_END; + } + + if (fscinfo.type != FB_TYPE_PACKED_PIXELS) { + fprintf(stderr, "This type of framebuffer is not supported.\n"); + goto ERR_END; + } + + if (fscinfo.visual == FB_VISUAL_PSEUDOCOLOR && vscinfo.bits_per_pixel == 8) { + if (fb_cmap_get(fbfp, cmap)) { + fprintf(stderr, "Can't get color map.\n"); + fb_cmap_destroy(cmap); + cmap = NULL; + goto ERR_END; + } + + if (fb_cmap_init()) + goto ERR_END; + + pixel_size = 1; + } + else if ((fscinfo.visual == FB_VISUAL_TRUECOLOR || + fscinfo.visual == FB_VISUAL_DIRECTCOLOR) && + (vscinfo.bits_per_pixel == 15 || + vscinfo.bits_per_pixel == 16 || + vscinfo.bits_per_pixel == 24 || vscinfo.bits_per_pixel == 32)) { + pixel_size = (vscinfo.bits_per_pixel + 7) / CHAR_BIT; + } + else { + fprintf(stderr, "This type of framebuffer is not supported.\n"); + goto ERR_END; + } + + is_open = TRUE; + return 0; + + ERR_END: + fb_close(); + return 1; +} + +void +fb_close(void) +{ + if (is_open != TRUE) + return; + + if (cmap != NULL) { + fb_cmap_destroy(cmap); + cmap = NULL; + } + if (cmap_org != NULL) { + fb_cmap_set(fbfp, cmap_org); + fb_cmap_destroy(cmap_org); + cmap = NULL; + } + if (buf != NULL) { + fb_munmap(buf, &fscinfo); + buf = NULL; + } + + if (fbfp >= 0) { + close(fbfp); + } + + is_open = FALSE; +} + +/*********** fb_image_* ***********/ + +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 || width < 1 + || height < 1) + return NULL; + + image = malloc(sizeof(*image)); + if (image == NULL) + return NULL; + + image->data = calloc(sizeof(*(image->data)), width * height * pixel_size); + if (image->data == NULL) { + free(image); + return NULL; + } + + image->num = 1; + image->id = 0; + image->delay = 0; + + 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; + + if (image == NULL || is_open != TRUE || x >= image->width + || y >= image->height) + return; + + work = fb_get_packed_color(r, g, b); + memcpy(image->data + image->rowstride * y + pixel_size * x, &work, + pixel_size); +} + +void +fb_image_fill(FB_IMAGE * image, int r, int g, int b) +{ + unsigned long work; + int offset; + + if (image == NULL || is_open != TRUE) + return; + + work = fb_get_packed_color(r, g, b); + + for (offset = 0; offset < image->len; offset += pixel_size) { + 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 (sx + width > image->width) + width = image->width - sx; + + if (sy + height > image->height) + height = image->height - sy; + + 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_copy(FB_IMAGE * dest, FB_IMAGE * src) +{ + if (dest == NULL || src == NULL) + return; + + if (dest->len != src->len) + return; + + memcpy(dest->data, src->data, src->len); +} + +/*********** fb_frame_* ***********/ + +FB_IMAGE ** +fb_frame_new(int w, int h, int n) +{ + FB_IMAGE **frame; + int i, error = 0; + + if (w > IMAGE_SIZE_MAX || h > IMAGE_SIZE_MAX || w < 1 || h < 1 || n < 1) + return NULL; + + frame = malloc(sizeof(*frame) * n); + if (frame == NULL) + return NULL; + + for (i = 0; i < n; i++) { + frame[i] = fb_image_new(w, h); + frame[i]->num = n; + frame[i]->id = i; + frame[i]->delay = 1000; + if (frame[i] == NULL) + error = 1; + } + + if (error) { + fb_frame_free(frame); + return NULL; + } + + return frame; +} + + +void +fb_frame_free(FB_IMAGE ** frame) +{ + int i, n; + + if (frame == NULL) + return; + + n = frame[0]->num; + for (i = 0; i < n; i++) { + fb_image_free(frame[i]); + } + free(frame); +} + +int +fb_width(void) +{ + if (is_open != TRUE) + return 0; + + return vscinfo.xres; +} + +int +fb_height(void) +{ + if (is_open != TRUE) + return 0; + + return vscinfo.yres; +} + +int +fb_clear(int x, int y, int w, int h, int r, int g, int b) +{ + int i, offset_fb; + static int rr = -1, gg = -1, bb = -1; + static char *tmp = NULL; + + if (is_open != TRUE || x > fb_width() || y > fb_height()) + return 1; + + if (x < 0) + x = 0; + if (y < 0) + y = 0; + + if (x + w > fb_width()) + w = fb_width() - x; + if (y + h > fb_height()) + h = fb_height() - y; + + if (tmp == NULL) { + tmp = malloc(fscinfo.line_length); + if (tmp == NULL) + return 1; + } + if (rr != r || gg != g || bb != b) { + unsigned long work; + int ww = fb_width(); + + work = fb_get_packed_color(r, g, b); + for (i = 0; i < ww; i++) + memcpy(tmp + pixel_size * i, &work, pixel_size); + rr = r; + gg = g; + bb = b; + } + offset_fb = fscinfo.line_length * y + pixel_size * x; + for (i = 0; i < h; i++) { + memcpy(buf + offset_fb, tmp, pixel_size * w); + offset_fb += fscinfo.line_length; + } + return 0; +} + +/********* static functions **************/ +static unsigned long +fb_get_packed_color(int r, int g, int b) +{ + if (pixel_size == 1) { + return fb_get_cmap_index(r, g, b); + } + else { + return + ((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); + } +} + +static int +fb_get_cmap_index(int r, int g, int b) +{ + int work; + if ((r & GREEN_MASK_8BIT) == (g & GREEN_MASK_8BIT) + && (g & GREEN_MASK_8BIT) == (b & GREEN_MASK_8BIT)) { + work = (r >> MONO_SHIFT_8BIT) + MONO_OFFSET_8BIT; + } + else { + work = ((r & RED_MASK_8BIT) >> RED_SHIFT_8BIT) + + ((g & GREEN_MASK_8BIT) >> GREEN_SHIFT_8BIT) + + ((b & BLUE_MASK_8BIT) >> BLUE_SHIFT_8BIT) + + COLOR_OFFSET_8BIT; + } + return work; +} + +static int +fb_cmap_init(void) +{ + int lp; + + if (cmap == NULL) + return 1; + + if (cmap->len < COLOR_OFFSET_8BIT + COLORS_8BIT) { + fprintf(stderr, "Can't allocate enough color.\n"); + return 1; + } + + if (cmap_org == NULL) { + if ((cmap_org = + fb_cmap_create(&fscinfo, &vscinfo)) == (struct fb_cmap *)-1) { + return 1; + } + + if (fb_cmap_get(fbfp, cmap_org)) { + fprintf(stderr, "Can't get color map.\n"); + fb_cmap_destroy(cmap_org); + cmap_org = NULL; + return 1; + } + } + + cmap->start = MONO_OFFSET_8BIT; + cmap->len = COLORS_8BIT + COLORS_MONO_8BIT; + + for (lp = 0; lp < COLORS_MONO_8BIT; lp++) { + int c; + c = (lp << (MONO_SHIFT_8BIT + 8)) + + (lp ? (0xFFFF - (MONO_MASK_8BIT << 8)) : 0); + if (cmap->red) + *(cmap->red + lp) = c; + if (cmap->green) + *(cmap->green + lp) = c; + if (cmap->blue) + *(cmap->blue + lp) = c; + } + + for (lp = 0; lp < COLORS_8BIT; lp++) { + int r, g, b; + r = lp & (RED_MASK_8BIT >> RED_SHIFT_8BIT); + g = lp & (GREEN_MASK_8BIT >> GREEN_SHIFT_8BIT); + b = lp & (BLUE_MASK_8BIT >> BLUE_SHIFT_8BIT); + if (cmap->red) + *(cmap->red + lp + COLORS_MONO_8BIT) + = (r << (RED_SHIFT_8BIT + 8)) + + (r ? (0xFFFF - (RED_MASK_8BIT << 8)) : 0); + if (cmap->green) + *(cmap->green + lp + COLORS_MONO_8BIT) + = (g << (GREEN_SHIFT_8BIT + 8)) + + (g ? (0xFFFF - (GREEN_MASK_8BIT << 8)) : 0); + if (cmap->blue) + *(cmap->blue + lp + COLORS_MONO_8BIT) + = (b << (BLUE_SHIFT_8BIT + 8)) + + (b ? (0xFFFF - (BLUE_MASK_8BIT << 8)) : 0); + } + + if (fb_cmap_set(fbfp, cmap)) { + fb_cmap_destroy(cmap); + cmap = NULL; + fprintf(stderr, "Can't set color map.\n"); + return 1; + } + return 0; +} + +/* + * (struct fb_cmap) Device independent colormap information. + * + * fb_cmap_create() create colormap information + * fb_cmap_destroy() destroy colormap information + * fb_cmap_get() get information + * fb_cmap_set() set information + */ + +#define LUT_MAX (256) + +static struct fb_cmap * +fb_cmap_create(struct fb_fix_screeninfo *fscinfo, + struct fb_var_screeninfo *vscinfo) +{ + struct fb_cmap *cmap; + int cmaplen = LUT_MAX; + + /* check the existence of colormap */ + if (fscinfo->visual == FB_VISUAL_MONO01 || + fscinfo->visual == FB_VISUAL_MONO10 || + fscinfo->visual == FB_VISUAL_TRUECOLOR) + return NULL; + + cmap = (struct fb_cmap *)malloc(sizeof(struct fb_cmap)); + if (!cmap) { + perror("cmap malloc error\n"); + return (struct fb_cmap *)-1; + } + memset(cmap, 0, sizeof(struct fb_cmap)); + + /* Allocates memory for a colormap */ + if (vscinfo->red.length) { + cmap->red = (__u16 *) malloc(sizeof(__u16) * cmaplen); + if (!cmap->red) { + perror("red lut malloc error\n"); + return (struct fb_cmap *)-1; + } + } + if (vscinfo->green.length) { + cmap->green = (__u16 *) malloc(sizeof(__u16) * cmaplen); + if (!cmap->green) { + if (vscinfo->red.length) + free(cmap->red); + perror("green lut malloc error\n"); + return (struct fb_cmap *)-1; + } + } + if (vscinfo->blue.length) { + cmap->blue = (__u16 *) malloc(sizeof(__u16) * cmaplen); + if (!cmap->blue) { + if (vscinfo->red.length) + free(cmap->red); + if (vscinfo->green.length) + free(cmap->green); + perror("blue lut malloc error\n"); + return (struct fb_cmap *)-1; + } + } + if (vscinfo->transp.length) { + cmap->transp = (__u16 *) malloc(sizeof(__u16) * cmaplen); + if (!cmap->transp) { + if (vscinfo->red.length) + free(cmap->red); + if (vscinfo->green.length) + free(cmap->green); + if (vscinfo->blue.length) + free(cmap->blue); + perror("transp lut malloc error\n"); + return (struct fb_cmap *)-1; + } + } + cmap->len = cmaplen; + return cmap; +} + +static void +fb_cmap_destroy(struct fb_cmap *cmap) +{ + if (cmap->red) + free(cmap->red); + if (cmap->green) + free(cmap->green); + if (cmap->blue) + free(cmap->blue); + if (cmap->transp) + free(cmap->transp); + free(cmap); +} + +static int +fb_cmap_get(int fbfp, struct fb_cmap *cmap) +{ + if (ioctl(fbfp, FBIOGETCMAP, cmap)) { + perror("ioctl FBIOGETCMAP error\n"); + return -1; + } + return 0; +} + +static int +fb_cmap_set(int fbfp, struct fb_cmap *cmap) +{ + if (ioctl(fbfp, FBIOPUTCMAP, cmap)) { + perror("ioctl FBIOPUTCMAP error\n"); + return -1; + } + return 0; +} + +/* + * access to framebuffer + * + * fb_mmap() map from framebuffer into memory + * fb_munmap() deletes the mappings + */ + +static void * +fb_mmap(int fbfp, struct fb_fix_screeninfo *scinfo) +{ + void *buf; + if ((buf = (unsigned char *) + mmap(NULL, scinfo->smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fbfp, + (off_t) 0)) + == MAP_FAILED) { + perror("mmap error"); + return NULL; + } + return buf; +} + +static int +fb_munmap(void *buf, struct fb_fix_screeninfo *scinfo) +{ + return munmap(buf, scinfo->smem_len); +} + +/* + * (struct fb_fix_screeninfo) device independent fixed information + * + * fb_fscrn_get() get information + */ +static int +fb_fscrn_get(int fbfp, struct fb_fix_screeninfo *scinfo) +{ + if (ioctl(fbfp, FBIOGET_FSCREENINFO, scinfo)) { + perror("ioctl FBIOGET_FSCREENINFO error\n"); + return -1; + } + return 0; +} + +/* + * (struct fb_var_screeninfo) device independent variable information + * + * fb_vscrn_get() get information + */ +static int +fb_vscrn_get(int fbfp, struct fb_var_screeninfo *scinfo) +{ + if (ioctl(fbfp, FBIOGET_VSCREENINFO, scinfo)) { + perror("ioctl FBIOGET_VSCREENINFO error\n"); + return -1; + } + return 0; +} diff --git a/w3mimg/fb/fb.h b/w3mimg/fb/fb.h new file mode 100644 index 0000000..1138bb0 --- /dev/null +++ b/w3mimg/fb/fb.h @@ -0,0 +1,34 @@ +/* $Id: fb.h,v 1.7 2003/07/07 15:48:17 ukai Exp $ */ +#ifndef fb_header +#define fb_header +#include + +typedef struct { + int num; + int id; + int delay; + int width; + int height; + int rowstride; + int len; + unsigned char *data; +} 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); +void fb_image_fill(FB_IMAGE * image, 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_copy(FB_IMAGE * dest, FB_IMAGE * src); + +FB_IMAGE **fb_frame_new(int w, int h, int num); +void fb_frame_free(FB_IMAGE ** frame); + +int fb_open(void); +void fb_close(void); +int fb_width(void); +int fb_height(void); +int fb_clear(int x, int y, int w, int h, int r, int g, int b); + +#endif diff --git a/w3mimg/fb/fb_gdkpixbuf.c b/w3mimg/fb/fb_gdkpixbuf.c new file mode 100644 index 0000000..e615da6 --- /dev/null +++ b/w3mimg/fb/fb_gdkpixbuf.c @@ -0,0 +1,209 @@ +/* $Id: fb_gdkpixbuf.c,v 1.16 2003/06/13 15:03:35 ukai Exp $ */ +/************************************************************************** + fb_gdkpixbuf.c 0.3 Copyright (C) 2002, hito + **************************************************************************/ + +#include +#include "fb.h" +#include "fb_img.h" + +static void draw(FB_IMAGE * img, int bg, int x, int y, int w, int h, + GdkPixbuf * pixbuf); +static GdkPixbuf *resize_image(GdkPixbuf * pixbuf, int width, int height); + +static void +get_animation_size(GdkPixbufAnimation * animation, int *w, int *h, int *delay) +{ + GList *frames; + int iw, ih, n, i, d = -1; + + frames = gdk_pixbuf_animation_get_frames(animation); + n = gdk_pixbuf_animation_get_num_frames(animation); + *w = gdk_pixbuf_animation_get_width(animation); + *h = gdk_pixbuf_animation_get_height(animation); + for (i = 0; i < n; i++) { + GdkPixbufFrame *frame; + GdkPixbuf *pixbuf; + int tmp; + + frame = (GdkPixbufFrame *) g_list_nth_data(frames, i); + tmp = gdk_pixbuf_frame_get_delay_time(frame); + if (tmp > d) + d = tmp; + pixbuf = gdk_pixbuf_frame_get_pixbuf(frame); + iw = gdk_pixbuf_frame_get_x_offset(frame) + + gdk_pixbuf_get_width(pixbuf); + ih = gdk_pixbuf_frame_get_y_offset(frame) + + gdk_pixbuf_get_height(pixbuf); + if (iw > *w) + *w = iw; + if (ih > *h) + *h = ih; + } + if (delay) + *delay = d; +} + +int +get_image_size(char *filename, int *w, int *h) +{ + GdkPixbufAnimation *animation; + if (filename == NULL) + return 1; + animation = gdk_pixbuf_animation_new_from_file(filename); + if (animation == NULL) + return 1; + get_animation_size(animation, w, h, NULL); + gdk_pixbuf_animation_unref(animation); + return 0; +} + +FB_IMAGE ** +fb_image_load(char *filename, int w, int h, int max_anim) +{ + GdkPixbufAnimation *animation; + GList *frames; + double ratio_w, ratio_h; + int n, i, j, fw, fh, frame_num, delay; + FB_IMAGE **fb_frame = NULL, *tmp_image = NULL; + + if (filename == NULL) + return NULL; + animation = gdk_pixbuf_animation_new_from_file(filename); + 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); + if (delay <= 0) + max_anim = -1; + if (max_anim < 0) { + frame_num = (-max_anim > n) ? n : -max_anim; + } + else if (max_anim > 0) { + frame_num = n = (max_anim > n) ? n : max_anim; + } + if (w < 1 || h < 1) { + w = fw; + h = fh; + ratio_w = ratio_h = 1; + } + else { + ratio_w = 1.0 * w / fw; + ratio_h = 1.0 * h / fh; + } + + fb_frame = fb_frame_new(w, h, frame_num); + if (fb_frame == NULL) + goto END; + + tmp_image = fb_image_new(w, h); + if (tmp_image == NULL) { + fb_frame_free(fb_frame); + fb_frame = NULL; + goto END; + } + + if (bg_r != 0 || bg_g != 0 || bg_b != 0) { + fb_image_fill(tmp_image, bg_r, bg_g, bg_b); + } + + for (j = 0; j < n; j++) { + GdkPixbufFrame *frame; + GdkPixbuf *org_pixbuf, *pixbuf; + int width, height, ofstx, ofsty; + + if (max_anim < 0) { + i = (j - n + frame_num > 0) ? (j - n + frame_num) : 0; + } + else { + i = j; + } + frame = (GdkPixbufFrame *) g_list_nth_data(frames, j); + org_pixbuf = gdk_pixbuf_frame_get_pixbuf(frame); + ofstx = gdk_pixbuf_frame_get_x_offset(frame); + ofsty = gdk_pixbuf_frame_get_y_offset(frame); + width = gdk_pixbuf_get_width(org_pixbuf); + height = gdk_pixbuf_get_height(org_pixbuf); + if (ofstx == 0 && ofsty == 0 && width == fw && height == fh) { + pixbuf = resize_image(org_pixbuf, w, h); + } + else { + pixbuf = + resize_image(org_pixbuf, width * ratio_w, height * ratio_h); + ofstx *= ratio_w; + ofsty *= ratio_h; + } + width = gdk_pixbuf_get_width(pixbuf); + height = gdk_pixbuf_get_height(pixbuf); + + 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); + + 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: + break; + case GDK_PIXBUF_FRAME_REVERT: + fb_image_copy(tmp_image, fb_frame[0]); + break; + default: + fb_image_copy(tmp_image, fb_frame[0]); + } + + if (org_pixbuf != pixbuf) + gdk_pixbuf_finalize(pixbuf); + } + END: + if (tmp_image) + fb_image_free(tmp_image); + gdk_pixbuf_animation_unref(animation); + return fb_frame; +} +static void +draw(FB_IMAGE * img, int bg, int x, int y, int w, int h, GdkPixbuf * pixbuf) +{ + int i, j, r, g, b, offset, bpp, rowstride; + guchar *pixels; + gboolean alpha; + if (img == NULL || pixbuf == NULL) + return; + rowstride = gdk_pixbuf_get_rowstride(pixbuf); + pixels = gdk_pixbuf_get_pixels(pixbuf); + alpha = gdk_pixbuf_get_has_alpha(pixbuf); + bpp = rowstride / w; + for (j = 0; j < h; j++) { + offset = j * rowstride; + for (i = 0; i < w; 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 + x, j + y, r, g, b); + } + } + } + return; +} +static GdkPixbuf * +resize_image(GdkPixbuf * pixbuf, int width, int height) +{ + GdkPixbuf *resized_pixbuf; + int w, h; + if (pixbuf == NULL) + return NULL; + w = gdk_pixbuf_get_width(pixbuf); + h = gdk_pixbuf_get_height(pixbuf); + if (width < 1 || height < 1) + return pixbuf; + if (w == width && h == height) + return pixbuf; + resized_pixbuf = + gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_HYPER); + if (resized_pixbuf == NULL) + return NULL; + return resized_pixbuf; +} diff --git a/w3mimg/fb/fb_img.c b/w3mimg/fb/fb_img.c new file mode 100644 index 0000000..3547a00 --- /dev/null +++ b/w3mimg/fb/fb_img.c @@ -0,0 +1,32 @@ +/* $Id: fb_img.c,v 1.6 2003/07/07 15:48:17 ukai Exp $ */ +#include +#include +#include +#include +#include "config.h" +#include "fb.h" +#include "fb_img.h" + +static int bg_r = 0, bg_g = 0, bg_b = 0; + +#if defined(USE_IMLIB2) +#include "w3mimg/fb/fb_imlib2.c" +#elif defined(USE_GDKPIXBUF) +#include "w3mimg/fb/fb_gdkpixbuf.c" +#else +#error no Imlib2 and GdkPixbuf support +#endif + +void +fb_image_set_bg(int r, int g, int b) +{ + bg_r = r; + bg_g = g; + bg_b = b; +} + +int +fb_image_clear(int x, int y, int w, int h) +{ + return fb_clear(x, y, w, h, bg_r, bg_g, bg_b); +} diff --git a/w3mimg/fb/fb_img.h b/w3mimg/fb/fb_img.h new file mode 100644 index 0000000..cd1301b --- /dev/null +++ b/w3mimg/fb/fb_img.h @@ -0,0 +1,11 @@ +/* $Id: fb_img.h,v 1.8 2003/07/09 15:07:11 ukai Exp $ */ +#ifndef fb_img_header +#define fb_img_header +#include "fb.h" + +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); +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 new file mode 100644 index 0000000..972f06e --- /dev/null +++ b/w3mimg/fb/fb_imlib2.c @@ -0,0 +1,126 @@ +/* $Id: fb_imlib2.c,v 1.9 2003/03/24 15:45:59 ukai Exp $ */ +/************************************************************************** + fb_imlib2.c 0.3 Copyright (C) 2002, hito + **************************************************************************/ + +#include +#include +#include "fb.h" +#include "fb_img.h" + +static void draw(FB_IMAGE * img, Imlib_Image image); +static Imlib_Image resize_image(Imlib_Image image, int width, int height); + +int +get_image_size(char *filename, int *w, int *h) +{ + Imlib_Image image; + + if (filename == NULL) + return 1; + + image = imlib_load_image(filename); + if (image == NULL) + return 1; + + imlib_context_set_image(image); + *w = imlib_image_get_width(); + *h = imlib_image_get_height(); + imlib_free_image(); + + return 0; +} + +FB_IMAGE ** +fb_image_load(char *filename, int w, int h, int n) +{ + Imlib_Image image; + FB_IMAGE **frame; + + if (filename == NULL) + return NULL; + + image = imlib_load_image(filename); + if (image == NULL) + return NULL; + + image = resize_image(image, w, h); + if (image == NULL) + return NULL; + + imlib_context_set_image(image); + + w = imlib_image_get_width(); + h = imlib_image_get_height(); + + frame = fb_frame_new(w, h, 1); + + if (frame == NULL) { + imlib_free_image(); + return NULL; + } + + draw(frame[0], image); + + imlib_free_image(); + + return frame; +} + +static void +draw(FB_IMAGE * img, Imlib_Image image) +{ + int i, j, r, g, b, a = 0, offset; + DATA32 *data; + + if (img == NULL) + return; + + imlib_context_set_image(image); + data = imlib_image_get_data_for_reading_only(); + + 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 (a == 0) { + fb_image_pset(img, i, j, bg_r, bg_g, bg_b); + } + else { + fb_image_pset(img, i, j, r, g, b); + } + } + } + return; +} + +static Imlib_Image +resize_image(Imlib_Image image, int width, int height) +{ + Imlib_Image resized_image; + int w, h; + + if (image == NULL) + return NULL; + + imlib_context_set_image(image); + w = imlib_image_get_width(); + h = imlib_image_get_height(); + + if (width < 1 || height < 1) + return image; + + if (w == width && h == height) + return image; + + resized_image = + imlib_create_cropped_scaled_image(0, 0, w, h, width, height); + + imlib_free_image(); + + return resized_image; +} diff --git a/w3mimg/fb/fb_w3mimg.c b/w3mimg/fb/fb_w3mimg.c new file mode 100644 index 0000000..b67bad1 --- /dev/null +++ b/w3mimg/fb/fb_w3mimg.c @@ -0,0 +1,202 @@ +/* $Id: fb_w3mimg.c,v 1.13 2003/08/29 15:06:52 ukai Exp $ */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "w3mimg/fb/fb.h" +#include "w3mimg/fb/fb_img.h" +#include "w3mimg/w3mimg.h" + +static int +w3mfb_init(w3mimg_op * self) +{ + if (self == NULL) + return 0; + return 1; +} + +static int +w3mfb_finish(w3mimg_op * self) +{ + if (self == NULL) + return 0; + return 1; +} + +static int +w3mfb_active(w3mimg_op * self) +{ + if (self == NULL) + return 0; + return 1; +} + +static void +w3mfb_set_background(w3mimg_op * self, char *background) +{ + if (self == NULL) + return; + if (background) { + int r, g, b; + if (sscanf(background, "#%02x%02x%02x", &r, &g, &b) == 3) + fb_image_set_bg(r, g, b); + } +} + +static void +w3mfb_sync(w3mimg_op * self) +{ + return; +} + +static void +w3mfb_close(w3mimg_op * self) +{ + fb_close(); +} + +static int +w3mfb_clear(w3mimg_op * self, int x, int y, int w, int h) +{ + if (self == NULL) + return 0; + fb_image_clear(x, y, w, h); + return 1; +} + +static int +w3mfb_load_image(w3mimg_op * self, W3MImage * img, char *fname, int w, int h) +{ + FB_IMAGE **im; + + if (self == NULL) + return 0; + im = fb_image_load(fname, w, h, self->max_anim); + if (!im) + return 0; + img->pixmap = im; + img->width = im[0]->width; + img->height = im[0]->height; + return 1; +} + +static int +w3mfb_show_image(w3mimg_op * self, W3MImage * img, int sx, int sy, + int sw, int sh, int x, int y) +{ + int i; + FB_IMAGE **frame; +#define WAIT_CNT 4 + + if (self == NULL) + return 0; + + if (img->pixmap == NULL) + return 0; + + frame = (FB_IMAGE **) img->pixmap; + i = frame[0]->id; + fb_image_draw(frame[i], + x + self->offset_x, y + self->offset_y, + sx, sy, (sw ? sw : img->width), (sh ? sh : img->height)); + if (frame[0]->num > 1) { + if (frame[1]->id > WAIT_CNT) { + frame[1]->id = 0; + if (i < frame[0]->num - 1) + frame[0]->id = i + 1; + else + frame[0]->id = 0; + } + frame[1]->id += 1; + } + return 1; +} + +static void +w3mfb_free_image(w3mimg_op * self, W3MImage * img) +{ + if (self == NULL) + return; + if (img && img->pixmap) { + fb_frame_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; +} + +#ifdef W3MIMGDISPLAY_SETUID +static int +check_tty_console(char *tty) +{ + if (tty == NULL || *tty == '\0') + return 0; + if (strncmp(tty, "/dev/", 5) == 0) + tty += 5; + if (strncmp(tty, "tty", 3) == 0 && isdigit(*(tty + 3))) + return 1; + if (strncmp(tty, "vc/", 3) == 0 && isdigit(*(tty + 3))) + return 1; + return 0; +} +#else +#define check_tty_console(tty) 1 +#endif + +w3mimg_op * +w3mimg_fbopen() +{ + w3mimg_op *wop = NULL; + wop = (w3mimg_op *) malloc(sizeof(w3mimg_op)); + if (wop == NULL) + return NULL; + memset(wop, 0, sizeof(w3mimg_op)); + + if (!check_tty_console(getenv("W3M_TTY")) && strcmp("jfbterm", getenv("TERM")) != 0) { + fprintf(stderr, "w3mimgdisplay/fb: tty is not console\n"); + goto error; + } + + if (fb_open()) + goto error; + + wop->width = fb_width(); + wop->height = fb_height(); + + wop->init = w3mfb_init; + wop->finish = w3mfb_finish; + wop->active = w3mfb_active; + wop->set_background = w3mfb_set_background; + wop->sync = w3mfb_sync; + wop->close = w3mfb_close; + wop->clear = w3mfb_clear; + + 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: + free(wop); + return NULL; +} diff --git a/w3mimg/fb/readme.txt b/w3mimg/fb/readme.txt new file mode 100644 index 0000000..92e71a5 --- /dev/null +++ b/w3mimg/fb/readme.txt @@ -0,0 +1,73 @@ +Source: http://homepage3.nifty.com/slokar/fb/ +original readme.txt + +■提供するもの + ・w3mimgdisplayfb w3mimgdisplay (ほぼ)互換の framebuffer 用画像ビューア + ・w3mimgsizefb w3mimgsize 互換の画像サイズ報告プログラム + +■必要なもの + ・GdkPixbuf or Imlib2 + ・TRUE-COLOR の framebuffer を利用できる環境 + +■コンパイル + ・Makefile の CFLAGS, LDFLAGS を Imlib2, GdkPixbuf のどちらか利用する + 方を有効にしてから make してださい。 + +■利用法 + ・w3mimgdisplay, w3mimgsize と同様 + +■制限等 + ・framebuffer は 15,16,24,32bpp PACKED-PIXELS TRUE-COLOR + にしか対応していません。 + ・現在 w3mimgdisplayfb は -bg オプションを使用しない場合の背景色は黒 + (#000000)と仮定しています。 + +■開発環境 + ・ w3m version w3m/0.3+cvs-1.353-m17n-20020316 + ・ linux 2.4.18 (Vine Linux 2.5) + ・ gcc 2.95.3 + ・ GdkPixbuf 0.16.0 + ・ Imlib2 1.0.6 + ・ $ dmesg |grep vesafb + vesafb: framebuffer at 0xe2000000, mapped to 0xc880d000, size 8192k + vesafb: mode is 1024x768x16, linelength=2048, pages=4 + vesafb: protected mode interface info at c000:4785 + vesafb: scrolling: redraw + vesafb: directcolor: size=0:5:6:5, shift=0:11:5:0 + ・ ビデオカード + VGA compatible controller: ATI Technologies Inc 3D Rage Pro AGP 1X/2X (rev 92). + Master Capable. Latency=64. Min Gnt=8. + Non-prefetchable 32 bit memory at 0xe2000000 [0xe2ffffff]. + I/O at 0xd800 [0xd8ff]. + Non-prefetchable 32 bit memory at 0xe1800000 [0xe1800fff]. + +■その他 + ・w3mimgsizefb, w3mimgdisplayfb は坂本浩則さんの w3mimgsize, + w3mimgdisplay をもとにしています(というかほとんどそのままです)。 + ・framebuffer 描画関係のコードは、やまさきしんじさんのサンプルプログ + ラムをもとにしています(というかほとんどそのままです)。 + ・まだ開発途上であり、動作確認も不十分です。使用される際はご自身の責任 + でお願いします。 + ・この配布物に含まれるコードは変更済み BSD ライセンスに従うものとしま + す。詳細は license.txt を参照してください。 + +■関連 URI + ・ W3M Homepage http://w3m.sourceforge.net/ + ・ w3m-img http://www2u.biglobe.ne.jp/~hsaka/w3m/index-ja.html + ・ Linux Kernel Hack Japan http://www.sainet.or.jp/~yamasaki/ + ・ Imlib2 http://www.enlightenment.org/pages/main.html + ・ GdkPixbuf http://developer.gnome.org/arch/imaging/gdkpixbuf.html + +■履歴 + ・2002/07/05 開発開始 + ・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 + http://homepage3.nifty.com/slokar/ -- cgit v1.2.3 From 6db339b3d7a391f196e7c4b725a4ed0bd00f31cf Mon Sep 17 00:00:00 2001 From: Tatsuya Kinoshita Date: Wed, 4 May 2011 16:23:02 +0900 Subject: Adding upstream version 0.5.2 --- w3mimg/fb/fb_gdkpixbuf.c | 112 +++++++++++++++++++++++++++++++++++++++++++---- w3mimg/fb/fb_img.h | 3 +- w3mimg/fb/fb_imlib2.c | 8 +++- w3mimg/fb/fb_w3mimg.c | 6 ++- 4 files changed, 117 insertions(+), 12 deletions(-) (limited to 'w3mimg/fb') diff --git a/w3mimg/fb/fb_gdkpixbuf.c b/w3mimg/fb/fb_gdkpixbuf.c index e615da6..36e3b62 100644 --- a/w3mimg/fb/fb_gdkpixbuf.c +++ b/w3mimg/fb/fb_gdkpixbuf.c @@ -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 +#include +#endif #include #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; diff --git a/w3mimg/fb/fb_img.h b/w3mimg/fb/fb_img.h index cd1301b..acdb5a0 100644 --- a/w3mimg/fb/fb_img.h +++ b/w3mimg/fb/fb_img.h @@ -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); diff --git a/w3mimg/fb/fb_imlib2.c b/w3mimg/fb/fb_imlib2.c index 972f06e..ea36637 100644 --- a/w3mimg/fb/fb_imlib2.c +++ b/w3mimg/fb/fb_imlib2.c @@ -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) { diff --git a/w3mimg/fb/fb_w3mimg.c b/w3mimg/fb/fb_w3mimg.c index b67bad1..d3ae5a9 100644 --- a/w3mimg/fb/fb_w3mimg.c +++ b/w3mimg/fb/fb_w3mimg.c @@ -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 #include #include @@ -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); -- cgit v1.2.3 From 5397d09e585a1938fb64bc9c5cd5daed1959eb90 Mon Sep 17 00:00:00 2001 From: Tatsuya Kinoshita Date: Wed, 4 May 2011 16:41:45 +0900 Subject: Adding upstream version 0.5.3 --- w3mimg/fb/CVS/Entries | 11 +++++++++++ w3mimg/fb/CVS/Repository | 1 + w3mimg/fb/CVS/Root | 1 + 3 files changed, 13 insertions(+) create mode 100644 w3mimg/fb/CVS/Entries create mode 100644 w3mimg/fb/CVS/Repository create mode 100644 w3mimg/fb/CVS/Root (limited to 'w3mimg/fb') diff --git a/w3mimg/fb/CVS/Entries b/w3mimg/fb/CVS/Entries new file mode 100644 index 0000000..549e962 --- /dev/null +++ b/w3mimg/fb/CVS/Entries @@ -0,0 +1,11 @@ +/.cvsignore/1.1/Mon Sep 22 22:53:53 2003// +/Makefile.in/1.4/Mon Apr 26 17:00:38 2004// +/fb.c/1.16/Sun Jul 13 16:19:10 2003// +/fb.h/1.7/Mon Jul 7 15:48:17 2003// +/fb_gdkpixbuf.c/1.21/Mon Nov 8 17:14:06 2004// +/fb_img.c/1.6/Mon Jul 7 15:48:17 2003// +/fb_img.h/1.9/Wed Aug 4 17:32:28 2004// +/fb_imlib2.c/1.10/Wed Aug 4 17:32:28 2004// +/fb_w3mimg.c/1.14/Wed Aug 4 17:32:28 2004// +/readme.txt/1.2/Mon Jul 22 16:17:32 2002// +D diff --git a/w3mimg/fb/CVS/Repository b/w3mimg/fb/CVS/Repository new file mode 100644 index 0000000..336666e --- /dev/null +++ b/w3mimg/fb/CVS/Repository @@ -0,0 +1 @@ +w3m/w3mimg/fb diff --git a/w3mimg/fb/CVS/Root b/w3mimg/fb/CVS/Root new file mode 100644 index 0000000..121fa06 --- /dev/null +++ b/w3mimg/fb/CVS/Root @@ -0,0 +1 @@ +:ext:inu@w3m.cvs.sourceforge.net:/cvsroot/w3m -- cgit v1.2.3 From 620796f8d750bc58e1cf1327ff54aed32e302c73 Mon Sep 17 00:00:00 2001 From: Tatsuya Kinoshita Date: Tue, 22 May 2012 23:06:58 +0900 Subject: Remove garbage files --- w3mimg/fb/CVS/Entries | 11 ----------- w3mimg/fb/CVS/Repository | 1 - w3mimg/fb/CVS/Root | 1 - 3 files changed, 13 deletions(-) delete mode 100644 w3mimg/fb/CVS/Entries delete mode 100644 w3mimg/fb/CVS/Repository delete mode 100644 w3mimg/fb/CVS/Root (limited to 'w3mimg/fb') diff --git a/w3mimg/fb/CVS/Entries b/w3mimg/fb/CVS/Entries deleted file mode 100644 index 549e962..0000000 --- a/w3mimg/fb/CVS/Entries +++ /dev/null @@ -1,11 +0,0 @@ -/.cvsignore/1.1/Mon Sep 22 22:53:53 2003// -/Makefile.in/1.4/Mon Apr 26 17:00:38 2004// -/fb.c/1.16/Sun Jul 13 16:19:10 2003// -/fb.h/1.7/Mon Jul 7 15:48:17 2003// -/fb_gdkpixbuf.c/1.21/Mon Nov 8 17:14:06 2004// -/fb_img.c/1.6/Mon Jul 7 15:48:17 2003// -/fb_img.h/1.9/Wed Aug 4 17:32:28 2004// -/fb_imlib2.c/1.10/Wed Aug 4 17:32:28 2004// -/fb_w3mimg.c/1.14/Wed Aug 4 17:32:28 2004// -/readme.txt/1.2/Mon Jul 22 16:17:32 2002// -D diff --git a/w3mimg/fb/CVS/Repository b/w3mimg/fb/CVS/Repository deleted file mode 100644 index 336666e..0000000 --- a/w3mimg/fb/CVS/Repository +++ /dev/null @@ -1 +0,0 @@ -w3m/w3mimg/fb diff --git a/w3mimg/fb/CVS/Root b/w3mimg/fb/CVS/Root deleted file mode 100644 index 121fa06..0000000 --- a/w3mimg/fb/CVS/Root +++ /dev/null @@ -1 +0,0 @@ -:ext:inu@w3m.cvs.sourceforge.net:/cvsroot/w3m -- cgit v1.2.3 From 1d0ba25a660483da1272a31dd077ed94441e3d9f Mon Sep 17 00:00:00 2001 From: Tatsuya Kinoshita Date: Sat, 2 Jan 2021 09:20:37 +0900 Subject: New upstream version 0.5.3+git20210102 --- w3mimg/fb/.cvsignore | 1 - w3mimg/fb/fb.c | 431 +++++++++++++++++++++++++++++++++++++++++++++++ w3mimg/fb/fb.h | 4 + w3mimg/fb/fb_gdkpixbuf.c | 2 +- w3mimg/fb/fb_imlib2.c | 1 - w3mimg/fb/fb_w3mimg.c | 9 +- w3mimg/fb/readme.txt | 98 +++++------ 7 files changed, 493 insertions(+), 53 deletions(-) delete mode 100644 w3mimg/fb/.cvsignore (limited to 'w3mimg/fb') diff --git a/w3mimg/fb/.cvsignore b/w3mimg/fb/.cvsignore deleted file mode 100644 index f3c7a7c..0000000 --- a/w3mimg/fb/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -Makefile diff --git a/w3mimg/fb/fb.c b/w3mimg/fb/fb.c index cd11128..7960584 100644 --- a/w3mimg/fb/fb.c +++ b/w3mimg/fb/fb.c @@ -12,12 +12,24 @@ #include #include #include +#if defined(__linux__) #include +#elif defined(__FreeBSD__) +#include +#endif +#if defined(__FreeBSD__) +#include +#include +#endif #include "fb.h" #define FB_ENV "FRAMEBUFFER" +#if defined(__linux__) #define FB_DEFDEV "/dev/fb0" +#elif defined(__FreeBSD__) +#define FB_DEFDEV "/dev/ttyv0" +#endif #define MONO_OFFSET_8BIT 0x40 #define COLORS_MONO_8BIT 0x40 @@ -38,22 +50,65 @@ #define IMAGE_SIZE_MAX 10000 +#if defined(__linux__) static struct fb_cmap *fb_cmap_create(struct fb_fix_screeninfo *, struct fb_var_screeninfo *); +#elif defined(__FreeBSD__) +static video_color_palette_t *fb_cmap_create(video_info_t *video_info, + video_adapter_info_t *video_adapter_info); +#endif +#if defined(__linux__) static void fb_cmap_destroy(struct fb_cmap *cmap); +#elif defined(__FreeBSD__) +static void fb_cmap_destroy(video_color_palette_t *cmap); +#endif +#if defined(__linux__) static int fb_fscrn_get(int fbfp, struct fb_fix_screeninfo *scinfo); +#endif +#if defined(__linux__) static void *fb_mmap(int fbfp, struct fb_fix_screeninfo *scinfo); +#elif defined(__FreeBSD__) +static void *fb_mmap(int fbfp, video_adapter_info_t *video_adapter_info); +#endif +#if defined(__linux__) static int fb_munmap(void *buf, struct fb_fix_screeninfo *scinfo); +#elif defined(__FreeBSD__) +static int fb_munmap(void *buf, video_adapter_info_t *video_adapter_info); +#endif +#if defined(__linux__) static int fb_vscrn_get(int fbfp, struct fb_var_screeninfo *scinfo); +#endif +#if defined(__linux__) static int fb_cmap_set(int fbfp, struct fb_cmap *cmap); +#elif defined(__FreeBSD__) +static int fb_cmap_set(int fbfp, video_color_palette_t *cmap); +#endif +#if defined(__linux__) static int fb_cmap_get(int fbfp, struct fb_cmap *cmap); +#elif defined(__FreeBSD__) +static int fb_cmap_get(int fbfp, video_color_palette_t *cmap); +#endif static int fb_cmap_init(void); static int fb_get_cmap_index(int r, int g, int b); static unsigned long fb_get_packed_color(int r, int g, int b); +#if defined(__FreeBSD__) +static int fb_video_mode_get(int fbfp, int *video_mode); +static int fb_video_info_get(int fbfp, video_info_t *video_info); +static int fb_video_adapter_info_get(int fbfp, video_adapter_info_t *video_adapter_info); +#endif +#if defined(__linux__) static struct fb_fix_screeninfo fscinfo; static struct fb_var_screeninfo vscinfo; +#elif defined(__FreeBSD__) +static video_info_t video_info; +static video_adapter_info_t video_adapter_info; +#endif +#if defined(__linux__) static struct fb_cmap *cmap = NULL, *cmap_org = NULL; +#elif defined(__FreeBSD__) +static video_color_palette_t *cmap = NULL, *cmap_org = NULL; +#endif static int is_open = FALSE; static int fbfp = -1; static size_t pixel_size = 0; @@ -63,6 +118,9 @@ int fb_open(void) { char *fbdev = { FB_DEFDEV }; +#if defined(__FreeBSD__) + int video_mode; +#endif if (is_open == TRUE) return 1; @@ -76,6 +134,7 @@ fb_open(void) goto ERR_END; } +#if defined(__linux__) if (fb_fscrn_get(fbfp, &fscinfo)) { goto ERR_END; } @@ -83,22 +142,69 @@ fb_open(void) if (fb_vscrn_get(fbfp, &vscinfo)) { goto ERR_END; } +#elif defined(__FreeBSD__) + if (fb_video_mode_get(fbfp, &video_mode)) { + goto ERR_END; + } + video_info.vi_mode = video_mode; + + if (fb_video_info_get(fbfp, &video_info)) { + goto ERR_END; + } + if (fb_video_adapter_info_get(fbfp, &video_adapter_info)) { + goto ERR_END; + } + if (!(video_info.vi_flags & V_INFO_GRAPHICS) || + !(video_info.vi_flags & V_INFO_LINEAR)) { + goto ERR_END; + } +#endif + +#if defined(__linux__) if ((cmap = fb_cmap_create(&fscinfo, &vscinfo)) == (struct fb_cmap *)-1) { goto ERR_END; } +#elif defined(__FreeBSD__) + if ((cmap = fb_cmap_create(&video_info, &video_adapter_info)) == (video_color_palette_t *)-1) { + goto ERR_END; + } +#endif +#if defined(__linux__) if (!(buf = fb_mmap(fbfp, &fscinfo))) { fprintf(stderr, "Can't allocate memory.\n"); goto ERR_END; } +#elif defined(__FreeBSD__) + if (!(buf = fb_mmap(fbfp, &video_adapter_info))) { + fprintf(stderr, "Can't allocate memory.\n"); + goto ERR_END; + } +#endif +#if defined(__linux__) if (fscinfo.type != FB_TYPE_PACKED_PIXELS) { fprintf(stderr, "This type of framebuffer is not supported.\n"); goto ERR_END; } +#elif defined(__FreeBSD__) + if (!(video_info.vi_mem_model == V_INFO_MM_PACKED || + video_info.vi_mem_model == V_INFO_MM_DIRECT)) { + fprintf(stderr, "This type of framebuffer is not supported.\n"); + goto ERR_END; + } +#endif +#if defined(__linux__) if (fscinfo.visual == FB_VISUAL_PSEUDOCOLOR && vscinfo.bits_per_pixel == 8) { +#elif defined(__FreeBSD__) + if (video_adapter_info.va_flags & V_ADP_PALETTE && + video_info.vi_mem_model == V_INFO_MM_PACKED && + video_info.vi_depth == 8) { +#else + if (0) { +#endif if (fb_cmap_get(fbfp, cmap)) { fprintf(stderr, "Can't get color map.\n"); fb_cmap_destroy(cmap); @@ -111,6 +217,7 @@ fb_open(void) pixel_size = 1; } +#if defined(__linux__) else if ((fscinfo.visual == FB_VISUAL_TRUECOLOR || fscinfo.visual == FB_VISUAL_DIRECTCOLOR) && (vscinfo.bits_per_pixel == 15 || @@ -118,6 +225,14 @@ fb_open(void) vscinfo.bits_per_pixel == 24 || vscinfo.bits_per_pixel == 32)) { pixel_size = (vscinfo.bits_per_pixel + 7) / CHAR_BIT; } +#elif defined(__FreeBSD__) + else if (video_info.vi_mem_model == V_INFO_MM_DIRECT && + (video_info.vi_depth == 15 || + video_info.vi_depth == 16 || + video_info.vi_depth == 24 || video_info.vi_depth == 32)) { + pixel_size = (video_info.vi_depth + 7) / CHAR_BIT; + } +#endif else { fprintf(stderr, "This type of framebuffer is not supported.\n"); goto ERR_END; @@ -147,7 +262,11 @@ fb_close(void) cmap = NULL; } if (buf != NULL) { +#if defined(__linux__) fb_munmap(buf, &fscinfo); +#elif defined(__FreeBSD__) + fb_munmap(buf, &video_adapter_info); +#endif buf = NULL; } @@ -259,11 +378,19 @@ fb_image_draw(FB_IMAGE * image, int x, int y, int sx, int sy, int width, if (y + height > fb_height()) height = fb_height() - y; +#if defined(__linux__) offset_fb = fscinfo.line_length * y + pixel_size * x; +#elif defined(__FreeBSD__) + offset_fb = video_adapter_info.va_line_width * y + pixel_size * x; +#endif 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); +#if defined(__linux__) offset_fb += fscinfo.line_length; +#elif defined(__FreeBSD__) + offset_fb += video_adapter_info.va_line_width; +#endif offset_img += image->rowstride; } @@ -336,7 +463,11 @@ fb_width(void) if (is_open != TRUE) return 0; +#if defined(__linux__) return vscinfo.xres; +#elif defined(__FreeBSD__) + return video_info.vi_width; +#endif } int @@ -345,7 +476,11 @@ fb_height(void) if (is_open != TRUE) return 0; +#if defined(__linux__) return vscinfo.yres; +#elif defined(__FreeBSD__) + return video_info.vi_height; +#endif } int @@ -369,7 +504,11 @@ fb_clear(int x, int y, int w, int h, int r, int g, int b) h = fb_height() - y; if (tmp == NULL) { +#if defined(__linux__) tmp = malloc(fscinfo.line_length); +#elif defined(__FreeBSD__) + tmp = malloc(video_adapter_info.va_line_width); +#endif if (tmp == NULL) return 1; } @@ -384,10 +523,18 @@ fb_clear(int x, int y, int w, int h, int r, int g, int b) gg = g; bb = b; } +#if defined(__linux__) offset_fb = fscinfo.line_length * y + pixel_size * x; +#elif defined(__FreeBSD__) + offset_fb = video_adapter_info.va_line_width * y + pixel_size * x; +#endif for (i = 0; i < h; i++) { memcpy(buf + offset_fb, tmp, pixel_size * w); +#if defined(__linux__) offset_fb += fscinfo.line_length; +#elif defined(__FreeBSD__) + offset_fb += video_adapter_info.va_line_width; +#endif } return 0; } @@ -400,11 +547,21 @@ fb_get_packed_color(int r, int g, int b) return fb_get_cmap_index(r, g, b); } else { +#if defined(__linux__) return ((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); +#elif defined(__FreeBSD__) + return + ((r >> (CHAR_BIT - video_info.vi_pixel_fsizes[0])) << + video_info.vi_pixel_fields[0]) + + ((g >> (CHAR_BIT - video_info.vi_pixel_fsizes[1])) << + video_info.vi_pixel_fields[1]) + + ((b >> (CHAR_BIT - video_info.vi_pixel_fsizes[2])) << + video_info.vi_pixel_fields[2]); +#endif } } @@ -433,16 +590,31 @@ fb_cmap_init(void) if (cmap == NULL) return 1; +#if defined(__linux__) if (cmap->len < COLOR_OFFSET_8BIT + COLORS_8BIT) { fprintf(stderr, "Can't allocate enough color.\n"); return 1; } +#elif defined(__FreeBSD__) + if (cmap->count < COLOR_OFFSET_8BIT + COLORS_8BIT) { + fprintf(stderr, "Can't allocate enough color.\n"); + return 1; + } +#endif if (cmap_org == NULL) { +#if defined(__linux__) if ((cmap_org = fb_cmap_create(&fscinfo, &vscinfo)) == (struct fb_cmap *)-1) { return 1; } +#elif defined(__FreeBSD__) + if ((cmap_org = + fb_cmap_create(&video_info, &video_adapter_info)) == + (video_color_palette_t *)-1) { + return 1; + } +#endif if (fb_cmap_get(fbfp, cmap_org)) { fprintf(stderr, "Can't get color map.\n"); @@ -452,8 +624,13 @@ fb_cmap_init(void) } } +#if defined(__linux__) cmap->start = MONO_OFFSET_8BIT; cmap->len = COLORS_8BIT + COLORS_MONO_8BIT; +#elif defined(__FreeBSD__) + cmap->index = MONO_OFFSET_8BIT; + cmap->count = COLORS_8BIT + COLORS_MONO_8BIT; +#endif for (lp = 0; lp < COLORS_MONO_8BIT; lp++) { int c; @@ -506,73 +683,223 @@ fb_cmap_init(void) #define LUT_MAX (256) +#if defined(__linux__) static struct fb_cmap * fb_cmap_create(struct fb_fix_screeninfo *fscinfo, struct fb_var_screeninfo *vscinfo) +#elif defined(__FreeBSD__) +static video_color_palette_t * +fb_cmap_create(video_info_t *video_info, + video_adapter_info_t *video_adapter_info) +#endif { +#if defined(__linux__) struct fb_cmap *cmap; +#elif defined(__FreeBSD__) + video_color_palette_t *cmap; +#endif int cmaplen = LUT_MAX; /* check the existence of colormap */ +#if defined(__linux__) if (fscinfo->visual == FB_VISUAL_MONO01 || fscinfo->visual == FB_VISUAL_MONO10 || fscinfo->visual == FB_VISUAL_TRUECOLOR) return NULL; +#elif defined(__FreeBSD__) + if (!(video_adapter_info->va_flags & V_ADP_PALETTE)) + return NULL; +#endif +#if defined(__linux__) cmap = (struct fb_cmap *)malloc(sizeof(struct fb_cmap)); +#elif defined(__FreeBSD__) + cmap = (video_color_palette_t *)malloc(sizeof(video_color_palette_t)); +#endif if (!cmap) { perror("cmap malloc error\n"); +#if defined(__linux__) return (struct fb_cmap *)-1; +#elif defined(__FreeBSD__) + return (video_color_palette_t *)-1; +#endif } +#if defined(__linux__) memset(cmap, 0, sizeof(struct fb_cmap)); +#elif defined(__FreeBSD__) + memset(cmap, 0, sizeof(video_color_palette_t)); +#endif + +#if defined(__FreeBSD__) + if (video_info->vi_mem_model == V_INFO_MM_PACKED) { + cmap->red = (u_char *) malloc(sizeof(u_char) * cmaplen); + if (!cmap->red) { + perror("red lut malloc error\n"); + return (video_color_palette_t *)-1; + } + cmap->green = (u_char *) malloc(sizeof(u_char) * cmaplen); + if (!cmap->green) { + perror("green lut malloc error\n"); + free(cmap->red); + return (video_color_palette_t *)-1; + } + cmap->blue = (u_char *) malloc(sizeof(u_char) * cmaplen); + if (!cmap->blue) { + perror("blue lut malloc error\n"); + free(cmap->red); + free(cmap->green); + return (video_color_palette_t *)-1; + } + cmap->transparent = (u_char *) malloc(sizeof(u_char) * cmaplen); + if (!cmap->transparent) { + perror("transparent lut malloc error\n"); + free(cmap->red); + free(cmap->green); + free(cmap->blue); + return (video_color_palette_t *)-1; + } + cmap->count = cmaplen; + return cmap; + } +#endif /* Allocates memory for a colormap */ +#if defined(__linux__) if (vscinfo->red.length) { cmap->red = (__u16 *) malloc(sizeof(__u16) * cmaplen); +#elif defined(__FreeBSD__) + if (video_info->vi_pixel_fsizes[0]) { + cmap->red = (u_char *) malloc(sizeof(u_char) * cmaplen); +#else + if (0) { +#endif if (!cmap->red) { perror("red lut malloc error\n"); +#if defined(__linux__) return (struct fb_cmap *)-1; +#elif defined(__FreeBSD__) + return (video_color_palette_t *)-1; +#endif } } +#if defined(__linux__) if (vscinfo->green.length) { cmap->green = (__u16 *) malloc(sizeof(__u16) * cmaplen); +#elif defined(__FreeBSD__) + if (video_info->vi_pixel_fsizes[1]) { + cmap->green = (u_char *) malloc(sizeof(u_char) * cmaplen); +#else + if (0) { +#endif if (!cmap->green) { +#if defined(__linux__) if (vscinfo->red.length) free(cmap->red); +#elif defined(__FreeBSD__) + if (video_info->vi_pixel_fsizes[0]) + free(cmap->red); +#endif perror("green lut malloc error\n"); +#if defined(__linux__) return (struct fb_cmap *)-1; +#elif defined(__FreeBSD__) + return (video_color_palette_t *)-1; +#endif } } +#if defined(__linux__) if (vscinfo->blue.length) { cmap->blue = (__u16 *) malloc(sizeof(__u16) * cmaplen); +#elif defined(__FreeBSD__) + if (video_info->vi_pixel_fsizes[2]) { + cmap->blue = (u_char *) malloc(sizeof(u_char) * cmaplen); +#else + if (0) { +#endif if (!cmap->blue) { +#if defined(__linux__) if (vscinfo->red.length) free(cmap->red); +#elif defined(__FreeBSD__) + if (video_info->vi_pixel_fsizes[0]) + free(cmap->red); +#endif +#if defined(__linux__) if (vscinfo->green.length) free(cmap->green); +#elif defined(__FreeBSD__) + if (video_info->vi_pixel_fsizes[1]) + free(cmap->green); +#endif perror("blue lut malloc error\n"); +#if defined(__linux__) return (struct fb_cmap *)-1; +#elif defined(__FreeBSD__) + return (video_color_palette_t *)-1; +#endif } } +#if defined(__linux__) if (vscinfo->transp.length) { cmap->transp = (__u16 *) malloc(sizeof(__u16) * cmaplen); +#elif defined(__FreeBSD__) + if (video_info->vi_pixel_fsizes[3]) { + cmap->transparent = (u_char *) malloc(sizeof(u_char) * cmaplen); +#else + if (0) { +#endif +#if defined(__linux__) if (!cmap->transp) { +#elif defined(__FreeBSD__) + if (!cmap->transparent) { +#else + if (0) { +#endif +#if defined(__linux__) if (vscinfo->red.length) free(cmap->red); +#elif defined(__FreeBSD__) + if (video_info->vi_pixel_fsizes[0]) + free(cmap->red); +#endif +#if defined(__linux__) if (vscinfo->green.length) free(cmap->green); +#elif defined(__FreeBSD__) + if (video_info->vi_pixel_fsizes[1]) + free(cmap->green); +#endif +#if defined(__linux__) if (vscinfo->blue.length) free(cmap->blue); perror("transp lut malloc error\n"); +#elif defined(__FreeBSD__) + if (video_info->vi_pixel_fsizes[2]) + free(cmap->blue); + perror("transparent lut malloc error\n"); +#endif +#if defined(__linux__) return (struct fb_cmap *)-1; +#elif defined(__FreeBSD__) + return (video_color_palette_t *)-1; +#endif } } +#if defined(__linux__) cmap->len = cmaplen; +#elif defined(__FreeBSD__) + cmap->count = cmaplen; +#endif return cmap; } +#if defined(__linux__) static void fb_cmap_destroy(struct fb_cmap *cmap) +#elif defined(__FreeBSD__) +static void +fb_cmap_destroy(video_color_palette_t *cmap) +#endif { if (cmap->red) free(cmap->red); @@ -580,28 +907,57 @@ fb_cmap_destroy(struct fb_cmap *cmap) free(cmap->green); if (cmap->blue) free(cmap->blue); +#if defined(__linux__) if (cmap->transp) free(cmap->transp); +#elif defined(__FreeBSD__) + if (cmap->transparent) + free(cmap->transparent); +#endif free(cmap); } +#if defined(__linux__) static int fb_cmap_get(int fbfp, struct fb_cmap *cmap) +#elif defined(__FreeBSD__) +static int +fb_cmap_get(int fbfp, video_color_palette_t *cmap) +#endif { +#if defined(__linux__) if (ioctl(fbfp, FBIOGETCMAP, cmap)) { perror("ioctl FBIOGETCMAP error\n"); return -1; } +#elif defined(__FreeBSD__) + if (ioctl(fbfp, FBIO_GETPALETTE, cmap) == -1) { + perror("ioctl FBIO_GETPALETTE error\n"); + return -1; + } +#endif return 0; } +#if defined(__linux__) static int fb_cmap_set(int fbfp, struct fb_cmap *cmap) +#elif defined(__FreeBSD__) +static int +fb_cmap_set(int fbfp, video_color_palette_t *cmap) +#endif { +#if defined(__linux__) if (ioctl(fbfp, FBIOPUTCMAP, cmap)) { perror("ioctl FBIOPUTCMAP error\n"); return -1; } +#elif defined(__FreeBSD__) + if (ioctl(fbfp, FBIO_SETPALETTE, cmap) == -1) { + perror("ioctl FBIO_SETPALETTE error\n"); + return -1; + } +#endif return 0; } @@ -612,10 +968,16 @@ fb_cmap_set(int fbfp, struct fb_cmap *cmap) * fb_munmap() deletes the mappings */ +#if defined(__linux__) static void * fb_mmap(int fbfp, struct fb_fix_screeninfo *scinfo) +#elif defined(__FreeBSD__) +static void * +fb_mmap(int fbfp, video_adapter_info_t *video_adapter_info) +#endif { void *buf; +#if defined(__linux__) if ((buf = (unsigned char *) mmap(NULL, scinfo->smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fbfp, (off_t) 0)) @@ -623,13 +985,41 @@ fb_mmap(int fbfp, struct fb_fix_screeninfo *scinfo) perror("mmap error"); return NULL; } +#elif defined(__FreeBSD__) + size_t mmap_offset; + size_t mmap_length; + mmap_offset = (size_t)(video_adapter_info->va_window) & (PAGE_MASK); + mmap_length = (size_t)(video_adapter_info->va_window_size + + mmap_offset + PAGE_MASK) & (~PAGE_MASK); + if ((buf = (unsigned char *) + mmap(NULL, mmap_length, PROT_READ | PROT_WRITE, MAP_SHARED, fbfp, + (off_t) 0)) + == MAP_FAILED) { + perror("mmap error"); + return NULL; + } +#endif return buf; } +#if defined(__linux__) static int fb_munmap(void *buf, struct fb_fix_screeninfo *scinfo) +#elif defined(__FreeBSD__) +static int +fb_munmap(void *buf, video_adapter_info_t *video_adapter_info) +#endif { +#if defined(__linux__) return munmap(buf, scinfo->smem_len); +#elif defined(__FreeBSD__) + size_t mmap_offset; + size_t mmap_length; + mmap_offset = (size_t)(video_adapter_info->va_window) & (PAGE_MASK); + mmap_length = (size_t)(video_adapter_info->va_window_size + + mmap_offset + PAGE_MASK) & (~PAGE_MASK); + return munmap((void *)((u_long)buf & (~PAGE_MASK)), mmap_length); +#endif } /* @@ -637,6 +1027,7 @@ fb_munmap(void *buf, struct fb_fix_screeninfo *scinfo) * * fb_fscrn_get() get information */ +#if defined(__linux__) static int fb_fscrn_get(int fbfp, struct fb_fix_screeninfo *scinfo) { @@ -646,12 +1037,14 @@ fb_fscrn_get(int fbfp, struct fb_fix_screeninfo *scinfo) } return 0; } +#endif /* * (struct fb_var_screeninfo) device independent variable information * * fb_vscrn_get() get information */ +#if defined(__linux__) static int fb_vscrn_get(int fbfp, struct fb_var_screeninfo *scinfo) { @@ -661,3 +1054,41 @@ fb_vscrn_get(int fbfp, struct fb_var_screeninfo *scinfo) } return 0; } +#endif + +#if defined(__FreeBSD__) +static int +fb_video_mode_get(int fbfp, int *video_mode) +{ + if (ioctl(fbfp, FBIO_GETMODE, video_mode) == -1) { + perror("ioctl FBIO_GETMODE error\n"); + return -1; + } + return 0; +} +#endif + +#if defined(__FreeBSD__) +static int +fb_video_info_get(int fbfp, video_info_t *video_info) +{ + if (ioctl(fbfp, FBIO_MODEINFO, video_info) == -1) { + perror("ioctl FBIO_MODEINFO error\n"); + return -1; + } + return 0; +} +#endif + +#if defined(__FreeBSD__) +static int +fb_video_adapter_info_get(int fbfp, video_adapter_info_t *video_adapter_info) +{ + if (ioctl(fbfp, FBIO_ADPINFO, video_adapter_info) == -1) { + perror("ioctl FBIO_ADPINFO error\n"); + return -1; + } + return 0; +} +#endif + diff --git a/w3mimg/fb/fb.h b/w3mimg/fb/fb.h index 1138bb0..5d86454 100644 --- a/w3mimg/fb/fb.h +++ b/w3mimg/fb/fb.h @@ -1,7 +1,11 @@ /* $Id: fb.h,v 1.7 2003/07/07 15:48:17 ukai Exp $ */ #ifndef fb_header #define fb_header +#if defined(__linux__) #include +#elif defined(__FreeBSD__) +#include +#endif typedef struct { int num; diff --git a/w3mimg/fb/fb_gdkpixbuf.c b/w3mimg/fb/fb_gdkpixbuf.c index 36e3b62..f1e8d97 100644 --- a/w3mimg/fb/fb_gdkpixbuf.c +++ b/w3mimg/fb/fb_gdkpixbuf.c @@ -6,7 +6,7 @@ #include "config.h" #if defined(USE_GTK2) #include -#include +#include #endif #include #include "fb.h" diff --git a/w3mimg/fb/fb_imlib2.c b/w3mimg/fb/fb_imlib2.c index ea36637..1a5151c 100644 --- a/w3mimg/fb/fb_imlib2.c +++ b/w3mimg/fb/fb_imlib2.c @@ -3,7 +3,6 @@ fb_imlib2.c 0.3 Copyright (C) 2002, hito **************************************************************************/ -#include #include #include "fb.h" #include "fb_img.h" diff --git a/w3mimg/fb/fb_w3mimg.c b/w3mimg/fb/fb_w3mimg.c index d3ae5a9..62511f0 100644 --- a/w3mimg/fb/fb_w3mimg.c +++ b/w3mimg/fb/fb_w3mimg.c @@ -153,10 +153,15 @@ check_tty_console(char *tty) return 0; if (strncmp(tty, "/dev/", 5) == 0) tty += 5; +#if defined(__linux__) if (strncmp(tty, "tty", 3) == 0 && isdigit(*(tty + 3))) return 1; if (strncmp(tty, "vc/", 3) == 0 && isdigit(*(tty + 3))) return 1; +#elif defined(__FreeBSD__) + if (strncmp(tty, "ttyv", 4) == 0 && isxdigit(*(tty + 4))) + return 1; +#endif return 0; } #else @@ -172,7 +177,9 @@ w3mimg_fbopen() return NULL; memset(wop, 0, sizeof(w3mimg_op)); - if (!check_tty_console(getenv("W3M_TTY")) && strcmp("jfbterm", getenv("TERM")) != 0) { + if (!check_tty_console(getenv("W3M_TTY")) && + strncmp("fbterm", getenv("TERM"), 6) != 0 && + strncmp("jfbterm", getenv("TERM"), 7) != 0) { fprintf(stderr, "w3mimgdisplay/fb: tty is not console\n"); goto error; } diff --git a/w3mimg/fb/readme.txt b/w3mimg/fb/readme.txt index 92e71a5..c3c43cd 100644 --- a/w3mimg/fb/readme.txt +++ b/w3mimg/fb/readme.txt @@ -1,73 +1,73 @@ Source: http://homepage3.nifty.com/slokar/fb/ original readme.txt -■提供するもの - ・w3mimgdisplayfb w3mimgdisplay (ほぼ)互換の framebuffer 用画像ビューア - ・w3mimgsizefb w3mimgsize 互換の画像サイズ報告プログラム +箴 + w3mimgdisplayfb w3mimgdisplay (祉)篋 framebuffer 糸ャ若 + w3mimgsizefb w3mimgsize 篋糸泣ゃ阪怨違 -■必要なもの - ・GdkPixbuf or Imlib2 - ・TRUE-COLOR の framebuffer を利用できる環境 +綽荀 + GdkPixbuf or Imlib2 + TRUE-COLOR framebuffer с医 -■コンパイル - ・Makefile の CFLAGS, LDFLAGS を Imlib2, GdkPixbuf のどちらか利用する - 方を有効にしてから make してださい。 +潟潟ゃ + Makefile CFLAGS, LDFLAGS Imlib2, GdkPixbuf < + 鴻鴻 make -■利用法 - ・w3mimgdisplay, w3mimgsize と同様 +羈 + w3mimgdisplay, w3mimgsize 罕 -■制限等 - ・framebuffer は 15,16,24,32bpp PACKED-PIXELS TRUE-COLOR - にしか対応していません。 - ・現在 w3mimgdisplayfb は -bg オプションを使用しない場合の背景色は黒 - (#000000)と仮定しています。 +狗膈 + framebuffer 15,16,24,32bpp PACKED-PIXELS TRUE-COLOR + 絲上障 + 紫憜 w3mimgdisplayfb -bg 激с潟篏睡翫蚊藥 + (#000000)篁絎障 -■開発環境 - ・ w3m version w3m/0.3+cvs-1.353-m17n-20020316 - ・ linux 2.4.18 (Vine Linux 2.5) - ・ gcc 2.95.3 - ・ GdkPixbuf 0.16.0 - ・ Imlib2 1.0.6 - ・ $ dmesg |grep vesafb +榊医 + w3m version w3m/0.3+cvs-1.353-m17n-20020316 + linux 2.4.18 (Vine Linux 2.5) + gcc 2.95.3 + GdkPixbuf 0.16.0 + Imlib2 1.0.6 + $ dmesg |grep vesafb vesafb: framebuffer at 0xe2000000, mapped to 0xc880d000, size 8192k vesafb: mode is 1024x768x16, linelength=2048, pages=4 vesafb: protected mode interface info at c000:4785 vesafb: scrolling: redraw vesafb: directcolor: size=0:5:6:5, shift=0:11:5:0 - ・ ビデオカード + 若 VGA compatible controller: ATI Technologies Inc 3D Rage Pro AGP 1X/2X (rev 92). Master Capable. Latency=64. Min Gnt=8. Non-prefetchable 32 bit memory at 0xe2000000 [0xe2ffffff]. I/O at 0xd800 [0xd8ff]. Non-prefetchable 32 bit memory at 0xe1800000 [0xe1800fff]. -■その他 - ・w3mimgsizefb, w3mimgdisplayfb は坂本浩則さんの w3mimgsize, - w3mimgdisplay をもとにしています(というかほとんどそのままです)。 - ・framebuffer 描画関係のコードは、やまさきしんじさんのサンプルプログ - ラムをもとにしています(というかほとんどそのままです)。 - ・まだ開発途上であり、動作確認も不十分です。使用される際はご自身の責任 - でお願いします。 - ・この配布物に含まれるコードは変更済み BSD ライセンスに従うものとしま - す。詳細は license.txt を参照してください。 +篁 + w3mimgsizefb, w3mimgdisplayfb 羌 w3mimgsize, + w3mimgdisplay 障(祉障障с) + framebuffer 脂≫潟若障泣潟 + 障(祉障障с) + 祉障咲筝с篏腆肴筝с篏睡荳莢篁 + с蕁障 + 祉絽障潟若紊贋 BSD ゃ祉潟鴻緇 + 荅括完 license.txt с -■関連 URI - ・ W3M Homepage http://w3m.sourceforge.net/ - ・ w3m-img http://www2u.biglobe.ne.jp/~hsaka/w3m/index-ja.html - ・ Linux Kernel Hack Japan http://www.sainet.or.jp/~yamasaki/ - ・ Imlib2 http://www.enlightenment.org/pages/main.html - ・ GdkPixbuf http://developer.gnome.org/arch/imaging/gdkpixbuf.html +∫ URI + W3M Homepage http://w3m.sourceforge.net/ + w3m-img http://www2u.biglobe.ne.jp/~hsaka/w3m/index-ja.html + Linux Kernel Hack Japan http://www.sainet.or.jp/~yamasaki/ + Imlib2 http://www.enlightenment.org/pages/main.html + GdkPixbuf http://developer.gnome.org/arch/imaging/gdkpixbuf.html -■履歴 - ・2002/07/05 開発開始 - ・2002/07/07 ImageMagick 版動作確認 - ・2002/07/10 GdkPixbuf 版動作確認 - ・2002/07/11 Imlib2 版動作確認 - ・2002/07/15 Version 0.1 - 公開 - ・2002/07/22 Version 0.2 - 描画の高速化 +絮ユ + 2002/07/05 咲紮 + 2002/07/07 ImageMagick 篏腆肴 + 2002/07/10 GdkPixbuf 篏腆肴 + 2002/07/11 Imlib2 篏腆肴 + 2002/07/15 Version 0.1 + + 2002/07/22 Version 0.2 + 祉蕭 -■連絡先 +g機 ZXB01226@nifty.com http://homepage3.nifty.com/slokar/ -- cgit v1.2.3