X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fimage-loader%2Fimage-load-thread.cpp;h=eba2eefa5e833c11577790974b2ec0de7ef96350;hp=f687af6cb7236eb7756b51bd0ab57f51ab8a63bb;hb=09edf9d2bb567a61a1e3f4900dbc5d44d456fe5d;hpb=246cad9dd94fc8b5f7114b0e5eb8841a6cd970c9 diff --git a/dali-toolkit/internal/image-loader/image-load-thread.cpp b/dali-toolkit/internal/image-loader/image-load-thread.cpp index f687af6..eba2eef 100644 --- a/dali-toolkit/internal/image-loader/image-load-thread.cpp +++ b/dali-toolkit/internal/image-loader/image-load-thread.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Samsung Electronics Co., Ltd. + * 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. @@ -20,8 +20,9 @@ // EXTERNAL INCLUDES #include -#include #include +#include +#include namespace Dali { @@ -32,6 +33,24 @@ namespace Toolkit namespace Internal { +LoadingTask::LoadingTask( uint32_t id, Dali::AnimatedImageLoading animatedImageLoading, uint32_t frameIndex ) +: pixelBuffer(), + url(), + id( id ), + dimensions(), + fittingMode(), + samplingMode(), + orientationCorrection(), + preMultiplyOnLoad( DevelAsyncImageLoader::PreMultiplyOnLoad::OFF ), + isMaskTask( false ), + maskPixelBuffer(), + contentScale( 1.0f ), + cropToMask( false ), + animatedImageLoading( animatedImageLoading ), + frameIndex( frameIndex ) +{ +} + LoadingTask::LoadingTask( uint32_t id, const VisualUrl& url, ImageDimensions dimensions, FittingMode::Type fittingMode, SamplingMode::Type samplingMode, bool orientationCorrection, DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad ) : pixelBuffer(), @@ -45,11 +64,14 @@ LoadingTask::LoadingTask( uint32_t id, const VisualUrl& url, ImageDimensions dim isMaskTask( false ), maskPixelBuffer(), contentScale( 1.0f ), - cropToMask( false ) + cropToMask( false ), + animatedImageLoading(), + frameIndex( 0u ) { } -LoadingTask::LoadingTask( uint32_t id, Devel::PixelBuffer pixelBuffer, Devel::PixelBuffer maskPixelBuffer, float contentScale, bool cropToMask ) +LoadingTask::LoadingTask( uint32_t id, Devel::PixelBuffer pixelBuffer, Devel::PixelBuffer maskPixelBuffer, float contentScale, bool cropToMask, + DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad ) : pixelBuffer( pixelBuffer ), url( "" ), id( id ), @@ -57,17 +79,23 @@ LoadingTask::LoadingTask( uint32_t id, Devel::PixelBuffer pixelBuffer, Devel::Pi fittingMode(), samplingMode(), orientationCorrection(), - preMultiplyOnLoad(), + preMultiplyOnLoad( preMultiplyOnLoad ), isMaskTask( true ), maskPixelBuffer( maskPixelBuffer ), contentScale( contentScale ), - cropToMask( cropToMask ) + cropToMask( cropToMask ), + animatedImageLoading(), + frameIndex( 0u ) { } void LoadingTask::Load() -{ - if( url.IsLocalResource() ) +{; + if( animatedImageLoading ) + { + pixelBuffer = animatedImageLoading.LoadFrame( frameIndex ); + } + else if( url.IsLocalResource() ) { pixelBuffer = Dali::LoadImageFromFile( url.GetUrl(), dimensions, fittingMode, samplingMode, orientationCorrection ); } @@ -76,12 +104,9 @@ void LoadingTask::Load() pixelBuffer = Dali::DownloadImageSynchronously ( url.GetUrl(), dimensions, fittingMode, samplingMode, orientationCorrection ); } - if( pixelBuffer && Pixel::HasAlpha( pixelBuffer.GetPixelFormat() ) ) + if( !pixelBuffer ) { - if( preMultiplyOnLoad == DevelAsyncImageLoader::PreMultiplyOnLoad::ON ) - { - pixelBuffer.MultiplyColorByAlpha(); - } + DALI_LOG_ERROR( "LoadingTask::Load: Loading is failed: %s\n", url.GetUrl().c_str() ); } } @@ -90,6 +115,17 @@ void LoadingTask::ApplyMask() pixelBuffer.ApplyMask( maskPixelBuffer, contentScale, cropToMask ); } +void LoadingTask::MultiplyAlpha() +{ + if( pixelBuffer && Pixel::HasAlpha( pixelBuffer.GetPixelFormat() ) ) + { + if( preMultiplyOnLoad == DevelAsyncImageLoader::PreMultiplyOnLoad::ON ) + { + pixelBuffer.MultiplyColorByAlpha(); + } + } +} + ImageLoadThread::ImageLoadThread( EventThreadCallback* trigger ) : mTrigger( trigger ), mLogFactory( Dali::Adaptor::Get().GetLogFactory() ) @@ -104,6 +140,18 @@ ImageLoadThread::~ImageLoadThread() Join(); delete mTrigger; + + for( auto&& iter : mLoadQueue ) + { + delete iter; + } + mLoadQueue.Clear(); + + for( auto&& iter : mCompleteQueue ) + { + delete iter; + } + mCompleteQueue.Clear(); } void ImageLoadThread::Run() @@ -121,6 +169,7 @@ void ImageLoadThread::Run() { task->ApplyMask(); } + task->MultiplyAlpha(); AddCompletedTask( task ); } @@ -129,7 +178,6 @@ void ImageLoadThread::Run() void ImageLoadThread::AddTask( LoadingTask* task ) { bool wasEmpty = false; - { // Lock while adding task to the queue ConditionalWait::ScopedLock lock( mConditionalWait );