content/canvas/src/ImageEncoder.h

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

     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/. */
     6 #ifndef ImageEncoder_h
     7 #define ImageEncoder_h
     9 #include "imgIEncoder.h"
    10 #include "nsDOMFile.h"
    11 #include "nsError.h"
    12 #include "mozilla/dom/HTMLCanvasElementBinding.h"
    13 #include "nsLayoutUtils.h"
    14 #include "nsNetUtil.h"
    15 #include "nsSize.h"
    17 class nsICanvasRenderingContextInternal;
    19 namespace mozilla {
    20 namespace dom {
    22 class EncodingRunnable;
    24 class ImageEncoder
    25 {
    26 public:
    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                               bool aUsePlaceholder,
    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,
    51                                    int32_t aFormat,
    52                                    const nsIntSize aSize,
    53                                    bool aUsePlaceholder,
    54                                    nsICanvasRenderingContextInternal* aContext,
    55                                    nsIScriptContext* aScriptContext,
    56                                    FileCallback& aCallback);
    58   // Gives you a stream containing the image represented by aImageBuffer.
    59   // The format is given in aFormat, for example
    60   // imgIEncoder::INPUT_FORMAT_HOSTARGB.
    61   static nsresult GetInputStream(int32_t aWidth,
    62                                  int32_t aHeight,
    63                                  uint8_t* aImageBuffer,
    64                                  int32_t aFormat,
    65                                  imgIEncoder* aEncoder,
    66                                  const char16_t* aEncoderOptions,
    67                                  nsIInputStream** aStream);
    69 private:
    70   // When called asynchronously, aContext is null.
    71   static nsresult
    72   ExtractDataInternal(const nsAString& aType,
    73                       const nsAString& aOptions,
    74                       uint8_t* aImageBuffer,
    75                       int32_t aFormat,
    76                       const nsIntSize aSize,
    77                       bool aUsePlaceholder,
    78                       nsICanvasRenderingContextInternal* aContext,
    79                       nsIInputStream** aStream,
    80                       imgIEncoder* aEncoder);
    82   // Creates and returns an encoder instance of the type specified in aType.
    83   // aType may change to "image/png" if no instance of the original type could
    84   // be created and we had to fall back to a PNG encoder. A null return value
    85   // should be interpreted as NS_IMAGELIB_ERROR_NO_ENCODER and aType is
    86   // undefined in this case.
    87   static already_AddRefed<imgIEncoder> GetImageEncoder(nsAString& aType);
    89   friend class EncodingRunnable;
    90 };
    92 } // namespace dom
    93 } // namespace mozilla
    95 #endif // ImageEncoder_h

mercurial