/// <exception cref="ArgumentException"><paramref name="colorSpace"/> is invalid.</exception>
/// <exception cref="NotSupportedException"><paramref name="colorSpace"/> is not supported by the decoder.</exception>
/// <seealso cref="ImageUtil.GetSupportedColorSpaces(ImageFormat)"/>
/// <exception cref="ArgumentException"><paramref name="colorSpace"/> is invalid.</exception>
/// <exception cref="NotSupportedException"><paramref name="colorSpace"/> is not supported by the decoder.</exception>
/// <seealso cref="ImageUtil.GetSupportedColorSpaces(ImageFormat)"/>
public void SetColorSpace(ColorSpace colorSpace)
{
ValidationUtil.ValidateEnum(typeof(ColorSpace), colorSpace, nameof(ColorSpace));
public void SetColorSpace(ColorSpace colorSpace)
{
ValidationUtil.ValidateEnum(typeof(ColorSpace), colorSpace, nameof(ColorSpace));
/// <param name="inputFilePath">The input file path from which to decode.</param>
/// <returns>A task that represents the asynchronous decoding operation.</returns>
/// <remarks>
/// <param name="inputFilePath">The input file path from which to decode.</param>
/// <returns>A task that represents the asynchronous decoding operation.</returns>
/// <remarks>
- /// Only Graphics Interchange Format(GIF) codec returns more than one frame.\n
- /// \n
- /// http://tizen.org/privilege/mediastorage is needed if <paramref name="inputFilePath"/> is relevant to the media storage.\n
+ /// Only Graphics Interchange Format(GIF) codec returns more than one frame.<br/>
+ /// <br/>
+ /// http://tizen.org/privilege/mediastorage is needed if <paramref name="inputFilePath"/> is relevant to the media storage.<br/>
/// http://tizen.org/privilege/externalstorage is needed if <paramref name="inputFilePath"/> is relevant to the external storage.
/// </remarks>
/// <exception cref="ArgumentNullException"><paramref name="inputFilePath"/> is null.</exception>
/// <exception cref="ArgumentException">
/// http://tizen.org/privilege/externalstorage is needed if <paramref name="inputFilePath"/> is relevant to the external storage.
/// </remarks>
/// <exception cref="ArgumentNullException"><paramref name="inputFilePath"/> is null.</exception>
/// <exception cref="ArgumentException">
- /// <paramref name="inputFilePath"/> is an empty string.\n
- /// - or -\n
- /// <paramref name="inputFilePath"/> is not a image file.\n
- /// - or -\n
- /// The format of <paramref name="inputFilePath"/> is not <see cref="InputFormat"/>.
+ /// <paramref name="inputFilePath"/> is an empty string.<br/>
+ /// -or-<br/>
+ /// <paramref name="inputFilePath"/> is not a image file.
/// </exception>
/// <exception cref="FileNotFoundException"><paramref name="inputFilePath"/> does not exists.</exception>
/// <exception cref="UnauthorizedAccessException">The caller does not have required permission to access the path.</exception>
/// <exception cref="FileFormatException">The format of <paramref name="inputFilePath"/> is not <see cref="InputFormat"/>.</exception>
/// <exception cref="ObjectDisposedException">The <see cref="ImageDecoder"/> has already been disposed of.</exception>
/// </exception>
/// <exception cref="FileNotFoundException"><paramref name="inputFilePath"/> does not exists.</exception>
/// <exception cref="UnauthorizedAccessException">The caller does not have required permission to access the path.</exception>
/// <exception cref="FileFormatException">The format of <paramref name="inputFilePath"/> is not <see cref="InputFormat"/>.</exception>
/// <exception cref="ObjectDisposedException">The <see cref="ImageDecoder"/> has already been disposed of.</exception>
public async Task<IEnumerable<BitmapFrame>> DecodeAsync(string inputFilePath)
{
if (inputFilePath == null)
public async Task<IEnumerable<BitmapFrame>> DecodeAsync(string inputFilePath)
{
if (inputFilePath == null)
SetInputPath(Handle, pathPtr).ThrowIfFailed("Failed to set input file path for decoding");
return await DecodeAsync();
}
SetInputPath(Handle, pathPtr).ThrowIfFailed("Failed to set input file path for decoding");
return await DecodeAsync();
}
/// </summary>
/// <param name="inputBuffer">The image buffer from which to decode.</param>
/// <returns>A task that represents the asynchronous decoding operation.</returns>
/// </summary>
/// <param name="inputBuffer">The image buffer from which to decode.</param>
/// <returns>A task that represents the asynchronous decoding operation.</returns>
- /// <exception cref="ArgumentException">
- /// <paramref name="inputBuffer"/> is an empty array.\n
- /// - or -\n
- /// The format of <paramref name="inputBuffer"/> is not <see cref="InputFormat"/>.
- /// </exception>
+ /// <exception cref="ArgumentException"><paramref name="inputBuffer"/> is an empty array.</exception>
/// <exception cref="FileFormatException">The format of <paramref name="inputBuffer"/> is not <see cref="InputFormat"/>.</exception>
/// <exception cref="ObjectDisposedException">The <see cref="ImageDecoder"/> has already been disposed of.</exception>
/// <exception cref="FileFormatException">The format of <paramref name="inputBuffer"/> is not <see cref="InputFormat"/>.</exception>
/// <exception cref="ObjectDisposedException">The <see cref="ImageDecoder"/> has already been disposed of.</exception>
- 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<IEnumerable<BitmapFrame>>();
+ DecodeRun(Handle, out var width, out var height, out var size).
+ ThrowIfFailed("Failed to decode");
- tcs.SetResult(new[] { new BitmapFrame(outBuffer, width, height, (int)size) });
- }
- catch (Exception e)
- {
- tcs.TrySetException(e);
- }
- finally
- {
- LibcSupport.Free(outBuffer);
- }
- });
+ internal Task<IEnumerable<BitmapFrame>> DecodeAsync()
+ {
+ Initialize(Handle);
+ return Task.Factory.StartNew(RunDecoding, CancellationToken.None,
+ TaskCreationOptions.DenyChildAttach | TaskCreationOptions.LongRunning,
+ TaskScheduler.Default);
/// Releases the unmanaged resources used by the ImageDecoder.
/// </summary>
/// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
/// Releases the unmanaged resources used by the ImageDecoder.
/// </summary>
/// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
public class BmpDecoder : ImageDecoder
{
private static readonly byte[] _header = { (byte)'B', (byte)'M' };
public class BmpDecoder : ImageDecoder
{
private static readonly byte[] _header = { (byte)'B', (byte)'M' };
/// Initializes a new instance of the <see cref="BmpDecoder"/> class.
/// </summary>
/// <remarks><see cref="ImageDecoder.InputFormat"/> will be the <see cref="ImageFormat.Bmp"/>.</remarks>
/// Initializes a new instance of the <see cref="BmpDecoder"/> class.
/// </summary>
/// <remarks><see cref="ImageDecoder.InputFormat"/> will be the <see cref="ImageFormat.Bmp"/>.</remarks>
public class PngDecoder : ImageDecoder
{
private static readonly byte[] _header = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a };
public class PngDecoder : ImageDecoder
{
private static readonly byte[] _header = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a };
/// Initializes a new instance of the <see cref="PngDecoder"/> class.
/// </summary>
/// <remarks><see cref="ImageDecoder.InputFormat"/> will be the <see cref="ImageFormat.Png"/>.</remarks>
/// Initializes a new instance of the <see cref="PngDecoder"/> class.
/// </summary>
/// <remarks><see cref="ImageDecoder.InputFormat"/> will be the <see cref="ImageFormat.Png"/>.</remarks>
public class JpegDecoder : ImageDecoder
{
private static readonly byte[] _header = { 0xFF, 0xD8 };
public class JpegDecoder : ImageDecoder
{
private static readonly byte[] _header = { 0xFF, 0xD8 };
public static readonly JpegDownscale DefaultJpegDownscale = JpegDownscale.None;
private JpegDownscale _jpegDownscale = DefaultJpegDownscale;
public static readonly JpegDownscale DefaultJpegDownscale = JpegDownscale.None;
private JpegDownscale _jpegDownscale = DefaultJpegDownscale;
/// Initializes a new instance of the <see cref="JpegDecoder"/> class.
/// </summary>
/// <remarks><see cref="ImageDecoder.InputFormat"/> will be the <see cref="ImageFormat.Jpeg"/>.</remarks>
/// Initializes a new instance of the <see cref="JpegDecoder"/> class.
/// </summary>
/// <remarks><see cref="ImageDecoder.InputFormat"/> will be the <see cref="ImageFormat.Jpeg"/>.</remarks>
/// Gets or sets the downscale at which the jpeg image should be decoded.
/// </summary>
/// <exception cref="ArgumentException"><paramref name="value"/> is invalid.</exception>
/// Gets or sets the downscale at which the jpeg image should be decoded.
/// </summary>
/// <exception cref="ArgumentException"><paramref name="value"/> is invalid.</exception>
public class GifDecoder : ImageDecoder
{
private static readonly byte[] _header = { (byte)'G', (byte)'I', (byte)'F' };
public class GifDecoder : ImageDecoder
{
private static readonly byte[] _header = { (byte)'G', (byte)'I', (byte)'F' };
/// Initializes a new instance of the <see cref="GifDecoder"/> class.
/// </summary>
/// <remarks><see cref="ImageDecoder.InputFormat"/> will be the <see cref="ImageFormat.Gif"/>.</remarks>
/// Initializes a new instance of the <see cref="GifDecoder"/> class.
/// </summary>
/// <remarks><see cref="ImageDecoder.InputFormat"/> will be the <see cref="ImageFormat.Gif"/>.</remarks>