wok-undigest rev 467
fbvnc: add 16 & 32 bpp support
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sat Sep 10 17:36:14 2011 +0200 (2011-09-10) |
parents | 0b636a2cb12e |
children | 20593bf0cf84 |
files | fbvnc/stuff/fbvnc.u |
line diff
1.1 --- a/fbvnc/stuff/fbvnc.u Sat Sep 10 12:46:41 2011 +0200 1.2 +++ b/fbvnc/stuff/fbvnc.u Sat Sep 10 17:36:14 2011 +0200 1.3 @@ -100,7 +100,7 @@ 1.4 static int mr, mc; /* mouse position */ 1.5 1.6 static char buf[MAXRES]; 1.7 -@@ -62,15 +63,18 @@ 1.8 +@@ -62,15 +63,22 @@ 1.9 if (connect(fd, addrinfo->ai_addr, addrinfo->ai_addrlen) == -1) { 1.10 close(fd); 1.11 freeaddrinfo(addrinfo); 1.12 @@ -111,16 +111,20 @@ 1.13 return fd; 1.14 } 1.15 1.16 ++static int bpp, Bpp; 1.17 +static struct rgb_conv format; 1.18 static int vnc_init(int fd) 1.19 { 1.20 ++ static struct { int bpp, fmt; } fmt[] = { 1.21 ++ { 32, 0x0888 }, { 16, 0x0565 }, { 8, 0x0233 }, { -1, 0 } 1.22 ++ }; 1.23 char vncver[] = "RFB 003.003\n"; 1.24 + int i; 1.25 + 1.26 struct vnc_client_init clientinit; 1.27 struct vnc_server_init serverinit; 1.28 struct vnc_client_pixelfmt pixfmt_cmd; 1.29 -@@ -88,68 +92,66 @@ 1.30 +@@ -88,68 +96,71 @@ 1.31 write(fd, &clientinit, sizeof(clientinit)); 1.32 read(fd, &serverinit, sizeof(serverinit)); 1.33 1.34 @@ -149,21 +153,28 @@ 1.35 - pixfmt_cmd.format.depth = 8; 1.36 pixfmt_cmd.format.bigendian = 0; 1.37 pixfmt_cmd.format.truecolor = 1; 1.38 - 1.39 +- 1.40 - pixfmt_cmd.format.rmax = htons(3); 1.41 - pixfmt_cmd.format.gmax = htons(7); 1.42 - pixfmt_cmd.format.bmax = htons(7); 1.43 -+ pixfmt_cmd.format.bpp = pixfmt_cmd.format.depth = 8; 1.44 -+ fill_rgb_conv(0x0233, &format); 1.45 ++ if (bpp < 0) bpp = 0; 1.46 ++ if (bpp >= 24) bpp = 32; 1.47 ++ i = 0; do { 1.48 ++ pixfmt_cmd.format.bpp = 1.49 ++ pixfmt_cmd.format.depth = fmt[i].bpp; 1.50 ++ fill_rgb_conv(fmt[i].fmt, &format); 1.51 ++ } while (bpp <= fmt[++i].bpp); 1.52 ++ Bpp = pixfmt_cmd.format.bpp / 8; 1.53 ++ 1.54 + pixfmt_cmd.format.rmax = htons(format.rmax); 1.55 + pixfmt_cmd.format.gmax = htons(format.gmax); 1.56 + pixfmt_cmd.format.bmax = htons(format.bmax); 1.57 pixfmt_cmd.format.rshl = 0; 1.58 - pixfmt_cmd.format.gshl = 2; 1.59 - pixfmt_cmd.format.bshl = 5; 1.60 +- 1.61 + pixfmt_cmd.format.gshl = format.gshr; 1.62 + pixfmt_cmd.format.bshl = format.bshr; 1.63 - 1.64 write(fd, &pixfmt_cmd, sizeof(pixfmt_cmd)); 1.65 return fd; 1.66 } 1.67 @@ -196,7 +207,7 @@ 1.68 -static void drawfb(char *s, int x, int y, int w, int h) 1.69 +static void drawfb(char *s, int x, int y, int w) 1.70 { 1.71 - fbval_t slice[1 << 14]; 1.72 +- fbval_t slice[1 << 14]; 1.73 - int i, j; 1.74 - for (i = 0; i < h; i++) { 1.75 - for (j = 0; j < w; j++) { 1.76 @@ -207,10 +218,11 @@ 1.77 - slice[j] = FB_VAL(r, g, b); 1.78 - } 1.79 - fb_set(y + i, x, slice, w); 1.80 ++ fbval_t slice[MAXRES]; 1.81 + int j, k; 1.82 + int mode = FBM_BPP(fb_mode()); 1.83 -+ for (j = k = 0; j < w; j++, k += mode) { 1.84 -+ int c = *(unsigned *) &s[j]; 1.85 ++ for (j = k = 0; j < w; j++, k += mode, s += Bpp) { 1.86 ++ fbval_t c = * (fbval_t *) s; 1.87 + int r = (c & format.rmax) << format.rskp; 1.88 + int g = ((c >> format.gshr) & format.gmax) << format.gskp; 1.89 + int b = ((c >> format.bshr) & format.bmax) << format.bskp; 1.90 @@ -221,7 +233,7 @@ 1.91 } 1.92 1.93 static void xread(int fd, void *buf, int len) 1.94 -@@ -181,18 +183,32 @@ 1.95 +@@ -181,18 +192,37 @@ 1.96 xread(fd, msg + 1, sizeof(*fbup) - 1); 1.97 n = ntohs(fbup->n); 1.98 for (j = 0; j < n; j++) { 1.99 @@ -234,12 +246,16 @@ 1.100 w = ntohs(uprect.w); 1.101 h = ntohs(uprect.h); 1.102 - if (x >= cols || x + w > cols) 1.103 -+ if (w > MAXRES) { 1.104 -+ fprintf(stderr,"too much pixels: %d, max %d\n", 1.105 -+ w, MAXRES); 1.106 ++ if (ntohl(uprect.enc) != 0) { 1.107 ++ fprintf(stderr,"Encoding not RAW: %d\n", 1.108 ++ ntohl(uprect.enc)); 1.109 return -1; 1.110 - if (y >= rows || y + h > rows) 1.111 -- return -1; 1.112 ++ } 1.113 ++ if (w * Bpp > MAXRES) { 1.114 ++ fprintf(stderr,"too much pixels: %dx%d, max %d\n", 1.115 ++ w, Bpp, MAXRES); 1.116 + return -1; 1.117 - xread(fd, buf, w * h); 1.118 - drawfb(buf, x, y, w, h); 1.119 + } 1.120 @@ -249,10 +265,10 @@ 1.121 + l = MIN(w, cols - x); 1.122 + if (x < 0) { 1.123 + l = MIN(w + x, cols); 1.124 -+ p -= x; 1.125 ++ p -= x * Bpp; 1.126 + x = 0; 1.127 + } 1.128 -+ for (; h--; y++) { 1.129 ++ for (w *= Bpp; h--; y++) { 1.130 + xread(fd, buf, w); 1.131 + if (y >= 0 && y < rows && l > 0) 1.132 + drawfb(p, x, y, l); 1.133 @@ -260,7 +276,7 @@ 1.134 } 1.135 break; 1.136 case VNC_SERVER_BELL: 1.137 -@@ -217,12 +233,31 @@ 1.138 +@@ -217,12 +247,31 @@ 1.139 char ie[3]; 1.140 struct vnc_client_ratevent me = {VNC_CLIENT_RATEVENT}; 1.141 int mask = 0; 1.142 @@ -294,7 +310,7 @@ 1.143 if (ie[0] & 0x01) 1.144 mask |= VNC_BUTTON1_MASK; 1.145 if (ie[0] & 0x04) 1.146 -@@ -233,6 +268,8 @@ 1.147 +@@ -233,6 +282,8 @@ 1.148 me.x = htons(mc); 1.149 me.mask = mask; 1.150 write(fd, &me, sizeof(me)); 1.151 @@ -303,7 +319,7 @@ 1.152 return 0; 1.153 } 1.154 1.155 -@@ -292,12 +329,11 @@ 1.156 +@@ -292,12 +343,11 @@ 1.157 k = 0xff0d; 1.158 break; 1.159 case 0x0c: /* ^L: redraw */ 1.160 @@ -318,7 +334,7 @@ 1.161 mod[nmod++] = 0xffe1; 1.162 if (k >= 1 && k <= 26) { 1.163 k = 'a' + k - 1; 1.164 -@@ -339,7 +375,7 @@ 1.165 +@@ -339,7 +389,7 @@ 1.166 write(STDIN_FILENO, show, strlen(show)); 1.167 } 1.168 1.169 @@ -327,7 +343,7 @@ 1.170 { 1.171 struct pollfd ufds[3]; 1.172 int pending = 0; 1.173 -@@ -350,29 +386,31 @@ 1.174 +@@ -350,29 +400,31 @@ 1.175 ufds[1].events = POLLIN; 1.176 ufds[2].fd = rat_fd; 1.177 ufds[2].events = POLLIN; 1.178 @@ -363,7 +379,7 @@ 1.179 } 1.180 1.181 int main(int argc, char * argv[]) 1.182 -@@ -380,27 +418,34 @@ 1.183 +@@ -380,27 +432,38 @@ 1.184 char *port = VNC_PORT; 1.185 char *host = "127.0.0.1"; 1.186 struct termios ti; 1.187 @@ -371,9 +387,13 @@ 1.188 + int vnc_fd, rat_fd, status; 1.189 + 1.190 + if (argc < 2) { 1.191 -+ fprintf(stderr, "Usage : fbvnc server [port]\n"); 1.192 ++ fprintf(stderr, "Usage : fbvnc [-bpp bits] server [port]\n"); 1.193 + return 0; 1.194 + } 1.195 ++ if (*argv[1] == '-' && argc >= 3) { 1.196 ++ argc -= 2; argv += 2; 1.197 ++ bpp = atoi(argv[0]); 1.198 ++ } 1.199 if (argc >= 2) 1.200 host = argv[1]; 1.201 if (argc >= 3)