Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/image/qpixmapdata.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the QtGui module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     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.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    4141
    4242#include "qpixmapdata_p.h"
     43#include <QtCore/qbuffer.h>
    4344#include <QtGui/qbitmap.h>
    4445#include <QtGui/qimagereader.h>
     46#include <private/qgraphicssystem_p.h>
     47#include <private/qapplication_p.h>
    4548
    4649QT_BEGIN_NAMESPACE
     
    4952                                     0x10, 0x20, 0x40, 0x80 };
    5053
     54QPixmapData *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
    5167QPixmapData::QPixmapData(PixelType pixelType, int objectId)
    52     : ref(0), detach_no(0), type(pixelType), id(objectId), ser_no(0), is_cached(false)
    53 {
    54 
     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)
     78{
    5579}
    5680
     
    5983}
    6084
    61 void QPixmapData::fromFile(const QString &fileName, const char *format,
     85QPixmapData *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
     96static 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
     116bool QPixmapData::fromFile(const QString &fileName, const char *format,
    62117                           Qt::ImageConversionFlags flags)
    63118{
    64     const QImage image = QImageReader(fileName, format).read();
     119    QImage image = QImageReader(fileName, format).read();
    65120    if (image.isNull())
    66         return;
    67 
    68     fromImage(image, flags);
     121        return false;
     122    fromImage(makeBitmapCompliantIfNeeded(this, image, flags), flags);
     123    return !isNull();
     124}
     125
     126bool 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();
    69134}
    70135
     
    72137{
    73138    fromImage(data->toImage().copy(rect), Qt::AutoColor);
     139}
     140
     141bool 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;
    74147}
    75148
     
    129202        return QBitmap();
    130203
    131     mask.setNumColors(2);
     204    mask.setColorCount(2);
    132205    mask.setColor(0, QColor(Qt::color0).rgba());
    133206    mask.setColor(1, QColor(Qt::color1).rgba());
     
    177250}
    178251
     252#if defined(Q_OS_SYMBIAN)
     253void* QPixmapData::toNativeType(NativeType /* type */)
     254{
     255    return 0;
     256}
     257
     258void QPixmapData::fromNativeType(void* /* pixmap */, NativeType /* typre */)
     259{
     260    return;
     261}
     262#endif
     263
    179264QT_END_NAMESPACE
Note: See TracChangeset for help on using the changeset viewer.