1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 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/. */
7 #ifndef mozilla_image_DecoderFactory_h
8 #define mozilla_image_DecoderFactory_h
10 #include "DecoderFlags.h"
11 #include "mozilla/Attributes.h"
12 #include "mozilla/Maybe.h"
13 #include "mozilla/NotNull.h"
14 #include "mozilla/gfx/2D.h"
16 #include "SurfaceFlags.h"
26 class SourceBufferIterator
;
29 * The type of decoder; this is usually determined from a MIME type using
30 * DecoderFactory::GetDecoderType().
32 enum class DecoderType
{
44 class DecoderFactory
{
46 /// @return the type of decoder which is appropriate for @aMimeType.
47 static DecoderType
GetDecoderType(const char* aMimeType
);
50 * Creates and initializes a decoder for non-animated images of type @aType.
51 * (If the image *is* animated, only the first frame will be decoded.) The
52 * decoder will send notifications to @aImage.
54 * @param aType Which type of decoder to create - JPEG, PNG, etc.
55 * @param aImage The image will own the decoder and which should receive
56 * notifications as decoding progresses.
57 * @param aSourceBuffer The SourceBuffer which the decoder will read its data
59 * @param aIntrinsicSize The intrinsic size of the image, normally obtained
60 * during the metadata decode.
61 * @param aOutputSize The output size for the decoder. If this is smaller than
62 * the intrinsic size, the decoder will downscale the
64 * @param aDecoderFlags Flags specifying the behavior of this decoder.
65 * @param aSurfaceFlags Flags specifying the type of output this decoder
67 * @param aOutTask Task representing the decoder.
68 * @return NS_OK if the decoder has been created/initialized successfully;
69 * NS_ERROR_ALREADY_INITIALIZED if there is already an active decoder
71 * Else some other unrecoverable error occurred.
73 static nsresult
CreateDecoder(DecoderType aType
, NotNull
<RasterImage
*> aImage
,
74 NotNull
<SourceBuffer
*> aSourceBuffer
,
75 const gfx::IntSize
& aIntrinsicSize
,
76 const gfx::IntSize
& aOutputSize
,
77 DecoderFlags aDecoderFlags
,
78 SurfaceFlags aSurfaceFlags
,
79 IDecodingTask
** aOutTask
);
82 * Creates and initializes a decoder for animated images of type @aType.
83 * The decoder will send notifications to @aImage.
85 * @param aType Which type of decoder to create - JPEG, PNG, etc.
86 * @param aImage The image will own the decoder and which should receive
87 * notifications as decoding progresses.
88 * @param aSourceBuffer The SourceBuffer which the decoder will read its data
90 * @param aIntrinsicSize The intrinsic size of the image, normally obtained
91 * during the metadata decode.
92 * @param aDecoderFlags Flags specifying the behavior of this decoder.
93 * @param aSurfaceFlags Flags specifying the type of output this decoder
95 * @param aCurrentFrame The current frame the decoder should auto advance to.
96 * @param aOutTask Task representing the decoder.
97 * @return NS_OK if the decoder has been created/initialized successfully;
98 * NS_ERROR_ALREADY_INITIALIZED if there is already an active decoder
100 * Else some other unrecoverable error occurred.
102 static nsresult
CreateAnimationDecoder(
103 DecoderType aType
, NotNull
<RasterImage
*> aImage
,
104 NotNull
<SourceBuffer
*> aSourceBuffer
, const gfx::IntSize
& aIntrinsicSize
,
105 DecoderFlags aDecoderFlags
, SurfaceFlags aSurfaceFlags
,
106 size_t aCurrentFrame
, IDecodingTask
** aOutTask
);
109 * Creates and initializes a decoder for animated images, cloned from the
112 * @param aDecoder Decoder to clone.
114 static already_AddRefed
<Decoder
> CloneAnimationDecoder(Decoder
* aDecoder
);
117 * Creates and initializes a metadata decoder of type @aType. This decoder
118 * will only decode the image's header, extracting metadata like the size of
119 * the image. No actual image data will be decoded and no surfaces will be
120 * allocated. The decoder will send notifications to @aImage.
122 * @param aType Which type of decoder to create - JPEG, PNG, etc.
123 * @param aImage The image will own the decoder and which should receive
124 * notifications as decoding progresses.
125 * @param aSourceBuffer The SourceBuffer which the decoder will read its data
128 static already_AddRefed
<IDecodingTask
> CreateMetadataDecoder(
129 DecoderType aType
, NotNull
<RasterImage
*> aImage
,
130 NotNull
<SourceBuffer
*> aSourceBuffer
);
133 * Creates and initializes a decoder for an ICO resource, which may be either
134 * a BMP or PNG image.
136 * @param aType Which type of decoder to create. This must be either BMP or
138 * @param aIterator The SourceBufferIterator which the decoder will read its
140 * @param aICODecoder The ICO decoder which is controlling this resource
141 * decoder. @aICODecoder's settings will be copied to the
142 * resource decoder, so the two decoders will have the
143 * same decoder flags, surface flags, target size, and
145 * @param aIsMetadataDecode Indicates whether or not this decoder is for
146 * metadata or not. Independent of the state of the
148 * @param aExpectedSize The expected size of the resource from the ICO header.
149 * @param aDataOffset If @aType is BMP, specifies the offset at which data
150 * begins in the BMP resource. Must be Some() if and only
153 static already_AddRefed
<Decoder
> CreateDecoderForICOResource(
154 DecoderType aType
, SourceBufferIterator
&& aIterator
,
155 NotNull
<nsICODecoder
*> aICODecoder
, bool aIsMetadataDecode
,
156 const Maybe
<gfx::IntSize
>& aExpectedSize
,
157 const Maybe
<uint32_t>& aDataOffset
= Nothing());
160 * Creates and initializes an anonymous decoder (one which isn't associated
161 * with an Image object). Only the first frame of the image will be decoded.
163 * @param aType Which type of decoder to create - JPEG, PNG, etc.
164 * @param aSourceBuffer The SourceBuffer which the decoder will read its data
166 * @param aOutputSize If Some(), the output size for the decoder. If this is
167 * smaller than the intrinsic size, the decoder will
168 * downscale the image. If Nothing(), the output size will
169 * be the intrinsic size.
170 * @param aDecoderFlags Flags specifying the behavior of this decoder.
171 * @param aSurfaceFlags Flags specifying the type of output this decoder
174 static already_AddRefed
<Decoder
> CreateAnonymousDecoder(
175 DecoderType aType
, NotNull
<SourceBuffer
*> aSourceBuffer
,
176 const Maybe
<gfx::IntSize
>& aOutputSize
, DecoderFlags aDecoderFlags
,
177 SurfaceFlags aSurfaceFlags
);
180 * Creates and initializes an anonymous metadata decoder (one which isn't
181 * associated with an Image object). This decoder will only decode the image's
182 * header, extracting metadata like the size of the image. No actual image
183 * data will be decoded and no surfaces will be allocated.
185 * @param aType Which type of decoder to create - JPEG, PNG, etc.
186 * @param aSourceBuffer The SourceBuffer which the decoder will read its data
189 static already_AddRefed
<Decoder
> CreateAnonymousMetadataDecoder(
190 DecoderType aType
, NotNull
<SourceBuffer
*> aSourceBuffer
);
193 virtual ~DecoderFactory() = 0;
196 * An internal method which allocates a new decoder of the requested @aType.
198 static already_AddRefed
<Decoder
> GetDecoder(DecoderType aType
,
204 } // namespace mozilla
206 #endif // mozilla_image_DecoderFactory_h