KExiv2

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

KDE's Doxygen guidelines are available online.