[2] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[561] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
---|
[2] | 6 | **
|
---|
| 7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
| 8 | **
|
---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
| 10 | ** Commercial Usage
|
---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
| 14 | ** a written agreement between you and Nokia.
|
---|
| 15 | **
|
---|
| 16 | ** GNU Lesser General Public License Usage
|
---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
| 20 | ** packaging of this file. Please review the following information to
|
---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
| 23 | **
|
---|
[561] | 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
[2] | 27 | **
|
---|
| 28 | ** GNU General Public License Usage
|
---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
| 32 | ** packaging of this file. Please review the following information to
|
---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
| 35 | **
|
---|
[561] | 36 | ** If you have questions regarding the use of this file, please contact
|
---|
| 37 | ** Nokia at [email protected].
|
---|
[2] | 38 | ** $QT_END_LICENSE$
|
---|
| 39 | **
|
---|
| 40 | ****************************************************************************/
|
---|
| 41 |
|
---|
| 42 | #include "qpixmapdata_p.h"
|
---|
[561] | 43 | #include <QtCore/qbuffer.h>
|
---|
[2] | 44 | #include <QtGui/qbitmap.h>
|
---|
| 45 | #include <QtGui/qimagereader.h>
|
---|
[561] | 46 | #include <private/qgraphicssystem_p.h>
|
---|
| 47 | #include <private/qapplication_p.h>
|
---|
[2] | 48 |
|
---|
| 49 | QT_BEGIN_NAMESPACE
|
---|
| 50 |
|
---|
| 51 | const uchar qt_pixmap_bit_mask[] = { 0x01, 0x02, 0x04, 0x08,
|
---|
| 52 | 0x10, 0x20, 0x40, 0x80 };
|
---|
| 53 |
|
---|
[561] | 54 | QPixmapData *QPixmapData::create(int w, int h, PixelType type)
|
---|
| 55 | {
|
---|
| 56 | QPixmapData *data;
|
---|
| 57 | QGraphicsSystem* gs = QApplicationPrivate::graphicsSystem();
|
---|
| 58 | if (gs)
|
---|
| 59 | data = gs->createPixmapData(static_cast<QPixmapData::PixelType>(type));
|
---|
| 60 | else
|
---|
| 61 | data = QGraphicsSystem::createDefaultPixmapData(static_cast<QPixmapData::PixelType>(type));
|
---|
| 62 | data->resize(w, h);
|
---|
| 63 | return data;
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 |
|
---|
[2] | 67 | QPixmapData::QPixmapData(PixelType pixelType, int objectId)
|
---|
[561] | 68 | : w(0),
|
---|
| 69 | h(0),
|
---|
| 70 | d(0),
|
---|
| 71 | is_null(true),
|
---|
| 72 | ref(0),
|
---|
| 73 | detach_no(0),
|
---|
| 74 | type(pixelType),
|
---|
| 75 | id(objectId),
|
---|
| 76 | ser_no(0),
|
---|
| 77 | is_cached(false)
|
---|
[2] | 78 | {
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | QPixmapData::~QPixmapData()
|
---|
| 82 | {
|
---|
| 83 | }
|
---|
| 84 |
|
---|
[561] | 85 | QPixmapData *QPixmapData::createCompatiblePixmapData() const
|
---|
| 86 | {
|
---|
| 87 | QPixmapData *d;
|
---|
| 88 | QGraphicsSystem *gs = QApplicationPrivate::graphicsSystem();
|
---|
| 89 | if (gs)
|
---|
| 90 | d = gs->createPixmapData(pixelType());
|
---|
| 91 | else
|
---|
| 92 | d = QGraphicsSystem::createDefaultPixmapData(pixelType());
|
---|
| 93 | return d;
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | static QImage makeBitmapCompliantIfNeeded(QPixmapData *d, const QImage &image, Qt::ImageConversionFlags flags)
|
---|
| 97 | {
|
---|
| 98 | if (d->pixelType() == QPixmapData::BitmapType) {
|
---|
| 99 | QImage img = image.convertToFormat(QImage::Format_MonoLSB, flags);
|
---|
| 100 |
|
---|
| 101 | // make sure image.color(0) == Qt::color0 (white)
|
---|
| 102 | // and image.color(1) == Qt::color1 (black)
|
---|
| 103 | const QRgb c0 = QColor(Qt::black).rgb();
|
---|
| 104 | const QRgb c1 = QColor(Qt::white).rgb();
|
---|
| 105 | if (img.color(0) == c0 && img.color(1) == c1) {
|
---|
| 106 | img.invertPixels();
|
---|
| 107 | img.setColor(0, c1);
|
---|
| 108 | img.setColor(1, c0);
|
---|
| 109 | }
|
---|
| 110 | return img;
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | return image;
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | bool QPixmapData::fromFile(const QString &fileName, const char *format,
|
---|
[2] | 117 | Qt::ImageConversionFlags flags)
|
---|
| 118 | {
|
---|
[561] | 119 | QImage image = QImageReader(fileName, format).read();
|
---|
[2] | 120 | if (image.isNull())
|
---|
[561] | 121 | return false;
|
---|
| 122 | fromImage(makeBitmapCompliantIfNeeded(this, image, flags), flags);
|
---|
| 123 | return !isNull();
|
---|
| 124 | }
|
---|
[2] | 125 |
|
---|
[561] | 126 | bool QPixmapData::fromData(const uchar *buf, uint len, const char *format, Qt::ImageConversionFlags flags)
|
---|
| 127 | {
|
---|
| 128 | QByteArray a = QByteArray::fromRawData(reinterpret_cast<const char *>(buf), len);
|
---|
| 129 | QBuffer b(&a);
|
---|
| 130 | b.open(QIODevice::ReadOnly);
|
---|
| 131 | QImage image = QImageReader(&b, format).read();
|
---|
| 132 | fromImage(makeBitmapCompliantIfNeeded(this, image, flags), flags);
|
---|
| 133 | return !isNull();
|
---|
[2] | 134 | }
|
---|
| 135 |
|
---|
| 136 | void QPixmapData::copy(const QPixmapData *data, const QRect &rect)
|
---|
| 137 | {
|
---|
| 138 | fromImage(data->toImage().copy(rect), Qt::AutoColor);
|
---|
| 139 | }
|
---|
| 140 |
|
---|
[561] | 141 | bool QPixmapData::scroll(int dx, int dy, const QRect &rect)
|
---|
| 142 | {
|
---|
| 143 | Q_UNUSED(dx);
|
---|
| 144 | Q_UNUSED(dy);
|
---|
| 145 | Q_UNUSED(rect);
|
---|
| 146 | return false;
|
---|
| 147 | }
|
---|
| |
---|