1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
/* -*- 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/. */
#include "nsISupports.idl"
interface nsIChannel;
interface nsIEventTarget;
interface nsIInputStream;
interface nsIURI;
interface imgIContainer;
interface imgILoader;
interface imgICache;
interface imgIScriptedNotificationObserver;
interface imgINotificationObserver;
interface imgIContainerCallback;
webidl Document;
[scriptable, builtinclass, uuid(4c2383a4-931c-484d-8c4a-973590f66e3f)]
interface imgITools : nsISupports
{
/**
* decodeImageFromBuffer
* Caller provides an buffer, a buffer size and a mimetype. We read from
* the stream and decompress it (according to the specified mime type) and
* return the resulting imgIContainer.
*
* @param aBuffer
* Data in memory.
* @param aSize
* Buffer size.
* @param aMimeType
* Type of image in the stream.
*/
imgIContainer decodeImageFromBuffer(in string aBuffer,
in unsigned long aSize,
in ACString aMimeType);
/**
* decodeImageFromArrayBuffer
* Caller provides an ArrayBuffer and a mimetype. We read from
* the stream and decompress it (according to the specified mime type) and
* return the resulting imgIContainer.
*
* @param aArrayBuffer
* An ArrayBuffer.
* @param aMimeType
* Type of image in the stream.
*/
[implicit_jscontext]
imgIContainer decodeImageFromArrayBuffer(in jsval aArrayBuffer,
in ACString aMimeType);
/**
* decodeImageFromChannelAsync
* See decodeImage. The main difference between this method and decodeImage
* is that here the operation is done async on a thread from the decode
* pool. When the operation is completed, the callback is executed with the
* result.
*
* @param aURI
* The original URI of the image
* @param aChannel
* Channel to the image to be decoded.
* @param aCallback
* The callback is executed when the imgContainer is fully created.
* @param aObserver
* Optional observer for the decoded image, the caller should make
* sure the observer is kept alive as long as necessary, as ImageLib
* does not keep a strong reference to the observer.
*/
void decodeImageFromChannelAsync(in nsIURI aURI,
in nsIChannel aChannel,
in imgIContainerCallback aCallback,
in imgINotificationObserver aObserver);
/**
* decodeImageAsync
* See decodeImage. The main difference between this method and decodeImage
* is that here the operation is done async on a thread from the decode
* pool. When the operation is completed, the callback is executed with the
* result.
*
* @param aStream
* An input stream for an encoded image file.
* @param aMimeType
* Type of image in the stream.
* @param aCallback
* The callback is executed when the imgContainer is fully created.
* @param aEventTarget
* This eventTarget is used to execute aCallback
*/
void decodeImageAsync(in nsIInputStream aStream,
in ACString aMimeType,
in imgIContainerCallback aCallback,
in nsIEventTarget aEventTarget);
/**
* encodeImage
* Caller provides an image container, and the mime type it should be
* encoded to. We return an input stream for the encoded image data.
*
* @param aContainer
* An image container.
* @param aMimeType
* Type of encoded image desired (eg "image/png").
* @param outputOptions
* Encoder-specific output options.
*/
nsIInputStream encodeImage(in imgIContainer aContainer,
in ACString aMimeType,
[optional] in AString outputOptions);
/**
* encodeScaledImage
* Caller provides an image container, and the mime type it should be
* encoded to. We return an input stream for the encoded image data.
* The encoded image is scaled to the specified dimensions.
*
* @param aContainer
* An image container.
* @param aMimeType
* Type of encoded image desired (eg "image/png").
* @param aWidth, aHeight
* The size (in pixels) desired for the resulting image. Specify 0 to
* use the given image's width or height. Values must be >= 0.
* @param outputOptions
* Encoder-specific output options.
*/
nsIInputStream encodeScaledImage(in imgIContainer aContainer,
in ACString aMimeType,
in long aWidth,
in long aHeight,
[optional] in AString outputOptions);
/**
* getImgLoaderForDocument
* Retrieve an image loader that reflects the privacy status of the given
* document.
*
* @param doc
* A document. Must not be null.
*/
imgILoader getImgLoaderForDocument(in Document doc);
/**
* getImgLoaderForDocument
* Retrieve an image cache that reflects the privacy status of the given
* document.
*
* @param doc
* A document. Null is allowed, but must _only_ be passed
* when there is no way to obtain a relevant document for
* the current context in which a cache is desired.
*/
imgICache getImgCacheForDocument(in Document doc);
/**
* encodeCroppedImage
* Caller provides an image container, and the mime type it should be
* encoded to. We return an input stream for the encoded image data.
* The encoded image is cropped to the specified dimensions.
*
* The given offset and size must not exceed the image bounds.
*
* @param aContainer
* An image container.
* @param aMimeType
* Type of encoded image desired (eg "image/png").
* @param aOffsetX, aOffsetY
* The crop offset (in pixels). Values must be >= 0.
* @param aWidth, aHeight
* The size (in pixels) desired for the resulting image. Specify 0 to
* use the given image's width or height. Values must be >= 0.
* @param outputOptions
* Encoder-specific output options.
*/
nsIInputStream encodeCroppedImage(in imgIContainer aContainer,
in ACString aMimeType,
in long aOffsetX,
in long aOffsetY,
in long aWidth,
in long aHeight,
[optional] in AString outputOptions);
/**
* Create a wrapper around a scripted notification observer (ordinarily
* imgINotificationObserver cannot be implemented from scripts).
*
* @param aObserver The scripted observer to wrap
*/
imgINotificationObserver
createScriptedObserver(in imgIScriptedNotificationObserver aObserver);
};
/**
* This is a companion interface for nsIAsyncInputStream::asyncWait.
*/
[function, scriptable, uuid(f195772c-a4c0-47ae-80ca-211e001c67be)]
interface imgIContainerCallback : nsISupports
{
/* If the operation fails, aStatus will contain the error value */
void onImageReady(in imgIContainer aImage, in nsresult aStatus);
};
|