File indexing completed on 2025-01-19 03:53:16
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2008-13-08 0007 * Description : Raw post processing corrections. 0008 * 0009 * SPDX-FileCopyrightText: 2008-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #include "rawpostprocessing.h" 0016 0017 // Local includes 0018 0019 #include "digikam_debug.h" 0020 #include "imagehistogram.h" 0021 #include "imagelevels.h" 0022 #include "wbfilter.h" 0023 #include "curvesfilter.h" 0024 #include "bcgfilter.h" 0025 #include "digikam_globals.h" 0026 0027 namespace DigikamRawImportNativePlugin 0028 { 0029 0030 RawPostProcessing::RawPostProcessing(DImg* const orgImage, QObject* const parent, const DRawDecoding& settings) 0031 : DImgThreadedFilter (parent), 0032 m_customRawSettings(settings) 0033 0034 { 0035 setFilterName("RawPostProcessing"); 0036 setOriginalImage(orgImage->copy()); 0037 initFilter(); 0038 } 0039 0040 RawPostProcessing::RawPostProcessing(DImgThreadedFilter* const parentFilter, 0041 const DImg& orgImage, 0042 const DImg& destImage, 0043 int progressBegin, 0044 int progressEnd, 0045 const DRawDecoding& settings) 0046 : DImgThreadedFilter(parentFilter, orgImage, destImage, progressBegin, progressEnd, 0047 parentFilter->filterName() + ": RawPostProcessing"), 0048 m_customRawSettings(settings) 0049 { 0050 // NOTE: use dynamic binding as this virtual method can be re-implemented in derived classes. 0051 0052 this->filterImage(); 0053 } 0054 0055 RawPostProcessing::~RawPostProcessing() 0056 { 0057 cancelFilter(); 0058 } 0059 0060 void RawPostProcessing::filterImage() 0061 { 0062 rawPostProcessing(); 0063 } 0064 0065 void RawPostProcessing::rawPostProcessing() 0066 { 0067 if (!m_orgImage.bits() || !m_orgImage.width() || !m_orgImage.height()) 0068 { 0069 qCWarning(DIGIKAM_GENERAL_LOG) << ("RawPostProcessing::rawPostProcessing: no image m_orgImage.bits() available!"); 0070 return; 0071 } 0072 0073 if (!m_customRawSettings.postProcessingSettingsIsDirty()) 0074 { 0075 m_destImage = m_orgImage; 0076 return; 0077 } 0078 0079 postProgress(20); 0080 0081 if ((m_customRawSettings.exposureComp != 0.0) || (m_customRawSettings.saturation != 1.0)) 0082 { 0083 WBContainer settings; 0084 settings.temperature = 6500.0; 0085 settings.dark = 0.5; 0086 settings.black = 0.0; 0087 settings.exposition = m_customRawSettings.exposureComp; 0088 settings.gamma = 1.0; 0089 settings.saturation = m_customRawSettings.saturation; 0090 settings.green = 1.0; 0091 WBFilter wb(&m_orgImage, 0L, settings); 0092 wb.startFilterDirectly(); 0093 m_orgImage.putImageData(wb.getTargetImage().bits()); 0094 } 0095 0096 postProgress(40); 0097 0098 if ((m_customRawSettings.lightness != 0.0) || (m_customRawSettings.contrast != 1.0) || (m_customRawSettings.gamma != 1.0)) 0099 { 0100 BCGContainer settings; 0101 settings.brightness = m_customRawSettings.lightness; 0102 settings.contrast = m_customRawSettings.contrast; 0103 settings.gamma = m_customRawSettings.gamma; 0104 BCGFilter bcg(&m_orgImage, 0L, settings); 0105 bcg.startFilterDirectly(); 0106 m_orgImage.putImageData(bcg.getTargetImage().bits()); 0107 } 0108 0109 postProgress(60); 0110 0111 if (!m_customRawSettings.curveAdjust.isEmpty()) 0112 { 0113 CurvesContainer prm(ImageCurves::CURVE_SMOOTH, m_orgImage.sixteenBit()); 0114 prm.values[LuminosityChannel] = m_customRawSettings.curveAdjust; 0115 CurvesFilter curves(&m_orgImage, 0L, prm); 0116 curves.startFilterDirectly(); 0117 m_orgImage.putImageData(curves.getTargetImage().bits()); 0118 } 0119 0120 postProgress(80); 0121 0122 m_destImage = m_orgImage; 0123 0124 postProgress(100); 0125 } 0126 0127 } // namespace DigikamRawImportNativePlugin