src/gui/painting/qdrawhelper.cpp
changeset 7 f7bc934e204c
parent 3 41300fa6a67c
equal deleted inserted replaced
3:41300fa6a67c 7:f7bc934e204c
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the QtGui module of the Qt Toolkit.
     7 ** This file is part of the QtGui module of the Qt Toolkit.
     8 **
     8 **
  1265 
  1265 
  1266 /*
  1266 /*
  1267   result = 0
  1267   result = 0
  1268   d = d * cia
  1268   d = d * cia
  1269 */
  1269 */
       
  1270 #define comp_func_Clear_impl(dest, length, const_alpha)\
       
  1271 {\
       
  1272     if (const_alpha == 255) {\
       
  1273         QT_MEMFILL_UINT(dest, length, 0);\
       
  1274     } else {\
       
  1275         int ialpha = 255 - const_alpha;\
       
  1276         PRELOAD_INIT(dest)\
       
  1277         for (int i = 0; i < length; ++i) {\
       
  1278             PRELOAD_COND(dest)\
       
  1279             dest[i] = BYTE_MUL(dest[i], ialpha);\
       
  1280         }\
       
  1281     }\
       
  1282 }
       
  1283 
  1270 static void QT_FASTCALL comp_func_solid_Clear(uint *dest, int length, uint, uint const_alpha)
  1284 static void QT_FASTCALL comp_func_solid_Clear(uint *dest, int length, uint, uint const_alpha)
  1271 {
  1285 {
  1272     if (const_alpha == 255) {
  1286     comp_func_Clear_impl(dest, length, const_alpha);
  1273         QT_MEMFILL_UINT(dest, length, 0);
       
  1274     } else {
       
  1275         int ialpha = 255 - const_alpha;
       
  1276         PRELOAD_INIT(dest)
       
  1277         for (int i = 0; i < length; ++i) {
       
  1278             PRELOAD_COND(dest)
       
  1279             dest[i] = BYTE_MUL(dest[i], ialpha);
       
  1280         }
       
  1281     }
       
  1282 }
  1287 }
  1283 
  1288 
  1284 static void QT_FASTCALL comp_func_Clear(uint *dest, const uint *, int length, uint const_alpha)
  1289 static void QT_FASTCALL comp_func_Clear(uint *dest, const uint *, int length, uint const_alpha)
  1285 {
  1290 {
  1286     if (const_alpha == 255) {
  1291     comp_func_Clear_impl(dest, length, const_alpha);
  1287         QT_MEMFILL_UINT(dest, length, 0);
       
  1288     } else {
       
  1289         int ialpha = 255 - const_alpha;
       
  1290         PRELOAD_INIT(dest)
       
  1291         for (int i = 0; i < length; ++i) {
       
  1292             PRELOAD_COND(dest)
       
  1293             dest[i] = BYTE_MUL(dest[i], ialpha);
       
  1294         }
       
  1295     }
       
  1296 }
  1292 }
  1297 
  1293 
  1298 /*
  1294 /*
  1299   result = s
  1295   result = s
  1300   dest = s * ca + d * cia
  1296   dest = s * ca + d * cia
  1362     PRELOAD_INIT2(dest, src)
  1358     PRELOAD_INIT2(dest, src)
  1363     if (const_alpha == 255) {
  1359     if (const_alpha == 255) {
  1364         for (int i = 0; i < length; ++i) {
  1360         for (int i = 0; i < length; ++i) {
  1365             PRELOAD_COND2(dest, src)
  1361             PRELOAD_COND2(dest, src)
  1366             uint s = src[i];
  1362             uint s = src[i];
  1367             dest[i] = s + BYTE_MUL(dest[i], qAlpha(~s));
  1363             if (s >= 0xff000000)
       
  1364                 dest[i] = s;
       
  1365             else if (s != 0)
       
  1366                 dest[i] = s + BYTE_MUL(dest[i], qAlpha(~s));
  1368         }
  1367         }
  1369     } else {
  1368     } else {
  1370         for (int i = 0; i < length; ++i) {
  1369         for (int i = 0; i < length; ++i) {
  1371             PRELOAD_COND2(dest, src)
  1370             PRELOAD_COND2(dest, src)
  1372             uint s = BYTE_MUL(src[i], const_alpha);
  1371             uint s = BYTE_MUL(src[i], const_alpha);
  2403     if (src2 < sa)
  2402     if (src2 < sa)
  2404         return (dst * (sa * 255 + (src2 - sa) * (255 - dst_np)) + temp) / 65025;
  2403         return (dst * (sa * 255 + (src2 - sa) * (255 - dst_np)) + temp) / 65025;
  2405     else if (4 * dst <= da)
  2404     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;
  2405         return (dst * sa * 255 + da * (src2 - sa) * ((((16 * dst_np - 12 * 255) * dst_np + 3 * 65025) * dst_np) / 65025) + temp) / 65025;
  2407     else {
  2406     else {
       
  2407 #   ifdef Q_CC_RVCT // needed to avoid compiler crash in RVCT 2.2
       
  2408         return (dst * sa * 255 + da * (src2 - sa) * (qIntSqrtInt(dst_np * 255) - dst_np) + temp) / 65025;
       
  2409 #   else
  2408         return (dst * sa * 255 + da * (src2 - sa) * (int(sqrt(qreal(dst_np * 255))) - dst_np) + temp) / 65025;
  2410         return (dst * sa * 255 + da * (src2 - sa) * (int(sqrt(qreal(dst_np * 255))) - dst_np) + temp) / 65025;
       
  2411 #   endif
  2409     }
  2412     }
  2410 }
  2413 }
  2411 
  2414 
  2412 template <typename T>
  2415 template <typename T>
  2413 Q_STATIC_TEMPLATE_FUNCTION inline void comp_func_solid_SoftLight_impl(uint *dest, int length, uint color, const T &coverage)
  2416 Q_STATIC_TEMPLATE_FUNCTION inline void comp_func_solid_SoftLight_impl(uint *dest, int length, uint color, const T &coverage)
  7169         && qRed(*dst) <= da && qBlue(*dst) <= da && qGreen(*dst) <= da
  7172         && qRed(*dst) <= da && qBlue(*dst) <= da && qGreen(*dst) <= da
  7170 #endif
  7173 #endif
  7171         ) {
  7174         ) {
  7172 
  7175 
  7173         int a = qGray(coverage);
  7176         int a = qGray(coverage);
  7174         sr = qt_div_255(sr * a);
  7177         sr = qt_div_255(qt_pow_rgb_invgamma[sr] * a);
  7175         sg = qt_div_255(sg * a);
  7178         sg = qt_div_255(qt_pow_rgb_invgamma[sg] * a);
  7176         sb = qt_div_255(sb * a);
  7179         sb = qt_div_255(qt_pow_rgb_invgamma[sb] * a);
  7177 
  7180 
  7178         int ia = 255 - a;
  7181         int ia = 255 - a;
  7179         dr = qt_div_255(dr * ia);
  7182         dr = qt_div_255(dr * ia);
  7180         dg = qt_div_255(dg * ia);
  7183         dg = qt_div_255(dg * ia);
  7181         db = qt_div_255(db * ia);
  7184         db = qt_div_255(db * ia);
  8087             functionForModeAsm = qt_functionForMode_SSE3DNOW;
  8090             functionForModeAsm = qt_functionForMode_SSE3DNOW;
  8088             functionForModeSolidAsm = qt_functionForModeSolid_SSE3DNOW;
  8091             functionForModeSolidAsm = qt_functionForModeSolid_SSE3DNOW;
  8089             qDrawHelper[QImage::Format_ARGB32_Premultiplied].blendColor = qt_blend_color_argb_sse3dnow;
  8092             qDrawHelper[QImage::Format_ARGB32_Premultiplied].blendColor = qt_blend_color_argb_sse3dnow;
  8090         }
  8093         }
  8091 #endif // 3DNOW
  8094 #endif // 3DNOW
  8092         extern void qt_blend_rgb32_on_rgb32_sse(uchar *destPixels, int dbpl,
  8095 
  8093                                                 const uchar *srcPixels, int sbpl,
  8096 
  8094                                                 int w, int h,
  8097 #ifdef QT_HAVE_SSE2
  8095                                                 int const_alpha);
  8098         if (features & SSE2) {
  8096         extern void qt_blend_argb32_on_argb32_sse(uchar *destPixels, int dbpl,
  8099             extern void qt_blend_rgb32_on_rgb32_sse2(uchar *destPixels, int dbpl,
  8097                                                   const uchar *srcPixels, int sbpl,
  8100                                                      const uchar *srcPixels, int sbpl,
  8098                                                   int w, int h,
  8101                                                      int w, int h,
  8099                                                   int const_alpha);
  8102                                                      int const_alpha);
  8100 
  8103             extern void qt_blend_argb32_on_argb32_sse2(uchar *destPixels, int dbpl,
  8101         qBlendFunctions[QImage::Format_RGB32][QImage::Format_RGB32] = qt_blend_rgb32_on_rgb32_sse;
  8104                                                        const uchar *srcPixels, int sbpl,
  8102         qBlendFunctions[QImage::Format_ARGB32_Premultiplied][QImage::Format_RGB32] = qt_blend_rgb32_on_rgb32_sse;
  8105                                                        int w, int h,
  8103         qBlendFunctions[QImage::Format_RGB32][QImage::Format_ARGB32_Premultiplied] = qt_blend_argb32_on_argb32_sse;
  8106                                                        int const_alpha);
  8104         qBlendFunctions[QImage::Format_ARGB32_Premultiplied][QImage::Format_ARGB32_Premultiplied] = qt_blend_argb32_on_argb32_sse;
  8107 
  8105     }
  8108 
       
  8109             qBlendFunctions[QImage::Format_RGB32][QImage::Format_RGB32] = qt_blend_rgb32_on_rgb32_sse2;
       
  8110             qBlendFunctions[QImage::Format_ARGB32_Premultiplied][QImage::Format_RGB32] = qt_blend_rgb32_on_rgb32_sse2;
       
  8111             qBlendFunctions[QImage::Format_RGB32][QImage::Format_ARGB32_Premultiplied] = qt_blend_argb32_on_argb32_sse2;
       
  8112             qBlendFunctions[QImage::Format_ARGB32_Premultiplied][QImage::Format_ARGB32_Premultiplied] = qt_blend_argb32_on_argb32_sse2;
       
  8113         } else
       
  8114 #endif
       
  8115         {
       
  8116             extern void qt_blend_rgb32_on_rgb32_sse(uchar *destPixels, int dbpl,
       
  8117                                                     const uchar *srcPixels, int sbpl,
       
  8118                                                     int w, int h,
       
  8119                                                     int const_alpha);
       
  8120             extern void qt_blend_argb32_on_argb32_sse(uchar *destPixels, int dbpl,
       
  8121                                                       const uchar *srcPixels, int sbpl,
       
  8122                                                       int w, int h,
       
  8123                                                       int const_alpha);
       
  8124 
       
  8125 
       
  8126             qBlendFunctions[QImage::Format_RGB32][QImage::Format_RGB32] = qt_blend_rgb32_on_rgb32_sse;
       
  8127             qBlendFunctions[QImage::Format_ARGB32_Premultiplied][QImage::Format_RGB32] = qt_blend_rgb32_on_rgb32_sse;
       
  8128             qBlendFunctions[QImage::Format_RGB32][QImage::Format_ARGB32_Premultiplied] = qt_blend_argb32_on_argb32_sse;
       
  8129             qBlendFunctions[QImage::Format_ARGB32_Premultiplied][QImage::Format_ARGB32_Premultiplied] = qt_blend_argb32_on_argb32_sse;
       
  8130         }
       
  8131 }
  8106 #endif // SSE
  8132 #endif // SSE
  8107 
  8133 
  8108 #ifdef QT_HAVE_IWMMXT
  8134 #ifdef QT_HAVE_IWMMXT
  8109     if (features & IWMMXT) {
  8135     if (features & IWMMXT) {
  8110         functionForModeAsm = qt_functionForMode_IWMMXT;
  8136         functionForModeAsm = qt_functionForMode_IWMMXT;