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/gfx/2D.h"
15 #include "SurfaceFlags.h"
27 * The type of decoder; this is usually determined from a MIME type using
28 * DecoderFactory::GetDecoderType().
30 enum class DecoderType
44 /// @return the type of decoder which is appropriate for @aMimeType.
45 static DecoderType
GetDecoderType(const char* aMimeType
);
48 * Creates and initializes a decoder for non-animated images of type @aType.
49 * (If the image *is* animated, only the first frame will be decoded.) The
50 * decoder will send notifications to @aImage.
52 * @param aType Which type of decoder to create - JPEG, PNG, etc.
53 * @param aImage The image will own the decoder and which should receive
54 * notifications as decoding progresses.
55 * @param aSourceBuffer The SourceBuffer which the decoder will read its data
57 * @param aTargetSize If not Nothing(), the target size which the image should
58 * be scaled to during decoding. It's an error to specify
59 * a target size for a decoder type which doesn't support
60 * downscale-during-decode.
61 * @param aDecoderFlags Flags specifying the behavior of this decoder.
62 * @param aSurfaceFlags Flags specifying the type of output this decoder
64 * @param aSampleSize The sample size requested using #-moz-samplesize (or 0
67 static already_AddRefed
<Decoder
>
68 CreateDecoder(DecoderType aType
,
70 SourceBuffer
* aSourceBuffer
,
71 const Maybe
<gfx::IntSize
>& aTargetSize
,
72 DecoderFlags aDecoderFlags
,
73 SurfaceFlags aSurfaceFlags
,
77 * Creates and initializes a decoder for animated images of type @aType.
78 * The decoder will send notifications to @aImage.
80 * @param aType Which type of decoder to create - JPEG, PNG, etc.
81 * @param aImage The image will own the decoder and which should receive
82 * notifications as decoding progresses.
83 * @param aSourceBuffer The SourceBuffer which the decoder will read its data
85 * @param aDecoderFlags Flags specifying the behavior of this decoder.
86 * @param aSurfaceFlags Flags specifying the type of output this decoder
89 static already_AddRefed
<Decoder
>
90 CreateAnimationDecoder(DecoderType aType
,
92 SourceBuffer
* aSourceBuffer
,
93 DecoderFlags aDecoderFlags
,
94 SurfaceFlags aSurfaceFlags
);
97 * Creates and initializes a metadata decoder of type @aType. This decoder
98 * will only decode the image's header, extracting metadata like the size of
99 * the image. No actual image data will be decoded and no surfaces will be
100 * allocated. The decoder will send notifications to @aImage.
102 * @param aType Which type of decoder to create - JPEG, PNG, etc.
103 * @param aImage The image will own the decoder and which should receive
104 * notifications as decoding progresses.
105 * @param aSourceBuffer The SourceBuffer which the decoder will read its data
107 * @param aSampleSize The sample size requested using #-moz-samplesize (or 0
110 static already_AddRefed
<Decoder
>
111 CreateMetadataDecoder(DecoderType aType
,
113 SourceBuffer
* aSourceBuffer
,
117 * Creates and initializes an anonymous decoder (one which isn't associated
118 * with an Image object). Only the first frame of the image will be decoded.
120 * @param aType Which type of decoder to create - JPEG, PNG, etc.
121 * @param aSourceBuffer The SourceBuffer which the decoder will read its data
123 * @param aSurfaceFlags Flags specifying the type of output this decoder
126 static already_AddRefed
<Decoder
>
127 CreateAnonymousDecoder(DecoderType aType
,
128 SourceBuffer
* aSourceBuffer
,
129 SurfaceFlags aSurfaceFlags
);
132 * Creates and initializes an anonymous metadata decoder (one which isn't
133 * associated with an Image object). This decoder will only decode the image's
134 * header, extracting metadata like the size of the image. No actual image
135 * data will be decoded and no surfaces will be allocated.
137 * @param aType Which type of decoder to create - JPEG, PNG, etc.
138 * @param aSourceBuffer The SourceBuffer which the decoder will read its data
141 static already_AddRefed
<Decoder
>
142 CreateAnonymousMetadataDecoder(DecoderType aType
,
143 SourceBuffer
* aSourceBuffer
);
146 virtual ~DecoderFactory() = 0;
149 * An internal method which allocates a new decoder of the requested @aType.
151 static already_AddRefed
<Decoder
> GetDecoder(DecoderType aType
,
157 } // namespace mozilla
159 #endif // mozilla_image_DecoderFactory_h