Util functions that convert a kind of buffers to url 16/234316/9
authorSeungho, Baek <sbsh.baek@samsung.com>
Mon, 25 May 2020 11:02:03 +0000 (20:02 +0900)
committerSeungho, Baek <sbsh.baek@samsung.com>
Thu, 4 Jun 2020 03:54:14 +0000 (12:54 +0900)
 - FrameBuffer without attached texture.
 - FrameBuffer already attached several textures
 - PixelData
 - NativeImageSource

Change-Id: I1793edf375dbdbe9dafc48432fbeb474904d9f46
Signed-off-by: Seungho, Baek <sbsh.baek@samsung.com>
automated-tests/src/dali-toolkit/CMakeLists.txt
automated-tests/src/dali-toolkit/utc-Dali-Image.cpp [new file with mode: 0644]
dali-toolkit/public-api/file.list
dali-toolkit/public-api/image-loader/image.cpp [new file with mode: 0644]
dali-toolkit/public-api/image-loader/image.h [new file with mode: 0644]

index 7e1f18b..f87d48c 100755 (executable)
@@ -21,6 +21,7 @@ SET(TC_SOURCES
   utc-Dali-FlexContainer.cpp
   utc-Dali-FlexNode.cpp
   utc-Dali-GaussianBlurView.cpp
   utc-Dali-FlexContainer.cpp
   utc-Dali-FlexNode.cpp
   utc-Dali-GaussianBlurView.cpp
+  utc-Dali-Image.cpp
   utc-Dali-ImageView.cpp
   utc-Dali-ImageVisual.cpp
   utc-Dali-JsonParser.cpp
   utc-Dali-ImageView.cpp
   utc-Dali-ImageVisual.cpp
   utc-Dali-JsonParser.cpp
diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Image.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Image.cpp
new file mode 100644 (file)
index 0000000..f19d181
--- /dev/null
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2019 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 <iostream>
+#include <stdlib.h>
+#include <dali-toolkit-test-suite-utils.h>
+#include <dali/public-api/rendering/texture.h>
+#include <dali/public-api/images/pixel-data.h>
+#include <dali/public-api/rendering/frame-buffer.h>
+#include <dali/public-api/adaptor-framework/native-image-source.h>
+#include <dali-toolkit/public-api/image-loader/image.h>
+
+using namespace Dali;
+using namespace Dali::Toolkit;
+
+namespace
+{
+} // namespace
+
+
+void dali_image_startup(void)
+{
+  test_return_value = TET_UNDEF;
+}
+
+void dali_image_cleanup(void)
+{
+  test_return_value = TET_PASS;
+}
+
+int UtcDaliImageConvertFrameBufferToUrl1(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline( "UtcDaliImageConvertFrameBufferToUrl1" );
+
+  unsigned int width(64);
+  unsigned int height(64);
+  FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
+
+  DALI_TEST_CHECK( frameBuffer );
+  std::string url = Dali::Toolkit::Image::GenerateUrl( frameBuffer, Pixel::Format::RGBA8888, width, height );
+
+  DALI_TEST_CHECK( url.size() > 0u );
+
+  END_TEST;
+}
+
+
+int UtcDaliImageConvertFrameBufferToUrl2(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline( "UtcDaliImageConvertFrameBufferToUrl2" );
+
+  unsigned int width(64);
+  unsigned int height(64);
+  FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
+
+  Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
+  frameBuffer.AttachColorTexture( texture );
+
+  DALI_TEST_CHECK( Dali::Toolkit::Image::GenerateUrl( frameBuffer, 0 ).size() > 0u );
+
+  END_TEST;
+}
+
+
+int UtcDaliImageConvertPixelDataToUrl(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline( "UtcDaliImageConvertPixelDataToUrl" );
+
+  unsigned int width(64);
+  unsigned int height(64);
+  unsigned int bufferSize = width*height*Pixel::GetBytesPerPixel( Pixel::RGB888 );
+
+  unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
+  PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGB888, PixelData::FREE );
+
+  DALI_TEST_CHECK( Dali::Toolkit::Image::GenerateUrl( pixelData ).size() > 0u );
+
+  END_TEST;
+}
+
+
+int UtcDaliImageConvertNativeImageSourceToUrl(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline( "UtcDaliImageConvertNativeImageSourceToUrl" );
+
+  unsigned int width(64);
+  unsigned int height(64);
+  try
+  {
+    NativeImageSourcePtr nativeImageSource = NativeImageSource::New(width, height, NativeImageSource::COLOR_DEPTH_DEFAULT );
+
+    DALI_TEST_CHECK( Dali::Toolkit::Image::GenerateUrl( nativeImageSource ).size() > 0u );
+  }
+  catch(Dali::DaliException& e)
+  {
+    DALI_TEST_PRINT_ASSERT( e );
+    DALI_TEST_ASSERT(e, "Adaptor::IsAvailable()", TEST_LOCATION);
+  }
+  catch(...)
+  {
+    tet_printf("Assertion test failed - wrong Exception\n" );
+    tet_result(TET_FAIL);
+  }
+
+  END_TEST;
+}
index 732531f..3aa3c5b 100644 (file)
@@ -29,6 +29,7 @@ SET( public_api_src_files
   ${public_api_src_dir}/controls/text-controls/text-label.cpp
   ${public_api_src_dir}/controls/text-controls/text-field.cpp
   ${public_api_src_dir}/controls/video-view/video-view.cpp
   ${public_api_src_dir}/controls/text-controls/text-label.cpp
   ${public_api_src_dir}/controls/text-controls/text-field.cpp
   ${public_api_src_dir}/controls/video-view/video-view.cpp
+  ${public_api_src_dir}/image-loader/image.cpp
   ${public_api_src_dir}/image-loader/async-image-loader.cpp
   ${public_api_src_dir}/image-loader/sync-image-loader.cpp
   ${public_api_src_dir}/styling/style-manager.cpp
   ${public_api_src_dir}/image-loader/async-image-loader.cpp
   ${public_api_src_dir}/image-loader/sync-image-loader.cpp
   ${public_api_src_dir}/styling/style-manager.cpp
@@ -85,6 +86,7 @@ SET( public_api_item_view_header_files
 )
 
 SET( public_api_image_loader_header_files
 )
 
 SET( public_api_image_loader_header_files
+  ${public_api_src_dir}/image-loader/image.h
   ${public_api_src_dir}/image-loader/async-image-loader.h
   ${public_api_src_dir}/image-loader/sync-image-loader.h
 )
   ${public_api_src_dir}/image-loader/async-image-loader.h
   ${public_api_src_dir}/image-loader/sync-image-loader.h
 )
diff --git a/dali-toolkit/public-api/image-loader/image.cpp b/dali-toolkit/public-api/image-loader/image.cpp
new file mode 100644 (file)
index 0000000..2645c07
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2020 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.
+ */
+
+// CLASS HEADER
+#include "image.h"
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/devel-api/image-loader/texture-manager.h>
+
+// EXTERNAL INCLUDES
+#include <dali/devel-api/rendering/frame-buffer-devel.h>
+
+namespace Dali
+{
+
+namespace Toolkit
+{
+
+namespace Image
+{
+
+std::string GenerateUrl( Dali::FrameBuffer frameBuffer, Pixel::Format pixelFormat, uint32_t width, uint32_t height )
+{
+  Texture texture = Texture::New( Dali::TextureType::TEXTURE_2D, pixelFormat, width, height );
+  frameBuffer.AttachColorTexture( texture, 0u, 0u );
+  return Dali::Toolkit::TextureManager::AddTexture( texture );
+}
+
+std::string GenerateUrl( const Dali::FrameBuffer frameBuffer, const uint8_t index )
+{
+  Texture texture = Dali::DevelFrameBuffer::GetColorTexture( frameBuffer, index );
+  return Dali::Toolkit::TextureManager::AddTexture( texture );
+}
+
+std::string GenerateUrl( const Dali::PixelData pixelData )
+{
+  Texture texture = Texture::New( TextureType::TEXTURE_2D, pixelData.GetPixelFormat(), pixelData.GetWidth(), pixelData.GetHeight() );
+  texture.Upload( pixelData );
+  return Dali::Toolkit::TextureManager::AddTexture( texture );
+}
+
+std::string GenerateUrl( const Dali::NativeImageSourcePtr nativeImageSource )
+{
+  Texture texture = Dali::Texture::New( *nativeImageSource );
+  return Dali::Toolkit::TextureManager::AddTexture( texture );
+}
+
+} // TextureManager
+
+} // Toolkit
+
+} // Dali
diff --git a/dali-toolkit/public-api/image-loader/image.h b/dali-toolkit/public-api/image-loader/image.h
new file mode 100644 (file)
index 0000000..7d27215
--- /dev/null
@@ -0,0 +1,89 @@
+#ifndef DALI_TOOLKIT_DEVEL_API_IMAGE_MANAGER_H
+#define DALI_TOOLKIT_DEVEL_API_IMAGE_MANAGER_H
+
+/*
+ * Copyright (c) 2020 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.
+ */
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/images/pixel-data.h>
+#include <dali/public-api/rendering/frame-buffer.h>
+#include <dali/public-api/adaptor-framework/native-image-source.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/public-api/dali-toolkit-common.h>
+
+namespace Dali
+{
+
+namespace Toolkit
+{
+
+/**
+ * API to interface with the toolkit image
+ * Allows developers to add FrameBuffer, PixelData and NativeImageSource to toolkit so that visuals can use them to render
+ */
+namespace Image
+{
+
+/**
+ * @brief Generate a Url from frame buffer.
+ * This Url can be used in visuals to render the frame buffer.
+ * @note Any color textures already attached in this freme buffer are not converted to the Url by this method.
+ * This method does not check for duplicates, If same frame buffer is entered multiple times, a different URL is returned each time.
+ * @param[in] frameBuffer the frame buffer to converted to Url
+ * @param[in] pixelFormat the pixel format for this frame buffer
+ * @param[in] width the width for this frame buffer
+ * @param[in] height the height for this frame buffer
+ * @return the Url string representing this frame buffer
+ */
+DALI_TOOLKIT_API std::string GenerateUrl( const Dali::FrameBuffer frameBuffer, Pixel::Format pixelFormat, uint32_t width, uint32_t height );
+
+/**
+ * @brief Generate a Url from frame buffer.
+ * This Url can be used in visuals to render the frame buffer.
+ * @note Only an color texture already attached in this frame buffer can be convert to Url by this method.
+ * This method does not check for duplicates, If same frame buffer is entered multiple times, a different URL is returned each time.
+ * @param[in] frameBuffer the frame buffer to converted to Url
+ * @param[in] index the index of the attached color texture.
+ * @return the Url string representing this frame buffer
+ */
+DALI_TOOLKIT_API std::string GenerateUrl( const Dali::FrameBuffer frameBuffer, const uint8_t index );
+
+/**
+ * @brief Generate a Url from Pixel data.
+ * This Url can be used in visuals to render the pixel data.
+ * @note This method does not check for duplicates, If same pixel data is entered multiple times, a different URL is returned each time.
+ * @param[in] pixelData the pixel data to converted to Url
+ * @return the Url string representing this pixel data
+ */
+DALI_TOOLKIT_API std::string GenerateUrl( const Dali::PixelData pixelData );
+
+/**
+ * @brief Generate a Url from native image source.
+ * This Url can be used in visuals to render the native image source.
+ * @note This method does not check for duplicates, If same native image source is entered multiple times, a different URL is returned each time.
+ * @param[in] nativeImageSource the native image source to converted to Url
+ * @return the Url string representing this native image source
+ */
+DALI_TOOLKIT_API std::string GenerateUrl( const Dali::NativeImageSourcePtr nativeImageSource );
+
+} // ImageUtil
+
+} // Toolkit
+
+} // Dali
+
+#endif // DALI_TOOLKIT_DEVEL_API_IMAGE_MANAGER_H