From 54bdcbd00f206dba5af21fd603bed6469caede43 Mon Sep 17 00:00:00 2001 From: "Seungho, Baek" Date: Mon, 25 May 2020 20:02:03 +0900 Subject: [PATCH 1/1] Util functions that convert a kind of buffers to url - FrameBuffer without attached texture. - FrameBuffer already attached several textures - PixelData - NativeImageSource Change-Id: I1793edf375dbdbe9dafc48432fbeb474904d9f46 Signed-off-by: Seungho, Baek --- automated-tests/src/dali-toolkit/CMakeLists.txt | 1 + .../src/dali-toolkit/utc-Dali-Image.cpp | 123 +++++++++++++++++++++ dali-toolkit/public-api/file.list | 2 + dali-toolkit/public-api/image-loader/image.cpp | 65 +++++++++++ dali-toolkit/public-api/image-loader/image.h | 89 +++++++++++++++ 5 files changed, 280 insertions(+) create mode 100644 automated-tests/src/dali-toolkit/utc-Dali-Image.cpp create mode 100644 dali-toolkit/public-api/image-loader/image.cpp create mode 100644 dali-toolkit/public-api/image-loader/image.h diff --git a/automated-tests/src/dali-toolkit/CMakeLists.txt b/automated-tests/src/dali-toolkit/CMakeLists.txt index 7e1f18b..f87d48c 100755 --- a/automated-tests/src/dali-toolkit/CMakeLists.txt +++ b/automated-tests/src/dali-toolkit/CMakeLists.txt @@ -21,6 +21,7 @@ SET(TC_SOURCES 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 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 index 0000000..f19d181 --- /dev/null +++ b/automated-tests/src/dali-toolkit/utc-Dali-Image.cpp @@ -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 +#include +#include +#include +#include +#include +#include +#include + +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( 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; +} diff --git a/dali-toolkit/public-api/file.list b/dali-toolkit/public-api/file.list index 732531f..3aa3c5b 100644 --- a/dali-toolkit/public-api/file.list +++ b/dali-toolkit/public-api/file.list @@ -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}/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 @@ -85,6 +86,7 @@ SET( public_api_item_view_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 ) diff --git a/dali-toolkit/public-api/image-loader/image.cpp b/dali-toolkit/public-api/image-loader/image.cpp new file mode 100644 index 0000000..2645c07 --- /dev/null +++ b/dali-toolkit/public-api/image-loader/image.cpp @@ -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 + +// EXTERNAL INCLUDES +#include + +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 index 0000000..7d27215 --- /dev/null +++ b/dali-toolkit/public-api/image-loader/image.h @@ -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 +#include +#include + +// INTERNAL INCLUDES +#include + +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 -- 2.7.4