wok-tiny rev 68

fbvnc: speedup
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Sep 12 15:43:10 2011 +0200 (2011-09-12)
parents 05be185b867c
children d62defb9bb77
files fbvnc-ssh/receipt fbvnc/stuff/fbvnc.u
line diff
     1.1 --- a/fbvnc-ssh/receipt	Sun Sep 11 17:42:22 2011 +0200
     1.2 +++ b/fbvnc-ssh/receipt	Mon Sep 12 15:43:10 2011 +0200
     1.3 @@ -33,7 +33,7 @@
     1.4  </tr>
     1.5  </table>
     1.6  <p>
     1.7 -You should add the public key in <b>\$HOME/.ssh/authorized_keys</b> of the VNS/SSH server.
     1.8 +You should add the public key in <b>\$HOME/.ssh/authorized_keys</b> of the VNC/SSH server.
     1.9  </p>
    1.10  <p>
    1.11  You can get it on the client (from configuration files) with:
     2.1 --- a/fbvnc/stuff/fbvnc.u	Sun Sep 11 17:42:22 2011 +0200
     2.2 +++ b/fbvnc/stuff/fbvnc.u	Mon Sep 12 15:43:10 2011 +0200
     2.3 @@ -5,7 +5,7 @@
     2.4   
     2.5   /* helper functions */
     2.6  +struct rgb_conv {
     2.7 -+	int rshl, gshl, bshr, gshr;
     2.8 ++	int rshl, gshl;
     2.9  +	int rskp, gskp, bskp;
    2.10  +	int rmax, gmax, bmax;
    2.11  +};
    2.12 @@ -46,7 +46,7 @@
    2.13   }
    2.14   
    2.15   void fb_free(void)
    2.16 -@@ -123,16 +127,27 @@
    2.17 +@@ -123,16 +127,26 @@
    2.18   	memcpy(fb_mem(r) + (c + vinfo.xoffset) * bpp, mem, len * bpp);
    2.19   }
    2.20   
    2.21 @@ -58,10 +58,9 @@
    2.22  +	s->rshl = s->gshl = bits;
    2.23  +	s->bskp = 8 - bits; s->bmax = (1 << bits) -1;
    2.24  +	bits = mode & 0xF;  mode >>= 4;
    2.25 -+	s->rshl += bits; s->bshr = bits;
    2.26 ++	s->rshl += bits;
    2.27  +	s->gskp = 8 - bits; s->gmax = (1 << bits) -1;
    2.28  +	bits = mode & 0xF;
    2.29 -+	s->bshr += s->gshr = bits;
    2.30  +	s->rskp = 8 - bits; s->rmax = (1 << bits) -1;
    2.31  +}
    2.32  +
    2.33 @@ -86,6 +85,12 @@
    2.34   }
    2.35  --- fbvnc.c
    2.36  +++ fbvnc.c
    2.37 +@@ -1,4 +1,4 @@
    2.38 +-/*
    2.39 ++/* // TODO user/passwd RDP?
    2.40 +  * fbvnc - a small linux framebuffer vnc viewer
    2.41 +  *
    2.42 +  * Copyright (C) 2009-2011 Ali Gholami Rudi
    2.43  @@ -36,13 +36,15 @@
    2.44   
    2.45   #define VNC_PORT		"5900"
    2.46 @@ -104,7 +109,7 @@
    2.47   
    2.48   static int vnc_connect(char *addr, char *port)
    2.49   {
    2.50 -@@ -61,22 +63,28 @@
    2.51 +@@ -61,22 +63,26 @@
    2.52   
    2.53   	if (connect(fd, addrinfo->ai_addr, addrinfo->ai_addrlen) == -1) {
    2.54   		close(fd);
    2.55 @@ -116,14 +121,12 @@
    2.56   	return fd;
    2.57   }
    2.58   
    2.59 -+static int bpp, Bpp;
    2.60 ++static int bpp, vnc_mode;
    2.61  +static struct rgb_conv format;
    2.62   static int vnc_init(int fd)
    2.63   {
    2.64  -	char vncver[] = "RFB 003.003\n";
    2.65 -+	static struct { int bpp, fmt; } fmt[] = {
    2.66 -+		{ 32, 0x0888 },  { 16, 0x0565 },  { 8, 0x0233 }, { -1, 0 }
    2.67 -+	};
    2.68 ++	static int vncfmt[] = { 0x40888, 0x20565, 0x10233, 0 };
    2.69  +	char vncver[12];
    2.70  +	int i;
    2.71  +
    2.72 @@ -137,7 +140,7 @@
    2.73   	read(fd, vncver, 12);
    2.74   
    2.75   	read(fd, &connstat, sizeof(connstat));
    2.76 -@@ -88,68 +96,71 @@
    2.77 +@@ -88,68 +94,78 @@
    2.78   	write(fd, &clientinit, sizeof(clientinit));
    2.79   	read(fd, &serverinit, sizeof(serverinit));
    2.80   
    2.81 @@ -166,28 +169,31 @@
    2.82  -	pixfmt_cmd.format.depth = 8;
    2.83   	pixfmt_cmd.format.bigendian = 0;
    2.84   	pixfmt_cmd.format.truecolor = 1;
    2.85 --
    2.86 + 
    2.87  -	pixfmt_cmd.format.rmax = htons(3);
    2.88  -	pixfmt_cmd.format.gmax = htons(7);
    2.89  -	pixfmt_cmd.format.bmax = htons(7);
    2.90 -+	if (bpp < 0) bpp = 0;
    2.91 -+	if (bpp >= 24) bpp = 32;
    2.92 -+	i = 0; do {
    2.93 -+		pixfmt_cmd.format.bpp =
    2.94 -+		pixfmt_cmd.format.depth = fmt[i].bpp;
    2.95 -+		fill_rgb_conv(fmt[i].fmt, &format);
    2.96 -+	} while (bpp <= fmt[++i].bpp);
    2.97 -+	Bpp = pixfmt_cmd.format.bpp / 8;
    2.98 +-	pixfmt_cmd.format.rshl = 0;
    2.99 +-	pixfmt_cmd.format.gshl = 2;
   2.100 +-	pixfmt_cmd.format.bshl = 5;
   2.101 +-
   2.102 ++	if (bpp < 1)
   2.103 ++		bpp = 1;
   2.104 ++	if (bpp >= 3)
   2.105 ++		bpp = 4;
   2.106 ++	for (i = 0; bpp <= FBM_BPP(vncfmt[i]); i++)
   2.107 ++		vnc_mode = vncfmt[i];
   2.108 ++	bpp = FBM_BPP(vnc_mode);
   2.109 ++	pixfmt_cmd.format.bpp =
   2.110 ++	pixfmt_cmd.format.depth = bpp << 3;
   2.111  +
   2.112 ++	fill_rgb_conv(FBM_COLORS(vnc_mode), &format);
   2.113  +	pixfmt_cmd.format.rmax = htons(format.rmax);
   2.114  +	pixfmt_cmd.format.gmax = htons(format.gmax);
   2.115  +	pixfmt_cmd.format.bmax = htons(format.bmax);
   2.116 - 	pixfmt_cmd.format.rshl = 0;
   2.117 --	pixfmt_cmd.format.gshl = 2;
   2.118 --	pixfmt_cmd.format.bshl = 5;
   2.119 --
   2.120 -+	pixfmt_cmd.format.gshl = format.gshr;
   2.121 -+	pixfmt_cmd.format.bshl = format.bshr;
   2.122 ++	pixfmt_cmd.format.rshl = format.rshl;
   2.123 ++	pixfmt_cmd.format.gshl = format.gshl;
   2.124 ++	pixfmt_cmd.format.bshl = 0;
   2.125   	write(fd, &pixfmt_cmd, sizeof(pixfmt_cmd));
   2.126   	return fd;
   2.127   }
   2.128 @@ -229,24 +235,27 @@
   2.129  -			int g = ((c >> 2) & 0x7) << 5;
   2.130  -			int b = ((c >> 5) & 0x7) << 5;
   2.131  -			slice[j] = FB_VAL(r, g, b);
   2.132 --		}
   2.133 ++	int mode = fb_mode();
   2.134 ++	if (mode != vnc_mode) {
   2.135 ++		fbval_t slice[MAXRES];
   2.136 ++		unsigned char *byte = (unsigned char *) slice;
   2.137 ++		int j;
   2.138 ++		int fb_bpp = FBM_BPP(mode);
   2.139 ++		for (j = 0; j < w; j++, byte += fb_bpp, s += bpp) {
   2.140 ++			fbval_t c = * (fbval_t *) s;
   2.141 ++			int r = ((c >> format.rshl) & format.rmax) << format.rskp;
   2.142 ++			int g = ((c >> format.gshl) & format.gmax) << format.gskp;
   2.143 ++			int b = (c & format.bmax) << format.bskp;
   2.144 ++			* (fbval_t *) byte = FB_VAL(r, g, b);
   2.145 + 		}
   2.146  -		fb_set(y + i, x, slice, w);
   2.147 -+	fbval_t slice[MAXRES];
   2.148 -+	unsigned char *byte = (unsigned char *) slice;
   2.149 -+	int j;
   2.150 -+	int mode = FBM_BPP(fb_mode());
   2.151 -+	for (j = 0; j < w; j++, byte += mode, s += Bpp) {
   2.152 -+		fbval_t c = * (fbval_t *) s;
   2.153 -+		int r = (c & format.rmax) << format.rskp;
   2.154 -+		int g = ((c >> format.gshr) & format.gmax) << format.gskp;
   2.155 -+		int b = ((c >> format.bshr) & format.bmax) << format.bskp;
   2.156 -+		* (fbval_t *) byte = FB_VAL(r, g, b);
   2.157 ++		s = (void *) slice;
   2.158   	}
   2.159 -+	fb_set(y, x, slice, w);
   2.160 ++	fb_set(y, x, s, w);
   2.161   }
   2.162   
   2.163   static void xread(int fd, void *buf, int len)
   2.164 -@@ -159,54 +170,79 @@
   2.165 +@@ -159,54 +175,79 @@
   2.166   	while (nr < len && (n = read(fd, buf + nr, len - nr)) > 0)
   2.167   		nr += n;
   2.168   	if (nr < len) {
   2.169 @@ -322,9 +331,9 @@
   2.170  +				int a, b, c = i;
   2.171  +				for (a = b = 0; w > b; b += a, c = 0) {
   2.172  +					a = MIN(w - b, MAXPIX);
   2.173 -+					xread(fd, buf, a * Bpp);
   2.174 ++					xread(fd, buf, a * bpp);
   2.175  +					if (y >= 0 && y < rows && l > b)
   2.176 -+						drawfb(buf + (c * Bpp), x + b,
   2.177 ++						drawfb(buf + (c * bpp), x + b,
   2.178  +						       y, MIN(a, l - b) - c);
   2.179  +				}
   2.180  +			}
   2.181 @@ -350,7 +359,7 @@
   2.182   		return -1;
   2.183   	}
   2.184   	return 0;
   2.185 -@@ -217,12 +253,31 @@
   2.186 +@@ -217,12 +258,31 @@
   2.187   	char ie[3];
   2.188   	struct vnc_client_ratevent me = {VNC_CLIENT_RATEVENT};
   2.189   	int mask = 0;
   2.190 @@ -384,7 +393,7 @@
   2.191   	if (ie[0] & 0x01)
   2.192   		mask |= VNC_BUTTON1_MASK;
   2.193   	if (ie[0] & 0x04)
   2.194 -@@ -233,6 +288,8 @@
   2.195 +@@ -233,6 +293,8 @@
   2.196   	me.x = htons(mc);
   2.197   	me.mask = mask;
   2.198   	write(fd, &me, sizeof(me));
   2.199 @@ -393,7 +402,7 @@
   2.200   	return 0;
   2.201   }
   2.202   
   2.203 -@@ -292,12 +349,11 @@
   2.204 +@@ -292,12 +354,11 @@
   2.205   			k = 0xff0d;
   2.206   			break;
   2.207   		case 0x0c:	/* ^L: redraw */
   2.208 @@ -408,7 +417,7 @@
   2.209   			mod[nmod++] = 0xffe1;
   2.210   		if (k >= 1 && k <= 26) {
   2.211   			k = 'a' + k - 1;
   2.212 -@@ -339,40 +395,42 @@
   2.213 +@@ -339,40 +400,42 @@
   2.214   	write(STDIN_FILENO, show, strlen(show));
   2.215   }
   2.216   
   2.217 @@ -458,7 +467,7 @@
   2.218   }
   2.219   
   2.220   int main(int argc, char * argv[])
   2.221 -@@ -380,27 +438,38 @@
   2.222 +@@ -380,27 +443,38 @@
   2.223   	char *port = VNC_PORT;
   2.224   	char *host = "127.0.0.1";
   2.225   	struct termios ti;
   2.226 @@ -471,7 +480,7 @@
   2.227  +  	}
   2.228  +  	if (*argv[1] == '-' && argc >= 3) {
   2.229  +  		argc -= 2; argv += 2;
   2.230 -+  		bpp = atoi(argv[0]);
   2.231 ++  		bpp = atoi(argv[0]) >> 3;
   2.232  +  	} 
   2.233   	if (argc >= 2)
   2.234   		host = argv[1];