content/canvas/src/ImageEncoder.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/canvas/src/ImageEncoder.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,95 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef ImageEncoder_h
    1.10 +#define ImageEncoder_h
    1.11 +
    1.12 +#include "imgIEncoder.h"
    1.13 +#include "nsDOMFile.h"
    1.14 +#include "nsError.h"
    1.15 +#include "mozilla/dom/HTMLCanvasElementBinding.h"
    1.16 +#include "nsLayoutUtils.h"
    1.17 +#include "nsNetUtil.h"
    1.18 +#include "nsSize.h"
    1.19 +
    1.20 +class nsICanvasRenderingContextInternal;
    1.21 +
    1.22 +namespace mozilla {
    1.23 +namespace dom {
    1.24 +
    1.25 +class EncodingRunnable;
    1.26 +
    1.27 +class ImageEncoder
    1.28 +{
    1.29 +public:
    1.30 +  // Extracts data synchronously and gives you a stream containing the image
    1.31 +  // represented by aContext. aType may change to "image/png" if we had to fall
    1.32 +  // back to a PNG encoder. A return value of NS_OK implies successful data
    1.33 +  // extraction. If there are any unrecognized custom parse options in
    1.34 +  // aOptions, NS_ERROR_INVALID_ARG will be returned. When encountering this
    1.35 +  // error it is usual to call this function again without any options at all.
    1.36 +  static nsresult ExtractData(nsAString& aType,
    1.37 +                              const nsAString& aOptions,
    1.38 +                              const nsIntSize aSize,
    1.39 +                              bool aUsePlaceholder,
    1.40 +                              nsICanvasRenderingContextInternal* aContext,
    1.41 +                              nsIInputStream** aStream);
    1.42 +
    1.43 +  // Extracts data asynchronously. aType may change to "image/png" if we had to
    1.44 +  // fall back to a PNG encoder. aOptions are the options to be passed to the
    1.45 +  // encoder and aUsingCustomOptions specifies whether custom parse options were
    1.46 +  // used (i.e. by using -moz-parse-options). If there are any unrecognized
    1.47 +  // custom parse options, we fall back to the default values for the encoder
    1.48 +  // without any options at all. A return value of NS_OK only implies
    1.49 +  // successful dispatching of the extraction step to the encoding thread.
    1.50 +  static nsresult ExtractDataAsync(nsAString& aType,
    1.51 +                                   const nsAString& aOptions,
    1.52 +                                   bool aUsingCustomOptions,
    1.53 +                                   uint8_t* aImageBuffer,
    1.54 +                                   int32_t aFormat,
    1.55 +                                   const nsIntSize aSize,
    1.56 +                                   bool aUsePlaceholder,
    1.57 +                                   nsICanvasRenderingContextInternal* aContext,
    1.58 +                                   nsIScriptContext* aScriptContext,
    1.59 +                                   FileCallback& aCallback);
    1.60 +
    1.61 +  // Gives you a stream containing the image represented by aImageBuffer.
    1.62 +  // The format is given in aFormat, for example
    1.63 +  // imgIEncoder::INPUT_FORMAT_HOSTARGB.
    1.64 +  static nsresult GetInputStream(int32_t aWidth,
    1.65 +                                 int32_t aHeight,
    1.66 +                                 uint8_t* aImageBuffer,
    1.67 +                                 int32_t aFormat,
    1.68 +                                 imgIEncoder* aEncoder,
    1.69 +                                 const char16_t* aEncoderOptions,
    1.70 +                                 nsIInputStream** aStream);
    1.71 +
    1.72 +private:
    1.73 +  // When called asynchronously, aContext is null.
    1.74 +  static nsresult
    1.75 +  ExtractDataInternal(const nsAString& aType,
    1.76 +                      const nsAString& aOptions,
    1.77 +                      uint8_t* aImageBuffer,
    1.78 +                      int32_t aFormat,
    1.79 +                      const nsIntSize aSize,
    1.80 +                      bool aUsePlaceholder,
    1.81 +                      nsICanvasRenderingContextInternal* aContext,
    1.82 +                      nsIInputStream** aStream,
    1.83 +                      imgIEncoder* aEncoder);
    1.84 +
    1.85 +  // Creates and returns an encoder instance of the type specified in aType.
    1.86 +  // aType may change to "image/png" if no instance of the original type could
    1.87 +  // be created and we had to fall back to a PNG encoder. A null return value
    1.88 +  // should be interpreted as NS_IMAGELIB_ERROR_NO_ENCODER and aType is
    1.89 +  // undefined in this case.
    1.90 +  static already_AddRefed<imgIEncoder> GetImageEncoder(nsAString& aType);
    1.91 +
    1.92 +  friend class EncodingRunnable;
    1.93 +};
    1.94 +
    1.95 +} // namespace dom
    1.96 +} // namespace mozilla
    1.97 +
    1.98 +#endif // ImageEncoder_h

mercurial