Bug 1521243 - Show a warning for invalid declarations and filter icon for overridden...
[gecko.git] / dom / canvas / ImageBitmapUtils.h
blobafbe36fed52157902df14712c45216e72fb7f5a8
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_ImageBitmapUtils_h
8 #define mozilla_dom_ImageBitmapUtils_h
10 #include "mozilla/UniquePtr.h"
11 #include "nsTArrayForwardDeclare.h"
13 namespace mozilla {
15 namespace layers {
16 class Image;
17 struct PlanarYCbCrData;
18 } // namespace layers
20 namespace dom {
22 struct ChannelPixelLayout;
23 template <typename>
24 class Sequence;
26 typedef nsTArray<ChannelPixelLayout> ImagePixelLayout;
29 * This function creates an ImagePixelLayout object which describes the
30 * default layout of the given ImageBitmapFormat with the given width, height
31 * and stride.
33 UniquePtr<ImagePixelLayout> CreateDefaultPixelLayout(ImageBitmapFormat aFormat,
34 uint32_t aWidth,
35 uint32_t aHeight,
36 uint32_t aStride);
39 * This function extracts information from the aImage parameter to customize
40 * the ImagePixelLayout object, that is, this function creates a customized
41 * ImagePixelLayout object which exactly describes the pixel layout of the
42 * given aImage.
44 UniquePtr<ImagePixelLayout> CreatePixelLayoutFromPlanarYCbCrData(
45 const layers::PlanarYCbCrData* aData);
48 * Get the number of channels of the given ImageBitmapFormat.
50 uint8_t GetChannelCountOfImageFormat(ImageBitmapFormat aFormat);
53 * This function always copies the image data in _aSrcBuffer_ into _aDstBuffer_
54 * and it also performs color conversion if the _aSrcFormat_ and the
55 * _aDstFormat_ are different.
57 * The source image is stored in the _aSrcBuffer_ and the corresponding pixel
58 * layout is described by the _aSrcLayout_.
60 * The copied and converted image will be stored in the _aDstBuffer_, which
61 * should be allocated with enough size before invoking this function and the
62 * needed size could be found by the CalculateImageBufferSize() method.
64 * The returned ImagePixelLayout object describes the pixel layout of the result
65 * image and will be null if on failure.
67 UniquePtr<ImagePixelLayout> CopyAndConvertImageData(
68 ImageBitmapFormat aSrcFormat, const uint8_t* aSrcBuffer,
69 const ImagePixelLayout* aSrcLayout, ImageBitmapFormat aDstFormat,
70 uint8_t* aDstBuffer);
73 * This function tries to find the best ImageBitmapFormat, from the aCandiates,
74 * which can be converted from the aSrcFormat. The algorithm now merely returns
75 * the FIRST one, from the aCandidates, which can be converted from the
76 * aSrcFormat.
78 * TODO: The algorithm should be updated after we implement optimizations for
79 * different platforms (different kinds of layers::Image), considering
80 * that some conversion might be cheaper through hardware.
82 ImageBitmapFormat FindBestMatchingFromat(
83 ImageBitmapFormat aSrcFormat,
84 const Sequence<ImageBitmapFormat>& aCandidates);
86 } // namespace dom
87 } // namespace mozilla
89 #endif // mozilla_dom_ImageBitmapUtils_h