File indexing completed on 2025-01-19 03:51:02
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2005-06-14 0007 * Description : A QImage loader for DImg framework - save method. 0008 * 0009 * SPDX-FileCopyrightText: 2005 by Renchi Raju <renchi dot raju at gmail dot com> 0010 * SPDX-FileCopyrightText: 2006-2021 by Caulier Gilles <caulier dot gilles at gmail dot com> 0011 * 0012 * SPDX-License-Identifier: GPL-2.0-or-later 0013 * 0014 * ============================================================ */ 0015 0016 #include "dimgqimageloader.h" 0017 0018 // Qt includes 0019 0020 #include <QImage> 0021 #include <QByteArray> 0022 #include <QColorSpace> 0023 #include <QImageReader> 0024 0025 // Local includes 0026 0027 #include "digikam_debug.h" 0028 #include "dimgloaderobserver.h" 0029 0030 namespace DigikamQImageDImgPlugin 0031 { 0032 0033 bool DImgQImageLoader::save(const QString& filePath, DImgLoaderObserver* const observer) 0034 { 0035 QVariant qualityAttr = imageGetAttribute(QLatin1String("quality")); 0036 int quality = qualityAttr.isValid() ? qualityAttr.toInt() : 90; 0037 0038 if (quality > 100) 0039 { 0040 quality = 100; 0041 } 0042 else if (quality < 0) 0043 { 0044 quality = 90; 0045 } 0046 0047 QVariant formatAttr = imageGetAttribute(QLatin1String("format")); 0048 QByteArray format = formatAttr.toByteArray(); 0049 QImage image = m_image->copyQImage(); 0050 QByteArray iccRawProfile = m_image->getIccProfile().data(); 0051 0052 if (!iccRawProfile.isEmpty()) 0053 { 0054 image.setColorSpace(QColorSpace::fromIccProfile(iccRawProfile)); 0055 } 0056 0057 if (observer) 0058 { 0059 observer->progressInfo(0.1F); 0060 } 0061 0062 // Saving is opaque to us. No support for stopping from observer, 0063 // progress info are only pseudo values 0064 0065 bool success = image.save(filePath, format.toUpper().constData(), quality); 0066 0067 if (observer && success) 0068 { 0069 observer->progressInfo(1.0F); 0070 } 0071 0072 imageSetAttribute(QLatin1String("format"), format.toUpper()); 0073 0074 saveMetadata(filePath); 0075 0076 return success; 0077 } 0078 0079 } // namespace DigikamQImageDImgPlugin