diff --git a/core/app/main/main.cpp b/core/app/main/main.cpp index f4f1c2aeef..fa97d74259 100644 --- a/core/app/main/main.cpp +++ b/core/app/main/main.cpp @@ -1,354 +1,354 @@ /* ============================================================ * * This file is a part of digiKam project * https://www.digikam.org * * Date : 2002-07-28 * Description : main program from digiKam * * Copyright (C) 2002-2006 by Renchi Raju * Copyright (C) 2002-2020 by Gilles Caulier * * This program is free software; you can redistribute it * and/or modify it under the terms of the GNU General * Public License as published by the Free Software Foundation; * either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * ============================================================ */ #include "digikam_config.h" -// ImageMagick includes - -#if defined(Q_CC_CLANG) -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wkeyword-macro" -#endif - -#ifdef HAVE_IMAGE_MAGICK -# include -using namespace Magick; -#endif - -#if defined(Q_CC_CLANG) -# pragma clang diagnostic pop -#endif - // Qt includes #include #include #include #include #include #include #include #include #include #include #include // KDE includes #include #include #include #include +// ImageMagick includes + +#if defined(Q_CC_CLANG) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wkeyword-macro" +#endif + +#ifdef HAVE_IMAGE_MAGICK +# include +using namespace Magick; +#endif + +#if defined(Q_CC_CLANG) +# pragma clang diagnostic pop +#endif + // Local includes #include "digikam_debug.h" #include "digikam_version.h" #include "digikam_globals.h" #include "metaengine.h" #include "dmessagebox.h" #include "albummanager.h" #include "firstrundlg.h" #include "collectionlocation.h" #include "collectionmanager.h" #include "daboutdata.h" #include "dbengineparameters.h" #include "digikamapp.h" #include "scancontroller.h" #include "coredbaccess.h" #include "thumbsdbaccess.h" #include "facedbaccess.h" #include "dxmlguiwindow.h" #include "applicationsettings.h" #include "similaritydbaccess.h" #include "databaseserverstarter.h" #ifdef Q_OS_WIN # include # include # include #endif using namespace Digikam; int main(int argc, char* argv[]) { QApplication app(argc, argv); tryInitDrMingw(); #ifdef HAVE_IMAGE_MAGICK InitializeMagick(nullptr); #endif #ifdef Q_OS_LINUX app.setAttribute(Qt::AA_UseHighDpiPixmaps, true); #endif #ifdef HAVE_QWEBENGINE app.setAttribute(Qt::AA_ShareOpenGLContexts, true); #endif // if we have some local breeze icon resource, prefer it DXmlGuiWindow::setupIconTheme(); KLocalizedString::setApplicationDomain("digikam"); KAboutData aboutData(QLatin1String("digikam"), // component name i18n("digiKam"), // display name digiKamVersion()); aboutData.setShortDescription(QString::fromUtf8("%1 - %2").arg(DAboutData::digiKamSlogan()).arg(DAboutData::digiKamFamily())); aboutData.setLicense(KAboutLicense::GPL); aboutData.setCopyrightStatement(DAboutData::copyright()); aboutData.setOtherText(additionalInformation()); aboutData.setHomepage(DAboutData::webProjectUrl().url()); DAboutData::authorsRegistration(aboutData); QCommandLineParser parser; KAboutData::setApplicationData(aboutData); parser.addVersionOption(); parser.addHelpOption(); aboutData.setupCommandLine(&parser); parser.addOption(QCommandLineOption(QStringList() << QLatin1String("download-from"), i18n("Open camera dialog at "), QLatin1String("path"))); parser.addOption(QCommandLineOption(QStringList() << QLatin1String("download-from-udi"), i18n("Open camera dialog for the device with Solid UDI "), QLatin1String("udi"))); parser.addOption(QCommandLineOption(QStringList() << QLatin1String("detect-camera"), i18n("Automatically detect and open a connected gphoto2 camera"))); parser.addOption(QCommandLineOption(QStringList() << QLatin1String("database-directory"), i18n("Start digikam with the SQLite database file found in the directory "), QLatin1String("dir"))); parser.addOption(QCommandLineOption(QStringList() << QLatin1String("config"), i18n("Start digikam with the configuration file "), QLatin1String("config"))); parser.process(app); aboutData.processCommandLine(&parser); MetaEngine::initializeExiv2(); // Force to use application icon for non plasma desktop as Unity for ex. QApplication::setWindowIcon(QIcon::fromTheme(QLatin1String("digikam"), app.windowIcon())); // Check if Qt database plugins are available. if (!QSqlDatabase::isDriverAvailable(DbEngineParameters::SQLiteDatabaseType()) && !QSqlDatabase::isDriverAvailable(DbEngineParameters::MySQLDatabaseType())) { if (QSqlDatabase::drivers().isEmpty()) { QMessageBox::critical(qApp->activeWindow(), qApp->applicationName(), i18n("Run-time Qt SQLite or MySQL database plugin is not available. " "please install it.\n" "There is no database plugin installed on your computer.")); } else { DMessageBox::showInformationList(QMessageBox::Warning, qApp->activeWindow(), qApp->applicationName(), i18n("Run-time Qt SQLite or MySQL database plugin are not available. " "Please install it.\n" "Database plugins installed on your computer are listed below."), QSqlDatabase::drivers()); } qCDebug(DIGIKAM_GENERAL_LOG) << "QT Sql drivers list: " << QSqlDatabase::drivers(); return 1; } QString commandLineDBPath; if (parser.isSet(QLatin1String("database-directory"))) { QDir commandLineDBDir(parser.value(QLatin1String("database-directory"))); if (!commandLineDBDir.exists()) { qCDebug(DIGIKAM_GENERAL_LOG) << "The given database-directory does not exist or is not readable. Ignoring." << commandLineDBDir.path(); } else { commandLineDBPath = commandLineDBDir.path(); } } if (parser.isSet(QLatin1String("config"))) { QString configFilename = parser.value(QLatin1String("config")); QFileInfo configFile(configFilename); if (configFile.isDir() || !configFile.dir().exists() || !configFile.isReadable() || !configFile.isWritable()) { QMessageBox::critical(qApp->activeWindow(), qApp->applicationName(), QLatin1String("--config ") + configFilename + i18n("

The given path for the config file " "is not valid. Either its parent " "directory does not exist, it is a " "directory itself or it cannot be read/" "written to.

")); qCDebug(DIGIKAM_GENERAL_LOG) << "Invalid path: --config" << configFilename; return 1; } } KSharedConfig::Ptr config = KSharedConfig::openConfig(); KConfigGroup group = config->group(QLatin1String("General Settings")); QString version = group.readEntry(QLatin1String("Version"), QString()); QString iconTheme = group.readEntry(QLatin1String("Icon Theme"), QString()); KConfigGroup mainConfig = config->group(QLatin1String("Album Settings")); QString firstAlbumPath; DbEngineParameters params; // Run the first run assistant if we have no or very old config if (!mainConfig.exists() || (version.startsWith(QLatin1String("0.5")))) { FirstRunDlg firstRun; firstRun.show(); if (firstRun.exec() == QDialog::Rejected) { return 1; } // parameters are written to config firstAlbumPath = firstRun.firstAlbumPath(); if (firstRun.getDbEngineParameters().isSQLite()) { AlbumManager::checkDatabaseDirsAfterFirstRun(firstRun.getDbEngineParameters().getCoreDatabaseNameOrDir(), firstAlbumPath); } } if (!commandLineDBPath.isNull()) { // command line option set? params = DbEngineParameters::parametersForSQLiteDefaultFile(commandLineDBPath); ApplicationSettings::instance()->setDatabaseDirSetAtCmd(true); ApplicationSettings::instance()->setDbEngineParameters(params); } else { params = DbEngineParameters::parametersFromConfig(); params.legacyAndDefaultChecks(firstAlbumPath); // sync to config, for all first-run or upgrade situations params.writeToConfig(); ApplicationSettings::instance()->setDbEngineParameters(params); } // initialize database if (!AlbumManager::instance()->setDatabase(params, !commandLineDBPath.isNull(), firstAlbumPath)) { DatabaseServerStarter::instance()->stopServerManagerProcess(); AlbumManager::instance()->removeFakeConnection(); CoreDbAccess::cleanUpDatabase(); ThumbsDbAccess::cleanUpDatabase(); FaceDbAccess::cleanUpDatabase(); SimilarityDbAccess::cleanUpDatabase(); MetaEngine::cleanupExiv2(); return 0; } if (!iconTheme.isEmpty()) { QIcon::setThemeName(iconTheme); } #ifdef Q_OS_WIN // Necessary to open native open with dialog on windows CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); #endif // create main window DigikamApp* const digikam = new DigikamApp(); // If application storage place in home directory to save customized XML settings files do not exist, create it, // else QFile will not able to create new files as well. if (!QFile::exists(QStandardPaths::writableLocation(QStandardPaths::DataLocation))) { QDir().mkpath(QStandardPaths::writableLocation(QStandardPaths::DataLocation)); } // If application cache place in home directory to save cached files do not exist, create it. if (!QFile::exists(QStandardPaths::writableLocation(QStandardPaths::CacheLocation))) { QDir().mkpath(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)); } // Bug #247175: // Add a connection to the destroyed() signal when the digiKam mainwindow has been // closed. This should prevent digiKam from staying open in the background. // // Right now this is the easiest and cleanest fix for the described problem, but we might re-think the // solution later on, just in case there are better ways to do it. QObject::connect(digikam, SIGNAL(destroyed(QObject*)), &app, SLOT(quit())); digikam->restoreSession(); digikam->show(); if (parser.isSet(QLatin1String("download-from"))) { digikam->downloadFrom(parser.value(QLatin1String("download-from"))); } else if (parser.isSet(QLatin1String("download-from-udi"))) { digikam->downloadFromUdi(parser.value(QLatin1String("download-from-udi"))); } else if (parser.isSet(QLatin1String("detect-camera"))) { digikam->autoDetect(); } int ret = app.exec(); CoreDbAccess::cleanUpDatabase(); ThumbsDbAccess::cleanUpDatabase(); FaceDbAccess::cleanUpDatabase(); SimilarityDbAccess::cleanUpDatabase(); MetaEngine::cleanupExiv2(); #ifdef Q_OS_WIN // Necessary to open native open with dialog on windows CoUninitialize(); #endif #ifdef HAVE_IMAGE_MAGICK # if MagickLibVersion >= 0x693 TerminateMagick(); # endif #endif return ret; } diff --git a/core/dplugins/dimg/imagemagick/dimgimagemagickplugin.cpp b/core/dplugins/dimg/imagemagick/dimgimagemagickplugin.cpp index f808798b9c..7c4055e9ee 100644 --- a/core/dplugins/dimg/imagemagick/dimgimagemagickplugin.cpp +++ b/core/dplugins/dimg/imagemagick/dimgimagemagickplugin.cpp @@ -1,311 +1,311 @@ /* ============================================================ * * This file is a part of digiKam project * https://www.digikam.org * * Date : 2019-09-21 * Description : ImageMagick DImg plugin. * * Copyright (C) 2020 by Gilles Caulier * * This program is free software; you can redistribute it * and/or modify it under the terms of the GNU General * Public License as published by the Free Software Foundation; * either version 2, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * ============================================================ */ #include "dimgimagemagickplugin.h" +// Qt includes + +#include + +// KDE includes + +#include + // Image Magick includes #if defined(Q_CC_CLANG) # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wkeyword-macro" #endif #include #if MagickLibVersion < 0x700 # include #endif using namespace Magick; using namespace MagickCore; #if defined(Q_CC_CLANG) # pragma clang diagnostic pop #endif -// Qt includes - -#include - -// KDE includes - -#include - // Local includes #include "digikam_debug.h" #include "digikam_globals.h" #include "dimgimagemagickloader.h" namespace DigikamImageMagickDImgPlugin { DImgImageMagickPlugin::DImgImageMagickPlugin(QObject* const parent) : DPluginDImg(parent) { MagickCoreGenesis((char*)NULL ,MagickFalse); } DImgImageMagickPlugin::~DImgImageMagickPlugin() { } void DImgImageMagickPlugin::cleanUp() { MagickCoreTerminus(); } QString DImgImageMagickPlugin::name() const { return i18n("ImageMagick loader"); } QString DImgImageMagickPlugin::iid() const { return QLatin1String(DPLUGIN_IID); } QIcon DImgImageMagickPlugin::icon() const { return QIcon::fromTheme(QLatin1String("image-x-generic")); } QString DImgImageMagickPlugin::description() const { return i18n("An image loader based on ImageMagick coders"); } QString DImgImageMagickPlugin::details() const { return i18n("

This plugin permit to load and save image using ImageMagick coders.

" "

ImageMagick is a free and open-source software suite for converting raster image and vector image files. " "It can read and write over 200 image file formats.

" "

See ImageMagick documentation for details.

" ); } QList DImgImageMagickPlugin::authors() const { return QList() << DPluginAuthor(QString::fromUtf8("Maik Qualmann"), QString::fromUtf8("metzpinguin at gmail dot com"), QString::fromUtf8("(C) 2019")) << DPluginAuthor(QString::fromUtf8("Gilles Caulier"), QString::fromUtf8("caulier dot gilles at gmail dot com"), QString::fromUtf8("(C) 2006-2019")) ; } void DImgImageMagickPlugin::setup(QObject* const /*parent*/) { // Nothing to do } QMap DImgImageMagickPlugin::extraAboutData() const { QString mimes = typeMimes(); QMap map; ExceptionInfo ex = *AcquireExceptionInfo(); size_t n = 0; const MagickInfo** inflst = GetMagickInfoList("*", &n, &ex); if (!inflst) { qWarning() << "ImageMagick coders list is null!"; return QMap(); } for (uint i = 0 ; i < n ; ++i) { const MagickInfo* inf = inflst[i]; if (inf) { QString mod = #if (MagickLibVersion >= 0x69A && defined(magick_module)) QString::fromLatin1(inf->magick_module).toUpper(); #else QString::fromLatin1(inf->module).toUpper(); #endif if (mimes.contains(mod)) { map.insert(mod, QLatin1String(inf->description)); } } } free(inflst); return map; } QString DImgImageMagickPlugin::loaderName() const { return QLatin1String("IMAGEMAGICK"); } QString DImgImageMagickPlugin::typeMimes() const { QStringList formats = decoderFormats(); formats.sort(); QString ret; foreach (const QString& str, formats) { if (!ret.contains(str)) { ret += QString::fromUtf8("%1 ").arg(str.toUpper()); } } return ret; } int DImgImageMagickPlugin::canRead(const QFileInfo& fileInfo, bool magic) const { QString filePath = fileInfo.filePath(); QString format = fileInfo.suffix().toUpper(); if (!magic) { QString mimeType(QMimeDatabase().mimeTypeForFile(filePath).name()); // Ignore non image format. if ( mimeType.startsWith(QLatin1String("video/")) || mimeType.startsWith(QLatin1String("audio/")) ) { return 0; } if (decoderFormats().contains(format)) { if (format == QLatin1String("WEBP")) { return 70; } else { return 90; } } } return 0; } int DImgImageMagickPlugin::canWrite(const QString& format) const { QStringList formats; ExceptionInfo ex = *AcquireExceptionInfo(); size_t n = 0; const MagickInfo** inflst = GetMagickInfoList("*", &n, &ex); if (!inflst) { qWarning() << "ImageMagick coders list is null!"; return 0; } for (uint i = 0 ; i < n ; ++i) { const MagickInfo* inf = inflst[i]; if (inf && inf->encoder) { #if (MagickLibVersion >= 0x69A && defined(magick_module)) formats.append(QString::fromLatin1(inf->magick_module).toUpper()); #else formats.append(QString::fromLatin1(inf->module).toUpper()); #endif } } free(inflst); if (formats.contains(format.toUpper())) { if (format.toUpper() == QLatin1String("WEBP")) { return 70; } else { return 90; } } return 0; } DImgLoader* DImgImageMagickPlugin::loader(DImg* const image, const DRawDecoding&) const { return new DImgImageMagickLoader(image); } QStringList DImgImageMagickPlugin::decoderFormats() const { QStringList formats; ExceptionInfo ex = *AcquireExceptionInfo(); size_t n = 0; const MagickInfo** inflst = GetMagickInfoList("*", &n, &ex); if (!inflst) { qWarning() << "ImageMagick coders list is null!"; return formats; } for (uint i = 0 ; i < n ; ++i) { const MagickInfo* inf = inflst[i]; if (inf && inf->decoder) { #if (MagickLibVersion >= 0x69A && defined(magick_module)) formats.append(QString::fromLatin1(inf->magick_module).toUpper()); #else formats.append(QString::fromLatin1(inf->module).toUpper()); #endif } } if (formats.contains(QLatin1String("JPEG"))) { formats.append(QLatin1String("JPG")); formats.append(QLatin1String("JPE")); } // Remove known formats that are not stable. formats.removeAll(QLatin1String("XCF")); free(inflst); return formats; } } // namespace DigikamImageMagickDImgPlugin diff --git a/core/showfoto/main/main.cpp b/core/showfoto/main/main.cpp index efa30f8996..ee9c48f508 100644 --- a/core/showfoto/main/main.cpp +++ b/core/showfoto/main/main.cpp @@ -1,184 +1,184 @@ /* ============================================================ * * This file is a part of digiKam project * https://www.digikam.org * * Date : 2004-11-22 * Description : showFoto is a stand alone version of image * editor with no support of digiKam database. * * Copyright (C) 2004-2005 by Renchi Raju * Copyright (C) 2004-2020 by Gilles Caulier * * This program is free software; you can redistribute it * and/or modify it under the terms of the GNU General * Public License as published by the Free Software Foundation; * either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * ============================================================ */ #include "digikam_config.h" -// ImageMagick includes - -#if defined(Q_CC_CLANG) -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wkeyword-macro" -#endif - -#ifdef HAVE_IMAGE_MAGICK -# include -using namespace Magick; -#endif - -#if defined(Q_CC_CLANG) -# pragma clang diagnostic pop -#endif - // Qt includes #include #include #include #include #include #include // KDE includes #include #include #include #include +// ImageMagick includes + +#if defined(Q_CC_CLANG) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wkeyword-macro" +#endif + +#ifdef HAVE_IMAGE_MAGICK +# include +using namespace Magick; +#endif + +#if defined(Q_CC_CLANG) +# pragma clang diagnostic pop +#endif + // Local includes #include "digikam_debug.h" #include "digikam_globals.h" #include "digikam_version.h" #include "metaengine.h" #include "daboutdata.h" #include "showfoto.h" #ifdef Q_OS_WIN # include # include # include #endif using namespace Digikam; int main(int argc, char* argv[]) { QApplication app(argc, argv); tryInitDrMingw(); #ifdef HAVE_IMAGE_MAGICK InitializeMagick(nullptr); #endif #ifdef Q_OS_LINUX app.setAttribute(Qt::AA_UseHighDpiPixmaps, true); #endif #ifdef HAVE_QWEBENGINE app.setAttribute(Qt::AA_ShareOpenGLContexts, true); #endif // if we have some local breeze icon resource, prefer it DXmlGuiWindow::setupIconTheme(); KLocalizedString::setApplicationDomain("digikam"); KAboutData aboutData(QLatin1String("showfoto"), // component name i18n("Showfoto"), // display name digiKamVersion()); // NOTE: showFoto version = digiKam version aboutData.setShortDescription(QString::fromUtf8("%1 - %2").arg(DAboutData::digiKamSlogan()).arg(DAboutData::digiKamFamily())); aboutData.setLicense(KAboutLicense::GPL); aboutData.setCopyrightStatement(DAboutData::copyright()); aboutData.setOtherText(additionalInformation()); aboutData.setHomepage(DAboutData::webProjectUrl().url()); aboutData.setProductName(QByteArray("digikam/showfoto")); // For bugzilla DAboutData::authorsRegistration(aboutData); QCommandLineParser parser; KAboutData::setApplicationData(aboutData); parser.addVersionOption(); parser.addHelpOption(); aboutData.setupCommandLine(&parser); parser.addPositionalArgument(QLatin1String("files"), i18n("File(s) or folder(s) to open"), QLatin1String("[file(s) or folder(s)]")); parser.process(app); aboutData.processCommandLine(&parser); KSharedConfig::Ptr config = KSharedConfig::openConfig(); KConfigGroup group = config->group(QLatin1String("ImageViewer Settings")); QString iconTheme = group.readEntry(QLatin1String("Icon Theme"), QString()); MetaEngine::initializeExiv2(); // Force to use application icon for non plasma desktop as Unity for ex. QApplication::setWindowIcon(QIcon::fromTheme(QLatin1String("showfoto"), app.windowIcon())); QList urlList; QStringList urls = parser.positionalArguments(); foreach (const QString& url, urls) { urlList.append(QUrl::fromLocalFile(url)); } parser.clearPositionalArguments(); if (!iconTheme.isEmpty()) { QIcon::setThemeName(iconTheme); } #ifdef Q_OS_WIN // Necessary to open native open with dialog on windows CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); #endif ShowFoto::ShowFoto* const w = new ShowFoto::ShowFoto(urlList); // If application storage place in home directory to save customized XML settings files do not exist, create it, // else QFile will not able to create new files as well. if (!QFile::exists(QStandardPaths::writableLocation(QStandardPaths::DataLocation))) { QDir().mkpath(QStandardPaths::writableLocation(QStandardPaths::DataLocation)); } // If application cache place in home directory to save cached files do not exist, create it. if (!QFile::exists(QStandardPaths::writableLocation(QStandardPaths::CacheLocation))) { QDir().mkpath(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)); } w->show(); int ret = app.exec(); MetaEngine::cleanupExiv2(); #ifdef Q_OS_WIN // Necessary to open native open with dialog on windows CoUninitialize(); #endif #ifdef HAVE_IMAGE_MAGICK # if MagickLibVersion >= 0x693 TerminateMagick(); # endif #endif return ret; } diff --git a/core/tests/dimg/magickloader.cpp b/core/tests/dimg/magickloader.cpp index 6a3f200828..32cbad4495 100644 --- a/core/tests/dimg/magickloader.cpp +++ b/core/tests/dimg/magickloader.cpp @@ -1,230 +1,230 @@ /* ============================================================ * * This file is a part of digiKam project * https://www.digikam.org * * Date : 2017-09-24 * Description : Test ImageMagick loader to QImage. * * Copyright (C) 2020 by Gilles Caulier * * This program is free software; you can redistribute it * and/or modify it under the terms of the GNU General * Public License as published by the Free Software Foundation; * either version 2, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * ============================================================ */ -// ImageMagick includes - -#include - -#if MagickLibVersion < 0x700 -# include -#endif - -using namespace Magick; -using namespace MagickCore; - // Qt includes #include #include #include #include #include #include #include #include #include #include #include +// ImageMagick includes + +#include + +#if MagickLibVersion < 0x700 +# include +#endif + +using namespace Magick; +using namespace MagickCore; + /** Convert from QImage to IM::Image */ /*Image* toImage(QImage* const qimage) { qDebug() << "toImage:" << qimage->width() << qimage->height(); Image* const newImage = new Image(Magick::Geometry(qimage->width(), qimage->height()), Magick::ColorRGB(0.5, 0.2, 0.3)); newImage->modifyImage(); double scale = 1 / 256.0; Magick::Quantum* pixels = 0; Magick::ColorRGB mgc; for (int y = 0 ; y < qimage->height() ; ++y) { pixels = newImage->setPixels(0, y, newImage->columns(), 1); for (int x = 0 ; x < qimage->width() ; ++x) { QColor pix = qimage->pixel(x, y); mgc.red (scale * pix.red()); mgc.green(scale * pix.green()); mgc.blue (scale * pix.blue()); *pixels++ = mgc; } newImage->syncPixels(); } return newImage; } */ /** Convert pixel from IM::Image to QImage. */ // -- ImageMagick codecs to QImage -------------------------------------------------------- bool loadWithImageMagick(const QString& path, QImage& qimg) { qDebug() << "Try to load image with ImageMagick codecs"; try { Magick::Image image; image.read(path.toUtf8().constData()); qDebug() << "IM toQImage :" << image.columns() << image.rows(); qDebug() << "IM QuantumRange :" << QuantumRange; Blob* const pixelBlob = new Blob; image.write(pixelBlob, "BGRA", 8); qDebug() << "IM blob size :" << pixelBlob->length(); qimg = QImage((uchar*)pixelBlob->data(), image.columns(), image.rows(), QImage::Format_ARGB32); #if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) qDebug() << "QImage data size:" << qimg.sizeInBytes(); #else qDebug() << "QImage data size:" << qimg.byteCount(); #endif if (qimg.isNull()) { return false; } } catch (Exception& error_) { qWarning() << "Cannot load [" << path << "] due to ImageMagick exception:" << error_.what(); qimg = QImage(); return false; } return true; } // --------------------------------------------------------------------------------------------------- int main(int argc, char** argv) { MagickCoreGenesis((char*)NULL, MagickFalse); ExceptionInfo ex = *AcquireExceptionInfo(); size_t n = 0; const MagickInfo** inflst = GetMagickInfoList("*", &n, &ex); if (!inflst) { qWarning() << "ImageMagick coders list is null!"; return -1; } qDebug().noquote() << "Name :: Module :: Mime Type :: Mode :: Version :: Description"; for (uint i = 0 ; i < n ; ++i) { const MagickInfo* inf = inflst[i]; if (inf) { QString mode; if (inf->decoder) mode.append(QLatin1Char('R')); else mode.append(QLatin1Char('-')); if (inf->encoder) mode.append(QLatin1Char('W')); else mode.append(QLatin1Char('-')); #if (MagickLibVersion >= 0x69A && defined(magick_module)) QString mod = QLatin1String(inf->magick_module); #else QString mod = QLatin1String(inf->module); #endif QString mime = QMimeDatabase().mimeTypeForFile(QFileInfo(QString::fromLatin1("foo.%1").arg(mod))).name(); if (mod != QLatin1String("DNG") && mod != QLatin1String("JPEG") && mod != QLatin1String("PNG") && mod != QLatin1String("TIFF") && mod != QLatin1String("JP2") && mime.startsWith(QLatin1String("image/"))) { qDebug().noquote() << QString::fromLatin1("%1").arg(QLatin1String(inf->name), 16) << "::" << QString::fromLatin1("%1").arg(mod, 16) << "::" << QString::fromLatin1("%1").arg(mime, 28) << "::" << QString::fromLatin1("%1").arg(mode, 5) << "::" << QString::fromLatin1("%1").arg(QLatin1String(inf->version), 28) << "::" << QString::fromLatin1("%1").arg(QLatin1String(inf->description), 64); } } } QApplication app(argc, argv); QStringList list; if (argc <= 1) { list = QFileDialog::getOpenFileNames(nullptr, QString::fromLatin1("Select Image Files to Load"), QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).first(), QLatin1String("Image Files (*.png *.jpg *.tif *.bmp *.gif *.xcf *.kra *.psd)")); } else { for (int i = 1 ; i < argc ; ++i) { list.append(QString::fromLocal8Bit(argv[i])); } } qDebug() << "Files to load:" << list; if (!list.isEmpty()) { foreach (const QString& path, list) { QImage qimg; bool ret = loadWithImageMagick(path, qimg); if (ret) { QLabel* const lbl = new QLabel; lbl->setPixmap(QPixmap::fromImage(qimg.scaled(512, 512, Qt::KeepAspectRatio))); lbl->show(); } else { qWarning() << "exit -1"; MagickCoreTerminus(); return -1; } } app.exec(); } free(inflst); MagickCoreTerminus(); return 0; }