Merge "Dali-Text: Keyboard Shortcuts" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / image-loader / image-atlas.h
index c85194f..af3cc41 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef DALI_TOOLKIT_IMAGE_ATLAS_H
 #define DALI_TOOLKIT_IMAGE_ATLAS_H
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  */
 
 // EXTERNAL INCLUDES
-#include <string>
-#include <stdint.h>
-#include <dali/public-api/object/base-handle.h>
+#include <dali/public-api/common/vector-wrapper.h>
 #include <dali/public-api/images/image-operations.h>
-#include <dali/public-api/images/pixel.h>
 #include <dali/public-api/images/pixel-data.h>
+#include <dali/public-api/images/pixel.h>
+#include <dali/public-api/object/base-handle.h>
 #include <dali/public-api/rendering/texture.h>
+#include <stdint.h>
+#include <string>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/devel-api/image-loader/atlas-upload-observer.h>
 
 namespace Dali
 {
-
 namespace Toolkit
 {
 namespace Internal DALI_INTERNAL
@@ -42,13 +45,19 @@ class ImageAtlas;
  * Only images with url provided or pixel data are supported for uploading.
  * The images are loaded by a worker thread to avoid blocking the main event thread.
  */
-class DALI_IMPORT_API ImageAtlas : public BaseHandle
+class DALI_TOOLKIT_API ImageAtlas : public BaseHandle
 {
 public:
-
   typedef uint32_t SizeType;
 
 public:
+  /**
+   * @brief Pack a group of  pixel data into atlas.
+   * @param[in] pixelData The group of the pixel data to be packed into the atlas.
+   * @param[out] textureRects The list of texture areas where each frame is located inside the atlas.
+   * @return The atlas texture.
+   */
+  static Texture PackToAtlas(const std::vector<PixelData>& pixelData, Dali::Vector<Vector4>& textureRects);
 
   /**
    * @brief Create a new ImageAtlas.
@@ -58,8 +67,7 @@ public:
    * @param [in] pixelFormat    The pixel format (rgba 32 bit by default).
    * @return A handle to a new ImageAtlas.
    */
-  static ImageAtlas New( SizeType width, SizeType height,
-                         Pixel::Format pixelFormat = Pixel::RGBA8888 );
+  static ImageAtlas New(SizeType width, SizeType height, Pixel::Format pixelFormat = Pixel::RGBA8888);
 
   /**
    * @brief Create an empty handle.
@@ -78,7 +86,7 @@ public:
    *
    * @param [in] handle A reference to the copied handle
    */
-  ImageAtlas( const ImageAtlas& handle );
+  ImageAtlas(const ImageAtlas& handle);
 
   /**
    * @brief This assignment operator is required for (smart) pointer semantics.
@@ -86,7 +94,7 @@ public:
    * @param [in] handle  A reference to the copied handle
    * @return A reference to this
    */
-  ImageAtlas& operator=( const ImageAtlas& handle );
+  ImageAtlas& operator=(const ImageAtlas& handle);
 
   /**
    * @brief Get the atlas image.
@@ -109,12 +117,12 @@ public:
    *
    * @param[in] brokenImageUrl The url of the broken image.
    */
-  void SetBrokenImage( const std::string& brokenImageUrl );
+  void SetBrokenImage(const std::string& brokenImageUrl);
 
   /**
    * @brief Upload a resource image to the atlas.
    *
-   * @note To make the atlasing efficient, an valid size should be provided.
+   * @note To make the atlasing efficient, a valid size should be provided.
    *       If size is not provided, then the image file will be opened to read the actual size for loading.
    *       Do not set a size that is bigger than the actual image size, as the up-scaling is not available,
    *       the content of the area not covered by actual image is undefined, it will not be cleared.
@@ -128,11 +136,37 @@ public:
    * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
    * @return True if there is enough space to fit this image in,false otherwise.
    */
-  bool Upload( Vector4& textureRect,
-               const std::string& url,
-               ImageDimensions size = ImageDimensions(),
-               FittingMode::Type fittingMode = FittingMode::DEFAULT,
-               bool orientationCorrection = true );
+  bool Upload(Vector4&           textureRect,
+              const std::string& url,
+              ImageDimensions    size                  = ImageDimensions(),
+              FittingMode::Type  fittingMode           = FittingMode::DEFAULT,
+              bool               orientationCorrection = true);
+
+  /**
+   * @brief Upload a resource image to the atlas.
+   *
+   * @note To make the atlasing efficient, a valid size should be provided.
+   *       If size is not provided, then the image file will be opened to read the actual size for loading.
+   *       Do not set a size that is bigger than the actual image size, as the up-scaling is not available,
+   *       the content of the area not covered by actual image is undefined, it will not be cleared.
+   *
+   * SamplingMode::BOX_THEN_LINEAR is used to sampling pixels from the input image while fitting it to desired size.
+   *
+   * @param [out] textureRect The texture area of the resource image in the atlas.
+   * @param [in] url The URL of the resource image file to use.
+   * @param [in] size The width and height to fit the loaded image to.
+   * @param [in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter.
+   * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
+   * @param[in] atlasUploadObserver The observer to observe the upload state inside the ImageAtlas.
+   * @return True if there is enough space to fit this image in,false otherwise.
+   * @note The valid callback function here is required to have the signature of void( void ).
+   */
+  bool Upload(Vector4&             textureRect,
+              const std::string&   url,
+              ImageDimensions      size,
+              FittingMode::Type    fittingMode,
+              bool                 orientationCorrection,
+              AtlasUploadObserver* atlasUploadObserver);
 
   /**
    * @brief Upload a pixel buffer to atlas
@@ -140,7 +174,7 @@ public:
    * @param [out] textureRect The texture area of the resource image in the atlas.
    * @param [in] pixelData The pixel data.
    */
-  bool Upload( Vector4& textureRect, PixelData pixelData );
+  bool Upload(Vector4& textureRect, PixelData pixelData);
 
   /**
    * @brief Remove the image at the given rectangle.
@@ -149,11 +183,10 @@ public:
    *
    * @param [in] textureRect The texture area to be removed.
    */
-  void Remove( const Vector4& textureRect );
+  void Remove(const Vector4& textureRect);
 
 public: // Not intended for developer use
-
-  explicit DALI_INTERNAL ImageAtlas( Internal::ImageAtlas* impl );
+  explicit DALI_INTERNAL ImageAtlas(Internal::ImageAtlas* impl);
 };
 
 } // namespace Toolkit