X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fimage-loader%2Fimage-atlas-impl.h;h=e302d92ad1dec03d8262b742199d69b7c960b6c3;hb=e443d5fbefaabaf421aebf83a0350ea98380a4eb;hp=25b50dea9149e9f535c068517341fc2d0202208a;hpb=3320153709e9409873ee708680b1b9eed8cb1060;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/image-loader/image-atlas-impl.h b/dali-toolkit/internal/image-loader/image-atlas-impl.h index 25b50de..e302d92 100644 --- a/dali-toolkit/internal/image-loader/image-atlas-impl.h +++ b/dali-toolkit/internal/image-loader/image-atlas-impl.h @@ -1,8 +1,8 @@ -#ifndef __DALI_TOOLKIT_IMAGE_ATLAS_IMPL_H__ -#define __DALI_TOOLKIT_IMAGE_ATLAS_IMPL_H__ +#ifndef DALI_TOOLKIT_IMAGE_ATLAS_IMPL_H +#define DALI_TOOLKIT_IMAGE_ATLAS_IMPL_H /* - * Copyright (c) 2015 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. @@ -18,15 +18,16 @@ */ // EXTERNAL INCLUDES +#include +#include #include #include #include -#include -#include // INTERNAL INCLUDES #include #include +#include #include namespace Dali @@ -35,20 +36,17 @@ class EventThreadCallback; namespace Toolkit { - namespace Internal { - class ImageAtlas : public BaseObject, public ConnectionTracker { public: - typedef Toolkit::ImageAtlas::SizeType SizeType; /** * @copydoc ImageAtlas::PackToAtlas( const std::vector&, Dali::Vector& ) */ - static Texture PackToAtlas( const std::vector& pixelData, Dali::Vector& textureRects ); + static Texture PackToAtlas(const std::vector& pixelData, Dali::Vector& textureRects); /** * Constructor @@ -56,12 +54,12 @@ public: * @param [in] height The atlas height in pixels. * @param [in] pixelFormat The pixel format. */ - ImageAtlas( SizeType width, SizeType height, Pixel::Format pixelFormat ); + ImageAtlas(SizeType width, SizeType height, Pixel::Format pixelFormat); /** * @copydoc Toolkit::ImageAtlas::New */ - static IntrusivePtr New( SizeType width, SizeType height, Pixel::Format pixelFormat ); + static IntrusivePtr New(SizeType width, SizeType height, Pixel::Format pixelFormat); /** * @copydoc Toolkit::ImageAtlas::GetAtlas @@ -76,81 +74,105 @@ public: /** * @copydoc Toolkit::ImageAtlas::SetBrokenImage */ - void SetBrokenImage( const std::string& brokenImageUrl ); + void SetBrokenImage(const std::string& brokenImageUrl); /** * @copydoc Toolkit::ImageAtlas::Upload( Vector4&, const std::string&, ImageDimensions,FittingMode::Type, bool ) */ - bool Upload( Vector4& textureRect, - const std::string& url, - ImageDimensions size, - FittingMode::Type fittingMode, - bool orientationCorrection, - AtlasUploadObserver* atlasUploadObserver ); + bool Upload(Vector4& textureRect, + const VisualUrl& url, + ImageDimensions size, + FittingMode::Type fittingMode, + bool orientationCorrection, + AtlasUploadObserver* atlasUploadObserver); + + /** + * @brief Upload a resource image to the atlas by encoded buffer. + * + * @note To make the atlasing efficient, a valid size should be provided. + * If size is not provided, then SegFault occured. + * Do not set a size that is bigger than the actual image size, as the up-scaling is not available, + * the content of the area not covered by actual image is undefined, it will not be cleared. + * + * SamplingMode::BOX_THEN_LINEAR is used to sampling pixels from the input image while fitting it to desired size. + * + * @param [out] textureRect The texture area of the resource image in the atlas. + * @param [in] encodedImageBuffer The encoded raw buffer of the resource image file to use. + * @param [in] size The width and height to fit the loaded image to. + * @param [in] fittingMode The method used to fit the shape of the image before loading to the shape defined by the size parameter. + * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header. + * @param [in] atlasUploadObserver The observer to observe the upload state inside the ImageAtlas. + * @return True if there is enough space to fit this image in,false otherwise. + * @note The valid callback function here is required to have the signature of void( void ). + */ + bool Upload(Vector4& textureRect, + const EncodedImageBuffer& encodedImageBuffer, + ImageDimensions size, + FittingMode::Type fittingMode, + bool orientationCorrection, + AtlasUploadObserver* atlasUploadObserver); /** * @copydoc Toolkit::ImageAtlas::Upload( Vector4&, PixelData ) */ - bool Upload( Vector4& textureRect, PixelData pixelData ); + bool Upload(Vector4& textureRect, PixelData pixelData); /** * @copydoc Toolkit::ImageAtlas::Remove */ - void Remove( const Vector4& textureRect ); + void Remove(const Vector4& textureRect); /** * Resets the destroying observer pointer so that we know not to call methods of this object any more. */ - void ObserverDestroyed( AtlasUploadObserver* observer ); + void ObserverDestroyed(AtlasUploadObserver* observer); protected: - /** * Destructor */ ~ImageAtlas(); private: - /** * @copydoc PixelDataRequester::ProcessPixels */ - void UploadToAtlas( uint32_t id, PixelData pixelData ); + void UploadToAtlas(uint32_t id, PixelData pixelData); /** * Upload broken image * * @param[in] area The pixel area for uploading. */ - void UploadBrokenImage( const Rect& area ); + void UploadBrokenImage(const Rect& area); // Undefined - ImageAtlas( const ImageAtlas& imageAtlas); + ImageAtlas(const ImageAtlas& imageAtlas); // Undefined - ImageAtlas& operator=( const ImageAtlas& imageAtlas ); + ImageAtlas& operator=(const ImageAtlas& imageAtlas); private: - /** * Each loading task( identified with an ID ) is associated with a rect region for packing the loaded pixel data into the atlas, * and an AtlasUploadObserver whose UploadCompleted method should get executed once the sub texture is ready. */ struct LoadingTaskInfo { - LoadingTaskInfo( unsigned short loadTaskId, - unsigned int packPositionX, - unsigned int packPositionY, - unsigned int width, - unsigned int height, - AtlasUploadObserver* observer ) - : loadTaskId( loadTaskId ), - packRect( packPositionX, packPositionY, width, height ), - observer( observer ) - {} - - unsigned short loadTaskId; - Rect packRect; + LoadingTaskInfo(uint32_t loadTaskId, + uint32_t packPositionX, + uint32_t packPositionY, + uint32_t width, + uint32_t height, + AtlasUploadObserver* observer) + : loadTaskId(loadTaskId), + packRect(packPositionX, packPositionY, width, height), + observer(observer) + { + } + + uint32_t loadTaskId; + Rect packRect; AtlasUploadObserver* observer; }; @@ -164,24 +186,22 @@ private: float mWidth; float mHeight; Pixel::Format mPixelFormat; - - }; } // namespace Internal -inline const Internal::ImageAtlas& GetImplementation( const Toolkit::ImageAtlas& imageAtlas ) +inline const Internal::ImageAtlas& GetImplementation(const Toolkit::ImageAtlas& imageAtlas) { - DALI_ASSERT_ALWAYS( imageAtlas && "ImageAtlas handle is empty" ); + DALI_ASSERT_ALWAYS(imageAtlas && "ImageAtlas handle is empty"); const BaseObject& handle = imageAtlas.GetBaseObject(); return static_cast(handle); } -inline Internal::ImageAtlas& GetImplementation( Toolkit::ImageAtlas& imageAtlas ) +inline Internal::ImageAtlas& GetImplementation(Toolkit::ImageAtlas& imageAtlas) { - DALI_ASSERT_ALWAYS( imageAtlas && "ImageAtlas handle is empty" ); + DALI_ASSERT_ALWAYS(imageAtlas && "ImageAtlas handle is empty"); BaseObject& handle = imageAtlas.GetBaseObject(); @@ -192,4 +212,4 @@ inline Internal::ImageAtlas& GetImplementation( Toolkit::ImageAtlas& imageAtlas } // namespace Dali -#endif /* __DALI_TOOLKIT_IMAGE_ATLAS_IMPL_H__ */ +#endif // DALI_TOOLKIT_IMAGE_ATLAS_IMPL_H