1 #ifndef DALI_TOOLKIT_IMAGE_ATLAS_MANAGER_H
2 #define DALI_TOOLKIT_IMAGE_ATLAS_MANAGER_H
5 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 #include <dali/public-api/adaptor-framework/encoded-image-buffer.h>
22 #include <dali/public-api/common/vector-wrapper.h>
23 #include <dali/public-api/object/ref-object.h>
24 #include <dali/public-api/rendering/texture-set.h>
28 #include <dali-toolkit/devel-api/image-loader/image-atlas.h>
29 #include <dali-toolkit/internal/visuals/visual-url.h>
35 class AtlasUploadObserver;
40 * The manager for automatic image atlasing. Owned by VisualFactory
42 class ImageAtlasManager : public RefObject
45 typedef std::vector<Toolkit::ImageAtlas> AtlasContainer;
46 typedef std::vector<TextureSet> TextureSetContainer;
56 * @brief Check whether the image of url could be Atlas or not.
58 * @param [in] url The URL of the resource image file to use.
59 * @param [in] size The width and height to fit the loaded image to.
60 * @return True if the image could be Atlas.
62 bool CheckAtlasAvailable(const VisualUrl& url, const ImageDimensions& size) const;
65 * @brief Add an image to the atlas.
67 * @note To make the atlasing efficient, an valid size should be provided.
68 * If size is not provided, then the image file will be opened to read the actual size for loading.
70 * SamplingMode::BOX_THEN_LINEAR is used to sampling pixels from the input image while fitting it to desired size.
72 * @param [out] textureRect The texture area of the resource image in the atlas.
73 * @param [in] url The URL of the resource image file to use.
74 * @param [in, out] size The width and height to fit the loaded image to.
75 * @param [in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter.
76 * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
77 * @param [in] atlasUploadObserver The object to observe the uploading state inside ImageAtlas.
78 * @return The texture set containing the image.
80 TextureSet Add(Vector4& textureRect,
82 ImageDimensions& size,
83 FittingMode::Type fittingMode = FittingMode::DEFAULT,
84 bool orientationCorrection = true,
85 AtlasUploadObserver* atlasUploadObserver = NULL);
88 * @brief Add an image to the atlas.
90 * @note To make the atlasing efficient, an valid size should be provided.
92 * SamplingMode::BOX_THEN_LINEAR is used to sampling pixels from the input image while fitting it to desired size.
94 * @param [out] textureRect The texture area of the resource image in the atlas.
95 * @param [in] encodedImageBuffer The encoded buffer of the resource image file to use.
96 * @param [in] size The width and height to fit the loaded image to.
97 * @param [in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter.
98 * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
99 * @param [in] atlasUploadObserver The object to observe the uploading state inside ImageAtlas.
100 * @return The texture set containing the image.
102 TextureSet Add(Vector4& textureRect,
103 const EncodedImageBuffer& encodedImageBuffer,
104 const ImageDimensions& size,
105 FittingMode::Type fittingMode = FittingMode::DEFAULT,
106 bool orientationCorrection = true,
107 AtlasUploadObserver* atlasUploadObserver = NULL);
110 * @brief Add a pixel buffer to the atlas
112 * @param [out] textureRect The texture area of the resource image in the atlas.
113 * @param [in] pixelData The pixel data.
114 * @return The texture set containing the image.
116 TextureSet Add(Vector4& textureRect,
117 PixelData pixelData);
120 * Remove the image at the given rectangle from the texture set.
122 * @param [in] textureSet The texture set containing the atlas image.
123 * @param [in] textureRect The texture area to be removed.
125 void Remove(TextureSet textureSet, const Vector4& textureRect);
128 * @brief Set the broken image which is used to replace the image if loading fails.
130 * @param[in] brokenImageUrl The url of the broken image.
132 void SetBrokenImage(const std::string& brokenImageUrl);
137 Shader GetShader() const;
141 * @brief Create a new atlas.
143 * This method is called when the newly added image or pixel buffer cannot fit into the current atlas list.
145 void CreateNewAtlas();
151 ~ImageAtlasManager() override;
154 * Undefined copy constructor.
156 ImageAtlasManager(const ImageAtlasManager&);
159 * Undefined assignment operator.
161 ImageAtlasManager& operator=(const ImageAtlasManager& rhs);
164 AtlasContainer mAtlasList;
165 TextureSetContainer mTextureSetList;
166 std::string mBrokenImageUrl;
169 } // namespace Internal
171 } // namespace Toolkit
175 #endif // DALI_TOOLKIT_ATLAS_MANAGER_H