File indexing completed on 2024-05-12 04:19:37

0001 // vim: set tabstop=4 shiftwidth=4 expandtab:
0002 /*
0003 Gwenview: an image viewer
0004 Copyright 2007 Aurélien Gâteau <agateau@kde.org>
0005 
0006 This program is free software; you can redistribute it and/or
0007 modify it under the terms of the GNU General Public License
0008 as published by the Free Software Foundation; either version 2
0009 of the License, or (at your option) any later version.
0010 
0011 This program is distributed in the hope that it will be useful,
0012 but WITHOUT ANY WARRANTY; without even the implied warranty of
0013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014 GNU General Public License for more details.
0015 
0016 You should have received a copy of the GNU General Public License
0017 along with this program; if not, write to the Free Software
0018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0019 
0020 */
0021 // Self
0022 #include "jpegdocumentloadedimpl.h"
0023 
0024 // Qt
0025 #include <QIODevice>
0026 #include <QImage>
0027 
0028 // KF
0029 
0030 // Local
0031 #include "jpegcontent.h"
0032 
0033 namespace Gwenview
0034 {
0035 struct JpegDocumentLoadedImplPrivate {
0036     JpegContent *mJpegContent = nullptr;
0037 };
0038 
0039 JpegDocumentLoadedImpl::JpegDocumentLoadedImpl(Document *doc, JpegContent *jpegContent)
0040     : DocumentLoadedImpl(doc, QByteArray() /* rawData */)
0041     , d(new JpegDocumentLoadedImplPrivate)
0042 {
0043     Q_ASSERT(jpegContent);
0044     d->mJpegContent = jpegContent;
0045 }
0046 
0047 JpegDocumentLoadedImpl::~JpegDocumentLoadedImpl()
0048 {
0049     delete d->mJpegContent;
0050     delete d;
0051 }
0052 
0053 bool JpegDocumentLoadedImpl::saveInternal(QIODevice *device, const QByteArray &format)
0054 {
0055     if (format == "jpeg") {
0056         if (!d->mJpegContent->thumbnail().isNull()) {
0057             const QImage thumbnail = document()->image().scaled(128, 128, Qt::KeepAspectRatio);
0058             d->mJpegContent->setThumbnail(thumbnail);
0059         }
0060 
0061         bool ok = d->mJpegContent->save(device);
0062         if (!ok) {
0063             setDocumentErrorString(d->mJpegContent->errorString());
0064         }
0065         return ok;
0066     } else {
0067         return DocumentLoadedImpl::saveInternal(device, format);
0068     }
0069 }
0070 
0071 void JpegDocumentLoadedImpl::setImage(const QImage &image)
0072 {
0073     d->mJpegContent->setImage(image);
0074     DocumentLoadedImpl::setImage(image);
0075 }
0076 
0077 void JpegDocumentLoadedImpl::applyTransformation(Orientation orientation)
0078 {
0079     DocumentLoadedImpl::applyTransformation(orientation);
0080 
0081     // Apply Exif transformation first to normalize image
0082     d->mJpegContent->transform(d->mJpegContent->orientation());
0083     d->mJpegContent->resetOrientation();
0084 
0085     d->mJpegContent->transform(orientation);
0086 }
0087 
0088 QByteArray JpegDocumentLoadedImpl::rawData() const
0089 {
0090     return d->mJpegContent->rawData();
0091 }
0092 
0093 } // namespace
0094 
0095 #include "moc_jpegdocumentloadedimpl.cpp"