Instanciate the libraw class in c#

Hi, I try to work with libraw in my c# project. (Very new with c, c++ ...)
I can convert a raw image to ppm easily with this:

var dataPtr = NativeMethods.libraw_init(LibRaw_constructor_flags.LIBRAW_OPIONS_NO_DATAERR_CALLBACK | LibRaw_constructor_flags.LIBRAW_OPIONS_NO_MEMERR_CALLBACK);

NativeMethods.libraw_open_file(dataPtr, @"C:\Users\me\Desktop\pict.CR2");
NativeMethods.libraw_dcraw_ppm_tiff_writer(dataPtr, @"C:\Users\me\Desktop\pict.ppm");

with native methods::

internal static class NativeMethods {
public static extern IntPtr libraw_init(LibRaw_constructor_flags flags);

public static extern int libraw_open_file(IntPtr data, string fileName);

public static extern int libraw_unpack(IntPtr data);

public static extern int libraw_dcraw_process(IntPtr lr);

public static extern int libraw_dcraw_ppm_tiff_writer(IntPtr processed,string filename);

But I would like to instanciate the libraw class to pass the out param ....
Tried to write a 'CreateLibraw' Methode in libraw.h.... but doesn't compile

Thanx for help :)


libraw.h does not contains

libraw.h does not contains string 'CreateLibraw', may be it something C# specific?

There are a lot of libraw_set_... calls in C api, that calls will set params in imgdata.params array

-- Alex Tutubalin @LibRaw LLC

C API does not expose the set imgdata.params.output_tiff


i am exactly stuck at the same spot as NicolasB although I am using VB.Net. but in the end there is no option to access the params.ouput_tiff from the DLLimport statements/ C API. so I can only create a ppm file and not a tiff

Alex i see that you point to some setters in your comment but i dont see any in the doc nor the source "libraw.h" file that could change the "output_tiff" value.

Note that the method posted above by NicolasB essentially lets libraw.dll do the whole work and no real object is passed back to the calling .NET program

The alternative would be to recreate the whole C++ class structure in VB (or C#) which is quite daunting just for this simple function.

C-API getters/setters are

C-API getters/setters are indeed limited (to the ones that really used in real applications), your contributions are welcome (please use GitHub pull request for that).

Besides that, tiff/ppm writer is very limited, esp. in tiff part (no compression, no striping/tiling, etc, etc). It is not intended for use in any real application, this is just a placeholder, to allow LibRaw samples to write some files.

Use make_mem_image() and your preferred TIFF writer (e.g. libtiff) in real apps.

-- Alex Tutubalin @LibRaw LLC

C API does not expose the set imgdata.params.output_tiff

Did anyone figure out how to do this? I'm another one interested in using libraw, here again in C#, but I cannot figure out how to pass parameters. Would appreciate any help I can get, even if implemented in VB or another language.

New Build works with VB.NET


we created a new build that exposes the TIFF option as a C API. Not sure when it will be part of the official release but should be part of the Nightlies.

You can see how i have used it in my VB.NET program: avail here:

scroll to line 1475 for the imports definitions and 1690 for the actual usage of the methods . You may have to change the calls for C# but i trust it should work just the same.

Note the new build was really to expose the -tiff option which is now avail via this statement:

<DllImport("libraw.dll", EntryPoint:="libraw_set_output_tif", CallingConvention:=CallingConvention.Cdecl)>

Hope this helps