-
Notifications
You must be signed in to change notification settings - Fork 860
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[image] Add support for libraw raw image loading. Tested with Sony A7…
…S and Sony A7RIII
- Loading branch information
1 parent
85a98c2
commit b9f1068
Showing
4 changed files
with
108 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# - Try to find libraw | ||
# | ||
# libraw_FOUND - system has libraw | ||
# libraw_INCLUDE_DIRS - the libraw include directories | ||
# libraw_LIBRARIES - link these to use libraw | ||
|
||
FIND_PATH( | ||
libraw_INCLUDE_DIRS | ||
NAMES libraw/libraw.h | ||
PATHS | ||
${LIBRAW_DIR} | ||
${LIBRAW_DIR}/include | ||
/usr/include/ | ||
/usr/local/include | ||
/opt/local/include | ||
) | ||
|
||
FIND_LIBRARY( | ||
libraw_LIBRARIES | ||
NAMES raw_r | ||
PATHS | ||
${LIBRAW_DIR} | ||
${LIBRAW_DIR}/lib | ||
/usr/lib | ||
/usr/local/lib | ||
/opt/local/lib | ||
) | ||
|
||
IF (libraw_INCLUDE_DIRS AND libraw_LIBRARIES) | ||
SET(libraw_FOUND TRUE) | ||
ENDIF (libraw_INCLUDE_DIRS AND libraw_LIBRARIES) | ||
|
||
IF (libraw_FOUND) | ||
IF (NOT libraw_FIND_QUIETLY) | ||
MESSAGE(STATUS "Found libraw: ${libraw_LIBRARIES}") | ||
ENDIF (NOT libraw_FIND_QUIETLY) | ||
ELSE (libraw_FOUND) | ||
IF (libraw_FIND_REQUIRED) | ||
MESSAGE(FATAL_ERROR "Could not find libraw") | ||
ENDIF (libraw_FIND_REQUIRED) | ||
ENDIF (libraw_FOUND) |
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,48 @@ | ||
#include <fstream> | ||
#include <pangolin/image/typed_image.h> | ||
|
||
#ifdef HAVE_LIBRAW | ||
# include <libraw/libraw.h> | ||
#endif | ||
|
||
namespace pangolin { | ||
|
||
TypedImage LoadLibRaw( | ||
const std::string& filename | ||
) { | ||
#ifdef HAVE_LIBRAW | ||
static LibRaw RawProcessor; | ||
|
||
int ret; | ||
|
||
if ((ret = RawProcessor.open_file(filename.c_str())) != LIBRAW_SUCCESS) | ||
{ | ||
throw std::runtime_error(libraw_strerror(ret)); | ||
} | ||
|
||
if ((ret = RawProcessor.unpack()) != LIBRAW_SUCCESS) | ||
{ | ||
throw std::runtime_error(libraw_strerror(ret)); | ||
} | ||
|
||
const auto& S = RawProcessor.imgdata.sizes; | ||
TypedImage image(S.width, S.height, PixelFormatFromString("GRAY16LE"), sizeof(uint16_t) * S.raw_width); | ||
PitchedCopy((char*)image.ptr, image.pitch, (char*)RawProcessor.imgdata.rawdata.raw_image, sizeof(uint16_t) * S.raw_width, sizeof(uint16_t) * image.w, image.h); | ||
|
||
// TODO: Support image metadata so that we can extract these fields. | ||
// RawProcessor.imgdata.other.iso_speed | ||
// RawProcessor.imgdata.other.aperture | ||
// RawProcessor.imgdata.other.focal_len | ||
// RawProcessor.imgdata.other.shutter | ||
// RawProcessor.imgdata.other.timestamp | ||
// RawProcessor.imgdata.makernotes.common.exifCameraElevationAngle | ||
// RawProcessor.imgdata.makernotes.sony.SonyDateTime | ||
|
||
return image; | ||
#else | ||
PANGOLIN_UNUSED(filename); | ||
throw std::runtime_error("Rebuild Pangolin for libraw support."); | ||
#endif | ||
} | ||
|
||
} |