Beispiel #1
0
        private void CheckImageItemType(uint itemId, ImageGridInfo gridInfo, string imageName, bool checkingGridChildren = false)
        {
            IItemInfoEntry entry = this.parser.TryGetItemInfoEntry(itemId);

            if (entry is null)
            {
                ExceptionUtil.ThrowFormatException($"The { imageName } image does not exist.");
            }
            else if (entry.ItemType != ItemInfoEntryTypes.AV01)
            {
                if (entry.ItemType == ItemInfoEntryTypes.ImageGrid)
                {
                    if (checkingGridChildren)
                    {
                        ExceptionUtil.ThrowFormatException("Nested image grids are not supported.");
                    }

                    if (gridInfo is null)
                    {
                        ExceptionUtil.ThrowFormatException($"The { imageName } image does not have any image grid information.");
                    }

                    IReadOnlyList <uint> childImageIds = gridInfo.ChildImageIds;

                    for (int i = 0; i < childImageIds.Count; i++)
                    {
                        CheckImageItemType(childImageIds[i], null, imageName, true);
                    }
                }
                else
                {
                    ExceptionUtil.ThrowFormatException($"The { imageName } image is not a supported format.");
                }
            }
        }
Beispiel #2
0
        private void EnsurePrimaryItemIsNotHidden()
        {
            IItemInfoEntry entry = this.parser.TryGetItemInfoEntry(this.primaryItemId);

            if (entry is null)
            {
                ExceptionUtil.ThrowFormatException("The primary item does not exist.");
            }
            else if (entry.IsHidden)
            {
                ExceptionUtil.ThrowFormatException("The primary item cannot be marked as hidden.");
            }
        }
Beispiel #3
0
        public ItemLocationEntry TryGetExifLocation(uint itemId)
        {
            foreach (IItemReferenceEntry item in GetMatchingReferences(itemId, ReferenceTypes.ContentDescription))
            {
                IItemInfoEntry entry = TryGetItemInfoEntry(item.FromItemId);

                if (entry != null && entry.ItemType == ItemInfoEntryTypes.Exif)
                {
                    return(TryGetItemLocation(item.FromItemId));
                }
            }

            return(null);
        }
Beispiel #4
0
        private void CheckRequiredImageProperties(uint itemId, ImageGridInfo gridInfo, string imageName)
        {
            bool hasUnsupportedProperties = false;

            IItemInfoEntry entry = this.parser.TryGetItemInfoEntry(itemId);

            if (entry is null)
            {
                ExceptionUtil.ThrowFormatException($"The { imageName } image does not exist.");
            }
            else if (entry.ItemType == ItemInfoEntryTypes.AV01)
            {
                hasUnsupportedProperties = this.parser.HasUnsupportedEssentialProperties(itemId);
            }
            else if (entry.ItemType == ItemInfoEntryTypes.ImageGrid)
            {
                if (gridInfo is null)
                {
                    ExceptionUtil.ThrowFormatException($"The { imageName } image does not have any image grid information.");
                }

                IReadOnlyList <uint> childImageIds = gridInfo.ChildImageIds;

                for (int i = 0; i < childImageIds.Count; i++)
                {
                    if (this.parser.HasUnsupportedEssentialProperties(childImageIds[i]))
                    {
                        hasUnsupportedProperties = true;
                        break;
                    }
                }
            }
            else
            {
                ExceptionUtil.ThrowFormatException($"The { imageName } image is not a supported format.");
            }

            if (hasUnsupportedProperties)
            {
                ExceptionUtil.ThrowFormatException($"The { imageName } image has essential item properties that are not supported.");
            }
        }
Beispiel #5
0
        public ItemLocationEntry TryGetXmpLocation(uint itemId)
        {
            foreach (IItemReferenceEntry item in GetMatchingReferences(itemId, ReferenceTypes.ContentDescription))
            {
                IItemInfoEntry entry = TryGetItemInfoEntry(item.FromItemId);

                if (entry != null && entry.ItemType == ItemInfoEntryTypes.Mime)
                {
                    MimeItemInfoEntryBox mimeItemInfo = (MimeItemInfoEntryBox)entry;
                    string contentType = mimeItemInfo.ContentType.Value;

                    if (string.Equals(contentType, XmpItemInfoEntry.XmpContentType, StringComparison.Ordinal))
                    {
                        return(TryGetItemLocation(item.FromItemId));
                    }
                }
            }

            return(null);
        }
Beispiel #6
0
        private Size GetImageSize(uint itemId, ImageGridInfo gridInfo, string imageName)
        {
            IItemInfoEntry entry = this.parser.TryGetItemInfoEntry(itemId);

            uint width;
            uint height;

            if (entry.ItemType == ItemInfoEntryTypes.AV01)
            {
                ImageSpatialExtentsBox extents = this.parser.TryGetAssociatedItemProperty <ImageSpatialExtentsBox>(itemId);

                if (extents is null)
                {
                    ExceptionUtil.ThrowFormatException($"The { imageName } image size property was not found.");
                }

                width  = extents.ImageWidth;
                height = extents.ImageHeight;
            }
            else if (entry.ItemType == ItemInfoEntryTypes.ImageGrid)
            {
                if (gridInfo is null)
                {
                    ExceptionUtil.ThrowFormatException($"The { imageName } image does not have any image grid information.");
                }

                width  = gridInfo.OutputWidth;
                height = gridInfo.OutputHeight;
            }
            else
            {
                throw new FormatException($"The { imageName } image is not a supported format.");
            }

            if (width > int.MaxValue || height > int.MaxValue)
            {
                throw new FormatException($"The { imageName } image dimensions are too large.");
            }

            return(new Size((int)width, (int)height));
        }
Beispiel #7
0
        private ImageGridDescriptor TryGetImageGridDescriptor(uint itemId)
        {
            IItemInfoEntry entry = TryGetItemInfoEntry(itemId);

            if (entry != null && entry.ItemType == ItemInfoEntryTypes.ImageGrid)
            {
                ItemLocationEntry locationEntry = TryGetItemLocation(itemId);

                if (locationEntry != null)
                {
                    if (locationEntry.TotalItemSize < ImageGridDescriptor.SmallDescriptorLength)
                    {
                        ExceptionUtil.ThrowFormatException("Invalid image grid descriptor length.");
                    }

                    using (AvifItemData itemData = ReadItemData(locationEntry))
                    {
                        Stream stream = null;

                        try
                        {
                            stream = itemData.GetStream();

                            using (EndianBinaryReader imageGridReader = new EndianBinaryReader(stream, this.reader.Endianess, this.arrayPool))
                            {
                                stream = null;

                                return(new ImageGridDescriptor(imageGridReader, itemData.Length));
                            }
                        }
                        finally
                        {
                            stream?.Dispose();
                        }
                    }
                }
            }

            return(null);
        }