Example #1
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);
            }
        }
Example #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);
     }
 }
 public virtual void TestGetImageWidthDescription()
 {
     _directory.SetInt(JpegDirectory.TagImageWidth, 123);
     Sharpen.Tests.AreEqual("123 pixels", _descriptor.GetImageWidthDescription());
     Sharpen.Tests.AreEqual("123 pixels", _directory.GetDescription(JpegDirectory.TagImageWidth));
 }
 public virtual void TestSetAndGetValue()
 {
     _directory.SetInt(123, 8);
     Sharpen.Tests.AreEqual(8, _directory.GetInt(123));
 }