Search code examples
labview

External function to user displayed image


So I have an external C function that returns a pointer to an array. I'm trying to figure out how to convert the pointer to something that can be be displayed on the screen using the latest version of LabView (2019, assume I have all the toolkits).

The C function signature imports fine and is designed to display 16 bit images.

STATUS DemoImage(unsigned short** ptr, int64* rows, int64* columns, int64 image_idx)

with ptr eventually filling a pointer containing the memory location to 16 bit image. rows, columns work as expected.

Whats the name of the controllers that convert the data type to something that can be displayed? I'd also appreciate answers that only address how to display a 8 bit images as I can convert them in my own library if worst, comes to worst.


Solution

  • There is a vi.lib VI not on the palette that you can use: GetValueByPointer.

    Detailed walkthrough

    For the step-by-step explanation, see this NI document.

    2D arrays are represented as an array of arrays. Since an array is really a pointer, a 2D array is a pointer to an array of pointers, where each pointer points to the individual rows of the array. So in order to dereference a 2D Array, you must first dereference the individual pointers to each row, and then dereference in individual elements in each row. The following snippet shows an example of this:

    block diagram of iterating over a 2D array

    Download examples

    For a download with examples, see this one instead, section 4.d.

    Returning values by reference (pass by ref)

    • Function:
      void ReturningValuesByReference_2DArrayOfIntegers (int rows, int cols, int ***newArray);
    • VI:
      Returning Values By Reference 2D Array Of Integers Complete.vi