Commit 0d076a4f2a8fe30919944ba37a626d32f1947316
1 parent
dcc7e265
Image scaling and filtering on load across all applicable demos
Signed-off-by: Andrew Cox <andrew.cox@partner.samsung.com> Change-Id: I7629356cb2678ee8eda85eff0cbef6a530ab7a17
Showing
9 changed files
with
145 additions
and
30 deletions
examples/bubble-effect/bubble-effect-example.cpp
| @@ -49,6 +49,25 @@ const unsigned int NUM_BUBBLE_SHAPE_IMAGES( sizeof( BUBBLE_SHAPE_IMAGES ) / size | @@ -49,6 +49,25 @@ const unsigned int NUM_BUBBLE_SHAPE_IMAGES( sizeof( BUBBLE_SHAPE_IMAGES ) / size | ||
| 49 | 49 | ||
| 50 | const Vector2 DEFAULT_BUBBLE_SIZE( 10.f, 30.f ); | 50 | const Vector2 DEFAULT_BUBBLE_SIZE( 10.f, 30.f ); |
| 51 | const unsigned int DEFAULT_NUMBER_OF_BUBBLES( 1000 ); | 51 | const unsigned int DEFAULT_NUMBER_OF_BUBBLES( 1000 ); |
| 52 | + | ||
| 53 | +/** | ||
| 54 | + * @brief Load an image, scaled-down to no more than the stage dimensions. | ||
| 55 | + * | ||
| 56 | + * Uses image scaling mode ImageAttributes::ScaleToFill to resize the image at | ||
| 57 | + * load time to cover the entire stage with pixels with no borders, | ||
| 58 | + * and filter mode ImageAttributes::BoxThenLinear to sample the image with | ||
| 59 | + * maximum quality. | ||
| 60 | + */ | ||
| 61 | +ResourceImage LoadStageFillingImage( const char * const imagePath ) | ||
| 62 | +{ | ||
| 63 | + Size stageSize = Stage::GetCurrent().GetSize(); | ||
| 64 | + ImageAttributes attributes; | ||
| 65 | + attributes.SetSize( stageSize.x, stageSize.y ); | ||
| 66 | + attributes.SetFilterMode( ImageAttributes::BoxThenLinear ); | ||
| 67 | + attributes.SetScalingMode( ImageAttributes::ScaleToFill ); | ||
| 68 | + return ResourceImage::New( imagePath, attributes ); | ||
| 69 | +} | ||
| 70 | + | ||
| 52 | }// end LOCAL_STUFF | 71 | }// end LOCAL_STUFF |
| 53 | 72 | ||
| 54 | // This example shows the usage of BubbleEmitter which displays lots of moving bubbles on the stage. | 73 | // This example shows the usage of BubbleEmitter which displays lots of moving bubbles on the stage. |
| @@ -114,7 +133,7 @@ private: | @@ -114,7 +133,7 @@ private: | ||
| 114 | ResourceImage::New( BUBBLE_SHAPE_IMAGES[mCurrentBubbleShapeImageId] ), | 133 | ResourceImage::New( BUBBLE_SHAPE_IMAGES[mCurrentBubbleShapeImageId] ), |
| 115 | DEFAULT_NUMBER_OF_BUBBLES, | 134 | DEFAULT_NUMBER_OF_BUBBLES, |
| 116 | DEFAULT_BUBBLE_SIZE); | 135 | DEFAULT_BUBBLE_SIZE); |
| 117 | - mBackgroundImage = ResourceImage::New( BACKGROUND_IMAGES[mCurrentBackgroundImageId] ); | 136 | + mBackgroundImage = LoadStageFillingImage( BACKGROUND_IMAGES[mCurrentBackgroundImageId] ); |
| 118 | mBubbleEmitter.SetBackground( mBackgroundImage, mHSVDelta ); | 137 | mBubbleEmitter.SetBackground( mBackgroundImage, mHSVDelta ); |
| 119 | 138 | ||
| 120 | // Get the root actor of all bubbles, and add it to stage. | 139 | // Get the root actor of all bubbles, and add it to stage. |
| @@ -235,7 +254,7 @@ private: | @@ -235,7 +254,7 @@ private: | ||
| 235 | { | 254 | { |
| 236 | if(button == mChangeBackgroundButton) | 255 | if(button == mChangeBackgroundButton) |
| 237 | { | 256 | { |
| 238 | - mBackgroundImage = ResourceImage::New( BACKGROUND_IMAGES[ ++mCurrentBackgroundImageId % NUM_BACKGROUND_IMAGES ] ); | 257 | + mBackgroundImage = LoadStageFillingImage( BACKGROUND_IMAGES[ ++mCurrentBackgroundImageId % NUM_BACKGROUND_IMAGES ] ); |
| 239 | 258 | ||
| 240 | mBubbleEmitter.SetBackground( mBackgroundImage, mHSVDelta ); | 259 | mBubbleEmitter.SetBackground( mBackgroundImage, mHSVDelta ); |
| 241 | 260 |
examples/cluster/cluster-example.cpp
| @@ -524,7 +524,13 @@ public: | @@ -524,7 +524,13 @@ public: | ||
| 524 | const char **paths = IMAGE_GROUPS[clusterType]; | 524 | const char **paths = IMAGE_GROUPS[clusterType]; |
| 525 | DALI_ASSERT_ALWAYS(paths); | 525 | DALI_ASSERT_ALWAYS(paths); |
| 526 | 526 | ||
| 527 | - // Add a background image to the cluster | 527 | + // Add a background image to the cluster, limiting the loaded size by |
| 528 | + // fitting it inside a quarter of the stage area with the conservative Box | ||
| 529 | + // filter mode: | ||
| 530 | + Dali::ImageAttributes backgroundAttributes; | ||
| 531 | + backgroundAttributes.SetSize( Stage::GetCurrent().GetSize() * 0.5f ); | ||
| 532 | + backgroundAttributes.SetFilterMode( Dali::ImageAttributes::Box ); | ||
| 533 | + backgroundAttributes.SetScalingMode( Dali::ImageAttributes::ShrinkToFit ); | ||
| 528 | Image bg = ResourceImage::New( CLUSTER_BACKGROUND_IMAGE_PATH ); | 534 | Image bg = ResourceImage::New( CLUSTER_BACKGROUND_IMAGE_PATH ); |
| 529 | ImageActor image = ImageActor::New(bg); | 535 | ImageActor image = ImageActor::New(bg); |
| 530 | clusterActor.SetBackgroundImage(image); | 536 | clusterActor.SetBackgroundImage(image); |
| @@ -552,10 +558,12 @@ public: | @@ -552,10 +558,12 @@ public: | ||
| 552 | actor.SetParentOrigin( ParentOrigin::CENTER ); | 558 | actor.SetParentOrigin( ParentOrigin::CENTER ); |
| 553 | actor.SetAnchorPoint( AnchorPoint::CENTER ); | 559 | actor.SetAnchorPoint( AnchorPoint::CENTER ); |
| 554 | 560 | ||
| 555 | - // Load the thumbnail | 561 | + // Load the thumbnail at quarter of screen width or standard size if that is smaller: |
| 556 | ImageAttributes attribs = ImageAttributes::New(); | 562 | ImageAttributes attribs = ImageAttributes::New(); |
| 557 | - attribs.SetSize(CLUSTER_IMAGE_THUMBNAIL_WIDTH, CLUSTER_IMAGE_THUMBNAIL_HEIGHT); | ||
| 558 | - attribs.SetScalingMode(Dali::ImageAttributes::ShrinkToFit); | 563 | + Size stageQuarter = Stage::GetCurrent().GetSize() * 0.25f; |
| 564 | + attribs.SetSize( std::min( stageQuarter.x, CLUSTER_IMAGE_THUMBNAIL_WIDTH), std::min( stageQuarter.y, CLUSTER_IMAGE_THUMBNAIL_HEIGHT ) ); | ||
| 565 | + attribs.SetFilterMode( Dali::ImageAttributes::BoxThenLinear ); | ||
| 566 | + attribs.SetScalingMode(Dali::ImageAttributes::ShrinkToFit ); | ||
| 559 | 567 | ||
| 560 | // Add a shadow image child actor | 568 | // Add a shadow image child actor |
| 561 | Image shadowImage = ResourceImage::New( CLUSTER_SHADOW_IMAGE_PATH, attribs ); | 569 | Image shadowImage = ResourceImage::New( CLUSTER_SHADOW_IMAGE_PATH, attribs ); |
examples/cube-transition-effect/cube-transition-effect-example.cpp
| @@ -85,6 +85,25 @@ const float CUBE_DISPLACEMENT_CROSS(30.f); | @@ -85,6 +85,25 @@ const float CUBE_DISPLACEMENT_CROSS(30.f); | ||
| 85 | 85 | ||
| 86 | // The duration of the current image staying on screen when slideshow is on | 86 | // The duration of the current image staying on screen when slideshow is on |
| 87 | const int VIEWINGTIME = 2000; // 2 seconds | 87 | const int VIEWINGTIME = 2000; // 2 seconds |
| 88 | + | ||
| 89 | +/** | ||
| 90 | + * @brief Load an image, scaled-down to no more than the stage dimensions. | ||
| 91 | + * | ||
| 92 | + * Uses image scaling mode ImageAttributes::ScaleToFill to resize the image at | ||
| 93 | + * load time to cover the entire stage with pixels with no borders, | ||
| 94 | + * and filter mode ImageAttributes::BoxThenLinear to sample the image with | ||
| 95 | + * maximum quality. | ||
| 96 | + */ | ||
| 97 | +ResourceImage LoadStageFillingImage( const char * const imagePath ) | ||
| 98 | +{ | ||
| 99 | + Size stageSize = Stage::GetCurrent().GetSize(); | ||
| 100 | + ImageAttributes attributes; | ||
| 101 | + attributes.SetSize( stageSize.x, stageSize.y ); | ||
| 102 | + attributes.SetFilterMode( ImageAttributes::BoxThenLinear ); | ||
| 103 | + attributes.SetScalingMode( ImageAttributes::ScaleToFill ); | ||
| 104 | + return ResourceImage::New( imagePath, attributes ); | ||
| 105 | +} | ||
| 106 | + | ||
| 88 | } // namespace | 107 | } // namespace |
| 89 | 108 | ||
| 90 | class CubeTransitionApp : public ConnectionTracker | 109 | class CubeTransitionApp : public ConnectionTracker |
| @@ -266,7 +285,7 @@ void CubeTransitionApp::OnInit( Application& application ) | @@ -266,7 +285,7 @@ void CubeTransitionApp::OnInit( Application& application ) | ||
| 266 | // show the first image | 285 | // show the first image |
| 267 | mImageConstraint = Constraint::New<Vector3>( Actor::Property::SCALE, LocalSource( Actor::Property::SIZE ), ParentSource( Actor::Property::SIZE ), ScaleToFitKeepAspectRatioConstraint() ); | 286 | mImageConstraint = Constraint::New<Vector3>( Actor::Property::SCALE, LocalSource( Actor::Property::SIZE ), ParentSource( Actor::Property::SIZE ), ScaleToFitKeepAspectRatioConstraint() ); |
| 268 | 287 | ||
| 269 | - mCurrentImage = ImageActor::New( ResourceImage::New( IMAGES[mIndex] ) ); | 288 | + mCurrentImage = ImageActor::New( LoadStageFillingImage( IMAGES[mIndex] ) ); |
| 270 | mCurrentImage.SetPositionInheritanceMode( USE_PARENT_POSITION ); | 289 | mCurrentImage.SetPositionInheritanceMode( USE_PARENT_POSITION ); |
| 271 | mCurrentImage.ApplyConstraint( mImageConstraint ); | 290 | mCurrentImage.ApplyConstraint( mImageConstraint ); |
| 272 | mParent.Add( mCurrentImage ); | 291 | mParent.Add( mCurrentImage ); |
| @@ -308,8 +327,9 @@ void CubeTransitionApp::OnPanGesture( Actor actor, const PanGesture& gesture ) | @@ -308,8 +327,9 @@ void CubeTransitionApp::OnPanGesture( Actor actor, const PanGesture& gesture ) | ||
| 308 | 327 | ||
| 309 | void CubeTransitionApp::GoToNextImage() | 328 | void CubeTransitionApp::GoToNextImage() |
| 310 | { | 329 | { |
| 311 | - ResourceImage image = ResourceImage::New( IMAGES[ mIndex ] ); | 330 | + ResourceImage image = LoadStageFillingImage( IMAGES[ mIndex ] ); |
| 312 | mNextImage = ImageActor::New( image ); | 331 | mNextImage = ImageActor::New( image ); |
| 332 | + | ||
| 313 | mNextImage.SetPositionInheritanceMode(USE_PARENT_POSITION); | 333 | mNextImage.SetPositionInheritanceMode(USE_PARENT_POSITION); |
| 314 | mNextImage.ApplyConstraint( mImageConstraint ); | 334 | mNextImage.ApplyConstraint( mImageConstraint ); |
| 315 | mCurrentEffect.SetTargetImage(mNextImage); | 335 | mCurrentEffect.SetTargetImage(mNextImage); |
examples/dissolve-effect/dissolve-effect-example.cpp
| @@ -71,6 +71,25 @@ const int VIEWINGTIME = 2000; // 2 seconds | @@ -71,6 +71,25 @@ const int VIEWINGTIME = 2000; // 2 seconds | ||
| 71 | const float TRANSITION_DURATION = 2.5f; //2.5 second | 71 | const float TRANSITION_DURATION = 2.5f; //2.5 second |
| 72 | 72 | ||
| 73 | const float INITIAL_DEPTH = -10.0f; | 73 | const float INITIAL_DEPTH = -10.0f; |
| 74 | + | ||
| 75 | +/** | ||
| 76 | + * @brief Load an image, scaled-down to no more than the stage dimensions. | ||
| 77 | + * | ||
| 78 | + * Uses image scaling mode ImageAttributes::ScaleToFill to resize the image at | ||
| 79 | + * load time to cover the entire stage with pixels with no borders, | ||
| 80 | + * and filter mode ImageAttributes::BoxThenLinear to sample the image with | ||
| 81 | + * maximum quality. | ||
| 82 | + */ | ||
| 83 | +ResourceImage LoadStageFillingImage( const char * const imagePath ) | ||
| 84 | +{ | ||
| 85 | + Size stageSize = Stage::GetCurrent().GetSize(); | ||
| 86 | + ImageAttributes attributes; | ||
| 87 | + attributes.SetSize( stageSize.x, stageSize.y ); | ||
| 88 | + attributes.SetFilterMode( ImageAttributes::BoxThenLinear ); | ||
| 89 | + attributes.SetScalingMode( ImageAttributes::ScaleToFill ); | ||
| 90 | + return ResourceImage::New( imagePath, attributes ); | ||
| 91 | +} | ||
| 92 | + | ||
| 74 | } // namespace | 93 | } // namespace |
| 75 | 94 | ||
| 76 | class DissolveEffectApp : public ConnectionTracker | 95 | class DissolveEffectApp : public ConnectionTracker |
| @@ -235,7 +254,7 @@ void DissolveEffectApp::OnInit( Application& application ) | @@ -235,7 +254,7 @@ void DissolveEffectApp::OnInit( Application& application ) | ||
| 235 | mSizeConstraint= Constraint::New<Vector3>( Actor::Property::SCALE, LocalSource( Actor::Property::SIZE ), ParentSource( Actor::Property::SIZE ), ScaleToFitKeepAspectRatioConstraint() ); | 254 | mSizeConstraint= Constraint::New<Vector3>( Actor::Property::SCALE, LocalSource( Actor::Property::SIZE ), ParentSource( Actor::Property::SIZE ), ScaleToFitKeepAspectRatioConstraint() ); |
| 236 | 255 | ||
| 237 | // show the first image | 256 | // show the first image |
| 238 | - mCurrentImage = ImageActor::New( ResourceImage::New( IMAGES[mIndex] ) ); | 257 | + mCurrentImage = ImageActor::New( LoadStageFillingImage( IMAGES[mIndex] ) ); |
| 239 | mCurrentImage.SetPositionInheritanceMode(USE_PARENT_POSITION_PLUS_LOCAL_POSITION); | 258 | mCurrentImage.SetPositionInheritanceMode(USE_PARENT_POSITION_PLUS_LOCAL_POSITION); |
| 240 | mCurrentImage.ApplyConstraint( mSizeConstraint ); | 259 | mCurrentImage.ApplyConstraint( mSizeConstraint ); |
| 241 | mParent.Add( mCurrentImage ); | 260 | mParent.Add( mCurrentImage ); |
| @@ -263,7 +282,7 @@ void DissolveEffectApp::OnPanGesture( Actor actor, const PanGesture& gesture ) | @@ -263,7 +282,7 @@ void DissolveEffectApp::OnPanGesture( Actor actor, const PanGesture& gesture ) | ||
| 263 | mIndex = (mIndex + NUM_IMAGES -1)%NUM_IMAGES; | 282 | mIndex = (mIndex + NUM_IMAGES -1)%NUM_IMAGES; |
| 264 | } | 283 | } |
| 265 | 284 | ||
| 266 | - Image image = ResourceImage::New( IMAGES[ mIndex ] ); | 285 | + Image image = LoadStageFillingImage( IMAGES[ mIndex ] ); |
| 267 | mNextImage = ImageActor::New( image ); | 286 | mNextImage = ImageActor::New( image ); |
| 268 | mNextImage.SetPositionInheritanceMode(USE_PARENT_POSITION_PLUS_LOCAL_POSITION); | 287 | mNextImage.SetPositionInheritanceMode(USE_PARENT_POSITION_PLUS_LOCAL_POSITION); |
| 269 | mNextImage.ApplyConstraint( mSizeConstraint ); | 288 | mNextImage.ApplyConstraint( mSizeConstraint ); |
| @@ -375,7 +394,7 @@ bool DissolveEffectApp::OnTimerTick() | @@ -375,7 +394,7 @@ bool DissolveEffectApp::OnTimerTick() | ||
| 375 | if(mSlideshow) | 394 | if(mSlideshow) |
| 376 | { | 395 | { |
| 377 | mIndex = (mIndex + 1)%NUM_IMAGES; | 396 | mIndex = (mIndex + 1)%NUM_IMAGES; |
| 378 | - Image image = ResourceImage::New( IMAGES[ mIndex ] ); | 397 | + Image image = LoadStageFillingImage( IMAGES[ mIndex ] ); |
| 379 | mNextImage = ImageActor::New( image ); | 398 | mNextImage = ImageActor::New( image ); |
| 380 | mNextImage.SetPositionInheritanceMode(USE_PARENT_POSITION_PLUS_LOCAL_POSITION); | 399 | mNextImage.SetPositionInheritanceMode(USE_PARENT_POSITION_PLUS_LOCAL_POSITION); |
| 381 | mNextImage.ApplyConstraint( mSizeConstraint ); | 400 | mNextImage.ApplyConstraint( mSizeConstraint ); |
examples/image-scaling-irregular-grid/image-scaling-irregular-grid-example.cpp
| @@ -183,6 +183,7 @@ Image CreateImage(const std::string& filename, unsigned int width, unsigned int | @@ -183,6 +183,7 @@ Image CreateImage(const std::string& filename, unsigned int width, unsigned int | ||
| 183 | 183 | ||
| 184 | attributes.SetSize( width, height ); | 184 | attributes.SetSize( width, height ); |
| 185 | attributes.SetScalingMode( scalingMode ); | 185 | attributes.SetScalingMode( scalingMode ); |
| 186 | + attributes.SetFilterMode( ImageAttributes::BoxThenLinear ); | ||
| 186 | Image image = ResourceImage::New( filename, attributes ); | 187 | Image image = ResourceImage::New( filename, attributes ); |
| 187 | return image; | 188 | return image; |
| 188 | } | 189 | } |
| @@ -359,6 +360,9 @@ public: | @@ -359,6 +360,9 @@ public: | ||
| 359 | mContentLayer.Add( mScrollView ); | 360 | mContentLayer.Add( mScrollView ); |
| 360 | mScrollView.Add( imageField ); | 361 | mScrollView.Add( imageField ); |
| 361 | mGridActor = imageField; | 362 | mGridActor = imageField; |
| 363 | + | ||
| 364 | + // Scroll to top of grid so first images loaded are on-screen: | ||
| 365 | + mScrollView.ScrollTo( Vector3( 0, -1000000, 0 ) ); | ||
| 362 | } | 366 | } |
| 363 | 367 | ||
| 364 | /** | 368 | /** |
examples/motion-blur/motion-blur-example.cpp
| @@ -88,9 +88,25 @@ const Vector3 BUTTON_TITLE_LABEL_INSTRUCTIONS_POPUP_SIZE_CONSTRAINT( 1.0f, 1.0f, | @@ -88,9 +88,25 @@ const Vector3 BUTTON_TITLE_LABEL_INSTRUCTIONS_POPUP_SIZE_CONSTRAINT( 1.0f, 1.0f, | ||
| 88 | const float BUTTON_TITLE_LABEL_Y_OFFSET = 0.05f; | 88 | const float BUTTON_TITLE_LABEL_Y_OFFSET = 0.05f; |
| 89 | 89 | ||
| 90 | const float ORIENTATION_DURATION = 0.5f; ///< Time to rotate to new orientation. | 90 | const float ORIENTATION_DURATION = 0.5f; ///< Time to rotate to new orientation. |
| 91 | -} // unnamed namespace | ||
| 92 | 91 | ||
| 92 | +/** | ||
| 93 | + * @brief Load an image, scaled-down to no more than the dimensions passed in. | ||
| 94 | + * | ||
| 95 | + * Uses ImageAttributes::ShrinkToFit which ensures the resulting image is | ||
| 96 | + * smaller than or equal to the specified dimensions while preserving its | ||
| 97 | + * original aspect ratio. | ||
| 98 | + */ | ||
| 99 | +ResourceImage LoadImageFittedInBox( const char * const imagePath, uint32_t maxWidth, uint32_t maxHeight ) | ||
| 100 | +{ | ||
| 101 | + // Load the image nicely scaled-down to fit within the specified max width and height: | ||
| 102 | + ImageAttributes attributes; | ||
| 103 | + attributes.SetSize( maxWidth, maxHeight); | ||
| 104 | + attributes.SetFilterMode( ImageAttributes::BoxThenLinear ); | ||
| 105 | + attributes.SetScalingMode( ImageAttributes::ShrinkToFit ); | ||
| 106 | + return ResourceImage::New( imagePath, attributes ); | ||
| 107 | +} | ||
| 93 | 108 | ||
| 109 | +} // unnamed namespace | ||
| 94 | 110 | ||
| 95 | 111 | ||
| 96 | // | 112 | // |
| @@ -187,10 +203,15 @@ public: | @@ -187,10 +203,15 @@ public: | ||
| 187 | // Motion blurred actor | 203 | // Motion blurred actor |
| 188 | // | 204 | // |
| 189 | 205 | ||
| 190 | - Image image = ResourceImage::New( MOTION_BLUR_ACTOR_IMAGE1 ); | 206 | + // Scale down actor to fit on very low resolution screens with space to interact: |
| 207 | + Size stageSize = Stage::GetCurrent().GetSize(); | ||
| 208 | + mMotionBlurActorSize = Size( std::min( stageSize.x * 0.3f, MOTION_BLUR_ACTOR_WIDTH ), std::min( stageSize.y * 0.3f, MOTION_BLUR_ACTOR_HEIGHT ) ); | ||
| 209 | + mMotionBlurActorSize = Size( std::min( mMotionBlurActorSize.x, mMotionBlurActorSize.y ), std::min( mMotionBlurActorSize.x, mMotionBlurActorSize.y ) ); | ||
| 210 | + | ||
| 211 | + Image image = LoadImageFittedInBox( MOTION_BLUR_ACTOR_IMAGE1, mMotionBlurActorSize.x, mMotionBlurActorSize.y ); | ||
| 191 | mMotionBlurImageActor = ImageActor::New(image); | 212 | mMotionBlurImageActor = ImageActor::New(image); |
| 192 | mMotionBlurImageActor.SetParentOrigin( ParentOrigin::CENTER ); | 213 | mMotionBlurImageActor.SetParentOrigin( ParentOrigin::CENTER ); |
| 193 | - mMotionBlurImageActor.SetSize(MOTION_BLUR_ACTOR_WIDTH, MOTION_BLUR_ACTOR_HEIGHT); | 214 | + mMotionBlurImageActor.SetSize(mMotionBlurActorSize.x, mMotionBlurActorSize.y); |
| 194 | 215 | ||
| 195 | mContentLayer.Add( mMotionBlurImageActor ); | 216 | mContentLayer.Add( mMotionBlurImageActor ); |
| 196 | 217 | ||
| @@ -207,8 +228,8 @@ public: | @@ -207,8 +228,8 @@ public: | ||
| 207 | 228 | ||
| 208 | mMotionBlurImageActor2 = ImageActor::New(image); | 229 | mMotionBlurImageActor2 = ImageActor::New(image); |
| 209 | mMotionBlurImageActor2.SetParentOrigin( ParentOrigin::CENTER ); | 230 | mMotionBlurImageActor2.SetParentOrigin( ParentOrigin::CENTER ); |
| 210 | - mMotionBlurImageActor2.SetSize(MOTION_BLUR_ACTOR_WIDTH, MOTION_BLUR_ACTOR_HEIGHT); | ||
| 211 | - mMotionBlurImageActor2.SetPosition(MOTION_BLUR_ACTOR_WIDTH * 1.1f, 0.0f); | 231 | + mMotionBlurImageActor2.SetSize(mMotionBlurActorSize.x, mMotionBlurActorSize.y); |
| 232 | + mMotionBlurImageActor2.SetPosition(mMotionBlurActorSize.x * 1.1f, 0.0f); | ||
| 212 | mMotionBlurImageActor.Add( mMotionBlurImageActor2 ); | 233 | mMotionBlurImageActor.Add( mMotionBlurImageActor2 ); |
| 213 | 234 | ||
| 214 | // Create shader used for doing motion blur | 235 | // Create shader used for doing motion blur |
| @@ -225,8 +246,8 @@ public: | @@ -225,8 +246,8 @@ public: | ||
| 225 | 246 | ||
| 226 | mMotionBlurImageActor3 = ImageActor::New(image); | 247 | mMotionBlurImageActor3 = ImageActor::New(image); |
| 227 | mMotionBlurImageActor3.SetParentOrigin( ParentOrigin::CENTER ); | 248 | mMotionBlurImageActor3.SetParentOrigin( ParentOrigin::CENTER ); |
| 228 | - mMotionBlurImageActor3.SetSize(MOTION_BLUR_ACTOR_WIDTH, MOTION_BLUR_ACTOR_HEIGHT); | ||
| 229 | - mMotionBlurImageActor3.SetPosition(-MOTION_BLUR_ACTOR_WIDTH * 1.1f, 0.0f); | 249 | + mMotionBlurImageActor3.SetSize(mMotionBlurActorSize.x, mMotionBlurActorSize.y); |
| 250 | + mMotionBlurImageActor3.SetPosition(-mMotionBlurActorSize.x * 1.1f, 0.0f); | ||
| 230 | mMotionBlurImageActor.Add( mMotionBlurImageActor3 ); | 251 | mMotionBlurImageActor.Add( mMotionBlurImageActor3 ); |
| 231 | 252 | ||
| 232 | // Create shader used for doing motion blur | 253 | // Create shader used for doing motion blur |
| @@ -243,8 +264,8 @@ public: | @@ -243,8 +264,8 @@ public: | ||
| 243 | 264 | ||
| 244 | mMotionBlurImageActor4 = ImageActor::New(image); | 265 | mMotionBlurImageActor4 = ImageActor::New(image); |
| 245 | mMotionBlurImageActor4.SetParentOrigin( ParentOrigin::CENTER ); | 266 | mMotionBlurImageActor4.SetParentOrigin( ParentOrigin::CENTER ); |
| 246 | - mMotionBlurImageActor4.SetSize(MOTION_BLUR_ACTOR_WIDTH, MOTION_BLUR_ACTOR_HEIGHT); | ||
| 247 | - mMotionBlurImageActor4.SetPosition(0.0f, MOTION_BLUR_ACTOR_HEIGHT * 1.1f); | 267 | + mMotionBlurImageActor4.SetSize(mMotionBlurActorSize.x, mMotionBlurActorSize.y); |
| 268 | + mMotionBlurImageActor4.SetPosition(0.0f, mMotionBlurActorSize.y * 1.1f); | ||
| 248 | mMotionBlurImageActor.Add( mMotionBlurImageActor4 ); | 269 | mMotionBlurImageActor.Add( mMotionBlurImageActor4 ); |
| 249 | 270 | ||
| 250 | // Create shader used for doing motion blur | 271 | // Create shader used for doing motion blur |
| @@ -261,8 +282,8 @@ public: | @@ -261,8 +282,8 @@ public: | ||
| 261 | 282 | ||
| 262 | mMotionBlurImageActor5 = ImageActor::New(image); | 283 | mMotionBlurImageActor5 = ImageActor::New(image); |
| 263 | mMotionBlurImageActor5.SetParentOrigin( ParentOrigin::CENTER ); | 284 | mMotionBlurImageActor5.SetParentOrigin( ParentOrigin::CENTER ); |
| 264 | - mMotionBlurImageActor5.SetSize(MOTION_BLUR_ACTOR_WIDTH, MOTION_BLUR_ACTOR_HEIGHT); | ||
| 265 | - mMotionBlurImageActor5.SetPosition(0.0f, -MOTION_BLUR_ACTOR_HEIGHT * 1.1f); | 285 | + mMotionBlurImageActor5.SetSize(mMotionBlurActorSize.x, mMotionBlurActorSize.y); |
| 286 | + mMotionBlurImageActor5.SetPosition(0.0f, -mMotionBlurActorSize.y * 1.1f); | ||
| 266 | mMotionBlurImageActor.Add( mMotionBlurImageActor5 ); | 287 | mMotionBlurImageActor.Add( mMotionBlurImageActor5 ); |
| 267 | 288 | ||
| 268 | // Create shader used for doing motion blur | 289 | // Create shader used for doing motion blur |
| @@ -478,7 +499,7 @@ public: | @@ -478,7 +499,7 @@ public: | ||
| 478 | mCurrentImage = 0; | 499 | mCurrentImage = 0; |
| 479 | } | 500 | } |
| 480 | 501 | ||
| 481 | - Image blurImage = ResourceImage::New( MOTION_BLUR_ACTOR_IMAGES[mCurrentImage] ); | 502 | + Image blurImage = LoadImageFittedInBox( MOTION_BLUR_ACTOR_IMAGES[mCurrentImage], mMotionBlurActorSize.x, mMotionBlurActorSize.y ); |
| 482 | mMotionBlurImageActor.SetImage(blurImage); | 503 | mMotionBlurImageActor.SetImage(blurImage); |
| 483 | } | 504 | } |
| 484 | 505 | ||
| @@ -498,6 +519,7 @@ private: | @@ -498,6 +519,7 @@ private: | ||
| 498 | // Motion blur | 519 | // Motion blur |
| 499 | MotionBlurEffect mMotionBlurEffect; | 520 | MotionBlurEffect mMotionBlurEffect; |
| 500 | ImageActor mMotionBlurImageActor; | 521 | ImageActor mMotionBlurImageActor; |
| 522 | + Size mMotionBlurActorSize; | ||
| 501 | 523 | ||
| 502 | #ifdef MULTIPLE_MOTION_BLURRED_ACTORS | 524 | #ifdef MULTIPLE_MOTION_BLURRED_ACTORS |
| 503 | MotionBlurEffect mMotionBlurEffect2; | 525 | MotionBlurEffect mMotionBlurEffect2; |
examples/refraction-effect/refraction-effect-example.cpp
| @@ -65,6 +65,24 @@ struct LightOffsetConstraint | @@ -65,6 +65,24 @@ struct LightOffsetConstraint | ||
| 65 | float mRadius; | 65 | float mRadius; |
| 66 | }; | 66 | }; |
| 67 | 67 | ||
| 68 | +/** | ||
| 69 | + * @brief Load an image, scaled-down to no more than the stage dimensions. | ||
| 70 | + * | ||
| 71 | + * Uses image scaling mode ImageAttributes::ScaleToFill to resize the image at | ||
| 72 | + * load time to cover the entire stage with pixels with no borders, | ||
| 73 | + * and filter mode ImageAttributes::BoxThenLinear to sample the image with | ||
| 74 | + * maximum quality. | ||
| 75 | + */ | ||
| 76 | +ResourceImage LoadStageFillingImage( const char * const imagePath ) | ||
| 77 | +{ | ||
| 78 | + Size stageSize = Stage::GetCurrent().GetSize(); | ||
| 79 | + ImageAttributes attributes; | ||
| 80 | + attributes.SetSize( stageSize.x, stageSize.y ); | ||
| 81 | + attributes.SetFilterMode( ImageAttributes::BoxThenLinear ); | ||
| 82 | + attributes.SetScalingMode( ImageAttributes::ScaleToFill ); | ||
| 83 | + return ResourceImage::New( imagePath, attributes ); | ||
| 84 | +} | ||
| 85 | + | ||
| 68 | } // namespace | 86 | } // namespace |
| 69 | 87 | ||
| 70 | /************************************************************************************************ | 88 | /************************************************************************************************ |
| @@ -338,7 +356,7 @@ private: | @@ -338,7 +356,7 @@ private: | ||
| 338 | mNoEffect = NoEffect::New(); // used in the other situations, basic render shader | 356 | mNoEffect = NoEffect::New(); // used in the other situations, basic render shader |
| 339 | // Create the mesh from the obj file and add to stage | 357 | // Create the mesh from the obj file and add to stage |
| 340 | mMaterial = Material::New( "Material" ) ; | 358 | mMaterial = Material::New( "Material" ) ; |
| 341 | - mMaterial.SetDiffuseTexture(ResourceImage::New(TEXTURE_IMAGES[mCurrentTextureId])); | 359 | + mMaterial.SetDiffuseTexture( LoadStageFillingImage( TEXTURE_IMAGES[mCurrentTextureId] ) ); |
| 342 | CreateSurface( MESH_FILES[mCurrentMeshId] ); | 360 | CreateSurface( MESH_FILES[mCurrentMeshId] ); |
| 343 | 361 | ||
| 344 | // Connect the callback to the touch signal on the mesh actor | 362 | // Connect the callback to the touch signal on the mesh actor |
| @@ -371,7 +389,7 @@ private: | @@ -371,7 +389,7 @@ private: | ||
| 371 | bool OnChangeTexture( Toolkit::Button button ) | 389 | bool OnChangeTexture( Toolkit::Button button ) |
| 372 | { | 390 | { |
| 373 | mCurrentTextureId = ( mCurrentTextureId + 1 ) % NUM_TEXTURE_IMAGES; | 391 | mCurrentTextureId = ( mCurrentTextureId + 1 ) % NUM_TEXTURE_IMAGES; |
| 374 | - mMaterial.SetDiffuseTexture(ResourceImage::New(TEXTURE_IMAGES[mCurrentTextureId])); | 392 | + mMaterial.SetDiffuseTexture( LoadStageFillingImage( TEXTURE_IMAGES[mCurrentTextureId] ) ); |
| 375 | 393 | ||
| 376 | return true; | 394 | return true; |
| 377 | } | 395 | } |
examples/scroll-view/scroll-view-example.cpp
| @@ -315,7 +315,7 @@ private: | @@ -315,7 +315,7 @@ private: | ||
| 315 | { | 315 | { |
| 316 | for(int column = 0;column<imageColumns;column++) | 316 | for(int column = 0;column<imageColumns;column++) |
| 317 | { | 317 | { |
| 318 | - ImageActor image = CreateImage( GetNextImagePath() ); | 318 | + ImageActor image = CreateImage( GetNextImagePath(), imageSize.x, imageSize.y ); |
| 319 | 319 | ||
| 320 | image.SetParentOrigin( ParentOrigin::CENTER ); | 320 | image.SetParentOrigin( ParentOrigin::CENTER ); |
| 321 | image.SetAnchorPoint( AnchorPoint::CENTER ); | 321 | image.SetAnchorPoint( AnchorPoint::CENTER ); |
| @@ -562,7 +562,8 @@ private: | @@ -562,7 +562,8 @@ private: | ||
| 562 | ImageAttributes attributes; | 562 | ImageAttributes attributes; |
| 563 | 563 | ||
| 564 | attributes.SetSize(width, height); | 564 | attributes.SetSize(width, height); |
| 565 | - attributes.SetScalingMode(ImageAttributes::ShrinkToFit); | 565 | + attributes.SetScalingMode(ImageAttributes::ScaleToFill); |
| 566 | + attributes.SetFilterMode( ImageAttributes::BoxThenLinear ); | ||
| 566 | Image img = ResourceImage::New(filename, attributes); | 567 | Image img = ResourceImage::New(filename, attributes); |
| 567 | ImageActor actor = ImageActor::New(img); | 568 | ImageActor actor = ImageActor::New(img); |
| 568 | actor.SetName( filename ); | 569 | actor.SetName( filename ); |
shared/view.h
| @@ -142,10 +142,14 @@ Dali::Layer CreateView( Dali::Application& application, | @@ -142,10 +142,14 @@ Dali::Layer CreateView( Dali::Application& application, | ||
| 142 | // Add the view to the stage before setting the background. | 142 | // Add the view to the stage before setting the background. |
| 143 | stage.Add( view ); | 143 | stage.Add( view ); |
| 144 | 144 | ||
| 145 | - // Set background image. | ||
| 146 | - if ( ! backgroundImagePath.empty() ) | 145 | + // Set background image, loading it at screen resolution: |
| 146 | + if ( !backgroundImagePath.empty() ) | ||
| 147 | { | 147 | { |
| 148 | - Dali::Image backgroundImage = Dali::ResourceImage::New( backgroundImagePath ); | 148 | + Dali::ImageAttributes backgroundAttributes; |
| 149 | + backgroundAttributes.SetSize( stage.GetSize() ); | ||
| 150 | + backgroundAttributes.SetFilterMode( Dali::ImageAttributes::BoxThenLinear ); | ||
| 151 | + backgroundAttributes.SetScalingMode( Dali::ImageAttributes::ScaleToFill ); | ||
| 152 | + Dali::Image backgroundImage = Dali::ResourceImage::New( backgroundImagePath, backgroundAttributes ); | ||
| 149 | Dali::ImageActor backgroundImageActor = Dali::ImageActor::New( backgroundImage ); | 153 | Dali::ImageActor backgroundImageActor = Dali::ImageActor::New( backgroundImage ); |
| 150 | view.SetBackground( backgroundImageActor ); | 154 | view.SetBackground( backgroundImageActor ); |
| 151 | } | 155 | } |