content/canvas/src/ImageEncoder.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial