summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasem Mutlaq <mutlaqja@ikarustech.com>2016-10-27 08:30:45 (GMT)
committerJasem Mutlaq <mutlaqja@ikarustech.com>2016-10-27 08:30:45 (GMT)
commitbef4d86e2a7762f1fbe3bdd25c52fb54fd557790 (patch)
tree938ff68d87a02ff509070545c52d896d6627719f
parent0dbb399d00316aa8af3eae9020a88849f60a3cc8 (diff)
Add LibRaw as optional dependency to handle reading of RAW files recieved from cameras. This enables multiplatform support for handling RAW files as libraw is available in major platforms
-rw-r--r--CMakeLists.txt12
-rw-r--r--cmake/modules/FindLibRaw.cmake79
-rw-r--r--config-kstars.h.cmake3
-rw-r--r--kstars/CMakeLists.txt6
-rw-r--r--kstars/indi/indiccd.cpp99
5 files changed, 171 insertions, 28 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 21aa0d7..873243b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -96,8 +96,7 @@ set_package_properties(CFitsio PROPERTIES DESCRIPTION "FITS IO Library" URL "htt
find_package(INDI 1.2.0)
#FIXME is there a better way to do this?
-if (INDI_FOUND)
-#FIXME is the following the right way of doing this?
+if (INDI_FOUND)
SET(HAVE_INDI 1)
else(INDI_FOUND)
SET(HAVE_INDI 0)
@@ -105,6 +104,15 @@ endif(INDI_FOUND)
set_package_properties(INDI PROPERTIES DESCRIPTION "Astronomical instrumentation control" URL "http://www.indilib.org" TYPE OPTIONAL PURPOSE "Support for controlling astronomical devices on Linux with KStars.")
+find_package(LibRaw)
+if (LibRaw_FOUND)
+SET(HAVE_LIBRAW 1)
+else (LibRaw_FOUND)
+SET(HAVE_LIBRAW 0)
+endif(LibRaw_FOUND)
+
+set_package_properties(LibRaw PROPERTIES DESCRIPTION "Library for reading RAW files" URL "http://www.libraw.org" TYPE OPTIONAL PURPOSE "Support for reading and displaying RAW files in KStars.")
+
find_package(WCSLIB)
if (WCSLIB_FOUND)
set(HAVE_WCSLIB 1)
diff --git a/cmake/modules/FindLibRaw.cmake b/cmake/modules/FindLibRaw.cmake
new file mode 100644
index 0000000..e2dbe09
--- /dev/null
+++ b/cmake/modules/FindLibRaw.cmake
@@ -0,0 +1,79 @@
+# - Find LibRaw
+# Find the LibRaw library <http://www.libraw.org>
+# This module defines
+# LibRaw_VERSION_STRING, 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)
+#
+# Copyright (c) 2013, Pino Toscano <pino at kde dot org>
+# Copyright (c) 2013, Gilles Caulier <caulier dot gilles at gmail dot com>
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+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_STRING "${_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_STRING
+ )
+
+MARK_AS_ADVANCED(LibRaw_VERSION_STRING
+ LibRaw_INCLUDE_DIR
+ LibRaw_LIBRARIES
+ LibRaw_r_LIBRARIES
+ LibRaw_DEFINITIONS
+ LibRaw_r_DEFINITIONS
+ )
diff --git a/config-kstars.h.cmake b/config-kstars.h.cmake
index 2546991..e761614 100644
--- a/config-kstars.h.cmake
+++ b/config-kstars.h.cmake
@@ -15,3 +15,6 @@
/* Define if we have KF5 >= 5.18.0 */
#cmakedefine HAVE_KF5WIT 1
+
+/* Define if you have libraw */
+#cmakedefine HAVE_LIBRAW 1
diff --git a/kstars/CMakeLists.txt b/kstars/CMakeLists.txt
index 00d4275..4722002 100644
--- a/kstars/CMakeLists.txt
+++ b/kstars/CMakeLists.txt
@@ -960,6 +960,12 @@ if(WCSLIB_FOUND)
target_link_libraries(KStarsLib ${WCSLIB_LIBRARIES})
endif (WCSLIB_FOUND)
+if(LibRaw_FOUND)
+if(NOT BUILD_KSTARS_LITE)
+ target_link_libraries(KStarsLib ${LibRaw_LIBRARIES})
+endif(NOT BUILD_KSTARS_LITE)
+endif (LibRaw_FOUND)
+
#FIXME Enable OpenGL Later
#if( OPENGL_FOUND )
# target_link_libraries(KStarsLib
diff --git a/kstars/indi/indiccd.cpp b/kstars/indi/indiccd.cpp
index 6bb8f45..fea10a7 100644
--- a/kstars/indi/indiccd.cpp
+++ b/kstars/indi/indiccd.cpp
@@ -25,6 +25,10 @@
#include "fitsviewer/fitsdata.h"
#endif
+#ifdef HAVE_LIBRAW
+#include <libraw/libraw.h>
+#endif
+
#include "driverinfo.h"
#include "clientmanager.h"
#include "streamwg.h"
@@ -38,7 +42,9 @@
#include "Options.h"
+
const int MAX_FILENAME_LEN = 1024;
+const QStringList RAWFormats = { "cr2", "crw", "nef", "raf", "dng" };
namespace ISD
{
@@ -1055,7 +1061,7 @@ void CCD::processText(ITextVectorProperty *tvp)
void CCD::processBLOB(IBLOB* bp)
{
- enum blobType { BLOB_IMAGE, BLOB_FITS, BLOB_CR2, BLOB_NEF, BLOB_OTHER} BType;
+ enum blobType { BLOB_IMAGE, BLOB_FITS, BLOB_RAW, BLOB_OTHER} BType;
BType = BLOB_OTHER;
@@ -1090,10 +1096,8 @@ void CCD::processBLOB(IBLOB* bp)
BType = BLOB_IMAGE;
else if (format.contains("fits"))
BType = BLOB_FITS;
- else if (format.contains("cr2"))
- BType = BLOB_CR2;
- else if (format.contains("nef"))
- BType = BLOB_NEF;
+ else if (RAWFormats.contains(format))
+ BType = BLOB_RAW;
if (BType == BLOB_OTHER)
{
@@ -1191,7 +1195,7 @@ void CCD::processBLOB(IBLOB* bp)
KStars::Instance()->statusBar()->showMessage( i18n("%1 file saved to %2", QString(fmt).toUpper(), filename ), 0);
// FIXME: Why is this leaking memory in Valgrind??!
- KNotification::event( QLatin1String( "FITSReceived" ) , i18n("FITS file is received"));
+ KNotification::event( QLatin1String( "FITSReceived" ) , i18n("Image file is received"));
/*if (targetChip->showFITS() == false && targetChip->getCaptureMode() == FITS_NORMAL)
{
@@ -1199,33 +1203,76 @@ void CCD::processBLOB(IBLOB* bp)
return;
}*/
- if (BType == BLOB_IMAGE || BType == BLOB_CR2 || BType == BLOB_NEF)
+ if (BType == BLOB_IMAGE || BType == BLOB_RAW)
{
- if (BType == BLOB_CR2 || BType == BLOB_NEF)
- {
- if (QStandardPaths::findExecutable("dcraw").isEmpty() == false && QStandardPaths::findExecutable("cjpeg").isEmpty() == false)
+ if (BType == BLOB_RAW)
+ {
+ #ifdef HAVE_LIBRAW
+
+ QString rawFileName = filename;
+ rawFileName = rawFileName.remove(0, rawFileName.lastIndexOf(QLatin1Literal("/")));
+ QString templateName = QString("%1/%2.XXXXXX").arg(QDir::tempPath()).arg(rawFileName);
+ QTemporaryFile imgPreview(templateName);
+ imgPreview.setAutoRemove(false);
+ imgPreview.open();
+ imgPreview.close();
+ QString preview_filename = imgPreview.fileName();
+
+ int ret=0;
+ // Creation of image processing object
+ LibRaw RawProcessor;
+
+ // Let us open the file
+ if( (ret = RawProcessor.open_file(rawFileName.toLatin1().data())) != LIBRAW_SUCCESS)
+ {
+ KStars::Instance()->statusBar()->showMessage(i18n("Cannot open %1: %2", rawFileName, libraw_strerror(ret)));
+ RawProcessor.recycle();
+ emit BLOBUpdated(bp);
+ return;
+ }
+
+ // Let us unpack the image
+ if( (ret = RawProcessor.unpack() ) != LIBRAW_SUCCESS)
{
- QProcess dcraw;
- QString rawFileName = filename;
- rawFileName = rawFileName.remove(0, rawFileName.lastIndexOf(QLatin1Literal("/")));
- QString templateName = QString("%1/%2.XXXXXX").arg(QDir::tempPath()).arg(rawFileName);
- QTemporaryFile jpgPreview(templateName);
- jpgPreview.setAutoRemove(false);
- jpgPreview.open();
- jpgPreview.close();
- QString jpeg_filename = jpgPreview.fileName();
-
- QString cmd = QString("/bin/sh -c \"dcraw -c -q 0 -w -H 5 -b 8 %1 | cjpeg -quality 80 > %2\"").arg(filename).arg(jpeg_filename);
- dcraw.start(cmd);
- dcraw.waitForFinished();
- filename = jpeg_filename;
+ KStars::Instance()->statusBar()->showMessage(i18n("Cannot unpack_thumb %1: %2", rawFileName, libraw_strerror(ret)));
+ if(LIBRAW_FATAL_ERROR(ret))
+ {
+ RawProcessor.recycle();
+ emit BLOBUpdated(bp);
+ return;
+ }
+ // if there has been a non-fatal error, we will try to continue
+ }
+
+ // Let us unpack the thumbnail
+ if( (ret = RawProcessor.unpack_thumb() ) != LIBRAW_SUCCESS)
+ {
+ KStars::Instance()->statusBar()->showMessage(i18n("Cannot unpack_thumb %1: %2", rawFileName, libraw_strerror(ret)));
+ RawProcessor.recycle();
+ emit BLOBUpdated(bp);
+ return;
}
else
+ // We have successfully unpacked the thumbnail, now let us write it to a file
{
- KStars::Instance()->statusBar()->showMessage(i18n("Unable to find dcraw and cjpeg. Please install the required tools to convert CR2/NEF to JPEG."));
+ //snprintf(thumbfn,sizeof(thumbfn),"%s.%s",av[i],T.tformat == LIBRAW_THUMBNAIL_JPEG ? "thumb.jpg" : "thumb.ppm");
+ if( LIBRAW_SUCCESS != (ret = RawProcessor.dcraw_thumb_writer(preview_filename.toLatin1().data())))
+ {
+ KStars::Instance()->statusBar()->showMessage(i18n("Cannot write %s %1: %2", preview_filename, libraw_strerror(ret)));
+ RawProcessor.recycle();
+ emit BLOBUpdated(bp);
+ return;
+ }
+ }
+
+ filename = preview_filename;
+
+ #else
+ // Silenty fail if KStars was not compiled with libraw
+ //KStars::Instance()->statusBar()->showMessage(i18n("Unable to find dcraw and cjpeg. Please install the required tools to convert CR2/NEF to JPEG."));
emit BLOBUpdated(bp);
return;
- }
+ #endif
}
if (imageViewer.isNull())