Changeset 64041 in webkit


Ignore:
Timestamp:
Jul 26, 2010 4:51:45 AM (14 years ago)
Author:
andreas.kling@nokia.com
Message:

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

Reviewed by Kenneth Rohde Christiansen.

[Qt] getImageData(): Single-pass RGB->BGR and un-premultiplication
https://bugs.webkit.org/show_bug.cgi?id=42945

Combine the two operations into a single loop over the pixel data.
Yields a considerable FPS gain on http://www.semantix.gr/statue.html

  • platform/graphics/qt/ImageBufferQt.cpp: (WebCore::getImageData):
Location:
trunk/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r64040 r64041  
     12010-07-26  Andreas Kling  <andreas.kling@nokia.com>
     2
     3        Reviewed by Kenneth Rohde Christiansen.
     4
     5        [Qt] getImageData(): Single-pass RGB->BGR and un-premultiplication
     6        https://bugs.webkit.org/show_bug.cgi?id=42945
     7
     8        Combine the two operations into a single loop over the pixel data.
     9        Yields a considerable FPS gain on http://www.semantix.gr/statue.html
     10
     11        * platform/graphics/qt/ImageBufferQt.cpp:
     12        (WebCore::getImageData):
     13
    1142010-07-26  Pavel Feldman  <pfeldman@chromium.org>
    215
  • trunk/WebCore/platform/graphics/qt/ImageBufferQt.cpp

    r63652 r64041  
    176176    int numRows = endy - originy;
    177177
    178     QImage image = imageData.m_pixmap.toImage();
    179     if (multiplied == Unmultiplied)
    180         image = image.convertToFormat(QImage::Format_ARGB32);
    181     else
    182         image = image.convertToFormat(QImage::Format_ARGB32_Premultiplied);
     178    // NOTE: For unmultiplied data, we undo the premultiplication below.
     179    QImage image = imageData.m_pixmap.toImage().convertToFormat(QImage::Format_ARGB32_Premultiplied);
    183180
    184181    ASSERT(!image.isNull());
    185182
    186     unsigned destBytesPerRow = 4 * rect.width();
    187     unsigned char* destRows = data + desty * destBytesPerRow + destx * 4;
    188     for (int y = 0; y < numRows; ++y) {
     183    const int bytesPerLine = image.bytesPerLine();
    189184#if QT_VERSION >= 0x040700
    190         const quint32* scanLine = reinterpret_cast<const quint32*>(image.constScanLine(y + originy));
     185    const uchar* bits = image.constBits();
    191186#else
    192         quint32* scanLine = reinterpret_cast<quint32*>(image.scanLine(y + originy));
     187    const uchar* bits = image.bits();
    193188#endif
    194         for (int x = 0; x < numColumns; x++) {
    195             QRgb value = scanLine[x + originx];
    196             int basex = x * 4;
    197 
    198             destRows[basex] = qRed(value);
    199             destRows[basex + 1] = qGreen(value);
    200             destRows[basex + 2] = qBlue(value);
    201             destRows[basex + 3] = qAlpha(value);
    202         }
    203         destRows += destBytesPerRow;
     189
     190    quint32* destRows = reinterpret_cast<quint32*>(&data[desty * rect.width() + destx]);
     191
     192    if (multiplied == Unmultiplied) {
     193        for (int y = 0; y < numRows; ++y) {
     194            const quint32* scanLine = reinterpret_cast<const quint32*>(bits + (y + originy) * bytesPerLine);
     195            for (int x = 0; x < numColumns; x++) {
     196                QRgb pixel = scanLine[x + originx];
     197                int alpha = qAlpha(pixel);
     198                // Un-premultiply and convert RGB to BGR.
     199                if (alpha == 255)
     200                    destRows[x] = (0xFF000000
     201                                | (qBlue(pixel) << 16)
     202                                | (qGreen(pixel) << 8)
     203                                | (qRed(pixel)));
     204                else if (alpha > 0)
     205                    destRows[x] = ((alpha << 24)
     206                                | (((255 * qBlue(pixel)) / alpha)) << 16)
     207                                | (((255 * qGreen(pixel)) / alpha) << 8)
     208                                | ((255 * qRed(pixel)) / alpha);
     209                else
     210                    destRows[x] = 0;
     211            }
     212            destRows += rect.width();
     213        }
     214    } else {
     215        for (int y = 0; y < numRows; ++y) {
     216            const quint32* scanLine = reinterpret_cast<const quint32*>(bits + (y + originy) * bytesPerLine);
     217            for (int x = 0; x < numColumns; x++) {
     218                QRgb pixel = scanLine[x + originx];
     219                // Convert RGB to BGR.
     220                destRows[x] = ((pixel << 16) & 0xff0000) | ((pixel >> 16) & 0xff) | (pixel & 0xff00ff00);
     221
     222            }
     223            destRows += rect.width();
     224        }
    204225    }
    205226
Note: See TracChangeset for help on using the changeset viewer.