private async Task SingleImageTypeTest(
            IList <string> resourceNames,
            ImageFormat expectedImageType)
        {
            foreach (string name in resourceNames)
            {
                Stream resourceStream = await GetResourceStream(name);

                try
                {
                    Assert.AreEqual(
                        expectedImageType,
                        ImageFormatChecker.GetImageFormat(resourceStream),
                        "failed with resource: " + name);
                }
                finally
                {
                    resourceStream.Dispose();
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Decodes image.
        /// </summary>
        /// <param name="encodedImage">
        /// Input image (encoded bytes plus meta data).
        /// </param>
        /// <param name="length">
        /// If image type supports decoding incomplete image then
        /// determines where the image data should be cut for decoding.
        /// </param>
        /// <param name="qualityInfo">
        /// Quality information for the image.
        /// </param>
        /// <param name="options">
        /// Options that cange decode behavior.
        /// </param>
        public Task <CloseableImage> DecodeImageAsync(
            EncodedImage encodedImage,
            int length,
            IQualityInfo qualityInfo,
            ImageDecodeOptions options)
        {
            ImageFormat imageFormat = encodedImage.Format;

            if (imageFormat == ImageFormat.UNINITIALIZED || imageFormat == ImageFormat.UNKNOWN)
            {
                imageFormat = ImageFormatChecker.GetImageFormat_WrapIOException(
                    encodedImage.GetInputStream());

                encodedImage.Format = imageFormat;
            }

            switch (imageFormat)
            {
            case ImageFormat.UNKNOWN:
                throw new ArgumentException("unknown image format");

            case ImageFormat.JPEG:
                return(DecodeJpegAsync(encodedImage, length, qualityInfo)
                       .ContinueWith(
                           task => ((CloseableImage)task.Result),
                           TaskContinuationOptions.ExecuteSynchronously));

            case ImageFormat.GIF:
                return(DecodeGifAsync(encodedImage, options));

            case ImageFormat.WEBP_ANIMATED:
                return(DecodeAnimatedWebpAsync(encodedImage, options));

            default:
                return(DecodeStaticImageAsync(encodedImage)
                       .ContinueWith(
                           task => ((CloseableImage)task.Result),
                           TaskContinuationOptions.ExecuteSynchronously));
            }
        }
예제 #3
0
        /// <summary>
        /// Sets the encoded image meta data.
        /// </summary>
        public async Task ParseMetaDataAsync()
        {
            ImageFormat format = ImageFormatChecker.GetImageFormat_WrapIOException(
                GetInputStream());

            Format = format;

            // Dimensions decoding is not yet supported for WebP since
            // BitmapUtil.DecodeDimensions has a bug where it will return 100x100 for
            // some WebPs even though those are not its actual dimensions.
            if (!ImageFormatHelper.IsWebpFormat(Format))
            {
                Tuple <int, int> dimensions = await BitmapUtil
                                              .DecodeDimensionsAsync(GetInputStream())
                                              .ConfigureAwait(false);

                if (dimensions != default(Tuple <int, int>))
                {
                    Width  = dimensions.Item1;
                    Height = dimensions.Item2;

                    // Load the rotation angle only if we have the dimensions
                    if (Format == ImageFormat.JPEG)
                    {
                        if (RotationAngle == UNKNOWN_ROTATION_ANGLE)
                        {
                            RotationAngle = JfifUtil.GetAutoRotateAngleFromOrientation(
                                JfifUtil.GetOrientation(GetInputStream()));
                        }
                    }
                    else
                    {
                        RotationAngle = 0;
                    }
                }
            }
        }