wok-undigest rev 471

fbvnc: speedup
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Sep 12 15:42:37 2011 +0200 (2011-09-12)
parents 5c5dbcecf5c7
children dc605c381b91
files fbvnc/stuff/fbvnc.u
line diff
     1.1 --- a/fbvnc/stuff/fbvnc.u	Sun Sep 11 09:44:08 2011 +0200
     1.2 +++ b/fbvnc/stuff/fbvnc.u	Mon Sep 12 15:42:37 2011 +0200
     1.3 @@ -5,7 +5,7 @@
     1.4   
     1.5   /* helper functions */
     1.6  +struct rgb_conv {
     1.7 -+	int rshl, gshl, bshr, gshr;
     1.8 ++	int rshl, gshl;
     1.9  +	int rskp, gskp, bskp;
    1.10  +	int rmax, gmax, bmax;
    1.11  +};
    1.12 @@ -46,7 +46,7 @@
    1.13   }
    1.14   
    1.15   void fb_free(void)
    1.16 -@@ -123,16 +127,27 @@
    1.17 +@@ -123,16 +127,26 @@
    1.18   	memcpy(fb_mem(r) + (c + vinfo.xoffset) * bpp, mem, len * bpp);
    1.19   }
    1.20   
    1.21 @@ -58,10 +58,9 @@
    1.22  +	s->rshl = s->gshl = bits;
    1.23  +	s->bskp = 8 - bits; s->bmax = (1 << bits) -1;
    1.24  +	bits = mode & 0xF;  mode >>= 4;
    1.25 -+	s->rshl += bits; s->bshr = bits;
    1.26 ++	s->rshl += bits;
    1.27  +	s->gskp = 8 - bits; s->gmax = (1 << bits) -1;
    1.28  +	bits = mode & 0xF;
    1.29 -+	s->bshr += s->gshr = bits;
    1.30  +	s->rskp = 8 - bits; s->rmax = (1 << bits) -1;
    1.31  +}
    1.32  +
    1.33 @@ -86,6 +85,12 @@
    1.34   }
    1.35  --- fbvnc.c
    1.36  +++ fbvnc.c
    1.37 +@@ -1,4 +1,4 @@
    1.38 +-/*
    1.39 ++/* // TODO user/passwd RDP?
    1.40 +  * fbvnc - a small linux framebuffer vnc viewer
    1.41 +  *
    1.42 +  * Copyright (C) 2009-2011 Ali Gholami Rudi
    1.43  @@ -36,13 +36,15 @@
    1.44   
    1.45   #define VNC_PORT		"5900"
    1.46 @@ -104,7 +109,7 @@
    1.47   
    1.48   static int vnc_connect(char *addr, char *port)
    1.49   {
    1.50 -@@ -61,22 +63,28 @@
    1.51 +@@ -61,22 +63,26 @@
    1.52   
    1.53   	if (connect(fd, addrinfo->ai_addr, addrinfo->ai_addrlen) == -1) {
    1.54   		close(fd);
    1.55 @@ -116,14 +121,12 @@
    1.56   	return fd;
    1.57   }
    1.58   
    1.59 -+static int bpp, Bpp;
    1.60 ++static int bpp, vnc_mode;
    1.61  +static struct rgb_conv format;
    1.62   static int vnc_init(int fd)
    1.63   {
    1.64  -	char vncver[] = "RFB 003.003\n";
    1.65 -+	static struct { int bpp, fmt; } fmt[] = {
    1.66 -+		{ 32, 0x0888 },  { 16, 0x0565 },  { 8, 0x0233 }, { -1, 0 }
    1.67 -+	};
    1.68 ++	static int vncfmt[] = { 0x40888, 0x20565, 0x10233, 0 };
    1.69  +	char vncver[12];
    1.70  +	int i;
    1.71  +
    1.72 @@ -137,7 +140,7 @@
    1.73   	read(fd, vncver, 12);
    1.74   
    1.75   	read(fd, &connstat, sizeof(connstat));
    1.76 -@@ -88,68 +96,71 @@
    1.77 +@@ -88,68 +94,78 @@
    1.78   	write(fd, &clientinit, sizeof(clientinit));
    1.79   	read(fd, &serverinit, sizeof(serverinit));
    1.80   
    1.81 @@ -166,28 +169,31 @@
    1.82  -	pixfmt_cmd.format.depth = 8;
    1.83   	pixfmt_cmd.format.bigendian = 0;
    1.84   	pixfmt_cmd.format.truecolor = 1;
    1.85 --
    1.86 + 
    1.87  -	pixfmt_cmd.format.rmax = htons(3);
    1.88  -	pixfmt_cmd.format.gmax = htons(7);
    1.89  -	pixfmt_cmd.format.bmax = htons(7);
    1.90 -+	if (bpp < 0) bpp = 0;
    1.91 -+	if (bpp >= 24) bpp = 32;
    1.92 -+	i = 0; do {
    1.93 -+		pixfmt_cmd.format.bpp =
    1.94 -+		pixfmt_cmd.format.depth = fmt[i].bpp;
    1.95 -+		fill_rgb_conv(fmt[i].fmt, &format);
    1.96 -+	} while (bpp <= fmt[++i].bpp);
    1.97 -+	Bpp = pixfmt_cmd.format.bpp / 8;
    1.98 +-	pixfmt_cmd.format.rshl = 0;
    1.99 +-	pixfmt_cmd.format.gshl = 2;
   1.100 +-	pixfmt_cmd.format.bshl = 5;
   1.101 +-
   1.102 ++	if (bpp < 1)
   1.103 ++		bpp = 1;
   1.104 ++	if (bpp >= 3)
   1.105 ++		bpp = 4;
   1.106 ++	for (i = 0; bpp <= FBM_BPP(vncfmt[i]); i++)
   1.107 ++		vnc_mode = vncfmt[i];
   1.108 ++	bpp = FBM_BPP(vnc_mode);
   1.109 ++	pixfmt_cmd.format.bpp =
   1.110 ++	pixfmt_cmd.format.depth = bpp << 3;
   1.111  +
   1.112 ++	fill_rgb_conv(FBM_COLORS(vnc_mode), &format);
   1.113  +	pixfmt_cmd.format.rmax = htons(format.rmax);
   1.114  +	pixfmt_cmd.format.gmax = htons(format.gmax);
   1.115  +	pixfmt_cmd.format.bmax = htons(format.bmax);
   1.116 - 	pixfmt_cmd.format.rshl = 0;
   1.117 --	pixfmt_cmd.format.gshl = 2;
   1.118 --	pixfmt_cmd.format.bshl = 5;
   1.119 --
   1.120 -+	pixfmt_cmd.format.gshl = format.gshr;
   1.121 -+	pixfmt_cmd.format.bshl = format.bshr;
   1.122 ++	pixfmt_cmd.format.rshl = format.rshl;
   1.123 ++	pixfmt_cmd.format.gshl = format.gshl;
   1.124 ++	pixfmt_cmd.format.bshl = 0;
   1.125   	write(fd, &pixfmt_cmd, sizeof(pixfmt_cmd));
   1.126   	return fd;
   1.127   }
   1.128 @@ -229,24 +235,27 @@
   1.129  -			int g = ((c >> 2) & 0x7) << 5;
   1.130  -			int b = ((c >> 5) & 0x7) << 5;
   1.131  -			slice[j] = FB_VAL(r, g, b);
   1.132 --		}
   1.133 ++	int mode = fb_mode();
   1.134 ++	if (mode != vnc_mode) {
   1.135 ++		fbval_t slice[MAXRES];
   1.136 ++		unsigned char *byte = (unsigned char *) slice;
   1.137 ++		int j;
   1.138 ++		int fb_bpp = FBM_BPP(mode);
   1.139 ++		for (j = 0; j < w; j++, byte += fb_bpp, s += bpp) {
   1.140 ++			fbval_t c = * (fbval_t *) s;
   1.141 ++			int r = ((c >> format.rshl) & format.rmax) << format.rskp;
   1.142 ++			int g = ((c >> format.gshl) & format.gmax) << format.gskp;
   1.143 ++			int b = (c & format.bmax) << format.bskp;
   1.144 ++			* (fbval_t *) byte = FB_VAL(r, g, b);
   1.145 + 		}
   1.146  -		fb_set(y + i, x, slice, w);
   1.147 -+	fbval_t slice[MAXRES];
   1.148 -+	unsigned char *byte = (unsigned char *) slice;
   1.149 -+	int j;
   1.150 -+	int mode = FBM_BPP(fb_mode());
   1.151 -+	for (j = 0; j < w; j++, byte += mode, s += Bpp) {
   1.152 -+		fbval_t c = * (fbval_t *) s;
   1.153 -+		int r = (c & format.rmax) << format.rskp;
   1.154 -+		int g = ((c >> format.gshr) & format.gmax) << format.gskp;
   1.155 -+		int b = ((c >> format.bshr) & format.bmax) << format.bskp;
   1.156 -+		* (fbval_t *) byte = FB_VAL(r, g, b);
   1.157 ++		s = (void *) slice;
   1.158   	}
   1.159 -+	fb_set(y, x, slice, w);
   1.160 ++	fb_set(y, x, s, w);
   1.161   }
   1.162   
   1.163   static void xread(int fd, void *buf, int len)
   1.164 -@@ -159,54 +170,79 @@
   1.165 +@@ -159,54 +175,79 @@
   1.166   	while (nr < len && (n = read(fd, buf + nr, len - nr)) > 0)
   1.167   		nr += n;
   1.168   	if (nr < len) {
   1.169 @@ -322,9 +331,9 @@
   1.170  +				int a, b, c = i;
   1.171  +				for (a = b = 0; w > b; b += a, c = 0) {
   1.172  +					a = MIN(w - b, MAXPIX);
   1.173 -+					xread(fd, buf, a * Bpp);
   1.174 ++					xread(fd, buf, a * bpp);
   1.175  +					if (y >= 0 && y < rows && l > b)
   1.176 -+						drawfb(buf + (c * Bpp), x + b,
   1.177 ++						drawfb(buf + (c * bpp), x + b,
   1.178  +						       y, MIN(a, l - b) - c);
   1.179  +				}
   1.180  +			}
   1.181 @@ -350,7 +359,7 @@
   1.182   		return -1;
   1.183   	}
   1.184   	return 0;
   1.185 -@@ -217,12 +253,31 @@
   1.186 +@@ -217,12 +258,31 @@
   1.187   	char ie[3];
   1.188   	struct vnc_client_ratevent me = {VNC_CLIENT_RATEVENT};
   1.189   	int mask = 0;
   1.190 @@ -384,7 +393,7 @@
   1.191   	if (ie[0] & 0x01)
   1.192   		mask |= VNC_BUTTON1_MASK;
   1.193   	if (ie[0] & 0x04)
   1.194 -@@ -233,6 +288,8 @@
   1.195 +@@ -233,6 +293,8 @@
   1.196   	me.x = htons(mc);
   1.197   	me.mask = mask;
   1.198   	write(fd, &me, sizeof(me));
   1.199 @@ -393,7 +402,7 @@
   1.200   	return 0;
   1.201   }
   1.202   
   1.203 -@@ -292,12 +349,11 @@
   1.204 +@@ -292,12 +354,11 @@
   1.205   			k = 0xff0d;
   1.206   			break;
   1.207   		case 0x0c:	/* ^L: redraw */
   1.208 @@ -408,7 +417,7 @@
   1.209   			mod[nmod++] = 0xffe1;
   1.210   		if (k >= 1 && k <= 26) {
   1.211   			k = 'a' + k - 1;
   1.212 -@@ -339,40 +395,42 @@
   1.213 +@@ -339,40 +400,42 @@
   1.214   	write(STDIN_FILENO, show, strlen(show));
   1.215   }
   1.216   
   1.217 @@ -458,7 +467,7 @@
   1.218   }
   1.219   
   1.220   int main(int argc, char * argv[])
   1.221 -@@ -380,27 +438,38 @@
   1.222 +@@ -380,27 +443,38 @@
   1.223   	char *port = VNC_PORT;
   1.224   	char *host = "127.0.0.1";
   1.225   	struct termios ti;
   1.226 @@ -471,7 +480,7 @@
   1.227  +  	}
   1.228  +  	if (*argv[1] == '-' && argc >= 3) {
   1.229  +  		argc -= 2; argv += 2;
   1.230 -+  		bpp = atoi(argv[0]);
   1.231 ++  		bpp = atoi(argv[0]) >> 3;
   1.232  +  	} 
   1.233   	if (argc >= 2)
   1.234   		host = argv[1];