예제 #1
0
bool IOWorker::write_ldr_frame(pfs::Frame* ldr_input,
                               const QString& filename,
                               const QString& inputFileName,
                               const QVector<float>& expoTimes,
                               TonemappingOptions* tmopts,
                               const pfs::Params& params)
{
    bool status = true;
    emit IO_init();

    QScopedPointer<TMOptionsOperations> operations;
    if (tmopts != NULL) {
        operations.reset(new TMOptionsOperations(tmopts));
    }
    
    QFileInfo qfi(filename);
    QString absoluteFileName = qfi.absoluteFilePath();
    QByteArray encodedName = QFile::encodeName(absoluteFileName);

    try
    {
        FrameWriterPtr writer = FrameWriterFactory::open(encodedName.constData(), params);
        writer->write(*ldr_input, params);
    }
    catch (pfs::io::UnsupportedFormat& exUnsupported) {
        qDebug() << "Exception: " << exUnsupported.what();

        QString format = qfi.suffix();
        // QScopedPointer will call delete when this object goes out of scope
        QScopedPointer<QImage> image(fromLDRPFStoQImage(ldr_input, 0.f, 1.f));
        status = image->save(filename, format.toLocal8Bit(), -1);
    }
    catch (pfs::io::InvalidFile& /*exInvalid*/) {
        status = false;
    }
    catch (pfs::io::WriteException& /*exWrite*/) {
        status = false;
    }

    if ( status )
    {
        // copy EXIF tags from the 1st bracketed image
        if ( !inputFileName.isEmpty() )
        {
            QFileInfo fileinfo(inputFileName);
            QString absoluteInputFileName = fileinfo.absoluteFilePath();
            QByteArray encodedInputFileName = QFile::encodeName(absoluteInputFileName);
            QString comment = operations->getExifComment();
            if ( !expoTimes.empty() ) {
                comment += "\nBracketed images exposure times:\n";
                foreach (float e, expoTimes) {
                    comment += QString("%1").arg(e) + "\n";
                }
            }