[Tizen] Fix premultiply alpha issue submit/tizen/20190917.064531
authorSeungho, Baek <sbsh.baek@samsung.com>
Tue, 17 Sep 2019 04:31:44 +0000 (13:31 +0900)
committerSeungho, Baek <sbsh.baek@samsung.com>
Tue, 17 Sep 2019 04:31:48 +0000 (13:31 +0900)
This reverts commit eaab1a875b43235fcf00efc623cb36b0a25cccdd.

dali-toolkit/devel-api/image-loader/async-image-loader-devel.cpp
dali-toolkit/devel-api/image-loader/async-image-loader-devel.h
dali-toolkit/internal/image-loader/async-image-loader-impl.cpp
dali-toolkit/internal/image-loader/async-image-loader-impl.h
dali-toolkit/internal/image-loader/image-load-thread.cpp
dali-toolkit/internal/image-loader/image-load-thread.h
dali-toolkit/internal/visuals/texture-manager-impl.cpp
dali-toolkit/internal/visuals/texture-manager-impl.h

index 3bd3368..5fc985f 100644 (file)
@@ -39,9 +39,10 @@ uint32_t ApplyMask( AsyncImageLoader asyncImageLoader,
                     Devel::PixelBuffer pixelBuffer,
                     Devel::PixelBuffer maskPixelBuffer,
                     float contentScale,
-                    bool cropToMask )
+                    bool cropToMask,
+                    DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad )
 {
-  return GetImplementation( asyncImageLoader ).ApplyMask( pixelBuffer, maskPixelBuffer, contentScale, cropToMask );
+  return GetImplementation( asyncImageLoader ).ApplyMask( pixelBuffer, maskPixelBuffer, contentScale, cropToMask, preMultiplyOnLoad );
 }
 
 PixelBufferLoadedSignalType& PixelBufferLoadedSignal( AsyncImageLoader asyncImageLoader )
index 681c00b..99ca154 100644 (file)
@@ -49,7 +49,7 @@ enum class PreMultiplyOnLoad
  * @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] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size
  * @param[in] orientationCorrection Reorient the image to respect any orientation metadata in its header
- * @param[in] preMultiplyOnLoad ON if the image color should be multiplied by it's alpha. Set to OFF if there is no alpha
+ * @param[in] preMultiplyOnLoad ON if the image color should be multiplied by it's alpha. Set to OFF if there is no alpha or if the image need to be applied alpha mask.
  * @return The loading task id
  */
 DALI_TOOLKIT_API uint32_t Load( AsyncImageLoader asyncImageLoader,
@@ -69,13 +69,15 @@ DALI_TOOLKIT_API uint32_t Load( AsyncImageLoader asyncImageLoader,
  * @param[in] maskPixelBuffer Pointer to raw masking data
  * @param[in] contentScale The factor to scale the content
  * @param[in] cropToMask Whether to crop the content to the mask size
+ * @param[in] preMultiplyOnLoad ON if the image color should be multiplied by it's alpha. Set to OFF if there is no alpha.
  * @return The masking task id
  */
 DALI_TOOLKIT_API uint32_t ApplyMask( AsyncImageLoader asyncImageLoader,
                                      Devel::PixelBuffer pixelBuffer,
                                      Devel::PixelBuffer maskPixelBuffer,
                                      float contentScale,
-                                     bool cropToMask );
+                                     bool cropToMask,
+                                     DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad );
 
 /**
  * Connect to this signal if you want to load a PixelBuffer instead of a PixelData.
index de0ee3f..f08b147 100644 (file)
@@ -69,14 +69,15 @@ uint32_t AsyncImageLoader::Load( const VisualUrl& url,
 uint32_t AsyncImageLoader::ApplyMask( Devel::PixelBuffer pixelBuffer,
                                       Devel::PixelBuffer maskPixelBuffer,
                                       float contentScale,
-                                      bool cropToMask )
+                                      bool cropToMask,
+                                      DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad)
 {
   if( !mIsLoadThreadStarted )
   {
     mLoadThread.Start();
     mIsLoadThreadStarted = true;
   }
-  mLoadThread.AddTask( new LoadingTask( ++mLoadTaskId, pixelBuffer, maskPixelBuffer, contentScale, cropToMask ) );
+  mLoadThread.AddTask( new LoadingTask( ++mLoadTaskId, pixelBuffer, maskPixelBuffer, contentScale, cropToMask, preMultiplyOnLoad ) );
 
   return mLoadTaskId;
 }
index 69a7617..a97088d 100644 (file)
@@ -65,12 +65,14 @@ public:
    * @param[in] maskPixelBuffer of the mask image
    * @param[in] contentScale The factor to scale the content
    * @param[in] cropToMask Whether to crop the content to the mask size
+   * @param[in] preMultiplyOnLoad ON if the image color should be multiplied by it's alpha. Set to OFF if there is no alpha.
    * @return The loading task id
    */
   uint32_t ApplyMask( Devel::PixelBuffer pixelBuffer,
                       Devel::PixelBuffer maskPixelBuffer,
                       float contentScale,
-                      bool cropToMask );
+                      bool cropToMask,
+                      DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad );
 
   /**
    * @copydoc Toolkit::AsyncImageLoader::ImageLoadedSignal
index f687af6..29a5dff 100644 (file)
@@ -49,7 +49,8 @@ LoadingTask::LoadingTask( uint32_t id, const VisualUrl& url, ImageDimensions dim
 {
 }
 
-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,7 +58,7 @@ LoadingTask::LoadingTask( uint32_t id, Devel::PixelBuffer pixelBuffer, Devel::Pi
   fittingMode(),
   samplingMode(),
   orientationCorrection(),
-  preMultiplyOnLoad(),
+  preMultiplyOnLoad( preMultiplyOnLoad ),
   isMaskTask( true ),
   maskPixelBuffer( maskPixelBuffer ),
   contentScale( contentScale ),
@@ -75,7 +76,15 @@ void LoadingTask::Load()
   {
     pixelBuffer = Dali::DownloadImageSynchronously ( url.GetUrl(), dimensions, fittingMode, samplingMode, orientationCorrection );
   }
+}
+
+void LoadingTask::ApplyMask()
+{
+  pixelBuffer.ApplyMask( maskPixelBuffer, contentScale, cropToMask );
+}
 
+void LoadingTask::MultiplyAlpha()
+{
   if( pixelBuffer && Pixel::HasAlpha( pixelBuffer.GetPixelFormat() ) )
   {
     if( preMultiplyOnLoad == DevelAsyncImageLoader::PreMultiplyOnLoad::ON )
@@ -85,11 +94,6 @@ void LoadingTask::Load()
   }
 }
 
-void LoadingTask::ApplyMask()
-{
-  pixelBuffer.ApplyMask( maskPixelBuffer, contentScale, cropToMask );
-}
-
 ImageLoadThread::ImageLoadThread( EventThreadCallback* trigger )
 : mTrigger( trigger ),
   mLogFactory( Dali::Adaptor::Get().GetLogFactory() )
@@ -121,6 +125,7 @@ void ImageLoadThread::Run()
     {
       task->ApplyMask();
     }
+    task->MultiplyAlpha();
 
     AddCompletedTask( task );
   }
index cd6bd32..2edd97a 100644 (file)
@@ -52,7 +52,7 @@ struct LoadingTask
    * @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] samplingMode The filtering method used when sampling pixels from the input image while fitting it to desired size.
    * @param [in] orientationCorrection Reorient the image to respect any orientation metadata in its header.
-   * @param [in] preMultiplyOnLoad ON if the image's color should be multiplied by it's alpha.
+   * @param [in] preMultiplyOnLoad ON if the image's color should be multiplied by it's alpha. Set to OFF if there is no alpha or if the image need to be applied alpha mask.
    */
   LoadingTask( uint32_t id,
                const VisualUrl& url,
@@ -69,12 +69,14 @@ struct LoadingTask
    * @param [in] maskPixelBuffer of the mask image
    * @param [in] contentScale The factor to scale the content
    * @param [in] cropToMask Whether to crop the content to the mask size
+   * @param [in] preMultiplyOnLoad ON if the image's color should be multiplied by it's alpha. Set to OFF if there is no alpha.
    */
   LoadingTask( uint32_t id,
               Devel::PixelBuffer pixelBuffer,
               Devel::PixelBuffer maskPixelBuffer,
               float contentScale,
-              bool cropToMask );
+              bool cropToMask,
+              DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad);
 
   /**
    * Load the image
@@ -86,6 +88,11 @@ struct LoadingTask
    */
   void ApplyMask();
 
+  /**
+   * Multiply alpha
+   */
+  void MultiplyAlpha();
+
 private:
 
   // Undefined
index 64a1977..c879226 100644 (file)
@@ -703,7 +703,8 @@ void TextureManager::LoadTexture( TextureInfo& textureInfo, TextureUploadObserve
   {
     auto& loadersContainer = textureInfo.url.IsLocalResource() ? mAsyncLocalLoaders : mAsyncRemoteLoaders;
     auto loadingHelperIt = loadersContainer.GetNext();
-    auto premultiplyOnLoad = textureInfo.preMultiplyOnLoad? DevelAsyncImageLoader::PreMultiplyOnLoad::ON : DevelAsyncImageLoader::PreMultiplyOnLoad::OFF;
+    auto premultiplyOnLoad = ( textureInfo.preMultiplyOnLoad && textureInfo.maskTextureId == INVALID_TEXTURE_ID ) ?
+                               DevelAsyncImageLoader::PreMultiplyOnLoad::ON : DevelAsyncImageLoader::PreMultiplyOnLoad::OFF;
     DALI_ASSERT_ALWAYS(loadingHelperIt != loadersContainer.End());
     loadingHelperIt->Load(textureInfo.textureId, textureInfo.url,
                           textureInfo.desiredSize, textureInfo.fittingMode,
@@ -893,8 +894,9 @@ void TextureManager::ApplyMask( TextureInfo& textureInfo, TextureId maskTextureI
     textureInfo.maskApplied = true;
     auto& loadersContainer = textureInfo.url.IsLocalResource() ? mAsyncLocalLoaders : mAsyncRemoteLoaders;
     auto loadingHelperIt = loadersContainer.GetNext();
+    auto premultiplyOnLoad = textureInfo.preMultiplyOnLoad ? DevelAsyncImageLoader::PreMultiplyOnLoad::ON : DevelAsyncImageLoader::PreMultiplyOnLoad::OFF;
     DALI_ASSERT_ALWAYS(loadingHelperIt != loadersContainer.End());
-    loadingHelperIt->ApplyMask( textureInfo.textureId, pixelBuffer, maskPixelBuffer, textureInfo.scaleFactor, textureInfo.cropToMask );
+    loadingHelperIt->ApplyMask( textureInfo.textureId, pixelBuffer, maskPixelBuffer, textureInfo.scaleFactor, textureInfo.cropToMask, premultiplyOnLoad );
   }
 }
 
@@ -1155,13 +1157,14 @@ void TextureManager::AsyncLoadingHelper::Load(TextureId          textureId,
 }
 
 void TextureManager::AsyncLoadingHelper::ApplyMask( TextureId textureId,
-                                               Devel::PixelBuffer pixelBuffer,
-                                               Devel::PixelBuffer maskPixelBuffer,
-                                               float contentScale,
-                                               bool cropToMask )
+                                                    Devel::PixelBuffer pixelBuffer,
+                                                    Devel::PixelBuffer maskPixelBuffer,
+                                                    float contentScale,
+                                                    bool cropToMask,
+                                                    DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad )
 {
   mLoadingInfoContainer.push_back(AsyncLoadingInfo(textureId));
-  auto id = DevelAsyncImageLoader::ApplyMask( mLoader, pixelBuffer, maskPixelBuffer, contentScale, cropToMask );
+  auto id = DevelAsyncImageLoader::ApplyMask( mLoader, pixelBuffer, maskPixelBuffer, contentScale, cropToMask, preMultiplyOnLoad );
   mLoadingInfoContainer.back().loadId = id;
 }
 
index 4f35040..ffc21d9 100755 (executable)
@@ -714,7 +714,7 @@ private:
      * @param[in] samplingMode          The SamplingMode to use
      * @param[in] orientationCorrection Whether to use image metadata to rotate or flip the image,
      *                                  e.g., from portrait to landscape
-     * @param[in] preMultiplyOnLoad     if the image's color should be multiplied by it's alpha.
+     * @param[in] preMultiplyOnLoad     if the image's color should be multiplied by it's alpha. Set to OFF if there is no alpha or if the image need to be applied alpha mask.
      */
     void Load(TextureId textureId,
               const VisualUrl& url,
@@ -731,12 +731,14 @@ private:
      * @param [in] maskPixelBuffer of the mask image
      * @param [in] contentScale The factor to scale the content
      * @param [in] cropToMask Whether to crop the content to the mask size
+     * @param [in] preMultiplyOnLoad if the image's color should be multiplied by it's alpha. Set to OFF if there is no alpha.
      */
     void ApplyMask( TextureId textureId,
                     Devel::PixelBuffer pixelBuffer,
                     Devel::PixelBuffer maskPixelBuffer,
                     float contentScale,
-                    bool cropToMask );
+                    bool cropToMask,
+                    DevelAsyncImageLoader::PreMultiplyOnLoad preMultiplyOnLoad );
 
   public:
     AsyncLoadingHelper(const AsyncLoadingHelper&) = delete;