Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing python ctypes to get buffer of floats from shared library into python string
    text
    copied!<p>I'm trying to use python ctypes to use these two C functions from a shared library:</p> <pre> <code>bool decompress_rgb(unsigned char *data, long dataLen, int scale) float* getRgbBuffer()</code></pre> <p>The first function is working fine. I can tell by putting some debug code in the shared library and checking the input.</p> <p>The problem is getting the data out. The RGB buffer is a pointer to a float (obviously) and this pointer stays constant during the life of the application. Therefore whenever I want to decompress an image, I call <code>decompress_rgb</code> and then need to see what's at the location pointed to by <code>getRgbBuffer</code>. I know that the buffer size is (720 * 288 * sizeof(float)) so I guess this has to come into play somewhere.</p> <p>There's no <code>c_float_p</code> type so I thought I'd try this:</p> <pre><code>getRgbBuffer.restype = c_char_p</code></pre> <p>Then I do:</p> <pre><code>ptr = getRgbBuffer() print "ptr is ", ptr</code></pre> <p>which just outputs:</p> <pre><code>ptr = 3078746120</code></pre> <p>I'm guessing that's the actual address rather than the content, but even if I was successfully dereferencing the pointer and getting the contents, it would only be the first char.</p> <p>How can I get the contents of the entire buffer into a python string? </p> <p><strong>Edit:</strong> Had to change:</p> <pre><code>getRgbBuffer.restype = c_char_p</code></pre> <p>to</p> <pre><code>getRgbBuffer.restype = c_void_p</code></pre> <p>but then BastardSaint's answer worked.</p>
 

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