예제 #1
0
        public byte[] GetExifData()
        {
            VerifyNotDisposed();

            ItemLocationEntry entry = this.parser.TryGetExifLocation(this.primaryItemId);

            if (entry != null)
            {
                ulong length = entry.TotalItemSize;

                // Ignore any EXIF blocks that are larger than 2GB.
                if (length < int.MaxValue)
                {
                    using (AvifItemData itemData = this.parser.ReadItemData(entry))
                        using (Stream stream = itemData.GetStream())
                        {
                            // The EXIF data block has a header that indicates the number of bytes
                            // that come before the start of the TIFF header.
                            // See ISO/IEC 23008-12:2017 section A.2.1.

                            long tiffStartOffset = stream.TryReadUInt32BigEndian();

                            if (tiffStartOffset != -1)
                            {
                                long dataLength = (long)length - tiffStartOffset - sizeof(uint);

                                if (dataLength > 0)
                                {
                                    if (tiffStartOffset != 0)
                                    {
                                        stream.Position += tiffStartOffset;
                                    }

                                    byte[] bytes = new byte[dataLength];

                                    stream.ProperRead(bytes, 0, bytes.Length);

                                    return(bytes);
                                }
                            }
                        }
                }
            }

            return(null);
        }
예제 #2
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);
        }