Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

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

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    4545#include "qnativeimage_p.h"
    4646#include "qimage_p.h"
     47#include "qpaintengine.h"
    4748
    4849#include "qbitmap.h"
    4950#include "qimage.h"
     51#include <QBuffer>
     52#include <QImageReader>
     53#include <private/qimage_p.h>
     54#include <private/qsimd_p.h>
    5055#include <private/qwidget_p.h>
    5156#include <private/qdrawhelper_p.h>
     
    128133}
    129134
     135bool QRasterPixmapData::fromData(const uchar *buffer, uint len, const char *format,
     136                      Qt::ImageConversionFlags flags)
     137{
     138    QByteArray a = QByteArray::fromRawData(reinterpret_cast<const char *>(buffer), len);
     139    QBuffer b(&a);
     140    b.open(QIODevice::ReadOnly);
     141    QImage image = QImageReader(&b, format).read();
     142    if (image.isNull())
     143        return false;
     144
     145    createPixmapForImage(image, flags, /* inplace = */true);
     146    return !isNull();
     147}
     148
    130149void QRasterPixmapData::fromImage(const QImage &sourceImage,
    131150                                  Qt::ImageConversionFlags flags)
    132151{
    133152    Q_UNUSED(flags);
    134 
    135 #ifdef Q_WS_QWS
    136     QImage::Format format;
    137     if (pixelType() == BitmapType) {
    138         format = QImage::Format_Mono;
    139     } else {
    140         format = QScreen::instance()->pixelFormat();
    141         if (format == QImage::Format_Invalid)
    142             format = QImage::Format_ARGB32_Premultiplied;
    143         else if (format == QImage::Format_Indexed8) // currently not supported
    144             format = QImage::Format_RGB444;
    145     }
    146 
    147     if (sourceImage.hasAlphaChannel()
    148         && ((flags & Qt::NoOpaqueDetection)
    149             || const_cast<QImage &>(sourceImage).data_ptr()->checkForAlphaPixels())) {
    150         switch (format) {
    151             case QImage::Format_RGB16:
    152                 format = QImage::Format_ARGB8565_Premultiplied;
    153                 break;
    154             case QImage::Format_RGB666:
    155                 format = QImage::Format_ARGB6666_Premultiplied;
    156                 break;
    157             case QImage::Format_RGB555:
    158                 format = QImage::Format_ARGB8555_Premultiplied;
    159                 break;
    160             case QImage::Format_RGB444:
    161                 format = QImage::Format_ARGB4444_Premultiplied;
    162                 break;
    163             default:
    164                 format = QImage::Format_ARGB32_Premultiplied;
    165                 break;
    166         }
    167     } else if (format == QImage::Format_Invalid) {
    168         format = QImage::Format_ARGB32_Premultiplied;
    169     }
    170 
    171     image = sourceImage.convertToFormat(format);
    172 #else
    173     if (pixelType() == BitmapType) {
    174         image = sourceImage.convertToFormat(QImage::Format_MonoLSB);
    175     } else {
    176         if (sourceImage.depth() == 1) {
    177             image = sourceImage.hasAlphaChannel()
    178                     ? sourceImage.convertToFormat(QImage::Format_ARGB32_Premultiplied)
    179                     : sourceImage.convertToFormat(QImage::Format_RGB32);
    180         } else {
    181 
    182             QImage::Format opaqueFormat = QNativeImage::systemFormat();
    183             QImage::Format alphaFormat = QImage::Format_ARGB32_Premultiplied;
    184 
    185             switch (opaqueFormat) {
    186             case QImage::Format_RGB16:
    187                 alphaFormat = QImage::Format_ARGB8565_Premultiplied;
    188                 break;
    189             default: // We don't care about the others...
    190                 break;
    191             }
    192 
    193             if (!sourceImage.hasAlphaChannel()
    194                 || ((flags & Qt::NoOpaqueDetection) == 0
    195                     && !const_cast<QImage &>(sourceImage).data_ptr()->checkForAlphaPixels())) {
    196                 image = sourceImage.convertToFormat(opaqueFormat);
    197             } else {
    198                 image = sourceImage.convertToFormat(alphaFormat);
    199             }
    200         }
    201     }
    202 #endif
    203     if (image.d) {
    204         w = image.d->width;
    205         h = image.d->height;
    206         d = image.d->depth;
    207     } else {
    208         w = h = d = 0;
    209     }
    210     is_null = (w <= 0 || h <= 0);
    211 
    212     setSerialNumber(image.serialNumber());
     153    QImage image = sourceImage;
     154    createPixmapForImage(image, flags, /* inplace = */false);
     155}
     156
     157void QRasterPixmapData::fromImageReader(QImageReader *imageReader,
     158                                        Qt::ImageConversionFlags flags)
     159{
     160    Q_UNUSED(flags);
     161    QImage image = imageReader->read();
     162    if (image.isNull())
     163        return;
     164
     165    createPixmapForImage(image, flags, /* inplace = */true);
    213166}
    214167
    215168// from qwindowsurface.cpp
    216169extern void qt_scrollRectInImage(QImage &img, const QRect &rect, const QPoint &offset);
     170
     171void QRasterPixmapData::copy(const QPixmapData *data, const QRect &rect)
     172{
     173    fromImage(data->toImage(rect).copy(), Qt::NoOpaqueDetection);
     174}
    217175
    218176bool QRasterPixmapData::scroll(int dx, int dy, const QRect &rect)
     
    239197            if (!image.hasAlphaChannel()) {
    240198                QImage::Format toFormat;
     199#if !(defined(QT_HAVE_NEON) || defined(QT_ALWAYS_HAVE_SSE2))
    241200                if (image.format() == QImage::Format_RGB16)
    242201                    toFormat = QImage::Format_ARGB8565_Premultiplied;
     
    248207                    toFormat = QImage::Format_ARGB4444_Premultiplied;
    249208                else
     209#endif
    250210                    toFormat = QImage::Format_ARGB32_Premultiplied;
    251211                image = QImage(image.width(), image.height(), toFormat);
     
    345305QImage QRasterPixmapData::toImage() const
    346306{
     307    if (!image.isNull()) {
     308        QImageData *data = const_cast<QImage &>(image).data_ptr();
     309        if (data->paintEngine && data->paintEngine->isActive()
     310            && data->paintEngine->paintDevice() == &image)
     311        {
     312            return image.copy();
     313        }
     314    }
     315
    347316    return image;
     317}
     318
     319QImage QRasterPixmapData::toImage(const QRect &rect) const
     320{
     321    if (rect.isNull())
     322        return image;
     323
     324    QRect clipped = rect.intersected(QRect(0, 0, w, h));
     325    if (d % 8 == 0)
     326        return QImage(image.scanLine(clipped.y()) + clipped.x() * (d / 8),
     327                      clipped.width(), clipped.height(),
     328                      image.bytesPerLine(), image.format());
     329    else
     330        return image.copy(clipped);
    348331}
    349332
     
    395378}
    396379
     380void QRasterPixmapData::createPixmapForImage(QImage &sourceImage, Qt::ImageConversionFlags flags, bool inPlace)
     381{
     382    QImage::Format format;
     383#ifdef Q_WS_QWS
     384    if (pixelType() == BitmapType) {
     385        format = QImage::Format_Mono;
     386    } else {
     387        format = QScreen::instance()->pixelFormat();
     388        if (format == QImage::Format_Invalid)
     389            format = QImage::Format_ARGB32_Premultiplied;
     390        else if (format == QImage::Format_Indexed8) // currently not supported
     391            format = QImage::Format_RGB444;
     392    }
     393
     394    if (sourceImage.hasAlphaChannel()
     395        && ((flags & Qt::NoOpaqueDetection)
     396            || const_cast<QImage &>(sourceImage).data_ptr()->checkForAlphaPixels())) {
     397        switch (format) {
     398            case QImage::Format_RGB16:
     399                format = QImage::Format_ARGB8565_Premultiplied;
     400                break;
     401            case QImage::Format_RGB666:
     402                format = QImage::Format_ARGB6666_Premultiplied;
     403                break;
     404            case QImage::Format_RGB555:
     405                format = QImage::Format_ARGB8555_Premultiplied;
     406                break;
     407            case QImage::Format_RGB444:
     408                format = QImage::Format_ARGB4444_Premultiplied;
     409                break;
     410            default:
     411                format = QImage::Format_ARGB32_Premultiplied;
     412                break;
     413        }
     414    } else if (format == QImage::Format_Invalid) {
     415        format = QImage::Format_ARGB32_Premultiplied;
     416    }
     417#else
     418    if (pixelType() == BitmapType) {
     419        format = QImage::Format_MonoLSB;
     420    } else {
     421        if (sourceImage.depth() == 1) {
     422            format = sourceImage.hasAlphaChannel()
     423                    ? QImage::Format_ARGB32_Premultiplied
     424                    : QImage::Format_RGB32;
     425        } else {
     426            QImage::Format opaqueFormat = QNativeImage::systemFormat();
     427            QImage::Format alphaFormat = QImage::Format_ARGB32_Premultiplied;
     428
     429#if !defined(QT_HAVE_NEON) && !defined(QT_ALWAYS_HAVE_SSE2)
     430            switch (opaqueFormat) {
     431            case QImage::Format_RGB16:
     432                alphaFormat = QImage::Format_ARGB8565_Premultiplied;
     433                break;
     434            default: // We don't care about the others...
     435                break;
     436            }
     437#endif
     438
     439            if (!sourceImage.hasAlphaChannel()) {
     440                format = opaqueFormat;
     441            } else if ((flags & Qt::NoOpaqueDetection) == 0
     442                       && !const_cast<QImage &>(sourceImage).data_ptr()->checkForAlphaPixels())
     443            {
     444                // image has alpha format but is really opaque, so try to do a
     445                // more efficient conversion
     446                if (sourceImage.format() == QImage::Format_ARGB32
     447                    || sourceImage.format() == QImage::Format_ARGB32_Premultiplied)
     448                {
     449                    if (!inPlace)
     450                        sourceImage.detach();
     451                    sourceImage.d->format = QImage::Format_RGB32;
     452                }
     453                format = opaqueFormat;
     454            } else {
     455                format = alphaFormat;
     456            }
     457        }
     458    }
     459#endif
     460
     461    if (inPlace && sourceImage.d->convertInPlace(format, flags)) {
     462        image = sourceImage;
     463    } else {
     464        image = sourceImage.convertToFormat(format);
     465    }
     466
     467    if (image.d) {
     468        w = image.d->width;
     469        h = image.d->height;
     470        d = image.d->depth;
     471    } else {
     472        w = h = d = 0;
     473    }
     474    is_null = (w <= 0 || h <= 0);
     475
     476    setSerialNumber(image.serialNumber());
     477}
     478
    397479QImage* QRasterPixmapData::buffer()
    398480{
Note: See TracChangeset for help on using the changeset viewer.