Exemplo n.º 1
0
        /// <summary>
        ///    Renders the Gif Comment to a Comment Extension Block which can be
        ///    embedded in a Gif file.
        /// </summary>
        /// <returns>
        ///    A <see cref="ByteVector"/> with the Comment Extension Block for the
        ///    Gif Comment, or <see langword="null" /> if the file does not have
        ///    a Gif Comment.
        /// </returns>
        private ByteVector RenderGifCommentBlock()
        {
            // Check, if GifCommentTag is contained
            GifCommentTag comment_tag = GetTag(TagTypes.GifComment) as GifCommentTag;

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

            string comment = comment_tag.Comment;

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

            ByteVector comment_data = new ByteVector();

            // Add Extension Introducer (0x21) and Comment Label (0xFE)
            comment_data.Add(new byte [] { 0x21, 0xFE });

            // Add data of comment in sub-blocks of max length 256.
            ByteVector comment_bytes = new ByteVector(comment);
            byte       block_max     = 255;

            for (int start = 0; start < comment_bytes.Count; start += block_max)
            {
                byte block_length = (byte)Math.Min(comment_bytes.Count - start, block_max);

                comment_data.Add(block_length);
                comment_data.Add(comment_bytes.Mid(start, block_length));
            }
            comment_data.Add(new byte [] { 0x00 });

            return(comment_data);
        }
Exemplo n.º 2
0
		/// <summary>
		///    Gets a tag of a specified type from the current instance,
		///    optionally creating a new tag if possible.
		/// </summary>
		/// <param name="type">
		///    A <see cref="TagLib.TagTypes" /> value indicating the
		///    type of tag to read.
		/// </param>
		/// <param name="create">
		///    A <see cref="bool" /> value specifying whether or not to
		///    try and create the tag if one is not found.
		/// </param>
		/// <returns>
		///    A <see cref="Tag" /> object containing the tag that was
		///    found in or added to the current instance. If no
		///    matching tag was found and none was created, <see
		///    langword="null" /> is returned.
		/// </returns>
		public override TagLib.Tag GetTag (TagLib.TagTypes type,
		                                   bool create)
		{
			foreach (Tag tag in ImageTag.AllTags) {
				if ((tag.TagTypes & type) == type)
					return tag;
			}

			if (!create || (type & ImageTag.AllowedTypes) == 0)
				return null;

			ImageTag new_tag = null;
			switch (type) {
			case TagTypes.JpegComment:
				new_tag = new JpegCommentTag ();
				break;

			case TagTypes.GifComment:
				new_tag = new GifCommentTag ();
				break;

			case TagTypes.Png:
				new_tag = new PngTag ();
				break;

			case TagTypes.TiffIFD:
				new_tag = new IFDTag ();
				break;

			case TagTypes.XMP:
				new_tag = new XmpTag ();
				break;
			}

			if (new_tag != null) {
				ImageTag.AddTag (new_tag);
				return new_tag;
			}

			throw new NotImplementedException (String.Format ("Adding tag of type {0} not supported!", type));
		}