Changeset 102158 in webkit


Ignore:
Timestamp:
Dec 6, 2011 11:29:42 AM (12 years ago)
Author:
noel.gordon@gmail.com
Message:

WebPImageDecoder computes image width and height multiple times
https://bugs.webkit.org/show_bug.cgi?id=73796

Reviewed by Adam Barth.

Once sufficient image data arrives, we can compute the decoded image height
and width from the WEBP image header data.

From then on, the decoded image size is known so there's no need to re-read
it from the WEBP image header again.

No change in behavior, so no new tests.

  • platform/image-decoders/webp/WEBPImageDecoder.cpp:

(WebCore::WEBPImageDecoder::decode):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r102157 r102158  
     12011-12-06  Noel Gordon  <noel.gordon@gmail.com>
     2
     3        WebPImageDecoder computes image width and height multiple times
     4        https://bugs.webkit.org/show_bug.cgi?id=73796
     5
     6        Reviewed by Adam Barth.
     7
     8        Once sufficient image data arrives, we can compute the decoded image height
     9        and width from the WEBP image header data.
     10
     11        From then on, the decoded image size is known so there's no need to re-read
     12        it from the WEBP image header again.
     13
     14        No change in behavior, so no new tests.
     15
     16        * platform/image-decoders/webp/WEBPImageDecoder.cpp:
     17        (WebCore::WEBPImageDecoder::decode):
     18
    1192011-12-06  Mike Reed  <reed@google.com>
    220
  • trunk/Source/WebCore/platform/image-decoders/webp/WEBPImageDecoder.cpp

    r101948 r102158  
    8686        return false;
    8787
     88    const uint8_t* dataBytes = reinterpret_cast<const uint8_t*>(m_data->data());
    8889    const size_t dataSize = m_data->size();
    89     if (dataSize < sizeOfHeader)
    90         return true;
    9190
    92     int width, height;
    93     const uint8_t* dataBytes = reinterpret_cast<const uint8_t*>(m_data->data());
    94     if (!WebPGetInfo(dataBytes, dataSize, &width, &height))
    95         return setFailed();
    96     if (!ImageDecoder::isSizeAvailable() && !setSize(width, height))
    97         return setFailed();
     91    if (!ImageDecoder::isSizeAvailable()) {
     92        if (dataSize < sizeOfHeader)
     93            return false;
     94        int width, height;
     95        if (!WebPGetInfo(dataBytes, dataSize, &width, &height))
     96            return setFailed();
     97        if (!setSize(width, height))
     98            return setFailed();
     99    }
     100
     101    ASSERT(ImageDecoder::isSizeAvailable());
    98102    if (onlySize)
    99103        return true;
     104    int width = size().width();
     105    int height = size().height();
    100106
    101107    bool allDataReceived = isAllDataReceived();
     
    103109    ASSERT(!m_frameBufferCache.isEmpty());
    104110    ImageFrame& buffer = m_frameBufferCache[0];
     111
    105112    if (buffer.status() == ImageFrame::FrameEmpty) {
    106         ASSERT(width == size().width());
    107         ASSERT(height == size().height());
    108113        if (!buffer.setSize(width, height))
    109114            return setFailed();
     
    114119        m_rgbOutput.resize(height * stride);
    115120    }
     121
    116122    int newLastVisibleRow = 0; // Last completed row.
    117123    if (allDataReceived) {
     
    133139        ASSERT(newLastVisibleRow <= height);
    134140    }
     141
    135142    // FIXME: remove this data copy.
    136143    for (int y = m_lastVisibleRow; y < newLastVisibleRow; ++y) {
     
    139146            buffer.setRGBA(x, y, src[bytesPerPixel * x + 0], src[bytesPerPixel * x + 1], src[bytesPerPixel * x + 2], 0xff);
    140147    }
     148
    141149    m_lastVisibleRow = newLastVisibleRow;
    142150    if (m_lastVisibleRow == height)
Note: See TracChangeset for help on using the changeset viewer.