コード例 #1
0
            private ImageStateInfo InitializeFromSingleImage(CompressedAV1Image color, CompressedAV1Image alpha)
            {
                ulong mediaDataBoxContentSize = color.Data.ByteLength;
                uint  itemId = FirstItemId;

                AvifWriterItem colorItem = AvifWriterItem.CreateFromImage(itemId, "Color", color, false);

                itemId++;
                this.PrimaryItemId = colorItem.Id;
                this.items.Add(colorItem);

                if (alpha != null)
                {
                    AvifWriterItem alphaItem = AvifWriterItem.CreateFromImage(itemId, "Alpha", alpha, true);
                    itemId++;
                    alphaItem.ItemReferences.Add(new ItemReferenceEntryBox(alphaItem.Id, ReferenceTypes.AuxiliaryImage, this.PrimaryItemId));
                    this.AlphaItemId = alphaItem.Id;

                    this.items.Add(alphaItem);
                    mediaDataBoxContentSize += alpha.Data.ByteLength;
                }

                return(new ImageStateInfo(mediaDataBoxContentSize, itemId));
            }
コード例 #2
0
            private ImageStateInfo InitializeFromImageGrid(IReadOnlyList <CompressedAV1Image> colorImages,
                                                           IReadOnlyList <CompressedAV1Image> alphaImages,
                                                           ImageGridMetadata imageGridMetadata)
            {
                ulong mediaDataBoxContentSize = 0;
                uint  itemId = FirstItemId;

                List <uint> colorImageIds = new List <uint>(colorImages.Count);
                List <uint> alphaImageIds = alphaImages != null ? new List <uint>(alphaImages.Count) : null;

                for (int i = 0; i < colorImages.Count; i++)
                {
                    CompressedAV1Image color     = colorImages[i];
                    AvifWriterItem     colorItem = AvifWriterItem.CreateFromImage(itemId, null, color, false);
                    itemId++;
                    colorImageIds.Add(colorItem.Id);
                    this.items.Add(colorItem);
                    mediaDataBoxContentSize += color.Data.ByteLength;

                    if (alphaImages != null)
                    {
                        CompressedAV1Image alpha     = alphaImages[i];
                        AvifWriterItem     alphaItem = AvifWriterItem.CreateFromImage(itemId, null, alpha, true);
                        itemId++;
                        alphaItem.ItemReferences.Add(new ItemReferenceEntryBox(alphaItem.Id, ReferenceTypes.AuxiliaryImage, colorItem.Id));
                        alphaImageIds.Add(alphaItem.Id);

                        this.items.Add(alphaItem);
                        mediaDataBoxContentSize += alpha.Data.ByteLength;
                    }
                }

                ulong gridDescriptorLength;

                if (imageGridMetadata.OutputHeight > ushort.MaxValue || imageGridMetadata.OutputWidth > ushort.MaxValue)
                {
                    gridDescriptorLength = ImageGridDescriptor.LargeDescriptorLength;
                }
                else
                {
                    gridDescriptorLength = ImageGridDescriptor.SmallDescriptorLength;
                }

                AvifWriterItem colorGridItem = AvifWriterItem.CreateFromImageGrid(itemId, "Color", 0, gridDescriptorLength);

                itemId++;
                colorGridItem.ItemReferences.Add(new ItemReferenceEntryBox(colorGridItem.Id, ReferenceTypes.DerivedImage, colorImageIds));

                this.PrimaryItemId = colorGridItem.Id;
                this.items.Add(colorGridItem);

                if (alphaImages != null)
                {
                    // The ImageGridDescriptor is shared between the color and alpha image.
                    AvifWriterItem alphaGridItem = AvifWriterItem.CreateFromImageGrid(itemId, "Alpha", 0, gridDescriptorLength);
                    itemId++;
                    alphaGridItem.ItemReferences.Add(new ItemReferenceEntryBox(alphaGridItem.Id, ReferenceTypes.AuxiliaryImage, colorGridItem.Id));
                    alphaGridItem.ItemReferences.Add(new ItemReferenceEntryBox(alphaGridItem.Id, ReferenceTypes.DerivedImage, alphaImageIds));

                    this.AlphaItemId = alphaGridItem.Id;
                    this.items.Add(alphaGridItem);
                }

                return(new ImageStateInfo(mediaDataBoxContentSize, itemId));
            }