예제 #1
0
        private ByteVector RenderExifSegment()
        {
            IFDTag exif = ImageTag.Exif;

            if (exif == null)
            {
                return(null);
            }
            uint       first_ifd_offset = 8;
            var        renderer         = new IFDRenderer(true, exif.Structure, first_ifd_offset);
            ByteVector exif_data        = renderer.Render();
            uint       segment_size     = (uint)(first_ifd_offset + exif_data.Count + 2 + 6);

            if (segment_size > ushort.MaxValue)
            {
                throw new Exception("Exif Segment is too big to render");
            }
            ByteVector data = new ByteVector(new byte[] { 0xFF, (byte)Marker.APP1 });

            data.Add(ByteVector.FromUShort((ushort)segment_size));
            data.Add("Exif\0\0");
            data.Add(ByteVector.FromString("MM", StringType.Latin1));
            data.Add(ByteVector.FromUShort(42));
            data.Add(ByteVector.FromUInt(first_ifd_offset));
            data.Add(exif_data);
            return(data);
        }
예제 #2
0
        public ByteVector Render(bool is_bigendian, uint offset, out ushort type, out uint count)
        {
            type = (ushort)IFDEntryType.Undefined;
            var        renderer = new IFDRenderer(this.is_bigendian ?? is_bigendian, Structure, absolute_offset?offset + ifd_offset:ifd_offset);
            ByteVector data     = renderer.Render();

            data.Insert(0, prefix);
            count = (uint)data.Count;
            return(data);
        }
예제 #3
0
        private void WriteFile()
        {
            IFDTag exif = ImageTag.Exif;

            if (exif == null)
            {
                throw new Exception("Tiff file without tags");
            }
            UpdateTags(exif);
            uint       first_ifd_offset = 8;
            ByteVector data             = RenderHeader(first_ifd_offset);
            var        renderer         = new IFDRenderer(IsBigEndian, exif.Structure, first_ifd_offset);

            data.Add(renderer.Render());
            Insert(data, 0, Length);
        }
예제 #4
0
        /// <summary>
        ///    Creates a <see cref="ByteVector"/> for the Exif segment of this file
        /// </summary>
        /// <returns>
        ///    A <see cref="ByteVector"/> with the whole Exif segment, if exif tags
        ///    exists, otherwise null.
        /// </returns>
        ByteVector RenderExifSegment()
        {
            // Check, if IFD0 is contained
            IFDTag exif = ImageTag.Exif;

            if (exif == null)
            {
                return(null);
            }

            // first IFD starts at 8
            uint first_ifd_offset = 8;

            // Render IFD0
            // FIXME: store endianess and use it here
            var        renderer  = new IFDRenderer(true, exif.Structure, first_ifd_offset);
            ByteVector exif_data = renderer.Render();

            uint segment_size = (uint)(first_ifd_offset + exif_data.Count + 2 + 6);

            // do not render data segments, which cannot fit into the possible segment size
            if (segment_size > ushort.MaxValue)
            {
                throw new Exception("Exif Segment is too big to render");
            }

            // Create whole segment
            var data = new ByteVector(new byte[] { 0xFF, (byte)Marker.APP1 })
            {
                ByteVector.FromUShort((ushort)segment_size),
                "Exif\0\0",
                ByteVector.FromString("MM", StringType.Latin1),
                ByteVector.FromUShort(42),
                ByteVector.FromUInt(first_ifd_offset),

                // Add ifd data itself
                exif_data
            };

            return(data);
        }
예제 #5
0
		/// <summary>
		///    Renders the current instance to a <see cref="ByteVector"/>
		/// </summary>
		/// <param name="is_bigendian">
		///    A <see cref="System.Boolean"/> indicating the endianess for rendering.
		/// </param>
		/// <param name="offset">
		///    A <see cref="System.UInt32"/> with the offset, the data is stored.
		/// </param>
		/// <param name="type">
		///    A <see cref="System.UInt16"/> the ID of the type, which is rendered
		/// </param>
		/// <param name="count">
		///    A <see cref="System.UInt32"/> with the count of the values which are
		///    rendered.
		/// </param>
		/// <returns>
		///    A <see cref="ByteVector"/> with the rendered data.
		/// </returns>
		public ByteVector Render (bool is_bigendian, uint offset, out ushort type, out uint count)
		{
			type = (ushort) IFDEntryType.Undefined;

			var renderer =
				new IFDRenderer (this.is_bigendian ?? is_bigendian, Structure, absolute_offset ? offset + ifd_offset : ifd_offset);

			ByteVector data = renderer.Render ();
			data.Insert (0, prefix);
			count = (uint) data.Count;
			return data;
		}