Exemplo n.º 1
0
		public virtual void Extract(sbyte[] segmentBytes, Com.Drew.Metadata.Metadata metadata, JpegSegmentType segmentType)
		{
            if (metadata.ContainsDirectory<JpegDirectory>())
			{
				// If this directory is already present, discontinue this operation.
				// We only store metadata for the *first* matching SOFn segment.
				return;
			}
			JpegDirectory directory = metadata.GetOrCreateDirectory<JpegDirectory>();
			// The value of TAG_COMPRESSION_TYPE is determined by the segment type found
			directory.SetInt(JpegDirectory.TagCompressionType, segmentType.byteValue - JpegSegmentType.Sof0.byteValue);
			SequentialReader reader = new SequentialByteArrayReader(segmentBytes);
			try
			{
				directory.SetInt(JpegDirectory.TagDataPrecision, reader.GetUInt8());
				directory.SetInt(JpegDirectory.TagImageHeight, reader.GetUInt16());
				directory.SetInt(JpegDirectory.TagImageWidth, reader.GetUInt16());
				short componentCount = reader.GetUInt8();
				directory.SetInt(JpegDirectory.TagNumberOfComponents, componentCount);
				// 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
				for (int i = 0; i < (int)componentCount; i++)
				{
					int componentId = reader.GetUInt8();
					int samplingFactorByte = reader.GetUInt8();
					int quantizationTableNumber = reader.GetUInt8();
					JpegComponent component = new JpegComponent(componentId, samplingFactorByte, quantizationTableNumber);
					directory.SetObject(JpegDirectory.TagComponentData1 + i, component);
				}
			}
			catch (IOException ex)
			{
				directory.AddError(ex.Message);
			}
		}