Ejemplo n.º 1
0
        /// <summary>
        /// Gets the component
        /// </summary>
        /// <param name="componentNumber">The zero-based index of the component.  This number is normally between 0 and 3. Use GetNumberOfComponents for bounds-checking.</param>
        /// <returns>the JpegComponent</returns>
        public JpegComponent GetComponent(int componentNumber)
        {
            int tagType = JpegDirectory.TAG_JPEG_COMPONENT_DATA_1 + componentNumber;

            JpegComponent component = (JpegComponent)GetObject(tagType);

            return(component);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the Component Data description
        /// </summary>
        /// <param name="componentNumber">the component number</param>
        /// <returns>the Component Data description</returns>
        public string GetComponentDataDescription(int componentNumber)
        {
            JpegComponent component =
                ((JpegDirectory)base.directory).GetComponent(componentNumber);

            if (component == null)
            {
                throw new MetadataException("No Jpeg component exists with number " + componentNumber);
            }

            // {0} component: Quantization table {1}, Sampling factors {2} horiz/{3} vert
            string[] tab = new string[] { component.GetComponentName(),
                     component.QuantizationTableNumber.ToString(),
                     component.HorizontalSamplingFactor.ToString(),
                     component.VerticalSamplingFactor.ToString() };

            return(BUNDLE["COMPONENT_DATA", tab]);
        }
Ejemplo n.º 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.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);
        }
Ejemplo n.º 4
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;
		}