public virtual async Task <ActionResult> Details(string id)
        {
            var          cts  = TaskHelper.CreateChildCancellationTokenSource(ClientDisconnectedToken());
            JpegMetadata data = null;

            try
            {
                var repository = FileSystemGenericRepositoryFactory.CreateJpegMetadataRepositoryReadOnly(cts.Token, PhysicalPath, IncludeSubDirectories);

                data = await repository.MetadataGetByPathAsync(id.Replace("/", "\\"));

                if (data == null)
                {
                    return(HandleReadException());
                }
            }
            catch
            {
                return(HandleReadException());
            }

            ViewBag.PageTitle = Title;
            ViewBag.Admin     = Admin;

            var dto = Mapper.Map <JpegMetadataDto>(data);

            return(View("Details", dto));
        }
        public virtual ActionResult Edit(string id, JpegMetadataDto dto)
        {
            var cts = TaskHelper.CreateChildCancellationTokenSource(ClientDisconnectedToken());

            if (ModelState.IsValid)
            {
                try
                {
                    var metadata = new JpegMetadata(PhysicalPath + id.Replace("/", "\\"));
                    Mapper.Map(dto, metadata);

                    var lat = metadata.Latitude;

                    metadata.SaveWithCaption(dto.Caption, dto.DateCreated);

                    //await Service.UpdateAsync(dto, cts.Token);
                    return(RedirectToControllerDefault().WithSuccess(this, Messages.UpdateSuccessful));
                }
                catch (Exception ex)
                {
                    HandleUpdateException(ex);
                }
            }

            ViewBag.PageTitle = Title;
            ViewBag.Admin     = Admin;
            return(View("Edit", dto));
        }
 public void Decode_DetectsCorrectColorType <TPixel>(TestImageProvider <TPixel> provider, JpegColorType expectedColorType)
     where TPixel : unmanaged, IPixel <TPixel>
 {
     using (Image <TPixel> image = provider.GetImage(JpegDecoder))
     {
         JpegMetadata meta = image.Metadata.GetJpegMetadata();
         Assert.Equal(expectedColorType, meta.ColorType);
     }
 }
Exemplo n.º 4
0
        public void Quality_BothComponentsQuality()
        {
            int quality = 50;

            var meta = new JpegMetadata {
                LuminanceQuality = quality, ChrominanceQuality = quality
            };

            Assert.Equal(meta.Quality, quality);
        }
Exemplo n.º 5
0
        public void Quality_LuminanceOnlyQuality()
        {
            int quality = 50;

            var meta = new JpegMetadata {
                LuminanceQuality = quality
            };

            Assert.Equal(meta.Quality, quality);
        }
Exemplo n.º 6
0
        public void Quality_ReturnsMaxQuality()
        {
            int qualityLuma   = 50;
            int qualityChroma = 30;

            var meta = new JpegMetadata {
                LuminanceQuality = qualityLuma, ChrominanceQuality = qualityChroma
            };

            Assert.Equal(meta.Quality, qualityLuma);
        }
        public void Identify_DetectsCorrectColorType(string imagePath, JpegColorType expectedColorType)
        {
            var testFile = TestFile.Create(imagePath);

            using (var stream = new MemoryStream(testFile.Bytes, false))
            {
                IImageInfo   image = JpegDecoder.Identify(Configuration.Default, stream);
                JpegMetadata meta  = image.Metadata.GetJpegMetadata();
                Assert.Equal(expectedColorType, meta.ColorType);
            }
        }
Exemplo n.º 8
0
        public void CloneIsDeep()
        {
            var meta = new JpegMetadata {
                Quality = 50
            };
            var clone = (JpegMetadata)meta.DeepClone();

            clone.Quality = 99;

            Assert.False(meta.Quality.Equals(clone.Quality));
        }
        public void Identify_VerifyQuality(string imagePath, int quality)
        {
            var testFile = TestFile.Create(imagePath);

            using (var stream = new MemoryStream(testFile.Bytes, false))
            {
                var          decoder = new JpegDecoder();
                IImageInfo   image   = decoder.Identify(Configuration.Default, stream);
                JpegMetadata meta    = image.Metadata.GetJpegMetadata();
                Assert.Equal(quality, meta.Quality);
            }
        }
Exemplo n.º 10
0
        public void CloneIsDeep()
        {
            var meta = new JpegMetadata {
                Quality = 50, ColorType = JpegColorType.Luminance
            };
            var clone = (JpegMetadata)meta.DeepClone();

            clone.Quality   = 99;
            clone.ColorType = JpegColorType.YCbCrRatio420;

            Assert.False(meta.Quality.Equals(clone.Quality));
            Assert.False(meta.ColorType.Equals(clone.ColorType));
        }
Exemplo n.º 11
0
        public void Decode_VerifyQuality(string imagePath, int quality)
        {
            var testFile = TestFile.Create(imagePath);

            using (var stream = new MemoryStream(testFile.Bytes, false))
            {
                using (Image image = JpegDecoder.Decode(Configuration.Default, stream))
                {
                    JpegMetadata meta = image.Metadata.GetJpegMetadata();
                    Assert.Equal(quality, meta.Quality);
                }
            }
        }
Exemplo n.º 12
0
        public void Decode_VerifyQuality(string imagePath, int quality)
        {
            var testFile = TestFile.Create(imagePath);

            using (var stream = new MemoryStream(testFile.Bytes, false))
            {
                var decoder = new JpegDecoder();
                using (Image <Rgba32> image = decoder.Decode <Rgba32>(Configuration.Default, stream))
                {
                    JpegMetadata meta = image.Metadata.GetFormatMetadata(JpegFormat.Instance);
                    Assert.Equal(quality, meta.Quality);
                }
            }
        }
        public void Encode_PreservesColorType <TPixel>(TestImageProvider <TPixel> provider, JpegColorType expectedColorType)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            // arrange
            using Image <TPixel> input = provider.GetImage(JpegDecoder);
            using var memoryStream = new MemoryStream();

            // act
            input.Save(memoryStream, JpegEncoder);

            // assert
            memoryStream.Position = 0;
            using var output      = Image.Load <Rgba32>(memoryStream);
            JpegMetadata meta = output.Metadata.GetJpegMetadata();

            Assert.Equal(expectedColorType, meta.ColorType);
        }
        public void Encode_PreservesQuality(string imagePath, int quality)
        {
            var testFile = TestFile.Create(imagePath);

            using (Image <Rgba32> input = testFile.CreateRgba32Image())
            {
                using (var memStream = new MemoryStream())
                {
                    input.Save(memStream, JpegEncoder);

                    memStream.Position = 0;
                    using (var output = Image.Load <Rgba32>(memStream))
                    {
                        JpegMetadata meta = output.Metadata.GetJpegMetadata();
                        Assert.Equal(quality, meta.Quality);
                    }
                }
            }
        }
        public void Encode_WithUnsupportedColorType_FromInputImage_DefaultsToYCbCr420 <TPixel>(TestImageProvider <TPixel> provider)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            // arrange
            using Image <TPixel> input = provider.GetImage(JpegDecoder);
            using var memoryStream = new MemoryStream();

            // act
            input.Save(memoryStream, new JpegEncoder()
            {
                Quality = 75
            });

            // assert
            memoryStream.Position = 0;
            using var output      = Image.Load <Rgba32>(memoryStream);
            JpegMetadata meta = output.Metadata.GetJpegMetadata();

            Assert.Equal(JpegColorType.YCbCrRatio420, meta.ColorType);
        }
        public void Encode_WithUnsupportedColorType_DefaultsToYCbCr420(JpegColorType colorType)
        {
            // arrange
            var jpegEncoder = new JpegEncoder()
            {
                ColorType = colorType
            };

            using var input        = new Image <Rgb24>(10, 10);
            using var memoryStream = new MemoryStream();

            // act
            input.Save(memoryStream, jpegEncoder);

            // assert
            memoryStream.Position = 0;
            using var output      = Image.Load <Rgba32>(memoryStream);
            JpegMetadata meta = output.Metadata.GetJpegMetadata();

            Assert.Equal(JpegColorType.YCbCrRatio420, meta.ColorType);
        }
Exemplo n.º 17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JpegMetadata"/> class.
 /// </summary>
 /// <param name="other">The metadata to create an instance from.</param>
 private JpegMetadata(JpegMetadata other)
 {
     this.Quality   = other.Quality;
     this.ColorType = other.ColorType;
 }
Exemplo n.º 18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JpegMetadata"/> class.
 /// </summary>
 /// <param name="other">The metadata to create an instance from.</param>
 private JpegMetadata(JpegMetadata other) => this.Quality = other.Quality;
Exemplo n.º 19
0
        public JpegMetadata MapFileInfoToJpegMetadata(FileInfo fileInfo)
        {
            var metadata = new JpegMetadata(fileInfo.FullName, _physicalPath);

            return(metadata);
        }
Exemplo n.º 20
0
        public void Quality_DefaultQuality()
        {
            var meta = new JpegMetadata();

            Assert.Equal(meta.Quality, ImageSharp.Formats.Jpeg.Components.Quantization.DefaultQualityFactor);
        }