Exemplo n.º 1
0
        /// <summary>
        /// Decompresses the JPEG-LS encoded data passed in the source byte array into the destination array.
        /// </summary>
        /// <param name="source">The byte array that contains the JPEG-LS encoded data to decompress.</param>
        /// <param name="count">The number of bytes of the array to decompress.</param>
        /// <param name="pixels">The byte array that will hold the pixels when the function returns.</param>
        /// <exception cref="ArgumentNullException">source -or- pixels is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException">count contains an invalid value.</exception>
        /// <exception cref="ArgumentException">Thrown when the destination array is too small to hold the decompressed pixel data.</exception>
        /// <exception cref="InvalidDataException">Thrown when the source array contains an invalid encoded JPEG-LS bit stream.</exception>
        public static void Decompress(byte[] source, int count, byte[] pixels)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (count < 0 || count > source.Length)
            {
                throw new ArgumentOutOfRangeException(nameof(count), "count < 0 || count > source.Length");
            }
            if (pixels == null)
            {
                throw new ArgumentNullException(nameof(pixels));
            }

            var error = Environment.Is64BitProcess ?
                        SafeNativeMethods.JpegLsDecode64(pixels, pixels.Length, source, count, IntPtr.Zero, IntPtr.Zero) :
                        SafeNativeMethods.JpegLsDecode(pixels, pixels.Length, source, count, IntPtr.Zero, IntPtr.Zero);

            HandleResult(error);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Decompresses the JPEG-LS encoded data passed in the source byte array into the destination array.
        /// </summary>
        /// <param name="source">The byte array that contains the JPEG-LS encoded data to decompress.</param>
        /// <param name="count">The number of bytes of the array to decompress.</param>
        /// <param name="pixels">The byte array that will hold the pixels when the function returns.</param>
        /// <exception cref="ArgumentNullException">source -or- pixels is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException">count contains an invalid value.</exception>
        /// <exception cref="ArgumentException">Thrown when the destination array is too small to hold the decompressed pixel data.</exception>
        /// <exception cref="InvalidDataException">Thrown when the source array contains an invalid encodeded JPEG-LS bit stream.</exception>
        public static void Decompress(byte[] source, int count, byte[] pixels)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if (count < 0 || count > source.Length)
            {
                throw new ArgumentOutOfRangeException(nameof(count), "count < 0 || count > source.Length");
            }
            if (pixels == null)
            {
                throw new ArgumentNullException(nameof(pixels));
            }
            Contract.EndContractBlock();

            var         errorMessage = new StringBuilder(256);
            JpegLSError error        = Is64BitProcess ?
                                       SafeNativeMethods.JpegLsDecode64(pixels, pixels.Length, source, count, IntPtr.Zero, errorMessage) :
                                       SafeNativeMethods.JpegLsDecode(pixels, pixels.Length, source, count, IntPtr.Zero, errorMessage);

            HandleResult(error, errorMessage);
        }