Ticket #4162: mythgallery16x9.diff

File mythgallery16x9.diff, 4.5 KB (added by kielogl@…, 18 years ago)

mythgallery aspect ratio patch

  • mythplugins-0.20.2/mythgallery/mythgallery/galleryutil.cpp

    diff -Naur old/mythplugins-0.20.2/mythgallery/mythgallery/galleryutil.cpp new/mythplugins-0.20.2/mythgallery/mythgallery/galleryutil.cpp
    old new  
    2828#include "galleryutil.h"
    2929#include "thumbgenerator.h"
    3030
     31#ifdef Q_WS_X11
     32#define USING_XV
     33#include "util-x11.h"
     34#endif // Q_WS_X11
     35
    3136#ifdef EXIF_SUPPORT
    3237#include <libexif/exif-data.h>
    3338#include <libexif/exif-entry.h>
     
    348353    return false;
    349354}
    350355
     356QSize GalleryUtil::ScaleToDest(QSize sz, QSize dest)
     357{
     358
     359    // calculate screen pixel aspect ratio
     360    double pixelAspect = 1.0;
     361#ifdef Q_WS_X11
     362    Display *display = MythXOpenDisplay();
     363    int scr = DefaultScreen(display);
     364    int displayWidthPixel  = DisplayWidth(display,scr);
     365    int displayHeightPixel = DisplayHeight(display,scr);
     366    int displayWidthMM     = DisplayWidthMM(display,scr);
     367    int displayHeightMM    = DisplayHeightMM(display,scr);
     368    // avoid divide by 0
     369    if ((displayWidthPixel != 0) && (displayHeightPixel != 0) &&
     370        (displayWidthMM != 0) && (displayHeightMM != 0))
     371    {
     372        pixelAspect =
     373            ((double)displayWidthMM / (double)displayWidthPixel) /
     374            ((double)displayHeightMM / (double)displayHeightPixel);
     375    }
     376#endif // Q_WS_X11
     377
     378    // calculate image aspect ratio
     379    double imageAspect = 1.0;
     380    // avoid divide by 0
     381    if ((sz.width() != 0) && (sz.height() != 0))
     382    {
     383        imageAspect =
     384           (double)sz.width() / (double)sz.height();
     385    }
     386
     387    // scale to dest height for most images
     388    int scalewidth = (int)((float)dest.height() * imageAspect / pixelAspect);
     389    int scaleheight = dest.height();
     390    if (scalewidth > dest.width())
     391    {
     392        // scale to dest width for extra wide images
     393        scalewidth = dest.width();
     394        scaleheight = (int)((float)dest.width() * pixelAspect / imageAspect);
     395    }
     396
     397    sz.scale(scalewidth, scaleheight, QSize::ScaleFree);
     398    return sz;
     399}
     400
    351401bool GalleryUtil::CopyDirectory(const QFileInfo src, QFileInfo &dst)
    352402{
    353403    QDir srcDir(src.absFilePath());
  • mythplugins-0.20.2/mythgallery/mythgallery/galleryutil.h

    diff -Naur old/mythplugins-0.20.2/mythgallery/mythgallery/galleryutil.h new/mythplugins-0.20.2/mythgallery/mythgallery/galleryutil.h
    old new  
    4343    static bool Copy(const QFileInfo &src, QFileInfo &dst);
    4444    static bool Move(const QFileInfo &src, QFileInfo &dst);
    4545    static bool Delete(const QFileInfo &file);
     46    static QSize ScaleToDest(QSize sz, QSize dest);
    4647
    4748  private:
    4849    static bool CopyDirectory(const QFileInfo src, QFileInfo &dst);
  • mythplugins-0.20.2/mythgallery/mythgallery/gltexture.cpp

    diff -Naur old/mythplugins-0.20.2/mythgallery/mythgallery/gltexture.cpp new/mythplugins-0.20.2/mythgallery/mythgallery/gltexture.cpp
    old new  
    2626// MythGallery headers
    2727#include "thumbview.h"
    2828#include "gltexture.h"
     29#include "galleryutil.h"
    2930
    3031/** \fn GLTexture::Init(const QImage&)
    3132 *  \brief Create the texture initialized with QImage
     
    8586
    8687void GLTexture::ScaleTo(const QSize &dest)
    8788{
    88     QSize sz = GetSize();
    89     sz.scale(dest.width(), dest.height(), QSize::ScaleMin);
     89    QSize sz = GalleryUtil::ScaleToDest(GetSize(), dest);
    9090    SetScale((float)sz.width()  / (float)dest.width(),
    9191             (float)sz.height() / (float)dest.height());
    9292}
  • mythplugins-0.20.2/mythgallery/mythgallery/singleview.cpp

    diff -Naur old/mythplugins-0.20.2/mythgallery/mythgallery/singleview.cpp new/mythplugins-0.20.2/mythgallery/mythgallery/singleview.cpp
    old new  
    594594    if (m_image.isNull())
    595595        return;
    596596
    597     QImage img = m_image.smoothScale((int) (screenwidth  * m_zoom),
    598                                      (int) (screenheight * m_zoom),
    599                                      QImage::ScaleMin);
     597    QSize dest = QSize(
     598        (int)(screenwidth * m_zoom),
     599        (int)(screenheight * m_zoom));
     600    QSize sz = GalleryUtil::ScaleToDest(m_image.size(), dest);
     601    QImage img = m_image.smoothScale(sz);
    600602
    601603    SetPixmap(new QPixmap(img));
    602604}