1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
9 #include "imgIEncoder.h"
10 #include "nsDOMFile.h"
12 #include "mozilla/dom/HTMLCanvasElementBinding.h"
13 #include "nsLayoutUtils.h"
14 #include "nsNetUtil.h"
17 class nsICanvasRenderingContextInternal
;
22 class EncodingRunnable
;
27 // Extracts data synchronously and gives you a stream containing the image
28 // represented by aContext. aType may change to "image/png" if we had to fall
29 // back to a PNG encoder. A return value of NS_OK implies successful data
30 // extraction. If there are any unrecognized custom parse options in
31 // aOptions, NS_ERROR_INVALID_ARG will be returned. When encountering this
32 // error it is usual to call this function again without any options at all.
33 static nsresult
ExtractData(nsAString
& aType
,
34 const nsAString
& aOptions
,
35 const nsIntSize aSize
,
36 nsICanvasRenderingContextInternal
* aContext
,
37 nsIInputStream
** aStream
);
39 // Extracts data asynchronously. aType may change to "image/png" if we had to
40 // fall back to a PNG encoder. aOptions are the options to be passed to the
41 // encoder and aUsingCustomOptions specifies whether custom parse options were
42 // used (i.e. by using -moz-parse-options). If there are any unrecognized
43 // custom parse options, we fall back to the default values for the encoder
44 // without any options at all. A return value of NS_OK only implies
45 // successful dispatching of the extraction step to the encoding thread.
46 static nsresult
ExtractDataAsync(nsAString
& aType
,
47 const nsAString
& aOptions
,
48 bool aUsingCustomOptions
,
49 uint8_t* aImageBuffer
,
51 const nsIntSize aSize
,
52 nsICanvasRenderingContextInternal
* aContext
,
53 nsIScriptContext
* aScriptContext
,
54 FileCallback
& aCallback
);
56 // Gives you a stream containing the image represented by aImageBuffer.
57 // The format is given in aFormat, for example
58 // imgIEncoder::INPUT_FORMAT_HOSTARGB.
59 static nsresult
GetInputStream(int32_t aWidth
,
61 uint8_t* aImageBuffer
,
63 imgIEncoder
* aEncoder
,
64 const PRUnichar
* aEncoderOptions
,
65 nsIInputStream
** aStream
);
68 // When called asynchronously, aContext is null.
70 ExtractDataInternal(const nsAString
& aType
,
71 const nsAString
& aOptions
,
72 uint8_t* aImageBuffer
,
74 const nsIntSize aSize
,
75 nsICanvasRenderingContextInternal
* aContext
,
76 nsIInputStream
** aStream
,
77 imgIEncoder
* aEncoder
);
79 // Creates and returns an encoder instance of the type specified in aType.
80 // aType may change to "image/png" if no instance of the original type could
81 // be created and we had to fall back to a PNG encoder. A null return value
82 // should be interpreted as NS_IMAGELIB_ERROR_NO_ENCODER and aType is
83 // undefined in this case.
84 static already_AddRefed
<imgIEncoder
> GetImageEncoder(nsAString
& aType
);
86 friend class EncodingRunnable
;
90 } // namespace mozilla
92 #endif // ImageEncoder_h