我有这个程序真的很慢.分析揭示了XGet

Image中的瓶颈(不是我不能在循环中调用XGetImage).在阅读推荐的解决方案时,请调用XShmGetImage,但文档真的很糟糕.

我正在寻找如何调用XShmCreateImage,XShmGetImage和XShmSetImage的简单示例代码.

深度分析肯定会使XGetImage成为根本瓶颈而不是XPutImage(是的,我知道调用XFlush使分析准确),因此我可能会得出结论,对内存分配器的隐式调用实际上是缓慢但没有XGetImage的变体这让我传递一个预分配的XImage,除了XShmGetImage.无论如何,Shm功能的使用可能会进一步提高.

MIT-SHM文档并不糟糕.它根本就不存在.

这是一个有效的咒语:

Display *d;

int s;

XImage *image;

XShmSegmentInfo shminfo;

d = XOpenDisplay(NULL);

s = DefaultScreen(d);

image = XShmCreateImage(d,

DefaultVisual(d,0), // Use a correct visual. Omitted for brevity

24, // Determine correct depth from the visual. Omitted for brevity

ZPixmap, NULL, &shminfo, 100, 100);

shminfo.shmid = shmget(IPC_PRIVATE,

image->bytes_per_line * image->height,

IPC_CREAT|0777);

shminfo.shmaddr = image->data = shmat(shminfo.shmid, 0, 0);

shminfo.readOnly = False;

XShmAttach(d, &shminfo);

XShmGetImage(d,

RootWindow(d,0),

image,

AllPlanes);

我有这个程序真的很慢.分析揭示了XGetImage中的瓶颈(不是我不能在循环中调用XGetImage).在阅读推荐的解决方案时,请调用XShmGetImage,但文档真的很糟糕.我正在寻找如何调用XShmCreateImage,XShmGetImage和XShmSetImage的简单示例代码.深度分析肯定会使XGetImage成为根本瓶颈而不是XPutImage(是的,我知道调用XFlush使分析... // 分别为:烟花中心到图片边缘的最远距离、烟花中心到图片左上角的距离 (x、y) 两个分量 int r[13] = { 120, 120, 155, 123, 130, 147, 138, 138, 130, 135, 140, 132, 155 }; int x[13] = { 120, 120, 110, 117, 110, 93, 102, 102, 110, 105, 100, 108, 110 }; int y[13] = { 120, 120, 85, 118, 120, 103, 105, 110, 110, 120, 120, 104, 85 }; for (int i = 0; i < NUM; i++) // 初始化烟花 Fire[i].x = 0; // 烟花中心坐标 Fire[i].y = 0; Fire[i].width = 240; // 图片宽 Fire[i].height = 240; // 图片高 Fire[i].max_r = r[i]; // 最大半径 Fire[i].cen_x = x[i]; // 中心距左上角距离 Fire[i].cen_y = y[i]; Fire[i].show = false; // 是否绽放 Fire[i].dt = 5; // 绽放时间间隔 Fire[i].t1 = timeGetTime(); Fire[i].r = 0; // 从 0 开始绽放 if ((Jet[i].y - Jet[i].hy) * 4 < Jet[i].height) // 上升到高度的 3 / 4,减速 Jet[i].dt = rand() % 4 + 10; if (Jet[i].y <= Jet[i].hy) // 上升到最大高度 put image (Jet[i].x, Jet[i].y, &Jet[i].img[Jet[i].n], SRCINVERT); // 擦掉烟花弹 Fire[i].x = Jet[i].hx + 10; // 在烟花弹中间爆炸 Fire[i].y = Jet[i].hy; // 在最高点绽放 Fire[i].show = true; // 开始绽放 Jet[i].shoot = false; // 停止发射 Jet[i].t1 = Jet[i].t2; // 绽放烟花 void Show(DWORD* pMem) // 烟花个阶段绽放时间间隔,制作变速绽放效果 int drt[16] = { 5, 5, 5, 5, 5, 6, 25, 25, 25, 25, 55, 55, 55, 55, 55 }; for (int i = 0; i Fire[i].dt&& Fire[i].show == true) if (Fire[i].r = Fire[i].max_r - 1) Fire[i].draw = false; Init_Fire(); Fire[i].t1 = Fire[i].t2; // 如果该号炮花可爆炸,根据当前爆炸半径画烟花,颜色值接近黑色的不输出。 if (Fire[i].draw) for (double a = 0; a <= 6.28; a += 0.01) int x1 = (int)(Fire[i].cen_x + Fire[i].r * cos(a)); // 相对于图片左上角的坐标 int y1 = (int)(Fire[i].cen_y - initgraph(350, 600); IMAGE img_bk; //define IMAGE 对象 load image (&img_bk, "D:\\background.jpg"); //读取图片到 IMAGE 对象 put image (0, 0, &img MIT-SHM—The MIT Shared Memory Extension How the shared memory extension works 1. REQUIREMENTS 2. WHAT IS PROVIDED 3. HOW TO USE THE SHARED MEMORY
byfanxiushu 2019-12-30转载或引用请注明原始作者。 前几章介绍xdisp_virt移植的时候,分别阐述了xdisp_virt移植整个工程,iOS平台相关的各种数据采集,macOS平台相关的各种数据采集。 这篇文章阐述Linux平台下的桌面图像数据采...
int dstY, // 绘制位置的 y 坐标 IMAGE *pSrcImg, // 要绘制的 IMAGE 对象指针 DWORD dwRop = SRCCOPY // 三元光栅操作码
你可以在 使用 put image 函数 前,先 使用 setbkmode 函数 将背景模式设置为透明,这样就可以避免put image 函数 输出的图覆盖outtextxy 函数 输出的字了。具体代码如下: setbkmode(TRANSPARENT); //设置背景模式为透明 outtextxy(x, y, str); //输出字 put image (x, y, &img); //输出图