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/painting/qdrawhelper.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**
    4040****************************************************************************/
     41
    4142#include <private/qdrawhelper_p.h>
    4243#include <private/qpaintengine_raster_p.h>
    4344#include <private/qpainter_p.h>
    4445#include <private/qdrawhelper_x86_p.h>
     46#include <private/qdrawhelper_armv6_p.h>
     47#include <private/qdrawhelper_neon_p.h>
    4548#include <private/qmath_p.h>
    4649#include <qmath.h>
    4750
    4851QT_BEGIN_NAMESPACE
     52
    4953
    5054#define MASK(src, a) src = BYTE_MUL(src, a)
     
    158162}
    159163
    160 #if defined(Q_CC_MSVC) && _MSC_VER <= 1300 && !defined(Q_CC_INTEL)
    161 template <typename EnumType, int value>
    162 class QEnumToType
    163 {
    164 public:
    165     inline EnumType operator()() const
    166     {
    167         return EnumType(value);
    168     }
    169 };
    170 template <QImage::Format format>
    171 class QImageFormatToType
    172 {
    173 public:
    174     inline QImage::Format operator()() const
    175     {
    176         return format;
    177     }
    178 };
    179 // Would have used QEnumToType instead of creating a specialized version for QImageFormatToType,
    180 // but that causes internal compiler error on VC6
    181 #define Q_TEMPLATE_IMAGEFORMAT_FIX(format) , const QImageFormatToType<format> &imageFormatType
    182 #define Q_TEMPLATE_IMAGEFORMAT_CALL(format) , QImageFormatToType<format>()
    183 #define Q_TEMPLATE_ENUM_FIX(Type, Value) , const QEnumToType<Type, Value> &enumTemplateType
    184 #define Q_TEMPLATE_ENUM_CALL(Type, Value) , QEnumToType<Type, Value>()
    185 #define Q_TEMPLATE_FIX(Type) , const QTypeInfo<Type> &templateType
    186 #define Q_TEMPLATE_CALL(Type) , QTypeInfo<Type>()
    187 #else
    188 #define Q_TEMPLATE_IMAGEFORMAT_FIX(format)
    189 #define Q_TEMPLATE_IMAGEFORMAT_CALL(format)
    190 #define Q_TEMPLATE_ENUM_FIX(Type, Value)
    191 #define Q_TEMPLATE_ENUM_CALL(Type, Value)
    192 #define Q_TEMPLATE_FIX(Type)
    193 #define Q_TEMPLATE_CALL(Type)
    194 #endif
    195 
    196164template <class DST>
    197165Q_STATIC_TEMPLATE_FUNCTION uint * QT_FASTCALL destFetch(uint *buffer, QRasterBuffer *rasterBuffer,
    198                                     int x, int y, int length
    199                                     Q_TEMPLATE_FIX(DST))
     166                                    int x, int y, int length)
    200167{
    201168    const DST *src = reinterpret_cast<DST*>(rasterBuffer->scanLine(y)) + x;
     
    206173}
    207174
    208 #if defined(Q_CC_MSVC) && _MSC_VER <= 1300 && !defined(Q_CC_INTEL)
    209 #define DEST_FETCH_DECL(DST)                                            \
    210     static uint * QT_FASTCALL destFetch_##DST(uint *buffer,             \
    211                                               QRasterBuffer *rasterBuffer, \
    212                                               int x, int y, int length) \
    213     {                                                                   \
    214         return destFetch<DST>(buffer, rasterBuffer, x, y, length Q_TEMPLATE_CALL(DST));      \
    215     }
    216 
    217 DEST_FETCH_DECL(qargb8565)
    218 DEST_FETCH_DECL(qrgb666)
    219 DEST_FETCH_DECL(qargb6666)
    220 DEST_FETCH_DECL(qrgb555)
    221 DEST_FETCH_DECL(qrgb888)
    222 DEST_FETCH_DECL(qargb8555)
    223 DEST_FETCH_DECL(qrgb444)
    224 DEST_FETCH_DECL(qargb4444)
    225 #undef DEST_FETCH_DECL
    226 # define SPANFUNC_POINTER_DESTFETCH(Arg) destFetch_##Arg
    227 #else // !VC6 && !VC2002
    228175# define SPANFUNC_POINTER_DESTFETCH(Arg) destFetch<Arg>
    229 #endif
    230176
    231177static const DestFetchProc destFetchProc[QImage::NImageFormats] =
     
    367313Q_STATIC_TEMPLATE_FUNCTION void QT_FASTCALL destStore(QRasterBuffer *rasterBuffer,
    368314                                  int x, int y,
    369                                   const uint *buffer, int length
    370                                   Q_TEMPLATE_FIX(DST))
     315                                  const uint *buffer, int length)
    371316{
    372317    DST *dest = reinterpret_cast<DST*>(rasterBuffer->scanLine(y)) + x;
    373     const quint32 *src = reinterpret_cast<const quint32*>(buffer);
     318    const quint32p *src = reinterpret_cast<const quint32p*>(buffer);
    374319    while (length--)
    375320        *dest++ = DST(*src++);
    376321}
    377322
    378 #if defined(Q_CC_MSVC) && _MSC_VER <= 1300 && !defined(Q_CC_INTEL)
    379 # define DEST_STORE_DECL(DST)                                           \
    380     static void QT_FASTCALL destStore_##DST(QRasterBuffer *rasterBuffer, \
    381                                             int x, int y,               \
    382                                             const uint *buffer, int length) \
    383     {                                                                   \
    384         destStore<DST>(rasterBuffer, x, y, buffer, length Q_TEMPLATE_CALL(DST));             \
    385     }
    386 
    387 DEST_STORE_DECL(qargb8565)
    388 DEST_STORE_DECL(qrgb555)
    389 DEST_STORE_DECL(qrgb666)
    390 DEST_STORE_DECL(qargb6666)
    391 DEST_STORE_DECL(qargb8555)
    392 DEST_STORE_DECL(qrgb888)
    393 DEST_STORE_DECL(qrgb444)
    394 DEST_STORE_DECL(qargb4444)
    395 # undef DEST_FETCH_DECL
    396 # define SPANFUNC_POINTER_DESTSTORE(DEST) destStore_##DEST
    397 #else // !VC6 && !VC2002
    398323# define SPANFUNC_POINTER_DESTSTORE(DEST) destStore<DEST>
    399 #endif
    400324
    401325static const DestStoreProc destStoreProc[QImage::NImageFormats] =
     
    426350  We need 5 fetch methods per surface type:
    427351  untransformed
    428   transformed
    429   transformed tiled
    430   transformed bilinear
    431   transformed bilinear tiled
     352  transformed (tiled and not tiled)
     353  transformed bilinear (tiled and not tiled)
    432354
    433355  We don't need bounds checks for untransformed, but we need them for the other ones.
     
    437359
    438360template <QImage::Format format>
    439 Q_STATIC_TEMPLATE_FUNCTION uint QT_FASTCALL qt_fetchPixel(const uchar *scanLine, int x, const QVector<QRgb> *rgb
    440                                    Q_TEMPLATE_IMAGEFORMAT_FIX(format));
     361Q_STATIC_TEMPLATE_FUNCTION uint QT_FASTCALL qt_fetchPixel(const uchar *scanLine, int x, const QVector<QRgb> *rgb);
    441362
    442363template<>
    443364Q_STATIC_TEMPLATE_SPECIALIZATION
    444365uint QT_FASTCALL qt_fetchPixel<QImage::Format_Mono>(const uchar *scanLine,
    445                                                  int x, const QVector<QRgb> *rgb
    446                                                  Q_TEMPLATE_IMAGEFORMAT_FIX(QImage::Format_Mono))
     366                                                 int x, const QVector<QRgb> *rgb)
    447367{
    448368    bool pixel = scanLine[x>>3] & (0x80 >> (x & 7));
     
    454374Q_STATIC_TEMPLATE_SPECIALIZATION
    455375uint QT_FASTCALL qt_fetchPixel<QImage::Format_MonoLSB>(const uchar *scanLine,
    456                                                     int x, const QVector<QRgb> *rgb
    457                                                     Q_TEMPLATE_IMAGEFORMAT_FIX(QImage::Format_MonoLSB))
     376                                                    int x, const QVector<QRgb> *rgb)
    458377{
    459378    bool pixel = scanLine[x>>3] & (0x1 << (x & 7));
     
    465384Q_STATIC_TEMPLATE_SPECIALIZATION
    466385uint QT_FASTCALL qt_fetchPixel<QImage::Format_Indexed8>(const uchar *scanLine,
    467                                                      int x, const QVector<QRgb> *rgb
    468                                                      Q_TEMPLATE_IMAGEFORMAT_FIX(QImage::Format_Indexed8))
     386                                                     int x, const QVector<QRgb> *rgb)
    469387{
    470388    return PREMUL(rgb->at(scanLine[x]));
     
    474392Q_STATIC_TEMPLATE_SPECIALIZATION
    475393uint QT_FASTCALL qt_fetchPixel<QImage::Format_ARGB32>(const uchar *scanLine,
    476                                                    int x, const QVector<QRgb> *
    477                                                    Q_TEMPLATE_IMAGEFORMAT_FIX(QImage::Format_ARGB32))
     394                                                   int x, const QVector<QRgb> *)
    478395{
    479396    return PREMUL(((const uint *)scanLine)[x]);
     
    483400Q_STATIC_TEMPLATE_SPECIALIZATION
    484401uint QT_FASTCALL qt_fetchPixel<QImage::Format_ARGB32_Premultiplied>(const uchar *scanLine,
    485                                                                  int x, const QVector<QRgb> *
    486                                                                  Q_TEMPLATE_IMAGEFORMAT_FIX(QImage::Format_ARGB32_Premultiplied))
     402                                                                 int x, const QVector<QRgb> *)
    487403{
    488404    return ((const uint *)scanLine)[x];
     
    492408Q_STATIC_TEMPLATE_SPECIALIZATION
    493409uint QT_FASTCALL qt_fetchPixel<QImage::Format_RGB16>(const uchar *scanLine,
    494                                                   int x, const QVector<QRgb> *
    495                                                   Q_TEMPLATE_IMAGEFORMAT_FIX(QImage::Format_RGB16))
     410                                                  int x, const QVector<QRgb> *)
    496411{
    497412    return qConvertRgb16To32(((const ushort *)scanLine)[x]);
     
    502417uint QT_FASTCALL qt_fetchPixel<QImage::Format_ARGB8565_Premultiplied>(const uchar *scanLine,
    503418                                                     int x,
    504                                                      const QVector<QRgb> *
    505                                                      Q_TEMPLATE_IMAGEFORMAT_FIX(QImage::Format_ARGB8565_Premultiplied))
     419                                                     const QVector<QRgb> *)
    506420{
    507421    const qargb8565 color = reinterpret_cast<const qargb8565*>(scanLine)[x];
     
    513427uint QT_FASTCALL qt_fetchPixel<QImage::Format_RGB666>(const uchar *scanLine,
    514428                                                   int x,
    515                                                    const QVector<QRgb> *
    516                                                    Q_TEMPLATE_IMAGEFORMAT_FIX(QImage::Format_RGB666))
     429                                                   const QVector<QRgb> *)
    517430{
    518431    const qrgb666 color = reinterpret_cast<const qrgb666*>(scanLine)[x];
     
    524437uint QT_FASTCALL qt_fetchPixel<QImage::Format_ARGB6666_Premultiplied>(const uchar *scanLine,
    525438                                                   int x,
    526                                                    const QVector<QRgb> *
    527                                                    Q_TEMPLATE_IMAGEFORMAT_FIX(QImage::Format_ARGB6666_Premultiplied))
     439                                                   const QVector<QRgb> *)
    528440{
    529441    const qargb6666 color = reinterpret_cast<const qargb6666*>(scanLine)[x];
     
    535447uint QT_FASTCALL qt_fetchPixel<QImage::Format_RGB555>(const uchar *scanLine,
    536448                                                   int x,
    537                                                    const QVector<QRgb> *
    538                                                    Q_TEMPLATE_IMAGEFORMAT_FIX(QImage::Format_RGB555))
     449                                                   const QVector<QRgb> *)
    539450{
    540451    const qrgb555 color = reinterpret_cast<const qrgb555*>(scanLine)[x];
     
    546457uint QT_FASTCALL qt_fetchPixel<QImage::Format_ARGB8555_Premultiplied>(const uchar *scanLine,
    547458                                                     int x,
    548                                                      const QVector<QRgb> *
    549                                                      Q_TEMPLATE_IMAGEFORMAT_FIX(QImage::Format_ARGB8555_Premultiplied))
     459                                                     const QVector<QRgb> *)
    550460{
    551461    const qargb8555 color = reinterpret_cast<const qargb8555*>(scanLine)[x];
     
    557467uint QT_FASTCALL qt_fetchPixel<QImage::Format_RGB888>(const uchar *scanLine,
    558468                                                   int x,
    559                                                    const QVector<QRgb> *
    560                                                    Q_TEMPLATE_IMAGEFORMAT_FIX(QImage::Format_RGB888))
     469                                                   const QVector<QRgb> *)
    561470{
    562471    const qrgb888 color = reinterpret_cast<const qrgb888*>(scanLine)[x];
     
    568477uint QT_FASTCALL qt_fetchPixel<QImage::Format_RGB444>(const uchar *scanLine,
    569478                                                   int x,
    570                                                    const QVector<QRgb> *
    571                                                    Q_TEMPLATE_IMAGEFORMAT_FIX(QImage::Format_RGB444))
     479                                                   const QVector<QRgb> *)
    572480{
    573481    const qrgb444 color = reinterpret_cast<const qrgb444*>(scanLine)[x];
     
    579487uint QT_FASTCALL qt_fetchPixel<QImage::Format_ARGB4444_Premultiplied>(const uchar *scanLine,
    580488                                                     int x,
    581                                                      const QVector<QRgb> *
    582                                                      Q_TEMPLATE_IMAGEFORMAT_FIX(QImage::Format_ARGB4444_Premultiplied))
     489                                                     const QVector<QRgb> *)
    583490{
    584491    const qargb4444 color = reinterpret_cast<const qargb4444*>(scanLine)[x];
     
    586493}
    587494
     495template<>
     496Q_STATIC_TEMPLATE_SPECIALIZATION
     497uint QT_FASTCALL qt_fetchPixel<QImage::Format_Invalid>(const uchar *,
     498                                                     int ,
     499                                                     const QVector<QRgb> *)
     500{
     501    return 0;
     502}
     503
    588504typedef uint (QT_FASTCALL *FetchPixelProc)(const uchar *scanLine, int x, const QVector<QRgb> *);
    589505
    590 #if defined(Q_CC_MSVC) && _MSC_VER <= 1300 && !defined(Q_CC_INTEL)
    591 
    592 // explicit template instantiations needed to compile with VC6 and VC2002
    593 
    594 #define SPANFUNC_INSTANTIATION_FETCHPIXEL(Arg)  \
    595         static inline uint fetchPixel_##Arg(const uchar * scanLine, int x, const QVector<QRgb> * rgb) \
    596 { \
    597         return qt_fetchPixel<QImage::Arg>(scanLine, x, rgb Q_TEMPLATE_IMAGEFORMAT_CALL(QImage::Arg)); \
    598 }
    599 
    600 SPANFUNC_INSTANTIATION_FETCHPIXEL(Format_Mono);
    601 SPANFUNC_INSTANTIATION_FETCHPIXEL(Format_MonoLSB);
    602 SPANFUNC_INSTANTIATION_FETCHPIXEL(Format_Indexed8);
    603 SPANFUNC_INSTANTIATION_FETCHPIXEL(Format_ARGB32_Premultiplied);
    604 SPANFUNC_INSTANTIATION_FETCHPIXEL(Format_ARGB32);
    605 SPANFUNC_INSTANTIATION_FETCHPIXEL(Format_RGB16);
    606 SPANFUNC_INSTANTIATION_FETCHPIXEL(Format_ARGB8565_Premultiplied);
    607 SPANFUNC_INSTANTIATION_FETCHPIXEL(Format_RGB666);
    608 SPANFUNC_INSTANTIATION_FETCHPIXEL(Format_ARGB6666_Premultiplied);
    609 SPANFUNC_INSTANTIATION_FETCHPIXEL(Format_RGB555);
    610 SPANFUNC_INSTANTIATION_FETCHPIXEL(Format_ARGB8555_Premultiplied);
    611 SPANFUNC_INSTANTIATION_FETCHPIXEL(Format_RGB888);
    612 SPANFUNC_INSTANTIATION_FETCHPIXEL(Format_RGB444);
    613 SPANFUNC_INSTANTIATION_FETCHPIXEL(Format_ARGB4444_Premultiplied);
    614 
    615 #undef SPANFUNC_INSTANTIATION_FETCHPIXEL
    616 
    617 #define SPANFUNC_POINTER_FETCHPIXEL(Arg) fetchPixel_##Arg
    618 
    619 #else // !VC6 && !VC2002
    620 # define SPANFUNC_POINTER_FETCHPIXEL(Arg) qt_fetchPixel<QImage::Arg>
    621 #endif
     506#define SPANFUNC_POINTER_FETCHPIXEL(Arg) qt_fetchPixel<QImage::Arg>
    622507
    623508
     
    654539template <QImage::Format format>
    655540Q_STATIC_TEMPLATE_FUNCTION const uint * QT_FASTCALL qt_fetchUntransformed(uint *buffer, const Operator *, const QSpanData *data,
    656                                              int y, int x, int length Q_TEMPLATE_IMAGEFORMAT_FIX(format))
     541                                             int y, int x, int length)
    657542{
    658543    const uchar *scanLine = data->texture.scanLine(y);
    659544    for (int i = 0; i < length; ++i)
    660         buffer[i] = qt_fetchPixel<format>(scanLine, x + i, data->texture.colorTable Q_TEMPLATE_IMAGEFORMAT_CALL(format));
     545        buffer[i] = qt_fetchPixel<format>(scanLine, x + i, data->texture.colorTable);
    661546    return buffer;
    662547}
     
    666551qt_fetchUntransformed<QImage::Format_ARGB32_Premultiplied>(uint *, const Operator *,
    667552                                                         const QSpanData *data,
    668                                                          int y, int x, int Q_TEMPLATE_IMAGEFORMAT_FIX(QImage::Format_ARGB32_Premultiplied))
     553                                                         int y, int x, int)
    669554{
    670555    const uchar *scanLine = data->texture.scanLine(y);
     
    672557}
    673558
    674 static const uint * QT_FASTCALL fetchTransformed(uint *buffer, const Operator *, const QSpanData *data,
     559template<TextureBlendType blendType>  /* either BlendTransformed or BlendTransformedTiled */
     560Q_STATIC_TEMPLATE_FUNCTION
     561const uint * QT_FASTCALL fetchTransformed(uint *buffer, const Operator *, const QSpanData *data,
    675562                                                         int y, int x, int length)
    676563{
     
    699586            int py = fy >> 16;
    700587
    701             bool out = (px < 0) || (px >= image_width)
    702                        || (py < 0) || (py >= image_height);
    703 
    704             const uchar *scanLine = data->texture.scanLine(py);
    705             *b = out ? uint(0) : fetch(scanLine, px, data->texture.colorTable);
     588            if (blendType == BlendTransformedTiled) {
     589                px %= image_width;
     590                py %= image_height;
     591                if (px < 0) px += image_width;
     592                if (py < 0) py += image_height;
     593
     594                const uchar *scanLine = data->texture.scanLine(py);
     595                *b = fetch(scanLine, px, data->texture.colorTable);
     596            } else {
     597                if ((px < 0) || (px >= image_width)
     598                    || (py < 0) || (py >= image_height)) {
     599                    *b = uint(0);
     600                } else {
     601                    const uchar *scanLine = data->texture.scanLine(py);
     602                    *b = fetch(scanLine, px, data->texture.colorTable);
     603                }
     604            }
    706605            fx += fdx;
    707606            fy += fdy;
     
    721620            const qreal tx = fx * iw;
    722621            const qreal ty = fy * iw;
    723             const int px = int(tx) - (tx < 0);
    724             const int py = int(ty) - (ty < 0);
    725 
    726             bool out = (px < 0) || (px >= image_width)
    727                        || (py < 0) || (py >= image_height);
    728 
    729             const uchar *scanLine = data->texture.scanLine(py);
    730             *b = out ? uint(0) : fetch(scanLine, px, data->texture.colorTable);
     622            int px = int(tx) - (tx < 0);
     623            int py = int(ty) - (ty < 0);
     624
     625            if (blendType == BlendTransformedTiled) {
     626                px %= image_width;
     627                py %= image_height;
     628                if (px < 0) px += image_width;
     629                if (py < 0) py += image_height;
     630
     631                const uchar *scanLine = data->texture.scanLine(py);
     632                *b = fetch(scanLine, px, data->texture.colorTable);
     633            } else {
     634                if ((px < 0) || (px >= image_width)
     635                    || (py < 0) || (py >= image_height)) {
     636                    *b = uint(0);
     637                } else {
     638                    const uchar *scanLine = data->texture.scanLine(py);
     639                    *b = fetch(scanLine, px, data->texture.colorTable);
     640                }
     641            }
    731642            fx += fdx;
    732643            fy += fdy;
     
    743654}
    744655
    745 static const uint * QT_FASTCALL fetchTransformedTiled(uint *buffer, const Operator *, const QSpanData *data,
    746                                                               int y, int x, int length)
    747 {
    748     FetchPixelProc fetch = fetchPixelProc[data->texture.format];
     656template<TextureBlendType blendType, QImage::Format format> /* blendType = BlendTransformedBilinear or BlendTransformedBilinearTiled */
     657Q_STATIC_TEMPLATE_FUNCTION
     658const uint * QT_FASTCALL fetchTransformedBilinear(uint *buffer, const Operator *, const QSpanData *data,
     659                                                  int y, int x, int length)
     660{
     661#ifdef Q_CC_RVCT // needed to avoid compiler crash in RVCT 2.2
     662    FetchPixelProc fetch;
     663    if (format != QImage::Format_Invalid)
     664        fetch = qt_fetchPixel<format>;
     665    else
     666        fetch = fetchPixelProc[data->texture.format];
     667#else
     668    FetchPixelProc fetch = (format != QImage::Format_Invalid) ? FetchPixelProc(qt_fetchPixel<format>) : fetchPixelProc[data->texture.format];
     669#endif
    749670
    750671    int image_width = data->texture.width;
     
    766687                      + data->m12 * cx + data->dy) * fixed_scale);
    767688
     689        fx -= half_point;
     690        fy -= half_point;
    768691        while (b < end) {
    769             int px = fx >> 16;
    770             int py = fy >> 16;
    771 
    772             px %= image_width;
    773             py %= image_height;
    774             if (px < 0) px += image_width;
    775             if (py < 0) py += image_height;
    776 
    777             const uchar *scanLine = data->texture.scanLine(py);
    778             *b = fetch(scanLine, px, data->texture.colorTable);
     692            int x1 = (fx >> 16);
     693            int x2 = x1 + 1;
     694            int y1 = (fy >> 16);
     695            int y2 = y1 + 1;
     696
     697            int distx = ((fx - (x1 << 16)) >> 8);
     698            int disty = ((fy - (y1 << 16)) >> 8);
     699            int idistx = 256 - distx;
     700            int idisty = 256 - disty;
     701
     702            if (blendType == BlendTransformedBilinearTiled) {
     703                x1 %= image_width;
     704                x2 %= image_width;
     705                y1 %= image_height;
     706                y2 %= image_height;
     707
     708                if (x1 < 0) x1 += image_width;
     709                if (x2 < 0) x2 += image_width;
     710                if (y1 < 0) y1 += image_height;
     711                if (y2 < 0) y2 += image_height;
     712
     713                Q_ASSERT(x1 >= 0 && x1 < image_width);
     714                Q_ASSERT(x2 >= 0 && x2 < image_width);
     715                Q_ASSERT(y1 >= 0 && y1 < image_height);
     716                Q_ASSERT(y2 >= 0 && y2 < image_height);
     717            } else {
     718                x1 = qBound(0, x1, image_width - 1);
     719                x2 = qBound(0, x2, image_width - 1);
     720                y1 = qBound(0, y1, image_height - 1);
     721                y2 = qBound(0, y2, image_height - 1);
     722            }
     723
     724            const uchar *s1 = data->texture.scanLine(y1);
     725            const uchar *s2 = data->texture.scanLine(y2);
     726
     727            uint tl = fetch(s1, x1, data->texture.colorTable);
     728            uint tr = fetch(s1, x2, data->texture.colorTable);
     729            uint bl = fetch(s2, x1, data->texture.colorTable);
     730            uint br = fetch(s2, x2, data->texture.colorTable);
     731
     732            uint xtop = INTERPOLATE_PIXEL_256(tl, idistx, tr, distx);
     733            uint xbot = INTERPOLATE_PIXEL_256(bl, idistx, br, distx);
     734            *b = INTERPOLATE_PIXEL_256(xtop, idisty, xbot, disty);
     735
    779736            fx += fdx;
    780737            fy += fdy;
     
    792749        while (b < end) {
    793750            const qreal iw = fw == 0 ? 1 : 1 / fw;
    794             const qreal tx = fx * iw;
    795             const qreal ty = fy * iw;
    796             int px = int(tx) - (tx < 0);
    797             int py = int(ty) - (ty < 0);
    798 
    799             px %= image_width;
    800             py %= image_height;
    801             if (px < 0) px += image_width;
    802             if (py < 0) py += image_height;
    803 
    804             const uchar *scanLine = data->texture.scanLine(py);
    805             *b = fetch(scanLine, px, data->texture.colorTable);
     751            const qreal px = fx * iw - 0.5;
     752            const qreal py = fy * iw - 0.5;
     753
     754            int x1 = int(px) - (px < 0);
     755            int x2 = x1 + 1;
     756            int y1 = int(py) - (py < 0);
     757            int y2 = y1 + 1;
     758
     759            int distx = int((px - x1) * 256);
     760            int disty = int((py - y1) * 256);
     761            int idistx = 256 - distx;
     762            int idisty = 256 - disty;
     763
     764            if (blendType == BlendTransformedBilinearTiled) {
     765                x1 %= image_width;
     766                x2 %= image_width;
     767                y1 %= image_height;
     768                y2 %= image_height;
     769
     770                if (x1 < 0) x1 += image_width;
     771                if (x2 < 0) x2 += image_width;
     772                if (y1 < 0) y1 += image_height;
     773                if (y2 < 0) y2 += image_height;
     774
     775                Q_ASSERT(x1 >= 0 && x1 < image_width);
     776                Q_ASSERT(x2 >= 0 && x2 < image_width);
     777                Q_ASSERT(y1 >= 0 && y1 < image_height);
     778                Q_ASSERT(y2 >= 0 && y2 < image_height);
     779            } else {
     780                x1 = qBound(0, x1, image_width - 1);
     781                x2 = qBound(0, x2, image_width - 1);
     782                y1 = qBound(0, y1, image_height - 1);
     783                y2 = qBound(0, y2, image_height - 1);
     784            }
     785
     786            const uchar *s1 = data->texture.scanLine(y1);
     787            const uchar *s2 = data->texture.scanLine(y2);
     788
     789            uint tl = fetch(s1, x1, data->texture.colorTable);
     790            uint tr = fetch(s1, x2, data->texture.colorTable);
     791            uint bl = fetch(s2, x1, data->texture.colorTable);
     792            uint br = fetch(s2, x2, data->texture.colorTable);
     793
     794            uint xtop = INTERPOLATE_PIXEL_256(tl, idistx, tr, distx);
     795            uint xbot = INTERPOLATE_PIXEL_256(bl, idistx, br, distx);
     796            *b = INTERPOLATE_PIXEL_256(xtop, idisty, xbot, disty);
     797
    806798            fx += fdx;
    807799            fy += fdy;
     
    818810}
    819811
    820 static const uint * QT_FASTCALL fetchTransformedBilinear(uint *buffer, const Operator *, const QSpanData *data,
    821                                                                  int y, int x, int length)
    822 {
    823     FetchPixelProc fetch = fetchPixelProc[data->texture.format];
    824 
    825     int image_width = data->texture.width;
    826     int image_height = data->texture.height;
    827 
    828     const qreal cx = x + 0.5;
    829     const qreal cy = y + 0.5;
    830 
    831     const uint *end = buffer + length;
    832     uint *b = buffer;
    833     if (data->fast_matrix) {
    834         // The increment pr x in the scanline
    835         int fdx = (int)(data->m11 * fixed_scale);
    836         int fdy = (int)(data->m12 * fixed_scale);
    837 
    838         int fx = int((data->m21 * cy
    839                       + data->m11 * cx + data->dx) * fixed_scale);
    840         int fy = int((data->m22 * cy
    841                       + data->m12 * cx + data->dy) * fixed_scale);
    842 
    843         fx -= half_point;
    844         fy -= half_point;
    845         while (b < end) {
    846             int x1 = (fx >> 16);
    847             int x2 = x1 + 1;
    848             int y1 = (fy >> 16);
    849             int y2 = y1 + 1;
    850 
    851             int distx = ((fx - (x1 << 16)) >> 8);
    852             int disty = ((fy - (y1 << 16)) >> 8);
    853             int idistx = 256 - distx;
    854             int idisty = 256 - disty;
    855 
    856             x1 = qBound(0, x1, image_width - 1);
    857             x2 = qBound(0, x2, image_width - 1);
    858             y1 = qBound(0, y1, image_height - 1);
    859             y2 = qBound(0, y2, image_height - 1);
    860 
    861             const uchar *s1 = data->texture.scanLine(y1);
    862             const uchar *s2 = data->texture.scanLine(y2);
    863 
    864             uint tl = fetch(s1, x1, data->texture.colorTable);
    865             uint tr = fetch(s1, x2, data->texture.colorTable);
    866             uint bl = fetch(s2, x1, data->texture.colorTable);
    867             uint br = fetch(s2, x2, data->texture.colorTable);
    868 
    869             uint xtop = INTERPOLATE_PIXEL_256(tl, idistx, tr, distx);
    870             uint xbot = INTERPOLATE_PIXEL_256(bl, idistx, br, distx);
    871             *b = INTERPOLATE_PIXEL_256(xtop, idisty, xbot, disty);
    872 
    873             fx += fdx;
    874             fy += fdy;
    875             ++b;
    876         }
    877     } else {
    878         const qreal fdx = data->m11;
    879         const qreal fdy = data->m12;
    880         const qreal fdw = data->m13;
    881 
    882         qreal fx = data->m21 * cy + data->m11 * cx + data->dx;
    883         qreal fy = data->m22 * cy + data->m12 * cx + data->dy;
    884         qreal fw = data->m23 * cy + data->m13 * cx + data->m33;
    885 
    886         while (b < end) {
    887             const qreal iw = fw == 0 ? 1 : 1 / fw;
    888             const qreal px = fx * iw - 0.5;
    889             const qreal py = fy * iw - 0.5;
    890 
    891             int x1 = int(px) - (px < 0);
    892             int x2 = x1 + 1;
    893             int y1 = int(py) - (py < 0);
    894             int y2 = y1 + 1;
    895 
    896             int distx = int((px - x1) * 256);
    897             int disty = int((py - y1) * 256);
    898             int idistx = 256 - distx;
    899             int idisty = 256 - disty;
    900 
    901             x1 = qBound(0, x1, image_width - 1);
    902             x2 = qBound(0, x2, image_width - 1);
    903             y1 = qBound(0, y1, image_height - 1);
    904             y2 = qBound(0, y2, image_height - 1);
    905 
    906             const uchar *s1 = data->texture.scanLine(y1);
    907             const uchar *s2 = data->texture.scanLine(y2);
    908 
    909             uint tl = fetch(s1, x1, data->texture.colorTable);
    910             uint tr = fetch(s1, x2, data->texture.colorTable);
    911             uint bl = fetch(s2, x1, data->texture.colorTable);
    912             uint br = fetch(s2, x2, data->texture.colorTable);
    913 
    914             uint xtop = INTERPOLATE_PIXEL_256(tl, idistx, tr, distx);
    915             uint xbot = INTERPOLATE_PIXEL_256(bl, idistx, br, distx);
    916             *b = INTERPOLATE_PIXEL_256(xtop, idisty, xbot, disty);
    917 
    918             fx += fdx;
    919             fy += fdy;
    920             fw += fdw;
    921             //force increment to avoid /0
    922             if (!fw) {
    923                 fw += fdw;
    924             }
    925             ++b;
    926         }
    927     }
    928 
    929     return buffer;
    930 }
    931 
    932 static const uint * QT_FASTCALL fetchTransformedBilinearTiled(uint *buffer, const Operator *, const QSpanData *data,
    933                                                                      int y, int x, int length)
    934 {
    935     FetchPixelProc fetch = fetchPixelProc[data->texture.format];
    936 
    937     int image_width = data->texture.width;
    938     int image_height = data->texture.height;
    939 
    940     const qreal cx = x + 0.5;
    941     const qreal cy = y + 0.5;
    942 
    943     const uint *end = buffer + length;
    944     uint *b = buffer;
    945     if (data->fast_matrix) {
    946         // The increment pr x in the scanline
    947         int fdx = (int)(data->m11 * fixed_scale);
    948         int fdy = (int)(data->m12 * fixed_scale);
    949 
    950         int fx = int((data->m21 * cy + data->m11 * cx + data->dx) * fixed_scale);
    951         int fy = int((data->m22 * cy + data->m12 * cx + data->dy) * fixed_scale);
    952 
    953         fx -= half_point;
    954         fy -= half_point;
    955         while (b < end) {
    956             int x1 = (fx >> 16);
    957             int x2 = x1 + 1;
    958             int y1 = (fy >> 16);
    959             int y2 = y1 + 1;
    960 
    961             int distx = ((fx - (x1 << 16)) >> 8);
    962             int disty = ((fy - (y1 << 16)) >> 8);
    963             int idistx = 256 - distx;
    964             int idisty = 256 - disty;
    965 
    966             x1 %= image_width;
    967             x2 %= image_width;
    968             y1 %= image_height;
    969             y2 %= image_height;
    970 
    971             if (x1 < 0) x1 += image_width;
    972             if (x2 < 0) x2 += image_width;
    973             if (y1 < 0) y1 += image_height;
    974             if (y2 < 0) y2 += image_height;
    975 
    976             Q_ASSERT(x1 >= 0 && x1 < image_width);
    977             Q_ASSERT(x2 >= 0 && x2 < image_width);
    978             Q_ASSERT(y1 >= 0 && y1 < image_height);
    979             Q_ASSERT(y2 >= 0 && y2 < image_height);
    980 
    981             const uchar *s1 = data->texture.scanLine(y1);
    982             const uchar *s2 = data->texture.scanLine(y2);
    983 
    984             uint tl = fetch(s1, x1, data->texture.colorTable);
    985             uint tr = fetch(s1, x2, data->texture.colorTable);
    986             uint bl = fetch(s2, x1, data->texture.colorTable);
    987             uint br = fetch(s2, x2, data->texture.colorTable);
    988 
    989             uint xtop = INTERPOLATE_PIXEL_256(tl, idistx, tr, distx);
    990             uint xbot = INTERPOLATE_PIXEL_256(bl, idistx, br, distx);
    991             *b = INTERPOLATE_PIXEL_256(xtop, idisty, xbot, disty);
    992 
    993             fx += fdx;
    994             fy += fdy;
    995             ++b;
    996         }
    997     } else {
    998         const qreal fdx = data->m11;
    999         const qreal fdy = data->m12;
    1000         const qreal fdw = data->m13;
    1001 
    1002         qreal fx = data->m21 * cy + data->m11 * cx + data->dx;
    1003         qreal fy = data->m22 * cy + data->m12 * cx + data->dy;
    1004         qreal fw = data->m23 * cy + data->m13 * cx + data->m33;
    1005 
    1006         while (b < end) {
    1007             const qreal iw = fw == 0 ? 1 : 1 / fw;
    1008             const qreal px = fx * iw - 0.5;
    1009             const qreal py = fy * iw - 0.5;
    1010 
    1011             int x1 = int(px) - (px < 0);
    1012             int x2 = x1 + 1;
    1013             int y1 = int(py) - (py < 0);
    1014             int y2 = y1 + 1;
    1015 
    1016             int distx = int((px - x1) * 256);
    1017             int disty = int((py - y1) * 256);
    1018             int idistx = 256 - distx;
    1019             int idisty = 256 - disty;
    1020 
    1021             x1 %= image_width;
    1022             x2 %= image_width;
    1023             y1 %= image_height;
    1024             y2 %= image_height;
    1025 
    1026             if (x1 < 0) x1 += image_width;
    1027             if (x2 < 0) x2 += image_width;
    1028             if (y1 < 0) y1 += image_height;
    1029             if (y2 < 0) y2 += image_height;
    1030 
    1031             Q_ASSERT(x1 >= 0 && x1 < image_width);
    1032             Q_ASSERT(x2 >= 0 && x2 < image_width);
    1033             Q_ASSERT(y1 >= 0 && y1 < image_height);
    1034             Q_ASSERT(y2 >= 0 && y2 < image_height);
    1035 
    1036             const uchar *s1 = data->texture.scanLine(y1);
    1037             const uchar *s2 = data->texture.scanLine(y2);
    1038 
    1039             uint tl = fetch(s1, x1, data->texture.colorTable);
    1040             uint tr = fetch(s1, x2, data->texture.colorTable);
    1041             uint bl = fetch(s2, x1, data->texture.colorTable);
    1042             uint br = fetch(s2, x2, data->texture.colorTable);
    1043 
    1044             uint xtop = INTERPOLATE_PIXEL_256(tl, idistx, tr, distx);
    1045             uint xbot = INTERPOLATE_PIXEL_256(bl, idistx, br, distx);
    1046             *b = INTERPOLATE_PIXEL_256(xtop, idisty, xbot, disty);
    1047 
    1048             fx += fdx;
    1049             fy += fdy;
    1050             fw += fdw;
    1051             //force increment to avoid /0
    1052             if (!fw) {
    1053                 fw += fdw;
    1054             }
    1055             ++b;
    1056         }
    1057     }
    1058 
    1059     return buffer;
    1060 }
    1061 
    1062 #if defined(Q_CC_MSVC) && _MSC_VER <= 1300 && !defined(Q_CC_INTEL)
    1063 
    1064 // explicit template instantiations needed to compile with VC6 and VC2002
    1065 
    1066 #define SPANFUNC_POINTER_FETCHUNTRANSFORMED(Arg)  \
    1067         const uint *qt_fetchUntransformed_##Arg(uint *buffer, const Operator *op, const QSpanData *data, \
    1068                                              int y, int x, int length) \
    1069 { \
    1070         return qt_fetchUntransformed<QImage::Arg>(buffer, op, data, y, x, length Q_TEMPLATE_IMAGEFORMAT_CALL(QImage::Arg)); \
    1071 }
    1072 
    1073 SPANFUNC_POINTER_FETCHUNTRANSFORMED(Format_Mono);
    1074 SPANFUNC_POINTER_FETCHUNTRANSFORMED(Format_MonoLSB);
    1075 SPANFUNC_POINTER_FETCHUNTRANSFORMED(Format_Indexed8);
    1076 SPANFUNC_POINTER_FETCHUNTRANSFORMED(Format_ARGB32_Premultiplied);
    1077 SPANFUNC_POINTER_FETCHUNTRANSFORMED(Format_ARGB32);
    1078 SPANFUNC_POINTER_FETCHUNTRANSFORMED(Format_RGB16);
    1079 SPANFUNC_POINTER_FETCHUNTRANSFORMED(Format_ARGB8565_Premultiplied);
    1080 SPANFUNC_POINTER_FETCHUNTRANSFORMED(Format_RGB666);
    1081 SPANFUNC_POINTER_FETCHUNTRANSFORMED(Format_ARGB6666_Premultiplied);
    1082 SPANFUNC_POINTER_FETCHUNTRANSFORMED(Format_RGB555);
    1083 SPANFUNC_POINTER_FETCHUNTRANSFORMED(Format_ARGB8555_Premultiplied);
    1084 SPANFUNC_POINTER_FETCHUNTRANSFORMED(Format_RGB888);
    1085 SPANFUNC_POINTER_FETCHUNTRANSFORMED(Format_RGB444);
    1086 SPANFUNC_POINTER_FETCHUNTRANSFORMED(Format_ARGB4444_Premultiplied);
    1087 
    1088 #undef SPANFUNC_POINTER_FETCHUNTRANSFORMED
    1089 
    1090 #define SPANFUNC_POINTER_FETCHHUNTRANSFORMED(Arg) qt_fetchUntransformed_##Arg
    1091 
    1092 #else // !VC6 && !VC2002
    1093 # define SPANFUNC_POINTER_FETCHHUNTRANSFORMED(Arg) qt_fetchUntransformed<QImage::Arg>
    1094 #endif
     812#define SPANFUNC_POINTER_FETCHHUNTRANSFORMED(Arg) qt_fetchUntransformed<QImage::Arg>
    1095813
    1096814static const SourceFetchProc sourceFetch[NBlendTypes][QImage::NImageFormats] = {
     
    1136854    {
    1137855        0, // Invalid
    1138         fetchTransformed,   // Mono
    1139         fetchTransformed,   // MonoLsb
    1140         fetchTransformed,   // Indexed8
    1141         fetchTransformed,   // RGB32
    1142         fetchTransformed,   // ARGB32
    1143         fetchTransformed,   // ARGB32_Premultiplied
    1144         fetchTransformed,   // RGB16
    1145         fetchTransformed,   // ARGB8565_Premultiplied
    1146         fetchTransformed,   // RGB666
    1147         fetchTransformed,   // ARGB6666_Premultiplied
    1148         fetchTransformed,   // RGB555
    1149         fetchTransformed,   // ARGB8555_Premultiplied
    1150         fetchTransformed,   // RGB888
    1151         fetchTransformed,   // RGB444
    1152         fetchTransformed,   // ARGB4444_Premultiplied
     856        fetchTransformed<BlendTransformed>,   // Mono
     857        fetchTransformed<BlendTransformed>,   // MonoLsb
     858        fetchTransformed<BlendTransformed>,   // Indexed8
     859        fetchTransformed<BlendTransformed>,   // RGB32
     860        fetchTransformed<BlendTransformed>,   // ARGB32
     861        fetchTransformed<BlendTransformed>,   // ARGB32_Premultiplied
     862        fetchTransformed<BlendTransformed>,   // RGB16
     863        fetchTransformed<BlendTransformed>,   // ARGB8565_Premultiplied
     864        fetchTransformed<BlendTransformed>,   // RGB666
     865        fetchTransformed<BlendTransformed>,   // ARGB6666_Premultiplied
     866        fetchTransformed<BlendTransformed>,   // RGB555
     867        fetchTransformed<BlendTransformed>,   // ARGB8555_Premultiplied
     868        fetchTransformed<BlendTransformed>,   // RGB888
     869        fetchTransformed<BlendTransformed>,   // RGB444
     870        fetchTransformed<BlendTransformed>,   // ARGB4444_Premultiplied
    1153871    },
    1154872    {
    1155873        0, // TransformedTiled
    1156         fetchTransformedTiled,   // Mono
    1157         fetchTransformedTiled,   // MonoLsb
    1158         fetchTransformedTiled,   // Indexed8
    1159         fetchTransformedTiled,   // RGB32
    1160         fetchTransformedTiled,   // ARGB32
    1161         fetchTransformedTiled,   // ARGB32_Premultiplied
    1162         fetchTransformedTiled,   // RGB16
    1163         fetchTransformedTiled,   // ARGB8565_Premultiplied
    1164         fetchTransformedTiled,   // RGB666
    1165         fetchTransformedTiled,   // ARGB6666_Premultiplied
    1166         fetchTransformedTiled,   // RGB555
    1167         fetchTransformedTiled,   // ARGB8555_Premultiplied
    1168         fetchTransformedTiled,   // RGB888
    1169         fetchTransformedTiled,   // RGB444
    1170         fetchTransformedTiled,   // ARGB4444_Premultiplied
     874        fetchTransformed<BlendTransformedTiled>,   // Mono
     875        fetchTransformed<BlendTransformedTiled>,   // MonoLsb
     876        fetchTransformed<BlendTransformedTiled>,   // Indexed8
     877        fetchTransformed<BlendTransformedTiled>,   // RGB32
     878        fetchTransformed<BlendTransformedTiled>,   // ARGB32
     879        fetchTransformed<BlendTransformedTiled>,   // ARGB32_Premultiplied
     880        fetchTransformed<BlendTransformedTiled>,   // RGB16
     881        fetchTransformed<BlendTransformedTiled>,   // ARGB8565_Premultiplied
     882        fetchTransformed<BlendTransformedTiled>,   // RGB666
     883        fetchTransformed<BlendTransformedTiled>,   // ARGB6666_Premultiplied
     884        fetchTransformed<BlendTransformedTiled>,   // RGB555
     885        fetchTransformed<BlendTransformedTiled>,   // ARGB8555_Premultiplied
     886        fetchTransformed<BlendTransformedTiled>,   // RGB888
     887        fetchTransformed<BlendTransformedTiled>,   // RGB444
     888        fetchTransformed<BlendTransformedTiled>,   // ARGB4444_Premultiplied
    1171889    },
    1172890    {
    1173891        0, // Bilinear
    1174         fetchTransformedBilinear,   // Mono
    1175         fetchTransformedBilinear,   // MonoLsb
    1176         fetchTransformedBilinear,   // Indexed8
    1177         fetchTransformedBilinear,   // RGB32
    1178         fetchTransformedBilinear,   // ARGB32
    1179         fetchTransformedBilinear,   // ARGB32_Premultiplied
    1180         fetchTransformedBilinear,   // RGB16
    1181         fetchTransformedBilinear,   // ARGB8565_Premultiplied
    1182         fetchTransformedBilinear,   // RGB666
    1183         fetchTransformedBilinear,   // ARGB6666_Premultiplied
    1184         fetchTransformedBilinear,   // RGB555
    1185         fetchTransformedBilinear,   // ARGB8555_Premultiplied
    1186         fetchTransformedBilinear,   // RGB888
    1187         fetchTransformedBilinear,   // RGB444
    1188         fetchTransformedBilinear    // ARGB4444_Premultiplied
     892        fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_Invalid>,   // Mono
     893        fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_Invalid>,   // MonoLsb
     894        fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_Invalid>,   // Indexed8
     895        fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_ARGB32_Premultiplied>,   // RGB32
     896        fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_ARGB32>,   // ARGB32
     897        fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_ARGB32_Premultiplied>,   // ARGB32_Premultiplied
     898        fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_Invalid>,   // RGB16
     899        fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_Invalid>,   // ARGB8565_Premultiplied
     900        fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_Invalid>,   // RGB666
     901        fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_Invalid>,   // ARGB6666_Premultiplied
     902        fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_Invalid>,   // RGB555
     903        fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_Invalid>,   // ARGB8555_Premultiplied
     904        fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_Invalid>,   // RGB888
     905        fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_Invalid>,   // RGB444
     906        fetchTransformedBilinear<BlendTransformedBilinear, QImage::Format_Invalid>    // ARGB4444_Premultiplied
    1189907    },
    1190908    {
    1191909        0, // BilinearTiled
    1192         fetchTransformedBilinearTiled,   // Mono
    1193         fetchTransformedBilinearTiled,   // MonoLsb
    1194         fetchTransformedBilinearTiled,   // Indexed8
    1195         fetchTransformedBilinearTiled,   // RGB32
    1196         fetchTransformedBilinearTiled,   // ARGB32
    1197         fetchTransformedBilinearTiled,   // ARGB32_Premultiplied
    1198         fetchTransformedBilinearTiled,   // RGB16
    1199         fetchTransformedBilinearTiled,   // ARGB8565_Premultiplied
    1200         fetchTransformedBilinearTiled,   // RGB666
    1201         fetchTransformedBilinearTiled,   // ARGB6666_Premultiplied
    1202         fetchTransformedBilinearTiled,   // RGB555
    1203         fetchTransformedBilinearTiled,   // ARGB8555_Premultiplied
    1204         fetchTransformedBilinearTiled,   // RGB888
    1205         fetchTransformedBilinearTiled,   // RGB444
    1206         fetchTransformedBilinearTiled    // ARGB4444_Premultiplied
     910        fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_Invalid>,   // Mono
     911        fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_Invalid>,   // MonoLsb
     912        fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_Invalid>,   // Indexed8
     913        fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_ARGB32_Premultiplied>,   // RGB32
     914        fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_ARGB32>,   // ARGB32
     915        fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_ARGB32_Premultiplied>,   // ARGB32_Premultiplied
     916        fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_Invalid>,   // RGB16
     917        fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_Invalid>,   // ARGB8565_Premultiplied
     918        fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_Invalid>,   // RGB666
     919        fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_Invalid>,   // ARGB6666_Premultiplied
     920        fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_Invalid>,   // RGB555
     921        fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_Invalid>,   // ARGB8555_Premultiplied
     922        fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_Invalid>,   // RGB888
     923        fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_Invalid>,   // RGB444
     924        fetchTransformedBilinear<BlendTransformedBilinearTiled, QImage::Format_Invalid>    // ARGB4444_Premultiplied
    1207925    },
    1208926};
     
    14661184        ry -= data->gradient.conical.center.y;
    14671185        while (buffer < end) {
    1468             qreal angle = atan2(ry, rx) + data->gradient.conical.angle;
     1186            qreal angle = qAtan2(ry, rx) + data->gradient.conical.angle;
    14691187
    14701188            *buffer = qt_gradient_pixel(&data->gradient, 1 - angle / (2*Q_PI));
     
    14801198            rw = 1;
    14811199        while (buffer < end) {
    1482             qreal angle = atan2(ry/rw - data->gradient.conical.center.x,
     1200            qreal angle = qAtan2(ry/rw - data->gradient.conical.center.x,
    14831201                                rx/rw - data->gradient.conical.center.y)
    14841202                          + data->gradient.conical.angle;
     
    14981216}
    14991217
    1500 
     1218#if defined(Q_CC_RVCT)
     1219// Force ARM code generation for comp_func_* -methods
     1220#  pragma push
     1221#  pragma arm
     1222#  if defined(QT_HAVE_ARMV6)
     1223static __forceinline void preload(const uint *start)
     1224{
     1225    asm( "pld [start]" );
     1226}
     1227static const uint L2CacheLineLength = 32;
     1228static const uint L2CacheLineLengthInInts = L2CacheLineLength/sizeof(uint);
     1229#    define PRELOAD_INIT(x) preload(x);
     1230#    define PRELOAD_INIT2(x,y) PRELOAD_INIT(x) PRELOAD_INIT(y)
     1231#    define PRELOAD_COND(x) if (((uint)&x[i])%L2CacheLineLength == 0) preload(&x[i] + L2CacheLineLengthInInts);
     1232// Two consecutive preloads stall, so space them out a bit by using different modulus.
     1233#    define PRELOAD_COND2(x,y) if (((uint)&x[i])%L2CacheLineLength == 0) preload(&x[i] + L2CacheLineLengthInInts); \
     1234         if (((uint)&y[i])%L2CacheLineLength == 16) preload(&y[i] + L2CacheLineLengthInInts);
     1235#  endif // QT_HAVE_ARMV6
     1236#endif // Q_CC_RVCT
     1237
     1238#if !defined(Q_CC_RVCT) || !defined(QT_HAVE_ARMV6)
     1239#    define PRELOAD_INIT(x)
     1240#    define PRELOAD_INIT2(x,y)
     1241#    define PRELOAD_COND(x)
     1242#    define PRELOAD_COND2(x,y)
     1243#endif
    15011244
    15021245/* The constant alpha factor describes an alpha factor that gets applied
     
    15311274    } else {
    15321275        int ialpha = 255 - const_alpha;
    1533         for (int i = 0; i < length; ++i)
     1276        PRELOAD_INIT(dest)
     1277        for (int i = 0; i < length; ++i) {
     1278            PRELOAD_COND(dest)
    15341279            dest[i] = BYTE_MUL(dest[i], ialpha);
     1280        }
    15351281    }
    15361282}
     
    15421288    } else {
    15431289        int ialpha = 255 - const_alpha;
    1544         for (int i = 0; i < length; ++i)
     1290        PRELOAD_INIT(dest)
     1291        for (int i = 0; i < length; ++i) {
     1292            PRELOAD_COND(dest)
    15451293            dest[i] = BYTE_MUL(dest[i], ialpha);
     1294        }
    15461295    }
    15471296}
     
    15581307        int ialpha = 255 - const_alpha;
    15591308        color = BYTE_MUL(color, const_alpha);
    1560         for (int i = 0; i < length; ++i)
     1309        PRELOAD_INIT(dest)
     1310        for (int i = 0; i < length; ++i) {
     1311            PRELOAD_COND(dest)
    15611312            dest[i] = color + BYTE_MUL(dest[i], ialpha);
     1313        }
    15621314    }
    15631315}
     
    15691321    } else {
    15701322        int ialpha = 255 - const_alpha;
    1571         for (int i = 0; i < length; ++i)
     1323        PRELOAD_INIT2(dest, src)
     1324        for (int i = 0; i < length; ++i) {
     1325            PRELOAD_COND2(dest, src)
    15721326            dest[i] = INTERPOLATE_PIXEL_255(src[i], const_alpha, dest[i], ialpha);
     1327        }
    15731328    }
    15741329}
     
    15951350        if (const_alpha != 255)
    15961351            color = BYTE_MUL(color, const_alpha);
    1597         for (int i = 0; i < length; ++i)
     1352        PRELOAD_INIT(dest)
     1353        for (int i = 0; i < length; ++i) {
     1354            PRELOAD_COND(dest)
    15981355            dest[i] = color + BYTE_MUL(dest[i], qAlpha(~color));
     1356        }
    15991357    }
    16001358}
     
    16021360static void QT_FASTCALL comp_func_SourceOver(uint *dest, const uint *src, int length, uint const_alpha)
    16031361{
     1362    PRELOAD_INIT2(dest, src)
    16041363    if (const_alpha == 255) {
    16051364        for (int i = 0; i < length; ++i) {
     1365            PRELOAD_COND2(dest, src)
    16061366            uint s = src[i];
    16071367            dest[i] = s + BYTE_MUL(dest[i], qAlpha(~s));
     
    16091369    } else {
    16101370        for (int i = 0; i < length; ++i) {
     1371            PRELOAD_COND2(dest, src)
    16111372            uint s = BYTE_MUL(src[i], const_alpha);
    16121373            dest[i] = s + BYTE_MUL(dest[i], qAlpha(~s));
     
    16241385    if (const_alpha != 255)
    16251386        color = BYTE_MUL(color, const_alpha);
     1387    PRELOAD_INIT(dest)
    16261388    for (int i = 0; i < length; ++i) {
     1389        PRELOAD_COND(dest)
    16271390        uint d = dest[i];
    16281391        dest[i] = d + BYTE_MUL(color, qAlpha(~d));
     
    16321395static void QT_FASTCALL comp_func_DestinationOver(uint *dest, const uint *src, int length, uint const_alpha)
    16331396{
     1397    PRELOAD_INIT2(dest, src)
    16341398    if (const_alpha == 255) {
    16351399        for (int i = 0; i < length; ++i) {
     1400            PRELOAD_COND2(dest, src)
    16361401            uint d = dest[i];
    16371402            dest[i] = d + BYTE_MUL(src[i], qAlpha(~d));
     
    16391404    } else {
    16401405        for (int i = 0; i < length; ++i) {
     1406            PRELOAD_COND2(dest, src)
    16411407            uint d = dest[i];
    16421408            uint s = BYTE_MUL(src[i], const_alpha);
     
    16521418static void QT_FASTCALL comp_func_solid_SourceIn(uint *dest, int length, uint color, uint const_alpha)
    16531419{
     1420    PRELOAD_INIT(dest)
    16541421    if (const_alpha == 255) {
    1655         for (int i = 0; i < length; ++i)
     1422        for (int i = 0; i < length; ++i) {
     1423            PRELOAD_COND(dest)
    16561424            dest[i] = BYTE_MUL(color, qAlpha(dest[i]));
     1425        }
    16571426    } else {
    16581427        color = BYTE_MUL(color, const_alpha);
    16591428        uint cia = 255 - const_alpha;
    16601429        for (int i = 0; i < length; ++i) {
     1430            PRELOAD_COND(dest)
    16611431            uint d = dest[i];
    16621432            dest[i] = INTERPOLATE_PIXEL_255(color, qAlpha(d), d, cia);
     
    16671437static void QT_FASTCALL comp_func_SourceIn(uint *dest, const uint *src, int length, uint const_alpha)
    16681438{
     1439    PRELOAD_INIT2(dest, src)
    16691440    if (const_alpha == 255) {
    1670         for (int i = 0; i < length; ++i)
     1441        for (int i = 0; i < length; ++i) {
     1442            PRELOAD_COND2(dest, src)
    16711443            dest[i] = BYTE_MUL(src[i], qAlpha(dest[i]));
     1444        }
    16721445    } else {
    16731446        uint cia = 255 - const_alpha;
    16741447        for (int i = 0; i < length; ++i) {
     1448            PRELOAD_COND2(dest, src)
    16751449            uint d = dest[i];
    16761450            uint s = BYTE_MUL(src[i], const_alpha);
     
    16911465        a = BYTE_MUL(a, const_alpha) + 255 - const_alpha;
    16921466    }
     1467    PRELOAD_INIT(dest)
    16931468    for (int i = 0; i < length; ++i) {
     1469        PRELOAD_COND(dest)
    16941470        dest[i] = BYTE_MUL(dest[i], a);
    16951471    }
     
    16981474static void QT_FASTCALL comp_func_DestinationIn(uint *dest, const uint *src, int length, uint const_alpha)
    16991475{
     1476    PRELOAD_INIT2(dest, src)
    17001477    if (const_alpha == 255) {
    1701         for (int i = 0; i < length; ++i)
     1478        for (int i = 0; i < length; ++i) {
     1479            PRELOAD_COND2(dest, src)
    17021480            dest[i] = BYTE_MUL(dest[i], qAlpha(src[i]));
     1481        }
    17031482    } else {
    17041483        int cia = 255 - const_alpha;
    17051484        for (int i = 0; i < length; ++i) {
     1485            PRELOAD_COND2(dest, src)
    17061486            uint a = BYTE_MUL(qAlpha(src[i]), const_alpha) + cia;
    17071487            dest[i] = BYTE_MUL(dest[i], a);
     
    17171497static void QT_FASTCALL comp_func_solid_SourceOut(uint *dest, int length, uint color, uint const_alpha)
    17181498{
     1499    PRELOAD_INIT(dest)
    17191500    if (const_alpha == 255) {
    1720         for (int i = 0; i < length; ++i)
     1501        for (int i = 0; i < length; ++i) {
     1502            PRELOAD_COND(dest)
    17211503            dest[i] = BYTE_MUL(color, qAlpha(~dest[i]));
     1504        }
    17221505    } else {
    17231506        color = BYTE_MUL(color, const_alpha);
    17241507        int cia = 255 - const_alpha;
    17251508        for (int i = 0; i < length; ++i) {
     1509            PRELOAD_COND(dest)
    17261510            uint d = dest[i];
    17271511            dest[i] = INTERPOLATE_PIXEL_255(color, qAlpha(~d), d, cia);
     
    17321516static void QT_FASTCALL comp_func_SourceOut(uint *dest, const uint *src, int length, uint const_alpha)
    17331517{
     1518    PRELOAD_INIT2(dest, src)
    17341519    if (const_alpha == 255) {
    1735         for (int i = 0; i < length; ++i)
     1520        for (int i = 0; i < length; ++i) {
     1521            PRELOAD_COND2(dest, src)
    17361522            dest[i] = BYTE_MUL(src[i], qAlpha(~dest[i]));
     1523        }
    17371524    } else {
    17381525        int cia = 255 - const_alpha;
    17391526        for (int i = 0; i < length; ++i) {
     1527            PRELOAD_COND2(dest, src)
    17401528            uint s = BYTE_MUL(src[i], const_alpha);
    17411529            uint d = dest[i];
     
    17551543    if (const_alpha != 255)
    17561544        a = BYTE_MUL(a, const_alpha) + 255 - const_alpha;
    1757     for (int i = 0; i < length; ++i)
     1545    PRELOAD_INIT(dest)
     1546    for (int i = 0; i < length; ++i) {
     1547        PRELOAD_COND(dest)
    17581548        dest[i] = BYTE_MUL(dest[i], a);
     1549    }
    17591550}
    17601551
    17611552static void QT_FASTCALL comp_func_DestinationOut(uint *dest, const uint *src, int length, uint const_alpha)
    17621553{
     1554    PRELOAD_INIT2(dest, src)
    17631555    if (const_alpha == 255) {
    1764         for (int i = 0; i < length; ++i)
     1556        for (int i = 0; i < length; ++i) {
     1557            PRELOAD_COND2(dest, src)
    17651558            dest[i] = BYTE_MUL(dest[i], qAlpha(~src[i]));
     1559        }
    17661560    } else {
    17671561        int cia = 255 - const_alpha;
    17681562        for (int i = 0; i < length; ++i) {
     1563            PRELOAD_COND2(dest, src)
    17691564            uint sia = BYTE_MUL(qAlpha(~src[i]), const_alpha) + cia;
    17701565            dest[i] = BYTE_MUL(dest[i], sia);
     
    17851580    }
    17861581    uint sia = qAlpha(~color);
    1787     for (int i = 0; i < length; ++i)
     1582    PRELOAD_INIT(dest)
     1583    for (int i = 0; i < length; ++i) {
     1584        PRELOAD_COND(dest)
    17881585        dest[i] = INTERPOLATE_PIXEL_255(color, qAlpha(dest[i]), dest[i], sia);
     1586    }
    17891587}
    17901588
    17911589static void QT_FASTCALL comp_func_SourceAtop(uint *dest, const uint *src, int length, uint const_alpha)
    17921590{
     1591    PRELOAD_INIT2(dest, src)
    17931592    if (const_alpha == 255) {
    17941593        for (int i = 0; i < length; ++i) {
     1594            PRELOAD_COND2(dest, src)
    17951595            uint s = src[i];
    17961596            uint d = dest[i];
     
    17991599    } else {
    18001600        for (int i = 0; i < length; ++i) {
     1601            PRELOAD_COND2(dest, src)
    18011602            uint s = BYTE_MUL(src[i], const_alpha);
    18021603            uint d = dest[i];
     
    18181619        a = qAlpha(color) + 255 - const_alpha;
    18191620    }
     1621    PRELOAD_INIT(dest)
    18201622    for (int i = 0; i < length; ++i) {
     1623        PRELOAD_COND(dest)
    18211624        uint d = dest[i];
    18221625        dest[i] = INTERPOLATE_PIXEL_255(d, a, color, qAlpha(~d));
     
    18261629static void QT_FASTCALL comp_func_DestinationAtop(uint *dest, const uint *src, int length, uint const_alpha)
    18271630{
     1631    PRELOAD_INIT2(dest, src)
    18281632    if (const_alpha == 255) {
    18291633        for (int i = 0; i < length; ++i) {
     1634            PRELOAD_COND2(dest, src)
    18301635            uint s = src[i];
    18311636            uint d = dest[i];
     
    18351640        int cia = 255 - const_alpha;
    18361641        for (int i = 0; i < length; ++i) {
     1642            PRELOAD_COND2(dest, src)
    18371643            uint s = BYTE_MUL(src[i], const_alpha);
    18381644            uint d = dest[i];
     
    18551661    uint sia = qAlpha(~color);
    18561662
     1663    PRELOAD_INIT(dest)
    18571664    for (int i = 0; i < length; ++i) {
     1665        PRELOAD_COND(dest)
    18581666        uint d = dest[i];
    18591667        dest[i] = INTERPOLATE_PIXEL_255(color, qAlpha(~d), d, sia);
     
    18631671static void QT_FASTCALL comp_func_XOR(uint *dest, const uint *src, int length, uint const_alpha)
    18641672{
     1673    PRELOAD_INIT2(dest, src)
    18651674    if (const_alpha == 255) {
    18661675        for (int i = 0; i < length; ++i) {
     1676            PRELOAD_COND2(dest, src)
    18671677            uint d = dest[i];
    18681678            uint s = src[i];
     
    18711681    } else {
    18721682        for (int i = 0; i < length; ++i) {
     1683            PRELOAD_COND2(dest, src)
    18731684            uint d = dest[i];
    18741685            uint s = BYTE_MUL(src[i], const_alpha);
     
    19211732    uint s = color;
    19221733
     1734    PRELOAD_INIT(dest)
    19231735    for (int i = 0; i < length; ++i) {
     1736        PRELOAD_COND(dest)
    19241737        uint d = dest[i];
    19251738#define MIX(mask) (qMin(((qint64(s)&mask) + (qint64(d)&mask)), qint64(mask)))
     
    19411754Q_STATIC_TEMPLATE_FUNCTION inline void comp_func_Plus_impl(uint *dest, const uint *src, int length, const T &coverage)
    19421755{
     1756    PRELOAD_INIT2(dest, src)
    19431757    for (int i = 0; i < length; ++i) {
     1758        PRELOAD_COND2(dest, src)
    19441759        uint d = dest[i];
    19451760        uint s = src[i];
     
    19771792    int sb = qBlue(color);
    19781793
     1794    PRELOAD_INIT(dest)
    19791795    for (int i = 0; i < length; ++i) {
     1796        PRELOAD_COND(dest)
    19801797        uint d = dest[i];
    19811798        int da = qAlpha(d);
     
    20031820Q_STATIC_TEMPLATE_FUNCTION inline void comp_func_Multiply_impl(uint *dest, const uint *src, int length, const T &coverage)
    20041821{
     1822    PRELOAD_INIT2(dest, src)
    20051823    for (int i = 0; i < length; ++i) {
     1824        PRELOAD_COND2(dest, src)
    20061825        uint d = dest[i];
    20071826        uint s = src[i];
     
    20411860    int sb = qBlue(color);
    20421861
     1862    PRELOAD_INIT(dest)
    20431863    for (int i = 0; i < length; ++i) {
     1864        PRELOAD_COND(dest)
    20441865        uint d = dest[i];
    20451866        int da = qAlpha(d);
     
    20671888Q_STATIC_TEMPLATE_FUNCTION inline void comp_func_Screen_impl(uint *dest, const uint *src, int length, const T &coverage)
    20681889{
     1890    PRELOAD_INIT2(dest, src)
    20691891    for (int i = 0; i < length; ++i) {
     1892        PRELOAD_COND2(dest, src)
    20701893        uint d = dest[i];
    20711894        uint s = src[i];
     
    21161939    int sb = qBlue(color);
    21171940
     1941    PRELOAD_INIT(dest)
    21181942    for (int i = 0; i < length; ++i) {
     1943        PRELOAD_COND(dest)
    21191944        uint d = dest[i];
    21201945        int da = qAlpha(d);
     
    21421967Q_STATIC_TEMPLATE_FUNCTION inline void comp_func_Overlay_impl(uint *dest, const uint *src, int length, const T &coverage)
    21431968{
     1969    PRELOAD_INIT2(dest, src)
    21441970    for (int i = 0; i < length; ++i) {
     1971        PRELOAD_COND2(dest, src)
    21451972        uint d = dest[i];
    21461973        uint s = src[i];
     
    21852012    int sb = qBlue(color);
    21862013
     2014    PRELOAD_INIT(dest)
    21872015    for (int i = 0; i < length; ++i) {
     2016        PRELOAD_COND(dest)
    21882017        uint d = dest[i];
    21892018        int da = qAlpha(d);
     
    22112040Q_STATIC_TEMPLATE_FUNCTION inline void comp_func_Darken_impl(uint *dest, const uint *src, int length, const T &coverage)
    22122041{
     2042    PRELOAD_INIT2(dest, src)
    22132043    for (int i = 0; i < length; ++i) {
     2044        PRELOAD_COND2(dest, src)
    22142045        uint d = dest[i];
    22152046        uint s = src[i];
     
    22542085    int sb = qBlue(color);
    22552086
     2087    PRELOAD_INIT(dest)
    22562088    for (int i = 0; i < length; ++i) {
     2089        PRELOAD_COND(dest)
    22572090        uint d = dest[i];
    22582091        int da = qAlpha(d);
     
    22802113Q_STATIC_TEMPLATE_FUNCTION inline void comp_func_Lighten_impl(uint *dest, const uint *src, int length, const T &coverage)
    22812114{
     2115    PRELOAD_INIT2(dest, src)
    22822116    for (int i = 0; i < length; ++i) {
     2117        PRELOAD_COND2(dest, src)
    22832118        uint d = dest[i];
    22842119        uint s = src[i];
     
    23332168    int sb = qBlue(color);
    23342169
     2170    PRELOAD_INIT(dest)
    23352171    for (int i = 0; i < length; ++i) {
     2172        PRELOAD_COND(dest)
    23362173        uint d = dest[i];
    23372174        int da = qAlpha(d);
     
    23592196Q_STATIC_TEMPLATE_FUNCTION inline void comp_func_ColorDodge_impl(uint *dest, const uint *src, int length, const T &coverage)
    23602197{
     2198    PRELOAD_INIT2(dest, src)
    23612199    for (int i = 0; i < length; ++i) {
     2200        PRELOAD_COND2(dest, src)
    23622201        uint d = dest[i];
    23632202        uint s = src[i];
     
    24012240    if (src == 0 || src_da + dst_sa <= sa_da)
    24022241        return qt_div_255(temp);
    2403     else
    2404         return qt_div_255(sa * (src_da + dst_sa - sa_da) / src + temp);
     2242    return qt_div_255(sa * (src_da + dst_sa - sa_da) / src + temp);
    24052243}
    24062244
     
    24132251    int sb = qBlue(color);
    24142252
     2253    PRELOAD_INIT(dest)
    24152254    for (int i = 0; i < length; ++i) {
     2255        PRELOAD_COND(dest)
    24162256        uint d = dest[i];
    24172257        int da = qAlpha(d);
     
    24392279Q_STATIC_TEMPLATE_FUNCTION inline void comp_func_ColorBurn_impl(uint *dest, const uint *src, int length, const T &coverage)
    24402280{
     2281    PRELOAD_INIT2(dest, src)
    24412282    for (int i = 0; i < length; ++i) {
     2283        PRELOAD_COND2(dest, src)
    24422284        uint d = dest[i];
    24432285        uint s = src[i];
     
    24892331    int sb = qBlue(color);
    24902332
     2333    PRELOAD_INIT(dest)
    24912334    for (int i = 0; i < length; ++i) {
     2335        PRELOAD_COND(dest)
    24922336        uint d = dest[i];
    24932337        int da = qAlpha(d);
     
    25152359Q_STATIC_TEMPLATE_FUNCTION inline void comp_func_HardLight_impl(uint *dest, const uint *src, int length, const T &coverage)
    25162360{
     2361    PRELOAD_INIT2(dest, src)
    25172362    for (int i = 0; i < length; ++i) {
     2363        PRELOAD_COND2(dest, src)
    25182364        uint d = dest[i];
    25192365        uint s = src[i];
     
    25422388
    25432389/*
    2544    if 2.Sca < Sa
    2545        Dca' = Dca.(Sa - (1 - Dca/Da).(2.Sca - Sa)) + Sca.(1 - Da) + Dca.(1 - Sa)
    2546    otherwise if 8.Dca <= Da
    2547        Dca' = Dca.(Sa - (1 - Dca/Da).(2.Sca - Sa).(3 - 8.Dca/Da)) + Sca.(1 - Da) + Dca.(1 - Sa)
    2548    otherwise
    2549        Dca' = (Dca.Sa + ((Dca/Da)^(0.5).Da - Dca).(2.Sca - Sa)) + Sca.(1 - Da) + Dca.(1 - Sa)
     2390    if 2.Sca <= Sa
     2391        Dca' = Dca.(Sa + (2.Sca - Sa).(1 - Dca/Da)) + Sca.(1 - Da) + Dca.(1 - Sa)
     2392    otherwise if 2.Sca > Sa and 4.Dca <= Da
     2393        Dca' = Dca.Sa + Da.(2.Sca - Sa).(4.Dca/Da.(4.Dca/Da + 1).(Dca/Da - 1) + 7.Dca/Da) + Sca.(1 - Da) + Dca.(1 - Sa)
     2394    otherwise if 2.Sca > Sa and 4.Dca > Da
     2395        Dca' = Dca.Sa + Da.(2.Sca - Sa).((Dca/Da)^0.5 - Dca/Da) + Sca.(1 - Da) + Dca.(1 - Sa)
    25502396*/
    25512397static inline int soft_light_op(int dst, int src, int da, int sa)
     
    25562402
    25572403    if (src2 < sa)
    2558         return (dst * ((sa * 255) - (255 - dst_np) * (src2 - sa)) + temp) / 65025;
    2559     else if (8 * dst <= da)
    2560         return (dst * ((sa * 255) - ((255 - dst_np) * (src2 - sa) * ((3 * 255) - 8 * dst_np)) / 255) + temp) / 65025;
     2404        return (dst * (sa * 255 + (src2 - sa) * (255 - dst_np)) + temp) / 65025;
     2405    else if (4 * dst <= da)
     2406        return (dst * sa * 255 + da * (src2 - sa) * ((((16 * dst_np - 12 * 255) * dst_np + 3 * 65025) * dst_np) / 65025) + temp) / 65025;
    25612407    else {
    2562         // sqrt is too expensive to do three times per pixel, so skipping it for now
    2563         // a future possibility is to use a LUT
    2564         return ((dst * sa * 255) + (int(dst_np) * da - (dst * 255)) * (src2 - sa) + temp) / 65025;
     2408        return (dst * sa * 255 + da * (src2 - sa) * (int(sqrt(qreal(dst_np * 255))) - dst_np) + temp) / 65025;
    25652409    }
    25662410}
     
    25742418    int sb = qBlue(color);
    25752419
     2420    PRELOAD_INIT(dest)
    25762421    for (int i = 0; i < length; ++i) {
     2422        PRELOAD_COND(dest)
    25772423        uint d = dest[i];
    25782424        int da = qAlpha(d);
     
    26002446Q_STATIC_TEMPLATE_FUNCTION inline void comp_func_SoftLight_impl(uint *dest, const uint *src, int length, const T &coverage)
    26012447{
     2448    PRELOAD_INIT2(dest, src)
    26022449    for (int i = 0; i < length; ++i) {
     2450        PRELOAD_COND2(dest, src)
    26032451        uint d = dest[i];
    26042452        uint s = src[i];
     
    26432491    int sb = qBlue(color);
    26442492
     2493    PRELOAD_INIT(dest)
    26452494    for (int i = 0; i < length; ++i) {
     2495        PRELOAD_COND(dest)
    26462496        uint d = dest[i];
    26472497        int da = qAlpha(d);
     
    26692519Q_STATIC_TEMPLATE_FUNCTION inline void comp_func_Difference_impl(uint *dest, const uint *src, int length, const T &coverage)
    26702520{
     2521    PRELOAD_INIT2(dest, src)
    26712522    for (int i = 0; i < length; ++i) {
     2523        PRELOAD_COND2(dest, src)
    26722524        uint d = dest[i];
    26732525        uint s = src[i];
     
    27062558    int sb = qBlue(color);
    27072559
     2560    PRELOAD_INIT(dest)
    27082561    for (int i = 0; i < length; ++i) {
     2562        PRELOAD_COND(dest)
    27092563        uint d = dest[i];
    27102564        int da = qAlpha(d);
     
    27322586Q_STATIC_TEMPLATE_FUNCTION inline void comp_func_Exclusion_impl(uint *dest, const uint *src, int length, const T &coverage)
    27332587{
     2588    PRELOAD_INIT2(dest, src)
    27342589    for (int i = 0; i < length; ++i) {
     2590        PRELOAD_COND2(dest, src)
    27352591        uint d = dest[i];
    27362592        uint s = src[i];
     
    27572613        comp_func_Exclusion_impl(dest, src, length, QPartialCoverage(const_alpha));
    27582614}
     2615
     2616#if defined(Q_CC_RVCT)
     2617// Restore pragma state from previous #pragma arm
     2618#  pragma pop
     2619#endif
    27592620
    27602621static void QT_FASTCALL rasterop_solid_SourceOrDestination(uint *dest,
     
    32213082
    32223083template <class T>
    3223 Q_STATIC_TEMPLATE_FUNCTION void blendColor(int count, const QSpan *spans, void *userData
    3224                        Q_TEMPLATE_FIX(T))
     3084Q_STATIC_TEMPLATE_FUNCTION void blendColor(int count, const QSpan *spans, void *userData)
    32253085{
    32263086    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
     
    32683128}
    32693129
    3270 #if defined(Q_CC_MSVC) && _MSC_VER <= 1300 && !defined(Q_CC_INTEL)
    3271 #define BLEND_COLOR_DECL(DST)                                           \
    3272     static void blendColor_##DST(int count,                             \
    3273                                  const QSpan *spans,                    \
    3274                                  void *userData)                        \
    3275     {                                                                   \
    3276         blendColor<DST>(count, spans, userData Q_TEMPLATE_CALL(DST));   \
    3277     }
    3278 
    3279 BLEND_COLOR_DECL(qargb8565)
    3280 BLEND_COLOR_DECL(qrgb666)
    3281 BLEND_COLOR_DECL(qargb6666)
    3282 BLEND_COLOR_DECL(qrgb555)
    3283 BLEND_COLOR_DECL(qargb8555)
    3284 BLEND_COLOR_DECL(qrgb888)
    3285 BLEND_COLOR_DECL(qrgb444)
    3286 BLEND_COLOR_DECL(qargb4444)
    3287 #undef DEST_FETCH_DECL
    3288 #define SPANFUNC_POINTER_BLENDCOLOR(DST) blendColor_##DST
    3289 #else // !VC6 && !VC2002
    3290 # define SPANFUNC_POINTER_BLENDCOLOR(DST) blendColor<DST>
    3291 #endif
     3130#define SPANFUNC_POINTER_BLENDCOLOR(DST) blendColor<DST>
    32923131
    32933132static void blend_color_rgb16(int count, const QSpan *spans, void *userData)
     
    33673206}
    33683207
    3369 template <SpanMethod spanMethod>
    3370 Q_STATIC_TEMPLATE_FUNCTION void blend_src_generic(int count, const QSpan *spans, void *userData
    3371                               Q_TEMPLATE_ENUM_FIX(SpanMethod, spanMethod))
    3372 {
    3373     QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    3374 
    3375     uint buffer[buffer_size];
    3376     uint src_buffer[buffer_size];
    3377     Operator op = getOperator(data, spans, count);
    3378 
     3208template <typename T>
     3209void handleSpans(int count, const QSpan *spans, const QSpanData *data, T &handler)
     3210{
    33793211    uint const_alpha = 256;
    33803212    if (data->type == QSpanData::Texture)
    33813213        const_alpha = data->texture.const_alpha;
    33823214
    3383     while (count--) {
     3215    int coverage = 0;
     3216    while (count) {
    33843217        int x = spans->x;
    3385         int length = spans->len;
    3386         const int coverage = (spans->coverage * const_alpha) >> 8;
     3218        const int y = spans->y;
     3219        int right = x + spans->len;
     3220
     3221        // compute length of adjacent spans
     3222        for (int i = 1; i < count && spans[i].y == y && spans[i].x == right; ++i)
     3223            right += spans[i].len;
     3224        int length = right - x;
     3225
    33873226        while (length) {
    33883227            int l = qMin(buffer_size, length);
    3389             const uint *src = op.src_fetch(src_buffer, &op, data, spans->y, x, l);
    3390             if (spanMethod == RegularSpans) {
    3391                 uint *dest = op.dest_fetch ? op.dest_fetch(buffer, data->rasterBuffer, x, spans->y, l) : buffer;
    3392                 op.func(dest, src, l, coverage);
    3393                 if (op.dest_store)
    3394                     op.dest_store(data->rasterBuffer, x, spans->y, dest, l);
    3395             } else {
    3396                 drawBufferSpan(data, src, l, x, spans->y, l, coverage);
     3228            length -= l;
     3229
     3230            int process_length = l;
     3231            int process_x = x;
     3232
     3233            const uint *src = handler.fetch(process_x, y, process_length);
     3234            int offset = 0;
     3235            while (l > 0) {
     3236                if (x == spans->x) // new span?
     3237                    coverage = (spans->coverage * const_alpha) >> 8;
     3238
     3239                int right = spans->x + spans->len;
     3240                int len = qMin(l, right - x);
     3241
     3242                handler.process(x, y, len, coverage, src, offset);
     3243
     3244                l -= len;
     3245                x += len;
     3246                offset += len;
     3247
     3248                if (x == right) { // done with current span?
     3249                    ++spans;
     3250                    --count;
     3251                }
    33973252            }
    3398             x += l;
    3399             length -= l;
    3400         }
    3401         ++spans;
    3402     }
    3403 }
     3253            handler.store(process_x, y, process_length);
     3254        }
     3255    }
     3256}
     3257
     3258struct QBlendBase
     3259{
     3260    QBlendBase(QSpanData *d, Operator o)
     3261        : data(d)
     3262        , op(o)
     3263        , dest(0)
     3264    {
     3265    }
     3266
     3267    QSpanData *data;
     3268    Operator op;
     3269
     3270    uint *dest;
     3271
     3272    uint buffer[buffer_size];
     3273    uint src_buffer[buffer_size];
     3274};
    34043275
    34053276template <SpanMethod spanMethod>
    3406 Q_STATIC_TEMPLATE_FUNCTION void blend_untransformed_generic(int count, const QSpan *spans, void *userData
    3407                                         Q_TEMPLATE_ENUM_FIX(SpanMethod, spanMethod))
     3277class BlendSrcGeneric : public QBlendBase
     3278{
     3279public:
     3280    BlendSrcGeneric(QSpanData *d, Operator o)
     3281        : QBlendBase(d, o)
     3282    {
     3283    }
     3284
     3285    const uint *fetch(int x, int y, int len)
     3286    {
     3287        if (spanMethod == RegularSpans)
     3288            dest = op.dest_fetch ? op.dest_fetch(buffer, data->rasterBuffer, x, y, len) : buffer;
     3289
     3290        return op.src_fetch(src_buffer, &op, data, y, x, len);
     3291    }
     3292
     3293    void process(int x, int y, int len, int coverage, const uint *src, int offset)
     3294    {
     3295        if (spanMethod == RegularSpans)
     3296            op.func(dest + offset, src + offset, len, coverage);
     3297        else
     3298            drawBufferSpan(data, src + offset, len, x, y, len, coverage);
     3299    }
     3300
     3301    void store(int x, int y, int len)
     3302    {
     3303        if (spanMethod == RegularSpans && op.dest_store) {
     3304            op.dest_store(data->rasterBuffer, x, y, dest, len);
     3305        }
     3306    }
     3307};
     3308
     3309template <SpanMethod spanMethod>
     3310Q_STATIC_TEMPLATE_FUNCTION void blend_src_generic(int count, const QSpan *spans, void *userData)
     3311{
     3312    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
     3313    BlendSrcGeneric<spanMethod> blend(data, getOperator(data, spans, count));
     3314    handleSpans(count, spans, data, blend);
     3315}
     3316
     3317template <SpanMethod spanMethod>
     3318Q_STATIC_TEMPLATE_FUNCTION void blend_untransformed_generic(int count, const QSpan *spans, void *userData)
    34083319{
    34093320    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
     
    34563367
    34573368template <SpanMethod spanMethod>
    3458 Q_STATIC_TEMPLATE_FUNCTION void blend_untransformed_argb(int count, const QSpan *spans, void *userData
    3459                                      Q_TEMPLATE_ENUM_FIX(SpanMethod, spanMethod))
     3369Q_STATIC_TEMPLATE_FUNCTION void blend_untransformed_argb(int count, const QSpan *spans, void *userData)
    34603370{
    34613371    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    34623372    if (data->texture.format != QImage::Format_ARGB32_Premultiplied
    34633373        && data->texture.format != QImage::Format_RGB32) {
    3464         blend_untransformed_generic<spanMethod>(count, spans, userData Q_TEMPLATE_ENUM_CALL(SpanMethod, spanMethod));
     3374        blend_untransformed_generic<spanMethod>(count, spans, userData);
    34653375        return;
    34663376    }
     
    47084618        mode != QPainter::CompositionMode_Source)
    47094619    {
    4710         blend_src_generic<RegularSpans>(count, spans, userData
    4711                                         Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     4620        blend_src_generic<RegularSpans>(count, spans, userData);
    47124621        return;
    47134622    }
     
    47644673                                       void *userData)
    47654674{
    4766 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_24)
     4675#if defined(QT_QWS_DEPTH_24)
    47674676    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    47684677
     
    47714680    else
    47724681#endif
    4773         blend_untransformed_generic<RegularSpans>(count, spans, userData
    4774                                                   Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     4682        blend_untransformed_generic<RegularSpans>(count, spans, userData);
    47754683}
    47764684
     
    47784686                                         void *userData)
    47794687{
    4780 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_18)
     4688#if defined(QT_QWS_DEPTH_18)
    47814689    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    47824690
     
    47874695    else
    47884696#endif
    4789         blend_untransformed_generic<RegularSpans>(count, spans, userData
    4790                                                   Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     4697        blend_untransformed_generic<RegularSpans>(count, spans, userData);
    47914698}
    47924699
     
    47944701                                       void *userData)
    47954702{
    4796 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_18)
     4703#if defined(QT_QWS_DEPTH_18)
    47974704    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    47984705
     
    48034710    else
    48044711#endif
    4805         blend_untransformed_generic<RegularSpans>(count, spans, userData
    4806                                                   Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     4712        blend_untransformed_generic<RegularSpans>(count, spans, userData);
    48074713}
    48084714
     
    48104716                                         void *userData)
    48114717{
    4812 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_16)
     4718#if defined(QT_QWS_DEPTH_16)
    48134719    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    48144720
     
    48194725    else
    48204726#endif
    4821         blend_untransformed_generic<RegularSpans>(count, spans, userData
    4822                                                   Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     4727        blend_untransformed_generic<RegularSpans>(count, spans, userData);
    48234728}
    48244729
     
    48264731                                       void *userData)
    48274732{
    4828 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_16)
     4733#if defined(QT_QWS_DEPTH_16)
    48294734    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    48304735
     
    48354740    else
    48364741#endif
    4837         blend_untransformed_generic<RegularSpans>(count, spans, userData
    4838                                                   Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     4742        blend_untransformed_generic<RegularSpans>(count, spans, userData);
    48394743}
    48404744
     
    48424746                                         void *userData)
    48434747{
    4844 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_15)
     4748#if defined(QT_QWS_DEPTH_15)
    48454749    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    48464750
     
    48514755    else
    48524756#endif
    4853         blend_untransformed_generic<RegularSpans>(count, spans, userData
    4854                                                   Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     4757        blend_untransformed_generic<RegularSpans>(count, spans, userData);
    48554758}
    48564759
     
    48584761                                       void *userData)
    48594762{
    4860 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_15)
     4763#if defined(QT_QWS_DEPTH_15)
    48614764    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    48624765
     
    48674770    else
    48684771#endif
    4869         blend_untransformed_generic<RegularSpans>(count, spans, userData
    4870                                                   Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     4772        blend_untransformed_generic<RegularSpans>(count, spans, userData);
    48714773}
    48724774
     
    48744776                                         void *userData)
    48754777{
    4876 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_12)
     4778#if defined(QT_QWS_DEPTH_12)
    48774779    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    48784780
     
    48834785    else
    48844786#endif
    4885         blend_untransformed_generic<RegularSpans>(count, spans, userData
    4886                                                   Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     4787        blend_untransformed_generic<RegularSpans>(count, spans, userData);
    48874788}
    48884789
     
    48904791                                       void *userData)
    48914792{
    4892 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_12)
     4793#if defined(QT_QWS_DEPTH_12)
    48934794    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    48944795
     
    48994800    else
    49004801#endif
    4901         blend_untransformed_generic<RegularSpans>(count, spans, userData
    4902                                                   Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     4802        blend_untransformed_generic<RegularSpans>(count, spans, userData);
    49034803}
    49044804
    49054805template <SpanMethod spanMethod>
    4906 Q_STATIC_TEMPLATE_FUNCTION void blend_tiled_generic(int count, const QSpan *spans, void *userData
    4907                                 Q_TEMPLATE_ENUM_FIX(SpanMethod, spanMethod))
     4806Q_STATIC_TEMPLATE_FUNCTION void blend_tiled_generic(int count, const QSpan *spans, void *userData)
    49084807{
    49094808    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
     
    49594858
    49604859template <SpanMethod spanMethod>
    4961 Q_STATIC_TEMPLATE_FUNCTION void blend_tiled_argb(int count, const QSpan *spans, void *userData
    4962                              Q_TEMPLATE_ENUM_FIX(SpanMethod, spanMethod))
     4860Q_STATIC_TEMPLATE_FUNCTION void blend_tiled_argb(int count, const QSpan *spans, void *userData)
    49634861{
    49644862    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    49654863    if (data->texture.format != QImage::Format_ARGB32_Premultiplied
    49664864        && data->texture.format != QImage::Format_RGB32) {
    4967         blend_tiled_generic<spanMethod>(count, spans, userData Q_TEMPLATE_ENUM_CALL(SpanMethod, spanMethod));
     4865        blend_tiled_generic<spanMethod>(count, spans, userData);
    49684866        return;
    49694867    }
     
    50214919        mode != QPainter::CompositionMode_Source)
    50224920    {
    5023         blend_src_generic<RegularSpans>(count, spans, userData
    5024                                         Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     4921        blend_src_generic<RegularSpans>(count, spans, userData);
    50254922        return;
    50264923    }
     
    50544951            sy += image_height;
    50554952
    5056         while (length) {
    5057             int l = qMin(image_width - sx, length);
    5058             if (buffer_size < l)
    5059                 l = buffer_size;
    5060 
    5061             DST *dest = ((DST*)data->rasterBuffer->scanLine(spans->y)) + x;
    5062             const SRC *src = (SRC*)data->texture.scanLine(sy) + sx;
    5063             if (modeSource && coverage == 255) {
     4953        if (modeSource && coverage == 255) {
     4954            // Copy the first texture block
     4955            length = qMin(image_width,length);
     4956            int tx = x;
     4957            while (length) {
     4958                int l = qMin(image_width - sx, length);
     4959                if (buffer_size < l)
     4960                    l = buffer_size;
     4961                DST *dest = ((DST*)data->rasterBuffer->scanLine(spans->y)) + tx;
     4962                const SRC *src = (SRC*)data->texture.scanLine(sy) + sx;
     4963
    50644964                qt_memconvert<DST, SRC>(dest, src, l);
    5065             } else if (sizeof(DST) == 3 && sizeof(SRC) == 3 && l >= 4 &&
    5066                        (quintptr(dest) & 3) == (quintptr(src) & 3))
    5067             {
    5068                 blendUntransformed_dest24(dest, src, coverage, l);
    5069             } else if (sizeof(DST) == 2 && sizeof(SRC) == 2 && l >= 2 &&
    5070                        (quintptr(dest) & 3) == (quintptr(src) & 3))
    5071             {
    5072                 blendUntransformed_dest16(dest, src, coverage, l);
    5073             } else {
    5074                 blendUntransformed_unaligned(dest, src, coverage, l);
     4965                length -= l;
     4966                tx += l;
     4967                sx = 0;
    50754968            }
    50764969
    5077             x += l;
    5078             length -= l;
    5079             sx = 0;
     4970            // Now use the rasterBuffer as the source of the texture,
     4971            // We can now progressively copy larger blocks
     4972            // - Less cpu time in code figuring out what to copy
     4973            // We are dealing with one block of data
     4974            // - More likely to fit in the cache
     4975            // - can use memcpy
     4976            int copy_image_width = qMin(image_width, int(spans->len));
     4977            length = spans->len - copy_image_width;
     4978            DST *src = ((DST*)data->rasterBuffer->scanLine(spans->y)) + x;
     4979            DST *dest = src + copy_image_width;
     4980            while (copy_image_width < length) {
     4981                qt_memconvert(dest, src, copy_image_width);
     4982                dest += copy_image_width;
     4983                length -= copy_image_width;
     4984                copy_image_width *= 2;
     4985            }
     4986            qt_memconvert(dest, src, length);
     4987        } else {
     4988            while (length) {
     4989                int l = qMin(image_width - sx, length);
     4990                if (buffer_size < l)
     4991                    l = buffer_size;
     4992                DST *dest = ((DST*)data->rasterBuffer->scanLine(spans->y)) + x;
     4993                const SRC *src = (SRC*)data->texture.scanLine(sy) + sx;
     4994                if (sizeof(DST) == 3 && sizeof(SRC) == 3 && l >= 4 &&
     4995                           (quintptr(dest) & 3) == (quintptr(src) & 3))
     4996                {
     4997                    blendUntransformed_dest24(dest, src, coverage, l);
     4998                } else if (sizeof(DST) == 2 && sizeof(SRC) == 2 && l >= 2 &&
     4999                           (quintptr(dest) & 3) == (quintptr(src) & 3))
     5000                {
     5001                    blendUntransformed_dest16(dest, src, coverage, l);
     5002                } else {
     5003                    blendUntransformed_unaligned(dest, src, coverage, l);
     5004                }
     5005
     5006                x += l;
     5007                length -= l;
     5008                sx = 0;
     5009            }
    50805010        }
    50815011        ++spans;
     
    50855015static void blend_tiled_rgb888(int count, const QSpan *spans, void *userData)
    50865016{
    5087 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_24)
     5017#if defined(QT_QWS_DEPTH_24)
    50885018    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    50895019
     
    50925022    else
    50935023#endif
    5094         blend_tiled_generic<RegularSpans>(count, spans, userData
    5095                                           Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     5024        blend_tiled_generic<RegularSpans>(count, spans, userData);
    50965025}
    50975026
    50985027static void blend_tiled_argb6666(int count, const QSpan *spans, void *userData)
    50995028{
    5100 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_18)
     5029#if defined(QT_QWS_DEPTH_18)
    51015030    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    51025031
     
    51075036    else
    51085037#endif
    5109         blend_tiled_generic<RegularSpans>(count, spans, userData
    5110                                           Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     5038        blend_tiled_generic<RegularSpans>(count, spans, userData);
    51115039}
    51125040
    51135041static void blend_tiled_rgb666(int count, const QSpan *spans, void *userData)
    51145042{
    5115 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_18)
     5043#if defined(QT_QWS_DEPTH_18)
    51165044    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    51175045
     
    51225050    else
    51235051#endif
    5124         blend_tiled_generic<RegularSpans>(count, spans, userData
    5125                                           Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     5052        blend_tiled_generic<RegularSpans>(count, spans, userData);
    51265053}
    51275054
    51285055static void blend_tiled_argb8565(int count, const QSpan *spans, void *userData)
    51295056{
    5130 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_16)
     5057#if defined(QT_QWS_DEPTH_16)
    51315058    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    51325059
     
    51375064    else
    51385065#endif
    5139         blend_tiled_generic<RegularSpans>(count, spans, userData
    5140                                           Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     5066        blend_tiled_generic<RegularSpans>(count, spans, userData);
    51415067}
    51425068
    51435069static void blend_tiled_rgb565(int count, const QSpan *spans, void *userData)
    51445070{
    5145 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_16)
     5071#if defined(QT_QWS_DEPTH_16)
    51465072    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    51475073
     
    51525078    else
    51535079#endif
    5154         blend_tiled_generic<RegularSpans>(count, spans, userData
    5155                                           Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     5080        blend_tiled_generic<RegularSpans>(count, spans, userData);
    51565081}
    51575082
    51585083static void blend_tiled_argb8555(int count, const QSpan *spans, void *userData)
    51595084{
    5160 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_15)
     5085#if defined(QT_QWS_DEPTH_15)
    51615086    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    51625087
     
    51675092    else
    51685093#endif
    5169         blend_tiled_generic<RegularSpans>(count, spans, userData
    5170                                           Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     5094        blend_tiled_generic<RegularSpans>(count, spans, userData);
    51715095}
    51725096
    51735097static void blend_tiled_rgb555(int count, const QSpan *spans, void *userData)
    51745098{
    5175 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_15)
     5099#if defined(QT_QWS_DEPTH_15)
    51765100    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    51775101
     
    51825106    else
    51835107#endif
    5184         blend_tiled_generic<RegularSpans>(count, spans, userData
    5185                                           Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     5108        blend_tiled_generic<RegularSpans>(count, spans, userData);
    51865109}
    51875110
    51885111static void blend_tiled_argb4444(int count, const QSpan *spans, void *userData)
    51895112{
    5190 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_12)
     5113#if defined(QT_QWS_DEPTH_12)
    51915114    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    51925115
     
    51975120    else
    51985121#endif
    5199         blend_tiled_generic<RegularSpans>(count, spans, userData
    5200                                           Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     5122        blend_tiled_generic<RegularSpans>(count, spans, userData);
    52015123}
    52025124
    52035125static void blend_tiled_rgb444(int count, const QSpan *spans, void *userData)
    52045126{
    5205 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_12)
     5127#if defined(QT_QWS_DEPTH_12)
    52065128    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    52075129
     
    52125134    else
    52135135#endif
    5214         blend_tiled_generic<RegularSpans>(count, spans, userData
    5215                                           Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     5136        blend_tiled_generic<RegularSpans>(count, spans, userData);
    52165137}
    52175138
    52185139
    52195140template <SpanMethod spanMethod>
    5220 Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_bilinear_argb(int count, const QSpan *spans, void *userData
    5221                                             Q_TEMPLATE_ENUM_FIX(SpanMethod, spanMethod))
     5141Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_bilinear_argb(int count, const QSpan *spans, void *userData)
    52225142{
    52235143    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    52245144    if (data->texture.format != QImage::Format_ARGB32_Premultiplied
    52255145        && data->texture.format != QImage::Format_RGB32) {
    5226         blend_src_generic<spanMethod>(count, spans, userData Q_TEMPLATE_ENUM_CALL(SpanMethod, spanMethod));
     5146        blend_src_generic<spanMethod>(count, spans, userData);
    52275147        return;
    52285148    }
     
    54035323
    54045324    if (mode != QPainter::CompositionMode_SourceOver) {
    5405         blend_src_generic<RegularSpans>(count, spans, userData
    5406                                         Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     5325        blend_src_generic<RegularSpans>(count, spans, userData);
    54075326        return;
    54085327    }
     
    56005519static void blend_transformed_bilinear_rgb888(int count, const QSpan *spans, void *userData)
    56015520{
    5602 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_24)
     5521#if defined(QT_QWS_DEPTH_24)
    56035522    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    56045523
     
    56075526    else
    56085527#endif
    5609         blend_src_generic<RegularSpans>(count, spans, userData
    5610                                         Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     5528        blend_src_generic<RegularSpans>(count, spans, userData);
    56115529}
    56125530
    56135531static void blend_transformed_bilinear_argb6666(int count, const QSpan *spans, void *userData)
    56145532{
    5615 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_18)
     5533#if defined(QT_QWS_DEPTH_18)
    56165534    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    56175535
     
    56225540    else
    56235541#endif
    5624         blend_src_generic<RegularSpans>(count, spans, userData
    5625                                         Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     5542        blend_src_generic<RegularSpans>(count, spans, userData);
    56265543}
    56275544
    56285545static void blend_transformed_bilinear_rgb666(int count, const QSpan *spans, void *userData)
    56295546{
    5630 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_18)
     5547#if defined(QT_QWS_DEPTH_18)
    56315548    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    56325549
     
    56375554    else
    56385555#endif
    5639         blend_src_generic<RegularSpans>(count, spans, userData
    5640                                         Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     5556        blend_src_generic<RegularSpans>(count, spans, userData);
    56415557}
    56425558
    56435559static void blend_transformed_bilinear_argb8565(int count, const QSpan *spans, void *userData)
    56445560{
    5645 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_16)
     5561#if defined(QT_QWS_DEPTH_16)
    56465562    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    56475563
     
    56525568    else
    56535569#endif
    5654         blend_src_generic<RegularSpans>(count, spans, userData
    5655                                         Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     5570        blend_src_generic<RegularSpans>(count, spans, userData);
    56565571}
    56575572
     
    56595574                                              void *userData)
    56605575{
    5661 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_16)
     5576#if defined(QT_QWS_DEPTH_16)
    56625577    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    56635578
     
    56685583    else
    56695584#endif
    5670         blend_src_generic<RegularSpans>(count, spans, userData
    5671                                         Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     5585        blend_src_generic<RegularSpans>(count, spans, userData);
    56725586}
    56735587
    56745588static void blend_transformed_bilinear_argb8555(int count, const QSpan *spans, void *userData)
    56755589{
    5676 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_15)
     5590#if defined(QT_QWS_DEPTH_15)
    56775591    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    56785592
     
    56835597    else
    56845598#endif
    5685         blend_src_generic<RegularSpans>(count, spans, userData
    5686                                         Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     5599        blend_src_generic<RegularSpans>(count, spans, userData);
    56875600}
    56885601
    56895602static void blend_transformed_bilinear_rgb555(int count, const QSpan *spans, void *userData)
    56905603{
    5691 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_15)
     5604#if defined(QT_QWS_DEPTH_15)
    56925605    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    56935606
     
    56985611    else
    56995612#endif
    5700         blend_src_generic<RegularSpans>(count, spans, userData
    5701                                         Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     5613        blend_src_generic<RegularSpans>(count, spans, userData);
    57025614}
    57035615
    57045616static void blend_transformed_bilinear_argb4444(int count, const QSpan *spans, void *userData)
    57055617{
    5706 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_12)
     5618#if defined(QT_QWS_DEPTH_12)
    57075619    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    57085620
     
    57135625    else
    57145626#endif
    5715         blend_src_generic<RegularSpans>(count, spans, userData
    5716                                         Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     5627        blend_src_generic<RegularSpans>(count, spans, userData);
    57175628}
    57185629
    57195630static void blend_transformed_bilinear_rgb444(int count, const QSpan *spans, void *userData)
    57205631{
    5721 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_12)
     5632#if defined(QT_QWS_DEPTH_12)
    57225633    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    57235634
     
    57285639    else
    57295640#endif
    5730         blend_src_generic<RegularSpans>(count, spans, userData
    5731                                         Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     5641        blend_src_generic<RegularSpans>(count, spans, userData);
    57325642}
    57335643
    57345644template <SpanMethod spanMethod>
    5735 Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_bilinear_tiled_argb(int count, const QSpan *spans, void *userData
    5736                                                   Q_TEMPLATE_ENUM_FIX(SpanMethod, spanMethod))
     5645Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_bilinear_tiled_argb(int count, const QSpan *spans, void *userData)
    57375646{
    57385647    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    57395648    if (data->texture.format != QImage::Format_ARGB32_Premultiplied
    57405649        && data->texture.format != QImage::Format_RGB32) {
    5741         blend_src_generic<spanMethod>(count, spans, userData Q_TEMPLATE_ENUM_CALL(SpanMethod, spanMethod));
     5650        blend_src_generic<spanMethod>(count, spans, userData);
    57425651        return;
    57435652    }
     
    59255834
    59265835template <SpanMethod spanMethod>
    5927 Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_argb(int count, const QSpan *spans, void *userData
    5928                                    Q_TEMPLATE_ENUM_FIX(SpanMethod, spanMethod))
     5836Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_argb(int count, const QSpan *spans, void *userData)
    59295837{
    59305838    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    59315839    if (data->texture.format != QImage::Format_ARGB32_Premultiplied
    59325840        && data->texture.format != QImage::Format_RGB32) {
    5933         blend_src_generic<spanMethod>(count, spans, userData Q_TEMPLATE_ENUM_CALL(SpanMethod, spanMethod));
     5841        blend_src_generic<spanMethod>(count, spans, userData);
    59345842        return;
    59355843    }
     
    60535961
    60545962    if (mode != QPainter::CompositionMode_SourceOver) {
    6055         blend_src_generic<RegularSpans>(count, spans, userData
    6056                                         Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     5963        blend_src_generic<RegularSpans>(count, spans, userData);
    60575964        return;
    60585965    }
     
    61966103                                     void *userData)
    61976104{
    6198 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_24)
     6105#if defined(QT_QWS_DEPTH_24)
    61996106    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    62006107
     
    62036110    else
    62046111#endif
    6205         blend_src_generic<RegularSpans>(count, spans, userData
    6206                                         Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     6112        blend_src_generic<RegularSpans>(count, spans, userData);
    62076113}
    62086114
     
    62106116                                       void *userData)
    62116117{
    6212 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_18)
     6118#if defined(QT_QWS_DEPTH_18)
    62136119    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    62146120
     
    62196125    else
    62206126#endif
    6221         blend_src_generic<RegularSpans>(count, spans, userData
    6222                                         Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     6127        blend_src_generic<RegularSpans>(count, spans, userData);
    62236128}
    62246129
     
    62266131                                       void *userData)
    62276132{
    6228 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_18)
     6133#if defined(QT_QWS_DEPTH_18)
    62296134    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    62306135
     
    62356140    else
    62366141#endif
    6237         blend_src_generic<RegularSpans>(count, spans, userData
    6238                                         Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     6142        blend_src_generic<RegularSpans>(count, spans, userData);
    62396143}
    62406144
     
    62426146                                         void *userData)
    62436147{
    6244 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_16)
     6148#if defined(QT_QWS_DEPTH_16)
    62456149    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    62466150
     
    62516155    else
    62526156#endif
    6253         blend_src_generic<RegularSpans>(count, spans, userData
    6254                                         Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     6157        blend_src_generic<RegularSpans>(count, spans, userData);
    62556158}
    62566159
     
    62586161                                       void *userData)
    62596162{
    6260 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_16)
     6163#if defined(QT_QWS_DEPTH_16)
    62616164    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    62626165
     
    62676170    else
    62686171#endif
    6269         blend_src_generic<RegularSpans>(count, spans, userData
    6270                                         Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     6172        blend_src_generic<RegularSpans>(count, spans, userData);
    62716173}
    62726174
     
    62746176                                         void *userData)
    62756177{
    6276 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_15)
     6178#if defined(QT_QWS_DEPTH_15)
    62776179    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    62786180
     
    62836185    else
    62846186#endif
    6285         blend_src_generic<RegularSpans>(count, spans, userData
    6286                                         Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     6187        blend_src_generic<RegularSpans>(count, spans, userData);
    62876188}
    62886189
     
    62906191                                       void *userData)
    62916192{
    6292 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_15)
     6193#if defined(QT_QWS_DEPTH_15)
    62936194    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    62946195
     
    62996200    else
    63006201#endif
    6301         blend_src_generic<RegularSpans>(count, spans, userData
    6302                                         Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     6202        blend_src_generic<RegularSpans>(count, spans, userData);
    63036203}
    63046204
     
    63066206                                         void *userData)
    63076207{
    6308 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_12)
     6208#if defined(QT_QWS_DEPTH_12)
    63096209    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    63106210
     
    63156215    else
    63166216#endif
    6317         blend_src_generic<RegularSpans>(count, spans, userData
    6318                                         Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     6217        blend_src_generic<RegularSpans>(count, spans, userData);
    63196218}
    63206219
     
    63226221                                       void *userData)
    63236222{
    6324 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_12)
     6223#if defined(QT_QWS_DEPTH_12)
    63256224    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    63266225
     
    63316230    else
    63326231#endif
    6333         blend_src_generic<RegularSpans>(count, spans, userData
    6334                                         Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     6232        blend_src_generic<RegularSpans>(count, spans, userData);
    63356233}
    63366234
    63376235template <SpanMethod spanMethod>
    6338 Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_tiled_argb(int count, const QSpan *spans, void *userData
    6339                                          Q_TEMPLATE_ENUM_FIX(SpanMethod, spanMethod))
     6236Q_STATIC_TEMPLATE_FUNCTION void blend_transformed_tiled_argb(int count, const QSpan *spans, void *userData)
    63406237{
    63416238    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    63426239    if (data->texture.format != QImage::Format_ARGB32_Premultiplied
    63436240        && data->texture.format != QImage::Format_RGB32) {
    6344         blend_src_generic<spanMethod>(count, spans, userData Q_TEMPLATE_ENUM_CALL(SpanMethod, spanMethod));
     6241        blend_src_generic<spanMethod>(count, spans, userData);
    63456242        return;
    63466243    }
     
    64766373
    64776374    if (mode != QPainter::CompositionMode_SourceOver) {
    6478         blend_src_generic<RegularSpans>(count, spans, userData
    6479                                         Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     6375        blend_src_generic<RegularSpans>(count, spans, userData);
    64806376        return;
    64816377    }
     
    66206516                                           void *userData)
    66216517{
    6622 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_24)
     6518#if defined(QT_QWS_DEPTH_24)
    66236519    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    66246520
     
    66276523    else
    66286524#endif
    6629         blend_src_generic<RegularSpans>(count, spans, userData
    6630                                         Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     6525        blend_src_generic<RegularSpans>(count, spans, userData);
    66316526}
    66326527
     
    66346529                                             void *userData)
    66356530{
    6636 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_18)
     6531#if defined(QT_QWS_DEPTH_18)
    66376532    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    66386533
     
    66436538    else
    66446539#endif
    6645         blend_src_generic<RegularSpans>(count, spans, userData
    6646                                         Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     6540        blend_src_generic<RegularSpans>(count, spans, userData);
    66476541}
    66486542
     
    66506544                                           void *userData)
    66516545{
    6652 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_18)
     6546#if defined(QT_QWS_DEPTH_18)
    66536547    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    66546548
     
    66596553    else
    66606554#endif
    6661         blend_src_generic<RegularSpans>(count, spans, userData
    6662                                         Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     6555        blend_src_generic<RegularSpans>(count, spans, userData);
    66636556}
    66646557
     
    66666559                                             void *userData)
    66676560{
    6668 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_16)
     6561#if defined(QT_QWS_DEPTH_16)
    66696562    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    66706563
     
    66756568    else
    66766569#endif
    6677         blend_src_generic<RegularSpans>(count, spans, userData
    6678                                         Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     6570        blend_src_generic<RegularSpans>(count, spans, userData);
    66796571}
    66806572
     
    66826574                                           void *userData)
    66836575{
    6684 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_16)
     6576#if defined(QT_QWS_DEPTH_16)
    66856577    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    66866578
     
    66916583    else
    66926584#endif
    6693         blend_src_generic<RegularSpans>(count, spans, userData
    6694                                         Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     6585        blend_src_generic<RegularSpans>(count, spans, userData);
    66956586}
    66966587
     
    66986589                                             void *userData)
    66996590{
    6700 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_15)
     6591#if defined(QT_QWS_DEPTH_15)
    67016592    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    67026593
     
    67076598    else
    67086599#endif
    6709         blend_src_generic<RegularSpans>(count, spans, userData
    6710                                         Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     6600        blend_src_generic<RegularSpans>(count, spans, userData);
    67116601}
    67126602
     
    67146604                                           void *userData)
    67156605{
    6716 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_15)
     6606#if defined(QT_QWS_DEPTH_15)
    67176607    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    67186608
     
    67236613    else
    67246614#endif
    6725         blend_src_generic<RegularSpans>(count, spans, userData
    6726                                         Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     6615        blend_src_generic<RegularSpans>(count, spans, userData);
    67276616}
    67286617
     
    67306619                                             void *userData)
    67316620{
    6732 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_12)
     6621#if defined(QT_QWS_DEPTH_12)
    67336622    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    67346623
     
    67396628    else
    67406629#endif
    6741         blend_src_generic<RegularSpans>(count, spans, userData
    6742                                         Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     6630        blend_src_generic<RegularSpans>(count, spans, userData);
    67436631}
    67446632
     
    67466634                                           void *userData)
    67476635{
    6748 #if !defined(Q_WS_QWS) || defined(QT_QWS_DEPTH_12)
     6636#if defined(QT_QWS_DEPTH_12)
    67496637    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
    67506638
     
    67556643    else
    67566644#endif
    6757         blend_src_generic<RegularSpans>(count, spans, userData
    6758                                         Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
    6759 }
    6760 
    6761 #if defined(Q_CC_MSVC) && _MSC_VER <= 1300 && !defined(Q_CC_INTEL)
    6762 
    6763 // explicit template instantiations needed to compile with VC6 and VC2002
    6764 
    6765 #define SPANFUNC_INSTANTIATION(Name, Arg)  \
    6766 static inline void Name##_##Arg(int count, const QSpan *spans, void *userData) \
    6767 { \
    6768     Name<Arg>(count, spans, userData Q_TEMPLATE_ENUM_CALL(SpanMethod, Arg)); \
    6769 }
    6770 
    6771 SPANFUNC_INSTANTIATION(blend_untransformed_generic, RegularSpans);
    6772 SPANFUNC_INSTANTIATION(blend_untransformed_argb, RegularSpans);
    6773 SPANFUNC_INSTANTIATION(blend_tiled_generic, RegularSpans);
    6774 SPANFUNC_INSTANTIATION(blend_tiled_argb, RegularSpans);
    6775 SPANFUNC_INSTANTIATION(blend_src_generic, RegularSpans);
    6776 SPANFUNC_INSTANTIATION(blend_transformed_argb, RegularSpans);
    6777 SPANFUNC_INSTANTIATION(blend_transformed_tiled_argb, RegularSpans);
    6778 SPANFUNC_INSTANTIATION(blend_transformed_bilinear_argb, RegularSpans);
    6779 SPANFUNC_INSTANTIATION(blend_transformed_bilinear_tiled_argb, RegularSpans);
    6780 #undef SPANFUNC_INSTANTIATION
    6781 
    6782 #define SPANFUNC_POINTER(Name, Arg) Name##_##Arg
    6783 
    6784 #else // !VC6 && !VC2002
     6645        blend_src_generic<RegularSpans>(count, spans, userData);
     6646}
     6647
    67856648# define SPANFUNC_POINTER(Name, Arg) Name<Arg>
    6786 #endif
    67876649
    67886650
     
    71517013
    71527014    } else {
    7153         blend_src_generic<RegularSpans>(count, spans, userData
    7154                                         Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     7015        blend_src_generic<RegularSpans>(count, spans, userData);
    71557016    }
    71567017}
     
    72007061
    72017062    } else {
    7202         blend_src_generic<RegularSpans>(count, spans, userData
    7203                                         Q_TEMPLATE_ENUM_CALL(SpanMethod, RegularSpans));
     7063        blend_src_generic<RegularSpans>(count, spans, userData);
    72047064    }
    72057065}
     
    72607120
    72617121void qt_build_pow_tables() {
    7262     qreal smoothing = 1.7;
     7122    qreal smoothing = qreal(1.7);
     7123
     7124#ifdef Q_WS_MAC
     7125    // decided by testing a few things on an iMac, should probably get this from the
     7126    // system...
     7127    smoothing = 2.0;
     7128#endif
    72637129
    72647130#ifdef Q_WS_WIN
     
    72767142#else
    72777143    for (int i=0; i<256; ++i) {
    7278         qt_pow_rgb_gamma[i] = uchar(qRound(pow(i / 255.0, smoothing) * 255));
    7279         qt_pow_rgb_invgamma[i] = uchar(qRound(pow(i / 255.0, 1 / smoothing) * 255));
     7144        qt_pow_rgb_gamma[i] = uchar(qRound(qPow(i / qreal(255.0), smoothing) * 255));
     7145        qt_pow_rgb_invgamma[i] = uchar(qRound(qPow(i / qreal(255.), 1 / smoothing) * 255));
    72807146    }
    72817147#endif
     
    72847150    const qreal gray_gamma = 2.31;
    72857151    for (int i=0; i<256; ++i)
    7286         qt_pow_gamma[i] = uint(qRound(pow(i / 255.0, gray_gamma) * 2047));
     7152        qt_pow_gamma[i] = uint(qRound(qPow(i / qreal(255.), gray_gamma) * 2047));
    72877153    for (int i=0; i<2048; ++i)
    7288         qt_pow_invgamma[i] = uchar(qRound(pow(i / 2047.0, 1 / gray_gamma) * 255));
     7154        qt_pow_invgamma[i] = uchar(qRound(qPow(i / 2047.0, 1 / gray_gamma) * 255));
    72897155#endif
    72907156}
     
    74067272                    {
    74077273                        int ialpha = 255 - coverage;
    7408                         dest[i] = BYTE_MUL(c, uint(coverage)) + BYTE_MUL(dest[i], ialpha);
     7274                        dest[i] = INTERPOLATE_PIXEL_255(c, coverage, dest[i], ialpha);
    74097275                    }
    74107276                }
     
    74477313                        {
    74487314                            int ialpha = 255 - coverage;
    7449                             dest[xp] = BYTE_MUL(c, uint(coverage)) + BYTE_MUL(dest[xp], ialpha);
     7315                            dest[xp] = INTERPOLATE_PIXEL_255(c, coverage, dest[xp], ialpha);
    74507316                        }
    74517317                    }
     
    75497415QT_RECTFILL(quint16)
    75507416QT_RECTFILL(qargb8565)
    7551 QT_RECTFILL(qrgb666);
    7552 QT_RECTFILL(qargb6666);
     7417QT_RECTFILL(qrgb666)
     7418QT_RECTFILL(qargb6666)
    75537419QT_RECTFILL(qrgb555)
    75547420QT_RECTFILL(qargb8555)
    75557421QT_RECTFILL(qrgb888)
    7556 QT_RECTFILL(qrgb444);
    7557 QT_RECTFILL(qargb4444);
     7422QT_RECTFILL(qrgb444)
     7423QT_RECTFILL(qargb4444)
    75587424#undef QT_RECTFILL
     7425
     7426inline static void qt_rectfill_nonpremul_quint32(QRasterBuffer *rasterBuffer,
     7427                                                 int x, int y, int width, int height,
     7428                                                 quint32 color)
     7429{
     7430    qt_rectfill<quint32>(reinterpret_cast<quint32 *>(rasterBuffer->buffer()),
     7431                         INV_PREMUL(color), x, y, width, height, rasterBuffer->bytesPerLine());
     7432}
    75597433
    75607434
     
    76007474        qt_alphamapblit_quint32,
    76017475        qt_alphargbblit_quint32,
    7602         qt_rectfill_quint32
     7476        qt_rectfill_nonpremul_quint32
    76037477    },
    76047478    // Format_ARGB32_Premultiplied
     
    78537727    SSE2        = 0x20,
    78547728    CMOV        = 0x40,
    7855     IWMMXT      = 0x80
     7729    IWMMXT      = 0x80,
     7730    NEON        = 0x100
    78567731};
    78577732
     
    78797754    static const bool doIWMMXT = !qgetenv("QT_NO_IWMMXT").toInt();
    78807755    return doIWMMXT ? IWMMXT : 0;
     7756#elif defined(QT_HAVE_NEON)
     7757    static const bool doNEON = !qgetenv("QT_NO_NEON").toInt();
     7758    return doNEON ? NEON : 0;
    78817759#else
    78827760    uint features = 0;
     
    80337911}
    80347912
     7913#if defined(Q_CC_RVCT) && defined(QT_HAVE_ARMV6)
     7914// Move these to qdrawhelper_arm.c when all
     7915// functions are implemented using arm assembly.
     7916static CompositionFunctionSolid qt_functionForModeSolid_ARMv6[numCompositionFunctions] = {
     7917        comp_func_solid_SourceOver,
     7918        comp_func_solid_DestinationOver,
     7919        comp_func_solid_Clear,
     7920        comp_func_solid_Source,
     7921        comp_func_solid_Destination,
     7922        comp_func_solid_SourceIn,
     7923        comp_func_solid_DestinationIn,
     7924        comp_func_solid_SourceOut,
     7925        comp_func_solid_DestinationOut,
     7926        comp_func_solid_SourceAtop,
     7927        comp_func_solid_DestinationAtop,
     7928        comp_func_solid_XOR,
     7929        comp_func_solid_Plus,
     7930        comp_func_solid_Multiply,
     7931        comp_func_solid_Screen,
     7932        comp_func_solid_Overlay,
     7933        comp_func_solid_Darken,
     7934        comp_func_solid_Lighten,
     7935        comp_func_solid_ColorDodge,
     7936        comp_func_solid_ColorBurn,
     7937        comp_func_solid_HardLight,
     7938        comp_func_solid_SoftLight,
     7939        comp_func_solid_Difference,
     7940        comp_func_solid_Exclusion,
     7941        rasterop_solid_SourceOrDestination,
     7942        rasterop_solid_SourceAndDestination,
     7943        rasterop_solid_SourceXorDestination,
     7944        rasterop_solid_NotSourceAndNotDestination,
     7945        rasterop_solid_NotSourceOrNotDestination,
     7946        rasterop_solid_NotSourceXorDestination,
     7947        rasterop_solid_NotSource,
     7948        rasterop_solid_NotSourceAndDestination,
     7949        rasterop_solid_SourceAndNotDestination
     7950};
     7951
     7952static CompositionFunction qt_functionForMode_ARMv6[numCompositionFunctions] = {
     7953        comp_func_SourceOver_armv6,
     7954        comp_func_DestinationOver,
     7955        comp_func_Clear,
     7956        comp_func_Source_armv6,
     7957        comp_func_Destination,
     7958        comp_func_SourceIn,
     7959        comp_func_DestinationIn,
     7960        comp_func_SourceOut,
     7961        comp_func_DestinationOut,
     7962        comp_func_SourceAtop,
     7963        comp_func_DestinationAtop,
     7964        comp_func_XOR,
     7965        comp_func_Plus,
     7966        comp_func_Multiply,
     7967        comp_func_Screen,
     7968        comp_func_Overlay,
     7969        comp_func_Darken,
     7970        comp_func_Lighten,
     7971        comp_func_ColorDodge,
     7972        comp_func_ColorBurn,
     7973        comp_func_HardLight,
     7974        comp_func_SoftLight,
     7975        comp_func_Difference,
     7976        comp_func_Exclusion,
     7977        rasterop_SourceOrDestination,
     7978        rasterop_SourceAndDestination,
     7979        rasterop_SourceXorDestination,
     7980        rasterop_NotSourceAndNotDestination,
     7981        rasterop_NotSourceOrNotDestination,
     7982        rasterop_NotSourceXorDestination,
     7983        rasterop_NotSource,
     7984        rasterop_NotSourceAndDestination,
     7985        rasterop_SourceAndNotDestination
     7986};
     7987
     7988static void qt_blend_color_argb_armv6(int count, const QSpan *spans, void *userData)
     7989{
     7990    QSpanData *data = reinterpret_cast<QSpanData *>(userData);
     7991
     7992    CompositionFunctionSolid func = qt_functionForModeSolid_ARMv6[data->rasterBuffer->compositionMode];
     7993    while (count--) {
     7994        uint *target = ((uint *)data->rasterBuffer->scanLine(spans->y)) + spans->x;
     7995        func(target, spans->len, data->solid.color, spans->coverage);
     7996        ++spans;
     7997    }
     7998}
     7999
     8000#endif // Q_CC_RVCT && QT_HAVE_ARMV6
     8001
     8002
    80358003void qInitDrawhelperAsm()
    80368004{
     
    81488116#endif // QT_NO_DEBUG
    81498117
     8118#if defined(Q_CC_RVCT) && defined(QT_HAVE_ARMV6)
     8119        functionForModeAsm = qt_functionForMode_ARMv6;
     8120        functionForModeSolidAsm = qt_functionForModeSolid_ARMv6;
     8121
     8122        qt_memfill32 = qt_memfill32_armv6;
     8123
     8124        qDrawHelper[QImage::Format_ARGB32_Premultiplied].blendColor = qt_blend_color_argb_armv6;
     8125
     8126        qBlendFunctions[QImage::Format_RGB32][QImage::Format_RGB32] = qt_blend_rgb32_on_rgb32_armv6;
     8127        qBlendFunctions[QImage::Format_ARGB32_Premultiplied][QImage::Format_RGB32] = qt_blend_rgb32_on_rgb32_armv6;
     8128        qBlendFunctions[QImage::Format_RGB32][QImage::Format_ARGB32_Premultiplied] = qt_blend_argb32_on_argb32_armv6;
     8129        qBlendFunctions[QImage::Format_ARGB32_Premultiplied][QImage::Format_ARGB32_Premultiplied] = qt_blend_argb32_on_argb32_armv6;
     8130#elif defined(QT_HAVE_NEON)
     8131        if (features & NEON) {
     8132            qBlendFunctions[QImage::Format_RGB32][QImage::Format_RGB32] = qt_blend_rgb32_on_rgb32_neon;
     8133            qBlendFunctions[QImage::Format_ARGB32_Premultiplied][QImage::Format_RGB32] = qt_blend_rgb32_on_rgb32_neon;
     8134            qBlendFunctions[QImage::Format_RGB32][QImage::Format_ARGB32_Premultiplied] = qt_blend_argb32_on_argb32_neon;
     8135            qBlendFunctions[QImage::Format_ARGB32_Premultiplied][QImage::Format_ARGB32_Premultiplied] = qt_blend_argb32_on_argb32_neon;
     8136        }
     8137#endif
     8138
    81508139    if (functionForModeSolidAsm) {
    81518140        const int destinationMode = QPainter::CompositionMode_Destination;
Note: See TracChangeset for help on using the changeset viewer.