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.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@39233 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index f180ecb..5c9e014 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,22 @@
+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.
+
+ * platform/graphics/qt/ImageDecoderQt.cpp:
+ (WebCore::ImageDecoderQt::create):
+ (WebCore::ImageDecoderQt::ImageDecoderQt):
+ (WebCore::ImageDecoderQt::imageFormat):
+ * platform/graphics/qt/ImageDecoderQt.h:
+ * platform/graphics/qt/ImageSourceQt.cpp:
+ (WebCore::ImageSource::setData):
+ (WebCore::ImageSource::filenameExtension):
+
2008-12-11 Stephanie Lewis <slewis@apple.com>
Reviewed by Geoff Garen
diff --git a/WebCore/platform/graphics/qt/ImageDecoderQt.cpp b/WebCore/platform/graphics/qt/ImageDecoderQt.cpp
index e3b00a1..8fa471e 100644
--- a/WebCore/platform/graphics/qt/ImageDecoderQt.cpp
+++ b/WebCore/platform/graphics/qt/ImageDecoderQt.cpp
@@ -178,9 +178,26 @@
return IncrementalReadComplete;
}
+ImageDecoderQt* ImageDecoderQt::create(const SharedBuffer& data)
+{
+ // We need at least 4 bytes to figure out what kind of image we're dealing with.
+ if (data.size() < 4)
+ return 0;
-// ImageDecoderQt
-ImageDecoderQt::ImageDecoderQt( )
+ QByteArray bytes = QByteArray::fromRawData(data.data(), data.size());
+ QBuffer buffer(&bytes);
+ if (!buffer.open(QBuffer::ReadOnly))
+ return 0;
+
+ QString imageFormat = QImageReader::imageFormat(&buffer).toLower();
+ if (imageFormat.isEmpty())
+ return 0; // Image format not supported
+
+ return new ImageDecoderQt(imageFormat);
+}
+
+ImageDecoderQt::ImageDecoderQt(const QString &imageFormat)
+ : m_imageFormat(imageFormat)
{
}
@@ -254,7 +271,6 @@
return m_imageList.size();
}
-
int ImageDecoderQt::repetitionCount() const
{
if (debugImageDecoderQt)
@@ -262,7 +278,6 @@
return m_loopCount;
}
-
bool ImageDecoderQt::supportsAlpha() const
{
return hasFirstImageHeader() && m_imageList[0].m_image.hasAlphaChannel();
@@ -275,6 +290,13 @@
return m_imageList[index].m_duration;
}
+QString ImageDecoderQt::imageFormat() const
+{
+ if (debugImageDecoderQt)
+ qDebug() << " ImageDecoderQt::imageFormat() returns" << m_imageFormat;
+ return m_imageFormat;
+};
+
RGBA32Buffer* ImageDecoderQt::frameBufferAtIndex(size_t index)
{
Q_ASSERT("use imageAtIndex instead");
diff --git a/WebCore/platform/graphics/qt/ImageDecoderQt.h b/WebCore/platform/graphics/qt/ImageDecoderQt.h
index 3573dd0..3ea76e3 100644
--- a/WebCore/platform/graphics/qt/ImageDecoderQt.h
+++ b/WebCore/platform/graphics/qt/ImageDecoderQt.h
@@ -38,34 +38,30 @@
class ImageDecoderQt : public ImageDecoder
{
- ImageDecoderQt(const ImageDecoderQt&);
- ImageDecoderQt &operator=(const ImageDecoderQt&);
public:
- ImageDecoderQt();
+ static ImageDecoderQt* create(const SharedBuffer& data);
~ImageDecoderQt();
typedef Vector<char> IncomingData;
virtual void setData(const IncomingData& data, bool allDataReceived);
-
virtual bool isSizeAvailable() const;
-
virtual int frameCount() const;
-
-
virtual int repetitionCount() const;
-
-
virtual RGBA32Buffer* frameBufferAtIndex(size_t index);
QPixmap* imageAtIndex(size_t index) const;
-
virtual bool supportsAlpha() const;
-
int duration(size_t index) const;
+ QString imageFormat() const;
void clearFrame(size_t index);
+
private:
+ ImageDecoderQt(const QString &imageFormat);
+ ImageDecoderQt(const ImageDecoderQt&);
+ ImageDecoderQt &operator=(const ImageDecoderQt&);
+
class ReadContext;
void reset();
bool hasFirstImageHeader() const;
@@ -89,6 +85,7 @@
ImageList m_imageList;
mutable QHash<int, QPixmap> m_pixmapCache;
int m_loopCount;
+ QString m_imageFormat;
};
diff --git a/WebCore/platform/graphics/qt/ImageSourceQt.cpp b/WebCore/platform/graphics/qt/ImageSourceQt.cpp
index 74e53c3..75d8aee 100644
--- a/WebCore/platform/graphics/qt/ImageSourceQt.cpp
+++ b/WebCore/platform/graphics/qt/ImageSourceQt.cpp
@@ -37,25 +37,6 @@
#include <QImageReader>
namespace WebCore {
-static bool canHandleImage(const SharedBuffer& _data)
-{
- // We need at least 4 bytes to figure out what kind of image we're dealing with.
- if (_data.size() < 4)
- return false;
-
- QByteArray data = QByteArray::fromRawData(_data.data(), _data.size());
- QBuffer buffer(&data);
- if (!buffer.open(QBuffer::ReadOnly))
- return false;
-
- return !QImageReader::imageFormat(&buffer).isEmpty();
-}
-
-ImageDecoderQt* createDecoder(const SharedBuffer& data) {
- if (!canHandleImage(data))
- return 0;
- return new ImageDecoderQt();
-}
ImageSource::ImageSource()
: m_decoder(0)
@@ -79,7 +60,7 @@
// If insufficient bytes are available to determine the image type, no decoder plugin will be
// made.
if (!m_decoder)
- m_decoder = createDecoder(*data);
+ m_decoder = ImageDecoderQt::create(*data);
if (!m_decoder)
return;
@@ -89,8 +70,10 @@
String ImageSource::filenameExtension() const
{
- notImplemented();
- return String();
+ if (!m_decoder)
+ return String();
+
+ return m_decoder->imageFormat();
}
bool ImageSource::isSizeAvailable()