public virtual void Extract(sbyte[] segmentBytes, Com.Drew.Metadata.Metadata metadata, JpegSegmentType segmentType) { JpegDirectory directory = new JpegDirectory(); metadata.AddDirectory(directory); // 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); } }
public virtual void TestGetComponentDescription() { JpegComponent component1 = new JpegComponent(1, unchecked ((int)(0x22)), 0); _directory.SetObject(JpegDirectory.TagComponentData1, component1); Sharpen.Tests.AreEqual("Y component: Quantization table 0, Sampling factors 2 horiz/2 vert", _directory.GetDescription(JpegDirectory.TagComponentData1)); Sharpen.Tests.AreEqual("Y component: Quantization table 0, Sampling factors 2 horiz/2 vert", _descriptor.GetComponentDataDescription(0)); }
public virtual void TestGetComponent() { JpegComponent component1 = new JpegComponent(1, 2, 3); JpegComponent component2 = new JpegComponent(1, 2, 3); JpegComponent component3 = new JpegComponent(1, 2, 3); JpegComponent component4 = new JpegComponent(1, 2, 3); _directory.SetObject(JpegDirectory.TagComponentData1, component1); _directory.SetObject(JpegDirectory.TagComponentData2, component2); _directory.SetObject(JpegDirectory.TagComponentData3, component3); _directory.SetObject(JpegDirectory.TagComponentData4, component4); // component numbers are zero-indexed for this method NUnit.Framework.Assert.AreSame(component1, _directory.GetComponent(0)); NUnit.Framework.Assert.AreSame(component2, _directory.GetComponent(1)); NUnit.Framework.Assert.AreSame(component3, _directory.GetComponent(2)); NUnit.Framework.Assert.AreSame(component4, _directory.GetComponent(3)); }