Bug 1810189 - Update MOTS for WebGPU: +jimb,+egubler,+nical,+teoxoy. DONTBUILD r...
[gecko.git] / image / Resolution.h
blobb305b867b2a869f9b798eb96793a76c173781822
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"
10 #include <cmath>
12 namespace mozilla {
13 namespace image {
15 /**
16 * The resolution of an image, in dppx.
18 struct Resolution {
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); }
30 float mX = 1.0f;
31 float mY = 1.0f;
33 void ScaleBy(float aScale) {
34 if (MOZ_LIKELY(aScale != 0.0f)) {
35 mX *= aScale;
36 mY *= aScale;
40 void ApplyXTo(int32_t& aWidth) const {
41 if (mX != 1.0f) {
42 aWidth = std::round(float(aWidth) / mX);
46 void ApplyXTo(float& aWidth) const {
47 if (mX != 1.0f) {
48 aWidth /= mX;
52 void ApplyYTo(int32_t& aHeight) const {
53 if (mY != 1.0f) {
54 aHeight = std::round(float(aHeight) / mY);
58 void ApplyYTo(float& aHeight) const {
59 if (mY != 1.0f) {
60 aHeight /= mY;
64 void ApplyTo(int32_t& aWidth, int32_t& aHeight) const {
65 ApplyXTo(aWidth);
66 ApplyYTo(aHeight);
69 void ApplyTo(float& aWidth, float& aHeight) const {
70 ApplyXTo(aWidth);
71 ApplyYTo(aHeight);
74 void ApplyInverseTo(int32_t& aWidth, int32_t& aHeight) {
75 if (mX != 1.0f) {
76 aWidth = std::round(float(aWidth) * mX);
78 if (mY != 1.0f) {
79 aHeight = std::round(float(aHeight) * mY);
84 } // namespace image
86 using ImageResolution = image::Resolution;
88 } // namespace mozilla
90 #endif