File indexing completed on 2025-01-05 03:56:30

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2006-09-15
0007  * Description : Exiv2 library interface.
0008  *               Tools for combining rotation operations.
0009  *
0010  * SPDX-FileCopyrightText: 2006-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0011  * SPDX-FileCopyrightText: 2006-2013 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 META_ENGINE_ROTATION_H
0018 #define META_ENGINE_ROTATION_H
0019 
0020 // Qt includes
0021 
0022 #include <QTransform>
0023 
0024 // Local includes
0025 
0026 #include "digikam_export.h"
0027 #include "metaengine.h"
0028 
0029 namespace Digikam
0030 {
0031 
0032 class DIGIKAM_EXPORT MetaEngineRotation
0033 {
0034 
0035 public:
0036 
0037     /**
0038      * This describes single transform primitives.
0039      * Note some of the defined Exif rotation flags combine
0040      * two of these actions.
0041      * The enum values correspond to those defined
0042      * as JXFORM_CODE in the often used the JPEG tool transupp.h.
0043      */
0044     enum TransformationAction
0045     {
0046         NoTransformation = 0, ///< no transformation
0047         FlipHorizontal   = 1, ///< horizontal flip
0048         FlipVertical     = 2, ///< vertical flip
0049         Rotate90         = 5, ///< 90-degree clockwise rotation
0050         Rotate180        = 6, ///< 180-degree rotation
0051         Rotate270        = 7  ///< 270-degree clockwise (or 90 ccw)
0052     };
0053 
0054 public:
0055 
0056     /**
0057      * Constructs the identity matrix (the matrix describing no transformation)
0058      */
0059     MetaEngineRotation();
0060 
0061     /**
0062      * Returns the matrix corresponding to the given TransformationAction
0063      */
0064     explicit MetaEngineRotation(TransformationAction action);
0065 
0066     /**
0067      * Returns the matrix corresponding to the given TransformationAction
0068      */
0069     explicit MetaEngineRotation(MetaEngine::ImageOrientation exifOrientation);
0070 
0071     bool operator==(const MetaEngineRotation& ma)   const;
0072     bool operator!=(const MetaEngineRotation& ma)   const;
0073 
0074     /**
0075      * Returns true of this matrix describes no transformation (is the identity matrix)
0076      */
0077     bool isNoTransform()                            const;
0078 
0079     MetaEngineRotation& operator*=(const MetaEngineRotation& ma);
0080 
0081     /**
0082      * Applies the given transform to this matrix
0083      */
0084     MetaEngineRotation& operator*=(TransformationAction action);
0085 
0086     /**
0087      * Applies the given transform actions to this matrix
0088      */
0089     MetaEngineRotation& operator*=(QList<TransformationAction> actions);
0090 
0091     /**
0092      * Applies the given Exif orientation flag to this matrix
0093      */
0094     MetaEngineRotation& operator*=(MetaEngine::ImageOrientation exifOrientation);
0095 
0096     MetaEngineRotation(int m11, int m12, int m21, int m22);
0097 
0098     /**
0099      * Returns the actions described by this matrix. The order matters.
0100      * Not all possible matrices are supported, but all those that can be combined
0101      * by Exif rotation flags and the transform actions above.
0102      * If isNoTransform() or the matrix is not supported returns an empty list.
0103      */
0104     QList<TransformationAction> transformations()   const;
0105 
0106     /**
0107      * Returns the Exif orientation flag describing this matrix.
0108      * Returns ORIENTATION_UNSPECIFIED if no flag matches this matrix.
0109      */
0110     MetaEngine::ImageOrientation exifOrientation()  const;
0111 
0112     /**
0113      * Returns a QTransform representing this matrix
0114      */
0115     QTransform toTransform()                              const;
0116 
0117     /**
0118      * Returns a QTransform for the given Exif orientation
0119      */
0120     static QTransform toTransform(MetaEngine::ImageOrientation orientation);
0121 
0122 protected:
0123 
0124     void set(int m11, int m12, int m21, int m22);
0125 
0126 protected:
0127 
0128     int m[2][2];
0129 };
0130 
0131 } // namespace Digikam
0132 
0133 #endif // META_ENGINE_ROTATION_H