[英]Color issues when forwarding X11 display to Windows
I have an application that plots data, line by line to an X11 display where each line is really comprised of different color pixels. 我有一个应用程序,可以逐行地将数据绘制到X11显示器上,其中每行实际上由不同的颜色像素组成。
I do this by mapping a data array to an XImage*
using XCreateImage
. 我通过使用XCreateImage
将数据数组映射到XImage*
来做到这XCreateImage
。 Then as the data is processed, I populate an XColor
variables with the red, green, and blue values and call XAllocColor
to allocate the color. 然后,在处理数据时,我用红色,绿色和蓝色值填充XColor
变量,并调用XAllocColor
分配颜色。 Then I assign the pixel value to the corresponding element in the data array. 然后,将像素值分配给数据数组中的相应元素。 When all the data is setup, I plot the line using XPutImage
. 设置完所有数据后,我使用XPutImage
绘制线。
When running the displays on Linux, everything looks great, exactly as expected. 在Linux上运行显示器时,一切看起来都很好,完全符合预期。 However, when I forward the X11 display onto Windows via ssh, the colors are all messed up. 但是,当我通过ssh将X11显示器转发到Windows时,颜色都弄乱了。
Any ideas? 有任何想法吗?
EDIT 编辑
If I do not use XCreateImage
and XPutImage
and create a GC
with the forground color I want, and use XDrawPoint
, it works just fine. 如果我不使用XCreateImage
和XPutImage
并使用XCreateImage
XPutImage
创建GC
,并使用XDrawPoint
,则效果很好。 Seems to be an issue with XImage
or the issue is overcome automatically when using a GC
. 似乎与XImage
或者使用GC
时,该问题已自动解决。
I found a solution. 我找到了解决方案。 The problem seems to stem from how Windows does colors vs. Linux. 问题似乎源于Windows与Linux相比如何着色。 Windows stores colors BGR and BGRA where Linux stores colors RGB and ARGB. Windows存储BGR和BGRA颜色,而Linux存储RGB和ARGB颜色。 So, whenever the display is going to Windows, I need to swap the Red and Blue values before calling XAllocColor
and after, I need to multiply the pixel
element of the XColor
by 256 to shift the colors past the alpha component. 因此,无论何时将显示器转到Windows,我都需要在调用XAllocColor
之前交换Red和Blue值,之后,我需要将XColor
的pixel
元素乘以256,以将颜色移到alpha分量之外。
There are some problems associated with this: 有一些与此相关的问题:
Because of this, I am actually doing the method I suggested in my Edit with a few modifications. 因此,我实际上是在做一些修改后在“ 编辑”中建议的方法。 Mainly, I create a GC
for each color that I plan on using during initialization, thus I can just look them up as needed, rather than creating them every time. 主要是,我为初始化期间计划使用的每种颜色创建一个GC
,因此我可以根据需要查找它们,而不必每次都创建它们。 This keeps the performance reasonably on par vs. using an XImage
. 与使用XImage
相比,这可以合理地保持性能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.