X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2FTizen.Multimedia.Util%2FImageUtil%2FImageDecoder.cs;h=81824ec70d5d24fbe95bd1d357c6708aea1d63aa;hb=d7c3f3fa9da5552e361af7ffff287491dccef840;hp=fcf1cab344cd5e230e280f98da577ae22f155a1e;hpb=ce445495b4555042bad49d5a4e3317faf13447f1;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git
diff --git a/src/Tizen.Multimedia.Util/ImageUtil/ImageDecoder.cs b/src/Tizen.Multimedia.Util/ImageUtil/ImageDecoder.cs
index fcf1cab..81824ec 100644
--- a/src/Tizen.Multimedia.Util/ImageUtil/ImageDecoder.cs
+++ b/src/Tizen.Multimedia.Util/ImageUtil/ImageDecoder.cs
@@ -20,6 +20,7 @@ using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
+using System.Threading;
using System.Threading.Tasks;
using static Interop;
using static Interop.Decode;
@@ -29,6 +30,7 @@ namespace Tizen.Multimedia.Util
///
/// This is a base class for image decoders.
///
+ /// 4
public abstract class ImageDecoder : IDisposable
{
private ImageDecoderHandle _handle;
@@ -47,6 +49,7 @@ namespace Tizen.Multimedia.Util
///
/// Gets the image format of this decoder.
///
+ /// 4
public ImageFormat InputFormat { get; }
private ImageDecoderHandle Handle
@@ -68,6 +71,7 @@ namespace Tizen.Multimedia.Util
/// is invalid.
/// is not supported by the decoder.
///
+ /// 4
public void SetColorSpace(ColorSpace colorSpace)
{
ValidationUtil.ValidateEnum(typeof(ColorSpace), colorSpace, nameof(ColorSpace));
@@ -86,23 +90,22 @@ namespace Tizen.Multimedia.Util
/// The input file path from which to decode.
/// A task that represents the asynchronous decoding operation.
///
- /// Only Graphics Interchange Format(GIF) codec returns more than one frame.\n
- /// \n
- /// http://tizen.org/privilege/mediastorage is needed if is relevant to the media storage.\n
+ /// Only Graphics Interchange Format(GIF) codec returns more than one frame.
+ ///
+ /// http://tizen.org/privilege/mediastorage is needed if is relevant to the media storage.
/// http://tizen.org/privilege/externalstorage is needed if is relevant to the external storage.
///
/// is null.
///
- /// is an empty string.\n
- /// - or -\n
- /// is not a image file.\n
- /// - or -\n
- /// The format of is not .
+ /// is an empty string.
+ /// -or-
+ /// is not a image file.
///
/// does not exists.
/// The caller does not have required permission to access the path.
/// The format of is not .
/// The has already been disposed of.
+ /// 4
public async Task> DecodeAsync(string inputFilePath)
{
if (inputFilePath == null)
@@ -123,7 +126,6 @@ namespace Tizen.Multimedia.Util
var pathPtr = Marshal.StringToHGlobalAnsi(inputFilePath);
try
{
-
SetInputPath(Handle, pathPtr).ThrowIfFailed("Failed to set input file path for decoding");
return await DecodeAsync();
}
@@ -138,17 +140,12 @@ namespace Tizen.Multimedia.Util
///
/// The image buffer from which to decode.
/// A task that represents the asynchronous decoding operation.
- ///
- /// Only Graphics Interchange Format(GIF) codec returns more than one frame.\n
- ///
+ /// Only Graphics Interchange Format(GIF) codec returns more than one frame.
/// is null.
- ///
- /// is an empty array.\n
- /// - or -\n
- /// The format of is not .
- ///
+ /// is an empty array.
/// The format of is not .
/// The has already been disposed of.
+ /// 4
public Task> DecodeAsync(byte[] inputBuffer)
{
if (inputBuffer == null)
@@ -204,37 +201,38 @@ namespace Tizen.Multimedia.Util
}
}
- internal Task> DecodeAsync()
+ private IEnumerable RunDecoding()
{
- Initialize(Handle);
+ IntPtr outBuffer = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr)));
+ Marshal.WriteIntPtr(outBuffer, IntPtr.Zero);
- IntPtr outBuffer = IntPtr.Zero;
- SetOutputBuffer(Handle, out outBuffer).ThrowIfFailed("Failed to decode given image");
+ try
+ {
+ SetOutputBuffer(Handle, outBuffer).ThrowIfFailed("Failed to decode given image");
- var tcs = new TaskCompletionSource>();
+ DecodeRun(Handle, out var width, out var height, out var size).
+ ThrowIfFailed("Failed to decode");
- Task.Run(() =>
+ yield return new BitmapFrame(Marshal.ReadIntPtr(outBuffer), width, height, (int)size);
+ }
+ finally
{
- try
+ if (Marshal.ReadIntPtr(outBuffer) != IntPtr.Zero)
{
- int width, height;
- ulong size;
+ LibcSupport.Free(Marshal.ReadIntPtr(outBuffer));
+ }
- DecodeRun(Handle, out width, out height, out size).ThrowIfFailed("Failed to decode");
+ Marshal.FreeHGlobal(outBuffer);
+ }
+ }
- tcs.SetResult(new[] { new BitmapFrame(outBuffer, width, height, (int)size) });
- }
- catch (Exception e)
- {
- tcs.TrySetException(e);
- }
- finally
- {
- LibcSupport.Free(outBuffer);
- }
- });
+ internal Task> DecodeAsync()
+ {
+ Initialize(Handle);
- return tcs.Task;
+ return Task.Factory.StartNew(RunDecoding, CancellationToken.None,
+ TaskCreationOptions.DenyChildAttach | TaskCreationOptions.LongRunning,
+ TaskScheduler.Default);
}
internal virtual void Initialize(ImageDecoderHandle handle)
@@ -254,6 +252,7 @@ namespace Tizen.Multimedia.Util
/// Releases the unmanaged resources used by the ImageDecoder.
///
/// true to release both managed and unmanaged resources; false to release only unmanaged resources.
+ /// 4
protected virtual void Dispose(bool disposing)
{
if (!_disposed)
@@ -269,6 +268,7 @@ namespace Tizen.Multimedia.Util
///
/// Releases all resources used by the ImageDecoder.
///
+ /// 4
public void Dispose()
{
Dispose(true);
@@ -279,6 +279,7 @@ namespace Tizen.Multimedia.Util
///
/// Provides the ability to decode Bitmap (BMP) encoded images.
///
+ /// 4
public class BmpDecoder : ImageDecoder
{
private static readonly byte[] _header = { (byte)'B', (byte)'M' };
@@ -287,6 +288,7 @@ namespace Tizen.Multimedia.Util
/// Initializes a new instance of the class.
///
/// will be the .
+ /// 4
public BmpDecoder() : base(ImageFormat.Bmp)
{
}
@@ -297,6 +299,7 @@ namespace Tizen.Multimedia.Util
///
/// Provides the ability to decode the Portable Network Graphics (PNG) encoded images.
///
+ /// 4
public class PngDecoder : ImageDecoder
{
private static readonly byte[] _header = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a };
@@ -305,6 +308,7 @@ namespace Tizen.Multimedia.Util
/// Initializes a new instance of the class.
///
/// will be the .
+ /// 4
public PngDecoder() : base(ImageFormat.Png)
{
}
@@ -315,6 +319,7 @@ namespace Tizen.Multimedia.Util
///
/// Provides the ability to decode the Joint Photographic Experts Group (JPEG) encoded images.
///
+ /// 4
public class JpegDecoder : ImageDecoder
{
private static readonly byte[] _header = { 0xFF, 0xD8 };
@@ -322,6 +327,7 @@ namespace Tizen.Multimedia.Util
///
/// A read-only field that represents the default value of .
///
+ /// 4
public static readonly JpegDownscale DefaultJpegDownscale = JpegDownscale.None;
private JpegDownscale _jpegDownscale = DefaultJpegDownscale;
@@ -330,6 +336,7 @@ namespace Tizen.Multimedia.Util
/// Initializes a new instance of the class.
///
/// will be the .
+ /// 4
public JpegDecoder() : base(ImageFormat.Jpeg)
{
}
@@ -338,6 +345,7 @@ namespace Tizen.Multimedia.Util
/// Gets or sets the downscale at which the jpeg image should be decoded.
///
/// is invalid.
+ /// 4
public JpegDownscale Downscale
{
get
@@ -365,6 +373,7 @@ namespace Tizen.Multimedia.Util
///
/// Provides the ability to decode the Graphics Interchange Format (GIF) encoded images.
///
+ /// 4
public class GifDecoder : ImageDecoder
{
private static readonly byte[] _header = { (byte)'G', (byte)'I', (byte)'F' };
@@ -373,6 +382,7 @@ namespace Tizen.Multimedia.Util
/// Initializes a new instance of the class.
///
/// will be the .
+ /// 4
public GifDecoder() : base(ImageFormat.Gif)
{
}