Fix image loading and implement icon class
authorzack <zack@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 26 Jan 2007 08:25:32 +0000 (08:25 +0000)
committerzack <zack@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 26 Jan 2007 08:25:32 +0000 (08:25 +0000)
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@19137 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/platform/graphics/BitmapImage.h
WebCore/platform/graphics/Icon.h
WebCore/platform/graphics/Image.h
WebCore/platform/graphics/qt/IconQt.cpp
WebCore/platform/graphics/qt/ImageDecoderQt.cpp
WebCore/platform/graphics/qt/ImageDecoderQt.h
WebCore/platform/graphics/qt/ImageQt.cpp
WebCore/platform/graphics/qt/ImageSourceQt.cpp

index 8ead01d..9c8ec2f 100644 (file)
@@ -1,3 +1,33 @@
+2007-01-26  Zack Rusin  <zack@kde.org>
+
+        Reviewed by Lars
+
+        Fixing image loading - we decode QImages
+        but render QPixmaps now. Implement Icon
+        class
+
+        * platform/graphics/BitmapImage.h:
+        * platform/graphics/Icon.h:
+        * platform/graphics/Image.h:
+        (WebCore::Image::getPixmap):
+        * platform/graphics/qt/IconQt.cpp:
+        (WebCore::Icon::Icon):
+        (WebCore::Icon::~Icon):
+        (WebCore::Icon::newIconForFile):
+        (WebCore::Icon::paint):
+        * platform/graphics/qt/ImageDecoderQt.cpp:
+        (WebCore::ImageDecoderQt::ImageData::ImageData):
+        (WebCore::ImageDecoderQt::ReadContext::read):
+        (WebCore::ImageDecoderQt::ReadContext::readImageLines):
+        (WebCore::ImageDecoderQt::reset):
+        (WebCore::ImageDecoderQt::imageAtIndex):
+        * platform/graphics/qt/ImageDecoderQt.h:
+        * platform/graphics/qt/ImageQt.cpp:
+        (WebCore::BitmapImage::drawPattern):
+        (WebCore::BitmapImage::getPixmap):
+        * platform/graphics/qt/ImageSourceQt.cpp:
+        (WebCore::ImageSource::createFrameAtIndex):
+
 2007-01-25  Justin Garcia  <justin.garcia@apple.com>
 
         Reviewed by oliver
index 5e00b02..cfc2351 100644 (file)
@@ -110,6 +110,10 @@ public:
 #if PLATFORM(CG)
     virtual CGImageRef getCGImageRef();
 #endif
+
+#if PLATFORM(QT)
+    virtual QPixmap* getPixmap() const;
+#endif
     
 #if PLATFORM(WIN)
     virtual bool getHBITMAP(HBITMAP);
index fb91e3c..6c1d77f 100644 (file)
@@ -33,6 +33,8 @@ class NSImage;
 #endif
 #elif PLATFORM(WIN)
 typedef struct HICON__* HICON;
+#elif PLATFORM(QT)
+#include <QIcon>
 #endif
 
 namespace WebCore {
@@ -59,6 +61,8 @@ private:
     NSImage* m_nsImage;
 #elif PLATFORM(WIN)
     HICON m_hIcon;
+#elif PLATFORM(QT)
+    QIcon m_icon;
 #endif
 };
 
index 9a744a4..b705b9e 100644 (file)
@@ -47,6 +47,10 @@ struct CGContext;
 typedef struct HBITMAP__ *HBITMAP;
 #endif
 
+#if PLATFORM(QT)
+class QPixmap;
+#endif
+
 namespace WebCore {
 
 class AffineTransform;
@@ -103,6 +107,10 @@ public:
     virtual CGImageRef getCGImageRef() { return 0; }
 #endif
 
+#if PLATFORM(QT)
+    virtual QPixmap* getPixmap() const { return 0; }
+#endif
+
 #if PLATFORM(WIN)
     virtual bool getHBITMAP(HBITMAP) { return false; }
 #endif
index f848eeb..3f6ebb1 100644 (file)
 #include "config.h"
 #include "Icon.h"
 
+#include "GraphicsContext.h"
+#include "DeprecatedString.h"
+#include "PlatformString.h"
+#include "IntRect.h"
+
+#include <qpainter.h>
+#include <qpixmap.h>
+#include <qrect.h>
 #include <qglobal.h>
 
 #define notImplemented() qDebug("FIXME: UNIMPLEMENTED: %s:%d (%s)", __FILE__, __LINE__, __FUNCTION__)
@@ -29,23 +37,26 @@ namespace WebCore {
 
 Icon::Icon()
 {
-    notImplemented();
 }
 
 Icon::~Icon()
 {
-    notImplemented();
 }
     
 PassRefPtr<Icon> Icon::newIconForFile(const String& filename)
 {
-    notImplemented();
-    return PassRefPtr<Icon>(0);
+    Icon *i = new Icon;
+    i->m_icon = QIcon(filename);
+    return PassRefPtr<Icon>(i);
 }
 
-void Icon::paint(GraphicsContext*, const IntRect&)
+void Icon::paint(GraphicsContext* ctx, const IntRect& rect)
 {
-    notImplemented();
+    QPixmap px = m_icon.pixmap(rect.size());
+    QPainter *p = static_cast<QPainter*>(ctx->platformContext());
+    if (p && !px.isNull()) {
+        p->drawPixmap(rect.x(), rect.y(), px);
+    }
 }
 
 }
index e8add38..6248e1c 100644 (file)
@@ -41,10 +41,8 @@ namespace {
 }
 
 namespace WebCore {
-ImageDecoderQt::ImageData::ImageData(const QPixmap& image, QImage::Format format, 
-                                     ImageState imageState, int duration)
-    : m_image(image), m_format(format),
-      m_imageState(imageState), m_duration(duration)
+ImageDecoderQt::ImageData::ImageData(const QImage& image, ImageState imageState, int duration) :
+    m_image(image), m_imageState(imageState), m_duration(duration)
 {
 }
 
@@ -119,7 +117,7 @@ ImageDecoderQt::ReadContext::ReadResult
             // for efficient reading
             QImage newImage = m_dataFormat != QImage::Format_Invalid  ?
                           QImage(m_size,m_dataFormat) : QImage();
-            m_target.push_back(ImageData(QPixmap::fromImage(newImage), m_dataFormat));
+            m_target.push_back(ImageData(newImage));
         }
 
         // read chunks
@@ -132,7 +130,7 @@ ImageDecoderQt::ReadContext::ReadResult
         case IncrementalReadComplete:
             m_target.back().m_imageState = ImageComplete;
             //store for next
-            m_dataFormat = m_target.back().m_format;
+            m_dataFormat = m_target.back().m_image.format();
             m_size = m_target.back().m_image.size();
             const bool supportsAnimation = m_reader.supportsAnimation();
 
@@ -160,8 +158,7 @@ ImageDecoderQt::ReadContext::IncrementalReadResult
 
     const qint64 startPos = m_buffer.pos ();
     // Oops, failed. Rewind.
-    QImage image = imageData.m_image.toImage();
-    if (!m_reader.read(&image)) {
+    if (!m_reader.read(&imageData.m_image)) {
         m_buffer.seek(startPos);
         const bool gotHeader = imageData.m_image.size().width();
 
@@ -175,7 +172,6 @@ ImageDecoderQt::ReadContext::IncrementalReadResult
         }
         return IncrementalReadFailed;
     }
-    imageData.m_image = QPixmap::fromImage(image);
     imageData.m_duration = m_reader.nextImageDelay();
     return IncrementalReadComplete;
 }
@@ -199,6 +195,7 @@ void ImageDecoderQt::reset()
 {
     m_failed = false;
     m_imageList.clear();
+    m_pixmapCache.clear();
     m_sizeAvailable = false;
     m_size = IntSize(-1, -1);
 }
@@ -278,7 +275,12 @@ const QPixmap* ImageDecoderQt::imageAtIndex(size_t index) const
 
     if (index >= m_imageList.size())
         return 0;
-    return &m_imageList[index].m_image;
+
+    if (!m_pixmapCache.contains(index)) {
+        m_pixmapCache.insert(index,
+                             QPixmap::fromImage(m_imageList[index].m_image));
+    }
+    return  &m_pixmapCache[index];
 }
 
 }
index 47d832d..f188540 100644 (file)
 #define ImageDecoderQt_h
 
 #include "ImageDecoder.h"
-#include <QtCore/QList>
+#include <QtGui/QImage>
 #include <QtGui/QPixmap>
+#include <QtCore/QList>
+#include <QtCore/QHash>
 
 namespace WebCore {
 
@@ -75,17 +77,15 @@ private:
             ImageComplete };
 
     struct ImageData {
-        ImageData(const QPixmap& image, QImage::Format format, 
-                  ImageState imageState = ImagePartial,
-                  int duration=0);
-        QPixmap m_image;
+        ImageData(const QImage& image, ImageState imageState = ImagePartial, int duration=0);
+        QImage m_image;
         ImageState m_imageState;
         int m_duration;
-        QImage::Format m_format;
     };
 
     typedef QList<ImageData> ImageList;
     ImageList m_imageList;
+    mutable QHash<int, QPixmap> m_pixmapCache;
 };
 
 
index ed46b42..c431442 100644 (file)
@@ -133,7 +133,7 @@ void BitmapImage::drawPattern(GraphicsContext* ctxt, const FloatRect& tileRect,
     QPixmap* framePixmap = nativeImageForCurrentFrame();
     if (!framePixmap) // If it's too early we won't have an image yet.
         return;
-    
+
     QPixmap pixmap = *framePixmap;
     QRect tr = QRectF(tileRect).toRect();
     if (tr.x() || tr.y() || tr.width() != pixmap.width() || tr.height() != pixmap.height())
@@ -159,6 +159,11 @@ void BitmapImage::checkForSolidColor()
     m_isSolidColor = false;
 }
 
+QPixmap* BitmapImage::getPixmap() const
+{
+    return const_cast<BitmapImage*>(this)->frameAtIndex(0);
+}
+
 }
 
 
index ae97cdc..ece7e1d 100644 (file)
@@ -161,7 +161,7 @@ NativeImagePtr ImageSource::createFrameAtIndex(size_t index)
         return 0;
 
     
-    const QPixmap* source = m_decoder->imageAtIndex( index);
+    const QPixmap* source = m_decoder->imageAtIndex(index);
     if (!source)
         return 0;