Add new comment

JNA wrappers for LibRaw

I'm trying to write some JNA wrappers for LibRaw, but I'm struggling with the JNA spell for the raw data, specifically for the *raw_image member of the libraw_rawdata_t structure. I can access other members of this and other related structure as expected, but assuming that I would need to use a JNA Pointer type for *raw_image, I only ever get a null for this member after an unpack (no errors) call. I assume libraw.dlI allocates the memory for this data and return a pointer to a short array. I also tried using a ShortByReference JNA type (as suggested by some examples) but that also returns null. The only way I can get a non-null return value is if I use a Java short[], but then I have to declare a size (which I don't know at this time). It also looks like the pointer doesn't point to any actual pixel data

If anyone has experience of JNA with LibRaw I'd be grateful for some hints!

My JNA code looks like this (but truncated from >1000 lines to just the relevant bits):

public interface LibRaw extends Library {
 
  public class LibRaw_data extends Structure {
 
    /*
    Other members
    */
 
    public LibRaw_rawdata rawdata; 
  }
 
  public class LibRaw_rawdata extends Structure {
 
    /*
    Other members
    */
 
    public Pointer raw_image; 
 
    /*
    Other members
    */
 
  }
 
  LibRaw INSTANCE = (LibRaw) Native.loadLibrary(dllPath, LibRaw.class);
 
  LibRaw_data libraw_init(int flags);
  int libraw_open_file( LibRaw_data lr, String fname );
  int libraw_unpack( LibRaw_data lr );
  void libraw_close( LibRaw_data lr );
 
  // ... other functions ...
 
}

Forums: