1 #ifndef DALI_TOOLKIT_IMAGE_ATLAS_MANAGER_H
2 #define DALI_TOOLKIT_IMAGE_ATLAS_MANAGER_H
5 * Copyright (c) 2021 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/common/vector-wrapper.h>
22 #include <dali/public-api/object/ref-object.h>
23 #include <dali/public-api/rendering/texture-set.h>
27 #include <dali-toolkit/devel-api/image-loader/image-atlas.h>
28 #include <dali-toolkit/internal/visuals/visual-url.h>
34 class AtlasUploadObserver;
39 * The manager for automatic image atlasing. Owned by VisualFactory
41 class ImageAtlasManager : public RefObject
44 typedef std::vector<Toolkit::ImageAtlas> AtlasContainer;
45 typedef std::vector<TextureSet> TextureSetContainer;
55 * @brief Add an image to the atlas.
57 * @note To make the atlasing efficient, an valid size should be provided.
58 * If size is not provided, then the image file will be opened to read the actual size for loading.
60 * SamplingMode::BOX_THEN_LINEAR is used to sampling pixels from the input image while fitting it to desired size.
62 * @param [out] textureRect The texture area of the resource image in the atlas.
63 * @param [in] url The URL of the resource image file to use.
64 * @param [in, out] size The width and height to fit the loaded image to.
65 * @param [in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter.
66 * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
67 * @param [in] atlasUploadObserver The object to observe the uploading state inside ImageAtlas.
68 * @return The texture set containing the image.
70 TextureSet Add(Vector4& textureRect,
72 ImageDimensions& size,
73 FittingMode::Type fittingMode = FittingMode::DEFAULT,
74 bool orientationCorrection = true,
75 AtlasUploadObserver* atlasUploadObserver = NULL);
77 * @brief Add a pixel buffer to the atlas
79 * @param [out] textureRect The texture area of the resource image in the atlas.
80 * @param [in] pixelData The pixel data.
81 * @return The texture set containing the image.
83 TextureSet Add(Vector4& textureRect,
87 * Remove the image at the given rectangle from the texture set.
89 * @param [in] textureSet The texture set containing the atlas image.
90 * @param [in] textureRect The texture area to be removed.
92 void Remove(TextureSet textureSet, const Vector4& textureRect);
95 * @brief Set the broken image which is used to replace the image if loading fails.
97 * @param[in] brokenImageUrl The url of the broken image.
99 void SetBrokenImage(const std::string& brokenImageUrl);
104 Shader GetShader() const;
108 * @brief Create a new atlas.
110 * This method is called when the newly added image or pixel buffer cannot fit into the current atlas list.
112 void CreateNewAtlas();
118 ~ImageAtlasManager() override;
121 * Undefined copy constructor.
123 ImageAtlasManager(const ImageAtlasManager&);
126 * Undefined assignment operator.
128 ImageAtlasManager& operator=(const ImageAtlasManager& rhs);
131 AtlasContainer mAtlasList;
132 TextureSetContainer mTextureSetList;
133 std::string mBrokenImageUrl;
136 } // namespace Internal
138 } // namespace Toolkit
142 #endif // DALI_TOOLKIT_ATLAS_MANAGER_H