コード例 #1
0
 public void ShouldReturnTheCorrectTypeWhenImageHasColorProfile()
 {
     using (var image = HeifImage.Decode(TestFiles.Dog))
     {
         Assert.Equal(HeifColorProfileType.Prof, image.ColorProfileType);
     }
 }
コード例 #2
0
        static unsafe Image CreateEightBitImageWithAlpha(HeifImage heifImage)
        {
            var image = new Image <Rgba32>(heifImage.Width, heifImage.Height);

            var heifPlaneData = heifImage.GetPlane(HeifChannel.Interleaved);

            byte *srcScan0  = (byte *)heifPlaneData.Scan0;
            int   srcStride = heifPlaneData.Stride;

            for (int y = 0; y < image.Height; y++)
            {
                byte *src = srcScan0 + (y * srcStride);
                var   dst = image.GetPixelRowSpan(y);

                for (int x = 0; x < image.Width; x++)
                {
                    ref var pixel = ref dst[x];

                    pixel.R = src[0];
                    pixel.G = src[1];
                    pixel.B = src[2];
                    pixel.A = src[3];

                    src += 4;
                }
            }
コード例 #3
0
 public void ShouldReturnNotPresentWhenImageHasNoColorProfile()
 {
     using (var image = HeifImage.Decode(TestFiles.C034))
     {
         Assert.Equal(HeifColorProfileType.NotPresent, image.ColorProfileType);
     }
 }
コード例 #4
0
            public void ShouldReturnTheCorrectWidthAndHeight()
            {
                var metadata = HeifImage.GetMetadata(TestFiles.Camel);

                Assert.Equal(1596, metadata.Width);
                Assert.Equal(1064, metadata.Height);
            }
コード例 #5
0
            public void ShouldThrowExceptionWhenFileIsInvalid()
            {
                var data = new byte[] { 42 };

                var exception = Assert.Throws <HeifException>(() => HeifImage.DecodeCollection(data));

                Assert.Equal("Unable to create heif context.", exception.Message);
            }
コード例 #6
0
 public void ShouldBeAbleToDecodeAvifFile()
 {
     using (var image = HeifImage.Decode(TestFiles.Bbb_4k))
     {
         Assert.Equal(3840, image.Metadata.Width);
         Assert.Equal(2160, image.Metadata.Height);
     }
 }
コード例 #7
0
 public void ShouldLoadTheMetadata()
 {
     using (var image = HeifImage.Decode(TestFiles.Camel))
     {
         Assert.Equal(1596, image.Metadata.Width);
         Assert.Equal(1064, image.Metadata.Height);
     }
 }
コード例 #8
0
            public void ShouldReturnNullForImageWithoutRawColorProfile()
            {
                using (var image = HeifImage.Decode(TestFiles.Camel))
                {
                    var profile = image.GetRawColorProfile();

                    Assert.Null(profile);
                }
            }
コード例 #9
0
            public void ShouldReturnTheProfile()
            {
                using (var image = HeifImage.Decode(TestFiles.C034))
                {
                    var profile = image.GetExifProfile();

                    Assert.NotNull(profile);
                    Assert.Equal(176, profile.Length);
                }
            }
コード例 #10
0
            public void ShouldReturnByteArrayWithCorrectSize()
            {
                using (var image = HeifImage.Decode(TestFiles.Camel))
                {
                    var data = image.ToYCbCrByteArray();

                    Assert.NotNull(data);
                    Assert.Equal(1596 * 1064 * 3, data.Length);
                }
            }
コード例 #11
0
            public void ShouldReturnThePlane(HeifChannel channel, int stride)
            {
                using (var image = HeifImage.Decode(TestFiles.Camel))
                {
                    var plane = image.GetPlane(channel);

                    Assert.Equal(stride, plane.Stride);
                    Assert.NotEqual(IntPtr.Zero, plane.Data);
                }
            }
コード例 #12
0
            public void ShouldReturnTheProfile()
            {
                using (var image = HeifImage.Decode(TestFiles.Dog))
                {
                    var profile = image.GetRawColorProfile();

                    Assert.NotNull(profile);
                    Assert.Equal(HeifColorProfileType.Prof, profile.Type);
                    Assert.NotNull(profile.Data);
                    Assert.Equal(548, profile.Data.Length);
                }
            }
コード例 #13
0
            public void ShouldReturnTheCorrectWidthAndHeight()
            {
                var metadatas = HeifImage.GetCollectionMetadata(TestFiles.Collection);

                Assert.Equal(4, metadatas.Count);

                foreach (var metadata in metadatas)
                {
                    Assert.Equal(1280, metadata.Width);
                    Assert.Equal(720, metadata.Height);
                }
            }
コード例 #14
0
            public void ShouldLoadTheMetadata()
            {
                using (var images = HeifImage.DecodeCollection(TestFiles.Collection))
                {
                    Assert.Equal(4, images.Count);

                    foreach (var image in images)
                    {
                        Assert.Equal(1280, image.Metadata.Width);
                        Assert.Equal(720, image.Metadata.Height);
                    }
                }
            }
コード例 #15
0
        public static HeifImage ConvertToHeifImage(Image <Rgba32> image)
        {
            AnalyzeImage(image, out bool isGrayscale, out bool hasTransparency);

            var        colorspace = isGrayscale ? HeifColorspace.Monochrome : HeifColorspace.Rgb;
            HeifChroma chroma;

            if (colorspace == HeifColorspace.Monochrome)
            {
                chroma = HeifChroma.Monochrome;
            }
            else
            {
                chroma = hasTransparency ? HeifChroma.InterleavedRgba32 : HeifChroma.InterleavedRgb24;
            }

            HeifImage heifImage = null;
            HeifImage temp      = null;

            try
            {
                temp = new HeifImage(image.Width, image.Height, colorspace, chroma);

                if (colorspace == HeifColorspace.Monochrome)
                {
                    temp.AddPlane(HeifChannel.Y, image.Width, image.Height, 8);

                    if (hasTransparency)
                    {
                        temp.AddPlane(HeifChannel.Alpha, image.Width, image.Height, 8);
                    }

                    CopyGrayscale(image, temp, hasTransparency);
                }
                else
                {
                    temp.AddPlane(HeifChannel.Interleaved, image.Width, image.Height, 8);

                    CopyRgb(image, temp, hasTransparency);
                }

                heifImage = temp;
                temp      = null;
            }
            finally
            {
                temp?.Dispose();
            }

            return(heifImage);
        }
コード例 #16
0
        public static HeifImage ConvertToHeifImage(Image <Rgb24> image)
        {
            bool isGrayscale = IsGrayscale(image);

            var colorspace = isGrayscale ? HeifColorspace.Monochrome : HeifColorspace.Rgb;
            var chroma     = colorspace == HeifColorspace.Monochrome ? HeifChroma.Monochrome : HeifChroma.InterleavedRgb24;

            HeifImage heifImage = null;
            HeifImage temp      = null;

            try
            {
                temp = new HeifImage(image.Width, image.Height, colorspace, chroma);

                if (colorspace == HeifColorspace.Monochrome)
                {
                    temp.AddPlane(HeifChannel.Y, image.Width, image.Height, 8);

                    CopyGrayscale(image, temp);
                }
                else
                {
                    temp.AddPlane(HeifChannel.Interleaved, image.Width, image.Height, 8);

                    CopyRgb(image, temp);
                }

                heifImage = temp;
                temp      = null;
            }
            finally
            {
                temp?.Dispose();
            }

            return(heifImage);
        }