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>
|
2021-03-25 13:19:44 +03:00
|
|
|
#include <utility>
|
|
|
|
#include "FrameTimeout.h"
|
|
|
|
#include "Orientation.h"
|
2013-08-28 02:10:28 +04:00
|
|
|
#include "mozilla/Maybe.h"
|
2021-03-25 13:19:44 +03:00
|
|
|
#include "mozilla/gfx/Point.h"
|
|
|
|
#include "mozilla/gfx/Rect.h"
|
2021-05-05 12:41:23 +03:00
|
|
|
#include "mozilla/image/Resolution.h"
|
2013-02-27 23:23:08 +04:00
|
|
|
#include "nsSize.h"
|
2017-10-25 01:22:55 +03:00
|
|
|
#include "nsTArray.h"
|
2012-12-20 20:49:25 +04:00
|
|
|
|
2021-05-05 12:41:23 +03:00
|
|
|
namespace mozilla::image {
|
2012-12-20 20:49:25 +04:00
|
|
|
|
|
|
|
// The metadata about an image that decoders accumulate as they decode.
|
|
|
|
class ImageMetadata {
|
|
|
|
public:
|
2021-05-05 12:41:23 +03:00
|
|
|
ImageMetadata() = default;
|
2012-12-20 20:49:25 +04:00
|
|
|
|
2015-08-14 10:37:13 +03:00
|
|
|
void SetHotspot(uint16_t aHotspotX, uint16_t aHotspotY) {
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2021-05-05 12:41:23 +03:00
|
|
|
void SetSize(int32_t aWidth, int32_t aHeight, Orientation aOrientation,
|
|
|
|
Resolution aResolution) {
|
2015-01-08 11:01:25 +03:00
|
|
|
if (!HasSize()) {
|
2021-10-06 17:41:17 +03:00
|
|
|
mSize.emplace(
|
|
|
|
aOrientation.ToOriented(UnorientedIntSize(aWidth, aHeight)));
|
2021-05-05 12:41:23 +03:00
|
|
|
mOrientation.emplace(aOrientation);
|
|
|
|
mResolution = aResolution;
|
2015-01-08 11:01:25 +03:00
|
|
|
}
|
2013-02-27 23:23:08 +04:00
|
|
|
}
|
2021-10-06 17:41:17 +03:00
|
|
|
OrientedIntSize 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
|
|
|
|
2021-10-06 17:41:17 +03:00
|
|
|
void AddNativeSize(const OrientedIntSize& aSize) {
|
2017-03-22 16:05:36 +03:00
|
|
|
mNativeSizes.AppendElement(aSize);
|
|
|
|
}
|
|
|
|
|
2021-05-05 12:41:23 +03:00
|
|
|
Resolution GetResolution() const { return mResolution; }
|
|
|
|
|
2021-10-06 17:41:17 +03:00
|
|
|
const nsTArray<OrientedIntSize>& GetNativeSizes() const {
|
|
|
|
return mNativeSizes;
|
|
|
|
}
|
2017-03-22 16:05:36 +03:00
|
|
|
|
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.
|
2021-05-05 12:41:23 +03:00
|
|
|
int32_t mLoopCount = -1;
|
|
|
|
|
|
|
|
/// The resolution of the image in dppx.
|
|
|
|
Resolution mResolution;
|
2012-12-20 20:49:25 +04:00
|
|
|
|
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.
|
2021-05-05 12:41:23 +03:00
|
|
|
FrameTimeout mFirstFrameTimeout = FrameTimeout::Forever();
|
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;
|
|
|
|
|
2021-10-06 17:41:17 +03:00
|
|
|
Maybe<OrientedIntSize> 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.
|
2021-10-06 17:41:17 +03:00
|
|
|
CopyableTArray<OrientedIntSize> mNativeSizes;
|
2017-03-22 16:05:36 +03:00
|
|
|
|
2021-05-05 12:41:23 +03:00
|
|
|
bool mHasAnimation = false;
|
2012-12-20 20:49:25 +04:00
|
|
|
};
|
|
|
|
|
2021-05-05 12:41:23 +03:00
|
|
|
} // namespace mozilla::image
|
2013-11-19 10:03:36 +04:00
|
|
|
|
2015-05-15 06:52:05 +03:00
|
|
|
#endif // mozilla_image_ImageMetadata_h
|