LibRaw 0.21.1 and RawSpeed v3

I followed the instructions on downloading a specific commit of rawspeed from DarkTable and I applied the 4 patches (actually, patch 01. is not needed as it is already in the rawspeed source code).

I was able to compile RawSpeed 3 successfully.

But when I enabled RawSpeed 3 support in the Makefile.dist of LibRaw and make the correct reference to the RawSpeed3 directory, LibRaw would compile but with the following linker errors:

Undefined symbols for architecture arm64:
"_rawspeed3_close", referenced from:
LibRaw::~LibRaw() in libraw.a(init_close_utils.o)
"_rawspeed3_release", referenced from:
LibRaw::recycle() in libraw.a(init_close_utils.o)

Then I found that these functions are in rawspeed3_capi.cpp under the RawSpeed3/rawspeed3_c_api folder.

How do I compile this rawspeed3_capi.cpp and the cameras.cpp?

The instructions on the RawSpeed v3 page is not clear on how to do it.

Please help.

Forums: 

Quote from RawSpeed3/README

Quote from RawSpeed3/README.md:

1.
To make a file with camera definitions, run the command (you can add it to the build system): sh ./rawspeed3_c_api/rsxml2c.sh < path/to/RawSpeed/data/cameras.xml > rawspeed3_c_api/cameras.cpp

The rsxml2c.sh script requires cat, tr, and sed unix command-line utilities installed, there is no specific version requirements.

2.
Add the resulting file (LibRaw/RawSpeed3/rawspeed3_c_api/cameras.cpp) and LibRaw/RawSpeed3/rawspeed3_c_api/rawspeed3_capi.cpp, to the build of the RawSpeed-v3 (dynamic) library, which you learned to build in the previous step. If building Windows DLL: rawspeed3_capi.cpp should be compiled with -DRAWSPEED_BUILDLIB to create dll export entries automatically.

3.
To check that everything works, you can use the LibRaw/RawSpeed3/rawspeed3_c_api/rawspeed3_capi_test.cpp test program, it should be possible to build it and link with RawSpeed-v3 (+ C-API); and after that this test program should be ready to decode RAW files passed to it from command line.

Please clarify what is not clear in the steps quoted above.

-- Alex Tutubalin @LibRaw LLC

It was actually step 2 on how

It was actually step 2 on how to add the files.

Anyway, I've it figured out so it is now compiled correctly. There was an error in the 01. patch, it should remove 'final' from CameraMetaData, and not adding to it.

There is also another error in CMakeLists.txt in RawSpeed-v3/src/librawspeed/common:

target_sources(rawspeed_get_number_of_processor_cores should be set to PUBLIC not PRIVATE. Or else it libraw would not link (can't find rawspeed_get_number_of_processor_cores).

There is one addition error in converting the cameras.xml file to cameras.cpp file. A null character was added in the last line of the cpp file. It won't compile unless it is removed. The null char was preceding the last line "";

I also need to add -fsanitize=address compile option to Makefile.dist, as RawSpeed3 source code automatically detect and enable -fsanitize=address compile flag, and it'll not link unless the same is specified in libraw and my code.

Now that I got it to compile and link, how do I specify RawSpeed3 during runtime?

I set imgdata.rawparams.use_rawspeed = 1 and for all the RAW files I tried, it doesn't decode them with RawSpeed3, including Sony ARW files or Nikon Z camera RAW files.

The doc mentioned about:

RawSpeed-v3 support is controlled via libraw_decoder_info.t->flags (LIBRAW_DECODER_TRYRAWSPEED3 bit).

First of all, there is no libraw_decoder_info.t->flags, but there is libraw_decoder_info_t->decoder_flags.

I assume you're referring to this decoder_flags?

I can assign decoder_flags = LIBRAW_DECODER_TRYRAWSPEED3, but how do I pass the libraw_decoder_info_t data structure to the raw processor so that it knows I want it to try RawSpeed3?

There is a get_decoder_info() function, but not a set_decoder_info().

Kuro

1) Sorry, we do not offer

1) Sorry, we do not offer advice on building RawSpeed3 as mentioned in the provided README
It is definitely possible to build it w/o address sanitizer.
We're not Cmake users, so I do not know what is 'target_sources(rawspeed_get_number_of_processor_cores....' message

2) LIBRAW_DECODER_TRYRAWSPEED3 bit is set in get_decoder_info() code. There is no way to change it from your app and no need for that.

LIBRAW_DECODER_TRYRAWSPEED3 bit is set only for decoders that are definitely faster in RawSpeed3, not for all decoders provided by the library (for example, it is mostly useless to decode unpacked/uncompressed data via RawSpeed3: it uses additional memory buffer for the decoded file with little or no benefit)

3) If you compile LibRaw with USE_RAWSPEED_BITS define, you need to set LIBRAW_RAWSPEEDV3_USE bit in imgdata.rawparams.use_rawspeed
If you compile LibRaw with just USE_RAWSPEED3 define, imgdata.rawparams.use_rawspeed=1 is enough.

-- Alex Tutubalin @LibRaw LLC

I recompiled without USE

I recompiled without USE_RAWSPEED_BITS and RawSpeed3 appeared to have been called when I decode a certain Sony ARW images.

But performance is terrible. Like 4.5x slower.

Not sure what is going on.

Kuro

Address sanitizer is still on

Address sanitizer is still on. I need to find ways to disable it in the RawSpeed3 source code (not sure how right now).

Do you see speed improvements with RAWSpeed 3 in general? Is it faster than the original RAWSpeed or does it simply offer more RAW file decode for different camera brands?

Kuro

Managed to turned off

Managed to turned off sanitizer and RawSpeed 3 is about 20-40+% faster than RawSpeed v1. Sony A7RM4 RAW decode speed is like 2x.

Kuro

Yes, this is expected speed

Yes, this is expected speed-up for huffman compressed files.

-- Alex Tutubalin @LibRaw LLC