libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
pixelaspect.h
Go to the documentation of this file.
1
8#pragma once
9
10
11#include <promeki/config.h>
12#if PROMEKI_ENABLE_CORE
13#include <promeki/datatype.h>
14#include <promeki/namespace.h>
15#include <promeki/rational.h>
16#include <promeki/result.h>
17#include <promeki/string.h>
18
19PROMEKI_NAMESPACE_BEGIN
20
21class DataStream;
22
59class PixelAspect {
60 public:
61 PROMEKI_DATATYPE(PixelAspect, DataTypePixelAspect, 1)
62
63
64 Error writeToStream(DataStream &s) const;
66 template <uint32_t V> static Result<PixelAspect> readFromStream(DataStream &s);
67
69 using RationalType = Rational<unsigned int>;
70
72 PixelAspect() : _par(1, 1) {}
73
80 PixelAspect(unsigned int w, unsigned int h) : _par(w, h) {}
81
83 explicit PixelAspect(const RationalType &r) : _par(r) {}
84
86 bool isValid() const { return _par.isValid() && _par.numerator() > 0 && _par.denominator() > 0; }
87
89 bool isSquare() const { return isValid() && _par.numerator() == _par.denominator(); }
90
92 unsigned int width() const { return _par.numerator(); }
93
95 unsigned int height() const { return _par.denominator(); }
96
98 const RationalType &rational() const { return _par; }
99
101 double toDouble() const { return _par.toDouble(); }
102
112 String toString() const;
113
120 static Result<PixelAspect> fromString(const String &s);
121
123 bool operator==(const PixelAspect &o) const { return _par == o._par; }
125 bool operator!=(const PixelAspect &o) const { return _par != o._par; }
126
127 private:
128 RationalType _par;
129};
130
131PROMEKI_NAMESPACE_END
132
133#endif // PROMEKI_ENABLE_CORE