src/plugins/imageformats/ico/qicohandler.cpp
changeset 18 2f34d5167611
parent 3 41300fa6a67c
child 30 5dc02b23752f
--- a/src/plugins/imageformats/ico/qicohandler.cpp	Tue Feb 02 00:43:10 2010 +0200
+++ b/src/plugins/imageformats/ico/qicohandler.cpp	Fri Apr 16 15:50:13 2010 +0300
@@ -1,6 +1,6 @@
 /****************************************************************************
 **
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 ** All rights reserved.
 ** Contact: Nokia Corporation (qt-info@nokia.com)
 **
@@ -53,6 +53,7 @@
 #include <QtGui/QImage>
 #include <QtCore/QFile>
 #include <QtCore/QBuffer>
+#include <qvariant.h>
 // These next two structs represent how the icon information is stored
 // in an ICO file.
 typedef struct
@@ -556,7 +557,11 @@
                 else                    // # colors used
                     icoAttrib.ncolors = header.biClrUsed ? header.biClrUsed : 1 << icoAttrib.nbits;
                 icoAttrib.w = iconEntry.bWidth;
+                if (icoAttrib.w == 0)
+                    icoAttrib.w = header.biWidth;
                 icoAttrib.h = iconEntry.bHeight;
+                if (icoAttrib.h == 0)
+                    icoAttrib.h = header.biHeight/2;
 
                 QImage::Format format = QImage::Format_ARGB32;
                 if (icoAttrib.nbits == 24)
@@ -768,6 +773,29 @@
     delete m_pICOReader;
 }
 
+QVariant QtIcoHandler::option(ImageOption option) const
+{
+    if (option == Size) {
+        QIODevice *device = QImageIOHandler::device();
+        qint64 oldPos = device->pos();
+        ICONDIRENTRY iconEntry;
+        if (device->seek(oldPos + ICONDIR_SIZE + (m_currentIconIndex * ICONDIRENTRY_SIZE))) {
+            if (readIconDirEntry(device, &iconEntry)) {
+                device->seek(oldPos);
+                return QSize(iconEntry.bWidth, iconEntry.bHeight);
+            }
+        }
+        if (!device->isSequential())
+            device->seek(oldPos);
+    }
+    return QVariant();
+}
+
+bool QtIcoHandler::supportsOption(ImageOption option) const
+{
+    return option == Size;
+}
+
 /*!
  * Verifies if some values (magic bytes) are set as expected in the header of the file.
  * If the magic bytes were found, it is assumed that the QtIcoHandler can read the file.