我正在研究使用“RAW”像素编码的 RFB 服务器的简单实现。我使用 TightVNC 作为我的桌面客户端。我的代码工作到客户端能够请求整个“桌面”(640x480 像素)的程度。我的测试图案在形状方面绘制正确,但颜色错误。
我尝试使用每像素 8 位:每个字节中三个红色、三个绿色和两个蓝色编码为 RRRGGGBB
。
我的 ServerInit 数据包包含此像素编码规范...
//all of these 13 fields are unsigned chars...
si.pf.bits_per_pixel = 8;
si.pf.depth = 8;
si.pf.big_endian_flag = 0;
si.pf.true_colour_flag = 1;
si.pf.red_max_hi = 0;
si.pf.red_max_lo = 7; // 3 bits
si.pf.green_max_hi = 0;
si.pf.green_max_lo = 7; // 3 bits
si.pf.blue_max_hi = 0;
si.pf.blue_max_lo = 3; // 2 bits
si.pf.red_shift = 5; // >>>>>RRR
si.pf.green_shift = 2; // >>RRRGGG
si.pf.blue_shift = 0; // RRRGGGBB
//remaining fields are omitted
整个结构定义如下:
typedef struct
{
uchar bits_per_pixel;
uchar depth;
uchar big_endian_flag;
uchar true_colour_flag;
uchar red_max_hi;
uchar red_max_lo;
uchar green_max_hi;
uchar green_max_lo;
uchar blue_max_hi;
uchar blue_max_lo;
uchar red_shift;
uchar green_shift;
uchar blue_shift;
uchar padding0;
uchar padding1;
uchar padding2;
}tPixelFormat;
现在,如果我用 0xe0
(二进制 111 000 00
)填充桌面图像,那么我希望它被解释为纯亮红色。但它显示为浅蓝色(就好像 8 个单独的位被反向解释一样!)。我的测试图案的形状是正确的,因为我在顶角绘制了一些白色像素(白色显然是二进制 111 111 11
)。
我不明白这个。我相信我已经遵循了 RFB 规范中描述的算法和编码... http://vncdotool.readthedocs.org/en/latest/rfbproto.html#serverinit
我做错了什么?
最佳答案
Wireshark 来救援!解决了。
事实证明,客户端发送了一个我没有看到的 SetPixelFormat
请求,代码忽略了它,显然服务器必须通过更改其输出格式来满足该请求。
解决方法是通过对客户端要求的值进行硬编码,从一开始就为客户端提供所需的内容。此时客户端再也不会发送该请求,因为它对服务器现在从一开始发出的内容感到满意。
关于c - 远程帧缓冲服务器中的颜色编码不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35845646/