Changeset 64157 in webkit


Ignore:
Timestamp:
Jul 27, 2010 2:17:44 PM (14 years ago)
Author:
andreas.kling@nokia.com
Message:

2010-07-27 Andreas Kling <andreas.kling@nokia.com>

Reviewed by Kenneth Rohde Christiansen.

[Qt] putImageData() optimizations
https://bugs.webkit.org/show_bug.cgi?id=43059

  • Single-pass premultiplication and BGR->RGB conversion
  • Use ARGB32PM for the temporary image so Qt calls the fast Source composition function
  • platform/graphics/qt/ImageBufferQt.cpp: (WebCore::premultiply): Added (static inline) (WebCore::putImageData):
Location:
trunk/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r64154 r64157  
     12010-07-27  Andreas Kling  <andreas.kling@nokia.com>
     2
     3        Reviewed by Kenneth Rohde Christiansen.
     4
     5        [Qt] putImageData() optimizations
     6        https://bugs.webkit.org/show_bug.cgi?id=43059
     7
     8        - Single-pass premultiplication and BGR->RGB conversion
     9        - Use ARGB32PM for the temporary image so Qt calls the
     10          fast Source composition function
     11
     12        * platform/graphics/qt/ImageBufferQt.cpp:
     13        (WebCore::premultiply): Added (static inline)
     14        (WebCore::putImageData):
     15
    1162010-07-27  Anders Carlsson  <andersca@apple.com>
    217
  • trunk/WebCore/platform/graphics/qt/ImageBufferQt.cpp

    r64041 r64157  
    238238}
    239239
     240static inline unsigned int premultiply(unsigned int x)
     241{
     242    unsigned int a = x >> 24;
     243    unsigned int t = (x & 0xff00ff) * a;
     244    t = (t + ((t >> 8) & 0xff00ff) + 0x800080) >> 8;
     245    t &= 0xff00ff;
     246
     247    x = ((x >> 8) & 0xff) * a;
     248    x = (x + ((x >> 8) & 0xff) + 0x80);
     249    x &= 0xff00;
     250    x |= t | (a << 24);
     251    return x;
     252}
     253
    240254template <Multiply multiplied>
    241255void putImageData(ImageData*& source, const IntRect& sourceRect, const IntPoint& destPoint, ImageBufferData& data, const IntSize& size)
     
    269283    unsigned srcBytesPerRow = 4 * source->width();
    270284
    271     QRect destRect(destx, desty, endx - destx, endy - desty);
    272 
    273     QImage::Format format = multiplied == Unmultiplied ? QImage::Format_ARGB32 : QImage::Format_ARGB32_Premultiplied;
    274     QImage image(destRect.size(), format);
    275 
    276     unsigned char* srcRows = source->data()->data()->data() + originy * srcBytesPerRow + originx * 4;
    277     for (int y = 0; y < numRows; ++y) {
    278         quint32* scanLine = reinterpret_cast<quint32*>(image.scanLine(y));
    279         for (int x = 0; x < numColumns; x++) {
    280             // ImageData stores the pixels in RGBA while QImage is ARGB
    281             quint32 pixel = reinterpret_cast<quint32*>(srcRows + 4 * x)[0];
    282             pixel = ((pixel << 16) & 0xff0000) | ((pixel >> 16) & 0xff) | (pixel & 0xff00ff00);
    283             scanLine[x] = pixel;
    284         }
    285 
    286         srcRows += srcBytesPerRow;
     285    // NOTE: For unmultiplied input data, we do the premultiplication below.
     286    QImage image(numColumns, numRows, QImage::Format_ARGB32_Premultiplied);
     287    uchar* bits = image.bits();
     288    const int bytesPerLine = image.bytesPerLine();
     289
     290    const quint32* srcScanLine = reinterpret_cast<const quint32*>(source->data()->data()->data() + originy * srcBytesPerRow + originx * 4);
     291
     292    if (multiplied == Unmultiplied) {
     293        for (int y = 0; y < numRows; ++y) {
     294            quint32* destScanLine = reinterpret_cast<quint32*>(bits + y * bytesPerLine);
     295            for (int x = 0; x < numColumns; x++) {
     296                // Premultiply and convert BGR to RGB.
     297                quint32 pixel = srcScanLine[x];
     298                destScanLine[x] = premultiply(((pixel << 16) & 0xff0000) | ((pixel >> 16) & 0xff) | (pixel & 0xff00ff00));
     299            }
     300            srcScanLine += source->width();
     301        }
     302    } else {
     303        for (int y = 0; y < numRows; ++y) {
     304            quint32* destScanLine = reinterpret_cast<quint32*>(bits + y * bytesPerLine);
     305            for (int x = 0; x < numColumns; x++) {
     306                // Convert BGR to RGB.
     307                quint32 pixel = srcScanLine[x];
     308                destScanLine[x] = ((pixel << 16) & 0xff0000) | ((pixel >> 16) & 0xff) | (pixel & 0xff00ff00);
     309            }
     310            srcScanLine += source->width();
     311        }
    287312    }
    288313
     
    300325
    301326    data.m_painter->setCompositionMode(QPainter::CompositionMode_Source);
    302     data.m_painter->drawImage(destRect, image);
     327    data.m_painter->drawImage(destx, desty, image);
    303328
    304329    if (!isPainting)
Note: See TracChangeset for help on using the changeset viewer.