Example #1
0
        /// <summary>
        /// Sets a property item with the given id to the collection within the current
        /// <see cref="ImageFactory"/> instance.
        /// </summary>
        /// <param name="imageFactory">The image factory.</param>
        /// <param name="id">The id to assign to the property item.</param>
        /// <param name="value">The value to assign to the property item.</param>
        /// <returns>
        /// The <see cref="ImageFactory"/>.
        /// </returns>
        public static ImageFactory SetPropertyItem(this ImageFactory imageFactory, ExifPropertyTag id, string value)
        {
            // TODO: Cover the different encoding types for different tags.
            var bytes = BitConverter.GetBytes(value);

            return(imageFactory.SetPropertyItem(id, ExifPropertyTagType.ASCII, bytes.Length, bytes));
        }
        private PSObject CreateProperty(PropertyItem propertyItem, out ExifPropertyTag tag)
        {
            try { tag = (ExifPropertyTag)(propertyItem.Id); } catch { tag = ExifPropertyTag.Unknown; }
            if (tag == ExifPropertyTag.Unknown || propertyItem.Value == null)
            {
                return(null);
            }
            ExifPropertyType type;

            try { type = (ExifPropertyType)(propertyItem.Type); } catch { type = ExifPropertyType.Undefined; }
            return(CreateProperty(propertyItem.Value, propertyItem.Len, type, tag));
        }
Example #3
0
        /// <summary>
        /// Sets a property item with the given id to the collection within the current
        /// <see cref="ImageFactory"/> instance.
        /// </summary>
        /// <param name="imageFactory">The image factory.</param>
        /// <param name="id">The id to assign to the property item.</param>
        /// <param name="type">The type to assign to the property item.</param>
        /// <param name="length">The length to assign to the property item.</param>
        /// <param name="value">The value to assign to the property item.</param>
        /// <returns>
        /// The <see cref="ImageFactory"/>.
        /// </returns>
        private static ImageFactory SetPropertyItem(
            this ImageFactory imageFactory,
            ExifPropertyTag id,
            ExifPropertyTagType type,
            int length,
            byte[] value)
        {
            PropertyItem item = FormatUtilities.CreatePropertyItem();

            item.Id    = (int)id;
            item.Type  = (short)type;
            item.Len   = length;
            item.Value = value;

            imageFactory.ExifPropertyItems[item.Id] = item;
            return(imageFactory);
        }
Example #4
0
 /// <summary>
 /// Sets a property item with the given id to the collection within the current
 /// <see cref="ImageFactory"/> instance.
 /// </summary>
 /// <param name="imageFactory">The image factory.</param>
 /// <param name="id">The id to assign to the property item.</param>
 /// <param name="value">The value to assign to the property item.</param>
 /// <returns>
 /// The <see cref="ImageFactory"/>.
 /// </returns>
 public static ImageFactory SetPropertyItem(this ImageFactory imageFactory, ExifPropertyTag id, uint value)
 {
     byte[] bytes = BitConverter.GetBytes(value);
     return(imageFactory.SetPropertyItem(id, ExifPropertyTagType.ULong, bytes.Length, bytes));
 }
Example #5
0
 /// <summary>
 /// Sets a property item with the given id to the collection within the current
 /// <see cref="ImageFactory"/> instance.
 /// </summary>
 /// <param name="imageFactory">The image factory.</param>
 /// <param name="id">The id to assign to the property item.</param>
 /// <param name="value">The value to assign to the property item.</param>
 /// <returns>
 /// The <see cref="ImageFactory"/>.
 /// </returns>
 public static ImageFactory SetPropertyItem(this ImageFactory imageFactory, ExifPropertyTag id, byte value)
 {
     byte[] bytes = { value };
     return(imageFactory.SetPropertyItem(id, ExifPropertyTagType.Byte, bytes.Length, bytes));
 }
Example #6
0
 /// <summary>
 /// Sets a property item with the given id to the collection within the current
 /// <see cref="ImageFactory"/> instance.
 /// </summary>
 /// <param name="imageFactory">The image factory.</param>
 /// <param name="id">The id to assign to the property item.</param>
 /// <param name="value">The value to assign to the property item.</param>
 /// <returns>
 /// The <see cref="ImageFactory"/>.
 /// </returns>
 public static ImageFactory SetPropertyItem(this ImageFactory imageFactory, ExifPropertyTag id, byte[] value)
 {
     return(imageFactory.SetPropertyItem(id, ExifPropertyTagType.Undefined, value.Length, value));
 }
Example #7
0
        /// <summary>
        /// Sets a property item with the given id to the collection within the current
        /// <see cref="ImageFactory"/> instance.
        /// </summary>
        /// <param name="imageFactory">The image factory.</param>
        /// <param name="id">The id to assign to the property item.</param>
        /// <param name="value">The value to assign to the property item.</param>
        /// <returns>
        /// The <see cref="ImageFactory"/>.
        /// </returns>
        public static ImageFactory SetPropertyItem(this ImageFactory imageFactory, ExifPropertyTag id, Rational <int> value)
        {
            var bytes = BitConverter.GetBytes(value);

            return(imageFactory.SetPropertyItem(id, ExifPropertyTagType.SRational, bytes.Length, bytes));
        }
 /// <summary>
 /// Sets a property item with the given id to the collection within the current
 /// <see cref="ImageFactory"/> instance.
 /// </summary>
 /// <param name="imageFactory">The image factory.</param>
 /// <param name="id">The id to assign to the property item.</param>
 /// <param name="value">The value to assign to the property item.</param>
 /// <returns>
 /// The <see cref="ImageFactory"/>.
 /// </returns>
 public static ImageFactory SetPropertyItem(this ImageFactory imageFactory, ExifPropertyTag id, uint value)
 {
     byte[] bytes = BitConverter.GetBytes(value);
     return imageFactory.SetPropertyItem(id, ExifPropertyTagType.ULong, bytes.Length, bytes);
 }
 /// <summary>
 /// Sets a property item with the given id to the collection within the current
 /// <see cref="ImageFactory"/> instance.
 /// </summary>
 /// <param name="imageFactory">The image factory.</param>
 /// <param name="id">The id to assign to the property item.</param>
 /// <param name="value">The value to assign to the property item.</param>
 /// <returns>
 /// The <see cref="ImageFactory"/>.
 /// </returns>
 public static ImageFactory SetPropertyItem(this ImageFactory imageFactory, ExifPropertyTag id, string value)
 {
     // TODO: Cover the different encoding types for different tags.
     byte[] bytes = BitConverter.GetBytes(value);
     return imageFactory.SetPropertyItem(id, ExifPropertyTagType.ASCII, bytes.Length, bytes);
 }
 /// <summary>
 /// Sets a property item with the given id to the collection within the current
 /// <see cref="ImageFactory"/> instance.
 /// </summary>
 /// <param name="imageFactory">The image factory.</param>
 /// <param name="id">The id to assign to the property item.</param>
 /// <param name="value">The value to assign to the property item.</param>
 /// <returns>
 /// The <see cref="ImageFactory"/>.
 /// </returns>
 public static ImageFactory SetPropertyItem(this ImageFactory imageFactory, ExifPropertyTag id, byte value)
 {
     byte[] bytes = { value };
     return imageFactory.SetPropertyItem(id, ExifPropertyTagType.Byte, bytes.Length, bytes);
 }
        /// <summary>
        /// Sets a property item with the given id to the collection within the current
        /// <see cref="ImageFactory"/> instance.
        /// </summary>
        /// <param name="imageFactory">The image factory.</param>
        /// <param name="id">The id to assign to the property item.</param>
        /// <param name="type">The type to assign to the property item.</param>
        /// <param name="length">The length to assign to the property item.</param>
        /// <param name="value">The value to assign to the property item.</param>
        /// <returns>
        /// The <see cref="ImageFactory"/>.
        /// </returns>
        private static ImageFactory SetPropertyItem(
            this ImageFactory imageFactory,
            ExifPropertyTag id,
            ExifPropertyTagType type,
            int length,
            byte[] value)
        {
            PropertyItem item = FormatUtilities.CreatePropertyItem();

            item.Id = (int)id;
            item.Type = (short)type;
            item.Len = length;
            item.Value = value;

            imageFactory.ExifPropertyItems[item.Id] = item;
            return imageFactory;
        }
 /// <summary>
 /// Sets a property item with the given id to the collection within the current
 /// <see cref="ImageFactory"/> instance.
 /// </summary>
 /// <param name="imageFactory">The image factory.</param>
 /// <param name="id">The id to assign to the property item.</param>
 /// <param name="value">The value to assign to the property item.</param>
 /// <returns>
 /// The <see cref="ImageFactory"/>.
 /// </returns>
 public static ImageFactory SetPropertyItem(this ImageFactory imageFactory, ExifPropertyTag id, byte[] value)
 {
     return imageFactory.SetPropertyItem(id, ExifPropertyTagType.Undefined, value.Length, value);
 }
Example #13
0
        private PSObject CreateProperty(byte[] bytes, int count, ExifPropertyType type, ExifPropertyTag tag)
        {
            Type t = tag.GetType();

            ExifPropertyTypeAttribute[] attributes = t.GetField(Enum.GetName(t, tag)).GetCustomAttributes(typeof(ExifPropertyTypeAttribute), false).OfType <ExifPropertyTypeAttribute>().ToArray();
            if (attributes.Length > 1 && attributes.Any(a => a.Type == type))
            {
                attributes = attributes.Where(a => a.Type == type).ToArray();
            }
            if (attributes.Length > 1 && attributes.Any(a => a.IsPrimary))
            {
                attributes = attributes.Where(a => a.IsPrimary).ToArray();
            }
            ExifPropertyTypeAttribute attr = attributes.DefaultIfEmpty(new ExifPropertyTypeAttribute(type)
            {
                HasNullTerminator = type == ExifPropertyType.ASCII
            }).First();

            if (type == ExifPropertyType.BestMatching)
            {
                type = attr.Type;
            }
            PSObject property;

            switch (type)
            {
            case ExifPropertyType.ASCII:
                if (attr.HasNullTerminator)
                {
                    if (attr.Count == 0)
                    {
                        property = AsStringZMulti(bytes, count);
                    }
                    else
                    {
                        property = AsStringZ(bytes, count);
                    }
                }
                else
                {
                    property = AsString(bytes, count);
                }
                break;

            case ExifPropertyType.Byte:
                property = AsByteValue(bytes, count);
                break;

            case ExifPropertyType.Long:
                property = AsUInt32Value(bytes, count);
                break;

            case ExifPropertyType.Rational:
                property = AsUDecimalValue(bytes, count);
                break;

            case ExifPropertyType.Short:
                property = AsUInt16Value(bytes, count);
                break;

            case ExifPropertyType.SLong:
                property = AsInt32Value(bytes, count);
                break;

            case ExifPropertyType.SRational:
                property = AsDecimalValue(bytes, count);
                break;

            default:
                property = AsHexValues(bytes, count);
                break;
            }

            property.TypeNames.Add("ExifPropertyTag." + Enum.GetName(typeof(ExifPropertyTag), tag));
            property.TypeNames.Add("ExifPropertyTag." + Enum.GetName(typeof(ExifPropertyTag), tag) + "." + Enum.GetName(typeof(ExifPropertyType), type));
            return(property);
        }