简体   繁体   中英

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.

I do this by mapping a data array to an XImage* using 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. 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 .

When running the displays on Linux, everything looks great, exactly as expected. However, when I forward the X11 display onto Windows via ssh, the colors are all messed up.

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. Seems to be an issue with XImage or the issue is overcome automatically when using a GC .

I found a solution. The problem seems to stem from how Windows does colors vs. Linux. Windows stores colors BGR and BGRA where Linux stores colors RGB and 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.

There are some problems associated with this:

  1. The application cannot tell if the display is rendered on Linux or Windows, so I am using an environment variable for testing
  2. This only works for 32-bit screen depths on Windows, ignore the multiply by 256 if the depth is only 24-bit, less than that I don't know

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. This keeps the performance reasonably on par vs. using an XImage .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM