Backed out changeset 177eae915693 (bug 1206581) for bustage
[gecko.git] / image / DecoderFactory.h
blobf7a6bfe60c0114d7d11e46345a2f3389c1fa24cc
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"
14 #include "nsCOMPtr.h"
15 #include "SurfaceFlags.h"
17 class nsACString;
19 namespace mozilla {
20 namespace image {
22 class Decoder;
23 class RasterImage;
24 class SourceBuffer;
26 /**
27 * The type of decoder; this is usually determined from a MIME type using
28 * DecoderFactory::GetDecoderType().
30 enum class DecoderType
32 PNG,
33 GIF,
34 JPEG,
35 BMP,
36 ICO,
37 ICON,
38 UNKNOWN
41 class DecoderFactory
43 public:
44 /// @return the type of decoder which is appropriate for @aMimeType.
45 static DecoderType GetDecoderType(const char* aMimeType);
47 /**
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
56 * from.
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
63 * should produce.
64 * @param aSampleSize The sample size requested using #-moz-samplesize (or 0
65 * if none).
67 static already_AddRefed<Decoder>
68 CreateDecoder(DecoderType aType,
69 RasterImage* aImage,
70 SourceBuffer* aSourceBuffer,
71 const Maybe<gfx::IntSize>& aTargetSize,
72 DecoderFlags aDecoderFlags,
73 SurfaceFlags aSurfaceFlags,
74 int aSampleSize);
76 /**
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
84 * from.
85 * @param aDecoderFlags Flags specifying the behavior of this decoder.
86 * @param aSurfaceFlags Flags specifying the type of output this decoder
87 * should produce.
89 static already_AddRefed<Decoder>
90 CreateAnimationDecoder(DecoderType aType,
91 RasterImage* aImage,
92 SourceBuffer* aSourceBuffer,
93 DecoderFlags aDecoderFlags,
94 SurfaceFlags aSurfaceFlags);
96 /**
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
106 * from.
107 * @param aSampleSize The sample size requested using #-moz-samplesize (or 0
108 * if none).
110 static already_AddRefed<Decoder>
111 CreateMetadataDecoder(DecoderType aType,
112 RasterImage* aImage,
113 SourceBuffer* aSourceBuffer,
114 int aSampleSize);
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
122 * from.
123 * @param aSurfaceFlags Flags specifying the type of output this decoder
124 * should produce.
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
139 * from.
141 static already_AddRefed<Decoder>
142 CreateAnonymousMetadataDecoder(DecoderType aType,
143 SourceBuffer* aSourceBuffer);
145 private:
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,
152 RasterImage* aImage,
153 bool aIsRedecode);
156 } // namespace image
157 } // namespace mozilla
159 #endif // mozilla_image_DecoderFactory_h