From: Heeyong Song Date: Thu, 3 Feb 2022 05:18:10 +0000 (+0900) Subject: Add stride to PixelData X-Git-Tag: dali_2.1.10~2^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-core.git;a=commitdiff_plain;h=53a534bebeb0f32519aa030f65d037f858b974e7 Add stride to PixelData Change-Id: Ida564386962e1afed91d3f6805b5a14f446a6937 --- diff --git a/automated-tests/src/dali/utc-Dali-PixelData.cpp b/automated-tests/src/dali/utc-Dali-PixelData.cpp index 419a4d5..bf80314 100644 --- a/automated-tests/src/dali/utc-Dali-PixelData.cpp +++ b/automated-tests/src/dali/utc-Dali-PixelData.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -58,6 +58,50 @@ int UtcDaliPixelData02(void) DALI_TEST_CHECK(pixelData); DALI_TEST_CHECK(pixelData.GetWidth() == width); DALI_TEST_CHECK(pixelData.GetHeight() == height); + DALI_TEST_CHECK(pixelData.GetStride() == 0); + DALI_TEST_CHECK(pixelData.GetPixelFormat() == Pixel::L8); + + END_TEST; +} + +int UtcDaliPixelData03(void) +{ + TestApplication application; + + uint32_t width = 10u; + uint32_t height = 10u; + uint32_t stride = 12u; + uint32_t bufferSize = stride * height * Pixel::GetBytesPerPixel(Pixel::RGB888); + + uint8_t* buffer = reinterpret_cast(malloc(bufferSize)); + PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, stride, Pixel::RGB888, PixelData::FREE); + + DALI_TEST_CHECK(pixelData); + DALI_TEST_CHECK(pixelData.GetWidth() == width); + DALI_TEST_CHECK(pixelData.GetHeight() == height); + DALI_TEST_CHECK(pixelData.GetStride() == stride); + DALI_TEST_CHECK(pixelData.GetPixelFormat() == Pixel::RGB888); + + END_TEST; +} + +int UtcDaliPixelData04(void) +{ + TestApplication application; + + uint32_t width = 10u; + uint32_t height = 10u; + uint32_t stride = 12u; + uint32_t bufferSize = stride * height * Pixel::GetBytesPerPixel(Pixel::L8); + uint8_t* buffer = new uint8_t[bufferSize]; + buffer[0] = 'a'; + + PixelData pixelData = PixelData::New(buffer, bufferSize, width, height, stride, Pixel::L8, PixelData::DELETE_ARRAY); + + DALI_TEST_CHECK(pixelData); + DALI_TEST_CHECK(pixelData.GetWidth() == width); + DALI_TEST_CHECK(pixelData.GetHeight() == height); + DALI_TEST_CHECK(pixelData.GetStride() == stride); DALI_TEST_CHECK(pixelData.GetPixelFormat() == Pixel::L8); END_TEST; diff --git a/dali/graphics-api/graphics-types.h b/dali/graphics-api/graphics-types.h index 55816f5..84f0fd3 100644 --- a/dali/graphics-api/graphics-types.h +++ b/dali/graphics-api/graphics-types.h @@ -2,7 +2,7 @@ #define DALI_GRAPHICS_API_TYPES /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -943,6 +943,7 @@ struct TextureUpdateInfo Extent2D srcExtent2D{}; uint32_t srcOffset{}; uint32_t srcSize{}; + uint32_t srcStride{}; Format srcFormat{}; ///< Should match dstTexture's format, otherwise conversion may occur }; diff --git a/dali/internal/event/images/pixel-data-impl.cpp b/dali/internal/event/images/pixel-data-impl.cpp index 23a1e1c..622f867 100644 --- a/dali/internal/event/images/pixel-data-impl.cpp +++ b/dali/internal/event/images/pixel-data-impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -26,12 +26,14 @@ PixelData::PixelData(uint8_t* buffer, uint32_t bufferSize, uint32_t width, uint32_t height, + uint32_t stride, Pixel::Format pixelFormat, Dali::PixelData::ReleaseFunction releaseFunction) : mBuffer(buffer), mBufferSize(bufferSize), mWidth(width), mHeight(height), + mStride(stride), mPixelFormat(pixelFormat), mReleaseFunction(releaseFunction) { @@ -56,10 +58,11 @@ PixelDataPtr PixelData::New(uint8_t* buffer, uint32_t bufferSize, uint32_t width, uint32_t height, + uint32_t stride, Pixel::Format pixelFormat, Dali::PixelData::ReleaseFunction releaseFunction) { - return new PixelData(buffer, bufferSize, width, height, pixelFormat, releaseFunction); + return new PixelData(buffer, bufferSize, width, height, stride, pixelFormat, releaseFunction); } uint32_t PixelData::GetWidth() const @@ -94,6 +97,11 @@ DevelPixelData::PixelDataBuffer PixelData::ReleaseBuffer() return pixelDataBuffer; } +uint32_t PixelData::GetStride() const +{ + return mStride; +} + } // namespace Internal } // namespace Dali diff --git a/dali/internal/event/images/pixel-data-impl.h b/dali/internal/event/images/pixel-data-impl.h index bac08db..5667496 100644 --- a/dali/internal/event/images/pixel-data-impl.h +++ b/dali/internal/event/images/pixel-data-impl.h @@ -2,7 +2,7 @@ #define DALI_INTERNAL_PIXEL_DATA_H /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -40,6 +40,7 @@ public: * @param [in] bufferSize The size of the buffer in bytes * @param [in] width Buffer width in pixels * @param [in] height Buffer height in pixels + * @param [in] stride Buffer stride in pixels, 0 means the buffer is tightly packed * @param [in] pixelFormat The pixel format * @param [in] releaseFunction The function used to release the memory. */ @@ -47,6 +48,7 @@ public: uint32_t bufferSize, uint32_t width, uint32_t height, + uint32_t stride, Pixel::Format pixelFormat, Dali::PixelData::ReleaseFunction releaseFunction); @@ -57,6 +59,7 @@ public: * @param [in] bufferSize The size of the buffer in bytes * @param [in] width Buffer width in pixels * @param [in] height Buffer height in pixels + * @param [in] stride Buffer stride in pixels, 0 means the buffer is tightly packed * @param [in] pixelFormat The pixel format * @param [in] releaseFunction The function used to release the memory. */ @@ -64,6 +67,7 @@ public: uint32_t bufferSize, uint32_t width, uint32_t height, + uint32_t stride, Pixel::Format pixelFormat, Dali::PixelData::ReleaseFunction releaseFunction); @@ -112,6 +116,11 @@ public: */ DevelPixelData::PixelDataBuffer ReleaseBuffer(); + /** + * @copydoc PixelData::GetStride() + */ + uint32_t GetStride() const; + private: /* * Undefined copy constructor. @@ -125,9 +134,10 @@ private: private: uint8_t* mBuffer; ///< The raw pixel data - uint32_t mBufferSize; ///< Buffer sized in bytes + uint32_t mBufferSize; ///< Buffer size in bytes uint32_t mWidth; ///< Buffer width in pixels uint32_t mHeight; ///< Buffer height in pixels + uint32_t mStride; ///< Buffer stride in pixels, 0 means the buffer is tightly packed Pixel::Format mPixelFormat; ///< Pixel format Dali::PixelData::ReleaseFunction mReleaseFunction; ///< Function for releasing memory }; diff --git a/dali/internal/render/renderers/render-texture.cpp b/dali/internal/render/renderers/render-texture.cpp index 0fb1cec..8887251 100644 --- a/dali/internal/render/renderers/render-texture.cpp +++ b/dali/internal/render/renderers/render-texture.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -289,6 +289,7 @@ void Texture::Upload(PixelDataPtr pixelData, const Internal::Texture::UploadPara info.srcExtent2D = {params.width, params.height}; info.srcOffset = 0; info.srcSize = pixelData->GetBufferSize(); + info.srcStride = pixelData->GetStride(); info.srcFormat = ConvertPixelFormat(pixelData->GetPixelFormat()); Graphics::TextureUpdateSourceInfo updateSourceInfo{}; diff --git a/dali/public-api/images/pixel-data.cpp b/dali/public-api/images/pixel-data.cpp index 7086e7d..2356c4b 100644 --- a/dali/public-api/images/pixel-data.cpp +++ b/dali/public-api/images/pixel-data.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -30,7 +30,19 @@ PixelData PixelData::New(uint8_t* buffer, Pixel::Format pixelFormat, ReleaseFunction releaseFunction) { - IntrusivePtr internal = Internal::PixelData::New(buffer, bufferSize, width, height, pixelFormat, releaseFunction); + IntrusivePtr internal = Internal::PixelData::New(buffer, bufferSize, width, height, 0, pixelFormat, releaseFunction); + return PixelData(internal.Get()); +} + +PixelData PixelData::New(uint8_t* buffer, + uint32_t bufferSize, + uint32_t width, + uint32_t height, + uint32_t stride, + Pixel::Format pixelFormat, + ReleaseFunction releaseFunction) +{ + IntrusivePtr internal = Internal::PixelData::New(buffer, bufferSize, width, height, stride, pixelFormat, releaseFunction); return PixelData(internal.Get()); } @@ -66,4 +78,9 @@ Pixel::Format PixelData::GetPixelFormat() const return GetImplementation(*this).GetPixelFormat(); } +uint32_t PixelData::GetStride() const +{ + return GetImplementation(*this).GetStride(); +} + } // namespace Dali diff --git a/dali/public-api/images/pixel-data.h b/dali/public-api/images/pixel-data.h index 03fefc6..b7778d5 100644 --- a/dali/public-api/images/pixel-data.h +++ b/dali/public-api/images/pixel-data.h @@ -2,7 +2,7 @@ #define DALI_PIXEL_DATA_H /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * Copyright (c) 2022 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. @@ -77,6 +77,26 @@ public: ReleaseFunction releaseFunction); /** + * @brief Creates a PixelData object. + * + * @SINCE_2_1.10 + * @param[in] buffer The raw pixel data + * @param[in] bufferSize The size of the buffer in bytes + * @param[in] width Buffer width in pixels + * @param[in] height Buffer height in pixels + * @param[in] stride Buffer stride in pixels, 0 means the buffer is tightly packed + * @param[in] pixelFormat The pixel format + * @param[in] releaseFunction The function used to release the memory + * @return A handle to the PixelData + */ + static PixelData New(uint8_t* buffer, + uint32_t bufferSize, + uint32_t width, + uint32_t height, + uint32_t stride, + Pixel::Format pixelFormat, + ReleaseFunction releaseFunction); + /** * @brief Creates an empty handle. * Use PixelData::New() to create an initialized object. * @@ -149,6 +169,14 @@ public: */ Pixel::Format GetPixelFormat() const; + /** + * @brief Gets the stride of the buffer in pixels. + * + * @SINCE_2_1.10 + * @return The stride of the buffer in pixels. 0 means the buffer is tightly packed. + */ + uint32_t GetStride() const; + public: /** * @brief The constructor.