2012-12-20 16:49:25 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2015-05-15 03:52:05 +00:00
|
|
|
#ifndef mozilla_image_ImageMetadata_h
|
|
|
|
#define mozilla_image_ImageMetadata_h
|
2013-11-19 06:03:36 +00:00
|
|
|
|
2013-07-30 14:25:31 +00:00
|
|
|
#include <stdint.h>
|
2013-08-27 22:10:28 +00:00
|
|
|
#include "mozilla/Maybe.h"
|
2013-02-27 19:23:08 +00:00
|
|
|
#include "nsSize.h"
|
2017-10-24 22:22:55 +00:00
|
|
|
#include "nsTArray.h"
|
2013-08-25 07:19:42 +00:00
|
|
|
#include "Orientation.h"
|
2017-03-22 13:05:36 +00:00
|
|
|
#include "FrameTimeout.h"
|
2012-12-20 16:49:25 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace image {
|
|
|
|
|
|
|
|
// The metadata about an image that decoders accumulate as they decode.
|
|
|
|
class ImageMetadata
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ImageMetadata()
|
2015-08-14 07:37:13 +00:00
|
|
|
: mLoopCount(-1)
|
2016-07-19 23:22:34 +00:00
|
|
|
, mFirstFrameTimeout(FrameTimeout::Forever())
|
2015-08-14 07:37:13 +00:00
|
|
|
, mHasAnimation(false)
|
2015-01-19 18:29:00 +00:00
|
|
|
{ }
|
2012-12-20 16:49:25 +00:00
|
|
|
|
2015-08-14 07:37:13 +00:00
|
|
|
void SetHotspot(uint16_t aHotspotX, uint16_t aHotspotY)
|
2012-12-20 16:49:25 +00:00
|
|
|
{
|
2015-08-14 07:37:13 +00:00
|
|
|
mHotspot = Some(gfx::IntPoint(aHotspotX, aHotspotY));
|
2012-12-20 16:49:25 +00:00
|
|
|
}
|
2015-08-14 07:37:13 +00:00
|
|
|
gfx::IntPoint GetHotspot() const { return *mHotspot; }
|
|
|
|
bool HasHotspot() const { return mHotspot.isSome(); }
|
|
|
|
|
2012-12-20 16:49:25 +00:00
|
|
|
void SetLoopCount(int32_t loopcount)
|
|
|
|
{
|
|
|
|
mLoopCount = loopcount;
|
|
|
|
}
|
2015-08-14 07:37:13 +00:00
|
|
|
int32_t GetLoopCount() const { return mLoopCount; }
|
|
|
|
|
2016-07-20 00:14:30 +00:00
|
|
|
void SetLoopLength(FrameTimeout aLength) { mLoopLength = Some(aLength); }
|
|
|
|
FrameTimeout GetLoopLength() const { return *mLoopLength; }
|
|
|
|
bool HasLoopLength() const { return mLoopLength.isSome(); }
|
|
|
|
|
2016-07-19 23:22:34 +00:00
|
|
|
void SetFirstFrameTimeout(FrameTimeout aTimeout) { mFirstFrameTimeout = aTimeout; }
|
|
|
|
FrameTimeout GetFirstFrameTimeout() const { return mFirstFrameTimeout; }
|
2012-12-20 16:49:25 +00:00
|
|
|
|
2016-07-20 06:35:41 +00:00
|
|
|
void SetFirstFrameRefreshArea(const gfx::IntRect& aRefreshArea)
|
|
|
|
{
|
|
|
|
mFirstFrameRefreshArea = Some(aRefreshArea);
|
|
|
|
}
|
|
|
|
gfx::IntRect GetFirstFrameRefreshArea() const { return *mFirstFrameRefreshArea; }
|
|
|
|
bool HasFirstFrameRefreshArea() const { return mFirstFrameRefreshArea.isSome(); }
|
|
|
|
|
2013-08-25 07:19:42 +00:00
|
|
|
void SetSize(int32_t width, int32_t height, Orientation orientation)
|
2013-02-27 19:23:08 +00:00
|
|
|
{
|
2015-01-08 08:01:25 +00:00
|
|
|
if (!HasSize()) {
|
|
|
|
mSize.emplace(nsIntSize(width, height));
|
|
|
|
mOrientation.emplace(orientation);
|
|
|
|
}
|
2013-02-27 19:23:08 +00:00
|
|
|
}
|
2015-08-14 07:37:13 +00:00
|
|
|
nsIntSize GetSize() const { return *mSize; }
|
2014-08-13 22:39:41 +00:00
|
|
|
bool HasSize() const { return mSize.isSome(); }
|
2016-07-21 23:42:29 +00:00
|
|
|
|
2017-03-22 13:05:36 +00:00
|
|
|
void AddNativeSize(const nsIntSize& aSize)
|
|
|
|
{
|
|
|
|
mNativeSizes.AppendElement(aSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsTArray<nsIntSize>& GetNativeSizes() const { return mNativeSizes; }
|
|
|
|
|
2016-07-21 23:42:29 +00:00
|
|
|
Orientation GetOrientation() const { return *mOrientation; }
|
2014-08-13 22:39:41 +00:00
|
|
|
bool HasOrientation() const { return mOrientation.isSome(); }
|
2013-02-27 19:23:08 +00:00
|
|
|
|
2015-08-14 07:37:13 +00:00
|
|
|
void SetHasAnimation() { mHasAnimation = true; }
|
|
|
|
bool HasAnimation() const { return mHasAnimation; }
|
2013-02-27 19:23:08 +00:00
|
|
|
|
2012-12-20 16:49:25 +00:00
|
|
|
private:
|
2015-08-14 07:37:13 +00:00
|
|
|
/// The hotspot found on cursors, if present.
|
|
|
|
Maybe<gfx::IntPoint> mHotspot;
|
2012-12-20 16:49:25 +00:00
|
|
|
|
2015-08-14 07:37:13 +00:00
|
|
|
/// The loop count for animated images, or -1 for infinite loop.
|
2012-12-20 16:49:25 +00:00
|
|
|
int32_t mLoopCount;
|
|
|
|
|
2016-07-20 00:14:30 +00:00
|
|
|
// The total length of a single loop through an animated image.
|
|
|
|
Maybe<FrameTimeout> mLoopLength;
|
|
|
|
|
2015-08-14 07:37:13 +00:00
|
|
|
/// The timeout of an animated image's first frame.
|
2016-07-19 23:22:34 +00:00
|
|
|
FrameTimeout mFirstFrameTimeout;
|
2015-08-14 07:37:13 +00:00
|
|
|
|
2016-07-20 06:35:41 +00:00
|
|
|
// The area of the image that needs to be invalidated when the animation
|
|
|
|
// loops.
|
|
|
|
Maybe<gfx::IntRect> mFirstFrameRefreshArea;
|
|
|
|
|
2013-02-27 19:23:08 +00:00
|
|
|
Maybe<nsIntSize> mSize;
|
2014-11-26 21:22:10 +00:00
|
|
|
Maybe<Orientation> mOrientation;
|
2015-08-14 07:37:13 +00:00
|
|
|
|
2017-03-22 13:05:36 +00:00
|
|
|
// Sizes the image can natively decode to.
|
|
|
|
nsTArray<nsIntSize> mNativeSizes;
|
|
|
|
|
2015-08-14 07:37:13 +00:00
|
|
|
bool mHasAnimation : 1;
|
2012-12-20 16:49:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace image
|
|
|
|
} // namespace mozilla
|
2013-11-19 06:03:36 +00:00
|
|
|
|
2015-05-15 03:52:05 +00:00
|
|
|
#endif // mozilla_image_ImageMetadata_h
|