Ejemplo n.º 1
0
 internal virtual void Initialize(ImageDecoderHandle handle)
 {
     if (_colorSpace.HasValue)
     {
         NativeDecoder.SetColorspace(Handle, _colorSpace.Value.ToImageColorSpace()).ThrowIfFailed("Failed to set color space");
     }
 }
Ejemplo n.º 2
0
        private IEnumerable <BitmapFrame> RunDecoding()
        {
            IntPtr imageHandle = IntPtr.Zero;
            IntPtr outBuffer   = IntPtr.Zero;

            try
            {
                NativeDecoder.DecodeRun(Handle, out imageHandle).ThrowIfFailed("Failed to decode");

                NativeUtil.GetImage(imageHandle, out int width, out int height, out ImageColorSpace colorspace,
                                    out outBuffer, out int size).ThrowIfFailed("Failed to get decoded image.");

                yield return(new BitmapFrame(outBuffer, width, height, size));
            }
            finally
            {
                if (outBuffer != IntPtr.Zero)
                {
                    LibcSupport.Free(outBuffer);
                }

                if (imageHandle != IntPtr.Zero)
                {
                    NativeUtil.Destroy(imageHandle).ThrowIfFailed("Failed to destroy handle");
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Decodes an image from the specified file.
        /// </summary>
        /// <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.<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">
        ///     <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>
        /// <since_tizen> 4 </since_tizen>
        public async Task <IEnumerable <BitmapFrame> > DecodeAsync(string inputFilePath)
        {
            if (inputFilePath == null)
            {
                throw new ArgumentNullException(nameof(inputFilePath));
            }

            if (inputFilePath.Length == 0)
            {
                throw new ArgumentException("path is empty.", nameof(inputFilePath));
            }

            if (CheckHeader(inputFilePath) == false)
            {
                throw new FileFormatException("The file has an invalid header.");
            }

            var pathPtr = Marshal.StringToHGlobalAnsi(inputFilePath);

            try
            {
                NativeDecoder.SetInputPath(Handle, pathPtr).ThrowIfFailed("Failed to set input file path for decoding");

                return(await DecodeAsync());
            }
            finally
            {
                Marshal.FreeHGlobal(pathPtr);
            }
        }
Ejemplo n.º 4
0
        internal ImageDecoder(ImageFormat format)
        {
            NativeDecoder.Create(out _handle).ThrowIfFailed("Failed to create ImageDecoder");

            Debug.Assert(_handle != null);

            InputFormat = format;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Decodes an image from the buffer.
        /// </summary>
        /// <param name="inputBuffer">The image buffer 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.</remarks>
        /// <exception cref="ArgumentNullException"><paramref name="inputBuffer"/> is null.</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>
        /// <since_tizen> 4 </since_tizen>
        public Task <IEnumerable <BitmapFrame> > DecodeAsync(byte[] inputBuffer)
        {
            if (inputBuffer == null)
            {
                throw new ArgumentNullException(nameof(inputBuffer));
            }

            if (inputBuffer.Length == 0)
            {
                throw new ArgumentException("buffer is empty.", nameof(inputBuffer));
            }

            if (CheckHeader(inputBuffer) == false)
            {
                throw new FileFormatException("buffer has an invalid header.");
            }

            NativeDecoder.SetInputBuffer(Handle, inputBuffer, (ulong)inputBuffer.Length).
            ThrowIfFailed("Failed to set input buffer for decoding");

            return(DecodeAsync());
        }
Ejemplo n.º 6
0
        internal override void Initialize(ImageDecoderHandle handle)
        {
            base.Initialize(handle);

            NativeDecoder.SetJpegDownscale(handle, Downscale).ThrowIfFailed("Failed to set downscale for decoding");
        }