2014-01-30 5 views
0

저는 리눅스에서 "PNG 이미지"프로젝트의 창 배경과 거의 같습니다. 순수 X11 API를 사용하고 최소 LodePNG을 사용하여 이미지를로드합니다. 문제는 배경이 원래 PNG 이미지의 부정적이며 무엇이 문제인지 알 수 없다는 것입니다. XLib 창 배경이 반전 된 색상이 있습니다.

은 기본적으로 다음 이미지를로드 픽스맵을 만들고 창에 배경을 적용하는 코드입니다 :

다음이 적용
// required headers 
// global variables 
Display *display; 
Window window; 
int window_width = 600; 
int window_height = 400; 

// main entry point 

// load the image with lodePNG (I didn't modify its code) 
vector<unsigned char> image; 
unsigned width, height; 

//decode 
unsigned error = lodepng::decode(image, width, height, "bg.png"); 
if(!error) 
{ 
    // And here is where I apply the image to the background 
    Screen* screen = NULL; 
    screen = DefaultScreenOfDisplay(display); 

    // Creating the pixmap 
    Pixmap pixmap = XCreatePixmap(
     display, 
     XDefaultRootWindow(display), 
     width, 
     height, 
     DefaultDepth(display, 0) 
    ); 

    // Creating the graphic context 
    XGCValues gr_values; 
    gr_values.function = GXcopy; 
    gr_values.background = WhitePixelOfScreen(display); 

    // Creating the image from the decoded PNG image 
    XImage *ximage = XCreateImage(
     display, 
     CopyFromParent, 
     DisplayPlanes(display, 0), 
     ZPixmap, 
     0, 
     (char*)&image, 
     width, 
     height, 
     32, 
     4 * width 
    ); 

    // Place the image into the pixmap 
    XPutImage(
     display, 
     pixmap, 
     gr_context, 
     ximage, 
     0, 0, 
     0, 0, 
     window_width, 
     window_height 
    ); 

    // Set the window background 
    XSetWindowBackgroundPixmap(display, window, pixmap); 

    // Free up used resources 
    XFreePixmap(display, pixmap); 
    XFreeGC(display, gr_context); 
} 

이미지 디코딩 (심하게 디코딩 할 수있는 가능성이있다) 그러나 배경에, 내가 말했듯이, 이미지의 색상이 반대로되어 왜 나는 모릅니다.

MORE INFO

디코딩 후에 I는 하나 디코딩 동일 PNG 파일에 동일한 이미지를 인코딩하므로 문제가 I는 Xlib를 플레이하는 방법 LodePNG뿐만 관련이없는 것 같습니다 그것을 창에 놓기 위해.

더 많은 정보 이제 반전 된 이미지를 원래 이미지와 비교하여 내 코드의 어딘가에서 RGB가 BGR로 변환되었음을 알았습니다. 원본 이미지의 한 픽셀이 반전 된 픽셀에 95, 102, 119 인 경우 119, 102, 95입니다.

답변

1

해결책을 찾았습니다 here. 가장 좋은 방법인지는 모르겠지만 확실합니다.