Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplay data from pnglib as an ximage
    primarykey
    data
    text
    <p>I need to import a PNG and display it on screen in a Motif application. For reasons best known to myself, I don't want to use any more libraries than I need to, and I'd like to stick with just Motif and pnglib.</p> <p>I've been battling with this for a couple of days now, and I'd like to put aside my pride and ask for some help. This screenshot shows the problem:</p> <p><a href="https://s3.amazonaws.com/gtrebol264929/pnglib_fail.png" rel="nofollow">https://s3.amazonaws.com/gtrebol264929/pnglib_fail.png</a></p> <p>The window on the right shows what the image should look like, the window on the left is my Motif application showing what it looks like in my app. Clearly I've got the image data OK, as the basic concept of the picture can be seen. But also clearly I've messed up how I get the pixel data from pnglib into an XImage. Below is my code:</p> <pre><code>char * xdata = malloc(width * height * (channels + 1)); memset(xdata,100,width * height * channels); int colc = 0; int bytec = 0; while (colc &lt; width) { int rowc = 0; while(rowc &lt; height) { png_byte * row = png.row_pointers[rowc]; memcpy(&amp;xdata[bytec],&amp;row[colc],1); bytec += 4; rowc += 1; } colc += 1; } XImage * img = XCreateImage(display, CopyFromParent, depth * channels, ZPixmap, 0, xdata, width, height, 32, bytes_per_line); printf("PNG %ix%i (depth: %i x %i) img: %p\n",width,height,depth,channels,img); XPutImage (display, win, gc, img, 0, 0, 0, 0, width, height); // 0, 0, 0, 0 are src x,y and dst x,y </code></pre> <p>png.row_pointers is the pixel data from pnglib. </p> <p>I'm pretty sure I've just misunderstood how the pixel data is stored, but I can't quite work out what I've done wrong. Any help is very much appreciated.</p> <p>All the best</p> <p>Garry</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload