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
11 #include "mozilla/Maybe.h"
14 #include "Orientation.h"
15 #include "FrameTimeout.h"
20 // The metadata about an image that decoders accumulate as they decode.
25 mFirstFrameTimeout(FrameTimeout::Forever()),
26 mHasAnimation(false) {}
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 SetFirstFrameTimeout(FrameTimeout aTimeout
) {
42 mFirstFrameTimeout
= aTimeout
;
44 FrameTimeout
GetFirstFrameTimeout() const { return mFirstFrameTimeout
; }
46 void SetFirstFrameRefreshArea(const gfx::IntRect
& aRefreshArea
) {
47 mFirstFrameRefreshArea
= Some(aRefreshArea
);
49 gfx::IntRect
GetFirstFrameRefreshArea() const {
50 return *mFirstFrameRefreshArea
;
52 bool HasFirstFrameRefreshArea() const {
53 return mFirstFrameRefreshArea
.isSome();
56 void SetSize(int32_t width
, int32_t height
, Orientation orientation
) {
58 mSize
.emplace(nsIntSize(width
, height
));
59 mOrientation
.emplace(orientation
);
62 nsIntSize
GetSize() const { return *mSize
; }
63 bool HasSize() const { return mSize
.isSome(); }
65 void AddNativeSize(const nsIntSize
& aSize
) {
66 mNativeSizes
.AppendElement(aSize
);
69 const nsTArray
<nsIntSize
>& GetNativeSizes() const { return mNativeSizes
; }
71 Orientation
GetOrientation() const { return *mOrientation
; }
72 bool HasOrientation() const { return mOrientation
.isSome(); }
74 void SetHasAnimation() { mHasAnimation
= true; }
75 bool HasAnimation() const { return mHasAnimation
; }
78 /// The hotspot found on cursors, if present.
79 Maybe
<gfx::IntPoint
> mHotspot
;
81 /// The loop count for animated images, or -1 for infinite loop.
84 // The total length of a single loop through an animated image.
85 Maybe
<FrameTimeout
> mLoopLength
;
87 /// The timeout of an animated image's first frame.
88 FrameTimeout mFirstFrameTimeout
;
90 // The area of the image that needs to be invalidated when the animation
92 Maybe
<gfx::IntRect
> mFirstFrameRefreshArea
;
94 Maybe
<nsIntSize
> mSize
;
95 Maybe
<Orientation
> mOrientation
;
97 // Sizes the image can natively decode to.
98 CopyableTArray
<nsIntSize
> mNativeSizes
;
100 bool mHasAnimation
: 1;
104 } // namespace mozilla
106 #endif // mozilla_image_ImageMetadata_h