public void ExtractRegionFullSize(int x, int y, int width, int height)
        {
            var filename = Path.GetFullPath(@"test_image.tif");
            var request  = new ImageRequest
                           (
                "",
                new ImageRegion(ImageRegionMode.Region, x, y, width, height),
                new ImageSize(ImageSizeMode.Full),
                new ImageRotation(0, false),
                ImageQuality.@default,
                ImageFormat.jpg
                           );

            (var state, var img) = TiffExpander.ExpandRegion(null, Log, new Uri(filename), request, false);
            using (img)
            {
                Assert.IsNotNull(img, "Image is null");
                Assert.AreEqual(width, img.Width, "Image width does not match expected width");
                Assert.AreEqual(height, img.Height, "Image height does not match expected height");

                using (var bmp = SKBitmap.FromImage(img))
                {
                    (var coli, var colj) = (x / 100, y / 100);
                    var colour = TestColours[coli, colj];
                    foreach (var c in bmp.Pixels.Distinct())
                    {
                        Assert.AreEqual(new SKColor(colour.Item1, colour.Item2, colour.Item3), c, "Expected colour values do not match");
                    }
                }
            }
        }
        public void ExtractSquareMax()
        {
            var filename = Path.GetFullPath(@"test_image.tif");
            var request  = new ImageRequest
                           (
                "",
                new ImageRegion(ImageRegionMode.Square),
                new ImageSize(ImageSizeMode.Max),
                new ImageRotation(0, false),
                ImageQuality.@default,
                ImageFormat.jpg
                           );

            (var state, var img) = TiffExpander.ExpandRegion(null, Log, new Uri(filename), request, false);
            using (img)
            {
                Assert.IsNotNull(img, "Image is null");
                Assert.AreEqual(1000, img.Width, "Image width does not match expected width");
                Assert.AreEqual(1000, img.Height, "Image height does not match expected height");

                using (var bmp = SKBitmap.FromImage(img))
                {
                    Assert.AreEqual(100, bmp.Pixels.Distinct().Count());
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Extract region from source image
        /// </summary>
        /// <param name="imageUri">The <see cref="Uri"/> of the source image</param>
        /// <param name="request">The <see cref="ImageRequest"/></param>
        /// <param name="allowSizeAboveFull">Allow the output size to exceed the original dimensions of the image</param>
        /// <param name="quality">The <see cref="ImageQuality"/> settings for encoding</param>
        /// <returns></returns>
        public async Task <(ProcessState, SKImage)> ExtractRegion(Uri imageUri, ImageRequest request, bool allowSizeAboveFull, TremendousIIIF.Common.Configuration.ImageQuality quality)
        {
            var sourceFormat = await GetSourceFormat(imageUri, request.RequestId);

            switch (sourceFormat)
            {
            case ImageFormat.jp2:
                return(J2KExpander.ExpandRegion(HttpClient, Log, imageUri, request, allowSizeAboveFull, quality));

            case ImageFormat.tif:
                return(TiffExpander.ExpandRegion(HttpClient, Log, imageUri, request, allowSizeAboveFull));

            default:
                throw new IOException("Unsupported source format");
            }
        }
        public void FullImage()
        {
            var filename = Path.GetFullPath(@"test_image.tif");
            var request  = new ImageRequest
                           (
                "",
                new ImageRegion(ImageRegionMode.Full),
                new ImageSize(ImageSizeMode.Full),
                new ImageRotation(0, false),
                ImageQuality.@default,
                ImageFormat.jpg
                           );

            (var state, var img) = TiffExpander.ExpandRegion(null, Log, new Uri(filename), request, false);

            Assert.IsNotNull(img, "Image is null");
            Assert.AreEqual(1000, img.Width, "Image width does not match expected width");
            Assert.AreEqual(1000, img.Height, "Image height does not match expected height");
        }