Extend Size class
* Compute resolution * Get abbreviation, eg. 1080p
This commit is contained in:
parent
78ceef49fb
commit
c79e0435fe
|
@ -111,6 +111,7 @@ set(SRC_FILES
|
||||||
flac/flacmetadata.cpp
|
flac/flacmetadata.cpp
|
||||||
flac/flacstream.cpp
|
flac/flacstream.cpp
|
||||||
signature.cpp
|
signature.cpp
|
||||||
|
size.cpp
|
||||||
statusprovider.cpp
|
statusprovider.cpp
|
||||||
tag.cpp
|
tag.cpp
|
||||||
tagtarget.cpp
|
tagtarget.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";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
20
size.h
20
size.h
|
@ -23,9 +23,12 @@ public:
|
||||||
constexpr uint32 height() const;
|
constexpr uint32 height() const;
|
||||||
void setWidth(uint32 value);
|
void setWidth(uint32 value);
|
||||||
void setHeight(uint32 value);
|
void setHeight(uint32 value);
|
||||||
|
constexpr uint32 resolution() const;
|
||||||
|
const char *abbreviation() const;
|
||||||
|
|
||||||
bool constexpr isNull() const;
|
bool constexpr isNull() const;
|
||||||
bool constexpr operator==(const Size &other) const;
|
bool constexpr operator==(const Size &other) const;
|
||||||
|
bool constexpr operator>=(const Size &other) const;
|
||||||
std::string toString() const;
|
std::string toString() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -81,6 +84,14 @@ inline void Size::setHeight(uint32 value)
|
||||||
m_height = 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.
|
* \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);
|
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.
|
* \brief Returns the string representation of the current size.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue