Ticket #7745: 0001-Patch-from-7745-add-dcraw-processing.patch

File 0001-Patch-from-7745-add-dcraw-processing.patch, 13.2 KB (added by beirdo, 9 years ago)

updated to svn [25661]

  • mythplugins/configure

    From b4510579dcc361615223fa04b60f5c38a9286ce0 Mon Sep 17 00:00:00 2001
    From: Gavin Hurlbut <gjhurlbu@gmail.com>
    Date: Sat, 14 Aug 2010 17:59:08 -0700
    Subject: [PATCH 1/2] Patch from #7745 - add dcraw processing
    
    
    diff --git a/mythplugins/configure b/mythplugins/configure
    index 2d6543d..c7db257 100755
    a b fftw 
    117117sdl
    118118exif
    119119newexif
     120dcraw
    120121"
    121122
    122123enable $PLUGIN_LIST $CONFIG_LIST
    MythGallery related options: 
    162163  --enable-mythgallery     build the mythgallery plugin [$gallery]
    163164  --enable-exif            enable reading of EXIF headers [$exif]
    164165  --enable-new-exif        use libexif > version 0.6.9 [$newexif]
     166  --enable-dcraw           use dcraw to view raw photos [$dcraw]
     167  --icc-profile=PROFILE    ICC profile for dcraw decoding [$icc]
    165168
    166169MythGame related options:
    167170  --enable-mythgame        build the mythgame plugin [$game]
    for opt do 
    247250  ;;
    248251  --disable-new-exif) disable newexif
    249252  ;;
     253  --enable-dcraw) dcraw="yes"
     254  ;;
     255  --disable-dcraw) dcraw="no"
     256  ;;
     257  --icc-profile=*) icc=`echo $opt | cut -d '=' -f 2`
     258  ;;
    250259  --enable-all)
    251260      enable $PLUGIN_LIST $CONFIG_LIST
    252261  ;;
    if ! disabled weather; then 
    453462    check_pl_lib "SOAP::Lite"  || disable_weather "SOAP::Lite"
    454463fi
    455464
     465if test "$dcraw" != "no" ; then
     466    dcraw="no"
     467    if test x`which dcraw` != x ; then
     468        dcraw="yes"
     469    fi
     470fi
     471
     472if test x"$icc" != x ; then
     473    # Assume relative paths are for files in the standard icc directory.
     474    case "$icc" in
     475    /*)
     476    ;;
     477    *) icc=/usr/share/color/icc/$icc
     478    ;;
     479    esac
     480    # Verify the presence of the file.
     481    if test ! -f "$icc" ; then
     482        icc=""
     483    fi
     484fi
     485
    456486if test "$music" != "no" ; then
    457487    vorbis="no"
    458488    if has_header ogg/ogg.h && has_header vorbis/vorbisenc.h && has_header vorbis/vorbisfile.h && has_header vorbis/codec.h && has_library libogg && has_library libvorbisfile && has_library libvorbisenc && has_library libvorbis ; then
    if test "$gallery" = "yes" ; then 
    659689    echo "    Automatically generated by configure - do not modify" >> ./mythgallery/mythgallery/config.h
    660690    echo "*/" >> ./mythgallery/mythgallery/config.h
    661691
     692    echo "#" > ./mythgallery/config.pro
     693    echo "#    Automatically generated by configure - modify only under penalty of death" >> ./mythgallery/config.pro
     694    echo "#" >> ./mythgallery/config.pro
     695
    662696    echo "#" > ./mythgallery/mythgallery/config.pro
    663697    echo "#    Automatically generated by configure - modify only under penalty of death" >> ./mythgallery/mythgallery/config.pro
    664698    echo "#" >> ./mythgallery/mythgallery/config.pro
    if test "$gallery" = "yes" ; then 
    702736    if test "$exif" = "no" ; then
    703737        echo "        EXIF           support will not be included in MythGallery"
    704738    fi
     739
     740    if test "$dcraw" = "yes" ; then
     741        echo "        Dcraw          support will be included in MythGallery"
     742        echo "SUBDIRS += dcrawplugin" >> ./mythgallery/config.pro
     743        echo "#define DCRAW_SUPPORT 1" >> ./mythgallery/mythgallery/config.h
     744        echo "LIBS += -L../dcrawplugin -ldcrawplugin" >> ./mythgallery/mythgallery/config.pro
     745        echo "TARGETDEPS += ../dcrawplugin/libdcrawplugin.a" >> ./mythgallery/mythgallery/config.pro
     746
     747        echo "/*" >  ./mythgallery/dcrawplugin/config.h
     748        echo "    Automatically generated by configure - do not modify" >> ./mythgallery/dcrawplugin/config.h
     749        echo "*/" >> ./mythgallery/dcrawplugin/config.h
     750
     751        if test x"$icc" != x ; then
     752            echo "        ICC profile    $icc"
     753            # Quote C escape characters.
     754            quoted_icc=`echo "$icc" | sed 's/\\([\\\\"?]\\)/\\\\\\1/g;\$!{s/\$/\\\\/}'`
     755            echo "#define ICC_PROFILE \"$quoted_icc\"" >> ./mythgallery/dcrawplugin/config.h
     756        fi
     757
     758    fi
     759
     760    if test "$dcraw" = "no" ; then
     761        echo "        Dcraw          support will not be included in MythGallery"
     762    fi
     763
    705764fi
    706765
    707766###########################################################
  • new file mythplugins/mythgallery/dcrawplugin/dcrawformats.cpp

    diff --git a/mythplugins/mythgallery/dcrawplugin/dcrawformats.cpp b/mythplugins/mythgallery/dcrawplugin/dcrawformats.cpp
    new file mode 100644
    index 0000000..1a1fb13
    - +  
     1#include "dcrawformats.h"
     2
     3#include <QSet>
     4#include <QString>
     5
     6namespace {
     7
     8QSet<QString> composeFormats()
     9{
     10    QSet<QString> formats;
     11    formats << "bay" << "BAY";
     12    formats << "bmq" << "BMQ";
     13    formats << "cr2" << "CR2";
     14    formats << "crw" << "CRW";
     15    formats << "cs1" << "CS1";
     16    formats << "dc2" << "DC2";
     17    formats << "dcr" << "DCR";
     18    formats << "dng" << "DNG";
     19    formats << "fff" << "FFF";
     20    formats << "k25" << "K25";
     21    formats << "kdc" << "KDC";
     22    formats << "mos" << "MOS";
     23    formats << "mrw" << "MRW";
     24    formats << "nef" << "NEF";
     25    formats << "orf" << "ORF";
     26    formats << "pef" << "PEF";
     27    formats << "raf" << "RAF";
     28    formats << "raw" << "RAW";
     29    formats << "rdc" << "RDC";
     30    formats << "srf" << "SRF";
     31    formats << "x3f" << "X3F";
     32    return formats;
     33}
     34
     35}    // anonymous namespace
     36
     37QSet<QString> DcrawFormats::getFormats()
     38{
     39    static QSet<QString> formats(composeFormats());
     40    return formats;
     41}
     42
     43QStringList DcrawFormats::getFilters()
     44{
     45    QSet<QString> formats(getFormats());
     46    QStringList filters;
     47    for (QSet<QString>::const_iterator i(formats.begin()); i != formats.end(); ++i)
     48        filters << ("*." + *i);
     49    return filters;
     50}
     51
  • new file mythplugins/mythgallery/dcrawplugin/dcrawformats.h

    diff --git a/mythplugins/mythgallery/dcrawplugin/dcrawformats.h b/mythplugins/mythgallery/dcrawplugin/dcrawformats.h
    new file mode 100644
    index 0000000..c6df45c
    - +  
     1
     2#include <QSet>
     3#include <QString>
     4#include <QStringList>
     5
     6class DcrawFormats
     7{
     8
     9public:
     10
     11    static QSet<QString> getFormats();
     12    static QStringList getFilters();
     13
     14};
     15
  • new file mythplugins/mythgallery/dcrawplugin/dcrawhandler.cpp

    diff --git a/mythplugins/mythgallery/dcrawplugin/dcrawhandler.cpp b/mythplugins/mythgallery/dcrawplugin/dcrawhandler.cpp
    new file mode 100644
    index 0000000..4a34481
    - +  
     1#include "dcrawhandler.h"
     2
     3#include "config.h"
     4
     5#include <cstddef>
     6
     7#include <QByteArray>
     8#include <QFile>
     9#include <QImage>
     10#include <QIODevice>
     11#include <QProcess>
     12#include <QString>
     13
     14namespace
     15{
     16
     17bool getPath(QIODevice *device, QString &path)
     18{
     19    QFile *file = qobject_cast<QFile *>(device);
     20    if (!file)
     21        return false;
     22    path = file->fileName();
     23    return true;
     24}
     25
     26}    // anonymous namespace
     27
     28bool DcrawHandler::canRead() const
     29{
     30    QString path;
     31    bool isFile = getPath(device(), path);
     32    if (!isFile)
     33        // It would still be possible to process this file,
     34        // but piping the image data to dcraw would be
     35        // difficult. This code path wouldn't be exercised in
     36        // MythGallery anyway. So for simplicity we give up.
     37        return false;
     38
     39    QProcess process(NULL);
     40    QString program = "dcraw";
     41    QStringList arguments;
     42    arguments << "-i" << path;
     43    process.start(program, arguments, QIODevice::NotOpen);
     44
     45    bool finished = process.waitForFinished();
     46    if (!finished)
     47        return false;
     48    if (process.exitStatus() != QProcess::NormalExit)
     49        return false;
     50    bool success = (process.exitCode() == 0);
     51    return success;
     52}
     53
     54bool DcrawHandler::read(QImage *image)
     55{
     56    QString path;
     57    bool isFile = getPath(device(), path);
     58    if (!isFile)
     59        // It would still be possible to process this file,
     60        // but piping the image data to dcraw would be
     61        // difficult. This code path wouldn't be exercised in
     62        // MythGallery anyway. So for simplicity we give up.
     63        return false;
     64
     65    QProcess process(NULL);
     66    QString program = "dcraw";
     67    QStringList arguments;
     68    arguments << "-c" << "-w" << "-W";
     69#ifdef ICC_PROFILE
     70    arguments << "-p" << ICC_PROFILE;
     71#endif // ICC_PROFILE
     72    arguments << path;
     73    process.start(program, arguments, QIODevice::ReadOnly);
     74
     75    bool finished = process.waitForFinished();
     76    if (!finished)
     77        return false;
     78    if (process.exitStatus() != QProcess::NormalExit)
     79        return false;
     80    if (process.exitCode() != 0)
     81        return false;
     82
     83    QByteArray buffer = process.readAll();
     84    if (buffer.isEmpty())
     85        return false;
     86
     87    bool loaded = image->loadFromData(buffer, "PPM");
     88    return loaded;
     89}
     90
  • new file mythplugins/mythgallery/dcrawplugin/dcrawhandler.h

    diff --git a/mythplugins/mythgallery/dcrawplugin/dcrawhandler.h b/mythplugins/mythgallery/dcrawplugin/dcrawhandler.h
    new file mode 100644
    index 0000000..ee43fe7
    - +  
     1#include <QImage>
     2#include <QImageIOHandler>
     3
     4class DcrawHandler : public QImageIOHandler
     5{
     6
     7public:
     8
     9    bool canRead() const;
     10    bool read(QImage *image);
     11
     12};
     13
  • new file mythplugins/mythgallery/dcrawplugin/dcrawplugin.cpp

    diff --git a/mythplugins/mythgallery/dcrawplugin/dcrawplugin.cpp b/mythplugins/mythgallery/dcrawplugin/dcrawplugin.cpp
    new file mode 100644
    index 0000000..6f9e3f4
    - +  
     1#include "dcrawplugin.h"
     2
     3#include "dcrawformats.h"
     4#include "dcrawhandler.h"
     5
     6#include <QByteArray>
     7#include <QImageIOHandler>
     8#include <QImageIOPlugin>
     9#include <QIODevice>
     10#include <QStringList>
     11
     12QStringList DcrawPlugin::keys() const
     13{
     14    return QStringList(DcrawFormats::getFormats().toList());
     15}
     16
     17QImageIOPlugin::Capabilities DcrawPlugin::capabilities(QIODevice *device, const QByteArray &format) const
     18{
     19    if (DcrawFormats::getFormats().contains(format))
     20        return CanRead;
     21
     22    if (format.isEmpty())
     23    {
     24        DcrawHandler handler;
     25        handler.setDevice(device);
     26        if (handler.canRead())
     27            return CanRead;
     28    }
     29
     30    return 0;
     31}
     32
     33QImageIOHandler *DcrawPlugin::create(QIODevice *device, const QByteArray &format) const
     34{
     35    DcrawHandler *handler = new DcrawHandler;
     36    handler->setDevice(device);
     37    handler->setFormat(format);
     38    return handler;
     39}
     40
     41Q_EXPORT_PLUGIN2(dcrawplugin, DcrawPlugin)
     42
  • new file mythplugins/mythgallery/dcrawplugin/dcrawplugin.h

    diff --git a/mythplugins/mythgallery/dcrawplugin/dcrawplugin.h b/mythplugins/mythgallery/dcrawplugin/dcrawplugin.h
    new file mode 100644
    index 0000000..33557b5
    - +  
     1#include <QByteArray>
     2#include <QIODevice>
     3#include <QImageIOHandler>
     4#include <QImageIOPlugin>
     5#include <QObject>
     6#include <QStringList>
     7
     8class DcrawPlugin : public QImageIOPlugin
     9{
     10
     11    Q_OBJECT
     12
     13public:
     14
     15    QStringList keys() const;
     16    Capabilities capabilities(QIODevice *device, const QByteArray &format) const;
     17    QImageIOHandler *create(QIODevice *device, const QByteArray &format) const;
     18
     19};
     20
  • new file mythplugins/mythgallery/dcrawplugin/dcrawplugin.pro

    diff --git a/mythplugins/mythgallery/dcrawplugin/dcrawplugin.pro b/mythplugins/mythgallery/dcrawplugin/dcrawplugin.pro
    new file mode 100644
    index 0000000..8d646dc
    - +  
     1include ( ../../mythconfig.mak )
     2include ( ../../settings.pro )
     3include ( ../../programs-libs.pro )
     4
     5TEMPLATE = lib
     6CONFIG += plugin static
     7TARGET = dcrawplugin
     8
     9# Input
     10HEADERS += config.h
     11HEADERS += dcrawformats.h
     12HEADERS += dcrawhandler.h
     13HEADERS += dcrawplugin.h
     14SOURCES += dcrawformats.cpp
     15SOURCES += dcrawhandler.cpp
     16SOURCES += dcrawplugin.cpp
     17
  • mythplugins/mythgallery/mythgallery.pro

    diff --git a/mythplugins/mythgallery/mythgallery.pro b/mythplugins/mythgallery/mythgallery.pro
    index fdb2d76..d48b939 100644
    a b  
    44
    55TEMPLATE = subdirs
    66
     7include (config.pro)
     8
     9!exists( config.pro ) {
     10   error(Missing config.pro: please run the configure script)
     11}
     12
    713# Directories
    8 SUBDIRS = mythgallery theme i18n
     14SUBDIRS += mythgallery theme i18n
     15
  • mythplugins/mythgallery/mythgallery/galleryutil.cpp

    diff --git a/mythplugins/mythgallery/mythgallery/galleryutil.cpp b/mythplugins/mythgallery/mythgallery/galleryutil.cpp
    index 8a73b01..b47c9e0 100644
    a b  
    3232#include "galleryutil.h"
    3333#include "thumbgenerator.h"
    3434
     35#ifdef DCRAW_SUPPORT
     36#include "../dcrawplugin/dcrawformats.h"
     37#endif // DCRAW_SUPPORT
     38
    3539#ifdef EXIF_SUPPORT
    3640#include <libexif/exif-data.h>
    3741#include <libexif/exif-entry.h>
    QStringList GalleryUtil::GetImageFilter(void) 
    5761    filt.push_back("*.tiff");
    5862    filt.push_back("*.bmp");
    5963    filt.push_back("*.gif");
     64
     65#ifdef DCRAW_SUPPORT
     66    filt << DcrawFormats::getFilters();
     67#endif // DCRAW_SUPPORT
     68
    6069    return filt;
    6170}
    6271
  • mythplugins/mythgallery/mythgallery/main.cpp

    diff --git a/mythplugins/mythgallery/mythgallery/main.cpp b/mythplugins/mythgallery/mythgallery/main.cpp
    index 98d7d62..97acbfb 100644
    a b  
    33
    44// qt
    55#include <QDir>
     6#include <QtPlugin>
    67
    78// myth
    89#include <mythcontext.h>
     
    1213#include <mythpluginapi.h>
    1314
    1415// mythgallery
     16#include "config.h"
    1517#include "iconview.h"
    1618#include "gallerysettings.h"
    1719#include "dbcheck.h"
    1820
     21#ifdef DCRAW_SUPPORT
     22Q_IMPORT_PLUGIN(dcrawplugin)
     23#endif // DCRAW_SUPPORT
     24
    1925static int run(MythMediaDevice *dev = NULL)
    2026{
    2127    QDir startdir(gCoreContext->GetSetting("GalleryDir"));