Deprecated load and resource policies as they dont work and cause more harm than...
[platform/core/uifw/dali-core.git] / dali / public-api / images / resource-image.h
index 96808b3..e57425b 100644 (file)
 #include <dali/public-api/common/loading-state.h>
 #include <dali/public-api/images/image.h>
 #include <dali/public-api/signals/dali-signal.h>
+#include <dali/public-api/images/image-operations.h>
 
 namespace Dali
 {
-struct Vector2;
-class ImageAttributes;
+/**
+ * @addtogroup dali-core-images
+ * @{
+ */
 
 namespace Internal DALI_INTERNAL
 {
@@ -41,48 +44,39 @@ class ResourceImage;
  *
  * <h3>ResourceImage Loading</h3>
  *
- * When the ResourceImage is created, resource loading will be attempted unless
- * the ResourceImage is created with IMMEDIATE loading policy or a compatible resource is found in cache.
- * In case of loading images ON_DEMAND, resource loading will only be attempted if the associated ImageActor
- * is put on Stage.
- * Custom loading requests can be made by providing an ImageAttributes object to ResourceImage::New().
- *
- * <i>LoadPolicies</i>
- * - IMMEDIATE: acquire image resource when creating ResourceImage.
- * - ON_DEMAND: only load in case the associated ImageActor is put on Stage
- *
- * <i>Resolution of conflicting policies</i>
- * If the same image is created more than once with conflicting policies, LoadPolicy "IMMEDIATE" overrides "ON_DEMAND".
+ * When the ResourceImage is created, resource loading will be attempted unless a compatible resource is found in cache.
+ * Scaling of images to a desired smaller size can be requested by providing desired dimensions,
+ * scaling mode and filter mode to to ResourceImage::New().
  *
  * <i>Custom load requests</i>
- * Size, scaling mode, orientation compensation can be set when requesting an image.
- * See ImageAttributes for more details.
+ * Size, scaling mode, filter mode, and orientation compensation can be set when requesting an image.
  *
  * <i>Compatible resources</i>
  *
- * Before loading a new ResourceImage the internal image resource cache is checked by dali.
+ * Before loading a new ResourceImage the internal image resource cache is checked by DALi.
  * If there is an image already loaded in memory and is deemed "compatible" with the requested image,
  * that resource is reused.
- * This happens for example if a loaded image exists with the same URL, and the difference between both
- * of the dimensions is less than 50%.
+ * This happens for example if a loaded image exists with the same URL, scaling and filtering modes,
+ * and the difference between both of the dimensions is less than a few pixels.
  *
  * <i>Reloading images</i>
  *
  * The same request used on creating the ResourceImage is re-issued when reloading images.
  * If the file changed since the last load operation, this might result in a different resource.
- * Reload only takes effect if both of these conditions apply:
- * - The ResourceImage has already finished loading
- * - The ResourceImage is either on Stage or using IMMEDIATE load policy
+ * Reload only takes effect if the ResourceImage has already finished loading
+ *
+ * Signals
+ * | %Signal Name           | Method                       |
+ * |------------------------|------------------------------|
+ * | image-loading-finished | @ref LoadingFinishedSignal() |
  */
 class DALI_IMPORT_API ResourceImage : public Image
 {
 public:
-  /**
-   * @brief Resource management options.
-   */
 
   /**
    * @brief LoadPolicy controls the way images are loaded into memory.
+   * @deprecated DALi 1.1.3 Image loading starts immediately in the frame when then ResourceImage object is created
    */
   enum LoadPolicy
   {
@@ -95,9 +89,6 @@ public:
    */
   typedef Signal< void (ResourceImage) > ResourceImageSignal;
 
-  // Signal Names
-  static const char* const SIGNAL_IMAGE_LOADING_FINISHED; ///< Name of LoadingFinished signal
-
 public:
 
   /**
@@ -110,7 +101,7 @@ public:
    * @param [in] url The URL of the image file.
    * @return The width and height in pixels of the image.
    */
-  static Vector2 GetImageSize( const std::string& url );
+  static ImageDimensions GetImageSize( const std::string& url );
 
   /**
    * @brief Constructor which creates an empty ResourceImage object.
@@ -142,42 +133,75 @@ public:
   ResourceImage& operator=( const ResourceImage& rhs );
 
   /**
+   * @name ResourceImageFactoryFunctions
+   * Create ResourceImage object instances using these functions.
+   */
+  ///@{
+
+  /**
    * @brief Create an initialised ResourceImage object.
    *
+   * Uses defaults for all options.
+   *
+   * @sa Dali::FittingMode::Type Dali::SamplingMode::Type
    * @param [in] url The URL of the image file to use.
+   * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
    * @return A handle to a newly allocated object
    */
-  static ResourceImage New( const std::string& url );
+  static ResourceImage New( const std::string& url, bool orientationCorrection = true );
 
   /**
    * @brief Create an initialised ResourceImage object.
    *
+   * @deprecated DALi 1.1.3 use New( const std::string& url ) instead.
+   *
    * @param [in] url The URL of the image file to use.
    * @param [in] loadPol    The LoadPolicy to apply when loading the image resource.
    * @param [in] releasePol The ReleasePolicy to apply to Image.
+   * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
    * @return A handle to a newly allocated object
    */
-  static ResourceImage New( const std::string& url, LoadPolicy loadPol, ReleasePolicy releasePol );
+  static ResourceImage New( const std::string& url, LoadPolicy loadPol, ReleasePolicy releasePol, bool orientationCorrection = true );
 
   /**
    * @brief Create an initialised ResourceImage object.
    *
    * @param [in] url The URL of the image file to use.
-   * @param [in] attributes Requested parameters for loading (size, scaling etc.).
+   * @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] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size.
+   * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
    * @return A handle to a newly allocated object
    */
-  static ResourceImage New( const std::string& url, const ImageAttributes& attributes );
+  static ResourceImage New( const std::string& url,
+                            ImageDimensions size,
+                            FittingMode::Type fittingMode = FittingMode::DEFAULT,
+                            SamplingMode::Type samplingMode = SamplingMode::DEFAULT,
+                            bool orientationCorrection = true );
 
   /**
    * @brief Create an initialised ResourceImage object.
    *
+   * @deprecated DALi 1.1.3 use New( const std::string& url, ImageDimensions size ) instead.
+   *
    * @param [in] url The URL of the image file to use.
-   * @param [in] attributes Requested parameters for loading (size, scaling etc.).
    * @param [in] loadPol    The LoadPolicy to apply when loading the image resource.
    * @param [in] releasePol The ReleasePolicy to apply to Image.
+   * @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] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size.
+   * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
    * @return A handle to a newly allocated object
    */
-  static ResourceImage New( const std::string& url, const ImageAttributes& attributes, LoadPolicy loadPol, ReleasePolicy releasePol );
+  static ResourceImage New( const std::string& url,
+                            LoadPolicy loadPol,
+                            ReleasePolicy releasePol,
+                            ImageDimensions size,
+                            FittingMode::Type fittingMode = FittingMode::DEFAULT,
+                            SamplingMode::Type samplingMode = SamplingMode::DEFAULT,
+                            bool orientationCorrection = true );
+
+  ///@}
 
   /**
    * @brief Downcast an Object handle to ResourceImage handle.
@@ -191,6 +215,7 @@ public:
 
   /**
    * @brief Return load policy.
+   * @deprecated DALi 1.1.3
    *
    * @return resource load policy
    */
@@ -215,23 +240,13 @@ public:
   /**
    * @brief Reload image from filesystem.
    *
-   * The set ImageAttributes are used when requesting the image again.
-   * @note if Image is offstage and OnDemand policy is set, reload request is ignored.
+   * The original set of image loading attributes (requested dimensions, scaling
+   * mode and filter mode) are used when requesting the image again.
+   * @note If image is offstage and OnDemand policy is set, the reload request is
+   * ignored.
    */
   void Reload();
 
-  /**
-   * @brief Get the attributes of an image.
-   *
-   * Only to be used after the image has finished loading.
-   * (Ticket's LoadingSucceeded callback was called)
-   * The returned value will reflect the true image dimensions once the asynchronous loading has finished.
-   * Connect to SignalLoadingFinished or use GetLoadingState to make sure this value is actual.
-   * @pre image should be loaded
-   * @return a copy of the attributes
-   */
-  ImageAttributes GetAttributes() const;
-
 public: // Signals
 
   /**
@@ -246,6 +261,9 @@ public: // Not intended for application developers
   explicit DALI_INTERNAL ResourceImage( Internal::ResourceImage* );
 };
 
+/**
+ * @}
+ */
 } // namespace Dali
 
 #endif // __DALI_RESOURCE_IMAGE_H__