XPutImage() error - Xwindows

This is a discussion on XPutImage() error - Xwindows ; Hello, I need to create a pixmap of depth 1 from an XImage, for using it as clipmask. Could anyone tell me why this piece of code give a XPutImage() BadMatch error: myClipImageData=(char *)malloc((20*20)+100); // keeps large myClipImage=XCreateImage(mydisplay,myvisual,1,XYBi tmap,0, myClipImageData,20,20,8,0); ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: XPutImage() error

  1. XPutImage() error

    Hello,
    I need to create a pixmap of depth 1 from an XImage, for using it as
    clipmask. Could anyone tell me why this piece of code give a XPutImage()
    BadMatch error:

    myClipImageData=(char *)malloc((20*20)+100); // keeps large
    myClipImage=XCreateImage(mydisplay,myvisual,1,XYBi tmap,0,
    myClipImageData,20,20,8,0);
    // create clipmask
    myClipPixmap=XCreatePixmap(mydisplay,window1,20,20 ,1);
    XPutImage(mydisplay,myClipPixmap,mygc,myClipImage, 0,0,0,0,20,20);
    XDestroyImage(myClipImage);

    while instead this (where mydepth is truecolor) works:

    myImageData=(char *)malloc((20*20*24)+1000); // keeps large
    myImage=XCreateImage(mydisplay,myvisual,mydepth,XY Pixmap,0,
    myImageData,20,20,8,0);
    // create the image which the clipmask will be applied to
    myPixmap=XCreatePixmap(mydisplay,window1,20,20,myd epth);
    XPutImage(mydisplay,myPixmap,mygc,myImage,0,0,0,0, 20,20);
    XDestroyImage(myImage);

    Thanks

    here follows full code extracted from my application:

    >>>>>>>>>>>>>>>>>>>>>test.c>>>>>>>>>>>>>>>>>>>>>>>>>>


    #include

    void main(void) {
    Visual *myvisual;
    Display *mydisplay;
    int myscreen,mydepth;
    unsigned long myforeground,mybackground; GC mygc;
    Drawable window1;
    XImage *myImage,*myClipImage;
    Pixmap myPixmap, myClipPixmap;
    char *myClipImageData,*myImageData;

    mydisplay=XOpenDisplay("");
    myscreen=DefaultScreen(mydisplay);
    mydepth=DefaultDepth(mydisplay,myscreen);
    myvisual=DefaultVisual(mydisplay,myscreen);
    myforeground=WhitePixel(mydisplay,myscreen);
    mybackground=BlackPixel(mydisplay,myscreen);

    window1=XCreateSimpleWindow(mydisplay,DefaultRootW indow(mydisplay),
    0,0,100,100,10,myforeground,mybackground);
    XMapRaised(mydisplay,window1);

    mygc=XCreateGC(mydisplay,window1,0,0);


    myImageData=(char *)malloc((20*20*24)+1000); // keeps large
    myImage=XCreateImage(mydisplay,myvisual,mydepth,XY Pixmap,0,
    myImageData,20,20,8,0);
    // create the image which the clipmask will be applied to
    myPixmap=XCreatePixmap(mydisplay,window1,20,20,myd epth);
    XPutImage(mydisplay,myPixmap,mygc,myImage,0,0,0,0, 20,20);
    XDestroyImage(myImage);
    printf("done pixmap\n");

    XSync(mydisplay,0);

    myClipImageData=(char *)malloc((20*20)+100); // keeps large
    // create clipmask
    myClipImage=XCreateImage(mydisplay,myvisual,1,XYBi tmap,0,
    myClipImageData,20,20,8,0);
    myClipPixmap=XCreatePixmap(mydisplay,window1,20,20 ,1);
    XPutImage(mydisplay,myClipPixmap,mygc,myClipImage, 0,0,0,0,20,20);
    XDestroyImage(myClipImage);
    printf("done pixmap clipmask\n");


    XFreeGC(mydisplay,mygc);
    XDestroyWindow(mydisplay,window1);
    XCloseDisplay(mydisplay);
    }

  2. Re: XPutImage() error

    Francesco Benzina writes:

    > Hello,
    > I need to create a pixmap of depth 1 from an XImage, for using it as
    > clipmask. Could anyone tell me why this piece of code give a XPutImage()
    > BadMatch error:
    >
    > myClipImageData=(char *)malloc((20*20)+100); // keeps large
    > myClipImage=XCreateImage(mydisplay,myvisual,1,XYBi tmap,0,
    > myClipImageData,20,20,8,0);
    > // create clipmask
    > myClipPixmap=XCreatePixmap(mydisplay,window1,20,20 ,1);
    > XPutImage(mydisplay,myClipPixmap,mygc,myClipImage, 0,0,0,0,20,20);
    > XDestroyImage(myClipImage);
    >
    > while instead this (where mydepth is truecolor) works:
    >
    > myImageData=(char *)malloc((20*20*24)+1000); // keeps large
    > myImage=XCreateImage(mydisplay,myvisual,mydepth,XY Pixmap,0,
    > myImageData,20,20,8,0);
    > // create the image which the clipmask will be applied to
    > myPixmap=XCreatePixmap(mydisplay,window1,20,20,myd epth);
    > XPutImage(mydisplay,myPixmap,mygc,myImage,0,0,0,0, 20,20);
    > XDestroyImage(myImage);


    The pixel format of the image must match that of the drawable it is
    drawn to. In your case XYPixmap seems to match, but XYBitmap does
    not.

    --
    Måns Rullgård
    mru@inprovide.com

  3. Re: XPutImage() error


    > The pixel format of the image must match that of the drawable it is
    > drawn to. In your case XYPixmap seems to match, but XYBitmap does
    > not.


    that is the question. Why XYPixmap match mydepth(==24), but XYBitmap
    does not match 1, that would be the right behaoviur?
    I need my pixmap to be deep 1 to use as clipmask. So how to build
    a 1-depth pixmap from an XImage (think XYBitmap) ?
    Otherwise, can a clipmask that I want to set with XSetClipMask() be
    a Pixmap deeper than 1?

  4. Re: XPutImage() error

    Francesco Benzina writes:

    >> The pixel format of the image must match that of the drawable it is
    >> drawn to. In your case XYPixmap seems to match, but XYBitmap does
    >> not.

    >
    > that is the question. Why XYPixmap match mydepth(==24), but XYBitmap
    > does not match 1, that would be the right behaoviur?
    > I need my pixmap to be deep 1 to use as clipmask. So how to build
    > a 1-depth pixmap from an XImage (think XYBitmap) ?


    Try using XCreateBitmapFromData().

    --
    Måns Rullgård
    mru@inprovide.com

+ Reply to Thread