1 /*
2 * Copyright (C) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #ifndef API_CORE_IMAGE_IIMAGE_CONTAINER_H
17 #define API_CORE_IMAGE_IIMAGE_CONTAINER_H
18
19 #include <cstdint>
20
21 #include <base/containers/array_view.h>
22 #include <base/containers/unique_ptr.h>
23 #include <base/util/formats.h>
24 #include <core/namespace.h>
25
CORE_BEGIN_NAMESPACE()26 CORE_BEGIN_NAMESPACE()
27 /** \addtogroup group_image_iimagecontainer
28 * @{
29 */
30
31 /**
32 * An interface that is used to represent a collection of bitmap image data.
33 *
34 * The container can be:
35 * - a single 1D/2D/3D bitmap image (e.g. loaded from a png file)
36 * - an array of 1D/2D images
37 * - a cube map
38 * - an array of cube maps
39 *
40 * All of the above possibly containing mipmaps.
41 */
42 class IImageContainer {
43 public:
44 /** Image flags */
45 enum ImageFlags : uint32_t {
46 /** Bit for cubemap */
47 FLAGS_CUBEMAP_BIT = 0x00000001,
48 /** Bit for packed */
49 FLAGS_PACKED_BIT = 0x00000002,
50 /** Bit for compressed */
51 FLAGS_COMPRESSED_BIT = 0x00000004,
52 /** Bit for request mipmaps */
53 FLAGS_REQUESTING_MIPMAPS_BIT = 0x00000008,
54 /** Image color data has been premultiplied with the alpha value */
55 FLAGS_PREMULTIPLIED_ALPHA_BIT = 0x00000010,
56 /** Image is animated */
57 FLAGS_ANIMATED_BIT = 0x00000020,
58 };
59
60 /** Image type */
61 enum ImageType : uint32_t {
62 /** 1D */
63 TYPE_1D = 0,
64 /** 2D */
65 TYPE_2D = 1,
66 /** 3D */
67 TYPE_3D = 2,
68 /** Max enumeration */
69 TYPE_MAX_ENUM = 0x7FFFFFFF
70 };
71
72 /** Image view type */
73 enum ImageViewType : uint32_t {
74 /** 1D */
75 VIEW_TYPE_1D = 0,
76 /** 2D */
77 VIEW_TYPE_2D = 1,
78 /** 3D */
79 VIEW_TYPE_3D = 2,
80 /** Cube */
81 VIEW_TYPE_CUBE = 3,
82 /** 1D array */
83 VIEW_TYPE_1D_ARRAY = 4,
84 /** 2D array */
85 VIEW_TYPE_2D_ARRAY = 5,
86 /** Cube array */
87 VIEW_TYPE_CUBE_ARRAY = 6,
88 /** Max enumeration */
89 VIEW_TYPE_MAX_ENUM = 0x7FFFFFFF
90 };
91
92 /** Image descriptor */
93 struct ImageDesc {
94 /** Flags for image descriptor */
95 uint32_t imageFlags { 0 };
96
97 /** Pixel width of block */
98 uint32_t blockPixelWidth { 0 };
99 /** Pixel height of block */
100 uint32_t blockPixelHeight { 0 };
101 /** Pixel depth of block */
102 uint32_t blockPixelDepth { 0 };
103 /** Bits per block */
104 uint32_t bitsPerBlock { 0 };
105
106 /** Image type */
107 ImageType imageType { ImageType::TYPE_MAX_ENUM };
108 /** Image view type */
109 ImageViewType imageViewType { ImageViewType::VIEW_TYPE_MAX_ENUM };
110 /** Format */
111 BASE_NS::Format format { BASE_NS::Format::BASE_FORMAT_UNDEFINED };
112
113 /** Width */
114 uint32_t width { 0 };
115 /** Height */
116 uint32_t height { 0 };
117 /** Depth */
118 uint32_t depth { 0 };
119
120 /** Mip count */
121 uint32_t mipCount { 1 };
122 /** Layer count */
123 uint32_t layerCount { 1 };
124 };
125
126 /** Descriptor for each subimage (mip level, cube face etc.) */
127 struct SubImageDesc {
128 /** Buffer offset */
129 uint32_t bufferOffset { 0 };
130 /** Buffer row length */
131 uint32_t bufferRowLength { 0 };
132 /** Buffer image height */
133 uint32_t bufferImageHeight { 0 };
134 /** Mip level */
135 uint32_t mipLevel { 0 };
136 /** Layer count */
137 uint32_t layerCount { 0 };
138 /** Width */
139 uint32_t width { 0 };
140 /** Height */
141 uint32_t height { 0 };
142 /** Depth */
143 uint32_t depth { 0 };
144 };
145
146 /** Preventing copy construction and assign. */
147 IImageContainer(IImageContainer const&) = delete;
148 IImageContainer& operator=(IImageContainer const&) = delete;
149
150 /** Return descriptor containing information about this image. */
151 virtual const ImageDesc& GetImageDesc() const = 0;
152
153 /** Return The data buffer that holds the data for all of the image elements of this container. */
154 virtual BASE_NS::array_view<const uint8_t> GetData() const = 0;
155
156 /** Return Array containing a SubImageDesc for each subimage (mipmap level, cubemap face etc.). */
157 virtual BASE_NS::array_view<const SubImageDesc> GetBufferImageCopies() const = 0;
158
159 struct Deleter {
160 constexpr Deleter() noexcept = default;
161 void operator()(IImageContainer* ptr) const
162 {
163 ptr->Destroy();
164 }
165 };
166 using Ptr = BASE_NS::unique_ptr<IImageContainer, Deleter>;
167
168 protected:
169 IImageContainer() = default;
170 virtual ~IImageContainer() = default;
171 virtual void Destroy() = 0;
172 };
173 /** @} */
174 CORE_END_NAMESPACE()
175
176 #endif // API_CORE_IMAGE_IIMAGE_CONTAINER_H
177