diff options
Diffstat (limited to 'src/gui/image/qimagereaderwriterhelpers.cpp')
-rw-r--r-- | src/gui/image/qimagereaderwriterhelpers.cpp | 66 |
1 files changed, 16 insertions, 50 deletions
diff --git a/src/gui/image/qimagereaderwriterhelpers.cpp b/src/gui/image/qimagereaderwriterhelpers.cpp index ef47fe15d0..502b0f95f0 100644 --- a/src/gui/image/qimagereaderwriterhelpers.cpp +++ b/src/gui/image/qimagereaderwriterhelpers.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2018 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "private/qimagereaderwriterhelpers_p.h" @@ -51,9 +15,9 @@ namespace QImageReaderWriterHelpers { #ifndef QT_NO_IMAGEFORMATPLUGIN -Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader, +Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, irhLoader, (QImageIOHandlerFactoryInterface_iid, "/imageformats"_L1)) -Q_GLOBAL_STATIC(QMutex, loaderMutex) +Q_GLOBAL_STATIC(QMutex, irhLoaderMutex) static void appendImagePluginFormats(QFactoryLoader *loader, QImageIOPlugin::Capability cap, @@ -104,9 +68,9 @@ static void appendImagePluginMimeTypes(QFactoryLoader *loader, QSharedPointer<QFactoryLoader> pluginLoader() { - loaderMutex()->lock(); - return QSharedPointer<QFactoryLoader>(loader(), [](QFactoryLoader *) { - loaderMutex()->unlock(); + irhLoaderMutex()->lock(); + return QSharedPointer<QFactoryLoader>(irhLoader(), [](QFactoryLoader *) { + irhLoaderMutex()->unlock(); }); } @@ -125,7 +89,7 @@ QList<QByteArray> supportedImageFormats(Capability cap) formats << _qt_BuiltInFormats[i].extension; #ifndef QT_NO_IMAGEFORMATPLUGIN - appendImagePluginFormats(loader(), pluginCapability(cap), &formats); + appendImagePluginFormats(irhLoader(), pluginCapability(cap), &formats); #endif // QT_NO_IMAGEFORMATPLUGIN std::sort(formats.begin(), formats.end()); @@ -133,15 +97,17 @@ QList<QByteArray> supportedImageFormats(Capability cap) return formats; } +static constexpr QByteArrayView imagePrefix() noexcept { return "image/"; } + QList<QByteArray> supportedMimeTypes(Capability cap) { QList<QByteArray> mimeTypes; mimeTypes.reserve(_qt_NumFormats); for (const auto &fmt : _qt_BuiltInFormats) - mimeTypes.append(QByteArrayLiteral("image/") + fmt.mimeType); + mimeTypes.emplace_back(imagePrefix() + fmt.mimeType); #ifndef QT_NO_IMAGEFORMATPLUGIN - appendImagePluginMimeTypes(loader(), pluginCapability(cap), &mimeTypes); + appendImagePluginMimeTypes(irhLoader(), pluginCapability(cap), &mimeTypes); #endif // QT_NO_IMAGEFORMATPLUGIN std::sort(mimeTypes.begin(), mimeTypes.end()); @@ -149,11 +115,11 @@ QList<QByteArray> supportedMimeTypes(Capability cap) return mimeTypes; } -QList<QByteArray> imageFormatsForMimeType(const QByteArray &mimeType, Capability cap) +QList<QByteArray> imageFormatsForMimeType(QByteArrayView mimeType, Capability cap) { QList<QByteArray> formats; - if (mimeType.startsWith("image/")) { - const QByteArray type = mimeType.mid(sizeof("image/") - 1); + if (mimeType.startsWith(imagePrefix())) { + const QByteArrayView type = mimeType.mid(imagePrefix().size()); for (const auto &fmt : _qt_BuiltInFormats) { if (fmt.mimeType == type && !formats.contains(fmt.extension)) formats << fmt.extension; @@ -163,7 +129,7 @@ QList<QByteArray> imageFormatsForMimeType(const QByteArray &mimeType, Capability #ifndef QT_NO_IMAGEFORMATPLUGIN QList<QByteArray> mimeTypes; QList<QByteArray> keys; - appendImagePluginMimeTypes(loader(), pluginCapability(cap), &mimeTypes, &keys); + appendImagePluginMimeTypes(irhLoader(), pluginCapability(cap), &mimeTypes, &keys); for (int i = 0; i < mimeTypes.size(); ++i) { if (mimeTypes.at(i) == mimeType) { const auto &key = keys.at(i); |