File indexing completed on 2025-01-05 03:56:02
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 - Mosaic identification. 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::identMosaic(DRawInfo* const identify, 0026 DRawInfo* const identifyMake) 0027 { 0028 // Check if CFA layout is supported by DNG SDK. 0029 0030 bool fujiRotate90 = false; 0031 0032 // Standard bayer layouts 0033 0034 if (identify->filterPattern == QLatin1String("GRBGGRBGGRBGGRBG")) 0035 { 0036 bayerPattern = Private::Standard; 0037 filter = 0; 0038 } 0039 else if (identify->filterPattern == QLatin1String("RGGBRGGBRGGBRGGB")) 0040 { 0041 bayerPattern = Private::Standard; 0042 filter = 1; 0043 } 0044 else if (identify->filterPattern == QLatin1String("BGGRBGGRBGGRBGGR")) 0045 { 0046 bayerPattern = Private::Standard; 0047 filter = 2; 0048 } 0049 else if (identify->filterPattern == QLatin1String("GBRGGBRGGBRGGBRG")) 0050 { 0051 bayerPattern = Private::Standard; 0052 filter = 3; 0053 } 0054 else if ((identify->filterPattern == QLatin1String("RGBGRGBGRGBGRGBG")) && 0055 (identifyMake->make.toUpper() == QLatin1String("FUJIFILM"))) 0056 { 0057 // Fuji layouts 0058 0059 bayerPattern = Private::Fuji; 0060 fujiRotate90 = false; 0061 filter = 0; 0062 } 0063 else if ((identify->filterPattern == QLatin1String("RBGGBRGGRBGGBRGG")) && 0064 (identifyMake->make.toUpper() == QLatin1String("FUJIFILM"))) 0065 { 0066 // Fuji layouts 0067 0068 bayerPattern = Private::Fuji; 0069 fujiRotate90 = true; 0070 filter = 0; 0071 } 0072 else if ((identify->filterPattern == QLatin1String("GGGGBRGGGGRBGGGG")) && 0073 (identifyMake->make.toUpper() == QLatin1String("FUJIFILM"))) 0074 { 0075 // Fuji layouts 0076 0077 bayerPattern = Private::Fuji6x6; 0078 fujiRotate90 = false; 0079 filter = 1; 0080 } 0081 else if ((identify->rawColors == 3) && 0082 (identify->filterPattern.isEmpty()) && 0083 ((uint32)rawData.size() == (identify->outputSize.width() * identify->outputSize.height() * 3 * sizeof(uint16)))) 0084 { 0085 bayerPattern = Private::LinearRaw; 0086 } 0087 else if (identify->rawColors == 4) // Four color sensors 0088 { 0089 bayerPattern = Private::FourColor; 0090 0091 if (identify->filterPattern.length() != 16) 0092 { 0093 qCCritical(DIGIKAM_GENERAL_LOG) << "DNGWriter: Bayer mosaic not supported. Aborted..."; 0094 0095 return FILE_NOT_SUPPORTED; 0096 } 0097 0098 for (int i = 0 ; i < 16 ; ++i) 0099 { 0100 filter = filter >> 2; 0101 0102 if (identify->filterPattern[i] == QLatin1Char('G')) 0103 { 0104 filter |= 0x00000000; 0105 } 0106 else if (identify->filterPattern[i] == QLatin1Char('M')) 0107 { 0108 filter |= 0x40000000; 0109 } 0110 else if (identify->filterPattern[i] == QLatin1Char('C')) 0111 { 0112 filter |= 0x80000000; 0113 } 0114 else if (identify->filterPattern[i] == QLatin1Char('Y')) 0115 { 0116 filter |= 0xC0000000; 0117 } 0118 else 0119 { 0120 qCCritical(DIGIKAM_GENERAL_LOG) << "DNGWriter: Bayer mosaic not supported. Aborted..."; 0121 0122 return FILE_NOT_SUPPORTED; 0123 } 0124 } 0125 } 0126 else 0127 { 0128 qCCritical(DIGIKAM_GENERAL_LOG) << "DNGWriter: Bayer mosaic not supported. Aborted..."; 0129 0130 return FILE_NOT_SUPPORTED; 0131 } 0132 0133 if (fujiRotate90) 0134 { 0135 if (!fujiRotate(rawData, *identify)) 0136 { 0137 qCCritical(DIGIKAM_GENERAL_LOG) << "Can not rotate fuji image. Aborted..."; 0138 0139 return PROCESS_FAILED; 0140 } 0141 0142 int tmp = outputWidth; 0143 outputWidth = outputHeight; 0144 outputHeight = tmp; 0145 } 0146 0147 activeArea = dng_rect(identify->outputSize.height(), identify->outputSize.width()); 0148 activeWidth = identify->outputSize.width(); 0149 activeHeight = identify->outputSize.height(); 0150 0151 // Check if number of Raw Color components is supported. 0152 0153 if ((identify->rawColors != 3) && 0154 (identify->rawColors != 4)) 0155 { 0156 qCCritical(DIGIKAM_GENERAL_LOG) << "DNGWriter: Number of Raw color components not supported. Aborted..."; 0157 0158 return PROCESS_FAILED; 0159 } 0160 0161 width = identify->outputSize.width(); 0162 height = identify->outputSize.height(); 0163 /* 0164 debugExtractedRAWData(rawData); 0165 */ 0166 if (cancel) 0167 { 0168 return PROCESS_CANCELED; 0169 } 0170 0171 return PROCESS_CONTINUE; 0172 } 0173 0174 } // namespace Digikam