Ticket #12424: 0014-Gallery-Use-common-orientation.patch

File 0014-Gallery-Use-common-orientation.patch, 7.9 KB (added by Roger Siddons <dizygotheca@…>, 5 years ago)
  • mythtv/libs/libmythmetadata/imagemetadata.cpp

    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  
    11#include "imagemetadata.h"
    22
    3 #include <QImage>
    4 
    53#include "mythlogging.h"
    64#include "mythcorecontext.h"  // for avcodeclock
    75#include "mythdirs.h"         // for ffprobe
    int Orientation::Transform(int transform) 
    4139}
    4240
    4341
    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 
    7642/*!
    7743 * \brief Adjust current orientation code to apply a transform to an image
    7844 * \details When displayed the image will be orientated iaw its orientation
  • mythtv/libs/libmythmetadata/imagemetadata.h

    diff --git a/mythtv/libs/libmythmetadata/imagemetadata.h b/mythtv/libs/libmythmetadata/imagemetadata.h
    index 79da608..6c11c37 100644
    a b public: 
    6868    QString Description();
    6969
    7070    static int FromRotation(const QString &degrees);
    71     static QImage ApplyExifOrientation(QImage &image, int orientation);
    7271
    7372private:
    7473    static QString AsText(int orientation);
  • mythtv/libs/libmythmetadata/imagethumbs.cpp

    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) 
    309309
    310310    // Orientate now to optimise load/display time - no orientation
    311311    // is required when displaying thumbnails
    312     image = Orientation::ApplyExifOrientation(image, orientBy);
     312    image = MythImage::ApplyExifOrientation(image, orientBy);
    313313
    314314    // Create the thumbnail
    315315    if (!image.save(im->m_thumbPath))
  • mythtv/libs/libmythui/mythimage.cpp

    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) 
    114114    Assign(pix.toImage());
    115115}
    116116
     117QImage 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
    117148/**
    118149 * Changes the orientation angle of the image according to
    119150 * the exif rotation values. The image will be rotated accordingly.
    void MythImage::Assign(const QPixmap &pix) 
    122153 */
    123154void MythImage::Orientation(int orientation)
    124155{
    125     if (m_isOriented)
    126         return;
    127 
    128     QMatrix matrix;
    129     switch (orientation)
     156    if (!m_isOriented)
    130157    {
    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;
    171160    }
    172 
    173     m_isOriented = true;
    174161}
    175162
    176163void MythImage::Resize(const QSize &newSize, bool preserveAspect)
  • mythtv/libs/libmythui/mythimage.h

    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 
    3131class MUI_PUBLIC MythImage : public QImage, public ReferenceCounter
    3232{
    3333  public:
     34    static QImage ApplyExifOrientation(QImage &image, int orientation);
     35
    3436    /// Creates a reference counted image, call DecrRef() to delete.
    3537    MythImage(MythPainter *parent, const char *name = "MythImage");
    3638
  • mythtv/libs/libmythui/mythuiimage.cpp

    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) 
    813813    Clear();
    814814    m_Delay = -1;
    815815
    816     if (m_imageProperties.isOriented && !img->IsOriented() &&
    817         (m_imageProperties.orientation >= 1 &&
    818          m_imageProperties.orientation <= 8))
     816    if (m_imageProperties.isOriented && !img->IsOriented())
    819817        img->Orientation(m_imageProperties.orientation);
    820818
    821819    if (m_imageProperties.forceSize.isNull())
    void MythUIImage::SetImages(QVector<MythImage *> *images) 
    881879        if (m_imageProperties.isGreyscale && !im->isGrayscale())
    882880            im->ToGreyscale();
    883881
    884         if (m_imageProperties.isOriented && !im->IsOriented() &&
    885             (m_imageProperties.orientation >= 1 &&
    886              m_imageProperties.orientation <= 8))
     882        if (m_imageProperties.isOriented && !im->IsOriented())
    887883            im->Orientation(m_imageProperties.orientation);
    888884
    889885        m_ImagesLock.lock();