if(mAnimatedImageLoading)
{
- mImageCache = new RollingAnimatedImageCache(textureManager, mDesiredSize, mFittingMode, mSamplingMode, mAnimatedImageLoading, mMaskingData, *this, mCacheSize, mBatchSize, mWrapModeU, mWrapModeV, IsSynchronousLoadingRequired(), mFactoryCache.GetPreMultiplyOnLoad());
+ mImageCache = new RollingAnimatedImageCache(textureManager, mDesiredSize, mFittingMode, mSamplingMode, mAnimatedImageLoading, mMaskingData, *this, mCacheSize, mBatchSize, mWrapModeU, mWrapModeV, IsSynchronousLoadingRequired(), IsPreMultipliedAlphaEnabled());
}
else if(mImageUrls)
{
uint16_t cacheSize = std::max(std::min(std::max(batchSize, mCacheSize), numUrls), MINIMUM_CACHESIZE);
if(cacheSize < numUrls)
{
- mImageCache = new RollingImageCache(textureManager, mDesiredSize, mFittingMode, mSamplingMode, *mImageUrls, mMaskingData, *this, cacheSize, batchSize, mFrameDelay);
+ mImageCache = new RollingImageCache(textureManager, mDesiredSize, mFittingMode, mSamplingMode, *mImageUrls, mMaskingData, *this, cacheSize, batchSize, mFrameDelay, IsPreMultipliedAlphaEnabled());
}
else
{
- mImageCache = new FixedImageCache(textureManager, mDesiredSize, mFittingMode, mSamplingMode, *mImageUrls, mMaskingData, *this, batchSize, mFrameDelay);
+ mImageCache = new FixedImageCache(textureManager, mDesiredSize, mFittingMode, mSamplingMode, *mImageUrls, mMaskingData, *this, batchSize, mFrameDelay, IsPreMultipliedAlphaEnabled());
}
}
}
}
-void AnimatedImageVisual::FrameReady(TextureSet textureSet, uint32_t interval)
+void AnimatedImageVisual::FrameReady(TextureSet textureSet, uint32_t interval, bool preMultiplied)
{
+ EnablePreMultipliedAlpha(preMultiplied);
+
// When image visual requested to load new frame to mImageCache and it is failed.
if(!mImageCache || !textureSet)
{
* @brief Called when the next frame is ready.
* @param[in] textureSet the texture set to apply
* @param[in] interval interval(ms) for the frame
+ * @param[in] preMultiplied whether the texture is premultied alpha or not.
*/
- void FrameReady(TextureSet textureSet, uint32_t interval) override;
+ void FrameReady(TextureSet textureSet, uint32_t interval, bool preMultiplied) override;
/**
* @brief Display the next frame. It is called when the mFrameDelayTimer ticks.
TextureManager::MaskingDataPointer& maskingData,
ImageCache::FrameReadyObserver& observer,
uint32_t batchSize,
- uint32_t interval)
-: ImageCache(textureManager, size, fittingMode, samplingMode, maskingData, observer, batchSize, interval),
+ uint32_t interval,
+ bool preMultiplyOnLoad)
+: ImageCache(textureManager, size, fittingMode, samplingMode, maskingData, observer, batchSize, interval, preMultiplyOnLoad),
mImageUrls(urlList),
mFront(FIRST_FRAME_INDEX)
{
ImageAtlasManagerPtr imageAtlasManager = nullptr;
Vector4 textureRect;
Dali::ImageDimensions textureRectSize;
- auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
- mTextureManager.LoadTexture(url, mDesiredSize, mFittingMode, mSamplingMode, mMaskingData, synchronousLoading, mImageUrls[frameIndex].mTextureId, textureRect, textureRectSize, atlasingStatus, loadingStatus, this, atlasObserver, imageAtlasManager, ENABLE_ORIENTATION_CORRECTION, TextureManager::ReloadPolicy::CACHED, preMultiply);
+ auto preMultiplyOnLoading = mPreMultiplyOnLoad ? TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD
+ : TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
+
+ mTextureManager.LoadTexture(url, mDesiredSize, mFittingMode, mSamplingMode, mMaskingData, synchronousLoading, mImageUrls[frameIndex].mTextureId, textureRect, textureRectSize, atlasingStatus, loadingStatus, this, atlasObserver, imageAtlasManager, ENABLE_ORIENTATION_CORRECTION, TextureManager::ReloadPolicy::CACHED, preMultiplyOnLoading);
mRequestingLoad = false;
}
}
return textureSet;
}
-void FixedImageCache::CheckFrontFrame(bool wasReady)
+void FixedImageCache::CheckFrontFrame(bool wasReady, bool preMultiplied)
{
if(wasReady == false && IsFrontReady())
{
- mObserver.FrameReady(GetFrontTextureSet(), mInterval);
+ mObserver.FrameReady(GetFrontTextureSet(), mInterval, preMultiplied);
}
}
{
mReadyFlags.back() = true;
}
- CheckFrontFrame(frontFrameReady);
+ CheckFrontFrame(frontFrameReady, textureInformation.preMultiplied);
}
else
{
mLoadState = TextureManager::LoadState::LOAD_FAILED;
- mObserver.FrameReady(TextureSet(), 0);
+ // preMultiplied should be false because broken image don't premultiply alpha on load
+ mObserver.FrameReady(TextureSet(), 0, false);
}
}
public:
/**
* Constructor.
- * @param[in] textureManager The texture manager
- * @param[in] size The width and height to fit the loaded image to.
- * @param[in] fittingMode The FittingMode of the resource to load
- * @param[in] samplingMode The SamplingMode of the resource to load
- * @param[in] urlList List of urls to cache
- * @param[in] maskingData Masking data to be applied.
- * @param[in] observer FrameReady observer
- * @param[in] batchSize The size of a batch to load
- * @param[in] interval Time interval between each frame
+ * @param[in] textureManager The texture manager
+ * @param[in] size The width and height to fit the loaded image to.
+ * @param[in] fittingMode The FittingMode of the resource to load
+ * @param[in] samplingMode The SamplingMode of the resource to load
+ * @param[in] urlList List of urls to cache
+ * @param[in] maskingData Masking data to be applied.
+ * @param[in] observer FrameReady observer
+ * @param[in] batchSize The size of a batch to load
+ * @param[in] interval Time interval between each frame
+ * @param[in] preMultiplyOnLoad The flag if image's color should be multiplied by it's alpha
*
* This will start loading textures immediately, according to the
* batch and cache sizes. The cache is as large as the number of urls.
TextureManager::MaskingDataPointer& maskingData,
ImageCache::FrameReadyObserver& observer,
uint32_t batchSize,
- uint32_t interval);
+ uint32_t interval,
+ bool preMultiplyOnLoad);
~FixedImageCache() override;
* @brief Check if the front frame has become ready - if so, inform observer
*
* @param[in] wasReady Readiness before call.
+ * @param[in] preMultiplied whether the texture is premultied alpha or not.
*/
- void CheckFrontFrame(bool wasReady);
+ void CheckFrontFrame(bool wasReady, bool preMultiplied);
protected:
/**
TextureManager::MaskingDataPointer& maskingData,
ImageCache::FrameReadyObserver& observer,
uint32_t batchSize,
- uint32_t interval)
+ uint32_t interval,
+ bool preMultiplyOnLoad)
: mTextureManager(textureManager),
mObserver(observer),
mMaskingData(maskingData),
mInterval(interval),
mLoadState(TextureManager::LoadState::NOT_STARTED),
mRequestingLoad(false),
+ mPreMultiplyOnLoad(preMultiplyOnLoad),
mTextureManagerAlive(true)
{
mTextureManager.AddObserver(*this);
* @brief Informs observer when the next texture set is ready to display
* @param[in] textureSet The ready texture set
* @param[in] interval interval(ms) for the frame
+ * @param[in] preMultiplied whether the texture is premultied alpha or not.
*/
- virtual void FrameReady(TextureSet textureSet, uint32_t interval) = 0;
+ virtual void FrameReady(TextureSet textureSet, uint32_t interval, bool preMultiplied) = 0;
};
struct UrlStore
public:
/**
* @brief Constructor.
- * @param[in] textureManager The texture manager
- * @param[in] size The width and height to fit the loaded image to.
- * @param[in] fittingMode The FittingMode of the resource to load
- * @param[in] samplingMode The SamplingMode of the resource to load
- * @param[in] observer FrameReady observer
- * @param[in] maskingData Masking data to be applied.
- * @param[in] batchSize The size of a batch to load
- * @param[in] interval Time interval(ms) between each frame
+ * @param[in] textureManager The texture manager
+ * @param[in] size The width and height to fit the loaded image to.
+ * @param[in] fittingMode The FittingMode of the resource to load
+ * @param[in] samplingMode The SamplingMode of the resource to load
+ * @param[in] observer FrameReady observer
+ * @param[in] maskingData Masking data to be applied.
+ * @param[in] batchSize The size of a batch to load
+ * @param[in] interval Time interval(ms) between each frame
+ * @param[in] preMultiplyOnLoad The flag if image's color should be multiplied by it's alpha
*
* This will start loading textures immediately, according to the
* batch and cache sizes. The cache is as large as the number of urls.
TextureManager::MaskingDataPointer& maskingData,
ImageCache::FrameReadyObserver& observer,
uint32_t batchSize,
- uint32_t interval);
+ uint32_t interval,
+ bool preMultiplyOnLoad);
virtual ~ImageCache();
uint32_t mInterval;
TextureManager::LoadState mLoadState;
bool mRequestingLoad : 1;
+ bool mPreMultiplyOnLoad : 1;
bool mTextureManagerAlive : 1;
};
const Dali::WrapMode::Type& wrapModeV,
bool isSynchronousLoading,
bool preMultiplyOnLoad)
-: ImageCache(textureManager, size, fittingMode, samplingMode, maskingData, observer, batchSize, 0u),
+: ImageCache(textureManager, size, fittingMode, samplingMode, maskingData, observer, batchSize, 0u, preMultiplyOnLoad),
mImageUrl(animatedImageLoading.GetUrl()),
mAnimatedImageLoading(animatedImageLoading),
mFrameCount(SINGLE_IMAGE_COUNT),
mQueue(cacheSize),
mWrapModeU(wrapModeU),
mWrapModeV(wrapModeV),
- mIsSynchronousLoading(isSynchronousLoading),
- mPreMultiplyOnLoad(preMultiplyOnLoad)
+ mIsSynchronousLoading(isSynchronousLoading)
{
mTextureIds.resize(mFrameCount);
mIntervals.assign(mFrameCount, 0);
bool synchronouslyLoaded = false;
if(mIsSynchronousLoading && mQueue.IsEmpty())
{
- textureSet = RequestFrameLoading(frameIndex, true);
+ auto preMultiplyOnLoading = mPreMultiplyOnLoad ? TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD
+ : TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
+
+ textureSet = RequestFrameLoading(frameIndex, true, preMultiplyOnLoading);
batchFrameIndex = (frameIndex + 1) % mFrameCount;
uint32_t interval = 0u;
if(textureSet)
synchronouslyLoaded = true;
interval = mAnimatedImageLoading.GetFrameInterval(mQueue.Back().mFrameNumber);
}
- MakeFrameReady(synchronouslyLoaded, textureSet, interval);
+ MakeFrameReady(synchronouslyLoaded, textureSet, interval, preMultiplyOnLoading == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD);
}
if(popExist || mQueue.IsEmpty() || synchronouslyLoaded)
return (!mQueue.IsEmpty() && mQueue.Front().mReady);
}
-TextureSet RollingAnimatedImageCache::RequestFrameLoading(uint32_t frameIndex, bool synchronousLoading)
+TextureSet RollingAnimatedImageCache::RequestFrameLoading(uint32_t frameIndex)
+{
+ auto preMultiplyOnLoading = mPreMultiplyOnLoad ? TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD
+ : TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
+
+ return RequestFrameLoading(frameIndex, false, preMultiplyOnLoading);
+}
+
+TextureSet RollingAnimatedImageCache::RequestFrameLoading(uint32_t frameIndex, bool synchronousLoading, TextureManager::MultiplyOnLoad& preMultiplyOnLoading)
{
ImageFrame imageFrame;
imageFrame.mFrameNumber = frameIndex;
mLoadState = TextureManager::LoadState::LOADING;
- auto preMultiplyOnLoading = mPreMultiplyOnLoad ? TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD
- : TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
-
TextureManager::TextureId loadTextureId = TextureManager::INVALID_TEXTURE_ID;
TextureSet textureSet = mTextureManager.LoadAnimatedImageTexture(mImageUrl,
mAnimatedImageLoading,
{
if(mLoadState != TextureManager::LoadState::LOADING)
{
- RequestFrameLoading(frameIndex, false);
+ RequestFrameLoading(frameIndex);
}
else
{
mLoadState = TextureManager::LoadState::NOT_STARTED;
}
-void RollingAnimatedImageCache::MakeFrameReady(bool loadSuccess, TextureSet textureSet, uint32_t interval)
+void RollingAnimatedImageCache::MakeFrameReady(bool loadSuccess, TextureSet textureSet, uint32_t interval, bool preMultiplied)
{
if(!loadSuccess)
{
mLoadState = TextureManager::LoadState::LOAD_FAILED;
- mObserver.FrameReady(TextureSet(), 0);
+ // preMultiplied should be false because broken image don't premultiply alpha on load
+ mObserver.FrameReady(TextureSet(), 0, false);
}
else
{
// If it is, notify frame ready to observer.
if(frontFrameReady == false && IsFrontReady())
{
- mObserver.FrameReady(textureSet, interval);
+ mObserver.FrameReady(textureSet, interval, preMultiplied);
}
}
}
textureInformation.textureSet.SetSampler(0u, sampler);
}
- MakeFrameReady(loadSuccess, textureInformation.textureSet, textureInformation.interval);
+ MakeFrameReady(loadSuccess, textureInformation.textureSet, textureInformation.interval, textureInformation.preMultiplied);
if(loadSuccess)
{
{
uint32_t loadingIndex = mLoadWaitingQueue.front();
mLoadWaitingQueue.erase(mLoadWaitingQueue.begin());
- RequestFrameLoading(loadingIndex, false);
+ RequestFrameLoading(loadingIndex);
}
else if(mQueue.Count() == 1u && textureInformation.frameCount > SINGLE_IMAGE_COUNT)
{
bool IsFrontReady() const;
/**
+ * @brief Request to Load a frame asynchronously
+ *
+ * @param[in] frameIndex index of frame to be loaded.
+ *
+ * @return the texture set currently loaded.
+ */
+ TextureSet RequestFrameLoading(uint32_t frameIndex);
+
+ /**
* @brief Request to Load a frame
*
- * @param[in] frameIndex index of frame to be loaded.
- * @param[in] synchronousLoading true if the frame should be loaded synchronously
+ * @param[in] frameIndex Index of frame to be loaded.
+ * @param[in] synchronousLoading True if the frame should be loaded synchronously
+ * @param[in,out] preMultiplyOnLoad True if the image color should be multiplied by it's alpha. Set to false if the
+ * image has no alpha channel
*
* @return the texture set currently loaded.
*/
- TextureSet RequestFrameLoading(uint32_t frameIndex, bool synchronousLoading);
+ TextureSet RequestFrameLoading(uint32_t frameIndex, bool synchronousLoading, TextureManager::MultiplyOnLoad& preMultiplyOnLoading);
/**
* @brief Load the next batch of images
* @param[in] loadSuccess whether the loading is succeded or not.
* @param[in] textureSet textureSet for this frame.
* @param[in] interval interval between this frame and next frame.
+ * @param[in] preMultiplied whether the texture is premultied alpha or not.
*/
- void MakeFrameReady(bool loadSuccess, TextureSet textureSet, uint32_t interval);
+ void MakeFrameReady(bool loadSuccess, TextureSet textureSet, uint32_t interval, bool preMultiplied);
/**
* @brief Pop front entity of Cache.
Dali::WrapMode::Type mWrapModeU : 3;
Dali::WrapMode::Type mWrapModeV : 3;
bool mIsSynchronousLoading;
- bool mPreMultiplyOnLoad;
};
} // namespace Internal
ImageCache::FrameReadyObserver& observer,
uint16_t cacheSize,
uint16_t batchSize,
- uint32_t interval)
-: ImageCache(textureManager, size, fittingMode, samplingMode, maskingData, observer, batchSize, interval),
+ uint32_t interval,
+ bool preMultiplyOnLoad)
+: ImageCache(textureManager, size, fittingMode, samplingMode, maskingData, observer, batchSize, interval, preMultiplyOnLoad),
mImageUrls(urlList),
mQueue(cacheSize)
{
ImageAtlasManagerPtr imageAtlasManager = nullptr;
Vector4 textureRect;
Dali::ImageDimensions textureRectSize;
- auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
+
+ auto preMultiplyOnLoading = mPreMultiplyOnLoad ? TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD
+ : TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
TextureManager::TextureId loadTextureId = TextureManager::INVALID_TEXTURE_ID;
TextureSet textureSet = mTextureManager.LoadTexture(
- url, mDesiredSize, mFittingMode, mSamplingMode, mMaskingData, synchronousLoading, loadTextureId, textureRect, textureRectSize, atlasingStatus, loadingStatus, this, atlasObserver, imageAtlasManager, ENABLE_ORIENTATION_CORRECTION, TextureManager::ReloadPolicy::CACHED, preMultiply);
+ url, mDesiredSize, mFittingMode, mSamplingMode, mMaskingData, synchronousLoading, loadTextureId, textureRect, textureRectSize, atlasingStatus, loadingStatus, this, atlasObserver, imageAtlasManager, ENABLE_ORIENTATION_CORRECTION, TextureManager::ReloadPolicy::CACHED, preMultiplyOnLoading);
mImageUrls[imageFrame.mUrlIndex].mTextureId = loadTextureId;
mRequestingLoad = false;
sampler.SetWrapMode(Dali::WrapMode::Type::DEFAULT, Dali::WrapMode::Type::DEFAULT);
textureInformation.textureSet.SetSampler(0u, sampler);
}
- mObserver.FrameReady(textureInformation.textureSet, mInterval);
+ mObserver.FrameReady(textureInformation.textureSet, mInterval, textureInformation.preMultiplied);
}
}
else
{
mLoadState = TextureManager::LoadState::LOAD_FAILED;
- mObserver.FrameReady(TextureSet(), 0);
+ // preMultiplied should be false because broken image don't premultiply alpha on load
+ mObserver.FrameReady(TextureSet(), 0, false);
}
LOG_CACHE;
public:
/**
* Constructor.
- * @param[in] textureManager The texture manager
- * @param[in] size The width and height to fit the loaded image to.
- * @param[in] fittingMode The FittingMode of the resource to load
- * @param[in] samplingMode The SamplingMode of the resource to load
- * @param[in] urlList List of urls to cache
- * @param[in] maskingData Masking data to be applied.
- * @param[in] observer FrameReady observer
- * @param[in] cacheSize The size of the cache
- * @param[in] batchSize The size of a batch to load
- * @param[in] interval Time interval between each frame
+ * @param[in] textureManager The texture manager
+ * @param[in] size The width and height to fit the loaded image to.
+ * @param[in] fittingMode The FittingMode of the resource to load
+ * @param[in] samplingMode The SamplingMode of the resource to load
+ * @param[in] urlList List of urls to cache
+ * @param[in] maskingData Masking data to be applied.
+ * @param[in] observer FrameReady observer
+ * @param[in] cacheSize The size of the cache
+ * @param[in] batchSize The size of a batch to load
+ * @param[in] interval Time interval between each frame
+ * @param[in] preMultiplyOnLoad The flag if image's color should be multiplied by it's alpha
*
* This will start loading textures immediately, according to the
* batch and cache sizes.
ImageCache::FrameReadyObserver& observer,
uint16_t cacheSize,
uint16_t batchSize,
- uint32_t interval);
+ uint32_t interval,
+ bool preMultiplyOnLoad);
/**
* Destructor