1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_image_ImageMetadata_h
8 #define mozilla_image_ImageMetadata_h
12 #include "FrameTimeout.h"
13 #include "Orientation.h"
14 #include "mozilla/Maybe.h"
15 #include "mozilla/gfx/Point.h"
16 #include "mozilla/gfx/Rect.h"
17 #include "mozilla/image/Resolution.h"
21 namespace mozilla::image
{
23 // The metadata about an image that decoders accumulate as they decode.
26 ImageMetadata() = default;
28 void SetHotspot(uint16_t aHotspotX
, uint16_t aHotspotY
) {
29 mHotspot
= Some(gfx::IntPoint(aHotspotX
, aHotspotY
));
31 gfx::IntPoint
GetHotspot() const { return *mHotspot
; }
32 bool HasHotspot() const { return mHotspot
.isSome(); }
34 void SetLoopCount(int32_t loopcount
) { mLoopCount
= loopcount
; }
35 int32_t GetLoopCount() const { return mLoopCount
; }
37 void SetLoopLength(FrameTimeout aLength
) { mLoopLength
= Some(aLength
); }
38 FrameTimeout
GetLoopLength() const { return *mLoopLength
; }
39 bool HasLoopLength() const { return mLoopLength
.isSome(); }
41 void SetFrameCount(uint32_t aCount
) { mFrameCount
= Some(aCount
); }
42 uint32_t GetFrameCount() const { return *mFrameCount
; }
43 bool HasFrameCount() const { return mFrameCount
.isSome(); }
45 void SetFirstFrameTimeout(FrameTimeout aTimeout
) {
46 mFirstFrameTimeout
= aTimeout
;
48 FrameTimeout
GetFirstFrameTimeout() const { return mFirstFrameTimeout
; }
50 void SetFirstFrameRefreshArea(const gfx::IntRect
& aRefreshArea
) {
51 mFirstFrameRefreshArea
= Some(aRefreshArea
);
53 gfx::IntRect
GetFirstFrameRefreshArea() const {
54 return *mFirstFrameRefreshArea
;
56 bool HasFirstFrameRefreshArea() const {
57 return mFirstFrameRefreshArea
.isSome();
60 void SetSize(int32_t aWidth
, int32_t aHeight
, Orientation aOrientation
,
61 Resolution aResolution
) {
64 aOrientation
.ToOriented(UnorientedIntSize(aWidth
, aHeight
)));
65 mOrientation
.emplace(aOrientation
);
66 mResolution
= aResolution
;
69 OrientedIntSize
GetSize() const { return *mSize
; }
70 bool HasSize() const { return mSize
.isSome(); }
72 void AddNativeSize(const OrientedIntSize
& aSize
) {
73 mNativeSizes
.AppendElement(aSize
);
76 Resolution
GetResolution() const { return mResolution
; }
78 const nsTArray
<OrientedIntSize
>& GetNativeSizes() const {
82 Orientation
GetOrientation() const { return *mOrientation
; }
83 bool HasOrientation() const { return mOrientation
.isSome(); }
85 void SetHasAnimation() { mHasAnimation
= true; }
86 bool HasAnimation() const { return mHasAnimation
; }
89 /// The hotspot found on cursors, if present.
90 Maybe
<gfx::IntPoint
> mHotspot
;
92 /// The loop count for animated images, or -1 for infinite loop.
93 int32_t mLoopCount
= -1;
95 /// The resolution of the image in dppx.
96 Resolution mResolution
;
98 // The total length of a single loop through an animated image.
99 Maybe
<FrameTimeout
> mLoopLength
;
101 // The total number of frames we expect from the animated image.
102 Maybe
<uint32_t> mFrameCount
;
104 /// The timeout of an animated image's first frame.
105 FrameTimeout mFirstFrameTimeout
= FrameTimeout::Forever();
107 // The area of the image that needs to be invalidated when the animation
109 Maybe
<gfx::IntRect
> mFirstFrameRefreshArea
;
111 Maybe
<OrientedIntSize
> mSize
;
112 Maybe
<Orientation
> mOrientation
;
114 // Sizes the image can natively decode to.
115 CopyableTArray
<OrientedIntSize
> mNativeSizes
;
117 bool mHasAnimation
= false;
120 } // namespace mozilla::image
122 #endif // mozilla_image_ImageMetadata_h