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: 

Thanks for the prompt reply.

Thanks for the prompt reply. Sorry, I should have provided a more complete problem statement (but where do you stop?) My code tests all the different data raw data pointers in libraw_rawdata_t and they are all null. I'm testing with Canon CR2 and Panasonic RW2. I assume unpack has done its job since it returned no error and libraw_image_sizes_t.raw_pitch has (what seems like) valid data (which it didn't have before the unpack).

You need to ensure you use

You need to ensure you use same data types definitions (.h files) and same structure alignment in both
- your code (that calculates offsets of imgdata.rawdata members during your code compilation)
- and LibRaw library (offsets calculated by compiler at library build stage).

-- Alex Tutubalin @LibRaw LLC

Also you may start with

Also you may start with simple C-language sample (just print non-zero pointer) to make sure it works on C side.

-- Alex Tutubalin @LibRaw LLC