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
;
18 class nsIGlobalObject
;
23 class EncodingRunnable
;
28 // Extracts data synchronously and gives you a stream containing the image
29 // represented by aContext. aType may change to "image/png" if we had to fall
30 // back to a PNG encoder. A return value of NS_OK implies successful data
31 // extraction. If there are any unrecognized custom parse options in
32 // aOptions, NS_ERROR_INVALID_ARG will be returned. When encountering this
33 // error it is usual to call this function again without any options at all.
34 static nsresult
ExtractData(nsAString
& aType
,
35 const nsAString
& aOptions
,
36 const nsIntSize aSize
,
37 nsICanvasRenderingContextInternal
* aContext
,
38 nsIInputStream
** aStream
);
40 // Extracts data asynchronously. aType may change to "image/png" if we had to
41 // fall back to a PNG encoder. aOptions are the options to be passed to the
42 // encoder and aUsingCustomOptions specifies whether custom parse options were
43 // used (i.e. by using -moz-parse-options). If there are any unrecognized
44 // custom parse options, we fall back to the default values for the encoder
45 // without any options at all. A return value of NS_OK only implies
46 // successful dispatching of the extraction step to the encoding thread.
47 static nsresult
ExtractDataAsync(nsAString
& aType
,
48 const nsAString
& aOptions
,
49 bool aUsingCustomOptions
,
50 uint8_t* aImageBuffer
,
52 const nsIntSize aSize
,
53 nsICanvasRenderingContextInternal
* aContext
,
54 nsIGlobalObject
* aGlobal
,
55 FileCallback
& aCallback
);
57 // Gives you a stream containing the image represented by aImageBuffer.
58 // The format is given in aFormat, for example
59 // imgIEncoder::INPUT_FORMAT_HOSTARGB.
60 static nsresult
GetInputStream(int32_t aWidth
,
62 uint8_t* aImageBuffer
,
64 imgIEncoder
* aEncoder
,
65 const char16_t
* aEncoderOptions
,
66 nsIInputStream
** aStream
);
69 // When called asynchronously, aContext is null.
71 ExtractDataInternal(const nsAString
& aType
,
72 const nsAString
& aOptions
,
73 uint8_t* aImageBuffer
,
75 const nsIntSize aSize
,
76 nsICanvasRenderingContextInternal
* aContext
,
77 nsIInputStream
** aStream
,
78 imgIEncoder
* aEncoder
);
80 // Creates and returns an encoder instance of the type specified in aType.
81 // aType may change to "image/png" if no instance of the original type could
82 // be created and we had to fall back to a PNG encoder. A null return value
83 // should be interpreted as NS_IMAGELIB_ERROR_NO_ENCODER and aType is
84 // undefined in this case.
85 static already_AddRefed
<imgIEncoder
> GetImageEncoder(nsAString
& aType
);
87 friend class EncodingRunnable
;
91 } // namespace mozilla
93 #endif // ImageEncoder_h