LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Cast uint8_t[256][3] array from DLL to a user defined palette for an image

Solved!
Go to solution

Hi!

I have a DLL with a function that fills a given buffer with an RGB palette for single-channel 8-bit images. I would like LabVIEW to pass a buffer to this function and then use the contents of that buffer as a user defined palette for an image. I have the source code for the function and I can change it to accept a different type of parameter if that would make things easier.

I had assumed that if I connected output field of the "buf" function parameter to "User palette" field of an image, LabVIEW would automatically allocate a buffer for the function to overwrite. I tried to use the Type Cast function, but nothing I connected to the "type" field would make it work.

What am I missing?

0 Kudos
Message 1 of 3
(2,913 Views)
Solution
Accepted by topic author ikrylov

There are several ways you could do that. One would be to preallocate a 2D array of 256 * 3 elements and feed it in the left side of the Call Library Node. After the call the palette is available on the right side and then you have to loop through the array and convert the inner dimension with an Array to Cluster node to the 3 elements.

 

The more straightforward way is to reconfigure the Call Library Node parameter as Adapt to Type, preallocate an array of 256 cluster elements, pass that into the CLN and then wire the right side of the CLN directly to the Palette property.

 

Palette to Call Library Node.png

 

Both ways are identical in terms of calling the C function in the DLL. The only possible difficulty might be to have to try to figure out if the array that your C function receives is ordered as a contiguous memory array with 256 * 3 elements or rather 3 * 256. I never know ahead and never bothered to try to remember the rules as it is generally easy enough to just trial and error.

Rolf Kalbermatter
My Blog
Message 2 of 3
(2,851 Views)

Thank you for your reply!

 

As you told me, I set the CLN parameter node to Adapt to Type / Array data pointer and connected an array constant to it (to the left). C declaration of

buf[256][3]

corresponded to 256-element array of 3-element clusters.

 

Now I can show images in a custom CubeHelix palette with cutoff:cubehelix.png

0 Kudos
Message 3 of 3
(2,835 Views)