linux C++ XImage RGB <-> BGR?

蓝咒 提交于 2019-12-06 12:40:10

问题


I have a vector containing RGBA (actualy I don't care about the alpha channel) value from a picture, I want to draw this picture with xlib. So I have to use an XImage and to got one I need to use XCreateImage.

XCreateImage requires "char *data" so first I need to convert my vector. I don't know if what I'm doing is efficient, but that works :

vector<unsigned char> picture;
cunsigned char *unsigneddata = &picture[0];
char *data;
data =  (char*)unsigneddata;

so now I can use "data" to draw my picture,

XImage *ximage = XCreateImage(display, visual /*errata : not window*/, 24, ZPixmap, 0, data, width, height, 32, 0);
XPutImage(dpy, *_w,gc,ximage,0,0,0,0,width,height);

my picture at screen has the red and the blue channels inverted. I don't know if I mess something or if it's correct and if I have to swap the channels. If I have to swap, there is another way than just doing a loop over the array to swap them ?


回答1:


you know what? I'm tired of dat shit! I just swap the values...

  // invert red and blue, xlib ams dumb, it using BGR instead of RGB...
  unsigned char red, blue;
  int i;
  for(i=0;i<image.size();i+=4){
   red  = image[i+2];
   blue = image[i];
   image[i]   = red;
   image[i+2] = blue;
  }

thank you for your comments n.m.



来源:https://stackoverflow.com/questions/17017432/linux-c-ximage-rgb-bgr

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!