Skip to content

Commit

Permalink
Add LibRaw cmake support.
Browse files Browse the repository at this point in the history
  • Loading branch information
TurboGit authored and cytrinox committed Nov 13, 2021
1 parent 559e1e1 commit 01da687
Show file tree
Hide file tree
Showing 24 changed files with 1,515 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@
[submodule "src/tests/integration"]
path = src/tests/integration
url = https://github.com/darktable-org/darktable-tests.git
[submodule "src/external/LibRaw"]
path = src/external/LibRaw
url = https://github.com/LibRaw/LibRaw.git
32 changes: 25 additions & 7 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ include(CheckCXXCompilerFlag)
include(CheckCSourceCompiles)
include(CheckCXXSymbolExists)


#
# Add files for libdarktable
#
Expand Down Expand Up @@ -382,14 +383,17 @@ if(USE_HEIF)
endif()
endif()

# For now we use the LibRaw submodule
if (USE_LIBRAW)
find_package(libraw 0.20.2)
if (libraw_FOUND)
list(APPEND LIBS ${libraw_LIBRARY})
add_definitions(-DHAVE_LIBRAW=1)
list(APPEND SOURCES "common/imageio_libraw.c")
set(DT_SUPPORTED_EXTENSIONS ${DT_SUPPORTED_EXTENSIONS} libraw CACHE INTERNAL "")
endif()
# find_package(libraw 0.20.2)
# if (libraw_FOUND)
# list(APPEND LIBS ${libraw_LIBRARY})
# add_definitions(-DHAVE_LIBRAW=1)
# list(APPEND SOURCES "common/imageio_libraw.c")
# set(DT_SUPPORTED_EXTENSIONS ${DT_SUPPORTED_EXTENSIONS} libraw CACHE INTERNAL "")
# endif()
add_definitions(-DHAVE_LIBRAW=1)
list(APPEND SOURCES "common/imageio_libraw.c")
endif()

if(USE_LENSFUN)
Expand Down Expand Up @@ -432,6 +436,10 @@ if (USE_ISOBMFF)
# This must be manually enabled during exiv2 build and can be checked with
# the EXV_ENABLE_BMFF symbol.
check_cxx_symbol_exists(EXV_ENABLE_BMFF "exiv2/exiv2.hpp" HAVE_EXV_ENABLE_BMFF)
# ??? This needs fix as we bypass the check for actual exiv2 version
if(APPLE)
set(HAVE_EXV_ENABLE_BMFF 1)
endif()
if(HAVE_EXV_ENABLE_BMFF)
add_definitions(-DHAVE_LIBEXIV2_WITH_ISOBMFF=1)
set(DT_SUPPORTED_EXTENSIONS ${DT_SUPPORTED_EXTENSIONS} cr3 CACHE INTERNAL "")
Expand Down Expand Up @@ -1033,3 +1041,13 @@ InstallDependencyFiles()

# Tell CPack about the components and group the data components together (CPACK_COMPONENT_${COMPONENT_NAME_ALL_CAPS}_GROUP).
set(CPACK_COMPONENTS_ALL DTApplication DTDebugSymbols DTDocuments)

if (USE_LIBRAW)
set(LIBRAW_PATH "${CMAKE_CURRENT_SOURCE_DIR}/external/LibRaw" CACHE STRING "Relative path to libraw directory (default=CMAKE_CURRENT_SOURCE_DIR)")
set(ENABLE_EXAMPLES OFF CACHE BOOLEAN "")
set(DT_SUPPORTED_EXTENSIONS ${DT_SUPPORTED_EXTENSIONS} libraw CACHE INTERNAL "")

# LibRaw sub-module
add_subdirectory(external/LibRaw-cmake)
target_link_libraries(lib_darktable PRIVATE libraw::libraw)
endif()
10 changes: 5 additions & 5 deletions src/common/imageio_libraw.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ gboolean dt_libraw_lookup_makermodel(const char *maker, const char *model,

dt_imageio_retval_t dt_imageio_open_libraw(dt_image_t *img, const char *filename, dt_mipmap_buffer_t *mbuf)
{
int err;
int err = 0;
int libraw_err = 0;
if(!_supported_image(filename)) return DT_IMAGEIO_FILE_CORRUPTED;
if(!img->exif_inited) (void)dt_exif_read(img, filename);
Expand Down Expand Up @@ -131,10 +131,10 @@ dt_imageio_retval_t dt_imageio_open_libraw(dt_image_t *img, const char *filename
img->height = raw->sizes.raw_height;

// Apply crop parameters
img->crop_x = raw->sizes.raw_inset_crop.cleft;
img->crop_y = raw->sizes.raw_inset_crop.ctop;
img->crop_width = raw->sizes.raw_width - raw->sizes.raw_inset_crop.cwidth - raw->sizes.raw_inset_crop.cleft;
img->crop_height = raw->sizes.raw_height - raw->sizes.raw_inset_crop.cheight - raw->sizes.raw_inset_crop.ctop;
img->crop_x = raw->sizes.raw_inset_crops[0].cleft;
img->crop_y = raw->sizes.raw_inset_crops[0].ctop;
img->crop_width = raw->sizes.raw_width - raw->sizes.raw_inset_crops[0].cwidth - raw->sizes.raw_inset_crops[0].cleft;
img->crop_height = raw->sizes.raw_height - raw->sizes.raw_inset_crops[0].cheight - raw->sizes.raw_inset_crops[0].ctop;

// We can reuse the libraw filters property, it's already well-handled in dt.
// It contains the BAYER filter pattern.
Expand Down
2 changes: 1 addition & 1 deletion src/external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ add_subdirectory(rawspeed ${DARKTABLE_LIBDIR}/rawspeed)
# Copying rawspeed resources to where dt expects them
add_custom_target("deploy" ALL)
SET(RAWSPEED_DATADIR "${CMAKE_CURRENT_SOURCE_DIR}/rawspeed/data")
add_custom_command(TARGET "deploy" PRE_BUILD
add_custom_command(TARGET "deploy" PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${DARKTABLE_DATADIR}/rawspeed/
COMMAND ${CMAKE_COMMAND} -E copy ${RAWSPEED_DATADIR}/cameras.xml ${RAWSPEED_DATADIR}/showcameras.xsl ${DARKTABLE_DATADIR}/rawspeed/
)
Expand Down
1 change: 1 addition & 0 deletions src/external/LibRaw
Submodule LibRaw added at 5bc2c6
1 change: 1 addition & 0 deletions src/external/LibRaw-cmake/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
33 changes: 33 additions & 0 deletions src/external/LibRaw-cmake/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: CI

on: [push, pull_request, workflow_dispatch]

env:
LIBRAW_GIT: https://github.com/LibRaw/LibRaw.git

defaults:
run:
shell: bash

jobs:
build:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
libraw_ref: ['0.20.2', 'master']

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2

- run: git clone $LIBRAW_GIT -b ${{ matrix.libraw_ref }}
name: Clone LibRaw

- run: |
mkdir build
cd build
cmake -DENABLE_OPENMP=OFF -DLIBRAW_PATH=$(pwd)/../LibRaw ..
cmake --build .
name: Build LibRaw
2 changes: 2 additions & 0 deletions src/external/LibRaw-cmake/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.project
build
Loading

0 comments on commit 01da687

Please sign in to comment.