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));
		}
Esempio n. 2
0
 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);
     }
 }
Esempio n. 3
0
        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 string GetComponentDataDescription(int componentNumber)
        {
            JpegComponent value = _directory.GetComponent(componentNumber);

            if (value == null)
            {
                return(null);
            }
            return(value.GetComponentName() + " component: Quantization table " + value.GetQuantizationTableNumber() + ", Sampling factors " + value.GetHorizontalSamplingFactor() + " horiz/" + value.GetVerticalSamplingFactor() + " vert");
        }
Esempio n. 6
0
        public virtual void TestComponentData1()
        {
            JpegComponent component = (JpegComponent)_directory.GetObject(JpegDirectory.TagComponentData1);

            NUnit.Framework.Assert.IsNotNull(component);
            Sharpen.Tests.AreEqual("Y", component.GetComponentName());
            Sharpen.Tests.AreEqual(1, component.GetComponentId());
            Sharpen.Tests.AreEqual(0, component.GetQuantizationTableNumber());
            Sharpen.Tests.AreEqual(2, component.GetHorizontalSamplingFactor());
            Sharpen.Tests.AreEqual(2, component.GetVerticalSamplingFactor());
        }
Esempio n. 7
0
        public virtual void TestComponentData2()
        {
            JpegComponent component = (JpegComponent)_directory.GetObject(JpegDirectory.TagComponentData2);

            NUnit.Framework.Assert.IsNotNull(component);
            Sharpen.Tests.AreEqual("Cb", component.GetComponentName());
            Sharpen.Tests.AreEqual(2, component.GetComponentId());
            Sharpen.Tests.AreEqual(1, component.GetQuantizationTableNumber());
            Sharpen.Tests.AreEqual(1, component.GetHorizontalSamplingFactor());
            Sharpen.Tests.AreEqual(1, component.GetVerticalSamplingFactor());
            Sharpen.Tests.AreEqual("Cb component: Quantization table 1, Sampling factors 1 horiz/1 vert", _directory.GetDescription(JpegDirectory.TagComponentData2));
        }
		public virtual void TestGetComponentCharacter()
		{
			JpegComponent component;
			component = new JpegComponent(1, 2, 3);
			Sharpen.Tests.AreEqual("Y", component.GetComponentName());
			component = new JpegComponent(2, 2, 3);
			Sharpen.Tests.AreEqual("Cb", component.GetComponentName());
			component = new JpegComponent(3, 2, 3);
			Sharpen.Tests.AreEqual("Cr", component.GetComponentName());
			component = new JpegComponent(4, 2, 3);
			Sharpen.Tests.AreEqual("I", component.GetComponentName());
			component = new JpegComponent(5, 2, 3);
			Sharpen.Tests.AreEqual("Q", component.GetComponentName());
		}
        public virtual void TestGetComponentCharacter()
        {
            JpegComponent component;

            component = new JpegComponent(1, 2, 3);
            Sharpen.Tests.AreEqual("Y", component.GetComponentName());
            component = new JpegComponent(2, 2, 3);
            Sharpen.Tests.AreEqual("Cb", component.GetComponentName());
            component = new JpegComponent(3, 2, 3);
            Sharpen.Tests.AreEqual("Cr", component.GetComponentName());
            component = new JpegComponent(4, 2, 3);
            Sharpen.Tests.AreEqual("I", component.GetComponentName());
            component = new JpegComponent(5, 2, 3);
            Sharpen.Tests.AreEqual("Q", component.GetComponentName());
        }
 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));
 }
        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));
        }
Esempio n. 12
0
        public virtual string GetComponentDataDescription(int componentNumber)
        {
            JpegComponent value = _directory.GetComponent(componentNumber);

            if (value == null)
            {
                return(null);
            }
            StringBuilder sb = new StringBuilder();

            sb.Append(value.GetComponentName());
            sb.Append(" component: Quantization table ");
            sb.Append(value.GetQuantizationTableNumber());
            sb.Append(", Sampling factors ");
            sb.Append(value.GetHorizontalSamplingFactor());
            sb.Append(" horiz/");
            sb.Append(value.GetVerticalSamplingFactor());
            sb.Append(" vert");
            return(sb.ToString());
        }