Skip to content

Commit

Permalink
Camera RAW images plugin
Browse files Browse the repository at this point in the history
Plugin to read RAW camera images based on LibRAW.

- Supersedes MR !86 
- Support to LibRaw 0.20 and 0.21-Beta
- Support to multi-shot images: use imageCount(), jumpToImage() to select the wanted shot
- By default generates 16-bits sRGB images using camera white balance and interpolation AHD
- Should fix CCBUG: 454208: on my Debian with KF5.96 and the pulgin installed, I see the preview of all my RAW files (ARW included) in Dolphin

News compared to V1 (MR !86)

- Fix possible stack overflow due to the huge size of LibRaw class
- Fix image allocation with Qt 6 (make use of QImageIOHandler::allocateImage()) 
- Support to XMP metapacket
- Support to quality option. For e.g. you can focus on quality (q = 10) or speed (q = 1)
- oss-fuzz available [here](https://github.com/mircomir/oss-fuzz/tree/raw_fuzz/projects/kimageformats)
  • Loading branch information
mircomir authored and nicolas17 committed Sep 19, 2022
1 parent 84941b7 commit 65a20b4
Show file tree
Hide file tree
Showing 13 changed files with 2,053 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitattributes
@@ -0,0 +1 @@
autotests/read/raw/RAW_KODAK_C330_FORMAT_NONE_YRGB.raw binary
9 changes: 8 additions & 1 deletion CMakeLists.txt
Expand Up @@ -8,7 +8,7 @@ set_package_properties(ECM PROPERTIES TYPE REQUIRED DESCRIPTION "Extra CMake Mod
feature_summary(WHAT REQUIRED_PACKAGES_NOT_FOUND FATAL_ON_MISSING_REQUIRED_PACKAGES)


set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
set(CMAKE_MODULE_PATH ${KImageFormats_SOURCE_DIR}/cmake/find-modules ${ECM_MODULE_PATH})

include(KDEInstallDirs)
include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE)
Expand Down Expand Up @@ -70,6 +70,13 @@ if(KIMAGEFORMATS_JXL)
endif()
add_feature_info(LibJXL LibJXL_FOUND "required for the QImage plugin for JPEG XL images")

# note: module FindLibRaw missing from https://invent.kde.org/frameworks/extra-cmake-modules
find_package(LibRaw 0.20.2)
set_package_properties(LibRaw PROPERTIES
TYPE OPTIONAL
PURPOSE "Required for the QImage plugin for RAW images"
)

ecm_set_disabled_deprecation_versions(
QT 5.15.2
KF 5.95
Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -18,6 +18,7 @@ The following image formats have read-only support:
- OpenEXR (exr)
- Photoshop documents (psd, psb, pdd, psdt)
- Sun Raster (ras)
- Camera RAW images (arw, cr2, cr3, dcs, dng, ...)

The following image formats have read and write support:

Expand Down
6 changes: 6 additions & 0 deletions autotests/CMakeLists.txt
Expand Up @@ -139,6 +139,12 @@ if (OpenEXR_FOUND)
# FIXME: OpenEXR tests
endif()

if (LibRaw_FOUND)
kimageformats_read_tests(
raw
)
endif()

find_package(Qt${QT_MAJOR_VERSION}Test ${REQUIRED_QT_VERSION} CONFIG QUIET)

if(NOT TARGET Qt${QT_MAJOR_VERSION}::Test)
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
901 changes: 901 additions & 0 deletions autotests/read/raw/RAW_KODAK_C330_FORMAT_NONE_YRGB.raw

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion autotests/readtest.cpp
Expand Up @@ -94,7 +94,6 @@ int main(int argc, char **argv)
QByteArray format = suffix.toLatin1();

QDir imgdir(QLatin1String(IMAGEDIR "/") + suffix);
imgdir.setNameFilters(QStringList(QLatin1String("*.") + suffix));
imgdir.setFilter(QDir::Files);

int passed = 0;
Expand All @@ -113,6 +112,9 @@ int main(int argc, char **argv)

const QFileInfoList lstImgDir = imgdir.entryInfoList();
for (const QFileInfo &fi : lstImgDir) {
if (!fi.suffix().compare("png", Qt::CaseInsensitive)) {
continue;
}
int suffixPos = fi.filePath().count() - suffix.count();
QString inputfile = fi.filePath();
QString expfile = fi.filePath().replace(suffixPos, suffix.count(), QStringLiteral("png"));
Expand Down
87 changes: 87 additions & 0 deletions cmake/find-modules/FindLibRaw.cmake
@@ -0,0 +1,87 @@
# - Find LibRaw
# Find the LibRaw library <https://www.libraw.org>
# This module defines
# LibRaw_VERSION, the version string of LibRaw
# LibRaw_INCLUDE_DIR, where to find libraw.h
# LibRaw_LIBRARIES, the libraries needed to use LibRaw (non-thread-safe)
# LibRaw_r_LIBRARIES, the libraries needed to use LibRaw (thread-safe)
# LibRaw_DEFINITIONS, the definitions needed to use LibRaw (non-thread-safe)
# LibRaw_r_DEFINITIONS, the definitions needed to use LibRaw (thread-safe)
#
# SPDX-FileCopyrightText: 2013 Pino Toscano <pino at kde dot org>
# SPDX-FileCopyrightText: 2013 Gilles Caulier <caulier dot gilles at gmail dot com>
#
# SPDX-License-Identifier: BSD-3-Clause

FIND_PACKAGE(PkgConfig)

IF(PKG_CONFIG_FOUND)
PKG_CHECK_MODULES(PC_LIBRAW libraw)
SET(LibRaw_DEFINITIONS ${PC_LIBRAW_CFLAGS_OTHER})

PKG_CHECK_MODULES(PC_LIBRAW_R libraw_r)
SET(LibRaw_r_DEFINITIONS ${PC_LIBRAW_R_CFLAGS_OTHER})
ENDIF()

FIND_PATH(LibRaw_INCLUDE_DIR libraw.h
HINTS
${PC_LIBRAW_INCLUDEDIR}
${PC_LibRaw_INCLUDE_DIRS}
PATH_SUFFIXES libraw
)

FIND_LIBRARY(LibRaw_LIBRARIES NAMES raw
HINTS
${PC_LIBRAW_LIBDIR}
${PC_LIBRAW_LIBRARY_DIRS}
)

FIND_LIBRARY(LibRaw_r_LIBRARIES NAMES raw_r
HINTS
${PC_LIBRAW_R_LIBDIR}
${PC_LIBRAW_R_LIBRARY_DIRS}
)

IF(LibRaw_INCLUDE_DIR)
FILE(READ ${LibRaw_INCLUDE_DIR}/libraw_version.h _libraw_version_content)

STRING(REGEX MATCH "#define LIBRAW_MAJOR_VERSION[ \t]*([0-9]*)\n" _version_major_match ${_libraw_version_content})
SET(_libraw_version_major "${CMAKE_MATCH_1}")

STRING(REGEX MATCH "#define LIBRAW_MINOR_VERSION[ \t]*([0-9]*)\n" _version_minor_match ${_libraw_version_content})
SET(_libraw_version_minor "${CMAKE_MATCH_1}")

STRING(REGEX MATCH "#define LIBRAW_PATCH_VERSION[ \t]*([0-9]*)\n" _version_patch_match ${_libraw_version_content})
SET(_libraw_version_patch "${CMAKE_MATCH_1}")

IF(_version_major_match AND _version_minor_match AND _version_patch_match)
SET(LibRaw_VERSION "${_libraw_version_major}.${_libraw_version_minor}.${_libraw_version_patch}")
ELSE()
IF(NOT LibRaw_FIND_QUIETLY)
MESSAGE(STATUS "Failed to get version information from ${LibRaw_INCLUDE_DIR}/libraw_version.h")
ENDIF()
ENDIF()
ENDIF()

INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibRaw
REQUIRED_VARS LibRaw_LIBRARIES LibRaw_INCLUDE_DIR
VERSION_VAR LibRaw_VERSION
)

MARK_AS_ADVANCED(LibRaw_VERSION
LibRaw_INCLUDE_DIR
LibRaw_LIBRARIES
LibRaw_r_LIBRARIES
LibRaw_DEFINITIONS
LibRaw_r_DEFINITIONS
)

if(LibRaw_FOUND AND NOT TARGET LibRaw::LibRaw)
add_library(LibRaw::LibRaw UNKNOWN IMPORTED)
set_target_properties(LibRaw::LibRaw PROPERTIES
IMPORTED_LOCATION "${LibRaw_LIBRARIES}"
INTERFACE_COMPILE_OPTIONS "${LibRaw_DEFINITIONS}"
INTERFACE_INCLUDE_DIRECTORIES "${LibRaw_INCLUDE_DIR}"
)
endif()
9 changes: 9 additions & 0 deletions src/imageformats/CMakeLists.txt
Expand Up @@ -130,6 +130,15 @@ install(FILES xcf.desktop DESTINATION ${KDE_INSTALL_KSERVICESDIR}/qimageioplugin

##################################

if (LibRaw_FOUND)
kimageformats_add_plugin(kimg_raw SOURCES raw.cpp)
kde_enable_exceptions()
target_link_libraries(kimg_raw LibRaw::LibRaw)
install(FILES raw.desktop DESTINATION ${KDE_INSTALL_KSERVICESDIR}/qimageioplugins/)
endif()

##################################

if (KF5Archive_FOUND)

kimageformats_add_plugin(kimg_kra SOURCES kra.cpp)
Expand Down

0 comments on commit 65a20b4

Please sign in to comment.