• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegraphics API Reference
  • KDE Home
  • Contact Us
 

libs/libkexiv2/libkexiv2

  • sources
  • kde-4.14
  • kdegraphics
  • libs
  • libkexiv2
  • libkexiv2
rotationmatrix.cpp
Go to the documentation of this file.
1 
28 #include "rotationmatrix.h"
29 
30 // KDE includes
31 
32 #include <kdebug.h>
33 
34 // local includes
35 
36 #include "version.h"
37 
38 namespace KExiv2Iface
39 {
40 
78 namespace Matrix
79 {
80 
81 static const RotationMatrix identity ( 1, 0, 0, 1);
82 static const RotationMatrix rotate90 ( 0, 1, -1, 0);
83 static const RotationMatrix rotate180 (-1, 0, 0, -1);
84 static const RotationMatrix rotate270 ( 0, -1, 1, 0);
85 static const RotationMatrix flipHorizontal (-1, 0, 0, 1);
86 static const RotationMatrix flipVertical ( 1, 0, 0, -1);
87 static const RotationMatrix rotate90flipHorizontal ( 0, 1, 1, 0);
88 static const RotationMatrix rotate90flipVertical ( 0, -1, -1, 0);
89 
90 RotationMatrix matrix(RotationMatrix::TransformationAction action)
91 {
92  switch (action)
93  {
94  case RotationMatrix::NoTransformation:
95  return identity;
96  case RotationMatrix::FlipHorizontal:
97  return flipHorizontal;
98  case RotationMatrix::FlipVertical:
99  return flipVertical;
100  case RotationMatrix::Rotate90:
101  return rotate90;
102  case RotationMatrix::Rotate180:
103  return rotate180;
104  case RotationMatrix::Rotate270:
105  return rotate270;
106  }
107  return identity;
108 }
109 
110 RotationMatrix matrix(KExiv2::ImageOrientation exifOrientation)
111 {
112  switch (exifOrientation)
113  {
114  case KExiv2::ORIENTATION_NORMAL:
115  return identity;
116  case KExiv2::ORIENTATION_HFLIP:
117  return flipHorizontal;
118  case KExiv2::ORIENTATION_ROT_180:
119  return rotate180;
120  case KExiv2::ORIENTATION_VFLIP:
121  return flipVertical;
122  case KExiv2::ORIENTATION_ROT_90_HFLIP:
123  return rotate90flipHorizontal;
124  case KExiv2::ORIENTATION_ROT_90:
125  return rotate90;
126  case KExiv2::ORIENTATION_ROT_90_VFLIP:
127  return rotate90flipVertical;
128  case KExiv2::ORIENTATION_ROT_270:
129  return rotate270;
130  case KExiv2::ORIENTATION_UNSPECIFIED:
131  return identity;
132  }
133  return identity;
134 }
135 
136 
137 } // namespace Matrix
138 
139 RotationMatrix::RotationMatrix()
140 {
141  set( 1, 0, 0, 1 );
142 }
143 
144 RotationMatrix::RotationMatrix(TransformationAction action)
145 {
146  *this = Matrix::matrix(action);
147 }
148 
149 RotationMatrix::RotationMatrix(KExiv2::ImageOrientation exifOrientation)
150 {
151  *this = Matrix::matrix(exifOrientation);
152 }
153 
154 RotationMatrix::RotationMatrix(int m11, int m12, int m21, int m22)
155 {
156  set(m11, m12, m21, m22);
157 }
158 
159 void RotationMatrix::set(int m11, int m12, int m21, int m22)
160 {
161  m[0][0]=m11;
162  m[0][1]=m12;
163  m[1][0]=m21;
164  m[1][1]=m22;
165 }
166 
167 bool RotationMatrix::isNoTransform() const
168 {
169  return *this == Matrix::identity;
170 }
171 
172 RotationMatrix& RotationMatrix::operator*=(const RotationMatrix& ma)
173 {
174  set( ma.m[0][0]*m[0][0] + ma.m[0][1]*m[1][0], ma.m[0][0]*m[0][1] + ma.m[0][1]*m[1][1],
175  ma.m[1][0]*m[0][0] + ma.m[1][1]*m[1][0], ma.m[1][0]*m[0][1] + ma.m[1][1]*m[1][1] );
176  return *this;
177 }
178 
179 bool RotationMatrix::operator==(const RotationMatrix& ma) const
180 {
181  return m[0][0]==ma.m[0][0] &&
182  m[0][1]==ma.m[0][1] &&
183  m[1][0]==ma.m[1][0] &&
184  m[1][1]==ma.m[1][1];
185 }
186 
187 bool RotationMatrix::operator!=(const RotationMatrix& ma) const
188 {
189  return !(*this==ma);
190 }
191 
192 RotationMatrix& RotationMatrix::operator*=(TransformationAction action)
193 {
194  return (*this *= Matrix::matrix(action));
195 }
196 
197 RotationMatrix& RotationMatrix::operator*=(QList<TransformationAction> actions)
198 {
199  foreach(const TransformationAction& action, actions)
200  {
201  *this *= Matrix::matrix(action);
202  }
203 
204  return *this;
205 }
206 
207 RotationMatrix& RotationMatrix::operator*=(KExiv2::ImageOrientation exifOrientation)
208 {
209  return (*this *= Matrix::matrix(exifOrientation));
210 }
211 
215 QList<RotationMatrix::TransformationAction> RotationMatrix::transformations() const
216 {
217  QList<TransformationAction> transforms;
218 
219  if (*this == Matrix::rotate90)
220  {
221  transforms << Rotate90;
222  }
223  else if (*this == Matrix::rotate180)
224  {
225  transforms << Rotate180;
226  }
227  else if (*this == Matrix::rotate270)
228  {
229  transforms << Rotate270;
230  }
231  else if (*this == Matrix::flipHorizontal)
232  {
233  transforms << FlipHorizontal;
234  }
235  else if (*this == Matrix::flipVertical)
236  {
237  transforms << FlipVertical;
238  }
239  else if (*this == Matrix::rotate90flipHorizontal)
240  {
241  //first rotate, then flip!
242  transforms << Rotate90;
243  transforms << FlipHorizontal;
244  }
245  else if (*this == Matrix::rotate90flipVertical)
246  {
247  //first rotate, then flip!
248  transforms << Rotate90;
249  transforms << FlipVertical;
250  }
251  return transforms;
252 }
253 
254 KExiv2::ImageOrientation RotationMatrix::exifOrientation() const
255 {
256  if (*this == Matrix::identity)
257  {
258  return KExiv2::ORIENTATION_NORMAL;
259  }
260  if (*this == Matrix::rotate90)
261  {
262  return KExiv2::ORIENTATION_ROT_90;
263  }
264  else if (*this == Matrix::rotate180)
265  {
266  return KExiv2::ORIENTATION_ROT_180;
267  }
268  else if (*this == Matrix::rotate270)
269  {
270  return KExiv2::ORIENTATION_ROT_270;
271  }
272  else if (*this == Matrix::flipHorizontal)
273  {
274  return KExiv2::ORIENTATION_HFLIP;
275  }
276  else if (*this == Matrix::flipVertical)
277  {
278  return KExiv2::ORIENTATION_VFLIP;
279  }
280  else if (*this == Matrix::rotate90flipHorizontal)
281  {
282  return KExiv2::ORIENTATION_ROT_90_HFLIP;
283  }
284  else if (*this == Matrix::rotate90flipVertical)
285  {
286  return KExiv2::ORIENTATION_ROT_90_VFLIP;
287  }
288  return KExiv2::ORIENTATION_UNSPECIFIED;
289 }
290 
291 QMatrix RotationMatrix::toMatrix() const
292 {
293  return toMatrix(exifOrientation());
294 }
295 
296 QMatrix RotationMatrix::toMatrix(KExiv2::ImageOrientation orientation)
297 {
298  QMatrix matrix;
299 
300  switch (orientation)
301  {
302  case KExiv2::ORIENTATION_NORMAL:
303  case KExiv2::ORIENTATION_UNSPECIFIED:
304  break;
305 
306  case KExiv2::ORIENTATION_HFLIP:
307  matrix.scale(-1, 1);
308  break;
309 
310  case KExiv2::ORIENTATION_ROT_180:
311  matrix.rotate(180);
312  break;
313 
314  case KExiv2::ORIENTATION_VFLIP:
315  matrix.scale(1, -1);
316  break;
317 
318  case KExiv2::ORIENTATION_ROT_90_HFLIP:
319  matrix.scale(-1, 1);
320  matrix.rotate(90);
321  break;
322 
323  case KExiv2::ORIENTATION_ROT_90:
324  matrix.rotate(90);
325  break;
326 
327  case KExiv2::ORIENTATION_ROT_90_VFLIP:
328  matrix.scale(1, -1);
329  matrix.rotate(90);
330  break;
331 
332  case KExiv2::ORIENTATION_ROT_270:
333  matrix.rotate(270);
334  break;
335  }
336 
337  return matrix;
338 }
339 
340 } // namespace KExiv2Iface
KExiv2Iface::RotationMatrix::operator!=
bool operator!=(const RotationMatrix &ma) const
Definition: rotationmatrix.cpp:187
KExiv2Iface::RotationMatrix::operator==
bool operator==(const RotationMatrix &ma) const
Definition: rotationmatrix.cpp:179
KExiv2Iface::KExiv2::ORIENTATION_HFLIP
Definition: kexiv2.h:100
KExiv2Iface::Matrix::matrix
RotationMatrix matrix(RotationMatrix::TransformationAction action)
Definition: rotationmatrix.cpp:90
KExiv2Iface::KExiv2::ORIENTATION_ROT_180
Definition: kexiv2.h:101
KExiv2Iface::KExiv2::ImageOrientation
ImageOrientation
The image orientation values given by Exif metadata.
Definition: kexiv2.h:96
KExiv2Iface::RotationMatrix::FlipHorizontal
no transformation
Definition: rotationmatrix.h:57
KExiv2Iface::RotationMatrix::Rotate90
vertical flip
Definition: rotationmatrix.h:59
KExiv2Iface::RotationMatrix::exifOrientation
KExiv2::ImageOrientation exifOrientation() const
Returns the Exif orienation flag describing this matrix.
Definition: rotationmatrix.cpp:254
KExiv2Iface::RotationMatrix::Rotate180
90-degree clockwise rotation
Definition: rotationmatrix.h:60
KExiv2Iface::RotationMatrix::FlipVertical
horizontal flip
Definition: rotationmatrix.h:58
KExiv2Iface::KExiv2::ORIENTATION_ROT_90_HFLIP
Definition: kexiv2.h:103
KExiv2Iface::RotationMatrix::Rotate270
180-degree rotation
Definition: rotationmatrix.h:61
KExiv2Iface::KExiv2::ORIENTATION_ROT_270
Definition: kexiv2.h:106
KExiv2Iface::RotationMatrix
Definition: rotationmatrix.h:43
KExiv2Iface::RotationMatrix::TransformationAction
TransformationAction
This describes single transform primitives.
Definition: rotationmatrix.h:54
KExiv2Iface::RotationMatrix::set
void set(int m11, int m12, int m21, int m22)
Definition: rotationmatrix.cpp:159
KExiv2Iface::Matrix::matrix
RotationMatrix matrix(KExiv2::ImageOrientation exifOrientation)
Definition: rotationmatrix.cpp:110
KExiv2Iface::Matrix::rotate180
static const RotationMatrix rotate180(-1, 0, 0,-1)
KExiv2Iface::Matrix::rotate90flipVertical
static const RotationMatrix rotate90flipVertical(0,-1,-1, 0)
QList
KExiv2Iface::Matrix::flipHorizontal
static const RotationMatrix flipHorizontal(-1, 0, 0, 1)
KExiv2Iface::RotationMatrix::m
int m[2][2]
Definition: rotationmatrix.h:113
KExiv2Iface::Matrix::rotate90
static const RotationMatrix rotate90(0, 1,-1, 0)
QMatrix::rotate
QMatrix & rotate(qreal degrees)
rotationmatrix.h
===========================================================This file is a part of digiKam project htt...
KExiv2Iface::Matrix::identity
static const RotationMatrix identity(1, 0, 0, 1)
KExiv2Iface::KExiv2::ORIENTATION_UNSPECIFIED
Definition: kexiv2.h:98
KExiv2Iface::KExiv2::ORIENTATION_ROT_90
Definition: kexiv2.h:104
KExiv2Iface::RotationMatrix::NoTransformation
Definition: rotationmatrix.h:56
QMatrix
KExiv2Iface::KExiv2::ORIENTATION_NORMAL
Definition: kexiv2.h:99
KExiv2Iface::RotationMatrix::transformations
QList< TransformationAction > transformations() const
Returns the actions described by this matrix.
Definition: rotationmatrix.cpp:215
KExiv2Iface::RotationMatrix::isNoTransform
bool isNoTransform() const
Returns true of this matrix describes no transformation (is the identity matrix)
Definition: rotationmatrix.cpp:167
KExiv2Iface::RotationMatrix::operator*=
RotationMatrix & operator*=(const RotationMatrix &ma)
Definition: rotationmatrix.cpp:172
KExiv2Iface::Matrix::rotate270
static const RotationMatrix rotate270(0,-1, 1, 0)
KExiv2Iface::RotationMatrix::RotationMatrix
RotationMatrix()
Constructs the identity matrix (the matrix describing no transformation)
Definition: rotationmatrix.cpp:139
KExiv2Iface::KExiv2::ORIENTATION_ROT_90_VFLIP
Definition: kexiv2.h:105
KExiv2Iface::Matrix::rotate90flipHorizontal
static const RotationMatrix rotate90flipHorizontal(0, 1, 1, 0)
KExiv2Iface::Matrix::flipVertical
static const RotationMatrix flipVertical(1, 0, 0,-1)
KExiv2Iface::KExiv2::ORIENTATION_VFLIP
Definition: kexiv2.h:102
KExiv2Iface::RotationMatrix::toMatrix
QMatrix toMatrix() const
Returns a QMatrix representing this matrix.
Definition: rotationmatrix.cpp:291
QMatrix::scale
QMatrix & scale(qreal sx, qreal sy)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:19:40 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libs/libkexiv2/libkexiv2

Skip menu "libs/libkexiv2/libkexiv2"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdegraphics API Reference

Skip menu "kdegraphics API Reference"
  •     libkdcraw
  •     libkexiv2
  •     libkipi
  •     libksane
  • okular

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal