Skip to content

Commit

Permalink
Add SubType setters/getters and SupportedSubTypes option.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
ABBAPOH committed Aug 5, 2014
1 parent 5097e31 commit c0ba249
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/gui/doc/snippets/code/src_gui_image_qimagewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]
4 changes: 4 additions & 0 deletions src/gui/image/qimageiohandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/

/*!
Expand Down
3 changes: 2 additions & 1 deletion src/gui/image/qimageiohandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ class Q_GUI_EXPORT QImageIOHandler
Endianness,
Animation,
BackgroundColor,
ImageFormat
ImageFormat,
SupportedSubTypes
};
virtual QVariant option(ImageOption option) const;
virtual void setOption(ImageOption option, const QVariant &value);
Expand Down
30 changes: 30 additions & 0 deletions src/gui/image/qimagereader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,36 @@ bool QImageReader::supportsAnimation() const
return false;
}

/*!
\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
Expand Down
3 changes: 3 additions & 0 deletions src/gui/image/qimagereader.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ class Q_GUI_EXPORT QImageReader

bool supportsAnimation() const;

QByteArray subType() const;
QList<QByteArray> supportedSubTypes() const;

bool canRead() const;
QImage read();
bool read(QImage *image);
Expand Down
44 changes: 44 additions & 0 deletions src/gui/image/qimagewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ class QImageWriterPrivate
float gamma;
QString description;
QString text;
QByteArray subType;

// error
QImageWriter::ImageWriterError imageWriterError;
Expand Down Expand Up @@ -517,6 +518,47 @@ float QImageWriter::gamma() const
return d->gamma;
}

/*!
\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
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/gui/image/qimagewriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ class Q_GUI_EXPORT QImageWriter
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;
Expand Down

0 comments on commit c0ba249

Please sign in to comment.