2012-12-20 20:49:25 +04: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 06:52:05 +03:00
|
|
|
#ifndef mozilla_image_ImageMetadata_h
|
|
|
|
#define mozilla_image_ImageMetadata_h
|
2013-11-19 10:03:36 +04:00
|
|
|
|
2013-07-30 18:25:31 +04:00
|
|
|
#include <stdint.h>
|
2013-08-28 02:10:28 +04:00
|
|
|
#include "mozilla/Maybe.h"
|
2013-02-27 23:23:08 +04:00
|
|
|
#include "nsSize.h"
|
2013-08-25 11:19:42 +04:00
|
|
|
#include "Orientation.h"
|
2017-03-22 16:05:36 +03:00
|
|
|
#include "FrameTimeout.h"
|
2012-12-20 20:49:25 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace image {
|
|
|
|
|
|
|
|
// The metadata about an image that decoders accumulate as they decode.
|
|
|
|
class ImageMetadata
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ImageMetadata()
|
2015-08-14 10:37:13 +03:00
|
|
|
: mLoopCount(-1)
|
2016-07-20 02:22:34 +03:00
|
|
|
, mFirstFrameTimeout(FrameTimeout::Forever())
|
2015-08-14 10:37:13 +03:00
|
|
|
, mHasAnimation(false)
|
2015-01-19 21:29:00 +03:00
|
|
|
{ }
|
2012-12-20 20:49:25 +04:00
|
|
|
|
2015-08-14 10:37:13 +03:00
|
|
|
void SetHotspot(uint16_t aHotspotX, uint16_t aHotspotY)
|
2012-12-20 20:49:25 +04:00
|
|
|
{
|
2015-08-14 10:37:13 +03:00
|
|
|
mHotspot = Some(gfx::IntPoint(aHotspotX, aHotspotY));
|
2012-12-20 20:49:25 +04:00
|
|
|
}
|
2015-08-14 10:37:13 +03:00
|
|
|
gfx::IntPoint GetHotspot() const { return *mHotspot; }
|
|
|
|
bool HasHotspot() const { return mHotspot.isSome(); }
|
|
|
|
|
2012-12-20 20:49:25 +04:00
|
|
|
void SetLoopCount(int32_t loopcount)
|
|
|
|
{
|
|
|
|
mLoopCount = loopcount;
|
|
|
|
}
|
2015-08-14 10:37:13 +03:00
|
|
|
int32_t GetLoopCount() const { return mLoopCount; }
|
|
|
|
|
2016-07-20 03:14:30 +03:00
|
|
|
void SetLoopLength(FrameTimeout aLength) { mLoopLength = Some(aLength); }
|
|
|
|
FrameTimeout GetLoopLength() const { return *mLoopLength; }
|
|
|
|
bool HasLoopLength() const { return mLoopLength.isSome(); }
|
|
|
|
|
2016-07-20 02:22:34 +03:00
|
|
|
void SetFirstFrameTimeout(FrameTimeout aTimeout) { mFirstFrameTimeout = aTimeout; }
|
|
|
|
FrameTimeout GetFirstFrameTimeout() const { return mFirstFrameTimeout; }
|
2012-12-20 20:49:25 +04:00
|
|
|
|
2016-07-20 09:35:41 +03: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 11:19:42 +04:00
|
|
|
void SetSize(int32_t width, int32_t height, Orientation orientation)
|
2013-02-27 23:23:08 +04:00
|
|
|
{
|
2015-01-08 11:01:25 +03:00
|
|
|
if (!HasSize()) {
|
|
|
|
mSize.emplace(nsIntSize(width, height));
|
|
|
|
mOrientation.emplace(orientation);
|
|
|
|
}
|
2013-02-27 23:23:08 +04:00
|
|
|
}
|
2015-08-14 10:37:13 +03:00
|
|
|
nsIntSize GetSize() const { return *mSize; }
|
2014-08-14 02:39:41 +04:00
|
|
|
bool HasSize() const { return mSize.isSome(); }
|
2016-07-22 02:42:29 +03:00
|
|
|
|
2017-03-22 16:05:36 +03:00
|
|
|
void AddNativeSize(const nsIntSize& aSize)
|
|
|
|
{
|
|
|
|
mNativeSizes.AppendElement(aSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsTArray<nsIntSize>& GetNativeSizes() const { return mNativeSizes; }
|
|
|
|
|
2016-07-22 02:42:29 +03:00
|
|
|
Orientation GetOrientation() const { return *mOrientation; }
|
2014-08-14 02:39:41 +04:00
|
|
|
bool HasOrientation() const { return mOrientation.isSome(); }
|
2013-02-27 23:23:08 +04:00
|
|
|
|
2015-08-14 10:37:13 +03:00
|
|
|
void SetHasAnimation() { mHasAnimation = true; }
|
|
|
|
bool HasAnimation() const { return mHasAnimation; }
|
2013-02-27 23:23:08 +04:00
|
|
|
|
2012-12-20 20:49:25 +04:00
|
|
|
private:
|
2015-08-14 10:37:13 +03:00
|
|
|
/// The hotspot found on cursors, if present.
|
|
|
|
Maybe<gfx::IntPoint> mHotspot;
|
2012-12-20 20:49:25 +04:00
|
|
|
|
2015-08-14 10:37:13 +03:00
|
|
|
/// The loop count for animated images, or -1 for infinite loop.
|
2012-12-20 20:49:25 +04:00
|
|
|
int32_t mLoopCount;
|
|
|
|
|
2016-07-20 03:14:30 +03:00
|
|
|
// The total length of a single loop through an animated image.
|
|
|
|
Maybe<FrameTimeout> mLoopLength;
|
|
|
|
|
2015-08-14 10:37:13 +03:00
|
|
|
/// The timeout of an animated image's first frame.
|
2016-07-20 02:22:34 +03:00
|
|
|
FrameTimeout mFirstFrameTimeout;
|
2015-08-14 10:37:13 +03:00
|
|
|
|
2016-07-20 09:35:41 +03:00
|
|
|
// The area of the image that needs to be invalidated when the animation
|
|
|
|
// loops.
|
|
|
|
Maybe<gfx::IntRect> mFirstFrameRefreshArea;
|
|
|
|
|
2013-02-27 23:23:08 +04:00
|
|
|
Maybe<nsIntSize> mSize;
|
2014-11-27 00:22:10 +03:00
|
|
|
Maybe<Orientation> mOrientation;
|
2015-08-14 10:37:13 +03:00
|
|
|
|
2017-03-22 16:05:36 +03:00
|
|
|
// Sizes the image can natively decode to.
|
|
|
|
nsTArray<nsIntSize> mNativeSizes;
|
|
|
|
|
2015-08-14 10:37:13 +03:00
|
|
|
bool mHasAnimation : 1;
|
2012-12-20 20:49:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace image
|
|
|
|
} // namespace mozilla
|
2013-11-19 10:03:36 +04:00
|
|
|
|
2015-05-15 06:52:05 +03:00
|
|
|
#endif // mozilla_image_ImageMetadata_h
|