Remove internal class QVolatileImage.
This made sense only for Symbian where there was a special CFbsBitmap-based backend present and it was used from the Symbian-specific VG and GL pixmap implementations. The generic version is merely a useless wrapper over QImage and is not in use anywhere in the codebase. Change-Id: I1dabe22dfb8cbbc35dce8e22703a3aff810fb5f9 Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com> Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com> Reviewed-by: Lars Knoll <lars.knoll@nokia.com>bb10
parent
3b80f1c4d5
commit
d87edf4e3e
|
|
@ -23,8 +23,6 @@ HEADERS += \
|
|||
image/qpixmapcache_p.h \
|
||||
image/qplatformpixmap_qpa.h \
|
||||
image/qimagepixmapcleanuphooks_p.h \
|
||||
image/qvolatileimage_p.h \
|
||||
image/qvolatileimagedata_p.h
|
||||
|
||||
SOURCES += \
|
||||
image/qbitmap.cpp \
|
||||
|
|
@ -42,13 +40,10 @@ SOURCES += \
|
|||
image/qpixmap_raster.cpp \
|
||||
image/qpixmap_blitter.cpp \
|
||||
image/qnativeimage.cpp \
|
||||
image/qimagepixmapcleanuphooks.cpp \
|
||||
image/qvolatileimage.cpp
|
||||
image/qimagepixmapcleanuphooks.cpp
|
||||
|
||||
win32: SOURCES += image/qpixmap_win.cpp
|
||||
|
||||
SOURCES += image/qvolatileimagedata.cpp
|
||||
|
||||
# Built-in image format support
|
||||
HEADERS += \
|
||||
image/qbmphandler_p.h \
|
||||
|
|
|
|||
|
|
@ -1,285 +0,0 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/
|
||||
**
|
||||
** This file is part of the QtGui module of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** GNU Lesser General Public License Usage
|
||||
** This file may be used under the terms of the GNU Lesser General Public
|
||||
** License version 2.1 as published by the Free Software Foundation and
|
||||
** appearing in the file LICENSE.LGPL included in the packaging of this
|
||||
** file. Please review the following information to ensure the GNU Lesser
|
||||
** General Public License version 2.1 requirements will be met:
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU General
|
||||
** Public License version 3.0 as published by the Free Software Foundation
|
||||
** and appearing in the file LICENSE.GPL included in the packaging of this
|
||||
** file. Please review the following information to ensure the GNU General
|
||||
** Public License version 3.0 requirements will be met:
|
||||
** http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** Other Usage
|
||||
** Alternatively, this file may be used in accordance with the terms and
|
||||
** conditions contained in a signed written agreement between you and Nokia.
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qvolatileimage_p.h"
|
||||
#include "qvolatileimagedata_p.h"
|
||||
#include <QtGui/private/qpaintengine_raster_p.h>
|
||||
#include <QtGui/qplatformpixmap_qpa.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QVolatileImagePaintEnginePrivate : public QRasterPaintEnginePrivate
|
||||
{
|
||||
public:
|
||||
QVolatileImagePaintEnginePrivate() { }
|
||||
QVolatileImage *img;
|
||||
};
|
||||
|
||||
class QVolatileImagePaintEngine : public QRasterPaintEngine
|
||||
{
|
||||
Q_DECLARE_PRIVATE(QVolatileImagePaintEngine)
|
||||
|
||||
public:
|
||||
QVolatileImagePaintEngine(QPaintDevice *device, QVolatileImage *img);
|
||||
bool begin(QPaintDevice *device);
|
||||
bool end();
|
||||
void drawPixmap(const QPointF &p, const QPixmap &pm);
|
||||
void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr);
|
||||
};
|
||||
|
||||
QVolatileImage::QVolatileImage()
|
||||
: d(new QVolatileImageData)
|
||||
{
|
||||
}
|
||||
|
||||
QVolatileImage::QVolatileImage(int w, int h, QImage::Format format)
|
||||
: d(new QVolatileImageData(w, h, format))
|
||||
{
|
||||
}
|
||||
|
||||
QVolatileImage::QVolatileImage(const QImage &sourceImage)
|
||||
: d(new QVolatileImageData(sourceImage))
|
||||
{
|
||||
}
|
||||
|
||||
QVolatileImage::QVolatileImage(void *nativeImage, void *nativeMask)
|
||||
: d(new QVolatileImageData(nativeImage, nativeMask))
|
||||
{
|
||||
}
|
||||
|
||||
// Need non-inline, non-autogenerated copy ctor, dtor, op= to keep the
|
||||
// fwd declared QSharedData working.
|
||||
|
||||
QVolatileImage::QVolatileImage(const QVolatileImage &other)
|
||||
: d(other.d)
|
||||
{
|
||||
}
|
||||
|
||||
QVolatileImage::~QVolatileImage()
|
||||
{
|
||||
}
|
||||
|
||||
QVolatileImage &QVolatileImage::operator=(const QVolatileImage &rhs)
|
||||
{
|
||||
d = rhs.d;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool QVolatileImage::isNull() const
|
||||
{
|
||||
return d->image.isNull();
|
||||
}
|
||||
|
||||
QImage::Format QVolatileImage::format() const
|
||||
{
|
||||
return d->image.format();
|
||||
}
|
||||
|
||||
int QVolatileImage::width() const
|
||||
{
|
||||
return d->image.width();
|
||||
}
|
||||
|
||||
int QVolatileImage::height() const
|
||||
{
|
||||
return d->image.height();
|
||||
}
|
||||
|
||||
int QVolatileImage::bytesPerLine() const
|
||||
{
|
||||
return d->image.bytesPerLine();
|
||||
}
|
||||
|
||||
int QVolatileImage::byteCount() const
|
||||
{
|
||||
return d->image.byteCount();
|
||||
}
|
||||
|
||||
int QVolatileImage::depth() const
|
||||
{
|
||||
return d->image.depth();
|
||||
}
|
||||
|
||||
bool QVolatileImage::hasAlphaChannel() const
|
||||
{
|
||||
return d->image.hasAlphaChannel();
|
||||
}
|
||||
|
||||
void QVolatileImage::beginDataAccess() const
|
||||
{
|
||||
d->beginDataAccess();
|
||||
}
|
||||
|
||||
void QVolatileImage::endDataAccess(bool readOnly) const
|
||||
{
|
||||
d->endDataAccess(readOnly);
|
||||
}
|
||||
|
||||
/*!
|
||||
Access to pixel data via bits() or constBits() should be guarded by
|
||||
begin/endDataAccess().
|
||||
*/
|
||||
uchar *QVolatileImage::bits()
|
||||
{
|
||||
return d->image.bits();
|
||||
}
|
||||
|
||||
const uchar *QVolatileImage::constBits() const
|
||||
{
|
||||
return d->image.constBits();
|
||||
}
|
||||
|
||||
bool QVolatileImage::ensureFormat(QImage::Format format)
|
||||
{
|
||||
return d->ensureFormat(format);
|
||||
}
|
||||
|
||||
/*!
|
||||
This will always perform a copy of the pixel data.
|
||||
*/
|
||||
QImage QVolatileImage::toImage() const
|
||||
{
|
||||
d->beginDataAccess();
|
||||
QImage newImage = d->image.copy(); // no sharing allowed
|
||||
d->endDataAccess(true);
|
||||
return newImage;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns a reference to the image that is potentially using some native
|
||||
buffer internally. Access to the image's pixel data should be guarded by
|
||||
begin/endDataAccess(). Use it when there is a need for QImage APIs not provided
|
||||
by this class. The returned QImage must never be shared or assigned to.
|
||||
*/
|
||||
QImage &QVolatileImage::imageRef() // non-const, in order to cause a detach
|
||||
{
|
||||
d->ensureImage();
|
||||
return d->image;
|
||||
}
|
||||
|
||||
void *QVolatileImage::duplicateNativeImage() const
|
||||
{
|
||||
return d->duplicateNativeImage();
|
||||
}
|
||||
|
||||
void QVolatileImage::fill(uint pixelValue)
|
||||
{
|
||||
beginDataAccess();
|
||||
imageRef().fill(pixelValue);
|
||||
endDataAccess();
|
||||
d->ensureImage();
|
||||
}
|
||||
|
||||
void QVolatileImage::copyFrom(QVolatileImage *source, const QRect &rect)
|
||||
{
|
||||
if (source->isNull()) {
|
||||
return;
|
||||
}
|
||||
QRect r = rect;
|
||||
if (rect.isNull()) {
|
||||
r = QRect(0, 0, source->width(), source->height());
|
||||
}
|
||||
source->beginDataAccess();
|
||||
QImage &srcImgRef(source->imageRef());
|
||||
int srcbpl = srcImgRef.bytesPerLine();
|
||||
int srcbpp = srcImgRef.depth() / 8;
|
||||
const uchar *sptr = srcImgRef.constBits() + r.y() * srcbpl;
|
||||
beginDataAccess();
|
||||
QImage &dstImgRef(imageRef());
|
||||
int dstbpl = dstImgRef.bytesPerLine();
|
||||
uchar *dptr = dstImgRef.bits();
|
||||
for (int y = 0; y < r.height(); ++y) {
|
||||
qMemCopy(dptr, sptr + r.x() * srcbpp, r.width() * srcbpp);
|
||||
sptr += srcbpl;
|
||||
dptr += dstbpl;
|
||||
}
|
||||
endDataAccess();
|
||||
source->endDataAccess(true);
|
||||
}
|
||||
|
||||
/*!
|
||||
To be called from the PlatformPixmap's paintEngine().
|
||||
*/
|
||||
QPaintEngine *QVolatileImage::paintEngine()
|
||||
{
|
||||
if (!d->pengine) {
|
||||
d->pengine = new QVolatileImagePaintEngine(&imageRef(), this);
|
||||
}
|
||||
return d->pengine;
|
||||
}
|
||||
|
||||
QVolatileImagePaintEngine::QVolatileImagePaintEngine(QPaintDevice *device,
|
||||
QVolatileImage *img)
|
||||
: QRasterPaintEngine(*(new QVolatileImagePaintEnginePrivate), device)
|
||||
{
|
||||
Q_D(QVolatileImagePaintEngine);
|
||||
d->img = img;
|
||||
}
|
||||
|
||||
bool QVolatileImagePaintEngine::begin(QPaintDevice *device)
|
||||
{
|
||||
Q_D(QVolatileImagePaintEngine);
|
||||
d->img->beginDataAccess();
|
||||
return QRasterPaintEngine::begin(device);
|
||||
}
|
||||
|
||||
bool QVolatileImagePaintEngine::end()
|
||||
{
|
||||
Q_D(QVolatileImagePaintEngine);
|
||||
bool ret = QRasterPaintEngine::end();
|
||||
d->img->endDataAccess();
|
||||
return ret;
|
||||
}
|
||||
|
||||
// For non-RasterClass pixmaps drawPixmap() would call toImage() which is slow in
|
||||
// our case. Therefore drawPixmap() is rerouted to drawImage().
|
||||
|
||||
void QVolatileImagePaintEngine::drawPixmap(const QPointF &p, const QPixmap &pm)
|
||||
{
|
||||
QRasterPaintEngine::drawPixmap(p, pm);
|
||||
}
|
||||
|
||||
void QVolatileImagePaintEngine::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr)
|
||||
{
|
||||
QRasterPaintEngine::drawPixmap(r, pm, sr);
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
@ -1,100 +0,0 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/
|
||||
**
|
||||
** This file is part of the QtGui module of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** GNU Lesser General Public License Usage
|
||||
** This file may be used under the terms of the GNU Lesser General Public
|
||||
** License version 2.1 as published by the Free Software Foundation and
|
||||
** appearing in the file LICENSE.LGPL included in the packaging of this
|
||||
** file. Please review the following information to ensure the GNU Lesser
|
||||
** General Public License version 2.1 requirements will be met:
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU General
|
||||
** Public License version 3.0 as published by the Free Software Foundation
|
||||
** and appearing in the file LICENSE.GPL included in the packaging of this
|
||||
** file. Please review the following information to ensure the GNU General
|
||||
** Public License version 3.0 requirements will be met:
|
||||
** http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** Other Usage
|
||||
** Alternatively, this file may be used in accordance with the terms and
|
||||
** conditions contained in a signed written agreement between you and Nokia.
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QVOLATILEIMAGE_P_H
|
||||
#define QVOLATILEIMAGE_P_H
|
||||
|
||||
//
|
||||
// W A R N I N G
|
||||
// -------------
|
||||
//
|
||||
// This file is not part of the Qt API. It exists purely as an
|
||||
// implementation detail. This header file may change from version to
|
||||
// version without notice, or even be removed.
|
||||
//
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
#include <QtGui/qimage.h>
|
||||
#include <QtCore/qshareddata.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QVolatileImageData;
|
||||
|
||||
class Q_GUI_EXPORT QVolatileImage
|
||||
{
|
||||
public:
|
||||
QVolatileImage();
|
||||
QVolatileImage(int w, int h, QImage::Format format);
|
||||
explicit QVolatileImage(const QImage &sourceImage);
|
||||
explicit QVolatileImage(void *nativeImage, void *nativeMask = 0);
|
||||
QVolatileImage(const QVolatileImage &other);
|
||||
~QVolatileImage();
|
||||
QVolatileImage &operator=(const QVolatileImage &rhs);
|
||||
|
||||
bool isNull() const;
|
||||
QImage::Format format() const;
|
||||
int width() const;
|
||||
int height() const;
|
||||
int bytesPerLine() const;
|
||||
int byteCount() const;
|
||||
int depth() const;
|
||||
bool hasAlphaChannel() const;
|
||||
void beginDataAccess() const;
|
||||
void endDataAccess(bool readOnly = false) const;
|
||||
uchar *bits();
|
||||
const uchar *constBits() const;
|
||||
bool ensureFormat(QImage::Format format);
|
||||
QImage toImage() const;
|
||||
QImage &imageRef();
|
||||
QPaintEngine *paintEngine();
|
||||
void fill(uint pixelValue);
|
||||
void *duplicateNativeImage() const;
|
||||
void copyFrom(QVolatileImage *source, const QRect &rect);
|
||||
|
||||
private:
|
||||
QSharedDataPointer<QVolatileImageData> d;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QVOLATILEIMAGE_P_H
|
||||
|
|
@ -1,114 +0,0 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/
|
||||
**
|
||||
** This file is part of the QtGui module of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** GNU Lesser General Public License Usage
|
||||
** This file may be used under the terms of the GNU Lesser General Public
|
||||
** License version 2.1 as published by the Free Software Foundation and
|
||||
** appearing in the file LICENSE.LGPL included in the packaging of this
|
||||
** file. Please review the following information to ensure the GNU Lesser
|
||||
** General Public License version 2.1 requirements will be met:
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU General
|
||||
** Public License version 3.0 as published by the Free Software Foundation
|
||||
** and appearing in the file LICENSE.GPL included in the packaging of this
|
||||
** file. Please review the following information to ensure the GNU General
|
||||
** Public License version 3.0 requirements will be met:
|
||||
** http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** Other Usage
|
||||
** Alternatively, this file may be used in accordance with the terms and
|
||||
** conditions contained in a signed written agreement between you and Nokia.
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "qvolatileimagedata_p.h"
|
||||
#include <QtGui/qpaintengine.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
QVolatileImageData::QVolatileImageData()
|
||||
: pengine(0)
|
||||
{
|
||||
}
|
||||
|
||||
QVolatileImageData::QVolatileImageData(int w, int h, QImage::Format format)
|
||||
: pengine(0)
|
||||
{
|
||||
image = QImage(w, h, format);
|
||||
}
|
||||
|
||||
QVolatileImageData::QVolatileImageData(const QImage &sourceImage)
|
||||
: pengine(0)
|
||||
{
|
||||
image = sourceImage;
|
||||
}
|
||||
|
||||
QVolatileImageData::QVolatileImageData(void *, void *)
|
||||
: pengine(0)
|
||||
{
|
||||
// Not supported.
|
||||
}
|
||||
|
||||
QVolatileImageData::QVolatileImageData(const QVolatileImageData &other)
|
||||
: QSharedData()
|
||||
{
|
||||
image = other.image;
|
||||
// The detach is not mandatory here but we do it nonetheless in order to
|
||||
// keep the behavior consistent with other platforms.
|
||||
image.detach();
|
||||
pengine = 0;
|
||||
}
|
||||
|
||||
QVolatileImageData::~QVolatileImageData()
|
||||
{
|
||||
delete pengine;
|
||||
}
|
||||
|
||||
void QVolatileImageData::beginDataAccess() const
|
||||
{
|
||||
// nothing to do here
|
||||
}
|
||||
|
||||
void QVolatileImageData::endDataAccess(bool readOnly) const
|
||||
{
|
||||
Q_UNUSED(readOnly);
|
||||
// nothing to do here
|
||||
}
|
||||
|
||||
bool QVolatileImageData::ensureFormat(QImage::Format format)
|
||||
{
|
||||
if (image.format() != format) {
|
||||
image = image.convertToFormat(format);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void *QVolatileImageData::duplicateNativeImage() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void QVolatileImageData::ensureImage()
|
||||
{
|
||||
// nothing to do here
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
@ -1,84 +0,0 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/
|
||||
**
|
||||
** This file is part of the QtGui module of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** GNU Lesser General Public License Usage
|
||||
** This file may be used under the terms of the GNU Lesser General Public
|
||||
** License version 2.1 as published by the Free Software Foundation and
|
||||
** appearing in the file LICENSE.LGPL included in the packaging of this
|
||||
** file. Please review the following information to ensure the GNU Lesser
|
||||
** General Public License version 2.1 requirements will be met:
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU General
|
||||
** Public License version 3.0 as published by the Free Software Foundation
|
||||
** and appearing in the file LICENSE.GPL included in the packaging of this
|
||||
** file. Please review the following information to ensure the GNU General
|
||||
** Public License version 3.0 requirements will be met:
|
||||
** http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** Other Usage
|
||||
** Alternatively, this file may be used in accordance with the terms and
|
||||
** conditions contained in a signed written agreement between you and Nokia.
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QVOLATILEIMAGEDATA_P_H
|
||||
#define QVOLATILEIMAGEDATA_P_H
|
||||
|
||||
//
|
||||
// W A R N I N G
|
||||
// -------------
|
||||
//
|
||||
// This file is not part of the Qt API. It exists purely as an
|
||||
// implementation detail. This header file may change from version to
|
||||
// version without notice, or even be removed.
|
||||
//
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
#include <QtGui/qimage.h>
|
||||
#include <QtCore/qshareddata.h>
|
||||
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QVolatileImageData : public QSharedData
|
||||
{
|
||||
public:
|
||||
QVolatileImageData();
|
||||
QVolatileImageData(int w, int h, QImage::Format format);
|
||||
QVolatileImageData(const QImage &sourceImage);
|
||||
QVolatileImageData(void *nativeImage, void *nativeMask);
|
||||
QVolatileImageData(const QVolatileImageData &other);
|
||||
~QVolatileImageData();
|
||||
|
||||
void beginDataAccess() const;
|
||||
void endDataAccess(bool readOnly = false) const;
|
||||
bool ensureFormat(QImage::Format format);
|
||||
void *duplicateNativeImage() const;
|
||||
void ensureImage();
|
||||
|
||||
QImage image;
|
||||
QPaintEngine *pengine;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QVOLATILEIMAGEDATA_P_H
|
||||
|
|
@ -9,7 +9,6 @@ SUBDIRS=\
|
|||
qimageiohandler \
|
||||
qimagewriter \
|
||||
qmovie \
|
||||
qvolatileimage \
|
||||
qicon \
|
||||
qpicture \
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +0,0 @@
|
|||
CONFIG += testcase
|
||||
TARGET = tst_qvolatileimage
|
||||
|
||||
QT += gui-private widgets testlib
|
||||
|
||||
SOURCES += tst_qvolatileimage.cpp
|
||||
|
|
@ -1,206 +0,0 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** Contact: http://www.qt-project.org/
|
||||
**
|
||||
** This file is part of the test suite of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** GNU Lesser General Public License Usage
|
||||
** This file may be used under the terms of the GNU Lesser General Public
|
||||
** License version 2.1 as published by the Free Software Foundation and
|
||||
** appearing in the file LICENSE.LGPL included in the packaging of this
|
||||
** file. Please review the following information to ensure the GNU Lesser
|
||||
** General Public License version 2.1 requirements will be met:
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU General
|
||||
** Public License version 3.0 as published by the Free Software Foundation
|
||||
** and appearing in the file LICENSE.GPL included in the packaging of this
|
||||
** file. Please review the following information to ensure the GNU General
|
||||
** Public License version 3.0 requirements will be met:
|
||||
** http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** Other Usage
|
||||
** Alternatively, this file may be used in accordance with the terms and
|
||||
** conditions contained in a signed written agreement between you and Nokia.
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
#include <QtGui/qpainter.h>
|
||||
#include <QtGui/qpaintengine.h>
|
||||
#include <QtGui/private/qvolatileimage_p.h>
|
||||
|
||||
class tst_QVolatileImage : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
tst_QVolatileImage() { }
|
||||
|
||||
private slots:
|
||||
void create();
|
||||
void ensureFormat();
|
||||
void dataAccess();
|
||||
void sharing();
|
||||
void fill();
|
||||
void copy();
|
||||
};
|
||||
|
||||
void tst_QVolatileImage::create()
|
||||
{
|
||||
QVolatileImage nullImg;
|
||||
QVERIFY(nullImg.isNull());
|
||||
|
||||
QVolatileImage img(100, 200, QImage::Format_ARGB32);
|
||||
QVERIFY(!img.isNull());
|
||||
QCOMPARE(img.width(), 100);
|
||||
QCOMPARE(img.height(), 200);
|
||||
QCOMPARE(img.format(), QImage::Format_ARGB32);
|
||||
QCOMPARE(img.byteCount(), img.bytesPerLine() * img.height());
|
||||
QCOMPARE(img.hasAlphaChannel(), true);
|
||||
QCOMPARE(img.depth(), 32);
|
||||
|
||||
QImage source(12, 23, QImage::Format_ARGB32_Premultiplied);
|
||||
img = QVolatileImage(source);
|
||||
QVERIFY(!img.isNull());
|
||||
QCOMPARE(img.width(), 12);
|
||||
QCOMPARE(img.height(), 23);
|
||||
QCOMPARE(img.format(), source.format());
|
||||
QCOMPARE(img.byteCount(), img.bytesPerLine() * img.height());
|
||||
QVERIFY(img.imageRef() == source);
|
||||
QVERIFY(img.toImage() == source);
|
||||
QCOMPARE(img.hasAlphaChannel(), true);
|
||||
QCOMPARE(img.hasAlphaChannel(), img.imageRef().hasAlphaChannel());
|
||||
QCOMPARE(img.hasAlphaChannel(), img.toImage().hasAlphaChannel());
|
||||
QCOMPARE(img.depth(), 32);
|
||||
}
|
||||
|
||||
void tst_QVolatileImage::ensureFormat()
|
||||
{
|
||||
QImage source(12, 23, QImage::Format_ARGB32_Premultiplied);
|
||||
QVolatileImage img(source);
|
||||
QVERIFY(!img.isNull());
|
||||
QVERIFY(img.imageRef() == source);
|
||||
QVERIFY(img.toImage() == source);
|
||||
|
||||
QVERIFY(img.ensureFormat(QImage::Format_ARGB32_Premultiplied)); // no-op
|
||||
QVERIFY(img.imageRef() == source);
|
||||
QVERIFY(img.toImage() == source);
|
||||
QVERIFY(img.format() == QImage::Format_ARGB32_Premultiplied);
|
||||
|
||||
QVERIFY(img.ensureFormat(QImage::Format_RGB32)); // new data under-the-hood
|
||||
QVERIFY(img.imageRef() != source);
|
||||
QVERIFY(img.toImage() != source);
|
||||
QVERIFY(img.format() == QImage::Format_RGB32);
|
||||
}
|
||||
|
||||
void tst_QVolatileImage::dataAccess()
|
||||
{
|
||||
QImage source(12, 23, QImage::Format_ARGB32_Premultiplied);
|
||||
QVolatileImage img(source);
|
||||
QVERIFY(!img.isNull());
|
||||
img.beginDataAccess();
|
||||
QVERIFY(img.constBits());
|
||||
QVERIFY(img.imageRef().constBits());
|
||||
QVERIFY(img.bits());
|
||||
QVERIFY(img.imageRef().bits());
|
||||
img.endDataAccess();
|
||||
|
||||
img = QVolatileImage(12, 23, QImage::Format_ARGB32);
|
||||
img.beginDataAccess();
|
||||
QVERIFY(img.constBits() && img.bits());
|
||||
img.endDataAccess();
|
||||
}
|
||||
|
||||
void tst_QVolatileImage::sharing()
|
||||
{
|
||||
QVolatileImage img1(100, 100, QImage::Format_ARGB32);
|
||||
QVolatileImage img2 = img1;
|
||||
img1.beginDataAccess();
|
||||
img2.beginDataAccess();
|
||||
QVERIFY(img1.constBits() == img2.constBits());
|
||||
img2.endDataAccess();
|
||||
img1.endDataAccess();
|
||||
img1.imageRef(); // non-const call, should detach
|
||||
img1.beginDataAccess();
|
||||
img2.beginDataAccess();
|
||||
QVERIFY(img1.constBits() != img2.constBits());
|
||||
img2.endDataAccess();
|
||||
img1.endDataAccess();
|
||||
|
||||
// toImage() should return a copy of the internal QImage.
|
||||
// imageRef() is a reference to the internal QImage.
|
||||
QVERIFY(img1.imageRef().constBits() != img1.toImage().constBits());
|
||||
}
|
||||
|
||||
bool fuzzyCompareImages(const QImage &image1, const QImage &image2, int tolerance)
|
||||
{
|
||||
if (image1.bytesPerLine() != image2.bytesPerLine()
|
||||
|| image1.width() != image2.width()
|
||||
|| image1.height() != image2.height()) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < image1.height(); i++) {
|
||||
const uchar *line1 = image1.scanLine(i);
|
||||
const uchar *line2 = image2.scanLine(i);
|
||||
int bytes = image1.bytesPerLine();
|
||||
for (int j = 0; j < bytes; j++) {
|
||||
int delta = line1[j] - line2[j];
|
||||
if (qAbs(delta) > tolerance)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void tst_QVolatileImage::fill()
|
||||
{
|
||||
QVolatileImage img(100, 100, QImage::Format_ARGB32_Premultiplied);
|
||||
QColor col = QColor(10, 20, 30);
|
||||
img.fill(col.rgba());
|
||||
QVERIFY(img.imageRef().pixel(1, 1) == col.rgba());
|
||||
QVERIFY(img.toImage().pixel(1, 1) == col.rgba());
|
||||
}
|
||||
|
||||
void tst_QVolatileImage::copy()
|
||||
{
|
||||
QVolatileImage img(100, 100, QImage::Format_RGB32);
|
||||
img.beginDataAccess();
|
||||
img.imageRef().fill(QColor(Qt::green).rgba());
|
||||
QPainter p(&img.imageRef());
|
||||
p.drawRect(10, 10, 50, 50);
|
||||
p.end();
|
||||
img.endDataAccess();
|
||||
|
||||
QVolatileImage img2(100, 100, QImage::Format_RGB32);
|
||||
img2.copyFrom(&img, QRect());
|
||||
QImage imgA = img.toImage();
|
||||
QImage imgB = img2.toImage();
|
||||
QCOMPARE(imgA.size(), imgB.size());
|
||||
QVERIFY(fuzzyCompareImages(imgA, imgB, 0));
|
||||
|
||||
img2 = QVolatileImage(20, 20, QImage::Format_RGB32);
|
||||
img2.copyFrom(&img, QRect(5, 5, 20, 20));
|
||||
imgA = img.toImage().copy(5, 5, 20, 20);
|
||||
imgB = img2.toImage();
|
||||
QCOMPARE(imgA.size(), imgB.size());
|
||||
QVERIFY(fuzzyCompareImages(imgA, imgB, 0));
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QVolatileImage)
|
||||
#include "tst_qvolatileimage.moc"
|
||||
Loading…
Reference in New Issue