diff options
Diffstat (limited to 'src/gui/image/qbitmap.cpp')
-rw-r--r-- | src/gui/image/qbitmap.cpp | 175 |
1 files changed, 79 insertions, 96 deletions
diff --git a/src/gui/image/qbitmap.cpp b/src/gui/image/qbitmap.cpp index 88af4073c8..2208cca1be 100644 --- a/src/gui/image/qbitmap.cpp +++ b/src/gui/image/qbitmap.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 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) 2016 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 "qbitmap.h" #include <qpa/qplatformpixmap.h> @@ -46,6 +10,8 @@ #include <qpainter.h> #include <private/qguiapplication_p.h> +#include <memory> + QT_BEGIN_NAMESPACE /*! @@ -114,44 +80,36 @@ QBitmap::QBitmap() \sa clear() */ - QBitmap::QBitmap(int w, int h) : QPixmap(QSize(w, h), QPlatformPixmap::BitmapType) { } /*! + \deprecated [6.0] Use fromPixmap instead. + Constructs a bitmap with the given \a size. The pixels in the bitmap are uninitialized. \sa clear() */ - QBitmap::QBitmap(const QSize &size) : QPixmap(size, QPlatformPixmap::BitmapType) { } /*! - \fn QBitmap::clear() - - Clears the bitmap, setting all its bits to Qt::color0. + \internal + This dtor must stay empty until Qt 7 (was inline until 6.2). */ +QBitmap::~QBitmap() = default; /*! - Constructs a bitmap that is a copy of the given \a pixmap. - - If the pixmap has a depth greater than 1, the resulting bitmap - will be dithered automatically. + \fn QBitmap::clear() - \sa QPixmap::depth(), fromImage(), fromData() + Clears the bitmap, setting all its bits to Qt::color0. */ -QBitmap::QBitmap(const QPixmap &pixmap) -{ - QBitmap::operator=(pixmap); -} - /*! Constructs a bitmap from the file specified by the given \a fileName. If the file does not exist, or has an unknown format, @@ -163,7 +121,6 @@ QBitmap::QBitmap(const QPixmap &pixmap) \sa QPixmap::isNull(), QImageReader::imageFormat() */ - QBitmap::QBitmap(const QString& fileName, const char *format) : QPixmap(QSize(0, 0), QPlatformPixmap::BitmapType) { @@ -171,41 +128,6 @@ QBitmap::QBitmap(const QString& fileName, const char *format) } /*! - \overload - - Assigns the given \a pixmap to this bitmap and returns a reference - to this bitmap. - - If the pixmap has a depth greater than 1, the resulting bitmap - will be dithered automatically. - - \sa QPixmap::depth() - */ - -QBitmap &QBitmap::operator=(const QPixmap &pixmap) -{ - if (pixmap.isNull()) { // a null pixmap - QBitmap(0, 0).swap(*this); - } else if (pixmap.depth() == 1) { // 1-bit pixmap - QPixmap::operator=(pixmap); // shallow assignment - } else { // n-bit depth pixmap - *this = fromImage(pixmap.toImage()); // will dither image - } - return *this; -} - -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) - -/*! - Destroys the bitmap. -*/ -QBitmap::~QBitmap() -{ -} - -#endif - -/*! \fn void QBitmap::swap(QBitmap &other) \since 4.8 @@ -218,7 +140,7 @@ QBitmap::~QBitmap() */ QBitmap::operator QVariant() const { - return QVariant(QMetaType::QBitmap, this); + return QVariant::fromValue(*this); } static QBitmap makeBitmap(QImage &&image, Qt::ImageConversionFlags flags) @@ -233,10 +155,10 @@ static QBitmap makeBitmap(QImage &&image, Qt::ImageConversionFlags flags) image.setColor(1, c0); } - QScopedPointer<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::BitmapType)); + std::unique_ptr<QPlatformPixmap> data(QGuiApplicationPrivate::platformIntegration()->createPlatformPixmap(QPlatformPixmap::BitmapType)); data->fromImageInPlace(image, flags | Qt::MonoOnly); - return QPixmap(data.take()); + return QBitmap::fromPixmap(QPixmap(data.release())); } /*! @@ -274,7 +196,7 @@ QBitmap QBitmap::fromImage(QImage &&image, Qt::ImageConversionFlags flags) Constructs a bitmap with the given \a size, and sets the contents to the \a bits supplied. - The bitmap data has to be byte aligned and provided in in the bit + The bitmap data has to be byte aligned and provided in the bit order specified by \a monoFormat. The mono format must be either QImage::Format_Mono or QImage::Format_MonoLSB. Use QImage::Format_Mono to specify data on the XBM format. @@ -290,7 +212,7 @@ QBitmap QBitmap::fromData(const QSize &size, const uchar *bits, QImage::Format m image.setColor(0, QColor(Qt::color0).rgb()); image.setColor(1, QColor(Qt::color1).rgb()); - // Need to memcpy each line separatly since QImage is 32bit aligned and + // Need to memcpy each line separately since QImage is 32bit aligned and // this data is only byte aligned... int bytesPerLine = (size.width() + 7) / 8; for (int y = 0; y < size.height(); ++y) @@ -299,6 +221,68 @@ QBitmap QBitmap::fromData(const QSize &size, const uchar *bits, QImage::Format m } /*! + Returns a copy of the given \a pixmap converted to a bitmap. + + If the pixmap has a depth greater than 1, the resulting bitmap + will be dithered automatically. + + \since 6.0 + + \sa QPixmap::depth() +*/ + +QBitmap QBitmap::fromPixmap(const QPixmap &pixmap) +{ + if (pixmap.isNull()) { // a null pixmap + return QBitmap(0, 0); + } else if (pixmap.depth() == 1) { // 1-bit pixmap + QBitmap bm; + if (pixmap.paintingActive()) { // make a deep copy + pixmap.copy().swap(bm); + } else { + bm.data = pixmap.data; // shallow assignment + } + return bm; + } + // n-bit depth pixmap, will dither image + return fromImage(pixmap.toImage()); +} + +#if QT_DEPRECATED_SINCE(6, 0) +/*! + \deprecated [6.0] Use fromPixmap instead. + Constructs a bitmap that is a copy of the given \a pixmap. + + If the pixmap has a depth greater than 1, the resulting bitmap + will be dithered automatically. + + \sa QPixmap::depth(), fromImage(), fromData() +*/ +QBitmap::QBitmap(const QPixmap &pixmap) +{ + *this = QBitmap::fromPixmap(pixmap); +} + +/*! + \deprecated [6.0] Use fromPixmap instead. + \overload + + Assigns the given \a pixmap to this bitmap and returns a reference + to this bitmap. + + If the pixmap has a depth greater than 1, the resulting bitmap + will be dithered automatically. + + \sa QPixmap::depth() + */ +QBitmap &QBitmap::operator=(const QPixmap &pixmap) +{ + *this = QBitmap::fromPixmap(pixmap); + return *this; +} +#endif + +/*! Returns a copy of this bitmap, transformed according to the given \a matrix. @@ -306,8 +290,7 @@ QBitmap QBitmap::fromData(const QSize &size, const uchar *bits, QImage::Format m */ QBitmap QBitmap::transformed(const QTransform &matrix) const { - QBitmap bm = QPixmap::transformed(matrix); - return bm; + return QBitmap::fromPixmap(QPixmap::transformed(matrix)); } QT_END_NAMESPACE |