如何上传32位图像到服务器端的像素图 [英] How to upload 32 bit image to server-side pixmap

查看:138
本文介绍了如何上传32位图像到服务器端的像素图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建客户端缓冲服务器端的RGBA像素图。 CreatePixmap&安培;工作的createImage确定为32位和24位,但XPutImage导致服务器返回的匹配误差

 失败请求的X误差:BadMatch(无效的参数属性)
  失败请求的主要运算code:72(X_PutImage)
  序列号失败的请求:8
  在输出流中当前的序列号:8

服务器不支持32位像素图(xdpyinfo输出: https://gist.github.com/2582961 )。在Ubuntu 12.04相同的行为(X.Org版本:1.11.3)和OSX与X.app(X.Org版本:1.10.3)

为什么以下code失败了呢?

 的#include<&stdlib.h中GT;
#包括LT&; X11 / Xlib.h>INT主(INT ARGC,字符** argv的)
{
    INT宽度= 100;
    INT高= 100;
    INT深度= 32; //正常工作与深度= 24
    INT bitmap_pad = 32; // 32 24和32 BPP,16,15及16条
    INT bytes_per_line = 0; //字节之一的扫描线的开始和下一个的开始之间的客户机的图像的数目
    显示*显示= XOpenDisplay(0);
    无符号字符* image32 =(无符号字符*)malloc的(宽*高* 4);
    XImage * IMG = XCreateImage(显示,CopyFromParent,深度,ZPixmap,0,image32,宽度,高度,bitmap_pad,bytes_per_line);
    像素图P = XCreatePixmap(显示器,XDefaultRootWindow(显示器),宽度,高度,深度);
    XPutImage(显示,P,DefaultGC(显示,0),IMG,0,0,0,0,宽度,高度); // 0,0,0,0是SRC x,y和DST的x,y
    XEvent EV;
    而(1){
       XNextEvent例行(显示器,功放及; EV);
    }
}

更新:它看起来像我终于得到了答案:用像素图来代替DefaultGC相关的用GC(其中有根窗口的深度)

 的#include<&stdlib.h中GT;
#包括LT&; X11 / Xlib.h>INT主(INT ARGC,字符** argv的)
{
    INT宽度= 100;
    INT高= 100;
    INT深度= 32; //正常工作与深度= 24
    INT bitmap_pad = 32; // 32 24和32 BPP,16,15及16条
    INT bytes_per_line = 0; //字节之一的扫描线的开始和下一个的开始之间的客户机的图像的数目
    显示*显示= XOpenDisplay(0);
    无符号字符* image32 =(无符号字符*)malloc的(宽*高* 4);
    XImage * IMG = XCreateImage(显示,CopyFromParent,深度,ZPixmap,0,image32,宽度,高度,bitmap_pad,bytes_per_line);
    像素图P = XCreatePixmap(显示器,XDefaultRootWindow(显示器),宽度,高度,深度);
    XGCValues​​ gcvalues​​;
    GC GC = XCreateGC(显示,P,0,&安培; gcvalues​​);
    XPutImage(显示,对,GC,IMG,0,0,0,0,宽度,高度); // 0,0,0,0是SRC x,y和DST的x,y
    XEvent EV;
    而(1){
       XNextEvent例行(显示器,功放及; EV);
    }
}


解决方案

那么,你的code适用于32位图像,如果你只是建立一个GC传递绘制的参数,它是32位。 XCreateGC(DPY,可拉伸,0,0),其中,可拉伸可以是具有32位深度的像素映像。它可以完美的我。

I'm trying to create server-side RGBA pixmap from client-side buffer. CreatePixmap & CreateImage work ok for 32 and 24 bit, but XPutImage result in Match Error returned by server

X Error of failed request:  BadMatch (invalid parameter attributes)
  Major opcode of failed request:  72 (X_PutImage)
  Serial number of failed request:  8
  Current serial number in output stream:  8

server does support 32 bit pixmaps (xdpyinfo output: https://gist.github.com/2582961). Same behaviour on ubuntu 12.04 (X.Org version: 1.11.3) and OSX with X.app (X.Org version: 1.10.3)

Why following code fails?

#include     <stdlib.h>
#include     <X11/Xlib.h>

int main(int argc, char **argv)
{
    int width = 100;
    int height = 100;
    int depth = 32; // works fine with depth = 24
    int bitmap_pad = 32; // 32 for 24 and 32 bpp, 16, for 15&16
    int bytes_per_line = 0; // number of bytes in the client image between the start of one scanline and the start of the next
    Display *display=XOpenDisplay(0);
    unsigned char *image32=(unsigned char *)malloc(width*height*4);
    XImage *img = XCreateImage(display, CopyFromParent, depth, ZPixmap, 0, image32, width, height, bitmap_pad, bytes_per_line);
    Pixmap p = XCreatePixmap(display, XDefaultRootWindow(display), width, height, depth);
    XPutImage(display, p, DefaultGC(display, 0), img, 0, 0, 0, 0, width, height); // 0, 0, 0, 0 are src x,y and dst x,y
    XEvent ev;
    while (1) {
       XNextEvent(display, &ev);
    }
}

Update: It looks like I finally got answer: use GC associated with pixmap instead of DefaultGC (which has depth of root window)

#include     <stdlib.h>
#include     <X11/Xlib.h>

int main(int argc, char **argv)
{
    int width = 100;
    int height = 100;
    int depth = 32; // works fine with depth = 24
    int bitmap_pad = 32; // 32 for 24 and 32 bpp, 16, for 15&16
    int bytes_per_line = 0; // number of bytes in the client image between the start of one scanline and the start of the next
    Display *display=XOpenDisplay(0);
    unsigned char *image32=(unsigned char *)malloc(width*height*4);
    XImage *img = XCreateImage(display, CopyFromParent, depth, ZPixmap, 0, image32, width, height, bitmap_pad, bytes_per_line);
    Pixmap p = XCreatePixmap(display, XDefaultRootWindow(display), width, height, depth);
    XGCValues gcvalues;
    GC gc = XCreateGC(display, p, 0, &gcvalues);
    XPutImage(display, p, gc, img, 0, 0, 0, 0, width, height); // 0, 0, 0, 0 are src x,y and dst x,y
    XEvent ev;
    while (1) {
       XNextEvent(display, &ev);
    }
}

解决方案

Well, your code works for 32 bits images if you just create a GC passing a drawable on argument which is 32 bits. XCreateGC(dpy, drawable, 0, 0), where drawable can be a pixmap with 32 bits depth. It works perfect with me.

这篇关于如何上传32位图像到服务器端的像素图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆