Exemple #1
0
        /// <summary>
        ///    Creates a <see cref="ByteVector"/> for the comment segment of this file
        /// </summary>
        /// <returns>
        ///    A <see cref="ByteVector"/> with the whole comment segment, if a comment tag
        ///    exists, otherwise null.
        /// </returns>
        private ByteVector RenderCOMSegment()
        {
            // check, if Comment is contained
            JpegCommentTag com_tag = GetTag(TagTypes.JpegComment) as JpegCommentTag;

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

            // create comment data
            ByteVector com_data =
                ByteVector.FromString(com_tag.Value + "\0", StringType.Latin1);

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

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

            // create segment
            ByteVector data = new ByteVector(new byte [] { 0xFF, (byte)Marker.COM });

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

            data.Add(com_data);

            return(data);
        }
Exemple #2
0
        /// <summary>
        ///    Reads a COM segment to find the JPEG comment.
        /// </summary>
        /// <param name="length">
        ///    The length of the segment that will be read.
        /// </param>
        private void ReadCOMSegment(int length)
        {
            if ((ImageTag.TagTypes & TagLib.TagTypes.JpegComment) != 0x00)
            {
                return;
            }

            long position = Tell;

            JpegCommentTag com_tag;

            if (length == 0)
            {
                com_tag = new JpegCommentTag();
            }
            else
            {
                ByteVector data = ReadBlock(length);

                int terminator = data.Find("\0", 0);

                if (terminator < 0)
                {
                    com_tag = new JpegCommentTag(data.ToString());
                }
                else
                {
                    com_tag = new JpegCommentTag(data.Mid(0, terminator).ToString());
                }
            }

            ImageTag.AddTag(com_tag);
            AddMetadataBlock(position - 4, length + 4);
        }