我需要导入 PNG 并将其显示在 Motif 应用程序的屏幕上。由于我自己最清楚的原因,我不想使用超出需要的库,并且我想只使用 Motif 和 pnglib。
我已经为此奋斗了几天,我想放下我的骄傲并寻求一些帮助。此屏幕截图显示了问题:
https://s3.amazonaws.com/gtrebol264929/pnglib_fail.png https://s3.amazonaws.com/gtrebol264929/pnglib_fail.png
右侧的窗口显示图像应是什么样子,左侧的窗口是我的 Motif 应用程序,显示它在我的应用程序中的样子。显然我已经得到了图像数据,因为可以看到图片的基本概念。但也很明显,我搞砸了如何将像素数据从 pnglib 获取到 XImage 中。下面是我的代码:
char * xdata = malloc(width * height * (channels + 1));
memset(xdata,100,width * height * channels);
int colc = 0;
int bytec = 0;
while (colc < width) {
int rowc = 0;
while(rowc < height) {
png_byte * row = png.row_pointers[rowc];
memcpy(&xdata[bytec],&row[colc],1);
bytec += 4;
rowc += 1;
}
colc += 1;
}
XImage * img = XCreateImage(display, CopyFromParent, depth * channels, ZPixmap, 0, xdata, width, height, 32, bytes_per_line);
printf("PNG %ix%i (depth: %i x %i) img: %p\n",width,height,depth,channels,img);
XPutImage (display, win, gc, img, 0, 0, 0, 0, width, height); // 0, 0, 0, 0 are src x,y and dst x,y
png.row_pointers 是来自 pnglib 的像素数据。
我很确定我只是误解了像素数据的存储方式,但我无法完全弄清楚我做错了什么。很感谢任何形式的帮助。
一切顺利
Garry