Stopped image-scaling examples using Deprecated SetImage( ResourceImage ) API 85/115385/3
authorNick Holland <nick.holland@partner.samsung.com>
Fri, 17 Feb 2017 14:21:48 +0000 (14:21 +0000)
committerNick Holland <nick.holland@partner.samsung.com>
Fri, 17 Feb 2017 15:08:45 +0000 (15:08 +0000)
Note: the examples no longer work correctly:
- Flickering
- Image scaling modes in ImageVisual aren't fully
functional.

Currently logs the following errors when image needs scaling up.

Change-Id: I972a4368719937edfdef9657e3c2f0155772fe67
ImageAtlas::UploadToAtlas(uint32_t, Dali::PixelData) Can not upscale the image from actual loaded size [ 326, 210 ] to specified size [ 358, 231 ]

examples/image-scaling-and-filtering/image-scaling-and-filtering-example.cpp
examples/image-scaling-irregular-grid/image-scaling-irregular-grid-example.cpp

index 1c4563c..c6941b4 100644 (file)
@@ -18,6 +18,7 @@
 #include <dali/dali.h>
 #include <dali-toolkit/dali-toolkit.h>
 #include <dali-toolkit/devel-api/controls/popup/popup.h>
+#include <dali-toolkit/public-api/visuals/image-visual-properties.h>
 #include "shared/view.h"
 #include <iostream>
 
@@ -522,21 +523,6 @@ public:
     }
   }
 
-  void OnImageLoaded( ResourceImage image )
-  {
-    DALI_ASSERT_DEBUG( image == mNextImage );
-    mImageView.SetImage( image );
-    mImageView.SetSize( Size( image.GetWidth(), image.GetHeight() ) );
-    mImageLoading = false;
-
-    // We have finished loading, if a resize had occured during the load, trigger another load now.
-    if( mQueuedImageLoad )
-    {
-      mQueuedImageLoad = false;
-      LoadImage();
-    }
-  }
-
   bool OnControlTouched( Actor actor, const TouchData& event )
   {
     if(event.GetPointCount() > 0)
@@ -687,21 +673,17 @@ private:
     const char * const path = IMAGE_PATHS[ mCurrentPath ];
     Stage stage = Stage::GetCurrent();
     Size imageSize = stage.GetSize() * mImageStageScale;
-    const ImageDimensions imageSizeInt = ImageDimensions::FromFloatArray( &imageSize.x );
+    mImageView.SetSize( imageSize );
 
-    ResourceImage image = ResourceImage::New( path, imageSizeInt, mFittingMode, mSamplingMode );
+    Property::Map map;
+    map[Toolkit::ImageVisual::Property::URL] = path;
+    map[Toolkit::ImageVisual::Property::DESIRED_WIDTH] = imageSize.x;
+    map[Toolkit::ImageVisual::Property::DESIRED_HEIGHT] = imageSize.y;
+    map[Toolkit::ImageVisual::Property::FITTING_MODE] = mFittingMode;
+    map[Toolkit::ImageVisual::Property::SAMPLING_MODE] = mSamplingMode;
 
-    // If the image was cached, the load has already occured, bypass hooking the signal.
-    if( image.GetLoadingState() )
-    {
-      OnImageLoaded( image );
-    }
-    else
-    {
-      image.LoadingFinishedSignal().Connect( this, &ImageScalingAndFilteringController::OnImageLoaded );
-    }
+    mImageView.SetProperty( Toolkit::ImageView::Property::IMAGE, map );
 
-    mNextImage = image;
   }
 
   void ResizeImage()
@@ -710,16 +692,7 @@ private:
     Stage stage = Stage::GetCurrent();
     Size imageSize = stage.GetSize() * mImageStageScale;
 
-    // If an image is already loading, queue another load when it has finished.
-    // This way we get continuous updates instead of constantly re-requesting loads.
-    if( mImageLoading )
-    {
-      mQueuedImageLoad = true;
-    }
-    else
-    {
-      LoadImage();
-    }
+    LoadImage();
 
     // Border size needs to be modified to take into account the width of the frame.
     Vector2 borderScale( ( imageSize + Vector2( BORDER_WIDTH * 2.0f, BORDER_WIDTH * 2.0f ) ) / stage.GetSize() );
@@ -742,7 +715,6 @@ private:
   Toolkit::ImageView mGrabCorner;
   PanGestureDetector mPanGestureDetector;
   Toolkit::ImageView mImageView;
-  ResourceImage mNextImage; //< Currently-loading image
   Vector2 mImageStageScale;
   int mCurrentPath;
   FittingMode::Type mFittingMode;
index fdae2c4..7edeec6 100644 (file)
@@ -168,23 +168,6 @@ const char* IMAGE_PATHS[] = {
 const unsigned NUM_IMAGE_PATHS = sizeof(IMAGE_PATHS) / sizeof(IMAGE_PATHS[0]) - 1u;
 
 
-/**
- * Creates an Image
- *
- * @param[in] filename The path of the image.
- * @param[in] width The width of the image in pixels.
- * @param[in] height The height of the image in pixels.
- * @param[in] fittingMode The mode to use when scaling the image to fit the desired dimensions.
- */
-Image CreateImage(const std::string& filename, unsigned int width, unsigned int height, Dali::FittingMode::Type fittingMode )
-{
-#ifdef DEBUG_PRINT_DIAGNOSTICS
-    fprintf( stderr, "CreateImage(%s, %u, %u, fittingMode=%u)\n", filename.c_str(), width, height, unsigned( fittingMode ) );
-#endif
-  Image image = ResourceImage::New( filename, ImageDimensions( width, height ), fittingMode, Dali::SamplingMode::BOX_THEN_LINEAR );
-
-  return image;
-}
 
 /**
  * Creates an ImageView
@@ -194,15 +177,23 @@ Image CreateImage(const std::string& filename, unsigned int width, unsigned int
  * @param[in] height The height of the image in pixels.
  * @param[in] fittingMode The mode to use when scaling the image to fit the desired dimensions.
  */
-ImageView CreateImageView(const std::string& filename, unsigned int width, unsigned int height, Dali::FittingMode::Type fittingMode )
+ImageView CreateImageView(const std::string& filename, int width, int height, Dali::FittingMode::Type fittingMode )
 {
-  Image img = CreateImage( filename, width, height, fittingMode );
-  ImageView actor = ImageView::New( img );
-  actor.SetName( filename );
-  actor.SetParentOrigin(ParentOrigin::CENTER);
-  actor.SetAnchorPoint(AnchorPoint::CENTER);
 
-  return actor;
+  ImageView imageView = ImageView::New();
+
+  Property::Map map;
+  map[Toolkit::ImageVisual::Property::URL] = filename;
+  map[Toolkit::ImageVisual::Property::DESIRED_WIDTH] = width;
+  map[Toolkit::ImageVisual::Property::DESIRED_HEIGHT] = height;
+  map[Toolkit::ImageVisual::Property::FITTING_MODE] = fittingMode;
+  imageView.SetProperty( Toolkit::ImageView::Property::IMAGE, map );
+
+  imageView.SetName( filename );
+  imageView.SetParentOrigin(ParentOrigin::CENTER);
+  imageView.SetAnchorPoint(AnchorPoint::CENTER);
+
+  return imageView;
 }
 
 /** Cycle the scaling mode options. */
@@ -494,13 +485,18 @@ public:
         Dali::FittingMode::Type newMode = NextMode( mFittingModes[id] );
         const Vector2 imageSize = mSizes[actor.GetId()];
 
-        const std::string& url = mResourceUrls[id];
-        Image newImage = CreateImage( url, imageSize.width + 0.5f, imageSize.height + 0.5f, newMode );
         ImageView imageView = ImageView::DownCast( actor );
-        if(imageView)
+        if( imageView)
         {
-          imageView.SetImage( newImage );
+          Property::Map map;
+          map[Visual::Property::TYPE] = Visual::IMAGE;
+          map[ImageVisual::Property::URL] = mResourceUrls[id];
+          map[ImageVisual::Property::DESIRED_WIDTH] = imageSize.width + 0.5f;
+          map[ImageVisual::Property::DESIRED_HEIGHT] =  imageSize.height + 0.5f;
+          map[ImageVisual::Property::FITTING_MODE] = newMode;
+          imageView.SetProperty( ImageView::Property::IMAGE, map );
         }
+
         mFittingModes[id] = newMode;
       }
     }
@@ -542,8 +538,16 @@ public:
 
         const Vector2 imageSize = mSizes[ id ];
         Dali::FittingMode::Type newMode = NextMode( mFittingModes[ id ] );
-        Image newImage = CreateImage( mResourceUrls[ id ], imageSize.width, imageSize.height, newMode );
-        gridImageView.SetImage( newImage );
+
+        Property::Map map;
+        map[Visual::Property::TYPE] = Visual::IMAGE;
+        map[ImageVisual::Property::URL] = mResourceUrls[id];
+        map[ImageVisual::Property::DESIRED_WIDTH] = imageSize.width;
+        map[ImageVisual::Property::DESIRED_HEIGHT] =  imageSize.height;
+        map[ImageVisual::Property::FITTING_MODE] = newMode;
+        gridImageView.SetProperty( ImageView::Property::IMAGE, map );
+
+
 
         mFittingModes[ id ] = newMode;