Пример #1
0
 public DataInformationBox(BoxLocation loc, SequentialReader sr)
     : base(loc)
 {
     Boxes = BoxReader.ReadBoxes(sr, loc);
 }
Пример #2
0
 public ItemPropertyBox(BoxLocation loc, SequentialReader sr) : base(loc)
 {
     Boxes = BoxReader.ReadBoxes(sr, loc);
 }
        private const int ExifTag = 0x45786966; // Exif

        public static DirectoryList ReadMetadata(Stream stream)
        {
            var directories = new List <Directory>();

            //
            // Read all boxes from the file
            //

            var reader = new SequentialStreamReader(stream);

            var boxes = BoxReader.ReadBoxes(reader);

            //
            // Map those boxes to directories
            //

            ParseQuickTimeTest();

            uint primaryItem = boxes.Descendant <PrimaryItemBox>()?.PrimaryItem ?? uint.MaxValue;
            var  itemRefs    = (boxes.Descendant <ItemReferenceBox>()?.Boxes ?? new SingleItemTypeReferenceBox[0])
                               .Where(i => i.Type == BoxTypes.ThmbTag || i.Type == BoxTypes.CdscTag).ToList();

            ParseImageProperties();

            if (stream.CanSeek)
            {
                ParseItemSegments();
            }

            return(directories);

            void ParseQuickTimeTest()
            {
                if (boxes.Descendant <FileTypeBox>() is { } ftype)
                {
                    var dir = new QuickTimeFileTypeDirectory();
                    if (ftype.MajorBrand > 0)
                    {
                        dir.Set(QuickTimeFileTypeDirectory.TagMajorBrand, ftype.MajorBrandString);
                    }

                    if (ftype.MinorBrand > 0)
                    {
                        dir.Set(QuickTimeFileTypeDirectory.TagMinorVersion, ftype.MinorBrandString);
                    }

                    if (ftype.CompatibleBrands.Count > 0)
                    {
                        dir.Set(
                            QuickTimeFileTypeDirectory.TagCompatibleBrands,
                            string.Join(", ", ftype.CompatibleBrandStrings.ToArray()));
                    }

                    directories.Add(dir);
                }
            }

            void ParseImageProperties()
            {
                uint[] allPrimaryTiles = (boxes.Descendant <ItemReferenceBox>()?.Boxes ?? new SingleItemTypeReferenceBox[0])
                                         .SelectMany(i => i.FromItemId == primaryItem && i.Type == BoxTypes.DimgTag ? i.ToItemIds : new uint[0])
                                         .ToArray();
                var itemPropertyBox = boxes.Descendant <ItemPropertyBox>();

                if (itemPropertyBox == null)
                {
                    return;
                }
                var props        = itemPropertyBox.Boxes.Descendant <ItemPropertyContainerBox>().Boxes;
                var associations = itemPropertyBox.Boxes.Descendant <ItemPropertyAssociationBox>();

                ParsePropertyBoxes(
                    "HEIC Primary Item Properties",
                    ImageProperties(primaryItem, allPrimaryTiles, associations, props));

                foreach (var itemRef in itemRefs)
                {
                    ParsePropertyBoxes(
                        "HEIC Thumbnail Properties",
                        ImageProperties(itemRef.FromItemId, new uint[0], associations, props));
                }

                return;
Пример #4
0
 public DataReferenceBox(BoxLocation location, SequentialReader reader)
     : base(location, reader)
 {
     BoxCount = reader.GetUInt32();
     Boxes    = BoxReader.ReadBoxes(reader, location);
 }
Пример #5
0
 public ItemInformationBox(BoxLocation location, SequentialReader reader)
     : base(location, reader)
 {
     Count = Version == 0 ? reader.GetUInt16() : reader.GetUInt32();
     Boxes = BoxReader.ReadBoxes(reader, location);
 }
Пример #6
0
 public MetaBox(BoxLocation location, SequentialReader reader)
     : base(location, reader)
 {
     Boxes = BoxReader.ReadBoxes(reader, location);
 }