Added example of CPU based image masking 36/132536/4
authorDavid Steele <david.steele@samsung.com>
Tue, 6 Jun 2017 18:08:01 +0000 (19:08 +0100)
committerDavid Steele <david.steele@samsung.com>
Fri, 9 Jun 2017 10:52:28 +0000 (11:52 +0100)
Change-Id: I908dff83e3140113ba108d660e903f75fd4e4dc1
Signed-off-by: David Steele <david.steele@samsung.com>
12 files changed:
examples-reel/dali-examples-reel.cpp
examples/alpha-blending-cpu/alpha-blending-cpu-example.cpp [new file with mode: 0644]
resources/images/application-icon-7-RGB565.png [new file with mode: 0644]
resources/images/mask-large.png [new file with mode: 0644]
resources/images/mask.png [new file with mode: 0644]
resources/images/mask.xcf [new file with mode: 0644]
resources/images/people-medium-7-masked.png [new file with mode: 0644]
resources/images/people-medium-7-rgb565.png [new file with mode: 0644]
resources/images/people-small-7b.jpg [new file with mode: 0644]
resources/po/en_GB.po
resources/po/en_US.po
shared/dali-demo-strings.h

index cdd64a071de1164316f9de5e6e9a411e2eabc16a..af4b9d0f695e9ebe1aded33316bb96f673904122 100644 (file)
@@ -38,6 +38,7 @@ int DALI_EXPORT_API main(int argc, char **argv)
 
   demo.AddExample(Example("animated-images.example", DALI_DEMO_STR_TITLE_ANIMATED_IMAGES));
   demo.AddExample(Example("animated-shapes.example", DALI_DEMO_STR_TITLE_ANIMATED_SHAPES));
+  demo.AddExample(Example("alpha-blending-cpu.example", DALI_DEMO_STR_TITLE_ALPHA_BLENDING_CPU));
   demo.AddExample(Example("builder.example", DALI_DEMO_STR_TITLE_SCRIPT_BASED_UI));
   demo.AddExample(Example("buttons.example", DALI_DEMO_STR_TITLE_BUTTONS));
   demo.AddExample(Example("clipping.example", DALI_DEMO_STR_TITLE_CLIPPING));
diff --git a/examples/alpha-blending-cpu/alpha-blending-cpu-example.cpp b/examples/alpha-blending-cpu/alpha-blending-cpu-example.cpp
new file mode 100644 (file)
index 0000000..8b8cd98
--- /dev/null
@@ -0,0 +1,158 @@
+/*
+ * Copyright (c) 2015 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <dali-toolkit/dali-toolkit.h>
+#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
+#include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
+#include <cstring>
+
+using namespace Dali;
+
+namespace
+{
+const char* const IMAGE_PATH_1 ( DEMO_IMAGE_DIR "people-small-7b.jpg" ); // 100x100
+const char* const IMAGE_PATH_2 ( DEMO_IMAGE_DIR "people-medium-7.jpg" );
+const char* const IMAGE_PATH_3 ( DEMO_IMAGE_DIR "people-medium-7-rgb565.png" ); // is compressed
+const char* const IMAGE_PATH_4 ( DEMO_IMAGE_DIR "people-medium-7-masked.png" ); // has alpha channel
+const char* const MASK_IMAGE_PATH_1 ( DEMO_IMAGE_DIR "mask.png" );
+const char* const MASK_IMAGE_PATH_2 ( DEMO_IMAGE_DIR "mask-large.png" ); // 300x300
+}
+
+class ImageViewAlphaBlendApp : public ConnectionTracker
+{
+public:
+  ImageViewAlphaBlendApp( Application& application )
+  : mApplication( application ),
+    mImageCombinationIndex( 0 )
+  {
+    // Connect to the Application's Init signal
+    mApplication.InitSignal().Connect( this, &ImageViewAlphaBlendApp::Create );
+  }
+
+  ~ImageViewAlphaBlendApp()
+  {
+    // Nothing to do here;
+  }
+
+private:
+  // The Init signal is received once (only) during the Application lifetime
+  void Create( Application& application )
+  {
+    // This creates an image view with one of 3 images, and one of 2 masks.
+    // Clicking the screen will cycle through each combination of mask and image.
+
+    // Get a handle to the stage
+    Stage stage = Stage::GetCurrent();
+    stage.KeyEventSignal().Connect(this, &ImageViewAlphaBlendApp::OnKeyEvent);
+    stage.SetBackgroundColor( Color::WHITE );
+
+    mImageView = Toolkit::ImageView::New();
+
+    mImageView.SetSize(200, 200);
+    mImageView.SetParentOrigin( ParentOrigin::CENTER );
+    stage.Add(mImageView);
+
+    mImageLabel = Toolkit::TextLabel::New();
+    mImageLabel.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
+    mImageLabel.SetAnchorPoint( ParentOrigin::BOTTOM_CENTER );
+    mImageLabel.SetPosition( Vector3( 0.0f, -50.0f, 0.0f ) );
+    mImageLabel.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::GREEN );
+    stage.Add(mImageLabel);
+
+    mMaskLabel = Toolkit::TextLabel::New();
+    mMaskLabel.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
+    mMaskLabel.SetAnchorPoint( ParentOrigin::BOTTOM_CENTER );
+    mMaskLabel.SetPosition( Vector3( 0.0f, 0.0f, 0.0f ) );
+    mMaskLabel.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Color::GREEN );
+    stage.Add(mMaskLabel);
+
+    LoadImages();
+
+    stage.TouchSignal().Connect( this, &ImageViewAlphaBlendApp::OnTouched );
+  }
+
+  void OnTouched( const TouchData& touchData )
+  {
+    static bool touched = false;
+    if( touchData.GetState( 0 ) == PointState::DOWN )
+    {
+      touched = true;
+    }
+
+    if( touchData.GetState( 0 ) == PointState::UP && touched)
+    {
+      mImageCombinationIndex++;
+      touched = false;
+      LoadImages();
+    }
+  }
+
+  void LoadImages()
+  {
+    const char* images[4] = { IMAGE_PATH_1, IMAGE_PATH_2, IMAGE_PATH_3, IMAGE_PATH_4 };
+    const char*  masks[2] = { MASK_IMAGE_PATH_1, MASK_IMAGE_PATH_2 };
+
+    const char* mask  = masks[mImageCombinationIndex%2 ]; // Cycle through masks
+    const char* image = images[(mImageCombinationIndex/2)%4]; // then images
+    Property::Map map;
+    map.Add( Toolkit::Visual::Property::TYPE, Toolkit::Visual::Type::IMAGE );
+    map.Add( Toolkit::ImageVisual::Property::URL, image );
+    map.Add( Toolkit::DevelImageVisual::Property::ALPHA_MASK_URL, mask );
+    mImageView.SetProperty( Toolkit::ImageView::Property::IMAGE, map );
+
+    mImageLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, strrchr(image, '/') );
+    mMaskLabel.SetProperty( Toolkit::TextLabel::Property::TEXT, strrchr(mask, '/') );
+  }
+
+  void OnKeyEvent(const KeyEvent& event)
+  {
+    if(event.state == KeyEvent::Down)
+    {
+      if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) )
+      {
+        mApplication.Quit();
+      }
+    }
+  }
+
+
+private:
+  Application&  mApplication;
+  Toolkit::ImageView mImageView;
+  Toolkit::TextLabel mImageLabel;
+  Toolkit::TextLabel mMaskLabel;
+
+  int mImageCombinationIndex;
+};
+
+void RunTest( Application& application )
+{
+  ImageViewAlphaBlendApp test( application );
+
+  application.MainLoop();
+}
+
+// Entry point for Linux & Tizen applications
+//
+int DALI_EXPORT_API main( int argc, char **argv )
+{
+  Application application = Application::New( &argc, &argv );
+
+  RunTest( application );
+
+  return 0;
+}
diff --git a/resources/images/application-icon-7-RGB565.png b/resources/images/application-icon-7-RGB565.png
new file mode 100644 (file)
index 0000000..bdbc28b
Binary files /dev/null and b/resources/images/application-icon-7-RGB565.png differ
diff --git a/resources/images/mask-large.png b/resources/images/mask-large.png
new file mode 100644 (file)
index 0000000..e280f35
Binary files /dev/null and b/resources/images/mask-large.png differ
diff --git a/resources/images/mask.png b/resources/images/mask.png
new file mode 100644 (file)
index 0000000..b3e423c
Binary files /dev/null and b/resources/images/mask.png differ
diff --git a/resources/images/mask.xcf b/resources/images/mask.xcf
new file mode 100644 (file)
index 0000000..b9628d0
Binary files /dev/null and b/resources/images/mask.xcf differ
diff --git a/resources/images/people-medium-7-masked.png b/resources/images/people-medium-7-masked.png
new file mode 100644 (file)
index 0000000..d94b586
Binary files /dev/null and b/resources/images/people-medium-7-masked.png differ
diff --git a/resources/images/people-medium-7-rgb565.png b/resources/images/people-medium-7-rgb565.png
new file mode 100644 (file)
index 0000000..07fa790
Binary files /dev/null and b/resources/images/people-medium-7-rgb565.png differ
diff --git a/resources/images/people-small-7b.jpg b/resources/images/people-small-7b.jpg
new file mode 100644 (file)
index 0000000..dd62dab
Binary files /dev/null and b/resources/images/people-small-7b.jpg differ
index 4c9c8f12b55e7e86dab6cab9c92afe83f49ce89b..7bd406512897ce5fdaf583dafa8e2f811faed4f9 100755 (executable)
@@ -4,6 +4,9 @@ msgstr "Animated Images"
 msgid "DALI_DEMO_STR_TITLE_ANIMATED_SHAPES"
 msgstr "Animated Shapes"
 
+msgid "DALI_DEMO_STR_TITLE_ALPHA_BLENDING_CPU"
+msgstr "CPU Alpha Blending"
+
 msgid "DALI_DEMO_STR_TITLE_BASIC_LIGHT"
 msgstr "Basic Light"
 
index ee9e456caa8290d5df1eee1925afd9eb691247ac..a1f44eaf4375622a9b29dd81156bbe5522c1649e 100755 (executable)
@@ -4,6 +4,9 @@ msgstr "Animated Images"
 msgid "DALI_DEMO_STR_TITLE_ANIMATED_SHAPES"
 msgstr "Animated Shapes"
 
+msgid "DALI_DEMO_STR_TITLE_ALPHA_BLENDING_CPU"
+msgstr "CPU Alpha Blending"
+
 msgid "DALI_DEMO_STR_TITLE_BASIC_LIGHT"
 msgstr "Basic Light"
 
index adc0bcaf0777e221822ce7462f69ebf027901a8c..ab83d1f1a79752dfa0623e888dd05ce2fe397b1d 100644 (file)
@@ -34,6 +34,7 @@ extern "C"
 
 #define DALI_DEMO_STR_TITLE_ANIMATED_IMAGES             dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_ANIMATED_IMAGES")
 #define DALI_DEMO_STR_TITLE_ANIMATED_SHAPES             dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_ANIMATED_SHAPES")
+#define DALI_DEMO_STR_TITLE_ALPHA_BLENDING_CPU          dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_ALPHA_BLENDING_CPU")
 #define DALI_DEMO_STR_TITLE_BASIC_LIGHT                 dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_BASIC_LIGHT")
 #define DALI_DEMO_STR_TITLE_BLOCKS                      dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_BLOCKS")
 #define DALI_DEMO_STR_TITLE_BUBBLES                     dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_BUBBLES")
@@ -98,6 +99,7 @@ extern "C"
 
 #define DALI_DEMO_STR_TITLE_ANIMATED_IMAGES             "Animated Images"
 #define DALI_DEMO_STR_TITLE_ANIMATED_SHAPES             "Animated Shapes"
+#define DALI_DEMO_STR_TITLE_ALPHA_BLENDING_CPU          "CPU Alpha Blending"
 #define DALI_DEMO_STR_TITLE_BASIC_LIGHT                 "Basic Light"
 #define DALI_DEMO_STR_TITLE_BLOCKS                      "Blocks"
 #define DALI_DEMO_STR_TITLE_BUBBLES                     "Bubbles"