From b962125bd5c6260c71f9d98ae2dbb7ea89cd87ad Mon Sep 17 00:00:00 2001
From: Roger Siddons <dizygotheca@ntlworld.com>
Date: Fri, 9 Oct 2015 23:29:22 +0100
Subject: [PATCH 14/15] Gallery: Use common orientation
Images are rotated to their correct orientation in 2 places;
- MythImage, when loading an image
- Gallery, when creating thumbnails
This patch removes the duplicated orientation code by making the MythImage functionality accessible to the Gallery.
diff --git a/mythtv/libs/libmythmetadata/imagemetadata.cpp b/mythtv/libs/libmythmetadata/imagemetadata.cpp
index 21cc055..5db9119 100644
a
|
b
|
|
1 | 1 | #include "imagemetadata.h" |
2 | 2 | |
3 | | #include <QImage> |
4 | | |
5 | 3 | #include "mythlogging.h" |
6 | 4 | #include "mythcorecontext.h" // for avcodeclock |
7 | 5 | #include "mythdirs.h" // for ffprobe |
… |
… |
int Orientation::Transform(int transform) |
41 | 39 | } |
42 | 40 | |
43 | 41 | |
44 | | QImage Orientation::ApplyExifOrientation(QImage &image, int orientation) |
45 | | { |
46 | | QTransform transform; |
47 | | |
48 | | switch (orientation) |
49 | | { |
50 | | case 1: // normal |
51 | | return image; |
52 | | case 2: // mirror horizontal |
53 | | return image.mirrored(true, false); |
54 | | case 3: // rotate 180 |
55 | | transform.rotate(180); |
56 | | return image.transformed(transform); |
57 | | case 4: // mirror vertical |
58 | | return image.mirrored(false, true); |
59 | | case 5: // mirror horizontal and rotate 270 CCW |
60 | | transform.rotate(270); |
61 | | return image.mirrored(true, false).transformed(transform); |
62 | | case 6: // rotate 90 CW |
63 | | transform.rotate(90); |
64 | | return image.transformed(transform); |
65 | | case 7: // mirror horizontal and rotate 90 CW |
66 | | transform.rotate(90); |
67 | | return image.mirrored(true, false).transformed(transform); |
68 | | case 8: // rotate 270 CW |
69 | | transform.rotate(270); |
70 | | return image.transformed(transform); |
71 | | } |
72 | | return image; |
73 | | } |
74 | | |
75 | | |
76 | 42 | /*! |
77 | 43 | * \brief Adjust current orientation code to apply a transform to an image |
78 | 44 | * \details When displayed the image will be orientated iaw its orientation |
diff --git a/mythtv/libs/libmythmetadata/imagemetadata.h b/mythtv/libs/libmythmetadata/imagemetadata.h
index 79da608..6c11c37 100644
a
|
b
|
public: |
68 | 68 | QString Description(); |
69 | 69 | |
70 | 70 | static int FromRotation(const QString °rees); |
71 | | static QImage ApplyExifOrientation(QImage &image, int orientation); |
72 | 71 | |
73 | 72 | private: |
74 | 73 | static QString AsText(int orientation); |
diff --git a/mythtv/libs/libmythmetadata/imagethumbs.cpp b/mythtv/libs/libmythmetadata/imagethumbs.cpp
index d12b364..3e659c2 100644
a
|
b
|
QString ThumbThread<DBFS>::CreateThumbnail(ImagePtrK im, int thumbPriority) |
309 | 309 | |
310 | 310 | // Orientate now to optimise load/display time - no orientation |
311 | 311 | // is required when displaying thumbnails |
312 | | image = Orientation::ApplyExifOrientation(image, orientBy); |
| 312 | image = MythImage::ApplyExifOrientation(image, orientBy); |
313 | 313 | |
314 | 314 | // Create the thumbnail |
315 | 315 | if (!image.save(im->m_thumbPath)) |
diff --git a/mythtv/libs/libmythui/mythimage.cpp b/mythtv/libs/libmythui/mythimage.cpp
index 7b951a6..8796f34 100644
a
|
b
|
void MythImage::Assign(const QPixmap &pix) |
114 | 114 | Assign(pix.toImage()); |
115 | 115 | } |
116 | 116 | |
| 117 | QImage MythImage::ApplyExifOrientation(QImage &image, int orientation) |
| 118 | { |
| 119 | QTransform transform; |
| 120 | |
| 121 | switch (orientation) |
| 122 | { |
| 123 | case 1: // normal |
| 124 | return image; |
| 125 | case 2: // mirror horizontal |
| 126 | return image.mirrored(true, false); |
| 127 | case 3: // rotate 180 |
| 128 | transform.rotate(180); |
| 129 | return image.transformed(transform); |
| 130 | case 4: // mirror vertical |
| 131 | return image.mirrored(false, true); |
| 132 | case 5: // mirror horizontal and rotate 270 CCW |
| 133 | transform.rotate(270); |
| 134 | return image.mirrored(true, false).transformed(transform); |
| 135 | case 6: // rotate 90 CW |
| 136 | transform.rotate(90); |
| 137 | return image.transformed(transform); |
| 138 | case 7: // mirror horizontal and rotate 90 CW |
| 139 | transform.rotate(90); |
| 140 | return image.mirrored(true, false).transformed(transform); |
| 141 | case 8: // rotate 270 CW |
| 142 | transform.rotate(270); |
| 143 | return image.transformed(transform); |
| 144 | } |
| 145 | return image; |
| 146 | } |
| 147 | |
117 | 148 | /** |
118 | 149 | * Changes the orientation angle of the image according to |
119 | 150 | * the exif rotation values. The image will be rotated accordingly. |
… |
… |
void MythImage::Assign(const QPixmap &pix) |
122 | 153 | */ |
123 | 154 | void MythImage::Orientation(int orientation) |
124 | 155 | { |
125 | | if (m_isOriented) |
126 | | return; |
127 | | |
128 | | QMatrix matrix; |
129 | | switch (orientation) |
| 156 | if (!m_isOriented) |
130 | 157 | { |
131 | | case 1: // If the image is in its original state |
132 | | break; |
133 | | |
134 | | case 2: // The image is horizontally flipped |
135 | | Assign(mirrored(true, false)); |
136 | | break; |
137 | | |
138 | | case 3: // The image is rotated 180° |
139 | | matrix.rotate(180); |
140 | | Assign(transformed(matrix, Qt::SmoothTransformation)); |
141 | | break; |
142 | | |
143 | | case 4: // The image is vertically flipped |
144 | | Assign(mirrored(false, true)); |
145 | | break; |
146 | | |
147 | | case 5: // The image is transposed (flipped horizontally, then rotated 90° CCW) |
148 | | matrix.rotate(90); |
149 | | Assign(transformed(matrix, Qt::SmoothTransformation)); |
150 | | Assign(mirrored(true, false)); |
151 | | break; |
152 | | |
153 | | case 6: // The image is rotated 90° CCW |
154 | | matrix.rotate(90); |
155 | | Assign(transformed(matrix, Qt::SmoothTransformation)); |
156 | | break; |
157 | | |
158 | | case 7: // The image is transversed (flipped horizontally, then rotated 90° CW) |
159 | | matrix.rotate(270); |
160 | | Assign(transformed(matrix, Qt::SmoothTransformation)); |
161 | | Assign(mirrored(true, false)); |
162 | | break; |
163 | | |
164 | | case 8: // The image is rotated 90° CW |
165 | | matrix.rotate(270); |
166 | | Assign(transformed(matrix, Qt::SmoothTransformation)); |
167 | | break; |
168 | | |
169 | | default: |
170 | | break; |
| 158 | Assign(ApplyExifOrientation(*this, orientation)); |
| 159 | m_isOriented = true; |
171 | 160 | } |
172 | | |
173 | | m_isOriented = true; |
174 | 161 | } |
175 | 162 | |
176 | 163 | void MythImage::Resize(const QSize &newSize, bool preserveAspect) |
diff --git a/mythtv/libs/libmythui/mythimage.h b/mythtv/libs/libmythui/mythimage.h
index 4962dc2..646f7c4 100644
a
|
b
|
class MUI_PUBLIC MythImageReader: public QImageReader |
31 | 31 | class MUI_PUBLIC MythImage : public QImage, public ReferenceCounter |
32 | 32 | { |
33 | 33 | public: |
| 34 | static QImage ApplyExifOrientation(QImage &image, int orientation); |
| 35 | |
34 | 36 | /// Creates a reference counted image, call DecrRef() to delete. |
35 | 37 | MythImage(MythPainter *parent, const char *name = "MythImage"); |
36 | 38 | |
diff --git a/mythtv/libs/libmythui/mythuiimage.cpp b/mythtv/libs/libmythui/mythuiimage.cpp
index c7961a8..fc067f7 100644
a
|
b
|
void MythUIImage::SetImage(MythImage *img) |
813 | 813 | Clear(); |
814 | 814 | m_Delay = -1; |
815 | 815 | |
816 | | if (m_imageProperties.isOriented && !img->IsOriented() && |
817 | | (m_imageProperties.orientation >= 1 && |
818 | | m_imageProperties.orientation <= 8)) |
| 816 | if (m_imageProperties.isOriented && !img->IsOriented()) |
819 | 817 | img->Orientation(m_imageProperties.orientation); |
820 | 818 | |
821 | 819 | if (m_imageProperties.forceSize.isNull()) |
… |
… |
void MythUIImage::SetImages(QVector<MythImage *> *images) |
881 | 879 | if (m_imageProperties.isGreyscale && !im->isGrayscale()) |
882 | 880 | im->ToGreyscale(); |
883 | 881 | |
884 | | if (m_imageProperties.isOriented && !im->IsOriented() && |
885 | | (m_imageProperties.orientation >= 1 && |
886 | | m_imageProperties.orientation <= 8)) |
| 882 | if (m_imageProperties.isOriented && !im->IsOriented()) |
887 | 883 | im->Orientation(m_imageProperties.orientation); |
888 | 884 | |
889 | 885 | m_ImagesLock.lock(); |