ImageBitmapUtils.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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/. */
  6. #ifndef mozilla_dom_ImageBitmapUtils_h
  7. #define mozilla_dom_ImageBitmapUtils_h
  8. #include "ImageBitmap.h"
  9. #include "mozilla/UniquePtr.h"
  10. #include "nsTArrayForwardDeclare.h"
  11. namespace mozilla {
  12. namespace layers {
  13. class Image;
  14. struct PlanarYCbCrData;
  15. }
  16. namespace dom {
  17. struct ChannelPixelLayout;
  18. template<typename> class Sequence;
  19. typedef nsTArray<ChannelPixelLayout> ImagePixelLayout;
  20. /*
  21. * This function creates an ImagePixelLayout object which describes the
  22. * default layout of the given ImageBitmapFormat with the given width, height
  23. * and stride.
  24. */
  25. UniquePtr<ImagePixelLayout>
  26. CreateDefaultPixelLayout(ImageBitmapFormat aFormat,
  27. uint32_t aWidth, uint32_t aHeight, uint32_t aStride);
  28. /*
  29. * This function extracts information from the aImage parameter to customize
  30. * the ImagePixelLayout object, that is, this function creates a customized
  31. * ImagePixelLayout object which exactly describes the pixel layout of the
  32. * given aImage.
  33. */
  34. UniquePtr<ImagePixelLayout>
  35. CreatePixelLayoutFromPlanarYCbCrData(const layers::PlanarYCbCrData* aData);
  36. /*
  37. * Get the number of channels of the given ImageBitmapFormat.
  38. */
  39. uint8_t
  40. GetChannelCountOfImageFormat(ImageBitmapFormat aFormat);
  41. /*
  42. * Get the needed buffer size to store the image data in the given
  43. * ImageBitmapFormat with the given width and height.
  44. */
  45. uint32_t
  46. CalculateImageBufferSize(ImageBitmapFormat aFormat,
  47. uint32_t aWidth, uint32_t aHeight);
  48. /*
  49. * This function always copies the image data in _aSrcBuffer_ into _aDstBuffer_
  50. * and it also performs color conversion if the _aSrcFormat_ and the
  51. * _aDstFormat_ are different.
  52. *
  53. * The source image is stored in the _aSrcBuffer_ and the corresponding pixel
  54. * layout is described by the _aSrcLayout_.
  55. *
  56. * The copied and converted image will be stored in the _aDstBuffer_, which
  57. * should be allocated with enough size before invoking this function and the
  58. * needed size could be found by the CalculateImageBufferSize() method.
  59. *
  60. * The returned ImagePixelLayout object describes the pixel layout of the result
  61. * image and will be null if on failure.
  62. */
  63. UniquePtr<ImagePixelLayout>
  64. CopyAndConvertImageData(ImageBitmapFormat aSrcFormat,
  65. const uint8_t* aSrcBuffer,
  66. const ImagePixelLayout* aSrcLayout,
  67. ImageBitmapFormat aDstFormat,
  68. uint8_t* aDstBuffer);
  69. /*
  70. * This function tries to find the best ImageBitmapFormat, from the aCandiates,
  71. * which can be converted from the aSrcFormat. The algorithm now merely returns
  72. * the FIRST one, from the aCandidates, which can be converted from the
  73. * aSrcFormat.
  74. *
  75. * TODO: The algorithm should be updated after we implement optimizations for
  76. * different platforms (different kinds of layers::Image), considering
  77. * that some conversion might be cheaper through hardware.
  78. */
  79. ImageBitmapFormat
  80. FindBestMatchingFromat(ImageBitmapFormat aSrcFormat,
  81. const Sequence<ImageBitmapFormat>& aCandidates);
  82. } // namespace dom
  83. } // namespace mozilla
  84. #endif // mozilla_dom_ImageBitmapUtils_h