/// <summary>
        /// Extracts aMetadata
        /// </summary>
        /// <param name="aMetadata">where to add aMetadata</param>
        /// <returns>the aMetadata found</returns>
        public override Metadata Extract(Metadata aMetadata)
        {
            if (base.data == null)
            {
                return aMetadata;
            }

            AbstractDirectory lcDirectory = aMetadata.GetDirectory("com.drew.metadata.jpeg.JpegCommentDirectory");
            string comment = Utils.Decode(base.data, true);
            lcDirectory.SetObject(JpegCommentDirectory.TAG_JPEG_COMMENT,comment);
            return aMetadata;
        }
Пример #2
0
		/// <summary>
		/// Extracts aMetadata
		/// </summary>
		/// <param name="aMetadata">where to add aMetadata</param>
		/// <returns>the aMetadata found</returns>
		public override Metadata Extract(Metadata aMetadata) 
		{
			if (base.data == null) 
			{
				return aMetadata;
			}

			AbstractDirectory lcDirectory = aMetadata.GetDirectory("com.drew.metadata.jpeg.JpegDirectory");

			try 
			{
				// data precision
				int dataPrecision =
					base.Get16Bits(JpegDirectory.TAG_JPEG_DATA_PRECISION);
				lcDirectory.SetObject(
					JpegDirectory.TAG_JPEG_DATA_PRECISION,
					dataPrecision);

				// process height
				int height = base.Get32Bits(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT);
				lcDirectory.SetObject(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT, height);

				// process width
				int width = base.Get32Bits(JpegDirectory.TAG_JPEG_IMAGE_WIDTH);
				lcDirectory.SetObject(JpegDirectory.TAG_JPEG_IMAGE_WIDTH, width);

				// number of components
				int numberOfComponents =
					base.Get16Bits(JpegDirectory.TAG_JPEG_NUMBER_OF_COMPONENTS);
				lcDirectory.SetObject(
					JpegDirectory.TAG_JPEG_NUMBER_OF_COMPONENTS,
					numberOfComponents);

				// for each component, there are three bytes of data:
				// 1 - Component ID: 1 = Y, 2 = Cb, 3 = Cr, 4 = I, 5 = Q
				// 2 - Sampling factors: bit 0-3 vertical, 4-7 horizontal
				// 3 - Quantization table number
				int offset = 6;
				for (int i = 0; i < numberOfComponents; i++) 
				{
					int componentId = base.Get16Bits(offset++);
					int samplingFactorByte = base.Get16Bits(offset++);
					int quantizationTableNumber = base.Get16Bits(offset++);
					JpegComponent lcJpegComponent =
						new JpegComponent(
						componentId,
						samplingFactorByte,
						quantizationTableNumber);
					lcDirectory.SetObject(
						JpegDirectory.TAG_JPEG_COMPONENT_DATA_1 + i,
						lcJpegComponent);
				}

			} 
			catch (MetadataException me) 
			{
                lcDirectory.HasError = true;
				Trace.TraceError("MetadataException: " + me.Message);
			}

			return aMetadata;
		}
Пример #3
0
        /// <summary>
        /// Extracts aMetadata
        /// </summary>
        /// <param name="aMetadata">where to add aMetadata</param>
        /// <returns>the aMetadata found</returns>
        public override Metadata Extract(Metadata aMetadata)
        {
            if (base.data == null)
            {
                return aMetadata;
            }

            AbstractDirectory lcDirectory = aMetadata.GetDirectory("com.drew.metadata.iptc.IptcDirectory");

            // find start of data
            int offset = 0;
            try
            {
                while (offset < base.data.Length - 1 && Get32Bits(offset) != 0x1c02)
                {
                    offset++;
                }
            }
            catch (MetadataException e)
            {
                lcDirectory.HasError = true;
                Trace.TraceError(
                    "Couldn't find start of Iptc data (invalid segment) ("+e.Message+")");
                return aMetadata;
            }

            // for each tag
            while (offset < base.data.Length)
            {
                // identifies start of a tag
                if (base.data[offset] != 0x1c)
                {
                    break;
                }
                // we need at least five bytes left to read a tag
                if ((offset + 5) >= base.data.Length)
                {
                    break;
                }

                offset++;

                int directoryType;
                int tagType;
                int tagByteCount;
                try
                {
                    directoryType = base.data[offset++];
                    tagType = base.data[offset++];
                    tagByteCount = Get32Bits(offset);
                }
                catch (MetadataException e)
                {
                    lcDirectory.HasError = true;
                    Trace.TraceError(
                        "Iptc data segment ended mid-way through tag descriptor ("+e.Message+")");
                    return aMetadata;
                }
                offset += 2;
                if ((offset + tagByteCount) > base.data.Length)
                {
                    lcDirectory.HasError = true;
                    Trace.TraceError(
                        "Data for tag extends beyond end of IPTC segment");
                    break;
                }

                ProcessTag(lcDirectory, directoryType, tagType, offset, tagByteCount);
                offset += tagByteCount;
            }

            return aMetadata;
        }