summaryrefslogtreecommitdiffstats
path: root/src/gui/image/qimagewriter.cpp
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2015-05-04 13:32:32 +0200
committerAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2015-05-12 09:25:11 +0000
commitba323b04cd78fb43e9e63b891e973d24b08250af (patch)
tree8ad4da1eaf991f061d3e24159a3a5b4fdaf8fbfa /src/gui/image/qimagewriter.cpp
parent12dd4ff7e7b4fae33fb74def603ce880eee0c16b (diff)
Optionally apply orientation on QImage read
Make it possible to read images with EXIF orientation automatically applied. This was originally implemented without opt-out in Qt 5.4, but reverted. Here it is implemented as opt-in for JPEG, and opt-out for TIFF to keep behavioral consistency. The EXIF support for JPEG was written by Rainer Keller. [ChangeLog][QtGui][Image plugins] An option has been added to QImageReader to enable automatic application of EXIF orientation. This behavior was default in Qt 5.4.1, but reverted in Qt 5.4.2. Task-number: QTBUG-37946 Task-number: QTBUG-43563 Task-number: QTBUG-45552 Task-number: QTBUG-45865 Change-Id: Iaafd2519b63ede66ecc1f8aa4c7118081312b8f5 Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
Diffstat (limited to 'src/gui/image/qimagewriter.cpp')
-rw-r--r--src/gui/image/qimagewriter.cpp39
1 files changed, 38 insertions, 1 deletions
diff --git a/src/gui/image/qimagewriter.cpp b/src/gui/image/qimagewriter.cpp
index b418101163..e9de1db4b2 100644
--- a/src/gui/image/qimagewriter.cpp
+++ b/src/gui/image/qimagewriter.cpp
@@ -91,6 +91,7 @@
#include <qbytearray.h>
#include <qfile.h>
#include <qfileinfo.h>
+#include <qimage.h>
#include <qimageiohandler.h>
#include <qjsonarray.h>
#include <qset.h>
@@ -254,6 +255,7 @@ public:
QByteArray subType;
bool optimizedWrite;
bool progressiveScanWrite;
+ QImageIOHandler::Transformations transformation;
// error
QImageWriter::ImageWriterError imageWriterError;
@@ -277,6 +279,7 @@ QImageWriterPrivate::QImageWriterPrivate(QImageWriter *qq)
progressiveScanWrite = false;
imageWriterError = QImageWriter::UnknownError;
errorString = QImageWriter::tr("Unknown error");
+ transformation = QImageIOHandler::TransformationNone;
q = qq;
}
@@ -616,6 +619,33 @@ bool QImageWriter::progressiveScanWrite() const
}
/*!
+ \since 5.5
+
+ Sets the image transformations metadata including orientation.
+
+ If transformation metadata is not supported by the image format,
+ the transform is applied before writing.
+
+ \sa transformation(), write()
+*/
+void QImageWriter::setTransformation(QImageIOHandler::Transformations transform)
+{
+ d->transformation = transform;
+}
+
+/*!
+ \since 5.5
+
+ Returns the transformation and orientation the image has been set to written with.
+
+ \sa setTransformation()
+*/
+QImageIOHandler::Transformations QImageWriter::transformation() const
+{
+ return d->transformation;
+}
+
+/*!
\obsolete
Use setText() instead.
@@ -694,6 +724,8 @@ bool QImageWriter::canWrite() const
return d->canWriteHelper();
}
+extern void qt_imageTransform(QImage &src, QImageIOHandler::Transformations orient);
+
/*!
Writes the image \a image to the assigned device or file
name. Returns \c true on success; otherwise returns \c false. If the
@@ -708,6 +740,7 @@ bool QImageWriter::write(const QImage &image)
if (!canWrite())
return false;
+ QImage img = image;
if (d->handler->supportsOption(QImageIOHandler::Quality))
d->handler->setOption(QImageIOHandler::Quality, d->quality);
if (d->handler->supportsOption(QImageIOHandler::CompressionRatio))
@@ -722,8 +755,12 @@ bool QImageWriter::write(const QImage &image)
d->handler->setOption(QImageIOHandler::OptimizedWrite, d->optimizedWrite);
if (d->handler->supportsOption(QImageIOHandler::ProgressiveScanWrite))
d->handler->setOption(QImageIOHandler::ProgressiveScanWrite, d->progressiveScanWrite);
+ if (d->handler->supportsOption(QImageIOHandler::ImageTransformation))
+ d->handler->setOption(QImageIOHandler::ImageTransformation, int(d->transformation));
+ else
+ qt_imageTransform(img, d->transformation);
- if (!d->handler->write(image))
+ if (!d->handler->write(img))
return false;
if (QFile *file = qobject_cast<QFile *>(d->device))
file->flush();