ImageOps.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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_ImageOps_h
  7. #define mozilla_image_ImageOps_h
  8. #include "nsCOMPtr.h"
  9. #include "nsRect.h"
  10. class gfxDrawable;
  11. class imgIContainer;
  12. class nsIInputStream;
  13. namespace mozilla {
  14. namespace gfx {
  15. class SourceSurface;
  16. }
  17. namespace image {
  18. class Image;
  19. struct Orientation;
  20. class ImageOps
  21. {
  22. public:
  23. /**
  24. * Creates a version of an existing image which does not animate and is frozen
  25. * at the first frame.
  26. *
  27. * @param aImage The existing image.
  28. */
  29. static already_AddRefed<Image> Freeze(Image* aImage);
  30. static already_AddRefed<imgIContainer> Freeze(imgIContainer* aImage);
  31. /**
  32. * Creates a clipped version of an existing image. Animation is unaffected.
  33. *
  34. * @param aImage The existing image.
  35. * @param aClip The rectangle to clip the image against.
  36. * @param aSVGViewportSize The specific viewort size of aImage. Unless aImage
  37. * is a vector image without intrinsic size, this
  38. * argument should be pass as Nothing().
  39. */
  40. static already_AddRefed<Image> Clip(Image* aImage, nsIntRect aClip,
  41. const Maybe<nsSize>& aSVGViewportSize =
  42. Nothing());
  43. static already_AddRefed<imgIContainer> Clip(imgIContainer* aImage,
  44. nsIntRect aClip,
  45. const Maybe<nsSize>& aSVGViewportSize =
  46. Nothing());
  47. /**
  48. * Creates a version of an existing image which is rotated and/or flipped to
  49. * the specified orientation.
  50. *
  51. * @param aImage The existing image.
  52. * @param aOrientation The desired orientation.
  53. */
  54. static already_AddRefed<Image> Orient(Image* aImage,
  55. Orientation aOrientation);
  56. static already_AddRefed<imgIContainer> Orient(imgIContainer* aImage,
  57. Orientation aOrientation);
  58. /**
  59. * Creates an image from a gfxDrawable.
  60. *
  61. * @param aDrawable The gfxDrawable.
  62. */
  63. static already_AddRefed<imgIContainer>
  64. CreateFromDrawable(gfxDrawable* aDrawable);
  65. /**
  66. * Decodes an image from an nsIInputStream directly into a SourceSurface,
  67. * without ever creating an Image or imgIContainer (which are mostly
  68. * main-thread-only). That means that this function may be called
  69. * off-main-thread.
  70. *
  71. * @param aInputStream An input stream containing an encoded image.
  72. * @param aMimeType The MIME type of the image.
  73. * @param aFlags Flags of the imgIContainer::FLAG_DECODE_* variety.
  74. * @return A SourceSurface containing the first frame of the image at its
  75. * intrinsic size, or nullptr if the image cannot be decoded.
  76. */
  77. static already_AddRefed<gfx::SourceSurface>
  78. DecodeToSurface(nsIInputStream* aInputStream,
  79. const nsACString& aMimeType,
  80. uint32_t aFlags);
  81. private:
  82. // This is a static utility class, so disallow instantiation.
  83. virtual ~ImageOps() = 0;
  84. };
  85. } // namespace image
  86. } // namespace mozilla
  87. #endif // mozilla_image_ImageOps_h