X11-图形渲染改进 [英] X11 - Graphics Rendering Improvement
问题描述
我目前正在将无符号整数数组渲染到窗口上的2D图像,但是,对于我要完成的操作而言,它太慢了.这是我的代码:
I am currently rendering an array of unsigned integers to a 2D image on a window, however, it is far too slow for what I want to accomplish with it. Here is my code:
int x = 0;
int y = 0;
GC gc;
XGCValues gcv;
gc = XCreateGC(display, drawable, GCForeground, &gcv);
while (y < height) {
while (x < width) {
XSetForeground(display, gc, AlphaBlend(pixels[(width*y)+x], backcolor));
XDrawPoint(display, drawable, gc, x, y);
x++;
}
x = 0;
y++;
}
XFlush(display);
我想知道是否有人向我展示了一种更快的方法,同时仍将我的无符号整数数组用作绘制到窗口的基本图像并将其保留在X11 API中.我想让它尽可能独立.我不想使用OpenGL,SDL或其他不需要的其他图形库.谢谢.
I was wondering if anyone show me a much faster method for doing this while still using my unsigned integer array as the base image to draw to the window as well as keeping it within the X11 API. I want to keep it as freestanding as possible. I don't want to use OpenGL, SDL or any other extra graphics libraries I do not need. Thank you.
推荐答案
I think that using XImage
could answer your need: see https://tronche.com/gui/x/xlib/graphics/images.html
XImage * s_image;
void init(...)
{
/* data linked to image, 4 bytes per pixel */
char *data = calloc(width * height, 4);
/* image itself */
s_image = XCreateImage(display,
DefaultVisual(display, screen),
DefaultDepth(display, screen),
ZPixmap, 0, data, width, height, 32, 0);
}
void display(...)
{
/* fill the image */
size_t offset = 0;
y = 0;
while (y < height) {
x = 0;
while (x < width) {
XPutPixel(s_image, x, y, AlphaBlend((pixels[offset++], backcolor));
x++;
}
y++;
}
/* put image on display */
XPutImage(display, drawable, cg, s_image, 0, 0, 0, 0, width, height);
XFlush(display);
}
这篇关于X11-图形渲染改进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!