• XQueryColor() failing on dual monitor system

    From [email protected]@21:1/5 to All on Fri Oct 27 09:18:08 2023
    XPost: comp.windows.x

    Hi

    I'm hoping to write some code to save the contents of a window clicked on by the mouse to a file and my plan was to get its image, save the pixels then reload them into an image created by XCreateImage. However on one of the 3 systems I'm using the XQueryColor() call fails in the following code (but never fails on the other 2). The only difference is the one it crashes on is a dual monitor system:

    :
    :
    screen = DefaultScreen(display);
    cmap = DefaultColormap(display,screen);
    :
    :
    win = event.xbutton.subwindow ?
    event.xbutton.subwindow : event.xbutton.window;

    XGetWindowAttributes(display,win,&att);
    printf("Window %ld, width = %d, height = %d\n",
    win,att.width,att.height);

    puts("Grabbing image...");
    oldimg = XGetImage(
    display,win,
    0,0,att.width,att.height,AllPlanes,XYPixmap);

    puts("Pixels...");
    for(x=0;x < att.width;++x)
    {
    for(y=0;y < att.height;++y)
    {
    printf("X,Y = %d,%d\n",x,y);
    pixel = XGetPixel(oldimg,x,y);
    col.pixel = pixel;
    XQueryColor(display,cmap,&col);


    $ ./a.out
    Window 54532344, width = 786, height = 1037
    Grabbing image...
    Pixels...
    :
    :
    X,Y = 12,26
    X,Y = 12,27
    X,Y = 12,28
    X,Y = 12,29
    X,Y = 12,30
    X Error of failed request: BadValue (integer parameter out of range for operati
    on)
    Major opcode of failed request: 91 (X_QueryColors)
    Value in failed request: 0x1000000
    Serial number of failed request: 11
    Current serial number in output stream: 11


    Is there some obvious mistake I'm making?

    Thanks for any help

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Marco Moock@21:1/5 to All on Fri Oct 27 11:59:15 2023
    XPost: comp.windows.x

    Am 27.10.2023 um 09:18:08 Uhr schrieb [email protected]:

    I'm hoping to write some code to save the contents of a window
    clicked on by the mouse to a file and my plan was to get its image,
    save the pixels then reload them into an image created by
    XCreateImage.

    Why don't use xwd to save the image of a window?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to [email protected] on Fri Oct 27 13:52:23 2023
    XPost: comp.windows.x

    [email protected] writes:
    Hi

    I'm hoping to write some code to save the contents of a window clicked on by >the mouse to a file

    $ man 1 xwd


    and my plan was to get its image, save the pixels then
    reload them into an image created by XCreateImage.

    $ man 1 convert (from the ImageMagick package)

    I'd look at the sources for xwd (part of the X11 distribution)
    to see how they handled the colormaps and/or direct color.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From [email protected]@21:1/5 to Marco Moock on Fri Oct 27 14:51:50 2023
    XPost: comp.windows.x

    On Fri, 27 Oct 2023 11:59:15 +0200
    Marco Moock <[email protected]> wrote:
    Am 27.10.2023 um 09:18:08 Uhr schrieb [email protected]:

    I'm hoping to write some code to save the contents of a window
    clicked on by the mouse to a file and my plan was to get its image,
    save the pixels then reload them into an image created by
    XCreateImage.

    Why don't use xwd to save the image of a window?

    Because I'm saving more than just the image of a window and I don't like
    using system() or popen() to fork a utility that may or may not be available.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From [email protected]@21:1/5 to Scott Lurndal on Fri Oct 27 16:07:30 2023
    XPost: comp.windows.x

    On Fri, 27 Oct 2023 15:57:58 GMT
    [email protected] (Scott Lurndal) wrote:
    [email protected] writes:
    On Fri, 27 Oct 2023 11:59:15 +0200
    Marco Moock <[email protected]> wrote:
    Am 27.10.2023 um 09:18:08 Uhr schrieb [email protected]:

    I'm hoping to write some code to save the contents of a window
    clicked on by the mouse to a file and my plan was to get its image,
    save the pixels then reload them into an image created by
    XCreateImage.

    Why don't use xwd to save the image of a window?

    Because I'm saving more than just the image of a window and I don't like >>using system() or popen() to fork a utility that may or may not be available. >>

    Use the source, luke.

    Yes, I did. Looks complicated but I still don't know what I'm doing wrong. Given I'm working with 24 bit colour I might just bypass XQueryColor() and
    get the RGB values direct from the pixel.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to [email protected] on Fri Oct 27 15:57:58 2023
    XPost: comp.windows.x

    [email protected] writes:
    On Fri, 27 Oct 2023 11:59:15 +0200
    Marco Moock <[email protected]> wrote:
    Am 27.10.2023 um 09:18:08 Uhr schrieb [email protected]:

    I'm hoping to write some code to save the contents of a window
    clicked on by the mouse to a file and my plan was to get its image,
    save the pixels then reload them into an image created by
    XCreateImage.

    Why don't use xwd to save the image of a window?

    Because I'm saving more than just the image of a window and I don't like >using system() or popen() to fork a utility that may or may not be available.


    Use the source, luke.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From candycanearter07@21:1/5 to [email protected] on Sat Oct 28 19:17:37 2023
    XPost: comp.windows.x

    On 10/27/23 04:18, [email protected] wrote:
    Hi

    I'm hoping to write some code to save the contents of a window clicked on by the mouse to a file and my plan was to get its image, save the pixels then reload them into an image created by XCreateImage. However on one of the 3 systems I'm using the XQueryColor() call fails in the following code (but never
    fails on the other 2). The only difference is the one it crashes on is a dual monitor system:

    :
    :
    screen = DefaultScreen(display);
    cmap = DefaultColormap(display,screen);
    :
    :
    win = event.xbutton.subwindow ?
    event.xbutton.subwindow : event.xbutton.window;

    XGetWindowAttributes(display,win,&att);
    printf("Window %ld, width = %d, height = %d\n",
    win,att.width,att.height);

    puts("Grabbing image...");
    oldimg = XGetImage(
    display,win,
    0,0,att.width,att.height,AllPlanes,XYPixmap);

    puts("Pixels...");
    for(x=0;x < att.width;++x)
    {
    for(y=0;y < att.height;++y)
    {
    printf("X,Y = %d,%d\n",x,y);
    pixel = XGetPixel(oldimg,x,y);
    col.pixel = pixel;
    XQueryColor(display,cmap,&col);


    $ ./a.out
    Window 54532344, width = 786, height = 1037
    Grabbing image...
    Pixels...
    :
    :
    X,Y = 12,26
    X,Y = 12,27
    X,Y = 12,28
    X,Y = 12,29
    X,Y = 12,30
    X Error of failed request: BadValue (integer parameter out of range for operati
    on)
    Major opcode of failed request: 91 (X_QueryColors)
    Value in failed request: 0x1000000
    Serial number of failed request: 11
    Current serial number in output stream: 11


    Is there some obvious mistake I'm making?

    Thanks for any help


    You could always try looking at the source code for xcolor and copy that.
    --
    user <candycane> is generated from /dev/urandom

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Spiros Bousbouras@21:1/5 to [email protected] on Sun Oct 29 13:28:54 2023
    XPost: comp.windows.x

    On Fri, 27 Oct 2023 09:18:08 -0000 (UTC)
    [email protected] wrote:
    Hi

    I'm hoping to write some code to save the contents of a window clicked on by the mouse to a file and my plan was to get its image, save the pixels then reload them into an image created by XCreateImage. However on one of the 3 systems I'm using the XQueryColor() call fails in the following code (but never
    fails on the other 2). The only difference is the one it crashes on is a dual monitor system:

    [...]

    Is there some obvious mistake I'm making?

    The standard advice in such cases is to post full compilable code which reproduces the problem and take it from there. If you are making an obvious mistake , the effort to create such code may reveal the mistake.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)