ImageMetadata.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  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/. */
  6. #ifndef mozilla_image_ImageMetadata_h
  7. #define mozilla_image_ImageMetadata_h
  8. #include <stdint.h>
  9. #include "mozilla/Maybe.h"
  10. #include "nsSize.h"
  11. #include "Orientation.h"
  12. namespace mozilla {
  13. namespace image {
  14. class RasterImage;
  15. // The metadata about an image that decoders accumulate as they decode.
  16. class ImageMetadata
  17. {
  18. public:
  19. ImageMetadata()
  20. : mLoopCount(-1)
  21. , mFirstFrameTimeout(FrameTimeout::Forever())
  22. , mHasAnimation(false)
  23. { }
  24. void SetHotspot(uint16_t aHotspotX, uint16_t aHotspotY)
  25. {
  26. mHotspot = Some(gfx::IntPoint(aHotspotX, aHotspotY));
  27. }
  28. gfx::IntPoint GetHotspot() const { return *mHotspot; }
  29. bool HasHotspot() const { return mHotspot.isSome(); }
  30. void SetLoopCount(int32_t loopcount)
  31. {
  32. mLoopCount = loopcount;
  33. }
  34. int32_t GetLoopCount() const { return mLoopCount; }
  35. void SetLoopLength(FrameTimeout aLength) { mLoopLength = Some(aLength); }
  36. FrameTimeout GetLoopLength() const { return *mLoopLength; }
  37. bool HasLoopLength() const { return mLoopLength.isSome(); }
  38. void SetFirstFrameTimeout(FrameTimeout aTimeout) { mFirstFrameTimeout = aTimeout; }
  39. FrameTimeout GetFirstFrameTimeout() const { return mFirstFrameTimeout; }
  40. void SetFirstFrameRefreshArea(const gfx::IntRect& aRefreshArea)
  41. {
  42. mFirstFrameRefreshArea = Some(aRefreshArea);
  43. }
  44. gfx::IntRect GetFirstFrameRefreshArea() const { return *mFirstFrameRefreshArea; }
  45. bool HasFirstFrameRefreshArea() const { return mFirstFrameRefreshArea.isSome(); }
  46. void SetSize(int32_t width, int32_t height, Orientation orientation)
  47. {
  48. if (!HasSize()) {
  49. mSize.emplace(nsIntSize(width, height));
  50. mOrientation.emplace(orientation);
  51. }
  52. }
  53. nsIntSize GetSize() const { return *mSize; }
  54. bool HasSize() const { return mSize.isSome(); }
  55. Orientation GetOrientation() const { return *mOrientation; }
  56. bool HasOrientation() const { return mOrientation.isSome(); }
  57. void SetHasAnimation() { mHasAnimation = true; }
  58. bool HasAnimation() const { return mHasAnimation; }
  59. private:
  60. /// The hotspot found on cursors, if present.
  61. Maybe<gfx::IntPoint> mHotspot;
  62. /// The loop count for animated images, or -1 for infinite loop.
  63. int32_t mLoopCount;
  64. // The total length of a single loop through an animated image.
  65. Maybe<FrameTimeout> mLoopLength;
  66. /// The timeout of an animated image's first frame.
  67. FrameTimeout mFirstFrameTimeout;
  68. // The area of the image that needs to be invalidated when the animation
  69. // loops.
  70. Maybe<gfx::IntRect> mFirstFrameRefreshArea;
  71. Maybe<nsIntSize> mSize;
  72. Maybe<Orientation> mOrientation;
  73. bool mHasAnimation : 1;
  74. };
  75. } // namespace image
  76. } // namespace mozilla
  77. #endif // mozilla_image_ImageMetadata_h