Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds support for the various raw photo formats as decoded by dcraw. A…
…s dcraw is only distributed as a binary, this actually creates a Qt plugin for mythgallery that runs dcraw externally. There are likely to be some RAW photo extensions that dcraw supports that got missed by the original author, and will need to be added. Also, I decided to leave the icc-profile as a configure-time setting for the moment as there's a push to be redoing all settings soon anyways, and we might as well redo it then. Original patch from Chad Parry <spam@chad.parry.org> Closes #7745 git-svn-id: http://svn.mythtv.org/svn/trunk@25667 7dbf422c-18fa-0310-86e9-fd20926502f2
- Loading branch information
Showing
11 changed files
with
331 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,52 @@ | ||
#include "dcrawformats.h" | ||
|
||
#include <QSet> | ||
#include <QString> | ||
|
||
namespace { | ||
|
||
QSet<QString> composeFormats() | ||
{ | ||
QSet<QString> formats; | ||
formats << "arw" << "ARW"; | ||
formats << "bay" << "BAY"; | ||
formats << "bmq" << "BMQ"; | ||
formats << "cr2" << "CR2"; | ||
formats << "crw" << "CRW"; | ||
formats << "cs1" << "CS1"; | ||
formats << "dc2" << "DC2"; | ||
formats << "dcr" << "DCR"; | ||
formats << "dng" << "DNG"; | ||
formats << "fff" << "FFF"; | ||
formats << "k25" << "K25"; | ||
formats << "kdc" << "KDC"; | ||
formats << "mos" << "MOS"; | ||
formats << "mrw" << "MRW"; | ||
formats << "nef" << "NEF"; | ||
formats << "orf" << "ORF"; | ||
formats << "pef" << "PEF"; | ||
formats << "raf" << "RAF"; | ||
formats << "raw" << "RAW"; | ||
formats << "rdc" << "RDC"; | ||
formats << "srf" << "SRF"; | ||
formats << "x3f" << "X3F"; | ||
return formats; | ||
} | ||
|
||
} // anonymous namespace | ||
|
||
QSet<QString> DcrawFormats::getFormats() | ||
{ | ||
static QSet<QString> formats(composeFormats()); | ||
return formats; | ||
} | ||
|
||
QStringList DcrawFormats::getFilters() | ||
{ | ||
QSet<QString> formats(getFormats()); | ||
QStringList filters; | ||
for (QSet<QString>::const_iterator i(formats.begin()); i != formats.end(); ++i) | ||
filters << ("*." + *i); | ||
return filters; | ||
} | ||
|
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,15 @@ | ||
|
||
#include <QSet> | ||
#include <QString> | ||
#include <QStringList> | ||
|
||
class DcrawFormats | ||
{ | ||
|
||
public: | ||
|
||
static QSet<QString> getFormats(); | ||
static QStringList getFilters(); | ||
|
||
}; | ||
|
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,90 @@ | ||
#include "dcrawhandler.h" | ||
|
||
#include "config.h" | ||
|
||
#include <cstddef> | ||
|
||
#include <QByteArray> | ||
#include <QFile> | ||
#include <QImage> | ||
#include <QIODevice> | ||
#include <QProcess> | ||
#include <QString> | ||
|
||
namespace | ||
{ | ||
|
||
bool getPath(QIODevice *device, QString &path) | ||
{ | ||
QFile *file = qobject_cast<QFile *>(device); | ||
if (!file) | ||
return false; | ||
path = file->fileName(); | ||
return true; | ||
} | ||
|
||
} // anonymous namespace | ||
|
||
bool DcrawHandler::canRead() const | ||
{ | ||
QString path; | ||
bool isFile = getPath(device(), path); | ||
if (!isFile) | ||
// It would still be possible to process this file, | ||
// but piping the image data to dcraw would be | ||
// difficult. This code path wouldn't be exercised in | ||
// MythGallery anyway. So for simplicity we give up. | ||
return false; | ||
|
||
QProcess process(NULL); | ||
QString program = "dcraw"; | ||
QStringList arguments; | ||
arguments << "-i" << path; | ||
process.start(program, arguments, QIODevice::NotOpen); | ||
|
||
bool finished = process.waitForFinished(); | ||
if (!finished) | ||
return false; | ||
if (process.exitStatus() != QProcess::NormalExit) | ||
return false; | ||
bool success = (process.exitCode() == 0); | ||
return success; | ||
} | ||
|
||
bool DcrawHandler::read(QImage *image) | ||
{ | ||
QString path; | ||
bool isFile = getPath(device(), path); | ||
if (!isFile) | ||
// It would still be possible to process this file, | ||
// but piping the image data to dcraw would be | ||
// difficult. This code path wouldn't be exercised in | ||
// MythGallery anyway. So for simplicity we give up. | ||
return false; | ||
|
||
QProcess process(NULL); | ||
QString program = "dcraw"; | ||
QStringList arguments; | ||
arguments << "-c" << "-w" << "-W"; | ||
#ifdef ICC_PROFILE | ||
arguments << "-p" << ICC_PROFILE; | ||
#endif // ICC_PROFILE | ||
arguments << path; | ||
process.start(program, arguments, QIODevice::ReadOnly); | ||
|
||
bool finished = process.waitForFinished(); | ||
if (!finished) | ||
return false; | ||
if (process.exitStatus() != QProcess::NormalExit) | ||
return false; | ||
if (process.exitCode() != 0) | ||
return false; | ||
|
||
QByteArray buffer = process.readAll(); | ||
if (buffer.isEmpty()) | ||
return false; | ||
|
||
bool loaded = image->loadFromData(buffer, "PPM"); | ||
return loaded; | ||
} | ||
|
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,13 @@ | ||
#include <QImage> | ||
#include <QImageIOHandler> | ||
|
||
class DcrawHandler : public QImageIOHandler | ||
{ | ||
|
||
public: | ||
|
||
bool canRead() const; | ||
bool read(QImage *image); | ||
|
||
}; | ||
|
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,42 @@ | ||
#include "dcrawplugin.h" | ||
|
||
#include "dcrawformats.h" | ||
#include "dcrawhandler.h" | ||
|
||
#include <QByteArray> | ||
#include <QImageIOHandler> | ||
#include <QImageIOPlugin> | ||
#include <QIODevice> | ||
#include <QStringList> | ||
|
||
QStringList DcrawPlugin::keys() const | ||
{ | ||
return QStringList(DcrawFormats::getFormats().toList()); | ||
} | ||
|
||
QImageIOPlugin::Capabilities DcrawPlugin::capabilities(QIODevice *device, const QByteArray &format) const | ||
{ | ||
if (DcrawFormats::getFormats().contains(format)) | ||
return CanRead; | ||
|
||
if (format.isEmpty()) | ||
{ | ||
DcrawHandler handler; | ||
handler.setDevice(device); | ||
if (handler.canRead()) | ||
return CanRead; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
QImageIOHandler *DcrawPlugin::create(QIODevice *device, const QByteArray &format) const | ||
{ | ||
DcrawHandler *handler = new DcrawHandler; | ||
handler->setDevice(device); | ||
handler->setFormat(format); | ||
return handler; | ||
} | ||
|
||
Q_EXPORT_PLUGIN2(dcrawplugin, DcrawPlugin) | ||
|
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,20 @@ | ||
#include <QByteArray> | ||
#include <QIODevice> | ||
#include <QImageIOHandler> | ||
#include <QImageIOPlugin> | ||
#include <QObject> | ||
#include <QStringList> | ||
|
||
class DcrawPlugin : public QImageIOPlugin | ||
{ | ||
|
||
Q_OBJECT | ||
|
||
public: | ||
|
||
QStringList keys() const; | ||
Capabilities capabilities(QIODevice *device, const QByteArray &format) const; | ||
QImageIOHandler *create(QIODevice *device, const QByteArray &format) const; | ||
|
||
}; | ||
|
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,17 @@ | ||
include ( ../../mythconfig.mak ) | ||
include ( ../../settings.pro ) | ||
include ( ../../programs-libs.pro ) | ||
|
||
TEMPLATE = lib | ||
CONFIG += plugin static | ||
TARGET = dcrawplugin | ||
|
||
# Input | ||
HEADERS += config.h | ||
HEADERS += dcrawformats.h | ||
HEADERS += dcrawhandler.h | ||
HEADERS += dcrawplugin.h | ||
SOURCES += dcrawformats.cpp | ||
SOURCES += dcrawhandler.cpp | ||
SOURCES += dcrawplugin.cpp | ||
|
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
Oops, something went wrong.