ImageUtils.h (1869B)
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 7 #ifndef mozilla_dom_ImageBitmapFormatUtils_h 8 #define mozilla_dom_ImageBitmapFormatUtils_h 9 10 #include <cstdint> 11 12 #include "nsTArrayForwardDeclare.h" 13 14 namespace mozilla { 15 16 template <typename T> 17 class Maybe; 18 19 namespace layers { 20 class Image; 21 } 22 23 class ErrorResult; 24 25 namespace dom { 26 27 struct ChannelPixelLayout; 28 enum class ImageBitmapFormat : uint8_t; 29 30 typedef nsTArray<ChannelPixelLayout> ImagePixelLayout; 31 32 /* 33 * ImageUtils is a wrapper around layers::Image. It provides three unified 34 * methods to all sub-classes of layers::Image, which are: 35 * 36 * (1) GetFormat() converts the image's format into ImageBitmapFormat enum. 37 * (2) GetBufferLength() returns the number of bytes that are used to store 38 * the image's underlying raw data. 39 * 40 * In theory, the functionalities of this class could be merged into the 41 * interface of layers::Image. However, this is designed as a isolated wrapper 42 * because we don't want to pollute the layers::Image's interface with methods 43 * that are only meaningful to the ImageBitmap. 44 */ 45 class ImageUtils { 46 public: 47 class Impl; 48 ImageUtils() = delete; 49 ImageUtils(const ImageUtils&) = delete; 50 ImageUtils(ImageUtils&&) = delete; 51 ImageUtils& operator=(const ImageUtils&) = delete; 52 ImageUtils& operator=(ImageUtils&&) = delete; 53 54 explicit ImageUtils(layers::Image* aImage); 55 ~ImageUtils(); 56 57 Maybe<ImageBitmapFormat> GetFormat() const; 58 59 uint32_t GetBufferLength() const; 60 61 protected: 62 Impl* mImpl; 63 }; 64 65 } // namespace dom 66 } // namespace mozilla 67 68 #endif /* mozilla_dom_ImageBitmapFormatUtils_h */