image-view: Add tvg image format 26/263426/7
authorJunsuChoi <jsuya.choi@samsung.com>
Thu, 2 Sep 2021 06:22:54 +0000 (15:22 +0900)
committerJunsuChoi <jsuya.choi@samsung.com>
Mon, 27 Sep 2021 05:47:04 +0000 (14:47 +0900)
Change-Id: I17c2968badef555ffe9562cba928b379668e6894

automated-tests/resources/test.tvg [new file with mode: 0644]
automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp
dali-toolkit/internal/visuals/visual-factory-impl.cpp
dali-toolkit/internal/visuals/visual-url.cpp
dali-toolkit/internal/visuals/visual-url.h

diff --git a/automated-tests/resources/test.tvg b/automated-tests/resources/test.tvg
new file mode 100644 (file)
index 0000000..78bb48f
Binary files /dev/null and b/automated-tests/resources/test.tvg differ
index 0450040..46d77a4 100644 (file)
@@ -2883,6 +2883,27 @@ int UtcDaliImageViewSvgRasterizationFailure(void)
   END_TEST;
 }
 
+int UtcDaliImageViewTVGLoading(void)
+{
+  ToolkitTestApplication application;
+
+  tet_infoline("ImageView Testing TVG image loading");
+
+  {
+    ImageView imageView = ImageView::New( );
+
+    imageView.SetImage( TEST_RESOURCE_DIR "/test.tvg" );
+
+    application.GetScene().Add( imageView );
+    DALI_TEST_CHECK( imageView );
+    Vector3 naturalSize = imageView.GetNaturalSize();
+
+    DALI_TEST_EQUALS( naturalSize.width, 100.0f, TEST_LOCATION );
+    DALI_TEST_EQUALS( naturalSize.height, 100.0f, TEST_LOCATION );
+  }
+  END_TEST;
+}
+
 namespace
 {
 
index 8c4b2f8..b86dcf0 100644 (file)
@@ -154,6 +154,7 @@ Toolkit::Visual::Base VisualFactory::CreateVisual(const Property::Map& propertyM
                 visualPtr = NPatchVisual::New(GetFactoryCache(), GetImageVisualShaderFactory(), visualUrl, propertyMap);
                 break;
               }
+              case VisualUrl::TVG:
               case VisualUrl::SVG:
               {
                 visualPtr = SvgVisual::New(GetFactoryCache(), GetImageVisualShaderFactory(), visualUrl, propertyMap);
@@ -318,6 +319,7 @@ Toolkit::Visual::Base VisualFactory::CreateVisual(const std::string& url, ImageD
         visualPtr = NPatchVisual::New(GetFactoryCache(), GetImageVisualShaderFactory(), visualUrl);
         break;
       }
+      case VisualUrl::TVG:
       case VisualUrl::SVG:
       {
         visualPtr = SvgVisual::New(GetFactoryCache(), GetImageVisualShaderFactory(), visualUrl);
index 30d9c02..0ad5778 100644 (file)
@@ -118,7 +118,9 @@ VisualUrl::Type ResolveType(const std::string& url)
     char         GIF[4]    = {'f', 'i', 'g', '.'};
     char         WEBP[5]   = {'p', 'b', 'e', 'w', '.'};
     char         JSON[5]   = {'n', 'o', 's', 'j', '.'};
+    char         TVG[4]    = {'g', 'v', 't', '.'};
     unsigned int svgScore  = 0;
+    unsigned int tvgScore  = 0;
     unsigned int gifScore  = 0;
     unsigned int webpScore = 0;
     unsigned int jsonScore = 0;
@@ -135,6 +137,14 @@ VisualUrl::Type ResolveType(const std::string& url)
           return VisualUrl::SVG;
         }
       }
+      if((offsetFromEnd < sizeof(TVG)) && (currentChar == TVG[offsetFromEnd]))
+      {
+        // early out if TVG as can't be used in N patch for now
+        if(++tvgScore == sizeof(TVG))
+        {
+          return VisualUrl::TVG;
+        }
+      }
       if((offsetFromEnd < sizeof(GIF)) && (currentChar == GIF[offsetFromEnd]))
       {
         // early out if GIF as can't be used in N patch for now
index 555e383..08a276a 100644 (file)
@@ -38,7 +38,8 @@ public:
     SVG,
     GIF,
     WEBP,
-    JSON
+    JSON,
+    TVG
   };
 
   enum ProtocolType