5 RGB12 = CHAN4(CIgnore, 4, CRed, 4, CGreen, 4, CBlue, 4),
6 BGR12 = CHAN4(CIgnore, 4, CBlue, 4, CGreen, 4, CRed, 4),
7 BGR8 = CHAN3(CBlue, 2, CGreen, 3, CRed, 3),
10 void (*cvtpixels)(uchar*, uchar*, int);
13 chan2fmt(Pixfmt *fmt, ulong chan)
18 for(rc = chan; rc; rc >>=8){
22 fmt->red = (Colorfmt){(1<<NBITS(c))-1, shift};
25 fmt->blue = (Colorfmt){(1<<NBITS(c))-1, shift};
28 fmt->green = (Colorfmt){(1<<NBITS(c))-1, shift};
36 * convert 32-bit data to 24-bit data by skipping
37 * the last of every four bytes. we skip the last
38 * because we keep the server in little endian mode.
41 cvt32to24(uchar *dst, uchar *src, int npixel)
45 for(i=0; i<npixel; i++){
54 * convert RGB12 (x4r4g4b4) into CMAP8
56 static uchar rgb12[16*16*16];
65 rgb12[r*256+g*16+b] = rgb2cmap(r*0x11, g*0x11, b*0x11);
69 cvtrgb12tocmap8(uchar *dst, uchar *src, int npixel)
73 for(i=0; i<npixel; i++){
74 s = (src[0] | (src[1]<<8)) & 0xFFF;
81 * convert BGR8 (b2g3r3, default VNC format) to CMAP8
84 static uchar bgr8[256];
92 b = (b<<6)|(b<<4)|(b<<2)|b;
94 g = (g<<5)|(g<<2)|(g>>1);
96 r = (r<<5)|(r<<2)|(r>>1);
97 bgr8[i] = rgb2cmap(r, g, b);
102 cvtbgr332tocmap8(uchar *dst, uchar *src, int npixel)
108 *dst++ = bgr8[*src++];
118 if((bpp / 8) * 8 != bpp)
119 sysfatal("screen not supported");
121 depth = screen->depth;
126 fprint(2, "24bit emulation using 32bpp\n");
128 cvtpixels = cvt32to24;
134 fprint(2, "8bit emulation using 12bpp\n");
138 cvtpixels = cvtrgb12tocmap8;
142 fprint(2, "8bit emulation using 6bpp\n"); /* 6: we throw away 1 r, g bit */
146 cvtpixels = cvtbgr332tocmap8;
156 if(v->red.max == 0 || v->green.max == 0 || v->blue.max == 0)
157 sysfatal("screen not supported");
160 fprint(2, "%d bpp, %d depth, 0x%lx chan, %d truecolor, %d bigendian\n",
161 v->bpp, v->depth, screen->chan, v->truecolor, v->bigendian);
163 /* send information to server */
164 vncwrchar(v, MPixFmt);
165 vncwrchar(v, 0); /* padding */
167 vncwrpixfmt(v, &v->Pixfmt);