File indexing completed on 2025-01-05 03:56:01

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2008-09-25
0007  * Description : a tool to convert RAW file to DNG - Raw data import.
0008  *
0009  * SPDX-FileCopyrightText: 2008-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  * SPDX-FileCopyrightText: 2010-2011 by Jens Mueller <tschenser at gmx dot de>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #include "dngwriter_p.h"
0017 
0018 // Local includes
0019 
0020 #include "dngwriterhost.h"
0021 
0022 namespace Digikam
0023 {
0024 
0025 int DNGWriter::Private::importRaw(DRawInfo* const identify,
0026                                   DRawInfo* const identifyMake)
0027 {
0028     if (parent->inputFile().isEmpty())
0029     {
0030         qCCritical(DIGIKAM_GENERAL_LOG) << "DNGWriter: No input file to convert. Aborted...";
0031 
0032         return PROCESS_FAILED;
0033     }
0034 
0035     inputInfo   = QFileInfo(parent->inputFile());
0036     dngFilePath = parent->outputFile();
0037 
0038     if (dngFilePath.isEmpty())
0039     {
0040         dngFilePath = QString(inputInfo.completeBaseName() + QLatin1String(".dng"));
0041     }
0042 
0043     outputInfo  = QFileInfo(dngFilePath);
0044 
0045     // -----------------------------------------------------------------------------------------
0046 
0047     qCDebug(DIGIKAM_GENERAL_LOG) << "DNGWriter: Loading RAW data from " << inputInfo.fileName();
0048 
0049     QPointer<DRawDecoder> rawProcessor(new DRawDecoder);
0050 
0051     if (!rawProcessor->rawFileIdentify(*identifyMake, parent->inputFile()))
0052     {
0053         qCCritical(DIGIKAM_GENERAL_LOG) << "DNGWriter: Reading RAW file failed. Aborted...";
0054 
0055         return PROCESS_FAILED;
0056     }
0057 
0058     // TODO: need to get correct default crop size to avoid artifacts at the borders
0059 
0060     if ((identifyMake->orientation == 5) || (identifyMake->orientation == 6))
0061     {
0062         outputHeight = identifyMake->outputSize.width();
0063         outputWidth  = identifyMake->outputSize.height();
0064     }
0065     else
0066     {
0067         outputHeight = identifyMake->outputSize.height();
0068         outputWidth  = identifyMake->outputSize.width();
0069     }
0070 
0071     if (!rawProcessor->extractRAWData(parent->inputFile(), rawData, *identify, 0))
0072     {
0073         qCCritical(DIGIKAM_GENERAL_LOG) << "DNGWriter: Loading RAW data failed. Aborted...";
0074 
0075         return FILE_NOT_SUPPORTED;
0076     }
0077 
0078     qCDebug(DIGIKAM_GENERAL_LOG) << "DNGWriter: Raw data loaded:" ;
0079     qCDebug(DIGIKAM_GENERAL_LOG) << "--- Data Size:     " << rawData.size() << " bytes";
0080     qCDebug(DIGIKAM_GENERAL_LOG) << "--- Date:          " << identify->dateTime.toString(Qt::ISODate);
0081     qCDebug(DIGIKAM_GENERAL_LOG) << "--- Make:          " << identify->make;
0082     qCDebug(DIGIKAM_GENERAL_LOG) << "--- Model:         " << identify->model;
0083     qCDebug(DIGIKAM_GENERAL_LOG) << "--- ImageSize:     " << identify->imageSize.width()  << "x" << identify->imageSize.height();
0084     qCDebug(DIGIKAM_GENERAL_LOG) << "--- FullSize:      " << identify->fullSize.width()   << "x" << identify->fullSize.height();
0085     qCDebug(DIGIKAM_GENERAL_LOG) << "--- OutputSize:    " << identify->outputSize.width() << "x" << identify->outputSize.height();
0086     qCDebug(DIGIKAM_GENERAL_LOG) << "--- Orientation:   " << identify->orientation;
0087     qCDebug(DIGIKAM_GENERAL_LOG) << "--- Top margin:    " << identify->topMargin;
0088     qCDebug(DIGIKAM_GENERAL_LOG) << "--- Left margin:   " << identify->leftMargin;
0089     qCDebug(DIGIKAM_GENERAL_LOG) << "--- Filter:        " << identify->filterPattern;
0090     qCDebug(DIGIKAM_GENERAL_LOG) << "--- Colors:        " << identify->rawColors;
0091     qCDebug(DIGIKAM_GENERAL_LOG) << "--- Black:         " << identify->blackPoint;
0092     qCDebug(DIGIKAM_GENERAL_LOG) << "--- White:         " << identify->whitePoint;
0093     qCDebug(DIGIKAM_GENERAL_LOG) << "--- CAM->XYZ:";
0094 
0095     for (int i = 0 ; i < 4 ; ++i)
0096     {
0097         qCDebug(DIGIKAM_GENERAL_LOG)
0098                  << "                   "
0099                  << QString().asprintf("%03.4f  %03.4f  %03.4f", identify->cameraXYZMatrix[i][0],
0100                                                                  identify->cameraXYZMatrix[i][1],
0101                                                                  identify->cameraXYZMatrix[i][2]);
0102     }
0103 
0104     if (cancel)
0105     {
0106         return PROCESS_CANCELED;
0107     }
0108 
0109     return PROCESS_CONTINUE;
0110 }
0111 
0112 } // namespace Digikam