File indexing completed on 2024-03-24 16:02:10

0001 /*
0002     SPDX-FileCopyrightText: 2006-2015 Gilles Caulier <caulier dot gilles at gmail dot com>
0003     SPDX-FileCopyrightText: 2004-2012 Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 
0007 */
0008 
0009 #ifndef LIBKEXIV2_ROTATIONMATRIX_H
0010 #define LIBKEXIV2_ROTATIONMATRIX_H
0011 
0012 // Local includes
0013 
0014 #include "kexiv2.h"
0015 #include "libkexiv2_export.h"
0016 
0017 // Qt includes
0018 #include <QtGlobal>
0019 
0020 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
0021 #if KEXIV2_ENABLE_DEPRECATED_SINCE(5, 1)
0022 #include <QMatrix>
0023 #endif
0024 #endif
0025 #include <QTransform>
0026 
0027 namespace KExiv2Iface
0028 {
0029 
0030 /**
0031  * @class RotationMatrix rotationmatrix.h <KExiv2/RotationMatrix>
0032  *
0033  * RotationMatrix
0034  */
0035 class LIBKEXIV2_EXPORT RotationMatrix
0036 {
0037 
0038 public:
0039 
0040     /** This describes single transform primitives.
0041      *  Note some of the defined Exif rotation flags combine
0042      *  two of these actions.
0043      *  The enum values correspond to those defined
0044      *  as JXFORM_CODE in the often used the JPEG tool transupp.h.
0045      */
0046     enum TransformationAction
0047     {
0048         NoTransformation = 0, /// no transformation
0049         FlipHorizontal   = 1, /// horizontal flip
0050         FlipVertical     = 2, /// vertical flip
0051         Rotate90         = 5, /// 90-degree clockwise rotation
0052         Rotate180        = 6, /// 180-degree rotation
0053         Rotate270        = 7  /// 270-degree clockwise (or 90 ccw)
0054     };
0055 
0056 public:
0057 
0058     /// Constructs the identity matrix (the matrix describing no transformation)
0059     RotationMatrix();
0060     /// Returns the matrix corresponding to the given TransformationAction
0061     RotationMatrix(TransformationAction action);
0062     /// Returns the matrix corresponding to the given TransformationAction
0063     RotationMatrix(KExiv2::ImageOrientation exifOrientation);
0064 
0065     bool operator==(const RotationMatrix& ma) const;
0066     bool operator!=(const RotationMatrix& ma) const;
0067 
0068     /// Returns true of this matrix describes no transformation (is the identity matrix)
0069     bool isNoTransform() const;
0070 
0071     RotationMatrix& operator*=(const RotationMatrix& ma);
0072 
0073     /// Applies the given transform to this matrix
0074     RotationMatrix& operator*=(TransformationAction action);
0075 
0076     /// Applies the given transform actions to this matrix
0077     RotationMatrix& operator*=(QList<TransformationAction> actions);
0078 
0079     /// Applies the given Exif orientation flag to this matrix
0080     RotationMatrix& operator*=(KExiv2::ImageOrientation exifOrientation);
0081 
0082     /** Returns the actions described by this matrix. The order matters.
0083      *  Not all possible matrices are supported, but all those that can be combined
0084      *  by Exif rotation flags and the transform actions above.
0085      *  If isNoTransform() or the matrix is not supported returns an empty list. */
0086     QList<TransformationAction> transformations() const;
0087 
0088     /** Returns the Exif orienation flag describing this matrix.
0089      *  Returns ORIENTATION_UNSPECIFIED if no flag matches this matrix.
0090      */
0091     KExiv2::ImageOrientation exifOrientation() const;
0092 
0093    /**
0094      * Returns a QTransform representing this matrix
0095      * @since 5.1
0096      */
0097     QTransform toTransform() const;
0098 
0099     /**
0100      * Returns a QTransform for the given Exif orientation
0101      * @since 5.1
0102      */
0103     static QTransform toTransform(KExiv2::ImageOrientation orientation);
0104 
0105 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
0106 #if KEXIV2_ENABLE_DEPRECATED_SINCE(5, 1)
0107     /// Returns a QMatrix representing this matrix
0108     /// @deprecated Since 5.1, use toTransform().
0109     KEXIV2_DEPRECATED_VERSION(5, 1, "Use toTransform()")
0110     QMatrix toMatrix() const;
0111 #endif
0112 #endif
0113 
0114 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
0115 #if KEXIV2_ENABLE_DEPRECATED_SINCE(5, 1)
0116     /// Returns a QMatrix for the given Exif orientation
0117     KEXIV2_DEPRECATED_VERSION(5, 1, "Use toTransform(KExiv2::ImageOrientation)")
0118     static QMatrix toMatrix(KExiv2::ImageOrientation orientation);
0119 #endif
0120 #endif
0121 
0122     RotationMatrix(int m11, int m12, int m21, int m22);
0123 
0124 protected:
0125 
0126     void set(int m11, int m12, int m21, int m22);
0127 
0128 protected:
0129 
0130     int m[2][2];
0131 };
0132 
0133 }  // namespace KExiv2Iface
0134 
0135 #endif  // LIBKEXIV2_ROTATIONMATRIX_H