diff -dru fbida-2.03/GNUmakefile fbida-2.03-4bpp/GNUmakefile --- fbida-2.03/GNUmakefile 2004-06-30 06:41:54.000000000 -0700 +++ fbida-2.03-4bpp/GNUmakefile 2005-07-29 00:39:24.000000000 -0700 @@ -7,7 +7,7 @@ resdir = $(DESTDIR)$(RESDIR) # fixup flags -CFLAGS += -DVERSION='"$(VERSION)"' -I$(srcdir) +CFLAGS += -DVERSION='"$(VERSION)"' -I$(srcdir) -mcpu=arm7tdmi -mtune=arm7tdmi # default target all: build @@ -43,7 +43,7 @@ HAVE_LIBSANE := $(call ac_lib,sane_init,sane) HAVE_LIBCURL := $(call ac_lib,curl_easy_init,curl) HAVE_LIBLIRC := $(call ac_lib,lirc_init,lirc_client) -HAVE_MOTIF := $(call ac_lib,XmStringGenerate,Xm,-L/usr/X11R6/$(LIB) -lXpm -lXt -lXext -lX11) +#HAVE_MOTIF := $(call ac_lib,XmStringGenerate,Xm,-L/usr/X11R6/$(LIB) -lXpm -lXt -lXext -lX11) endef # transparent http/ftp access using curl depends on fopencookie (glibc) diff -dru fbida-2.03/dither.c fbida-2.03-4bpp/dither.c --- fbida-2.03/dither.c 2004-03-28 03:32:06.000000000 -0800 +++ fbida-2.03-4bpp/dither.c 2005-07-29 00:40:33.000000000 -0700 @@ -191,3 +191,27 @@ *(dest++) = a & 0xff; } } + +void +dither_line_gray_4bpp(unsigned char *src, unsigned char *dest, int y, int width) +{ + long *ymod, xmod; + register long a,g; + int x; + + ymod = DM[y & DITHER_MASK]; + + for(x = 0; x < width; x++) { + xmod = width & DITHER_MASK; + + g = (src[0] * 77 + src[1] * 151 + src[2] * 28) >> 8; + a = gray_dither[g]; + src += 3; + if (ymod[xmod] < a) + a >>= 8; + if(x % 2) + dest[x/2] |= (unsigned char)(a << 4); + else + dest[x/2] = (unsigned char)a; + } +} diff -dru fbida-2.03/dither.h fbida-2.03-4bpp/dither.h --- fbida-2.03/dither.h 2004-03-28 03:32:06.000000000 -0800 +++ fbida-2.03-4bpp/dither.h 2005-07-28 18:12:29.000000000 -0700 @@ -4,3 +4,4 @@ void init_dither(int, int, int, int); void dither_line_color(unsigned char *, unsigned char *, int, int); void dither_line_gray(unsigned char *, unsigned char *, int, int); +void dither_line_gray_4bpp(unsigned char *, unsigned char *, int, int); diff -dru fbida-2.03/fb-gui.c fbida-2.03-4bpp/fb-gui.c --- fbida-2.03/fb-gui.c 2004-08-17 04:47:30.000000000 -0700 +++ fbida-2.03-4bpp/fb-gui.c 2005-07-29 00:20:21.000000000 -0700 @@ -72,6 +72,24 @@ } } +static void +dither_palette_gray_4bpp(void) +{ + /* + * I want to put to each color register it's own number. + * This is how register value is calculated: + * gray = (R * 77 + G * 151 + B * 28) >> 20; + * Assuming R == G == B, reverse formula will be: + * V = (gray << 20) / 256 + */ + + unsigned long gray; + for(gray = 0; gray < 16; gray++) { + p_red[gray] = p_green[gray] = p_blue[gray] = gray << 12; + } + p_cmap.len = 16; +} + static void shadow_lut_init_one(int32_t *lut, int bits, int shift) { int i; @@ -130,6 +148,7 @@ int x; switch (fb_var.bits_per_pixel) { + case 4: case 8: dither_line(buffer, ptr, line, swidth); break; @@ -171,7 +190,7 @@ for (i = 0; i < sheight; i++, offset += fb_fix.line_length) { if (0 == sdirty[i]) continue; - shadow_render_line(i, fb_mem + offset, shadow[i]); + shadow_render_line(i, fb_mem + fb_mem_offset + offset, shadow[i]); sdirty[i] = 0; } } @@ -201,7 +220,7 @@ void shadow_set_palette(int fd) { - if (fb_fix.visual != FB_VISUAL_DIRECTCOLOR && fb_var.bits_per_pixel != 8) + if (fb_fix.visual != FB_VISUAL_DIRECTCOLOR && fb_fix.visual != FB_VISUAL_PSEUDOCOLOR) return; if (-1 == ioctl(fd,FBIOPUTCMAP,&p_cmap)) { perror("ioctl FBIOPUTCMAP"); @@ -250,6 +269,14 @@ linear_palette(8,8,8); shadow_lut_init(24); break; + case 4: + /* work only with grayscale 4bpp */ + if (fb_var.grayscale) { + dither_palette_gray_4bpp(); + init_dither(2, 2, 2, 16); + dither_line = dither_line_gray_4bpp; + break; + } default: fprintf(stderr, "Oops: %i bit/pixel ???\n", fb_var.bits_per_pixel); @@ -643,11 +670,11 @@ void fb_clear_mem(void) { if (visible) - fb_memset(fb_mem,0,fb_fix.smem_len); + fb_memset(fb_mem + fb_mem_offset,0,fb_fix.smem_len); } void fb_clear_screen(void) { if (visible) - fb_memset(fb_mem,0,fb_fix.line_length * fb_var.yres); + fb_memset(fb_mem + fb_mem_offset,0,fb_fix.line_length * fb_var.yres); } diff -dru fbida-2.03/fbtools.c fbida-2.03-4bpp/fbtools.c --- fbida-2.03/fbtools.c 2004-11-08 05:09:20.000000000 -0800 +++ fbida-2.03-4bpp/fbtools.c 2005-07-28 23:36:13.000000000 -0700 @@ -51,6 +51,7 @@ static struct fb_var_screeninfo fb_ovar; static unsigned short ored[256], ogreen[256], oblue[256]; static struct fb_cmap ocmap = { 0, 256, ored, ogreen, oblue }; +static unsigned char *ofbcontent = NULL; /* -------------------------------------------------------------------- */ /* devices */ @@ -369,7 +370,7 @@ perror("ioctl FBIOGET_FSCREENINFO"); exit(1); } - if (fb_ovar.bits_per_pixel == 8 || + if (fb_fix.visual == FB_VISUAL_PSEUDOCOLOR || fb_fix.visual == FB_VISUAL_DIRECTCOLOR) { if (-1 == ioctl(fb,FBIOGETCMAP,&ocmap)) { perror("ioctl FBIOGETCMAP"); @@ -433,6 +434,12 @@ } // fprintf(stderr,"fb_mem = %p\n",fb_mem); + /* store old framebuffer */ + ofbcontent = (unsigned char*)malloc(fb_fix.smem_len); + if (NULL != ofbcontent) { + memcpy(ofbcontent, fb_mem + fb_mem_offset, fb_fix.smem_len); + } + /* move viewport to upper left corner */ if (fb_var.xoffset != 0 || fb_var.yoffset != 0) { fb_var.xoffset = 0; @@ -465,7 +472,12 @@ perror("ioctl FBIOPUT_VSCREENINFO"); if (-1 == ioctl(fb,FBIOGET_FSCREENINFO,&fb_fix)) perror("ioctl FBIOGET_FSCREENINFO"); - if (fb_ovar.bits_per_pixel == 8 || + if (NULL != ofbcontent) { + memcpy(fb_mem + fb_mem_offset, ofbcontent, fb_fix.smem_len); + free(ofbcontent); + ofbcontent = NULL; + } + if (fb_fix.visual == FB_VISUAL_PSEUDOCOLOR || fb_fix.visual == FB_VISUAL_DIRECTCOLOR) { if (-1 == ioctl(fb,FBIOPUTCMAP,&ocmap)) perror("ioctl FBIOPUTCMAP");