File indexing completed on 2025-01-19 03:55:55
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2004-09-29 0007 * Description : helper methods for JPEG image format. 0008 * 0009 * SPDX-FileCopyrightText: 2004-2005 by Renchi Raju <renchi dot raju at gmail dot com> 0010 * SPDX-FileCopyrightText: 2006-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0011 * SPDX-FileCopyrightText: 2006-2012 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de> 0012 * 0013 * SPDX-License-Identifier: GPL-2.0-or-later 0014 * 0015 * ============================================================ */ 0016 0017 #ifndef DIGIKAM_JPEG_UTILS_H 0018 #define DIGIKAM_JPEG_UTILS_H 0019 0020 // Qt includes 0021 0022 #include <QString> 0023 #include <QImage> 0024 0025 // Local includes 0026 0027 #include "digikam_config.h" 0028 #include "digikam_export.h" 0029 #include "dmetadata.h" 0030 #include "metaengine_rotation.h" 0031 0032 namespace Digikam 0033 { 0034 0035 namespace JPEGUtils 0036 { 0037 0038 typedef MetaEngineRotation::TransformationAction TransformAction; 0039 0040 class DIGIKAM_EXPORT JpegRotator 0041 { 0042 public: 0043 0044 /** 0045 * Create a JpegRotator reading from the given file. 0046 * Per default, it will replace the file, read the current orientation from the metadata, 0047 * and use the src file name as documentName. 0048 */ 0049 explicit JpegRotator(const QString& file); 0050 0051 /** 0052 * Destructor 0053 */ 0054 ~JpegRotator(); 0055 0056 /** 0057 * Per default, the orientation is read from the metadata of the file. 0058 * You can override this value 0059 */ 0060 void setCurrentOrientation(MetaEngine::ImageOrientation orientation); 0061 0062 /** 0063 * Set the Exif document name of the destination file. 0064 * Default value is the source's file name 0065 */ 0066 void setDocumentName(const QString& documentName); 0067 0068 /** 0069 * Set the destination file. By default, the source file will be overwritten 0070 * by atomic operation if the operation had succeeded. 0071 */ 0072 void setDestinationFile(const QString& dest); 0073 0074 /** 0075 * Rotate the JPEG file's content according to the current orientation, 0076 * resetting the current orientation to normal. 0077 * The final result of loading the image does not change. 0078 */ 0079 bool autoExifTransform(); 0080 0081 /** 0082 * Rotate the given image by the given TransformAction. 0083 * The current orientation will be taken into account 0084 */ 0085 bool exifTransform(TransformAction action); 0086 0087 /** 0088 * Rotate the given image by the given Matrix. 0089 * The matrix describes the final transformation, 0090 * it is not adjusted by current rotation. 0091 */ 0092 bool exifTransform(const MetaEngineRotation& matrix); 0093 0094 protected: 0095 0096 QString m_file; 0097 QString m_destFile; 0098 QString m_documentName; 0099 QSize m_originalSize; 0100 DMetadata* m_metadata; 0101 MetaEngine::ImageOrientation m_orientation; 0102 0103 protected: 0104 0105 void updateMetadata(const QString& fileName, const MetaEngineRotation& matrix); 0106 bool performJpegTransform(TransformAction action, const QString& src, const QString& dest); 0107 0108 private: 0109 0110 // Disable 0111 JpegRotator(const JpegRotator&) = delete; 0112 JpegRotator& operator=(const JpegRotator&) = delete; 0113 }; 0114 0115 DIGIKAM_EXPORT bool loadJPEGScaled(QImage& image, const QString& path, int maximumSize); 0116 DIGIKAM_EXPORT bool jpegConvert(const QString& src, 0117 const QString& dest, 0118 const QString& documentName, 0119 const QString& format=QLatin1String("PNG")); 0120 DIGIKAM_EXPORT bool isJpegImage(const QString& file); 0121 DIGIKAM_EXPORT int getJpegQuality(const QString& file); 0122 0123 } // namespace JPEGUtils 0124 0125 } // namespace Digikam 0126 0127 #endif // DIGIKAM_JPEG_UTILS_H