utils.h 2.45 KB
Newer Older
Gus Grubba's avatar
Gus Grubba committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
    Copyright (C) 2011-2012 Collabora Ltd. <info@collabora.com>

    This library is free software; you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License version 2.1
    as published by the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
16
#pragma once
Gus Grubba's avatar
Gus Grubba committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76

#include <QRectF>
#include <QSize>
#include <QMetaType>

// utilities for GST_DEBUG
#define QSIZE_FORMAT "(%d x %d)"
#define QSIZE_FORMAT_ARGS(size) \
    size.width(), size.height()
#define QRECTF_FORMAT "(x: %f, y: %f, w: %f, h: %f)"
#define QRECTF_FORMAT_ARGS(rect) \
    (float) rect.x(), (float) rect.y(), (float) rect.width(), (float) rect.height()

struct Fraction
{
    inline Fraction() {}
    inline Fraction(int numerator, int denominator)
        : numerator(numerator), denominator(denominator) {}

    inline bool operator==(const Fraction & other) const
    { return numerator == other.numerator && denominator == other.denominator; }
    inline bool operator!=(const Fraction & other) const
    { return !operator==(other); }

    inline qreal ratio() const
    { return (qreal) numerator / (qreal) denominator; }
    inline qreal invRatio() const
    { return (qreal) denominator / (qreal) numerator; }

    int numerator;
    int denominator;
};

struct PaintAreas
{
    void calculate(const QRectF & targetArea,
                   const QSize & videoSize,
                   const Fraction & pixelAspectRatio,
                   const Fraction & displayAspectRatio,
                   Qt::AspectRatioMode aspectRatioMode);

    // the area that we paint on
    QRectF targetArea;
    // the area where the video should be painted on
    // (subrect of or equal to targetArea)
    QRectF videoArea;

    // the part of the video rectangle that we are going to blit on the videoArea
    // in the normalized (0,1] range (texture coordinates)
    QRectF sourceRect;

    // these are small subrects of targetArea that are not
    // covered by videoArea to keep the video's aspect ratio
    QRectF blackArea1;
    QRectF blackArea2;
};

Q_DECLARE_METATYPE(Fraction)
Q_DECLARE_METATYPE(PaintAreas)