Files
rawTherapee/RawSpeed3
Lawrence Lee 4c61b7d3c3 Squashed 'rtengine/libraw/' changes from 1ef70158d..12b0e5d60
12b0e5d60 Snapshot 202403
a4c9b1981 loop parameters in remove_trailing_spaces
e231b01a4 CR3-Qstep table: avoid wrong 64-bit code generation
21368133a 0.21.2 release
a6f212a4a tag type => tag size mapping fixed
41506ef73 cubic_spline: better handling of non-integer data
17294b5fd extra metadata check in arq_load_raw
47d9dd8e2 Better incorrect data handling in cubic_spline
3baa51068 skip invalid pattern in xtrans_interpolate
eaf63bf5f Check HL recovery coeffs before processing
a14574080 limit wavelet denoise minimum size
4e597e4e9 Merge pull request #594 from pinotree/path_max
086dcb9a6 raw-identify: use fallback if PATH_MAX not available
0e105f9f8 additional check against corrupted ljpeg layout
0c8b68e9f Disable color conversion for Canon 16-bit thumbnails
cd1abd695 docs/changelog: explained the case when no thumbnail is found in specific file
6fffd414b rename swapXX to libraw_swapXX to avoid name conflict
af78ae48a Check against corrupted LJPEG header in Canon sRAW decoder
ba780e600 Limit embedded color profile allocation/read size
122bf7c5b Wrong alloc result check for 16-bit bitmap thumbnail
e6dd2709e check pana_data/buffer offset before use
ae2dc5884 Check P1 quadrant linearization coeff[15] against zero
f2998bacc avoid integer overflow in buffer space check
443b7fb51 prevent buffer overrun in buffer_datastream::scanf_one
35a6d3615 ensure correct T.tlength for 16b bitmap thumbnails(2)
b69ea8be5 ensure correct T.tlength for 16b bitmap thumbnails
2b6eca897 Do not run sraw decoder on (crafted) bayer files
68808b57f better striped thumbnails handling
9ab70f6dc do not set shrink flag for 3/4 component images
32425dd96 allow more decoders for fuji-rotated RAWs
REVERT: 1ef70158d 0.21.2 release
REVERT: 62f042366 tag type => tag size mapping fixed
REVERT: ee087e3fe cubic_spline: better handling of non-integer data
REVERT: af755b991 extra metadata check in arq_load_raw
REVERT: 0fadd8819 Better incorrect data handling in cubic_spline
REVERT: d7fb66053 skip invalid pattern in xtrans_interpolate
REVERT: d059ed280 Check HL recovery coeffs before processing
REVERT: 104730519 limit wavelet denoise minimum size
REVERT: cae09838e raw-identify: use fallback if PATH_MAX not available
REVERT: d6c677608 additional check against corrupted ljpeg layout
REVERT: 1001a6ac1 Disable color conversion for Canon 16-bit thumbnails
REVERT: a5130b01b docs/changelog: explained the case when no thumbnail is found in specific file
REVERT: 600c0c63d rename swapXX to libraw_swapXX to avoid name conflict
REVERT: 299c8a11b Check against corrupted LJPEG header in Canon sRAW decoder
REVERT: ec8671ad9 Limit embedded color profile allocation/read size
REVERT: 5229d5942 Wrong alloc result check for 16-bit bitmap thumbnail
REVERT: b278b775f check pana_data/buffer offset before use
REVERT: 7f4b8d3af Check P1 quadrant linearization coeff[15] against zero
REVERT: e942a7db6 avoid integer overflow in buffer space check
REVERT: f6a57cfb8 prevent buffer overrun in buffer_datastream::scanf_one
REVERT: 3e62ed304 ensure correct T.tlength for 16b bitmap thumbnails(2)
REVERT: 8e52d81cd ensure correct T.tlength for 16b bitmap thumbnails
REVERT: 8e1af15e2 Do not run sraw decoder on (crafted) bayer files
REVERT: 0ace959c2 better striped thumbnails handling
REVERT: 477e0719f do not set shrink flag for 3/4 component images
REVERT: c8efae6c5 allow more decoders for fuji-rotated RAWs

git-subtree-dir: rtengine/libraw
git-subtree-split: 12b0e5d60c57bb795382fda8494fc45f683550b8
2024-04-13 22:44:59 -07:00
..

About RawSpeed v3

The current version of the RawSpeed library (https://github.com/darktable-org/rawspeed ) does not have a version number, we call it "version 3" to distinguish it from RawSpeed/master, the version number is taken from darktable 3.x (which uses this library).

This library provides faster decoding of some RAW formats (even faster than RawSpeed v1), the difference can be tens of percent (without using OpenMP) for Huffman-compressed files (Canon CR2, Nikon NEF, etc).

Unfortunately, the RawSpeed-v3 source code is constantly changing and this is due not so much to the development of the library (support for new cameras, formats, etc.), but to the fact that the current maintainer is using it as an aid in self-development as a programmer.

They are extremely reluctant to accept 3rd-party patches to this library, therefore, the fixes necessary for correct work with LibRaw have been added to the LibRaw distribution (see below). All our patches, of course, are suitable only for a specific version (commit-id) of RawSpeed-v3, if you want to use a different version, you will have to adjust them.

Building RawSpeed v3 and C-API wrapper

Preparing the source

  1. Take a specific commit from github de70ef5fbc

  2. Apply the following patches from LibRaw/RawSpeed3/patches folder:

  • 01.CameraMeta-extensibility.patch - allows derived classes from CameraMeta, which allows loading camera descriptions not only from a disk file.
  • 02.Makernotes-processing.patch - fixes an error in processing the Makernotes tag.
  • 03.remove-limits-and-logging.patch - removes debug printing and file size limits. This patch is optional, but if you are going to decode files from cameras that were not available at the time a particular version of RawSpeed was created, then this patch can be useful.
  • 04.clang-cl-compatibility.patch - fixes for compatibility with Microsoft C++ library.
  • 05.no-phase-one-correction.patch - disables RawSpeed's PhaseOne flat field correction because LibRaw implements own

Building the RawSpeed-v3 library

We do not offer advice on building RawSpeed3, if you need such advice please contact the maintainer of the library. At a minimum, it can be compiled with Clang (XCode) on macOS and clang-cl (MSVC) on Windows.

Use your favorite build system. Files for CMake come with RawSpeed, but any other build system can be used (in that case you probably will need to create your own rawspeedconfig.h instead of one created via CMake).

In our projects we use RawSpeed-v3 without OpenMP.

Building the C-API wrapper

To simplify the integration with LibRaw, we have implemented a simple wrapper with a C interface, which hides everything unnecessary, thus:

  • To build LibRaw (with RawSpeed-v3 support) you do not need access to RawSpeed .h-files
  • When building LibRaw and RawSpeed-v3 using different compilers there is no issue with C++ name mangling.

The wrapper sources are in the LibRaw/RawSpeed3/rawspeed3_c_api folder, they include four files:

  1. rawspeed3_capi.h - header file
  2. rawspeed3_capi.cpp - wrapper sources
  3. rsxml2c.sh - shell script that will convert RawSpeed/data/cameras.xml to a C++ file containing camera definitions
  4. rawspeed3_capi_test.cpp - test program for checking the build correctness and operation ability.

The wrapper provides simple decode only interface (init library, decode RAW passed via buffer, free decoded file buffer, release the library) it is self-documented via comments in the rawspeed3_capi.h file.

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.

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.

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.

Building LibRaw with RawSpeed-v3 support

When building, specify the following parameters

  • LibRaw/RawSpeed3/rawspeed3_c_api to the search path for include files
  • Specify preprocessor flags -DUSE_RAWSPEED3 -DUSE_RAWSPEED_BITS:
    • USE_RAWSPEED3 enables the use of RawSpeed-v3
    • USE_RAWSPEED_BITS enables (a more granulated) control of RawSpeed-v3 / RawSpeed processing
  • set the RawSpeed-v3 (+ C-API) library, obtained in the previous steps, as an input linker file

Using LibRaw with RawSpeed-v3 Support

Use LibRaw as usual. Enable RawSpeed3 use by setting bits in imgdata.rawparams.userawspeed (LIBRAW_RAWSPEEDV3_USE, LIBRAW_RAWSPEEDV3_IGNOREERRORS, LIBRAW_RAWSPEEDV3_FAILONUNKNOWN) If RawSpeed was set as the decoder the following bits will be set in imgdata.processwarnings:

  • LIBRAW_WARN_RAWSPEED3_PROCESSED - if decoding was successful
  • LIBRAW_WARN_RAWSPEED3_PROBLEM - if decoding attempt failed (flags and bits are described in LibRaw's Changelog)

With RawSpeed-v3, the entire RAW file is read into the memory buffer (as it is with RawSpeed version 1), so it increases LibRaw memory footprint.