aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksei German <aleksei.german@qt.io>2022-03-03 16:49:33 +0100
committerAleksei German <aleksei.german@qt.io>2022-03-03 18:01:40 +0100
commitb6d541ebcb57c22606ea95c370a44660c66e7b07 (patch)
tree7024574a5178b688e66a092f07bd34cecbeb50e6
parent667651de95b8bf4c79f477424c4ade4aebb623bf (diff)
QULExtras: Remove imageChecker
Usage of the singleton is already removed from qml, seemingly nothing depends on it. Task-number: QDS-6400 Change-Id: If3a7b5ac76e174dc461bd8a8bdeef7b3ffd0baf8 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
-rw-r--r--src/imports/compatibility/QtQuickUltralite/Extras/extras.pro6
-rw-r--r--src/imports/compatibility/QtQuickUltralite/Extras/imagechecker.cpp128
-rw-r--r--src/imports/compatibility/QtQuickUltralite/Extras/imagechecker.h47
-rw-r--r--src/imports/compatibility/QtQuickUltralite/Extras/studiocompatibilityqulextras.cpp10
4 files changed, 2 insertions, 189 deletions
diff --git a/src/imports/compatibility/QtQuickUltralite/Extras/extras.pro b/src/imports/compatibility/QtQuickUltralite/Extras/extras.pro
index 6061c5b..19cc529 100644
--- a/src/imports/compatibility/QtQuickUltralite/Extras/extras.pro
+++ b/src/imports/compatibility/QtQuickUltralite/Extras/extras.pro
@@ -12,11 +12,7 @@ OTHER_FILES += \
$$QML_FILES
SOURCES += \
- $$PWD/studiocompatibilityqulextras.cpp \
- $$PWD/imagechecker.cpp
-
-HEADERS += \
- $$PWD/imagechecker.h
+ $$PWD/studiocompatibilityqulextras.cpp
!static: qtConfig(quick-designer): include(designer/designer.pri)
## include(doc/doc.pri)
diff --git a/src/imports/compatibility/QtQuickUltralite/Extras/imagechecker.cpp b/src/imports/compatibility/QtQuickUltralite/Extras/imagechecker.cpp
deleted file mode 100644
index db2ef8e..0000000
--- a/src/imports/compatibility/QtQuickUltralite/Extras/imagechecker.cpp
+++ /dev/null
@@ -1,128 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2021 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of Qt Quick Ultralite compatibility.
-**
-** $QT_BEGIN_LICENSE:GPL$
-** 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 General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 or (at your option) 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.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-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "imagechecker.h"
-
-#include <QImage>
-#include <QQmlEngine>
-#include <QQuickImageProvider>
-#include <QQmlContext>
-#include <QDebug>
-
-namespace {
-
-QRgb getDominantColor(const QImage &image)
-{
- QRgb color = 0;
- for (int y = 0; y < image.height(); ++y) {
- const auto *scanline = reinterpret_cast<const QRgb *>(image.scanLine(y));
- for (int x = 0; x < image.width(); ++x) {
- const auto c = scanline[x];
- if (qAlpha(c) > qAlpha(color))
- color = c;
- }
- }
- return qUnpremultiply(color) & 0x00ffffff;
-}
-
-bool isUsingOnlyDominantColor(const QImage &argb32, const QRgb color)
-{
- const auto compare = [](int c1, int c2) -> bool { return qAbs(c1 - c2) <= 2; };
-
- for (int y = 0; y < argb32.height(); ++y) {
- const auto *scanline = reinterpret_cast<const QRgb *>(argb32.scanLine(y));
- for (int x = 0; x < argb32.width(); ++x) {
- const auto c = scanline[x];
- const auto premul = qPremultiply(color | (qAlpha(c) << 24));
- if (!compare(qRed(c), qRed(premul)) || !compare(qGreen(c), qGreen(premul))
- || !compare(qBlue(c), qBlue(premul))) {
- return false;
- }
- }
- }
- return true;
-}
-
-bool isAlpha8(const QImage &image)
-{
- if (image.format() == QImage::Format_Alpha8) {
- return true;
- } else if (image.hasAlphaChannel()) {
- const auto argb32 = image.convertToFormat(QImage::Format_ARGB32_Premultiplied);
- const auto dominantColor = getDominantColor(argb32);
-
- return isUsingOnlyDominantColor(argb32, dominantColor);
- }
- return false;
-}
-
-} // namespace
-
-ImageChecker::ImageChecker() = default;
-
-ImageChecker *ImageChecker::getInstance()
-{
- static ImageChecker *instance = new ImageChecker;
- return instance;
-}
-
-Q_INVOKABLE bool ImageChecker::isMonochrome(const QUrl &url)
-{
- QImage image;
-
- const auto scheme = url.scheme();
-
- if (scheme == "image") {
- image = getImageFromProvider(url);
- } else if (scheme == "qrc") {
- const auto imageId = ":" + url.path();
- image.load(imageId);
- } else if (scheme == "file") {
- const auto imageId = url.path();
- image.load(imageId);
- } else {
- qDebug() << Q_FUNC_INFO << "ColorizedImage doesn't support url.scheme: " << scheme << ", for image: " << url;
- }
-
- return isAlpha8(image);
-}
-
-QImage ImageChecker::getImageFromProvider(const QUrl &url) const
-{
- const auto *engine = QQmlEngine::contextForObject(this)->engine();
- auto *imageProvider = static_cast<QQuickImageProvider *>(engine->imageProvider(url.host()));
- QSize imageActualSize;
- QSize imageRequestedSize;
- const auto imageId = url.path().remove(0, 1);
- QImage image = imageProvider->requestImage(imageId, &imageActualSize, imageRequestedSize);
- if (image.isNull()) {
- image = imageProvider->requestPixmap(imageId, &imageActualSize, imageRequestedSize).toImage();
- }
- return image;
-}
diff --git a/src/imports/compatibility/QtQuickUltralite/Extras/imagechecker.h b/src/imports/compatibility/QtQuickUltralite/Extras/imagechecker.h
deleted file mode 100644
index b2eace1..0000000
--- a/src/imports/compatibility/QtQuickUltralite/Extras/imagechecker.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2021 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of Qt Quick Ultralite compatibility.
-**
-** $QT_BEGIN_LICENSE:GPL$
-** 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 General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 or (at your option) 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.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-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#pragma once
-
-#include <QObject>
-
-class ImageChecker : public QObject
-{
- Q_OBJECT
- Q_DISABLE_COPY(ImageChecker)
-
-public:
- Q_INVOKABLE bool isMonochrome(const QUrl &imageProviderUrl);
- static ImageChecker *getInstance();
-
-private:
- ImageChecker();
-
- QImage getImageFromProvider(const QUrl &url) const;
-};
diff --git a/src/imports/compatibility/QtQuickUltralite/Extras/studiocompatibilityqulextras.cpp b/src/imports/compatibility/QtQuickUltralite/Extras/studiocompatibilityqulextras.cpp
index 60e863e..8b2804d 100644
--- a/src/imports/compatibility/QtQuickUltralite/Extras/studiocompatibilityqulextras.cpp
+++ b/src/imports/compatibility/QtQuickUltralite/Extras/studiocompatibilityqulextras.cpp
@@ -27,8 +27,6 @@
**
****************************************************************************/
-#include "imagechecker.h"
-
#include <QQmlEngine>
#include <QQmlContext>
#include <QtQml/qqmlextensionplugin.h>
@@ -50,14 +48,8 @@ StudioCompatibilityQULExtras::StudioCompatibilityQULExtras(QObject *parent)
{
}
-static QObject *imageCheckerSingletonTypeProvider(QQmlEngine *, QJSEngine *)
-{
- return ImageChecker::getInstance();
-}
-
-void StudioCompatibilityQULExtras::registerTypes(const char *uri)
+void StudioCompatibilityQULExtras::registerTypes(const char *)
{
- qmlRegisterSingletonType<ImageChecker>(uri, 1, 0, "ImageChecker", imageCheckerSingletonTypeProvider);
}
QT_END_NAMESPACE