tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ImageMetadata.h (3861B)


      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 
      7 #ifndef mozilla_image_ImageMetadata_h
      8 #define mozilla_image_ImageMetadata_h
      9 
     10 #include <stdint.h>
     11 #include "FrameTimeout.h"
     12 #include "Orientation.h"
     13 #include "mozilla/Maybe.h"
     14 #include "mozilla/gfx/Point.h"
     15 #include "mozilla/gfx/Rect.h"
     16 #include "mozilla/image/Resolution.h"
     17 #include "nsSize.h"
     18 #include "nsTArray.h"
     19 
     20 namespace mozilla::image {
     21 
     22 // The metadata about an image that decoders accumulate as they decode.
     23 class ImageMetadata {
     24 public:
     25  ImageMetadata() = default;
     26 
     27  void SetHotspot(uint16_t aHotspotX, uint16_t aHotspotY) {
     28    mHotspot = Some(gfx::IntPoint(aHotspotX, aHotspotY));
     29  }
     30  gfx::IntPoint GetHotspot() const { return *mHotspot; }
     31  bool HasHotspot() const { return mHotspot.isSome(); }
     32 
     33  void SetLoopCount(int32_t loopcount) { mLoopCount = loopcount; }
     34  int32_t GetLoopCount() const { return mLoopCount; }
     35 
     36  void SetLoopLength(FrameTimeout aLength) { mLoopLength = Some(aLength); }
     37  FrameTimeout GetLoopLength() const { return *mLoopLength; }
     38  bool HasLoopLength() const { return mLoopLength.isSome(); }
     39 
     40  void SetFrameCount(uint32_t aCount) { mFrameCount = Some(aCount); }
     41  uint32_t GetFrameCount() const { return *mFrameCount; }
     42  bool HasFrameCount() const { return mFrameCount.isSome(); }
     43 
     44  void SetFirstFrameTimeout(FrameTimeout aTimeout) {
     45    mFirstFrameTimeout = aTimeout;
     46  }
     47  FrameTimeout GetFirstFrameTimeout() const { return mFirstFrameTimeout; }
     48 
     49  void SetFirstFrameRefreshArea(const gfx::IntRect& aRefreshArea) {
     50    mFirstFrameRefreshArea = Some(aRefreshArea);
     51  }
     52  gfx::IntRect GetFirstFrameRefreshArea() const {
     53    return *mFirstFrameRefreshArea;
     54  }
     55  bool HasFirstFrameRefreshArea() const {
     56    return mFirstFrameRefreshArea.isSome();
     57  }
     58 
     59  void SetSize(int32_t aWidth, int32_t aHeight, Orientation aOrientation,
     60               Resolution aResolution) {
     61    if (!HasSize()) {
     62      mSize.emplace(
     63          aOrientation.ToOriented(UnorientedIntSize(aWidth, aHeight)));
     64      mOrientation.emplace(aOrientation);
     65      mResolution = aResolution;
     66    }
     67  }
     68  OrientedIntSize GetSize() const { return *mSize; }
     69  bool HasSize() const { return mSize.isSome(); }
     70 
     71  void AddNativeSize(const OrientedIntSize& aSize) {
     72    mNativeSizes.AppendElement(aSize);
     73  }
     74 
     75  Resolution GetResolution() const { return mResolution; }
     76 
     77  const nsTArray<OrientedIntSize>& GetNativeSizes() const {
     78    return mNativeSizes;
     79  }
     80 
     81  Orientation GetOrientation() const { return *mOrientation; }
     82  bool HasOrientation() const { return mOrientation.isSome(); }
     83 
     84  void SetHasAnimation() { mHasAnimation = true; }
     85  bool HasAnimation() const { return mHasAnimation; }
     86 
     87 private:
     88  /// The hotspot found on cursors, if present.
     89  Maybe<gfx::IntPoint> mHotspot;
     90 
     91  /// The loop count for animated images, or -1 for infinite loop.
     92  int32_t mLoopCount = -1;
     93 
     94  /// The resolution of the image in dppx.
     95  Resolution mResolution;
     96 
     97  // The total length of a single loop through an animated image.
     98  Maybe<FrameTimeout> mLoopLength;
     99 
    100  // The total number of frames we expect from the animated image.
    101  Maybe<uint32_t> mFrameCount;
    102 
    103  /// The timeout of an animated image's first frame.
    104  FrameTimeout mFirstFrameTimeout = FrameTimeout::Forever();
    105 
    106  // The area of the image that needs to be invalidated when the animation
    107  // loops.
    108  Maybe<gfx::IntRect> mFirstFrameRefreshArea;
    109 
    110  Maybe<OrientedIntSize> mSize;
    111  Maybe<Orientation> mOrientation;
    112 
    113  // Sizes the image can natively decode to.
    114  CopyableTArray<OrientedIntSize> mNativeSizes;
    115 
    116  bool mHasAnimation = false;
    117 };
    118 
    119 }  // namespace mozilla::image
    120 
    121 #endif  // mozilla_image_ImageMetadata_h