Changeset 39233 in webkit


Ignore:
Timestamp:
Dec 12, 2008, 2:54:42 AM (16 years ago)
Author:
vestbo@webkit.org
Message:

2008-12-12 Tor Arne Vestbø <tavestbo@trolltech.com>

Reviewed by Simon Hausmann.

Implement ImageSource::filenameExtension() for the Qt port

We're using QImageReader::imageFormat().toLower() to check
that the image format is supported, and if it is we store
the resulting extension when creating the ImageDecoderQt.

Location:
trunk/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r39228 r39233  
     12008-12-12  Tor Arne Vestbø  <tavestbo@trolltech.com>
     2
     3        Reviewed by Simon Hausmann.
     4
     5        Implement ImageSource::filenameExtension() for the Qt port
     6       
     7        We're using QImageReader::imageFormat().toLower() to check
     8        that the image format is supported, and if it is we store
     9        the resulting extension when creating the ImageDecoderQt.
     10
     11        * platform/graphics/qt/ImageDecoderQt.cpp:
     12        (WebCore::ImageDecoderQt::create):
     13        (WebCore::ImageDecoderQt::ImageDecoderQt):
     14        (WebCore::ImageDecoderQt::imageFormat):
     15        * platform/graphics/qt/ImageDecoderQt.h:
     16        * platform/graphics/qt/ImageSourceQt.cpp:
     17        (WebCore::ImageSource::setData):
     18        (WebCore::ImageSource::filenameExtension):
     19
    1202008-12-11  Stephanie Lewis  <slewis@apple.com>
    221
  • trunk/WebCore/platform/graphics/qt/ImageDecoderQt.cpp

    r37061 r39233  
    179179}
    180180
    181 
    182 // ImageDecoderQt
    183 ImageDecoderQt::ImageDecoderQt( )
     181ImageDecoderQt* ImageDecoderQt::create(const SharedBuffer& data)
     182{
     183    // We need at least 4 bytes to figure out what kind of image we're dealing with.
     184    if (data.size() < 4)
     185        return 0;
     186
     187    QByteArray bytes = QByteArray::fromRawData(data.data(), data.size());
     188    QBuffer buffer(&bytes);
     189    if (!buffer.open(QBuffer::ReadOnly))
     190        return 0;
     191
     192    QString imageFormat = QImageReader::imageFormat(&buffer).toLower();
     193    if (imageFormat.isEmpty())
     194        return 0; // Image format not supported
     195
     196    return new ImageDecoderQt(imageFormat);
     197}
     198
     199ImageDecoderQt::ImageDecoderQt(const QString &imageFormat)
     200    : m_imageFormat(imageFormat)
    184201{
    185202}
     
    255272}
    256273
    257 
    258274int ImageDecoderQt::repetitionCount() const
    259275{
     
    262278    return m_loopCount;
    263279}
    264 
    265280
    266281bool ImageDecoderQt::supportsAlpha() const
     
    275290    return  m_imageList[index].m_duration;
    276291}
     292
     293QString ImageDecoderQt::imageFormat() const
     294{
     295    if (debugImageDecoderQt)
     296           qDebug() << " ImageDecoderQt::imageFormat() returns" << m_imageFormat;
     297    return m_imageFormat;
     298};
    277299
    278300RGBA32Buffer* ImageDecoderQt::frameBufferAtIndex(size_t index)
  • trunk/WebCore/platform/graphics/qt/ImageDecoderQt.h

    r37061 r39233  
    3939class ImageDecoderQt : public ImageDecoder
    4040{
    41     ImageDecoderQt(const ImageDecoderQt&);
    42     ImageDecoderQt &operator=(const ImageDecoderQt&);
    4341public:
    44     ImageDecoderQt();
     42    static ImageDecoderQt* create(const SharedBuffer& data);
    4543    ~ImageDecoderQt();
    4644
     
    4846
    4947    virtual void setData(const IncomingData& data, bool allDataReceived);
    50 
    5148    virtual bool isSizeAvailable() const;
    52 
    5349    virtual int frameCount() const;
    54 
    55 
    5650    virtual int repetitionCount() const;
    57 
    58 
    5951    virtual RGBA32Buffer* frameBufferAtIndex(size_t index);
    6052
    6153    QPixmap* imageAtIndex(size_t index) const;
    62 
    6354    virtual bool supportsAlpha() const;
    64 
    6555    int duration(size_t index) const;
     56    QString imageFormat() const;
    6657
    6758    void clearFrame(size_t index);
     59
    6860private:
     61    ImageDecoderQt(const QString &imageFormat);
     62    ImageDecoderQt(const ImageDecoderQt&);
     63    ImageDecoderQt &operator=(const ImageDecoderQt&);
     64
    6965    class ReadContext;
    7066    void reset();
     
    9086    mutable QHash<int, QPixmap> m_pixmapCache;
    9187    int m_loopCount;
     88    QString m_imageFormat;
    9289};
    9390
  • trunk/WebCore/platform/graphics/qt/ImageSourceQt.cpp

    r39209 r39233  
    3838
    3939namespace WebCore {
    40 static bool canHandleImage(const SharedBuffer& _data)
    41 {
    42     // We need at least 4 bytes to figure out what kind of image we're dealing with.
    43     if (_data.size() < 4)
    44         return false;
    45 
    46     QByteArray data = QByteArray::fromRawData(_data.data(), _data.size());
    47     QBuffer buffer(&data);
    48     if (!buffer.open(QBuffer::ReadOnly))
    49         return false;
    50 
    51     return !QImageReader::imageFormat(&buffer).isEmpty();
    52 }
    53 
    54 ImageDecoderQt* createDecoder(const SharedBuffer& data) {
    55     if (!canHandleImage(data))
    56         return 0;
    57     return new ImageDecoderQt();
    58 }
    5940
    6041ImageSource::ImageSource()
     
    8061    // made.
    8162    if (!m_decoder)
    82         m_decoder = createDecoder(*data);
     63        m_decoder = ImageDecoderQt::create(*data);
    8364
    8465    if (!m_decoder)
     
    9071String ImageSource::filenameExtension() const
    9172{
    92     notImplemented();
    93     return String();
     73    if (!m_decoder)
     74        return String();
     75
     76    return m_decoder->imageFormat();
    9477}
    9578
Note: See TracChangeset for help on using the changeset viewer.