From c79e0435fe54f3f3400f272ce94fcbb04a7ac5ed Mon Sep 17 00:00:00 2001 From: Martchus Date: Thu, 17 Aug 2017 18:18:10 +0200 Subject: [PATCH] Extend Size class * Compute resolution * Get abbreviation, eg. 1080p --- CMakeLists.txt | 1 + size.cpp | 31 +++++++++++++++++++++++++++++++ size.h | 20 ++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 size.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b41a39..6d6b693 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -111,6 +111,7 @@ set(SRC_FILES flac/flacmetadata.cpp flac/flacstream.cpp signature.cpp + size.cpp statusprovider.cpp tag.cpp tagtarget.cpp diff --git a/size.cpp b/size.cpp new file mode 100644 index 0000000..9b38057 --- /dev/null +++ b/size.cpp @@ -0,0 +1,31 @@ +#include "./size.h" + +namespace Media { + +/*! + * \brief Returns an abbreviation for the current instance, eg. 720p for sizes greather than 1280×720 + * and 1080p for sizes greather than 1920×1080. + */ +const char *Size::abbreviation() const +{ + if(*this >= Size(7680, 4320)) { + return "8k"; + } else if(*this >= Size(3840, 2160)) { + return "4k"; + } else if(*this >= Size(1920, 1080)) { + return "1080p"; + } else if(*this >= Size(1280, 720)) { + return "720p"; + } else if(*this >= Size(704, 576)) { + return "576p"; + } else if(*this >= Size(640, 480)) { + return "480p"; + } else if(*this >= Size(480, 320)) { + return "320p"; + } else if(*this >= Size(320, 240)) { + return "240p"; + } + return "<240p"; +} + +} diff --git a/size.h b/size.h index 4e24109..7c183f7 100644 --- a/size.h +++ b/size.h @@ -23,9 +23,12 @@ public: constexpr uint32 height() const; void setWidth(uint32 value); void setHeight(uint32 value); + constexpr uint32 resolution() const; + const char *abbreviation() const; bool constexpr isNull() const; bool constexpr operator==(const Size &other) const; + bool constexpr operator>=(const Size &other) const; std::string toString() const; private: @@ -81,6 +84,14 @@ inline void Size::setHeight(uint32 value) m_height = value; } +/*! + * \brief Returns the resolution of the current instance (product of with and height). + */ +constexpr uint32 Size::resolution() const +{ + return m_width * m_height; +} + /*! * \brief Returns an indication whether both the width and height is 0. */ @@ -97,6 +108,15 @@ constexpr bool Size::operator==(const Size &other) const return (m_width == other.m_width) && (m_height == other.m_height); } +/*! + * \brief Returns whether this instance is greather than \a other. + * \remarks Both dimensions must be greather. This operator does *not* take the resolution() into account. + */ +constexpr bool Size::operator>=(const Size &other) const +{ + return (m_width >= other.m_width) && (m_height >= other.m_height); +} + /*! * \brief Returns the string representation of the current size. */