aboutsummaryrefslogtreecommitdiffstats
path: root/w3mimg
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--w3mimg/.cvsignore1
-rw-r--r--w3mimg/Makefile.in4
-rw-r--r--w3mimg/fb/.cvsignore1
-rw-r--r--w3mimg/fb/fb.c431
-rw-r--r--w3mimg/fb/fb.h4
-rw-r--r--w3mimg/fb/fb_gdkpixbuf.c2
-rw-r--r--w3mimg/fb/fb_imlib2.c1
-rw-r--r--w3mimg/fb/fb_w3mimg.c9
-rw-r--r--w3mimg/fb/readme.txt98
-rw-r--r--w3mimg/win/.cvsignore1
-rw-r--r--w3mimg/x11/.cvsignore1
-rw-r--r--w3mimg/x11/x11_w3mimg.c92
-rw-r--r--w3mimgdisplay.c4
13 files changed, 576 insertions, 73 deletions
diff --git a/w3mimg/.cvsignore b/w3mimg/.cvsignore
deleted file mode 100644
index f3c7a7c..0000000
--- a/w3mimg/.cvsignore
+++ /dev/null
@@ -1 +0,0 @@
-Makefile
diff --git a/w3mimg/Makefile.in b/w3mimg/Makefile.in
index dfc550c..8e2ad73 100644
--- a/w3mimg/Makefile.in
+++ b/w3mimg/Makefile.in
@@ -16,9 +16,9 @@ IMGCFLAGS=@IMGX11CFLAGS@ @IMGFBCFLAGS@ @IMGWINCFLAGS@
IMGOBJS=@IMGOBJS@
.PHONY: $(SUBDIRS)
-all: @IMGTARGETS@ w3mimg.a
+all: w3mimg.a
-w3mimg.a: $(IMGOBJS)
+w3mimg.a: w3mimg.o @IMGTARGETS@
$(AR) rv $@ $(IMGOBJS)
$(RANLIB) $@
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 <errno.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
+#if defined(__linux__)
#include <linux/fb.h>
+#elif defined(__FreeBSD__)
+#include <sys/fbio.h>
+#endif
+#if defined(__FreeBSD__)
+#include <sys/types.h>
+#include <machine/param.h>
+#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 <linux/fb.h>
+#elif defined(__FreeBSD__)
+#include <sys/fbio.h>
+#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 <glib-object.h>
-#include <gdk/gdk.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
#endif
#include <gdk-pixbuf/gdk-pixbuf.h>
#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 <X11/Xlib.h>
#include <Imlib2.h>
#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/
diff --git a/w3mimg/win/.cvsignore b/w3mimg/win/.cvsignore
deleted file mode 100644
index f3c7a7c..0000000
--- a/w3mimg/win/.cvsignore
+++ /dev/null
@@ -1 +0,0 @@
-Makefile
diff --git a/w3mimg/x11/.cvsignore b/w3mimg/x11/.cvsignore
deleted file mode 100644
index f3c7a7c..0000000
--- a/w3mimg/x11/.cvsignore
+++ /dev/null
@@ -1 +0,0 @@
-Makefile
diff --git a/w3mimg/x11/x11_w3mimg.c b/w3mimg/x11/x11_w3mimg.c
index f5be4a8..9a539de 100644
--- a/w3mimg/x11/x11_w3mimg.c
+++ b/w3mimg/x11/x11_w3mimg.c
@@ -14,7 +14,7 @@
#elif defined(USE_GDKPIXBUF)
#if defined(USE_GTK2)
#include <glib-object.h>
-#include <gdk/gdk.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gdk-pixbuf-xlib/gdk-pixbuf-xlib.h>
#else
#include <gdk-pixbuf/gdk-pixbuf-xlib.h>
@@ -121,24 +121,32 @@ x11_init(w3mimg_op * self)
if (self == NULL)
return 0;
xi = (struct x11_info *)self->priv;
+#if defined(USE_IMLIB)
if (xi == NULL)
return 0;
-#if defined(USE_IMLIB)
if (!xi->id) {
xi->id = Imlib_init(xi->display);
if (!xi->id)
return 0;
}
#elif defined(USE_GDKPIXBUF)
- if (!xi->init_flag) {
+ if (!xi) {
+#if defined(USE_GTK2)
+ g_type_init();
+#endif
+ }
+ else if (!xi->init_flag) {
+ XWindowAttributes attr;
#if defined(USE_GTK2)
g_type_init();
#endif
- gdk_pixbuf_xlib_init(xi->display, 0);
+ XGetWindowAttributes(xi->display, xi->parent, &attr);
+ /* gdk_pixbuf_xlib_init_with_depth() ignores depth, sigh... */
+ gdk_pixbuf_xlib_init_with_depth(xi->display, 0, attr.depth);
xi->init_flag = TRUE;
}
#endif
- if (!xi->imageGC) {
+ if (xi && !xi->imageGC) {
xi->imageGC = XCreateGC(xi->display, xi->parent, 0, NULL);
if (!xi->imageGC)
return 0;
@@ -200,14 +208,16 @@ x11_set_background(w3mimg_op * self, char *background)
{
XColor screen_def, exact_def;
struct x11_info *xi;
+ XWindowAttributes attr;
if (self == NULL)
return;
xi = (struct x11_info *)self->priv;
if (xi == NULL)
return;
+ XGetWindowAttributes(xi->display, xi->window, &attr);
if (background &&
- XAllocNamedColor(xi->display, DefaultColormap(xi->display, 0),
+ XAllocNamedColor(xi->display, attr.colormap,
background, &screen_def, &exact_def))
xi->background_pixel = screen_def.pixel;
else {
@@ -216,7 +226,7 @@ x11_set_background(w3mimg_op * self, char *background)
XImage *i;
p = XCreatePixmap(xi->display, xi->window, 1, 1,
- DefaultDepth(xi->display, 0));
+ attr.depth);
gc = XCreateGC(xi->display, xi->window, 0, NULL);
if (!p || !gc)
exit(1); /* XXX */
@@ -258,6 +268,7 @@ x11_img_new(struct x11_info *xi, int w, int h, int n)
{
struct x11_image *img = NULL;
int i;
+ XWindowAttributes attr;
img = malloc(sizeof(*img));
if (!img)
@@ -267,9 +278,10 @@ x11_img_new(struct x11_info *xi, int w, int h, int n)
if (!img->pixmap)
goto ERROR;
+ XGetWindowAttributes(xi->display, xi->window, &attr);
for (i = 0; i < n; i++) {
img->pixmap[i] = XCreatePixmap(xi->display, xi->parent, w, h,
- DefaultDepth(xi->display, 0));
+ attr.depth);
if (!img->pixmap[i])
goto ERROR;
@@ -318,6 +330,41 @@ resize_image(GdkPixbuf * pixbuf, int width, int height)
return NULL;
return resized_pixbuf;
}
+
+#if defined(USE_GTK2)
+static void
+render_pixbuf_to_pixmap_32(Display *display, GC gc, Pixmap pixmap, GdkPixbuf * pixbuf)
+{
+ unsigned int x, y, width, height, rowstride, bytes_per_pixel;
+ unsigned char *line;
+ XImage *image;
+
+ width = gdk_pixbuf_get_width(pixbuf) ;
+ height = gdk_pixbuf_get_height(pixbuf) ;
+
+ if (!(image = XGetImage(display, pixmap, 0, 0, width, height, AllPlanes, ZPixmap)))
+ return ;
+
+ bytes_per_pixel = (gdk_pixbuf_get_has_alpha(pixbuf)) ? 4 : 3;
+ rowstride = gdk_pixbuf_get_rowstride(pixbuf);
+ line = gdk_pixbuf_get_pixels(pixbuf);
+
+ for (y = 0; y < height; y++) {
+ u_char *pixel;
+
+ pixel = line;
+ for (x = 0; x < width; x++) {
+ XPutPixel(image, x, y,
+ (pixel[0] <<16) | (pixel[1] <<8) | pixel[2] | 0xff000000);
+ pixel += bytes_per_pixel;
+ }
+ line += rowstride;
+ }
+
+ XPutImage(display, pixmap, gc, image, 0, 0, 0, 0, width, height);
+ XDestroyImage(image);
+}
+#endif
#endif
static int
@@ -342,6 +389,7 @@ x11_load_image(w3mimg_op * self, W3MImage * img, char *fname, int w, int h)
GList *frames;
#endif
#endif
+ XWindowAttributes attr;
if (self == NULL)
return 0;
@@ -349,6 +397,7 @@ x11_load_image(w3mimg_op * self, W3MImage * img, char *fname, int w, int h)
if (xi == NULL)
return 0;
+ XGetWindowAttributes(xi->display, xi->window, &attr);
#if defined(USE_IMLIB)
im = Imlib_load_image(xi->id, fname);
if (!im)
@@ -358,7 +407,7 @@ x11_load_image(w3mimg_op * self, W3MImage * img, char *fname, int w, int h)
if (h <= 0)
h = im->rgb_height;
img->pixmap = (void *)XCreatePixmap(xi->display, xi->parent, w, h,
- DefaultDepth(xi->display, 0));
+ attr.depth);
if (!img->pixmap)
return 0;
XSetForeground(xi->display, xi->imageGC, xi->background_pixel);
@@ -374,17 +423,21 @@ x11_load_image(w3mimg_op * self, W3MImage * img, char *fname, int w, int h)
w = imlib_image_get_width();
if (h <= 0)
h = imlib_image_get_height();
+
+ im = imlib_create_cropped_scaled_image(0, 0, imlib_image_get_width(), imlib_image_get_height(), w, h);
+ imlib_context_set_image(im);
+
img->pixmap = (void *)XCreatePixmap(xi->display, xi->parent, w, h,
- DefaultDepth(xi->display, 0));
+ attr.depth);
if (!img->pixmap)
return 0;
XSetForeground(xi->display, xi->imageGC, xi->background_pixel);
XFillRectangle(xi->display, (Pixmap) img->pixmap, xi->imageGC, 0, 0, w, h);
imlib_context_set_display(xi->display);
- imlib_context_set_visual(DefaultVisual(xi->display, 0));
- imlib_context_set_colormap(DefaultColormap(xi->display, 0));
+ imlib_context_set_visual(attr.visual);
+ imlib_context_set_colormap(attr.colormap);
imlib_context_set_drawable((Drawable) img->pixmap);
- imlib_render_image_on_drawable_at_size(0, 0, w, h);
+ imlib_render_image_on_drawable(0, 0);
imlib_free_image();
#elif defined(USE_GDKPIXBUF)
max_anim = self->max_anim;
@@ -416,7 +469,7 @@ x11_load_image(w3mimg_op * self, W3MImage * img, char *fname, int w, int h)
ratio_h = 1.0 * h / ih;
}
tmp_pixmap = XCreatePixmap(xi->display, xi->parent, w, h,
- DefaultDepth(xi->display, 0));
+ attr.depth);
XSetForeground(xi->display, xi->imageGC, xi->background_pixel);
XFillRectangle(xi->display, (Pixmap) tmp_pixmap, xi->imageGC, 0, 0, w, h);
if (!tmp_pixmap) {
@@ -459,7 +512,10 @@ x11_load_image(w3mimg_op * self, W3MImage * img, char *fname, int w, int h)
if (delay > ximg->delay)
ximg->delay = delay;
- gdk_pixbuf_xlib_render_to_drawable_alpha(pixbuf,
+ if (attr.depth == 32)
+ render_pixbuf_to_pixmap_32(xi->display, xi->imageGC, ximg->pixmap[j], pixbuf);
+ else
+ gdk_pixbuf_xlib_render_to_drawable_alpha(pixbuf,
(Drawable) ximg->pixmap[j], 0,
0, 0, 0, w, h,
GDK_PIXBUF_ALPHA_BILEVEL, 1,
@@ -653,9 +709,11 @@ x11_get_image_size(w3mimg_op * self, W3MImage * img, char *fname, int *w,
if (self == NULL)
return 0;
+#if defined(USE_IMLIB) && defined(USE_IMLIB2)
xi = (struct x11_info *)self->priv;
if (xi == NULL)
return 0;
+#endif
#if defined(USE_IMLIB)
im = Imlib_load_image(xi->id, fname);
@@ -755,6 +813,9 @@ w3mimg_x11open()
return NULL;
memset(wop, 0, sizeof(w3mimg_op));
+ if (getenv("W3M_USE_REMOTE_IMAGE"))
+ goto end;
+
xi = (struct x11_info *)malloc(sizeof(struct x11_info));
if (xi == NULL)
goto error;
@@ -807,6 +868,7 @@ w3mimg_x11open()
wop->priv = xi;
+ end:
wop->init = x11_init;
wop->finish = x11_finish;
wop->active = x11_active;
diff --git a/w3mimgdisplay.c b/w3mimgdisplay.c
index 5486a47..ccfa373 100644
--- a/w3mimgdisplay.c
+++ b/w3mimgdisplay.c
@@ -281,6 +281,10 @@ DrawImage(char *buf, int redraw)
maxImage = n + 1;
imageBuf = (W3MImage *) realloc((void *)imageBuf,
sizeof(W3MImage) * maxImage);
+ if (imageBuf == NULL) {
+ fprintf(stderr, "Out of memory\n");
+ exit(1);
+ }
for (; i < maxImage; i++)
imageBuf[i].pixmap = NULL;
}