forked from darktable-org/darktable
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial CMake & skeleton to support LibRAW.
This will be used to load CR3.
- Loading branch information
Showing
7 changed files
with
194 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#.rst: | ||
# Findlibraw | ||
# ------- | ||
# | ||
# Try to find libraw on a Unix system. | ||
# | ||
# This will define the following variables: | ||
# | ||
# ``libraw_FOUND`` | ||
# True if (the requested version of) libraw is available | ||
# ``libraw_VERSION`` | ||
# The version of libraw | ||
# ``libraw_LIBRARIES`` | ||
# This should be passed to target_compile_options() if the target is not | ||
# used for linking | ||
# ``libraw_INCLUDE_DIRS`` | ||
# This should be passed to target_include_directories() if the target is not | ||
# used for linking | ||
# ``libraw_DEFINITIONS`` | ||
# This should be passed to target_compile_options() if the target is not | ||
# used for linking | ||
|
||
find_package(PkgConfig) | ||
pkg_check_modules(PKG_libraw QUIET raw) | ||
|
||
set(libraw_VERSION ${PKG_libraw_VERSION}) | ||
set(libraw_DEFINITIONS ${PKG_libraw_CFLAGS_OTHER}) | ||
|
||
find_path(libraw_INCLUDE_DIR | ||
NAMES libraw/libraw.h | ||
HINTS ${PKG_libraw_INCLUDE_DIRS} | ||
) | ||
|
||
find_library(libraw_LIBRARY | ||
NAMES raw | ||
HINTS ${PKG_libraw_LIBRARY_DIRS} | ||
) | ||
|
||
include(FindPackageHandleStandardArgs) | ||
find_package_handle_standard_args(libraw | ||
FOUND_VAR libraw_FOUND | ||
REQUIRED_VARS libraw_LIBRARY | ||
libraw_INCLUDE_DIR | ||
VERSION_VAR libraw_VERSION | ||
) | ||
|
||
set(libraw_INCLUDE_DIRS ${libraw_INCLUDE_DIR}) | ||
set(libraw_LIBRARIES ${libraw_LIBRARY}) | ||
|
||
mark_as_advanced(libraw_INCLUDE_DIR) | ||
mark_as_advanced(libraw_LIBRARY) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
This file is part of darktable, | ||
Copyright (C) 2021 darktable developers. | ||
darktable is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
darktable is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with darktable. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifdef HAVE_LIBRAW | ||
#include "common/darktable.h" | ||
#include "imageio.h" | ||
#include "imageio_gm.h" | ||
#include "develop/develop.h" | ||
#include "common/exif.h" | ||
#include "common/colorspaces.h" | ||
#include "control/conf.h" | ||
|
||
#include <memory.h> | ||
#include <stdio.h> | ||
#include <inttypes.h> | ||
#include <strings.h> | ||
#include <assert.h> | ||
|
||
#include <libraw/libraw.h> | ||
|
||
|
||
/* LibRAW is expected to read only new canon CR3 files */ | ||
|
||
static gboolean _supported_image(const gchar *filename) | ||
{ | ||
const char *extensions_whitelist[] = { "cr3", NULL }; | ||
gboolean supported = FALSE; | ||
char *ext = g_strrstr(filename, "."); | ||
if(!ext) return FALSE; | ||
ext++; | ||
for(const char **i = extensions_whitelist; *i != NULL; i++) | ||
if(!g_ascii_strncasecmp(ext, *i, strlen(*i))) | ||
{ | ||
supported = TRUE; | ||
break; | ||
} | ||
return supported; | ||
} | ||
|
||
|
||
dt_imageio_retval_t dt_imageio_open_libraw(dt_image_t *img, const char *filename, dt_mipmap_buffer_t *mbuf) | ||
{ | ||
int err = DT_IMAGEIO_FILE_CORRUPTED; | ||
|
||
if(!_supported_image(filename)) return DT_IMAGEIO_FILE_CORRUPTED; | ||
|
||
if(!img->exif_inited) (void)dt_exif_read(img, filename); | ||
|
||
libraw_data_t *raw_data = libraw_init(0); | ||
|
||
if(!libraw_open_file(raw_data, filename)) | ||
goto error; | ||
|
||
img->buf_dsc.cst = iop_cs_RAW; | ||
img->flags |= DT_IMAGE_4BAYER; | ||
img->flags &= ~DT_IMAGE_LDR; | ||
img->flags |= DT_IMAGE_RAW; | ||
img->loader = LOADER_LIBRAW; | ||
|
||
libraw_close(raw_data); | ||
|
||
return DT_IMAGEIO_OK; | ||
|
||
error: | ||
libraw_close(raw_data); | ||
return err; | ||
} | ||
#endif | ||
|
||
// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh | ||
// vim: shiftwidth=2 expandtab tabstop=2 cindent | ||
// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
This file is part of darktable, | ||
Copyright (C) 2021 darktable developers. | ||
darktable is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
darktable is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with darktable. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef DT_IMAGEIO_LIBRAW_H | ||
#define DT_IMAGEIO_LIBRAW_H | ||
|
||
#include "common/image.h" | ||
#include "common/mipmap_cache.h" | ||
|
||
#ifdef HAVE_LIBRAW | ||
dt_imageio_retval_t dt_imageio_open_libraw(dt_image_t *img, const char *filename, dt_mipmap_buffer_t *buf); | ||
#else | ||
inline dt_imageio_retval_t dt_imageio_open_libraw(dt_image_t *img, const char *filename, | ||
dt_mipmap_buffer_t *buf) | ||
{ | ||
return DT_IMAGEIO_FILE_NOT_FOUND; | ||
} | ||
#endif | ||
|
||
#endif | ||
// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh | ||
// vim: shiftwidth=2 expandtab tabstop=2 cindent | ||
// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified; |