1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_image_Resolution_h
7 #define mozilla_image_Resolution_h
9 #include "mozilla/Assertions.h"
16 * The resolution of an image, in dppx.
19 Resolution() = default;
20 Resolution(float aX
, float aY
) : mX(aX
), mY(aY
) {
21 MOZ_ASSERT(mX
!= 0.0f
);
22 MOZ_ASSERT(mY
!= 0.0f
);
25 bool operator==(const Resolution
& aOther
) const {
26 return mX
== aOther
.mX
&& mY
== aOther
.mY
;
28 bool operator!=(const Resolution
& aOther
) const { return !(*this == aOther
); }
33 void ScaleBy(float aScale
) {
34 if (MOZ_LIKELY(aScale
!= 0.0f
)) {
40 void ApplyXTo(int32_t& aWidth
) const {
42 aWidth
= std::round(float(aWidth
) / mX
);
46 void ApplyXTo(float& aWidth
) const {
52 void ApplyYTo(int32_t& aHeight
) const {
54 aHeight
= std::round(float(aHeight
) / mY
);
58 void ApplyYTo(float& aHeight
) const {
64 void ApplyTo(int32_t& aWidth
, int32_t& aHeight
) const {
69 void ApplyTo(float& aWidth
, float& aHeight
) const {
74 void ApplyInverseTo(int32_t& aWidth
, int32_t& aHeight
) {
76 aWidth
= std::round(float(aWidth
) * mX
);
79 aHeight
= std::round(float(aHeight
) * mY
);
86 using ImageResolution
= image::Resolution
;
88 } // namespace mozilla