diff options
| -rw-r--r-- | ChangeLog | 23 | ||||
| -rw-r--r-- | XMakefile | 30 | ||||
| -rw-r--r-- | config.h.dist | 10 | ||||
| -rwxr-xr-x | configure | 119 | ||||
| -rw-r--r-- | w3mimg/fb/fb.c | 600 | ||||
| -rw-r--r-- | w3mimg/fb/fb.h | 16 | ||||
| -rw-r--r-- | w3mimg/fb/fb_gdkpixbuf.c | 128 | ||||
| -rw-r--r-- | w3mimg/fb/fb_gdkpixbuf.h | 15 | ||||
| -rw-r--r-- | w3mimg/fb/fb_img.c | 29 | ||||
| -rw-r--r-- | w3mimg/fb/fb_img.h | 22 | ||||
| -rw-r--r-- | w3mimg/fb/fb_imlib2.c | 150 | ||||
| -rw-r--r-- | w3mimg/fb/fb_imlib2.h | 14 | ||||
| -rw-r--r-- | w3mimg/fb/fb_w3mimg.c | 133 | ||||
| -rw-r--r-- | w3mimg/fb/license.txt | 26 | ||||
| -rw-r--r-- | w3mimg/fb/readme.txt | 69 | ||||
| -rw-r--r-- | w3mimg/w3mimg.h | 52 | ||||
| -rw-r--r-- | w3mimg/x11/x11_w3mimg.c | 330 | ||||
| -rw-r--r-- | w3mimgdisplay.c | 233 | ||||
| -rw-r--r-- | w3mimgsize.c | 29 | 
19 files changed, 1806 insertions, 222 deletions
| @@ -1,3 +1,24 @@ +2002-07-18  Fumitoshi UKAI  <ukai@debian.or.jp> + +	* merge w3m-img for framebuffer support +	* w3mimg/w3mimg.h: created +	* w3mimg/x11/x11_w3mimg.c: created +	* w3mimg/fb/fb_w3mimg.c: created +	* w3mimgsize.c w3mimgdisplay.c: modified +	* configure: modified +	* XMakefile: modified +	* config.h.dist: updated + +2002-07-18  Hiroshi Kawashima <kei@sm.sony.co.jp> + +	* w3m-img for framebuffer support +	* http://homepage3.nifty.com/slokar/fb/ +	* w3mimg/fb/fb.c w3mimg/fb/fb.h  +	  w3mimg/fb/fb_img.c w3mimg/fb/fb_img.h +	  w3mimg/fb/fb_gdkpixbuf.c w3mimg/fb/fb_gdkpixbuf.h +	  w3mimg/fb/fb_imlib2.c w3mimg/fb/fb_imlib.h +	  w3mimg/fb/readme.txt w3mimg/fb/license.txt: added +  2002-07-18  Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>  	* [w3m-dev 03263] fix lastA segfault @@ -3561,4 +3582,4 @@  	* release-0-2-1  	* import w3m-0.2.1 -$Id: ChangeLog,v 1.401 2002/07/17 16:07:37 ukai Exp $ +$Id: ChangeLog,v 1.402 2002/07/17 20:58:48 ukai Exp $ @@ -1,4 +1,4 @@ -# $Id: XMakefile,v 1.24 2002/06/18 04:59:09 inu Exp $ +# $Id: XMakefile,v 1.25 2002/07/17 20:58:48 ukai Exp $  SRCS=main.c file.c buffer.c display.c etc.c search.c linein.c table.c local.c \  	form.c map.c frame.c rc.c menu.c mailcap.c image.c\  	func.c cookie.c history.c backend.c $(KEYBIND_SRC) @@ -92,19 +92,31 @@ $(INFLATE): inflate.o  inflate.o: inflate.c  	$(CC) $(CFLAGS) $(Z_CFLAGS) -c inflate.c -$(IMGDISPLAY): w3mimgdisplay.o -	$(CC) $(CFLAGS) `imlib-config --cflags` $(LDFLAGS) -o $(IMGDISPLAY) \ -		w3mimgdisplay.o `imlib-config --libs` +$(IMGDISPLAY): w3mimgdisplay.o $(IMGOBJS) +	$(CC) $(CFLAGS) $(IMGCFLAGS) $(LDFLAGS) -o $(IMGDISPLAY) \ +		w3mimgdisplay.o $(IMGOBJS) $(IMGLDFLAGS) -$(IMGSIZE): w3mimgsize.o -	$(CC) $(CFLAGS) `imlib-config --cflags` $(LDFLAGS) -o $(IMGSIZE) \ -		w3mimgsize.o `imlib-config --libs` +$(IMGSIZE): w3mimgsize.o $(IMGOBJS) +	$(CC) $(CFLAGS) $(IMGCFLAGS) $(LDFLAGS) -o $(IMGSIZE) \ +		w3mimgsize.o $(IMGOBJS) $(IMGLDFLAGS)  w3mimgdisplay.o: w3mimgdisplay.c -	$(CC) $(CFLAGS) `imlib-config --cflags` -c w3mimgdisplay.c +	$(CC) $(CFLAGS) $(IMGCFLAGS) -c w3mimgdisplay.c  w3mimgsize.o: w3mimgsize.c -	$(CC) $(CFLAGS) `imlib-config --cflags` -c w3mimgsize.c +	$(CC) $(CFLAGS) $(IMGCFLAGS) -c w3mimgsize.c + +w3mimg/x11/x11_w3mimg.o: w3mimg/x11/x11_w3mimg.c +	$(CC) $(CFLAGS) $(IMGCFLAGS) -o $@ -c w3mimg/x11/x11_w3mimg.c + +w3mimg/fb/fb_w3mimg.o: w3mimg/fb/fb_w3mimg.c +	$(CC) $(CFLAGS) $(IMGCFLAGS) -o $@ -c w3mimg/fb/fb_w3mimg.c + +w3mimg/fb/fb.o: w3mimg/fb/fb.c +	$(CC) $(CFLAGS) $(IMGCFLAGS) -o $@ -c w3mimg/fb/fb.c + +w3mimg/fb/fb_img.o: w3mimg/fb/fb_img.c w3mimg/fb/fb_gdkpixbuf.c w3mimg/fb/fb_imlib2.c +	$(CC) $(CFLAGS) $(IMGCFLAGS) -o $@ -c w3mimg/fb/fb_img.c  gc/gc.a:  	cd gc; $(MAKE) base_lib gc.a CC='$(CC)' CFLAGS='$(GCCFLAGS) $(GC_CFLAGS)' SPECIALCFLAGS='-I./\$(srcdir)/include $(GC_CFLAGS)' diff --git a/config.h.dist b/config.h.dist index 2d37c0c..94b8053 100644 --- a/config.h.dist +++ b/config.h.dist @@ -85,6 +85,11 @@ MATHLIB=-lm  Z_CFLAGS=-I/usr/include  ZLIB=-L/usr/lib -lz  EXT_TARGETS=$(BOOKMARKER) $(HELPER) $(INFLATE) +IMGCFLAGS= +IMGLDFLAGS= +IMGX11CFLAGS= +IMGFBCFLAGS= +IMGOBJS=  GC_CFLAGS=  GCLIB=gc/gc.a  GCTARGET=gc/gc.a @@ -125,6 +130,11 @@ MODEL=Linux.i686-monster-ja  #define USE_EXTERNAL_URI_LOADER  #undef USE_ALARM  #undef USE_IMAGE +#undef USE_W3MIMG_X11 +#undef USE_W3MIMG_FB +#undef USE_IMLIB +#undef USE_GDKPIXBUF +#undef USE_IMLIB2  #define USE_HELP_CGI  #undef USE_XFACE @@ -1,5 +1,5 @@  #!/bin/sh -# $Id: configure,v 1.69 2002/05/14 15:30:01 ukai Exp $ +# $Id: configure,v 1.70 2002/07/17 20:58:48 ukai Exp $  #	Configuration.  # @@ -439,7 +439,7 @@ find_imlib() {    version=`$IMLIB_CONFIG --version`    if [ "x$version" = x ]; then      echo "You don't have Imlib. Install Imlib (version >= $imlib_version)." -    exit 1 +    return 1    fi    major=`echo "$version" | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1/'`    minor=`echo "$version" | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\2/'` @@ -447,8 +447,59 @@ find_imlib() {    echo "The version of Imlib is $version."    if [ "$major" -ne $imlib_major -o "$minor" -ne $imlib_minor -o "$micro" -lt $imlib_micro ]; then      echo "Imlib is too old. Install Imlib (version >= $imlib_version)." -    exit 1 +    return 1 +  fi +  return 0 +} + +find_imlib2() { +  imlib_major=1 +  imlib_minor=0 +  imlib_micro=5 +  imlib_version=$imlib_major.$imlib_minor.$imlib_micro +  echo "Checking Imlib 2." +  if [ "x$IMLIB2_CONFIG" = x ]; then +    IMLIB2_CONFIG=imlib2-config +  fi +  version=`$IMLIB2_CONFIG --version` +  if [ "x$version" = x ]; then +    echo "You don't have Imlib 2. Install Imlib 2 (version >= $imlib_version)." +    return 1 +  fi +  major=`echo "$version" | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1/'` +  minor=`echo "$version" | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\2/'` +  micro=`echo "$version" | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\3/'` +  echo "The version of Imlib 2 is $version." +  if [ "$major" -ne $imlib_major -o "$minor" -lt $imlib_minor -o "$micro" -lt $imlib_micro ]; then +    echo "Imlib 2 is too old. Install Imlib 2 (version >= $imlib_version)." +    return 1 +  fi +  return 0 +} + +find_gdkpixbuf() { +  gdkpixbuf_major=0 +  gdkpixbuf_minor=16 +  gdkpixbuf_micro=0 +  gdkpixbuf_version=$gdkpixbuf_major.$gdkpixbuf_minor.$gdkpixbuf_micro +  echo "Checking GdkPixbuf ." +  if [ "x$GDKPIXBUF_CONFIG" = x ]; then +    GDKPIXBUF_CONFIG=gdk-pixbuf-config +  fi +  version=`$GDKPIXBUF_CONFIG --version` +  if [ "x$version" = x ]; then +    echo "You don't have GdkPixbuf. Install GdkPixbuf (version >= $gdkpixbuf_version)." +    return 1 +  fi +  major=`echo "$version" | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1/'` +  minor=`echo "$version" | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\2/'` +  micro=`echo "$version" | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\3/'` +  echo "The version of GdkPixbuf is $version." +  if [ "$major" -ne $gdkpixbuf_major -o "$minor" -lt $gdkpixbuf_minor -o "$micro" -lt $gdkpixbuf_micro ]; then +    echo "GdkPixbuf is too old. Install GdkPixbuf (version >= $gdkpixbuf_version)." +    return 1    fi +  return 0  }  #-------------------------------------------------------------- @@ -736,13 +787,21 @@ else    def_param "use_digest_auth" n  fi -ask_param "Inline image support (you need Imlib library)" use_image n +ask_param "Inline image support" use_image n  if [ "$use_image" = y ]; then    def_use_image="#define USE_IMAGE"    imgtarget='$(IMGDISPLAY) $(IMGSIZE)' +  ask_param "X11 inline image support (you need Imlib1 library)" use_w3mimg_x11 y +  d_w3mimg_fb=n +  if test -e /dev/fb0; then +      d_w3mimg_fb=y +  fi +  ask_param "Linux Framebuffer inline image support (you need Imlib2 or GdkPixbuf)" use_w3mimg_fb $d_w3mimg_fb  else    def_use_image="#undef USE_IMAGE"    imgtarget='' +  use_w3mimg_x11=n +  use_w3mimg_fb=n  fi  if [ "$use_color" = y ]; then @@ -1974,8 +2033,48 @@ else    echo "You have IPv6 support."  fi +def_use_w3mimg_x11="#undef USE_W3MIMG_X11" +def_use_w3mimg_fb="#undef USE_W3MIMG_FB" +def_use_imlib='#undef USE_IMLIB' +def_use_gdkpixbuf='#undef USE_GDKPIXBUF' +def_use_imlib2='#undef USE_IMLIB2' +imgx11cflags='' +imgfbcflags='' +imgx11ldflags='' +imgfbldflags='' +imbobjs='' +  if [ "$use_image" = y ]; then -  find_imlib +  if [ "$use_w3mimg_x11" = y ]; then +      if find_imlib; then +	  def_use_w3mimg_x11="#define USE_W3MIMG_X11" +	  def_use_imlib='#define USE_IMLIB' +	  imgobjs="$imgobjs w3mimg/x11/x11_w3mimg.o" +	  imgx11cflags='`imlib-config --cflags`' +	  imgx11ldflags='`imlib-config --libs`' +      else +	  use_w3mimg_x11=n +	  echo "Disable X11 inline image" +      fi +  fi +  if [ "$use_w3mimg_fb" = y ]; then +      if find_gdkpixbuf; then +	  def_use_w3mimg_fb="#define USE_W3MIMG_FB" +	  imgobjs="$imgobjs w3mimg/fb/fb_w3mimg.o w3mimg/fb/fb.o w3mimg/fb/fb_img.o" +	  def_use_gdkpixbuf='#define USE_GDKPIXBUF' +	  imgfbcflags='`gdk-pixbuf-config --cflags`' +	  imgfbldflags='`gdk-pixbuf-config --libs`' +      elif find_imlib2; then +	  def_use_imlib2='#define USE_IMLIB2' +	  imgobjs="$imgobjs w3mimg/fb/fb_w3mimg.o w3mimg/fb/fb.o w3mimg/fb/fb_img.o" +	  def_use_imlib2='#define USE_IMLIB2' +	  imgfbcflags='`imlib2-config --cflags`' +	  imgfbldflags='`imlib2-config --libs`' +      else +	  use_w3mimg_fb=n +	  echo "Disable Linux framebuffer inline image" +      fi +  fi  fi  rm -f _zmachdep$extension _zmachdep.c _zmachdep.o @@ -2108,6 +2207,11 @@ MATHLIB=$mathlib  Z_CFLAGS=$z_cflags  ZLIB=$zlib  EXT_TARGETS=\$(BOOKMARKER) \$(HELPER) $inflate $imgtarget +IMGCFLAGS=$imgx11cflags $imgfbcflags +IMGLDFLAGS=$imgx11ldflags $imgfbldflags +IMGX11CFLAGS=$imgx11cflags +IMGFBCFLAGS=$imgfbcflags +IMGOBJS=$imgobjs  GC_CFLAGS=$gc_cflags  GCLIB=$gclib $pthreadlib  GCTARGET=$gctarget @@ -2149,6 +2253,11 @@ $def_use_nntp  $def_use_gopher  $def_use_alarm  $def_use_image +$def_use_w3mimg_x11 +$def_use_w3mimg_fb +$def_use_imlib +$def_use_gdkpixbuf +$def_use_imlib2  $def_use_help_cgi  $def_use_xface diff --git a/w3mimg/fb/fb.c b/w3mimg/fb/fb.c new file mode 100644 index 0000000..5ac319b --- /dev/null +++ b/w3mimg/fb/fb.c @@ -0,0 +1,600 @@ +/************************************************************************** +                fb.c 0.2 Copyright (C) 2002, hito + **************************************************************************/ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <fcntl.h> +#include <limits.h> +#include <errno.h> +#include <sys/ioctl.h> +#include <sys/mman.h> +#include <linux/fb.h> + +#include "fb.h" + +#define FB_ENV		"FRAMEBUFFER" +#define	FB_DEFDEV	"/dev/fb0" + +#define FALSE 0 +#define TRUE  1 + +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 struct fb_fix_screeninfo	fscinfo; +static struct fb_var_screeninfo	vscinfo; +static struct fb_cmap *cmap = NULL; +static int is_open = FALSE; +static int fbfp = -1; +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){ +    printf("FB_VISUAL_PSEUDOCOLOR\n"); +    if(vscinfo.bits_per_pixel!=8){ +      fprintf(stderr, "未対応フレームバッファ\n"); +      goto ERR_END; +    } + +    if(fb_cmap_get(fbfp,cmap)){ +      fprintf(stderr, "カラーマップ獲得失敗\n"); +      //      fb_cmap_destroy(cmap); +      goto ERR_END; +    } +    //    fb_cmap_disp(cmap); + +    if(cmap->len <(LINUX_LOGO_COLORS + LOGO_COLOR_OFFSET)){ +      fprintf(stderr, "色の割付領域が不足しています\n"); +      goto ERR_END; +    } + +    cmap->start = LOGO_COLOR_OFFSET; +    cmap->len   = LINUX_LOGO_COLORS; + +    for(lp = 0; lp < LINUX_LOGO_COLORS; lp++){ +      if(cmap->red){ +	*(cmap->red+lp) = (linux_logo_red[lp]<<CHAR_BIT)+linux_logo_red[lp]; +      } +      if(cmap->green){ +	*(cmap->green+lp)= (linux_logo_green[lp]<<CHAR_BIT)+linux_logo_green[lp]; +      } +      if(cmap->blue){ +	*(cmap->blue+lp)= (linux_logo_blue[lp]<<CHAR_BIT)+linux_logo_blue[lp]; +      } +    } +    if(fb_cmap_set(fbfp,cmap)){ +      fb_cmap_destroy(cmap); +      fprintf(stderr, "カラーマップ獲得失敗\n"); +      goto ERR_END; +    } +  } +    */ + +  if(!(fscinfo.visual == FB_VISUAL_TRUECOLOR && +     (vscinfo.bits_per_pixel == 15 || +      vscinfo.bits_per_pixel == 16 || +      vscinfo.bits_per_pixel == 24 || +      vscinfo.bits_per_pixel == 32))){ +    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(buf != NULL){ +    fb_munmap(buf,&fscinfo); +    buf = NULL; +  } + +  if(fbfp >= 0){ +    close(fbfp); +  } + +  is_open = FALSE; +} + +void fb_pset(int x, int y, int r, int g, int b) +{ +  unsigned long work; +  int offset; +  static size_t size = 0; + +  if(is_open != TRUE || x >= vscinfo.xres || y >= vscinfo.yres) +    return; + +  if(size == 0) +    size = (vscinfo.bits_per_pixel + 7) / CHAR_BIT; + +  offset = fscinfo.line_length * y + size * x; + +  if(offset >= fscinfo.smem_len) +    return; + +  work= +    ((r >> (CHAR_BIT - vscinfo.red.length  )) << vscinfo.red.offset)+ +    ((g >> (CHAR_BIT - vscinfo.green.length)) << vscinfo.green.offset)+ +    ((b >> (CHAR_BIT - vscinfo.blue.length )) << vscinfo.blue.offset); +  memcpy(buf + offset, &work, size); +} + +int fb_get_color(int x, int y, int *r, int *g, int *b) +{ +  unsigned long work = 0; +  int offset; +  static size_t size = 0; + +  if(is_open != TRUE || x >= vscinfo.xres || y >= vscinfo.yres) +    return 1; + +  if(size == 0) +    size = (vscinfo.bits_per_pixel + 7) / CHAR_BIT; + +  offset = fscinfo.line_length * y + size * x; +  if(offset >= fscinfo.smem_len) +    return 1; + +  memcpy(&work, buf + offset, size); + +  *r = ((work >> vscinfo.red.offset) & (0x000000ff >> (CHAR_BIT - vscinfo.red.length))) +	      << (CHAR_BIT - vscinfo.red.length); +  *g = ((work >> vscinfo.green.offset) & (0x000000ff >> (CHAR_BIT - vscinfo.green.length))) +	      <<(CHAR_BIT - vscinfo.green.length); +  *b = ((work >> vscinfo.blue.offset)  & (0x000000ff >> (CHAR_BIT - vscinfo.blue.length))) +	      << (CHAR_BIT - vscinfo.blue.length); +  return 0; +} + +void fb_clear(void) +{ +  if(is_open != TRUE) +    return; + +  memset(buf, 0, (vscinfo.xres * vscinfo.yres * vscinfo.bits_per_pixel) / CHAR_BIT); +} + +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; +} + +void fb_cmap_disp(void) +{ +  int lp; + +  if(is_open != TRUE) +    return; + +  printf("cmap DUMP\n"); +  printf("start		:[%08x]\n", cmap->start); +  printf("len		:[%08x]\n", cmap->len); +  printf("red		:[%8p]\n", cmap->red); +  if(cmap->red){ +    for(lp=0;lp<cmap->len;lp++){ +      if((lp+1)%16==0) printf("%04x\n",*(cmap->red+lp)); +      else printf("%04x ",*(cmap->red+lp)); +    } +    if(lp%16) printf("\n"); +  } +  printf("green		:[%8p]\n",cmap->green); +  if(cmap->green){ +    for(lp=0;lp<cmap->len;lp++){ +      if((lp+1)%16==0) printf("%04x\n",*(cmap->green+lp)); +      else printf("%04x ",*(cmap->green+lp)); +    } +    if(lp%16) printf("\n"); +  } +  printf("blue		:[%8p]\n",cmap->blue); +  if(cmap->blue){ +    for(lp=0;lp<cmap->len;lp++){ +      if((lp+1)%16==0) printf("%04x\n",*(cmap->blue+lp)); +      else printf("%04x ",*(cmap->blue+lp)); +    } +    if(lp%16) printf("\n"); +  } +  printf("transp		:[%8p]\n",cmap->transp); +  if(cmap->transp){ +    for(lp=0;lp<cmap->len;lp++){ +      if((lp+1)%16==0) printf("%04x\n",*(cmap->transp+lp)); +      else printf("%04x ",*(cmap->transp+lp)); +    } +    if(lp%16) printf("\n"); +  } +  return; +} + + +void fb_fscrn_disp(void) +{ +  if(is_open != TRUE) +    return; + +  printf("scinfo[%8p] DUMP\n",      &fscinfo); +  printf("id		:[%s]\n",    fscinfo.id); +  printf("smem_start	:[%08lx]\n", fscinfo.smem_start); +  printf("smem_len	:[%d]\n",    fscinfo.smem_len); +  printf("type		:[%d] ",     fscinfo.type); +  switch(fscinfo.type){ +  case FB_TYPE_PACKED_PIXELS: +    printf("FB_TYPE_PACKED_PIXELS\n");break; +  case FB_TYPE_PLANES: +    printf("FB_TYPE_PLANES\n");break; +  case FB_TYPE_INTERLEAVED_PLANES: +    printf("FB_TYPE_INTERLEAVED_PLANES\n");break; +  case FB_TYPE_TEXT: +    printf("FB_TYPE_TEXT\n");break; +  default:printf("Unknown type.\n"); +  } +  printf("type_aux	:[%d] ",fscinfo.type_aux); +  switch(fscinfo.type_aux){ +  case FB_AUX_TEXT_MDA: +    printf("FB_AUX_TEXT_MDA\n");break; +  case FB_AUX_TEXT_CGA: +    printf("FB_AUX_TEXT_CGA\n");break; +  case FB_AUX_TEXT_S3_MMIO: +    printf("FB_AUX_TEXT_S3_MMIO\n");break; +  case FB_AUX_TEXT_MGA_STEP16: +    printf("FB_AUX_TEXT_MGA_STEP16\n");break; +  case FB_AUX_TEXT_MGA_STEP8: +    printf("FB_AUX_TEXT_MGA_STEP8\n");break; +  default:printf("Unknown type_aux.\n"); +  } +  printf("visual		:[%d] ",fscinfo.visual); +  switch(fscinfo.visual){ +  case FB_VISUAL_MONO01: +    printf("FB_VISUAL_MONO01\n");break; +  case FB_VISUAL_MONO10: +    printf("FB_VISUAL_MONO10\n");break; +  case FB_VISUAL_TRUECOLOR: +    printf("FB_VISUAL_TRUECOLOR\n");break; +  case FB_VISUAL_PSEUDOCOLOR: +    printf("FB_VISUAL_PSEUDOCOLOR\n");break; +  case FB_VISUAL_DIRECTCOLOR: +    printf("FB_VISUAL_DIRECTCOLOR\n");break; +  case FB_VISUAL_STATIC_PSEUDOCOLOR: +    printf("FB_VISUAL_STATIC_PSEUDOCOLOR\n");break; +  default:printf("Unknown Visual mode.\n"); +  } +  printf("xpanstep	:[%d]\n",fscinfo.xpanstep); +  printf("ypanstep	:[%d]\n",fscinfo.ypanstep); +  printf("ywrapstep	:[%d]\n",fscinfo.ywrapstep); +  printf("line_length	:[%d]\n",fscinfo.line_length); +  printf("mmio_start	:[%08lx]\n",fscinfo.mmio_start); +  printf("mmio_len	:[%d]\n",fscinfo.mmio_len); +  printf("accel		:[%d] ",fscinfo.accel); +  switch(fscinfo.accel){ +  case FB_ACCEL_NONE: +    printf("FB_ACCEL_NONE\n");break; +  case FB_ACCEL_ATARIBLITT: +    printf("FB_ACCEL_ATARIBLITT\n");break; +  case FB_ACCEL_AMIGABLITT: +    printf("FB_ACCEL_AMIGABLITT\n");break; +  case FB_ACCEL_S3_TRIO64: +    printf("FB_ACCEL_S3_TRIO64\n");break; +  case FB_ACCEL_NCR_77C32BLT: +    printf("FB_ACCEL_NCR_77C32BLT\n");break; +  case FB_ACCEL_S3_VIRGE: +    printf("FB_ACCEL_S3_VIRGE\n");break; +  case FB_ACCEL_ATI_MACH64GX: +    printf("FB_ACCEL_ATI_MACH64GX\n");break; +  case FB_ACCEL_DEC_TGA: +    printf("FB_ACCEL_DEC_TGA\n");break; +  case FB_ACCEL_ATI_MACH64CT: +    printf("FB_ACCEL_ATI_MACH64CT\n");break; +  case FB_ACCEL_ATI_MACH64VT: +    printf("FB_ACCEL_ATI_MACH64VT\n");break; +  case FB_ACCEL_ATI_MACH64GT: +    printf("FB_ACCEL_ATI_MACH64GT\n");break; +  case FB_ACCEL_SUN_CREATOR: +    printf("FB_ACCEL_SUN_CREATOR\n");break; +  case FB_ACCEL_SUN_CGSIX: +    printf("FB_ACCEL_SUN_CGSIX\n");break; +  case FB_ACCEL_SUN_LEO: +    printf("FB_ACCEL_SUN_LEO\n");break; +  case FB_ACCEL_IMS_TWINTURBO: +    printf("FB_ACCEL_IMS_TWINTURBO\n");break; +  case FB_ACCEL_3DLABS_PERMEDIA2: +    printf("FB_ACCEL_3DLABS_PERMEDIA2\n");break; +  case FB_ACCEL_MATROX_MGA2064W: +    printf("FB_ACCEL_MATROX_MGA2064W\n");break; +  case FB_ACCEL_MATROX_MGA1064SG: +    printf("FB_ACCEL_MATROX_MGA1064SG\n");break; +  case FB_ACCEL_MATROX_MGA2164W: +    printf("FB_ACCEL_MATROX_MGA2164W\n");break; +  case FB_ACCEL_MATROX_MGA2164W_AGP: +    printf("FB_ACCEL_MATROX_MGA2164W_AGP\n");break; +  case FB_ACCEL_MATROX_MGAG100: +    printf("FB_ACCEL_MATROX_MGAG100\n");break; +  case FB_ACCEL_MATROX_MGAG200: +    printf("FB_ACCEL_MATROX_MGAG200\n");break; +  case FB_ACCEL_SUN_CG14: +    printf("FB_ACCEL_SUN_CG14\n");break; +  case FB_ACCEL_SUN_BWTWO: +    printf("FB_ACCEL_SUN_BWTWO\n");break; +  case FB_ACCEL_SUN_CGTHREE: +    printf("FB_ACCEL_SUN_CGTHREE\n");break; +  case FB_ACCEL_SUN_TCX: +    printf("FB_ACCEL_SUN_TCX\n");break; +  default:printf("Unknown Visual mode.\n"); +  } +  return; +} + +void fb_vscrn_disp(void) +{ +  if(is_open != TRUE) +    return; +  printf("vscinfo DUMP\n"); +  printf("xres		:[%d]\n",vscinfo.xres); +  printf("yres		:[%d]\n",vscinfo.yres); +  printf("xres_virtual	:[%d]\n",vscinfo.xres_virtual); +  printf("yres_virtual	:[%d]\n",vscinfo.yres_virtual); +  printf("xoffset		:[%d]\n",vscinfo.xoffset); +  printf("yoffset		:[%d]\n",vscinfo.yoffset); +  printf("bits_per_pixel	:[%d]\n",vscinfo.bits_per_pixel); +  printf("grayscale	:[%d]\n",vscinfo.grayscale); +  printf("red.offset	:[%d]\n",vscinfo.red.offset); +  printf("red.length	:[%d]\n",vscinfo.red.length); +  printf("red.msb_right	:[%d]\n",vscinfo.red.msb_right); +  printf("green.offset	:[%d]\n",vscinfo.green.offset); +  printf("green.length	:[%d]\n",vscinfo.green.length); +  printf("green.msb_right	:[%d]\n",vscinfo.green.msb_right); +  printf("blue.offset	:[%d]\n",vscinfo.blue.offset); +  printf("blue.length	:[%d]\n",vscinfo.blue.length); +  printf("blue.msb_right	:[%d]\n",vscinfo.blue.msb_right); +  printf("transp.offset	:[%d]\n",vscinfo.transp.offset); +  printf("transp.length	:[%d]\n",vscinfo.transp.length); +  printf("transp.msb_right:[%d]\n",vscinfo.transp.msb_right); +  printf("nonstd		:[%d]\n",vscinfo.nonstd); +  printf("activate	:[%d]\n",vscinfo.activate); +  printf("height		:[%d]\n",vscinfo.height); +  printf("width		:[%d]\n",vscinfo.width); +  printf("accel_flags	:[%d]\n",vscinfo.accel_flags); +  printf("pixclock	:[%d]\n",vscinfo.pixclock); +  printf("left_margin	:[%d]\n",vscinfo.left_margin); +  printf("right_margin	:[%d]\n",vscinfo.right_margin); +  printf("upper_margin	:[%d]\n",vscinfo.upper_margin); +  printf("lower_margin	:[%d]\n",vscinfo.lower_margin); +  printf("hsync_len	:[%d]\n",vscinfo.hsync_len); +  printf("vsync_len	:[%d]\n",vscinfo.vsync_len); +  printf("sync		:[%d]\n",vscinfo.sync); +  printf("vmode		:[%d]\n",vscinfo.vmode); +  return; +} + +/********* static functions **************/ + +/* +	(struct fb_cmap)デバイスに依存しないカラーマップ情報 + +	fb_cmap_create()	新規のカラーマップ情報 +	fb_cmap_destroy()	カラーマップ情報の破棄 +	fb_cmap_disp()		情報の表示 +	fb_cmap_get()		情報の獲得 +	fb_cmap_set()		情報の設定 +*/ + +#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; + +	/* カラーマップの存在チェック */ +	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)); + +	/* 各分色が存在しそうだったらカラーマップ用の領域を確保 */ +	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; +} +*/ +/* +	フレームバッファに対するアクセス + +	fb_mmap()		フレームバッファのメモリ上へのマップ +	fb_munmap()		フレームバッファのメモリ上からのアンマップ +*/ + +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)デバイスに依存しない固定された情報 + +	fb_fscrn_disp()		情報の表示 +	fb_fscrn_get()		情報の獲得 +*/ + + +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)デバイスに依存しない変更可能な情報 + +	fb_vscrn_disp()		情報の表示 +	fb_vscrn_get()		情報の獲得 +	fb_vscrn_set()		情報の設定 +*/ + + +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; +} + +/* +static int fb_vscrn_set(int fbfp,struct fb_var_screeninfo* scinfo) +{ +	if(ioctl(fbfp,FBIOPUT_VSCREENINFO,scinfo)){ +		perror("ioctl FBIOPUT_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..ebe8aef --- /dev/null +++ b/w3mimg/fb/fb.h @@ -0,0 +1,16 @@ +#ifndef fb_header +#define fb_header +#include <linux/fb.h> + +int  fb_open(void); +void fb_close(void); +void fb_pset(int x, int y, int r, int g, int b); +void fb_clear(void); +int  fb_width(void); +int  fb_height(void); +void fb_cmap_disp(void); +void fb_fscrn_disp(void); +void fb_vscrn_disp(void); +int fb_get_color(int x, int y, int *r, int *g, int *b); + +#endif diff --git a/w3mimg/fb/fb_gdkpixbuf.c b/w3mimg/fb/fb_gdkpixbuf.c new file mode 100644 index 0000000..8a505ce --- /dev/null +++ b/w3mimg/fb/fb_gdkpixbuf.c @@ -0,0 +1,128 @@ +/************************************************************************** +                fb_gdkpixbuf.c 0.2 Copyright (C) 2002, hito + **************************************************************************/ + +#include "fb.h" +#include "fb_img.h" + +static void set_prm(IMAGE *img); + +IMAGE *fb_load_image(char *filename, int w, int h) +{ +  GdkPixbuf *pixbuf; +  IMAGE *img; + +  if(filename == NULL) +    return NULL; + +  img = malloc(sizeof(*img)); +  if(img == NULL) +    return NULL; +   +  pixbuf = gdk_pixbuf_new_from_file(filename); +  if(pixbuf == NULL){ +    free(img); +    return NULL; +  } + +  img->pixbuf = pixbuf; +  set_prm(img); + +  fb_resize_image(img, w, h); + +  return img; +} + +int fb_draw_image(IMAGE *img, int x, int y, int sx, int sy, int width, int height) +{ +  int i, j, r, g, b, offset, bpp; + +  if(img == NULL) +    return 1; + +  bpp = img->rowstride / img->width; +  for(j = sy; j < sy + height && j < img->height; j++){ +    offset = j * img->rowstride + bpp * sx; +    for(i = sx; i < sx + width && i < img->width; i++, offset += bpp){ +      r = img->pixels[offset]; +      g = img->pixels[offset + 1]; +      b = img->pixels[offset + 2]; +      if(img->alpha && img->pixels[offset + 3] == 0) +	fb_pset(i + x - sx, j + y - sy, bg_r, bg_g, bg_b); +      else +	fb_pset(i + x - sx, j + y - sy, r, g, b); +    } +  } +  return 0; +} + +int fb_resize_image(IMAGE *img, int width, int height) +{ +  GdkPixbuf *pixbuf; +  if(width < 1 || height < 1 || img == NULL) +    return 1; + +  if(width == img->width && height == img->height) +    return 0; + +  pixbuf = gdk_pixbuf_scale_simple(img->pixbuf, width, height, GDK_INTERP_HYPER); +  if(pixbuf == NULL) +    return 1; +  gdk_pixbuf_finalize(img->pixbuf); + +  img->pixbuf = pixbuf; +  set_prm(img); +  return 0; +} + +void fb_free_image(IMAGE *img) +{ +  if(img == NULL) +    return; + +  gdk_pixbuf_finalize(img->pixbuf); +  free(img); +} + +IMAGE *fb_dup_image(IMAGE *img) +{ +  GdkPixbuf *pixbuf; +  IMAGE *new_img; + +  if(img == NULL) +    return NULL; + +  new_img = malloc(sizeof(*img)); +  if(new_img == NULL) +    return NULL; + +  pixbuf = gdk_pixbuf_copy(img->pixbuf); +  if(pixbuf == NULL){ +    free(new_img); +    return NULL; +  } + +  new_img->pixbuf = pixbuf; +  set_prm(new_img); +  return new_img; +} + +int fb_rotate_image(IMAGE *img, int angle) +{ +  return 1; +} + +static void set_prm(IMAGE *img) +{ +  GdkPixbuf *pixbuf; + +  if(img == NULL) +    return; +  pixbuf = img->pixbuf; + +  img->pixels = gdk_pixbuf_get_pixels(pixbuf); +  img->width  = gdk_pixbuf_get_width(pixbuf); +  img->height = gdk_pixbuf_get_height(pixbuf); +  img->alpha  = gdk_pixbuf_get_has_alpha(pixbuf); +  img->rowstride = gdk_pixbuf_get_rowstride(pixbuf); +} diff --git a/w3mimg/fb/fb_gdkpixbuf.h b/w3mimg/fb/fb_gdkpixbuf.h new file mode 100644 index 0000000..b95d34c --- /dev/null +++ b/w3mimg/fb/fb_gdkpixbuf.h @@ -0,0 +1,15 @@ +#ifndef fb_gdkpixbuf_header +#define fb_gdkpixbuf_header + +#include <gdk-pixbuf/gdk-pixbuf.h> + +typedef struct { +  int width; +  int height; +  int rowstride; +  int alpha; +  GdkPixbuf *pixbuf; +  guchar    *pixels; +} IMAGE; + +#endif diff --git a/w3mimg/fb/fb_img.c b/w3mimg/fb/fb_img.c new file mode 100644 index 0000000..06da9ac --- /dev/null +++ b/w3mimg/fb/fb_img.c @@ -0,0 +1,29 @@ +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/wait.h> +#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 + +int fb_draw_image_simple(IMAGE *img, int x, int y) +{ +  return fb_draw_image(img, x, y, 0, 0, img->width, img->height); +} + +void fb_set_bg(int r, int g, int b) +{ +  bg_r = r; +  bg_g = g; +  bg_b = b; +} diff --git a/w3mimg/fb/fb_img.h b/w3mimg/fb/fb_img.h new file mode 100644 index 0000000..f29a0a7 --- /dev/null +++ b/w3mimg/fb/fb_img.h @@ -0,0 +1,22 @@ +#ifndef fb_img_header +#define fb_img_header +#include "config.h" + +#if defined(USE_IMLIB2) + #include "w3mimg/fb/fb_imlib2.h" +#elif defined(USE_GDKPIXBUF) + #include "w3mimg/fb/fb_gdkpixbuf.h" +#else +#error no Imlib2 and GdkPixbuf support +#endif + +IMAGE *fb_load_image(char *filename, int w, int h); +int    fb_draw_image(IMAGE *img, int x, int y, int sx, int sy, int width, int height); +int    fb_draw_image_simple(IMAGE *img, int x, int y); +int    fb_resize_image(IMAGE *img, int width, int height); +void   fb_free_image(IMAGE *img); +void   fb_set_bg(int r, int g, int b); +IMAGE *fb_dup_image(IMAGE *img); +int    fb_rotate_image(IMAGE *img, int angle); + +#endif diff --git a/w3mimg/fb/fb_imlib2.c b/w3mimg/fb/fb_imlib2.c new file mode 100644 index 0000000..3c42ce8 --- /dev/null +++ b/w3mimg/fb/fb_imlib2.c @@ -0,0 +1,150 @@ +/************************************************************************** +                fb_imlib2.c 0.2 Copyright (C) 2002, hito + **************************************************************************/ + +#include "fb.h" +#include "fb_img.h" + +static void set_prm(IMAGE *img); + +IMAGE *fb_load_image(char *filename, int w, int h) +{ +  Imlib_Image image; +  IMAGE *img; + +  if(filename == NULL) +    return NULL; + +  img = malloc(sizeof(*img)); +  if(img == NULL) +    return NULL; + +  image = imlib_load_image(filename); +  if(image == NULL){ +    free(img); +    return NULL; +  } + +  imlib_context_set_image(image); + +  img->image = image; +  set_prm(img); + +  fb_resize_image(img, w, h); + +  return img; +} + +int fb_draw_image(IMAGE *img, int x, int y, int sx, int sy, int width, int height) +{ +  int i, j, r, g, b, a = 0, offset; + +  if(img == NULL) +    return 1; + +  for(j = sy; j < sy + height && j < img->height; j++){ +    offset = j * img->width; +    for(i = sx; i < sx + width && i < img->width; i++){ +      a = (img->data[offset + i] >> 24) & 0x000000ff; +      r = (img->data[offset + i] >> 16) & 0x000000ff; +      g = (img->data[offset + i] >>  8) & 0x000000ff; +      b = (img->data[offset + i]      ) & 0x000000ff; + +      if(a == 0) +	fb_pset(i + x - sx, j + y - sy, bg_r, bg_g, bg_b); +      else +	fb_pset(i + x - sx, j + y - sy, r, g, b); +    } +  } +  return 0; +} + +int fb_resize_image(IMAGE *img, int width, int height) +{ +  Imlib_Image image; + +  if(width < 1 || height < 1 || img == NULL) +    return 1; + +  if(width == img->width && height == img->height) +    return 0; + +  image = imlib_create_cropped_scaled_image(0, 0, img->width, img->height, width, height); +  if(image == NULL) +    return 1; + +  imlib_context_set_image(img->image); +  imlib_free_image(); + +  img->image = image; +  set_prm(img); +  return 0; +} + +void fb_free_image(IMAGE *img) +{ +  if(img == NULL) +    return; + +  imlib_context_set_image(img->image); +  imlib_free_image(); +  free(img); +} + +IMAGE *fb_dup_image(IMAGE *img) +{ +  Imlib_Image image; +  IMAGE *new_img; + +  if(img == NULL) +    return NULL; + +  new_img = malloc(sizeof(*img)); +  if(new_img == NULL) +    return NULL; + +  imlib_context_set_image(img->image); +  image = imlib_clone_image(); + +  if(image == NULL){ +    free(new_img); +    return NULL; +  } + +  new_img->image = image; +  set_prm(new_img); +  return new_img; +} + +int fb_rotate_image(IMAGE *img, int angle) +{ +  int orientation; + +  if(img == NULL) +    return 1; + +  imlib_context_set_image(img->image); + +  if(angle == 90){ +    orientation = 1; +  }else if(angle == -90){ +    orientation = 3; +  }else{ +    return 1; +  } + +  imlib_image_orientate(orientation); +  set_prm(img); +  return 0; +} + +static void set_prm(IMAGE *img) +{ +  if(img == NULL) +    return; + +  imlib_context_set_image(img->image); +  img->data   = imlib_image_get_data_for_reading_only(); +  img->width  = imlib_image_get_width(); +  img->height = imlib_image_get_height(); +} diff --git a/w3mimg/fb/fb_imlib2.h b/w3mimg/fb/fb_imlib2.h new file mode 100644 index 0000000..a091c60 --- /dev/null +++ b/w3mimg/fb/fb_imlib2.h @@ -0,0 +1,14 @@ +#ifndef fb_imlib2_header +#define fb_imlib2_header + +#include <X11/Xlib.h> +#include <Imlib2.h> + +typedef struct { +  int width; +  int height; +  Imlib_Image image; +  DATA32 *data; +} IMAGE; + +#endif diff --git a/w3mimg/fb/fb_w3mimg.c b/w3mimg/fb/fb_w3mimg.c new file mode 100644 index 0000000..c022f22 --- /dev/null +++ b/w3mimg/fb/fb_w3mimg.c @@ -0,0 +1,133 @@ +/* $Id: fb_w3mimg.c,v 1.1 2002/07/17 20:58:48 ukai Exp $ */ +#include <stdio.h> +#include <stdlib.h> +#include <ctype.h> + +#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_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_load_image(w3mimg_op *self, W3MImage *img, char *fname, int w, int h) +{ +    IMAGE *im; + +    if (self == NULL) +	return 0; +    im = fb_load_image(fname, w, h); +    if (!im) +	return 0; +    img->pixmap = im; +    img->width = im->width; +    img->height = im->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) +{ +    if (self == NULL) +	return 0; + +    fb_draw_image((IMAGE *)img->pixmap, +		  x + self->offset_x, y + self->offset_y, +		  sx, sy, +		  (sw ? sw : img->width), +		  (sh ? sh : img->height)); +    return 1; +} + +static void +w3mfb_free_image(w3mimg_op *self, W3MImage *img) +{ +    if (self == NULL) +	return; +    if (img && img->pixmap) { +	fb_free_image((IMAGE *)img->pixmap); +	img->pixmap = NULL; +	img->width = 0; +	img->height = 0; +    } +} + +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 (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->load_image = w3mfb_load_image; +    wop->show_image = w3mfb_show_image; +    wop->free_image = w3mfb_free_image; + +    return wop; +error: +    free(wop); +    return NULL; +} diff --git a/w3mimg/fb/license.txt b/w3mimg/fb/license.txt new file mode 100644 index 0000000..8536a27 --- /dev/null +++ b/w3mimg/fb/license.txt @@ -0,0 +1,26 @@ +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: +  + 1. Redistributions of source code must retain the above copyright +    notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright +    notice, this list of conditions and the following disclaimer in +    the documentation and/or other materials provided with the +    distribution. + 3. The name of the author may not be used to endorse or promote +    products derived from this software without specific prior written +    permission. + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + diff --git a/w3mimg/fb/readme.txt b/w3mimg/fb/readme.txt new file mode 100644 index 0000000..e6fada3 --- /dev/null +++ b/w3mimg/fb/readme.txt @@ -0,0 +1,69 @@ +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 版動作確認 + +■連絡先 +  ZXB01226@nifty.com +  http://homepage3.nifty.com/slokar/ diff --git a/w3mimg/w3mimg.h b/w3mimg/w3mimg.h new file mode 100644 index 0000000..086b1d5 --- /dev/null +++ b/w3mimg/w3mimg.h @@ -0,0 +1,52 @@ +/* $Id: w3mimg.h,v 1.1 2002/07/17 20:58:48 ukai Exp $ */ +#include "config.h" + +#ifdef USE_W3MIMG_FB +#include "w3mimg/fb/fb.h" +#include "w3mimg/fb/fb_img.h" +#endif + +typedef struct { +    void *pixmap;	/* driver specific */ +    int width; +    int height; +} W3MImage; + +typedef struct _w3mimg_op { +    void *priv;	/* driver specific data */ +    int width, height;	/* window width, height */ +    int offset_x, offset_y; /* offset */ + +    int (*init)(struct _w3mimg_op *self); +    int (*finish)(struct _w3mimg_op *self); +    int (*active)(struct _w3mimg_op *self); +    void (*set_background)(struct _w3mimg_op *self, char *background); +    void (*sync)(struct _w3mimg_op *self); +    void (*close)(struct _w3mimg_op *self); + +    int (*load_image)(struct _w3mimg_op *self, W3MImage *img, char *fname,  +		      int w, int h); +    int (*show_image)(struct _w3mimg_op *self, W3MImage *img, +		      int sx, int sy, int sw, int sh, int x, int y); +    void (*free_image)(struct _w3mimg_op *self, W3MImage *img); +} w3mimg_op; + +#ifdef USE_W3MIMG_X11 +w3mimg_op *w3mimg_x11open(); +#endif +#ifdef USE_W3MIMG_FB +w3mimg_op *w3mimg_fbopen(); +#endif + +static w3mimg_op *w3mimg_open() { +    w3mimg_op *w_op = NULL; +#ifdef USE_W3MIMG_X11 +    if (w_op == NULL) +	w_op = w3mimg_x11open(); +#endif +#ifdef USE_W3MIMG_FB +    if (w_op == NULL) +	w_op = w3mimg_fbopen(); +#endif +    return w_op; +} diff --git a/w3mimg/x11/x11_w3mimg.c b/w3mimg/x11/x11_w3mimg.c new file mode 100644 index 0000000..685f038 --- /dev/null +++ b/w3mimg/x11/x11_w3mimg.c @@ -0,0 +1,330 @@ +/* $Id: x11_w3mimg.c,v 1.1 2002/07/17 20:58:48 ukai Exp $ */ +#include <stdio.h> +#include <stdlib.h> +#include <ctype.h> + +#include <Imlib.h> + +#include "w3mimg/w3mimg.h" + +#define OFFSET_X	2 +#define OFFSET_Y	2 + +struct x11_info { +    Display *display; +    Window window, parent; +    unsigned long background_pixel; +    GC imageGC; +    ImlibData *id; +}; + +static int +x11_init(w3mimg_op *self) +{ +    struct x11_info *xi; +    if (self == NULL) +	return 0; +    xi = (struct x11_info *)self->priv; +    if (xi == NULL) +	return 0; +    if (! xi->id) { +	xi->id = Imlib_init(xi->display); +	if (! xi->id) +	    return 0; +    } +    if (! xi->imageGC) { +	xi->imageGC = XCreateGC(xi->display, xi->parent, 0, NULL); +	if (! xi->imageGC) +	    return 0; +    } +    return 1; +} + +static int +x11_finish(w3mimg_op *self) +{ +    struct x11_info *xi; +    if (self == NULL) +	return 0; +    xi = (struct x11_info *)self->priv; +    if (xi == NULL) +	return 0; +    if (xi->imageGC) { +	XFreeGC(xi->display, xi->imageGC); +	xi->imageGC = NULL; +    } +    return 1; +} + +static int +x11_active(w3mimg_op *self) +{ +    struct x11_info *xi; +    if (self == NULL) +	return 0; +    xi = (struct x11_info *)self->priv; +    if (xi == NULL) +	return 0; +    if (! xi->imageGC) +	return 0; +    return 1; +} + +static void +x11_set_background(w3mimg_op *self, char *background) +{ +    XColor screen_def, exact_def; +    struct x11_info *xi; +    if (self == NULL) +	return; +    xi = (struct x11_info *)self->priv; +    if (xi == NULL) +	return; + +    if (background &&  +	XAllocNamedColor(xi->display, DefaultColormap(xi->display, 0), +			 background, &screen_def, &exact_def)) +	xi->background_pixel = screen_def.pixel; +    else { +	Pixmap p; +	GC gc; +	XImage *i; + +	p = XCreatePixmap(xi->display, xi->window, 1, 1,  +			  DefaultDepth(xi->display, 0)); +	gc = XCreateGC(xi->display, xi->window, 0, NULL); +	if (!p || !gc) +	    exit(1); /* XXX */ +	XCopyArea(xi->display, xi->window, p, gc, +		  (self->offset_x >= 1) ? (self->offset_x - 1) : 0, +		  (self->offset_y >= 1) ? (self->offset_y - 1) : 0, +		  1, 1, 0, 0); +	i = XGetImage(xi->display, p, 0, 0, 1, 1, -1, ZPixmap); +	if (!i) +	    exit(1); +	xi->background_pixel = XGetPixel(i, 0, 0); +	XDestroyImage(i); +	XFreeGC(xi->display, gc); +	XFreePixmap(xi->display, p); +    } +} + +static void +x11_sync(w3mimg_op *self) +{ +    struct x11_info *xi; +    if (self == NULL) +	return; +    xi = (struct x11_info *)self->priv; +    if (xi == NULL) +	return; +    XSync(xi->display, False); +} + +static void +x11_close(w3mimg_op *self) +{ +    /* XCloseDisplay(xi->display); */ +} + +static int +x11_load_image(w3mimg_op *self, W3MImage *img, char *fname, int w, int h) +{ +    struct x11_info *xi; +    ImlibImage *im; + +    if (self == NULL) +	return 0; +    xi = (struct x11_info *)self->priv; +    if (xi == NULL) +	return 0; + +    im = Imlib_load_image(xi->id, fname); +    if (!im) +	return 0; +    if (w <= 0) +	w = im->rgb_width; +    if (h <= 0) +	h = im->rgb_height; +    img->pixmap = (void *)XCreatePixmap(xi->display, xi->parent, w, h, +					DefaultDepth(xi->display, 0)); +    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_paste_image(xi->id, im, (Pixmap)img->pixmap, 0, 0, w, h); +    Imlib_kill_image(xi->id, im); +    img->width = w; +    img->height = h; +    return 1; +} + +static int +x11_show_image(w3mimg_op *self, W3MImage *img, int sx, int sy, int sw, int sh, +	       int x, int y) +{ +    struct x11_info *xi; +    if (self == NULL) +	return 0; +    xi = (struct x11_info *)self->priv; +    if (xi == NULL) +	return 0; + +    XCopyArea(xi->display, (Pixmap)img->pixmap, xi->window, xi->imageGC, +	      sx, sy,  +	      (sw ? sw : img->width), +	      (sh ? sh : img->height), +	      x + self->offset_x, y + self->offset_y); +    return 1; +} + +static void +x11_free_image(w3mimg_op *self, W3MImage *img) +{ +    struct x11_info *xi; +    if (self == NULL) +	return; +    xi = (struct x11_info *)self->priv; +    if (xi == NULL) +	return; +    if (img && img->pixmap) { +	XFreePixmap(xi->display,  (Pixmap)img->pixmap); +	img->pixmap = NULL; +	img->width = 0; +	img->height = 0; +    } +} + + +/* *INDENT-OFF* */ +/* +  xterm/kterm/hanterm/cxterm +    top window (WINDOWID) +      +- text window +           +- scrollbar +  rxvt/aterm/Eterm/wterm +    top window (WINDOWID) +      +- text window +      +- scrollbar +      +- menubar (etc.) +  gnome-terminal +    top window +      +- text window (WINDOWID) +      +- scrollbar +      +- menubar +  mlterm (-s) +    top window +      +- text window (WINDOWID) +      +- scrollbar +  mlterm +    top window = text window (WINDOWID) + +  powershell +    top window +      +- window +      |    +- text window +      |    +- scrollbar +      +- menubar (etc.) +  dtterm +    top window +      +- window +           +- window +           |    +- window +           |         +- text window +           |         +- scrollbar +           +- menubar +  hpterm +    top window +      +- window +           +- text window +           +- scrollbar +           +- (etc.) +*/ +/* *INDENT-ON* */ + +w3mimg_op * +w3mimg_x11open() +{ +    w3mimg_op *wop = NULL; +    struct x11_info *xi = NULL; +    char *id; +    int revert, i, nchildren; +    XWindowAttributes attr; +    Window root, *children; + +    wop = (w3mimg_op *)malloc(sizeof(w3mimg_op)); +    if (wop == NULL) +	return NULL; +    memset(wop, 0, sizeof(w3mimg_op)); + +    xi = (struct x11_info *)malloc(sizeof(struct x11_info)); +    if (xi == NULL) +	goto error; +    memset(xi, 0, sizeof(struct x11_info)); + +    xi->display = XOpenDisplay(NULL); +    if (xi->display == NULL) { +	goto error; +    } +    if ((id = getenv("WINDOWID")) != NULL) +	xi->window = (Window)atoi(id); +    else +	XGetInputFocus(xi->display, &xi->window, &revert); +    if (! xi->window) +	exit(1); + +    XGetWindowAttributes(xi->display, xi->window, &attr); +    wop->width = attr.width; +    wop->height = attr.height; + +    while (1) { +	Window p_window; + +	XQueryTree(xi->display, xi->window, &root, &xi->parent,  +		   &children, &nchildren); +	p_window = xi->window; +	for (i = 0; i < nchildren; i++) { +	    XGetWindowAttributes(xi->display, children[i], &attr); +	    if (attr.width > wop->width * 0.7 &&  +		attr.height > wop->height * 0.7) { +		/* maybe text window */ +		wop->width = attr.width; +		wop->height = attr.height; +		xi->window = children[i]; +	    } +	} +	if (p_window == xi->window) +	    break; +    } +    wop->offset_x = OFFSET_X; +    for (i = 0; i < nchildren; i++) { +	XGetWindowAttributes(xi->display, children[i], &attr); +	if (attr.x <= 0 && attr.width < 30 && +	    attr.height > wop->height * 0.7) { +	    /* scrollbar of xterm/kterm ? */ +	    wop->offset_x += attr.x + attr.width + attr.border_width * 2; +	    break; +	} +    } +    wop->offset_y = OFFSET_Y; +     +    wop->priv = xi; + +    wop->init = x11_init; +    wop->finish = x11_finish; +    wop->active = x11_active; +    wop->set_background = x11_set_background; +    wop->sync = x11_sync; +    wop->close = x11_close; + +    wop->load_image = x11_load_image; +    wop->show_image = x11_show_image; +    wop->free_image = x11_free_image; + +    return wop; +error: +    if (xi) +	free(xi); +    free(wop); +    return NULL; +} diff --git a/w3mimgdisplay.c b/w3mimgdisplay.c index 1ff442e..e450871 100644 --- a/w3mimgdisplay.c +++ b/w3mimgdisplay.c @@ -1,175 +1,49 @@ -/* $Id: w3mimgdisplay.c,v 1.2 2002/01/31 18:28:24 ukai Exp $ */ +/* $Id: w3mimgdisplay.c,v 1.3 2002/07/17 20:58:48 ukai Exp $ */  #include <stdio.h>  #include <stdlib.h> -#include <Imlib.h> +#include <ctype.h> +#include "config.h" +#include "w3mimg/w3mimg.h" -static Display *display; -static Window window, parent; -static unsigned long background_pixel; +w3mimg_op *w_op;  static char *background = NULL; -static int offset_x = 2, offset_y = 2; +static int offset_x = 0, offset_y = 0;  static int defined_bg = 0, defined_x = 0, defined_y = 0, defined_test = 0;  static int defined_debug = 0;  #define MAX_IMAGE 1000 -typedef struct { -    Pixmap pixmap; -    int width; -    int height; -} Image; -static Image *imageBuf = NULL; +static W3MImage *imageBuf = NULL;  static int maxImage = 0; -static GC imageGC = NULL;  static void GetOption(int argc, char **argv);  static void DrawImage(char *buf, int redraw);  static void ClearImage(void); -/* *INDENT-OFF* */ -/* -  xterm/kterm/hanterm/cxterm -    top window (WINDOWID) -      +- text window -           +- scrollbar -  rxvt/aterm/Eterm/wterm -    top window (WINDOWID) -      +- text window -      +- scrollbar -      +- menubar (etc.) -  gnome-terminal -    top window -      +- text window (WINDOWID) -      +- scrollbar -      +- menubar -  mlterm (-s) -    top window -      +- text window (WINDOWID) -      +- scrollbar -  mlterm -    top window = text window (WINDOWID) - -  powershell -    top window -      +- window -      |    +- text window -      |    +- scrollbar -      +- menubar (etc.) -  dtterm -    top window -      +- window -           +- window -           |    +- window -           |         +- text window -           |         +- scrollbar -           +- menubar -  hpterm -    top window -      +- window -           +- text window -           +- scrollbar -           +- (etc.) -*/ -/* *INDENT-ON* */ -  int  main(int argc, char **argv)  { -    Window root, *children; -    XWindowAttributes attr; -    XColor screen_def, exact_def; -    int revert, nchildren, len, width, height, i; +    int len;      char buf[1024 + 128]; -    char *id;      GetOption(argc, argv);      if (!defined_debug)  	fclose(stderr); -    display = XOpenDisplay(NULL); -    if (!display) +    w_op = w3mimg_open(); +    if (w_op == NULL)  	exit(1); -    if ((id = getenv("WINDOWID")) != NULL) -	window = (Window) atoi(id); -    else -	XGetInputFocus(display, &window, &revert); -    if (!window) -	exit(1); - -    XGetWindowAttributes(display, window, &attr); -    width = attr.width; -    height = attr.height; -    while (1) { -	Window p_window; - -	XQueryTree(display, window, &root, &parent, &children, &nchildren); -	if (defined_debug) -	    fprintf(stderr, -		    "window=%lx root=%lx parent=%lx nchildren=%d width=%d height=%d\n", -		    (unsigned long)window, (unsigned long)root, -		    (unsigned long)parent, nchildren, width, height); -	p_window = window; -	for (i = 0; i < nchildren; i++) { -	    XGetWindowAttributes(display, children[i], &attr); -	    if (defined_debug) -		fprintf(stderr, -			"children[%d]=%lx x=%d y=%d width=%d height=%d\n", i, -			children[i], attr.x, attr.y, attr.width, attr.height); -	    if (attr.width > width * 0.7 && attr.height > height * 0.7) { -		/* maybe text window */ -		width = attr.width; -		height = attr.height; -		window = children[i]; -	    } -	} -	if (p_window == window) -	    break; -    } -    if (!defined_x) { -	for (i = 0; i < nchildren; i++) { -	    XGetWindowAttributes(display, children[i], &attr); -	    if (attr.x <= 0 && attr.width < 30 && attr.height > height * 0.7) { -		if (defined_debug) -		    fprintf(stderr, -			    "children[%d]=%lx x=%d y=%d width=%d height=%d\n", -			    i, children[i], attr.x, attr.y, attr.width, -			    attr.height); -		/* scrollbar of xterm/kterm ? */ -		offset_x += attr.x + attr.width + attr.border_width * 2; -		break; -	    } -	} -    } +    if (defined_x) +	w_op->offset_x = offset_x; +    if (defined_y) +	w_op->offset_y = offset_y;      if (defined_test) { -	printf("%d %d\n", width - offset_x, height - offset_y); +	printf("%d %d\n", w_op->width - w_op->offset_x,  +	       w_op->height - w_op->offset_y);  	exit(0);      } -    if (defined_bg && XAllocNamedColor(display, DefaultColormap(display, 0), -				       background, &screen_def, &exact_def)) -	background_pixel = screen_def.pixel; -    else { -	Pixmap p; -	GC gc; -	XImage *i; - -	p = XCreatePixmap(display, window, 1, 1, DefaultDepth(display, 0)); -	gc = XCreateGC(display, window, 0, NULL); -	if (!p || !gc) -	    exit(1); -	XCopyArea(display, window, p, gc, (offset_x >= 1) ? (offset_x - 1) : 0, -		  (offset_y >= 1) ? (offset_y - 1) : 0, 1, 1, 0, 0); -	i = XGetImage(display, p, 0, 0, 1, 1, -1, ZPixmap); -	if (!i) -	    exit(1); -	background_pixel = XGetPixel(i, 0, 0); -	XDestroyImage(i); -	XFreeGC(display, gc); -	XFreePixmap(display, p); -	/* -	 * background_pixel = WhitePixel(display, 0); -	 */ -    } +    w_op->set_background(w_op, background);      while (fgets(buf, sizeof(buf), stdin) != NULL) {  	if (!(isdigit(buf[0]) && buf[1] == ';')) { @@ -194,18 +68,26 @@ main(int argc, char **argv)  	    ClearImage();  	    break;  	case '3': -	    XSync(display, False); +	    w_op->sync(w_op);  	    break;  	case '4':  	    fputs("\n", stdout);  	    fflush(stdout);  	    break; +#if 0 /* def USE_W3MIMG_FB */ +	case '5': +	    if (w3mimg_mode == W3MIMG_FB_MODE) { +		IMAGE *im = fb_load_image(&buf[2], 0, 0); +		fprintf(stdout, "%d %d\n", im->width, im->height); +		fflush(stdout); +		fb_free_image(im); +	    } +	    break; +#endif  	}      }      ClearImage(); -    /* -     * XCloseDisplay(display); -     */ +    w_op->close(w_op);      exit(0);  } @@ -248,8 +130,6 @@ GetOption(int argc, char **argv)  void  DrawImage(char *buf, int redraw)  { -    static ImlibData *id = NULL; -    ImlibImage *im;      char *p = buf;      int n = 0, x = 0, y = 0, w = 0, h = 0, sx = 0, sy = 0, sw = 0, sh = 0; @@ -296,20 +176,12 @@ DrawImage(char *buf, int redraw)      if (n < 0 || n >= MAX_IMAGE)  	return;      if (redraw) { -	if (!imageGC || n >= maxImage || !imageBuf[n].pixmap) +	if (! w_op->active(w_op) || n >= maxImage || !imageBuf[n].pixmap)  	    return;  	goto draw_image;      } -    if (!id) { -	id = Imlib_init(display); -	if (!id) -	    return; -    } -    if (!imageGC) { -	imageGC = XCreateGC(display, parent, 0, NULL); -	if (!imageGC) -	    return; -    } +    w_op->init(w_op); +      if (n >= maxImage) {  	int i = maxImage;  	maxImage = i ? (i * 2) : 2; @@ -317,51 +189,30 @@ DrawImage(char *buf, int redraw)  	    maxImage = MAX_IMAGE;  	else if (n >= maxImage)  	    maxImage = n + 1; -	imageBuf = (Image *) realloc((void *)imageBuf, -				     sizeof(Image) * maxImage); +	imageBuf = (W3MImage *) realloc((void *)imageBuf, +				     sizeof(W3MImage) * maxImage);  	for (; i < maxImage; i++) -	    imageBuf[i].pixmap = (Pixmap) NULL; +	    imageBuf[i].pixmap = NULL;      }      if (imageBuf[n].pixmap) { -	XFreePixmap(display, imageBuf[n].pixmap); -	imageBuf[n].pixmap = (Pixmap) NULL; +	w_op->free_image(w_op, &imageBuf[n]); +	imageBuf[n].pixmap = NULL;      } -    im = Imlib_load_image(id, p); -    if (!im) -	return; -    if (!w) -	w = im->rgb_width; -    if (!h) -	h = im->rgb_height; -    imageBuf[n].pixmap = XCreatePixmap(display, parent, w, h, -				       DefaultDepth(display, 0)); -    if (!imageBuf[n].pixmap) -	return; -    XSetForeground(display, imageGC, background_pixel); -    XFillRectangle(display, imageBuf[n].pixmap, imageGC, 0, 0, w, h); -    Imlib_paste_image(id, im, imageBuf[n].pixmap, 0, 0, w, h); -    Imlib_kill_image(id, im); -    imageBuf[n].width = w; -    imageBuf[n].height = h; +    w_op->load_image(w_op, &imageBuf[n], p, w, h); +    draw_image: -    XCopyArea(display, imageBuf[n].pixmap, window, imageGC, -	      sx, sy, (sw ? sw : imageBuf[n].width), -	      (sh ? sh : imageBuf[n].height), x + offset_x, y + offset_y); +    w_op->show_image(w_op, &imageBuf[n], sx, sy, sw, sh, x, y);  }  void  ClearImage(void)  { -    if (imageGC) { -	XFreeGC(display, imageGC); -	imageGC = NULL; -    } +    w_op->finish(w_op);      if (imageBuf) {  	int i;  	for (i = 0; i < maxImage; i++) { -	    if (imageBuf[i].pixmap) -		XFreePixmap(display, imageBuf[i].pixmap); +	    w_op->free_image(w_op, &imageBuf[i]);  	}  	free(imageBuf);  	imageBuf = NULL; diff --git a/w3mimgsize.c b/w3mimgsize.c index 89a28f6..72f0cea 100644 --- a/w3mimgsize.c +++ b/w3mimgsize.c @@ -1,31 +1,28 @@ -/* $Id: w3mimgsize.c,v 1.1 2002/01/31 17:54:57 ukai Exp $ */ +/* $Id: w3mimgsize.c,v 1.2 2002/07/17 20:58:48 ukai Exp $ */  #include <stdio.h>  #include <stdlib.h> -#include <Imlib.h> +#include <string.h> +#include "config.h" +#include "w3mimg/w3mimg.h"  int  main(int argc, char **argv)  { -    Display *display; -    ImlibData *id; -    ImlibImage *im; +    w3mimg_op *w_op = NULL; +    W3MImage img;      fclose(stderr);      if (argc < 2)  	exit(1); -    display = XOpenDisplay(NULL); -    if (!display) +    w_op = w3mimg_open(); +    if (w_op == NULL)  	exit(1); -    id = Imlib_init(display); -    if (!id) + +    if (!w_op->init(w_op))  	exit(1); -    im = Imlib_load_image(id, argv[1]); -    if (!im) + +    if (!w_op->load_image(w_op, &img, argv[1], -1, -1))  	exit(1); -    printf("%d %d\n", im->rgb_width, im->rgb_height); -    /* -     * Imlib_kill_image(id, im); -     * XCloseDisplay(display); -     */ +    printf("%d %d\n", img.width, img.height);      exit(0);  } | 
