Ejemplo n.º 1
0
        /// <summary>
        ///    Creates a <see cref="ByteVector"/> for the Xmp segment of this file
        /// </summary>
        /// <returns>
        ///    A <see cref="ByteVector"/> with the whole Xmp segment, if xmp tags
        ///    exists, otherwise null.
        /// </returns>
        private ByteVector RenderXMPSegment()
        {
            // Check, if XmpTag is contained
            XmpTag xmp = ImageTag.Xmp;

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

            ByteVector xmp_data = XmpTag.XAP_NS + "\0";

            xmp_data.Add(xmp.Render());

            uint segment_size = (uint)(2 + xmp_data.Count);

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

            // Create whole segment
            ByteVector data = new ByteVector(new byte [] { 0xFF, (byte)Marker.APP1 });

            data.Add(ByteVector.FromUShort((ushort)segment_size));
            data.Add(xmp_data);

            return(data);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Saves all the metadata that fits in XMP to a file.
        /// </summary>
        /// <example>SaveXmplFile("c:\dir\metadata.xmp")</example>
        public void SaveXmpFile(string path)
        {
            var tag = new XmpTag();

            SaveInImageTag(tag);
            File.WriteAllText(path, tag.Render(), Encoding.UTF8);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///    Renders the XMP data to a Application Extension Block which can be
        ///    embedded in a Gif file.
        /// </summary>
        /// <returns>
        ///    A <see cref="ByteVector"/> with the Application Extension Block for the
        ///    XMP data, or <see langword="null" /> if the file does not have XMP data.
        /// </returns>
        private ByteVector RenderXMPBlock()
        {
            // Check, if XmpTag is contained
            XmpTag xmp = ImageTag.Xmp;

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

            ByteVector xmp_data = new ByteVector();

            // Add Extension Introducer (0x21), Application Extension Label (0xFF) and
            // the Block Size (0x0B
            xmp_data.Add(new byte [] { 0x21, 0xFF, 0x0B });

            // Application Identifier and Appl. Auth. Code
            xmp_data.Add(XMP_IDENTIFIER);
            xmp_data.Add(XMP_AUTH_CODE);

            // Add XMP data and Magic Trailer
            // For XMP, we do not need to store the data in sub-blocks, therfore we
            // can just add the whole rendered data. (The trailer fixes this)
            xmp_data.Add(xmp.Render());
            xmp_data.Add(XMP_MAGIC_TRAILER);

            return(xmp_data);
        }
Ejemplo n.º 4
0
        void TestRender(XmpTag tag, XmpValidator validator)
        {
            string xmp = tag.Render();

            var parsed_tag = new XmpTag(xmp, null);

            validator(parsed_tag);
        }
Ejemplo n.º 5
0
        private ByteVector RenderXMPBlock()
        {
            XmpTag xmp = ImageTag.Xmp;

            if (xmp == null)
            {
                return(null);
            }
            ByteVector xmp_data = new ByteVector();

            xmp_data.Add(new byte[] { 0x21, 0xFF, 0x0B });
            xmp_data.Add(XMP_IDENTIFIER);
            xmp_data.Add(XMP_AUTH_CODE);
            xmp_data.Add(xmp.Render());
            xmp_data.Add(XMP_MAGIC_TRAILER);
            return(xmp_data);
        }
Ejemplo n.º 6
0
        private ByteVector RenderXMPChunk()
        {
            XmpTag xmp = ImageTag.Xmp;

            if (xmp == null)
            {
                return(null);
            }
            ByteVector chunk    = new ByteVector();
            ByteVector xmp_data = xmp.Render();

            chunk.Add(ByteVector.FromUInt((uint)xmp_data.Count + (uint)XMP_CHUNK_HEADER.Length));
            chunk.Add(iTXt_CHUNK_TYPE);
            chunk.Add(XMP_CHUNK_HEADER);
            chunk.Add(xmp_data);
            chunk.Add(ComputeCRC(iTXt_CHUNK_TYPE, XMP_CHUNK_HEADER, xmp_data));
            return(chunk);
        }
Ejemplo n.º 7
0
        private ByteVector RenderXMPSegment()
        {
            XmpTag xmp = ImageTag.Xmp;

            if (xmp == null)
            {
                return(null);
            }
            ByteVector xmp_data = XmpTag.XAP_NS + "\0";

            xmp_data.Add(xmp.Render());
            uint segment_size = (uint)(2 + xmp_data.Count);

            if (segment_size > ushort.MaxValue)
            {
                throw new Exception("XMP 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(xmp_data);
            return(data);
        }
Ejemplo n.º 8
0
        /// <summary>
        ///    Creates a Chunk containing the XMP data.
        /// </summary>
        /// <returns>
        ///    A <see cref="ByteVector"/> with the XMP data chunk
        ///    or <see langword="null" /> if no XMP data is contained.
        /// </returns>
        private ByteVector RenderXMPChunk()
        {
            // Check, if XmpTag is contained
            XmpTag xmp = ImageTag.Xmp;

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

            ByteVector chunk = new ByteVector();

            // render the XMP data itself
            ByteVector xmp_data = xmp.Render();

            // TODO check uint size.
            chunk.Add(ByteVector.FromUInt((uint)xmp_data.Count + (uint)XMP_CHUNK_HEADER.Length));
            chunk.Add(iTXt_CHUNK_TYPE);
            chunk.Add(XMP_CHUNK_HEADER);
            chunk.Add(xmp_data);
            chunk.Add(ComputeCRC(iTXt_CHUNK_TYPE, XMP_CHUNK_HEADER, xmp_data));

            return(chunk);
        }
Ejemplo n.º 9
0
        /// <summary>
        ///    Update the XMP stored in the Tiff IFD
        /// </summary>
        /// <param name="exif">
        ///    A <see cref="IFDTag"/> The Tiff IFD to update the entries
        /// </param>
        private void UpdateTags(IFDTag exif)
        {
            // update the XMP entry
            exif.Structure.RemoveTag(0, (ushort)IFDEntryTag.XMP);

            XmpTag xmp = ImageTag.Xmp;

            if (xmp != null)
            {
                exif.Structure.AddEntry(0, new ByteVectorIFDEntry((ushort)IFDEntryTag.XMP, xmp.Render()));
            }
        }