[ImageUtil] Supports WebP encoder and decoder (#1881)
authorhsgwon <haesu.gwon@samsung.com>
Thu, 13 Aug 2020 07:51:32 +0000 (16:51 +0900)
committerGitHub <noreply@github.com>
Thu, 13 Aug 2020 07:51:32 +0000 (16:51 +0900)
src/Tizen.Multimedia.Util/ImageUtil/ImageDecoder.cs
src/Tizen.Multimedia.Util/ImageUtil/ImageEncoder.cs
src/Tizen.Multimedia.Util/ImageUtil/ImageFormat.cs
src/Tizen.Multimedia.Util/Interop/Interop.ImageUtil.Encode.cs

index 71236b5..431644c 100644 (file)
@@ -394,4 +394,24 @@ namespace Tizen.Multimedia.Util
 
         internal override byte[] Header => _header;
     }
+
+    /// <summary>
+    /// Provides the ability to decode the WebP (Lossless and lossy compression for images on the web) encoded images.
+    /// </summary>
+    /// <since_tizen> 8 </since_tizen>
+    public class WebPDecoder : ImageDecoder
+    {
+        private static readonly byte[] _header = { 0x57, 0x45, 0x42, 0x50 };
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="WebPDecoder"/> class.
+        /// </summary>
+        /// <remarks><see cref="ImageDecoder.InputFormat"/> will be the <see cref="ImageFormat.WebP"/>.</remarks>
+        /// <since_tizen> 8 </since_tizen>
+        public WebPDecoder() : base(ImageFormat.WebP)
+        {
+        }
+
+        internal override byte[] Header => _header;
+    }
 }
index c20c710..758dce5 100644 (file)
@@ -476,4 +476,51 @@ namespace Tizen.Multimedia.Util
         }
     }
 
+    /// <summary>
+    /// Provides the ability to encode the WebP (Lossless and lossy compression for images on the web) format images.
+    /// </summary>
+    /// <since_tizen> 8 </since_tizen>
+    public class WebPEncoder : ImageEncoder
+    {
+        /// <summary>
+        /// Initializes a new instance of the <see cref="WebPEncoder"/> class.
+        /// </summary>
+        /// <remarks><see cref="ImageEncoder.OutputFormat"/> will be the <see cref="ImageFormat.WebP"/>.</remarks>
+        /// <since_tizen> 8 </since_tizen>
+        public WebPEncoder() :
+            base(ImageFormat.WebP)
+        {
+        }
+
+        /// <summary>
+        /// Initializes a new instance of the <see cref="WebPEncoder"/> class with the information for lossless or lossy compression.
+        /// </summary>
+        /// <remarks><see cref="ImageEncoder.OutputFormat"/> will be the <see cref="ImageFormat.WebP"/>.</remarks>
+        /// <param name="lossless">
+        /// The flag determining whether the compression is lossless or lossy: true for lossless, false for lossy.<br/>
+        /// The default value is false.
+        /// </param>
+        /// <since_tizen> 8 </since_tizen>
+        public WebPEncoder(bool lossless) :
+            base(ImageFormat.WebP)
+        {
+            Lossless = lossless;
+        }
+
+        /// <summary>
+        /// Gets or sets the lossless or lossy WebP compression.
+        /// </summary>
+        /// <value>
+        /// The property determining whether the WebP compression is lossless or lossy.<br/>
+        /// The default is false(lossy).</value>
+        /// <since_tizen> 8 </since_tizen>
+        public bool Lossless { get; set; }
+
+        internal override void Configure(ImageEncoderHandle handle)
+        {
+            NativeEncoder.SetWebPLossless(handle, Lossless).
+                ThrowIfFailed("Failed to configure encoder; Lossless");
+        }
+    }
+
 }
index 2fc1d55..1e055c6 100644 (file)
@@ -38,5 +38,10 @@ namespace Tizen.Multimedia.Util
         /// The Bitmap format.
         /// </summary>
         Bmp,
+        /// <summary>
+        /// The WebP format.
+        /// </summary>
+        /// <since_tizen> 8 </since_tizen>
+        WebP,
     }
 }
index f2df4b3..0391c3b 100644 (file)
@@ -64,6 +64,9 @@ internal static partial class Interop
 
             [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_encode_run")]
             internal static extern ImageUtilError Run(ImageEncoderHandle handle, out ulong size);
+
+            [DllImport(Libraries.ImageUtil, EntryPoint = "image_util_encode_set_webp_lossless")]
+            internal static extern ImageUtilError SetWebPLossless(ImageEncoderHandle handle, bool lossless);
         }
     }