summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Komissarov <ABBAPOH@gmail.com>2014-04-26 14:27:04 +0400
committerIvan Komissarov <ABBAPOH@gmail.com>2014-08-05 17:23:12 +0200
commitc0ba249a48fd85ee8e047ff47448a4ed32d6cd91 (patch)
tree327e2c08c5c406de78bd5e77010e65425c99b2e7
parent5097e310305beaa27d6b87699a04c43e598b6688 (diff)
Add SubType setters/getters and SupportedSubTypes option.
SubType can be used to determine an internal format of an image such as pixel format and/or compression algorithms. Change-Id: Icf296d54bb509e4e2bdb70544df678fc53f57c79 Reviewed-by: Gunnar Sletta <gunnar.sletta@jollamobile.com>
-rw-r--r--src/gui/doc/snippets/code/src_gui_image_qimagewriter.cpp7
-rw-r--r--src/gui/image/qimageiohandler.cpp4
-rw-r--r--src/gui/image/qimageiohandler.h3
-rw-r--r--src/gui/image/qimagereader.cpp30
-rw-r--r--src/gui/image/qimagereader.h3
-rw-r--r--src/gui/image/qimagewriter.cpp44
-rw-r--r--src/gui/image/qimagewriter.h4
7 files changed, 94 insertions, 1 deletions
diff --git a/src/gui/doc/snippets/code/src_gui_image_qimagewriter.cpp b/src/gui/doc/snippets/code/src_gui_image_qimagewriter.cpp
index f6fef00ab0..11b0a32ac4 100644
--- a/src/gui/doc/snippets/code/src_gui_image_qimagewriter.cpp
+++ b/src/gui/doc/snippets/code/src_gui_image_qimagewriter.cpp
@@ -57,3 +57,10 @@ QImageWriter writer(fileName);
if (writer.supportsOption(QImageIOHandler::Description))
writer.setText("Author", "John Smith");
//! [2]
+
+//! [3]
+QImageWriter writer("some/image.dds");
+if (writer.supportsOption(QImageIOHandler::SubType))
+ writer.setSubType("A8R8G8B8");
+writer.write(image);
+//! [3]
diff --git a/src/gui/image/qimageiohandler.cpp b/src/gui/image/qimageiohandler.cpp
index d67b22c31e..fc0a54f2d2 100644
--- a/src/gui/image/qimageiohandler.cpp
+++ b/src/gui/image/qimageiohandler.cpp
@@ -157,6 +157,10 @@
\value ImageFormat The image's data format returned by the handler.
This can be any of the formats listed in QImage::Format.
+
+ \value SupportedSubTypes Image formats that support different saving
+ variants should return a list of supported variant names
+ (QList<QByteArray>) in this option.
*/
/*!
diff --git a/src/gui/image/qimageiohandler.h b/src/gui/image/qimageiohandler.h
index 2ba99beab3..a3f74b326d 100644
--- a/src/gui/image/qimageiohandler.h
+++ b/src/gui/image/qimageiohandler.h
@@ -90,7 +90,8 @@ public:
Endianness,
Animation,
BackgroundColor,
- ImageFormat
+ ImageFormat,
+ SupportedSubTypes
};
virtual QVariant option(ImageOption option) const;
virtual void setOption(ImageOption option, const QVariant &value);
diff --git a/src/gui/image/qimagereader.cpp b/src/gui/image/qimagereader.cpp
index d3edf40acc..a281349aa9 100644
--- a/src/gui/image/qimagereader.cpp
+++ b/src/gui/image/qimagereader.cpp
@@ -1100,6 +1100,36 @@ bool QImageReader::supportsAnimation() const
}
/*!
+ \since 5.4
+
+ Returns the subtype of the image.
+*/
+QByteArray QImageReader::subType() const
+{
+ if (!d->initHandler())
+ return QByteArray();
+
+ if (d->handler->supportsOption(QImageIOHandler::SubType))
+ return d->handler->option(QImageIOHandler::SubType).toByteArray();
+ return QByteArray();
+}
+
+/*!
+ \since 5.4
+
+ Returns the list of subtypes supported by an image.
+*/
+QList<QByteArray> QImageReader::supportedSubTypes() const
+{
+ if (!d->initHandler())
+ return QList<QByteArray>();
+
+ if (!d->handler->supportsOption(QImageIOHandler::SupportedSubTypes))
+ return d->handler->option(QImageIOHandler::SupportedSubTypes).value< QList<QByteArray> >();
+ return QList<QByteArray>();
+}
+
+/*!
Returns \c true if an image can be read for the device (i.e., the
image format is supported, and the device seems to contain valid
data); otherwise returns \c false.
diff --git a/src/gui/image/qimagereader.h b/src/gui/image/qimagereader.h
index 8409545079..fd23bc8e6c 100644
--- a/src/gui/image/qimagereader.h
+++ b/src/gui/image/qimagereader.h
@@ -113,6 +113,9 @@ public:
bool supportsAnimation() const;
+ QByteArray subType() const;
+ QList<QByteArray> supportedSubTypes() const;
+
bool canRead() const;
QImage read();
bool read(QImage *image);
diff --git a/src/gui/image/qimagewriter.cpp b/src/gui/image/qimagewriter.cpp
index c003e56573..b31e312a76 100644
--- a/src/gui/image/qimagewriter.cpp
+++ b/src/gui/image/qimagewriter.cpp
@@ -259,6 +259,7 @@ public:
float gamma;
QString description;
QString text;
+ QByteArray subType;
// error
QImageWriter::ImageWriterError imageWriterError;
@@ -518,6 +519,47 @@ float QImageWriter::gamma() const
}
/*!
+ \since 5.4
+
+ This is an image format specific function that sets the
+ subtype of the image to \a type. Subtype can be used by
+ a handler to determine which format it should use while
+ saving the image.
+
+ For example, saving an image in DDS format with A8R8G8R8 subtype:
+
+ \snippet code/src_gui_image_qimagewriter.cpp 3
+*/
+void QImageWriter::setSubType(const QByteArray &type)
+{
+ d->subType = type;
+}
+
+/*!
+ \since 5.4
+
+ Returns the subtype of the image.
+
+ \sa setSubType()
+*/
+QByteArray QImageWriter::subType() const
+{
+ return d->subType;
+}
+
+/*!
+ \since 5.4
+
+ Returns the list of subtypes supported by an image.
+*/
+QList<QByteArray> QImageWriter::supportedSubTypes() const
+{
+ if (!supportsOption(QImageIOHandler::SupportedSubTypes))
+ return QList<QByteArray>();
+ return d->handler->option(QImageIOHandler::SupportedSubTypes).value< QList<QByteArray> >();
+}
+
+/*!
\obsolete
Use setText() instead.
@@ -618,6 +660,8 @@ bool QImageWriter::write(const QImage &image)
d->handler->setOption(QImageIOHandler::Gamma, d->gamma);
if (!d->description.isEmpty() && d->handler->supportsOption(QImageIOHandler::Description))
d->handler->setOption(QImageIOHandler::Description, d->description);
+ if (!d->subType.isEmpty() && d->handler->supportsOption(QImageIOHandler::SubType))
+ d->handler->setOption(QImageIOHandler::SubType, d->subType);
if (!d->handler->write(image))
return false;
diff --git a/src/gui/image/qimagewriter.h b/src/gui/image/qimagewriter.h
index 024ad3aa5a..ee920e6dee 100644
--- a/src/gui/image/qimagewriter.h
+++ b/src/gui/image/qimagewriter.h
@@ -87,6 +87,10 @@ public:
void setGamma(float gamma);
float gamma() const;
+ void setSubType(const QByteArray &type);
+ QByteArray subType() const;
+ QList<QByteArray> supportedSubTypes() const;
+
// Obsolete as of 4.1
void setDescription(const QString &description);
QString description() const;