2013-04-06 01:14:34 +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_ImageOps_h
|
|
|
|
#define mozilla_image_ImageOps_h
|
2013-04-06 01:14:34 +04:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
2015-04-21 18:04:57 +03:00
|
|
|
#include "nsRect.h"
|
2017-03-22 16:05:36 +03:00
|
|
|
#include "ImageMetadata.h"
|
2013-04-06 01:14:34 +04:00
|
|
|
|
2014-07-22 04:59:22 +04:00
|
|
|
class gfxDrawable;
|
2013-04-06 01:14:34 +04:00
|
|
|
class imgIContainer;
|
2015-08-01 04:10:31 +03:00
|
|
|
class nsIInputStream;
|
2013-04-06 01:14:34 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
2015-08-01 04:10:31 +03:00
|
|
|
|
|
|
|
namespace gfx {
|
|
|
|
class SourceSurface;
|
|
|
|
}
|
|
|
|
|
2013-04-06 01:14:34 +04:00
|
|
|
namespace image {
|
|
|
|
|
|
|
|
class Image;
|
2014-06-19 04:57:51 +04:00
|
|
|
struct Orientation;
|
2017-03-22 16:05:36 +03:00
|
|
|
class SourceBuffer;
|
2013-04-06 01:14:34 +04:00
|
|
|
|
|
|
|
class ImageOps
|
|
|
|
{
|
|
|
|
public:
|
2017-03-22 16:05:36 +03:00
|
|
|
class ImageBuffer {
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ImageOps::ImageBuffer);
|
|
|
|
protected:
|
|
|
|
friend class ImageOps;
|
|
|
|
|
|
|
|
ImageBuffer() { }
|
|
|
|
virtual ~ImageBuffer() { }
|
|
|
|
|
|
|
|
virtual already_AddRefed<SourceBuffer> GetSourceBuffer() const = 0;
|
|
|
|
};
|
|
|
|
|
2013-04-06 01:14:34 +04:00
|
|
|
/**
|
|
|
|
* Creates a version of an existing image which does not animate and is frozen
|
|
|
|
* at the first frame.
|
|
|
|
*
|
|
|
|
* @param aImage The existing image.
|
|
|
|
*/
|
|
|
|
static already_AddRefed<Image> Freeze(Image* aImage);
|
|
|
|
static already_AddRefed<imgIContainer> Freeze(imgIContainer* aImage);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a clipped version of an existing image. Animation is unaffected.
|
|
|
|
*
|
2016-03-08 10:54:13 +03:00
|
|
|
* @param aImage The existing image.
|
|
|
|
* @param aClip The rectangle to clip the image against.
|
|
|
|
* @param aSVGViewportSize The specific viewort size of aImage. Unless aImage
|
|
|
|
* is a vector image without intrinsic size, this
|
|
|
|
* argument should be pass as Nothing().
|
2013-04-06 01:14:34 +04:00
|
|
|
*/
|
2016-03-08 10:54:13 +03:00
|
|
|
static already_AddRefed<Image> Clip(Image* aImage, nsIntRect aClip,
|
|
|
|
const Maybe<nsSize>& aSVGViewportSize =
|
|
|
|
Nothing());
|
2014-12-04 22:43:00 +03:00
|
|
|
static already_AddRefed<imgIContainer> Clip(imgIContainer* aImage,
|
2016-03-08 10:54:13 +03:00
|
|
|
nsIntRect aClip,
|
|
|
|
const Maybe<nsSize>& aSVGViewportSize =
|
|
|
|
Nothing());
|
2013-04-06 01:14:34 +04:00
|
|
|
|
2013-08-25 11:19:43 +04:00
|
|
|
/**
|
|
|
|
* Creates a version of an existing image which is rotated and/or flipped to
|
|
|
|
* the specified orientation.
|
|
|
|
*
|
|
|
|
* @param aImage The existing image.
|
|
|
|
* @param aOrientation The desired orientation.
|
|
|
|
*/
|
2014-12-04 22:43:00 +03:00
|
|
|
static already_AddRefed<Image> Orient(Image* aImage,
|
|
|
|
Orientation aOrientation);
|
|
|
|
static already_AddRefed<imgIContainer> Orient(imgIContainer* aImage,
|
|
|
|
Orientation aOrientation);
|
2013-08-25 11:19:43 +04:00
|
|
|
|
2014-07-22 04:59:22 +04:00
|
|
|
/**
|
|
|
|
* Creates an image from a gfxDrawable.
|
|
|
|
*
|
|
|
|
* @param aDrawable The gfxDrawable.
|
|
|
|
*/
|
2014-12-04 22:43:00 +03:00
|
|
|
static already_AddRefed<imgIContainer>
|
|
|
|
CreateFromDrawable(gfxDrawable* aDrawable);
|
2014-07-22 04:59:22 +04:00
|
|
|
|
2017-03-22 16:05:36 +03:00
|
|
|
/**
|
|
|
|
* Create a buffer to be used with DecodeMetadata and DecodeToSurface. Reusing
|
|
|
|
* an ImageBuffer representing the given input stream is more efficient if one
|
|
|
|
* has multiple Decode* calls to make on that stream.
|
|
|
|
*
|
2017-10-19 12:39:30 +03:00
|
|
|
* @param aInputStream An input stream containing an encoded image. The
|
|
|
|
* ownership is taken.
|
2017-03-22 16:05:36 +03:00
|
|
|
* @return An image buffer derived from the input stream.
|
|
|
|
*/
|
|
|
|
static already_AddRefed<ImageBuffer>
|
2017-10-19 12:39:30 +03:00
|
|
|
CreateImageBuffer(already_AddRefed<nsIInputStream> aInputStream);
|
2017-03-22 16:05:36 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Decodes an image's metadata from an nsIInputStream into the given
|
|
|
|
* structure. This function may be called off-main-thread.
|
|
|
|
*
|
2017-10-19 12:39:30 +03:00
|
|
|
* @param aInputStream An input stream containing an encoded image. Ownership
|
|
|
|
* is taken.
|
2017-03-22 16:05:36 +03:00
|
|
|
* @param aMimeType The MIME type of the image.
|
|
|
|
* @param aMetadata Where the image metadata is stored upon success.
|
|
|
|
* @return The status of the operation.
|
|
|
|
*/
|
|
|
|
static nsresult
|
2017-10-19 12:39:30 +03:00
|
|
|
DecodeMetadata(already_AddRefed<nsIInputStream> aInputStream,
|
2017-03-22 16:05:36 +03:00
|
|
|
const nsACString& aMimeType,
|
|
|
|
ImageMetadata& aMetadata);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Same as above but takes an ImageBuffer instead of nsIInputStream.
|
|
|
|
*/
|
|
|
|
static nsresult
|
|
|
|
DecodeMetadata(ImageBuffer* aBuffer,
|
|
|
|
const nsACString& aMimeType,
|
|
|
|
ImageMetadata& aMetadata);
|
|
|
|
|
2015-08-01 04:10:31 +03:00
|
|
|
/**
|
|
|
|
* Decodes an image from an nsIInputStream directly into a SourceSurface,
|
|
|
|
* without ever creating an Image or imgIContainer (which are mostly
|
|
|
|
* main-thread-only). That means that this function may be called
|
|
|
|
* off-main-thread.
|
|
|
|
*
|
2017-10-19 12:39:30 +03:00
|
|
|
* @param aInputStream An input stream containing an encoded image. The
|
|
|
|
* ownership is taken.
|
2015-08-01 04:10:31 +03:00
|
|
|
* @param aMimeType The MIME type of the image.
|
|
|
|
* @param aFlags Flags of the imgIContainer::FLAG_DECODE_* variety.
|
|
|
|
* @return A SourceSurface containing the first frame of the image at its
|
|
|
|
* intrinsic size, or nullptr if the image cannot be decoded.
|
|
|
|
*/
|
2015-08-01 04:10:34 +03:00
|
|
|
static already_AddRefed<gfx::SourceSurface>
|
2017-10-19 12:39:30 +03:00
|
|
|
DecodeToSurface(already_AddRefed<nsIInputStream> aInputStream,
|
2015-08-01 04:10:31 +03:00
|
|
|
const nsACString& aMimeType,
|
2017-03-22 16:05:36 +03:00
|
|
|
uint32_t aFlags,
|
|
|
|
const Maybe<gfx::IntSize>& aSize = Nothing());
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Same as above but takes an ImageBuffer instead of nsIInputStream.
|
|
|
|
*/
|
|
|
|
static already_AddRefed<gfx::SourceSurface>
|
|
|
|
DecodeToSurface(ImageBuffer* aBuffer,
|
|
|
|
const nsACString& aMimeType,
|
|
|
|
uint32_t aFlags,
|
|
|
|
const Maybe<gfx::IntSize>& aSize = Nothing());
|
2015-08-01 04:10:31 +03:00
|
|
|
|
2013-04-06 01:14:34 +04:00
|
|
|
private:
|
2017-03-22 16:05:36 +03:00
|
|
|
class ImageBufferImpl;
|
|
|
|
|
2013-04-06 01:14:34 +04:00
|
|
|
// This is a static utility class, so disallow instantiation.
|
|
|
|
virtual ~ImageOps() = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace image
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2015-05-15 06:52:05 +03:00
|
|
|
#endif // mozilla_image_ImageOps_h
|