michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef ImageEncoder_h michael@0: #define ImageEncoder_h michael@0: michael@0: #include "imgIEncoder.h" michael@0: #include "nsDOMFile.h" michael@0: #include "nsError.h" michael@0: #include "mozilla/dom/HTMLCanvasElementBinding.h" michael@0: #include "nsLayoutUtils.h" michael@0: #include "nsNetUtil.h" michael@0: #include "nsSize.h" michael@0: michael@0: class nsICanvasRenderingContextInternal; michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: class EncodingRunnable; michael@0: michael@0: class ImageEncoder michael@0: { michael@0: public: michael@0: // Extracts data synchronously and gives you a stream containing the image michael@0: // represented by aContext. aType may change to "image/png" if we had to fall michael@0: // back to a PNG encoder. A return value of NS_OK implies successful data michael@0: // extraction. If there are any unrecognized custom parse options in michael@0: // aOptions, NS_ERROR_INVALID_ARG will be returned. When encountering this michael@0: // error it is usual to call this function again without any options at all. michael@0: static nsresult ExtractData(nsAString& aType, michael@0: const nsAString& aOptions, michael@0: const nsIntSize aSize, michael@0: bool aUsePlaceholder, michael@0: nsICanvasRenderingContextInternal* aContext, michael@0: nsIInputStream** aStream); michael@0: michael@0: // Extracts data asynchronously. aType may change to "image/png" if we had to michael@0: // fall back to a PNG encoder. aOptions are the options to be passed to the michael@0: // encoder and aUsingCustomOptions specifies whether custom parse options were michael@0: // used (i.e. by using -moz-parse-options). If there are any unrecognized michael@0: // custom parse options, we fall back to the default values for the encoder michael@0: // without any options at all. A return value of NS_OK only implies michael@0: // successful dispatching of the extraction step to the encoding thread. michael@0: static nsresult ExtractDataAsync(nsAString& aType, michael@0: const nsAString& aOptions, michael@0: bool aUsingCustomOptions, michael@0: uint8_t* aImageBuffer, michael@0: int32_t aFormat, michael@0: const nsIntSize aSize, michael@0: bool aUsePlaceholder, michael@0: nsICanvasRenderingContextInternal* aContext, michael@0: nsIScriptContext* aScriptContext, michael@0: FileCallback& aCallback); michael@0: michael@0: // Gives you a stream containing the image represented by aImageBuffer. michael@0: // The format is given in aFormat, for example michael@0: // imgIEncoder::INPUT_FORMAT_HOSTARGB. michael@0: static nsresult GetInputStream(int32_t aWidth, michael@0: int32_t aHeight, michael@0: uint8_t* aImageBuffer, michael@0: int32_t aFormat, michael@0: imgIEncoder* aEncoder, michael@0: const char16_t* aEncoderOptions, michael@0: nsIInputStream** aStream); michael@0: michael@0: private: michael@0: // When called asynchronously, aContext is null. michael@0: static nsresult michael@0: ExtractDataInternal(const nsAString& aType, michael@0: const nsAString& aOptions, michael@0: uint8_t* aImageBuffer, michael@0: int32_t aFormat, michael@0: const nsIntSize aSize, michael@0: bool aUsePlaceholder, michael@0: nsICanvasRenderingContextInternal* aContext, michael@0: nsIInputStream** aStream, michael@0: imgIEncoder* aEncoder); michael@0: michael@0: // Creates and returns an encoder instance of the type specified in aType. michael@0: // aType may change to "image/png" if no instance of the original type could michael@0: // be created and we had to fall back to a PNG encoder. A null return value michael@0: // should be interpreted as NS_IMAGELIB_ERROR_NO_ENCODER and aType is michael@0: // undefined in this case. michael@0: static already_AddRefed GetImageEncoder(nsAString& aType); michael@0: michael@0: friend class EncodingRunnable; michael@0: }; michael@0: michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: #endif // ImageEncoder_h