public TProperty TryGetAssociatedItemProperty <TProperty>(uint itemId) where TProperty : class, IItemProperty { if (typeof(TProperty).IsAbstract) { ExceptionUtil.ThrowInvalidOperationException($"Cannot call this method with an abstract type, type: { typeof(TProperty).Name }."); } ItemPropertiesBox itemPropertiesBox = this.metaBox.ItemProperties; IReadOnlyList <ItemPropertyAssociationEntry> items = itemPropertiesBox.TryGetAssociatedProperties(itemId); if (items != null) { for (int i = 0; i < items.Count; i++) { IItemProperty property = itemPropertiesBox.TryGetProperty(items[i].PropertyIndex); if (property is TProperty requestedProperty) { return(requestedProperty); } } } return(null); }
public bool HasUnsupportedEssentialProperties(uint itemId) { ItemPropertiesBox itemPropertiesBox = this.metaBox.ItemProperties; IReadOnlyList <ItemPropertyAssociationEntry> items = itemPropertiesBox.TryGetAssociatedProperties(itemId); if (items != null) { for (int i = 0; i < items.Count; i++) { ItemPropertyAssociationEntry entry = items[i]; if (entry.Essential) { IItemProperty property = itemPropertiesBox.TryGetProperty(entry.PropertyIndex); if (property is null) { return(true); } } } } return(false); }
public void GetTransformationProperties(uint itemId, out CleanApertureBox cleanAperture, out ImageRotateBox imageRotate, out ImageMirrorBox imageMirror) { cleanAperture = null; imageRotate = null; imageMirror = null; ItemPropertiesBox itemPropertiesBox = this.metaBox.ItemProperties; IReadOnlyList <ItemPropertyAssociationEntry> items = itemPropertiesBox.TryGetAssociatedProperties(itemId); if (items != null) { for (int i = 0; i < items.Count; i++) { IItemProperty property = itemPropertiesBox.TryGetProperty(items[i].PropertyIndex); if (property != null) { if (property.Type == BoxTypes.CleanAperture) { cleanAperture = (CleanApertureBox)property; } else if (property.Type == BoxTypes.ImageRotation) { imageRotate = (ImageRotateBox)property; } else if (property.Type == BoxTypes.ImageMirror) { imageMirror = (ImageMirrorBox)property; } } } } }
private void PopulateItemProperties() { IReadOnlyList <AvifWriterItem> items = this.state.Items; ItemPropertiesBox itemPropertiesBox = this.metaBox.ItemProperties; // The property association ids are 1-based ushort propertyAssociationIndex = 1; // Cache the property association index values for the ImageSpatialExtentsBox // and PixelAspectRatioBox. // These boxes can be shared between the color and alpha images, which provides // a small reduction in file size. // // Gray-scale images can also share the AV1ConfigBox and PixelInformationBox // between the color and alpha images. // This works because the color and alpha images are the same size and YUV format. ushort imageSpatialExtentsAssociationIndex = 0; ushort pixelAspectRatioAssociationIndex = 0; ushort colorAv1ConfigAssociationIndex = 0; ushort colorPixelInformationAssociationIndex = 0; ushort alphaAv1ConfigAssociationIndex = 0; ushort alphaPixelInformationAssociationIndex = 0; ushort alphaChannelAssociationIndex = 0; for (int i = 0; i < items.Count; i++) { AvifWriterItem item = items[i]; if (item.Image != null) { if (imageSpatialExtentsAssociationIndex == 0) { itemPropertiesBox.AddProperty(new ImageSpatialExtentsBox((uint)item.Image.Width, (uint)item.Image.Height)); imageSpatialExtentsAssociationIndex = propertyAssociationIndex; propertyAssociationIndex++; } itemPropertiesBox.AddPropertyAssociation(item.Id, false, imageSpatialExtentsAssociationIndex); if (pixelAspectRatioAssociationIndex == 0) { itemPropertiesBox.AddProperty(new PixelAspectRatioBox(1, 1)); pixelAspectRatioAssociationIndex = propertyAssociationIndex; propertyAssociationIndex++; } itemPropertiesBox.AddPropertyAssociation(item.Id, false, pixelAspectRatioAssociationIndex); if (colorAv1ConfigAssociationIndex == 0 || item.IsAlphaImage && alphaAv1ConfigAssociationIndex == 0) { itemPropertiesBox.AddProperty(AV1ConfigBoxBuilder.Build(item.Image)); if (this.colorImageIsGrayscale) { colorAv1ConfigAssociationIndex = alphaAv1ConfigAssociationIndex = propertyAssociationIndex; } else { if (item.IsAlphaImage) { alphaAv1ConfigAssociationIndex = propertyAssociationIndex; } else { colorAv1ConfigAssociationIndex = propertyAssociationIndex; } } propertyAssociationIndex++; } if (colorPixelInformationAssociationIndex == 0 || item.IsAlphaImage && alphaPixelInformationAssociationIndex == 0) { itemPropertiesBox.AddProperty(new PixelInformationBox(item.Image.Format)); if (this.colorImageIsGrayscale) { colorPixelInformationAssociationIndex = alphaPixelInformationAssociationIndex = propertyAssociationIndex; } else { if (item.IsAlphaImage) { alphaPixelInformationAssociationIndex = propertyAssociationIndex; } else { colorPixelInformationAssociationIndex = propertyAssociationIndex; } } propertyAssociationIndex++; } if (item.IsAlphaImage) { itemPropertiesBox.AddPropertyAssociation(item.Id, true, alphaAv1ConfigAssociationIndex); itemPropertiesBox.AddPropertyAssociation(item.Id, true, alphaPixelInformationAssociationIndex); if (alphaChannelAssociationIndex == 0) { itemPropertiesBox.AddProperty(new AlphaChannelBox()); alphaChannelAssociationIndex = propertyAssociationIndex; propertyAssociationIndex++; } itemPropertiesBox.AddPropertyAssociation(item.Id, true, alphaChannelAssociationIndex); } else { itemPropertiesBox.AddPropertyAssociation(item.Id, true, colorAv1ConfigAssociationIndex); itemPropertiesBox.AddPropertyAssociation(item.Id, true, colorPixelInformationAssociationIndex); } } } if (this.state.ImageGrid != null) { itemPropertiesBox.AddProperty(new ImageSpatialExtentsBox(this.state.ImageGrid.OutputWidth, this.state.ImageGrid.OutputHeight)); ushort gridImageSpatialExtentsAssociationIndex = propertyAssociationIndex; propertyAssociationIndex++; itemPropertiesBox.AddPropertyAssociation(this.state.PrimaryItemId, false, gridImageSpatialExtentsAssociationIndex); if (this.state.AlphaItemId != 0) { itemPropertiesBox.AddPropertyAssociation(this.state.AlphaItemId, false, gridImageSpatialExtentsAssociationIndex); itemPropertiesBox.AddPropertyAssociation(this.state.AlphaItemId, true, alphaChannelAssociationIndex); } } if (this.colorInformationBox != null) { itemPropertiesBox.AddProperty(this.colorInformationBox); itemPropertiesBox.AddPropertyAssociation(this.state.PrimaryItemId, true, propertyAssociationIndex); } }