Ejemplo n.º 1
0
        public void ConstructorTest()
        {
            ReportStart();
            _pf = new PackedFields(0);               // 00000000
            Assert.AreEqual(0, _pf.Byte);
            for (int i = 0; i < 8; i++)
            {
                Assert.AreEqual(false, _pf.GetBit(i), "bit " + i);
            }

            _pf = new PackedFields(255);               // 11111111
            Assert.AreEqual(255, _pf.Byte);
            for (int i = 0; i < 8; i++)
            {
                Assert.AreEqual(true, _pf.GetBit(i), "bit " + i);
            }

            _pf = new PackedFields(36);               // 00100010
            Assert.AreEqual(36, _pf.Byte);
            Assert.AreEqual(false, _pf.GetBit(0));
            Assert.AreEqual(false, _pf.GetBit(1));
            Assert.AreEqual(true, _pf.GetBit(2));
            Assert.AreEqual(false, _pf.GetBit(3));
            Assert.AreEqual(false, _pf.GetBit(4));
            Assert.AreEqual(true, _pf.GetBit(5));
            Assert.AreEqual(false, _pf.GetBit(6));
            Assert.AreEqual(false, _pf.GetBit(7));
            ReportEnd();
        }
Ejemplo n.º 2
0
 public void GetSetBitTest()
 {
     ReportStart();
     for (int i = 0; i < 8; i++)
     {
         _pf = new PackedFields();
         _pf.SetBit(i, true);
         Assert.AreEqual(true, _pf.GetBit(i));
     }
     ReportEnd();
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Writes this component to the supplied output stream.
        /// </summary>
        /// <param name="outputStream">
        /// The output stream to write to.
        /// </param>
        public override void WriteToStream(Stream outputStream)
        {
            WriteByte(_blockSize, outputStream);

            PackedFields packed = new PackedFields();

            packed.SetBits(3, 3, (int)_disposalMethod);
            packed.SetBit(6, _expectsUserInput);
            packed.SetBit(7, _hasTransparentColour);
            WriteByte(packed.Byte, outputStream);

            WriteShort(_delayTime, outputStream);
            WriteByte(_transparentColourIndex, outputStream);
            WriteByte(0, outputStream); // block terminator
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Writes this component to the supplied output stream.
        /// </summary>
        /// <param name="outputStream">
        /// The output stream to write to.
        /// </param>
        public override void WriteToStream(Stream outputStream)
        {
            // Position and size of the image in this frame
            WriteShort(_position.X, outputStream);
            WriteShort(_position.Y, outputStream);
            WriteShort(_size.Width, outputStream);
            WriteShort(_size.Height, outputStream);

            PackedFields packed = new PackedFields();

            packed.SetBit(0, _hasLocalColourTable);
            packed.SetBit(1, _isInterlaced);
            packed.SetBit(2, _isSorted);
            packed.SetBits(5, 3, _localColourTableSizeBits);
            WriteByte(packed.Byte, outputStream);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Reads and returns an image descriptor from the supplied stream.
        /// </summary>
        /// <param name="inputStream">
        /// The input stream to read.
        /// </param>
        public ImageDescriptor(Stream inputStream)
        {
            int leftPosition = ReadShort(inputStream);               // (sub)image position & size
            int topPosition  = ReadShort(inputStream);
            int width        = ReadShort(inputStream);
            int height       = ReadShort(inputStream);

            _position = new Point(leftPosition, topPosition);
            _size     = new Size(width, height);

            PackedFields packed = new PackedFields(Read(inputStream));

            _hasLocalColourTable      = packed.GetBit(0);
            _isInterlaced             = packed.GetBit(1);
            _isSorted                 = packed.GetBit(2);
            _localColourTableSizeBits = packed.GetBits(5, 3);
        }
        /// <summary>
        /// Constructor.
        /// Reads and returns a logical screen descriptor from the supplied
        /// input stream.
        /// </summary>
        /// <param name="inputStream">
        /// The input stream to be read.
        /// </param>
        /// <param name="xmlDebugging">
        /// Whether or not to create debug XML.
        /// </param>
        public LogicalScreenDescriptor(Stream inputStream, bool xmlDebugging)
            : base(xmlDebugging)
        {
            // logical screen size
            int width  = ReadShort(inputStream);
            int height = ReadShort(inputStream);

            _screenSize = new Size(width, height);

            PackedFields packed = new PackedFields(Read(inputStream));

            _hasGlobalColourTable = packed.GetBit(0);
            _colourResolution     = packed.GetBits(1, 3);
            _gctIsSorted          = packed.GetBit(4);
            _gctSizeBits          = packed.GetBits(5, 3);

            _backgroundColourIndex = Read(inputStream);
            _pixelAspectRatio      = Read(inputStream);

            if (XmlDebugging)
            {
                WriteDebugXmlStartElement("LogicalScreenSize");
                WriteDebugXmlAttribute("Width", width);
                WriteDebugXmlAttribute("Height", height);
                WriteDebugXmlEndElement();

                WriteDebugXmlStartElement("PackedFields");
                WriteDebugXmlAttribute("ByteRead", ToHex(packed.Byte));
                WriteDebugXmlAttribute("HasGlobalColourTable", _hasGlobalColourTable);
                WriteDebugXmlAttribute("ColourResolution", _colourResolution);
                WriteDebugXmlAttribute("GlobalColourTableIsSorted", _gctIsSorted);
                WriteDebugXmlAttribute("GlobalColourTableSizeBits", _gctSizeBits);
                WriteDebugXmlEndElement();

                WriteDebugXmlElement("BackgroundColourIndex", _backgroundColourIndex);
                WriteDebugXmlElement("PixelAspectRatio", _pixelAspectRatio);
            }

            if (width < 0 || height < 0 || packed.Byte < 0 ||
                _backgroundColourIndex < 0 || _pixelAspectRatio < 0)
            {
                SetStatus(ErrorState.EndOfInputStream, "");
            }
            WriteDebugXmlFinish();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Writes this component to the supplied output stream.
        /// </summary>
        /// <param name="outputStream">
        /// The output stream to write to.
        /// </param>
        public override void WriteToStream(Stream outputStream)
        {
            // logical screen size
            WriteShort(_screenSize.Width, outputStream);
            WriteShort(_screenSize.Height, outputStream);

            // Packed fields
            PackedFields packed = new PackedFields();

            packed.SetBit(0, _hasGlobalColourTable);
            packed.SetBits(1, 3, _colourResolution);
            packed.SetBit(4, _gctIsSorted);
            packed.SetBits(5, 3, _gctSizeBits);
            WriteByte(packed.Byte, outputStream);

            WriteByte(_backgroundColourIndex, outputStream);
            WriteByte(_pixelAspectRatio, outputStream);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Reads and returns an image descriptor from the supplied stream.
        /// </summary>
        /// <param name="inputStream">
        /// The input stream to read.
        /// </param>
        /// <param name="xmlDebugging">Whether or not to create debug XML</param>
        public ImageDescriptor(Stream inputStream, bool xmlDebugging)
            : base(xmlDebugging)
        {
            int leftPosition = ReadShort(inputStream);               // (sub)image position & size
            int topPosition  = ReadShort(inputStream);
            int width        = ReadShort(inputStream);
            int height       = ReadShort(inputStream);

            _position = new Point(leftPosition, topPosition);
            _size     = new Size(width, height);

            PackedFields packed = new PackedFields(Read(inputStream));

            _hasLocalColourTable      = packed.GetBit(0);
            _isInterlaced             = packed.GetBit(1);
            _isSorted                 = packed.GetBit(2);
            _localColourTableSizeBits = packed.GetBits(5, 3);

            if (XmlDebugging)
            {
                WriteDebugXmlStartElement("Position");
                WriteDebugXmlAttribute("X", _position.X);
                WriteDebugXmlAttribute("Y", _position.Y);
                WriteDebugXmlEndElement();

                WriteDebugXmlStartElement("Size");
                WriteDebugXmlAttribute("Width", _size.Width);
                WriteDebugXmlAttribute("Height", _size.Height);
                WriteDebugXmlEndElement();

                WriteDebugXmlStartElement("PackedFields");
                WriteDebugXmlAttribute("ByteRead", ToHex(packed.Byte));
                WriteDebugXmlAttribute("HasLocalColourTable",
                                       _hasLocalColourTable);
                WriteDebugXmlAttribute("IsInterlaced", _isInterlaced);
                WriteDebugXmlAttribute("LocalColourTableIsSorted", _isSorted);
                WriteDebugXmlAttribute("LocalColourTableSizeBits",
                                       _localColourTableSizeBits);
                WriteDebugXmlEndElement();

                WriteDebugXmlFinish();
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="inputStream">
        /// The input stream to read.
        /// </param>
        public GraphicControlExtension(Stream inputStream)
        {
            _blockSize = Read(inputStream);               // block size

            PackedFields packed = new PackedFields(Read(inputStream));

            _disposalMethod       = (DisposalMethod)packed.GetBits(3, 3);
            _expectsUserInput     = packed.GetBit(6);
            _hasTransparentColour = packed.GetBit(7);

            if (_disposalMethod == 0)
            {
                _disposalMethod = DisposalMethod.DoNotDispose;                 // elect to keep old image if discretionary
            }

            _delayTime = ReadShort(inputStream);         // delay in hundredths of a second
            _transparentColourIndex = Read(inputStream); // transparent color index
            Read(inputStream);                           // block terminator
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="inputStream">
        /// The input stream to read.
        /// </param>
        /// <param name="xmlDebugging">Whether or not to create debug XML</param>
        public GraphicControlExtension(Stream inputStream, bool xmlDebugging)
            : base(xmlDebugging)
        {
            _blockSize = Read(inputStream); // block size

            PackedFields packed = new PackedFields(Read(inputStream));

            _disposalMethod       = (DisposalMethod)packed.GetBits(3, 3);
            _expectsUserInput     = packed.GetBit(6);
            _hasTransparentColour = packed.GetBit(7);

            if (_disposalMethod == 0)
            {
                _disposalMethod = DisposalMethod.DoNotDispose; // elect to keep old image if discretionary
            }

            _delayTime = ReadShort(inputStream);         // delay in hundredths of a second
            _transparentColourIndex = Read(inputStream); // transparent color index
            int blockTerminator = Read(inputStream);     // block terminator

            if (xmlDebugging)
            {
                WriteDebugXmlElement("BlockSize", _blockSize);

                WriteDebugXmlStartElement("PackedFields");
                WriteDebugXmlAttribute("ByteRead", ToHex(packed.Byte));
                WriteDebugXmlAttribute("DisposalMethod",
                                       _disposalMethod.ToString());
                WriteDebugXmlAttribute("ExpectsUserInput", _expectsUserInput);
                WriteDebugXmlAttribute("HasTransparentColour", _hasTransparentColour);
                WriteDebugXmlEndElement();

                WriteDebugXmlElement("DelayTime", _delayTime);
                WriteDebugXmlElement("TransparentColourIndex",
                                     _transparentColourIndex);
                WriteDebugXmlElement("BlockTerminator", blockTerminator);

                WriteDebugXmlFinish();
            }
        }
Ejemplo n.º 11
0
 public void GetSetBitsTest()
 {
     ReportStart();
     _pf = new PackedFields();
     _pf.SetBits(2, 3, 4);
     Assert.AreEqual(false, _pf.GetBit(0));
     Assert.AreEqual(false, _pf.GetBit(1));
     Assert.AreEqual(true, _pf.GetBit(2));
     Assert.AreEqual(false, _pf.GetBit(3));
     Assert.AreEqual(false, _pf.GetBit(4));
     Assert.AreEqual(false, _pf.GetBit(5));
     Assert.AreEqual(false, _pf.GetBit(6));
     Assert.AreEqual(false, _pf.GetBit(7));
     Assert.AreEqual(4, _pf.GetBits(2, 3));
     Assert.AreEqual(4, _pf.GetBits(1, 4));
     Assert.AreEqual(4, _pf.GetBits(0, 5));
     Assert.AreEqual(8, _pf.GetBits(0, 6));
     Assert.AreEqual(16, _pf.GetBits(0, 7));
     Assert.AreEqual(32, _pf.GetBits(0, 8));
     Assert.AreEqual(32, _pf.Byte);
     ReportEnd();
 }
Ejemplo n.º 12
0
 public void GetSetBitsTest2()
 {
     ReportStart();
     _pf = new PackedFields();
     _pf.SetBits(1, 5, 13);
     Assert.AreEqual(false, _pf.GetBit(0));
     Assert.AreEqual(false, _pf.GetBit(1));
     Assert.AreEqual(true, _pf.GetBit(2));
     Assert.AreEqual(true, _pf.GetBit(3));
     Assert.AreEqual(false, _pf.GetBit(4));
     Assert.AreEqual(true, _pf.GetBit(5));
     Assert.AreEqual(false, _pf.GetBit(6));
     Assert.AreEqual(false, _pf.GetBit(7));
     Assert.AreEqual(13, _pf.GetBits(1, 5));
     Assert.AreEqual(13, _pf.GetBits(0, 6));
     Assert.AreEqual(13, _pf.GetBits(2, 4));
     Assert.AreEqual(26, _pf.GetBits(1, 6));
     Assert.AreEqual(13, _pf.GetBits(0, 6));
     Assert.AreEqual(26, _pf.GetBits(0, 7));
     Assert.AreEqual(52, _pf.GetBits(0, 8));
     Assert.AreEqual(52, _pf.Byte);
     ReportEnd();
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Constructor.
        /// Reads and returns a logical screen descriptor from the supplied
        /// input stream.
        /// </summary>
        /// <param name="inputStream">
        /// The input stream to be read.
        /// </param>
        public LogicalScreenDescriptor(Stream inputStream)
        {
            // logical screen size
            int width  = ReadShort(inputStream);
            int height = ReadShort(inputStream);

            _screenSize = new Size(width, height);

            PackedFields packed = new PackedFields(Read(inputStream));

            _hasGlobalColourTable = packed.GetBit(0);
            _colourResolution     = packed.GetBits(1, 3);
            _gctIsSorted          = packed.GetBit(4);
            _gctSizeBits          = packed.GetBits(5, 3);

            _backgroundColourIndex = Read(inputStream);
            _pixelAspectRatio      = Read(inputStream);

            if (width < 0 || height < 0 || packed.Byte < 0 ||
                _backgroundColourIndex < 0 || _pixelAspectRatio < 0)
            {
                SetStatus(ErrorState.EndOfInputStream, "");
            }
        }
Ejemplo n.º 14
0
		/// <summary>
		/// Writes this component to the supplied output stream.
		/// </summary>
		/// <param name="outputStream">
		/// The output stream to write to.
		/// </param>
		public override void WriteToStream( Stream outputStream )
		{
			WriteByte( _blockSize, outputStream );
			
			PackedFields packed = new PackedFields();
			packed.SetBits( 3, 3, (int) _disposalMethod );
			packed.SetBit( 6, _expectsUserInput );
			packed.SetBit( 7, _hasTransparentColour );
			WriteByte( packed.Byte, outputStream );
			
			WriteShort( _delayTime , outputStream);
			WriteByte( _transparentColourIndex, outputStream );
			WriteByte( 0, outputStream ); // block terminator
		}
Ejemplo n.º 15
0
		/// <summary>
		/// Constructor.
		/// </summary>
		/// <param name="inputStream">
		/// The input stream to read.
		/// </param>
		/// <param name="xmlDebugging">Whether or not to create debug XML</param>
		public GraphicControlExtension( Stream inputStream, bool xmlDebugging )
			: base( xmlDebugging )
		{
			_blockSize = Read( inputStream ); // block size
			
			PackedFields packed = new PackedFields( Read( inputStream ) );
			_disposalMethod = (DisposalMethod) packed.GetBits( 3, 3 );
			_expectsUserInput = packed.GetBit( 6 );
			_hasTransparentColour = packed.GetBit( 7 );

			if( _disposalMethod == 0 )
			{
				_disposalMethod = DisposalMethod.DoNotDispose; // elect to keep old image if discretionary
			}
			
			_delayTime = ReadShort( inputStream ); // delay in hundredths of a second
			_transparentColourIndex = Read( inputStream ); // transparent color index
			int blockTerminator = Read( inputStream ); // block terminator
			
			if( xmlDebugging )
			{
				WriteDebugXmlElement( "BlockSize", _blockSize );
				
				WriteDebugXmlStartElement( "PackedFields" );
				WriteDebugXmlAttribute( "ByteRead", ToHex( packed.Byte ) );
				WriteDebugXmlAttribute( "DisposalMethod", 
				                        _disposalMethod.ToString() );
				WriteDebugXmlAttribute( "ExpectsUserInput", _expectsUserInput );
				WriteDebugXmlAttribute( "HasTransparentColour", _hasTransparentColour );
				WriteDebugXmlEndElement();
				
				WriteDebugXmlElement( "DelayTime", _delayTime );
				WriteDebugXmlElement( "TransparentColourIndex", 
				                      _transparentColourIndex );
				WriteDebugXmlElement( "BlockTerminator", blockTerminator );
				
				WriteDebugXmlFinish();
			}
		}
Ejemplo n.º 16
0
		/// <summary>
		/// Writes this component to the supplied output stream.
		/// </summary>
		/// <param name="outputStream">
		/// The output stream to write to.
		/// </param>
		public override void WriteToStream( Stream outputStream )
		{
			// Position and size of the image in this frame
			WriteShort( _position.X, outputStream );
			WriteShort( _position.Y, outputStream );
			WriteShort( _size.Width, outputStream );
			WriteShort( _size.Height, outputStream );
			
			PackedFields packed = new PackedFields();
			packed.SetBit( 0, _hasLocalColourTable );
			packed.SetBit( 1, _isInterlaced );
			packed.SetBit( 2, _isSorted );
			packed.SetBits( 5, 3, _localColourTableSizeBits );
			WriteByte( packed.Byte, outputStream );
		}
Ejemplo n.º 17
0
        /// <summary>
        /// Constructor.
        /// Reads and returns a logical screen descriptor from the supplied
        /// input stream.
        /// </summary>
        /// <param name="inputStream">
        /// The input stream to be read.
        /// </param>
        /// <param name="xmlDebugging">
        /// Whether or not to create debug XML.
        /// </param>
        public LogicalScreenDescriptor( Stream inputStream, bool xmlDebugging )
            : base(xmlDebugging)
        {
            // logical screen size
            int width = ReadShort( inputStream );
            int height = ReadShort( inputStream );
            _screenSize = new Size( width, height );

            PackedFields packed = new PackedFields( Read( inputStream ) );
            _hasGlobalColourTable = packed.GetBit( 0 );
            _colourResolution = packed.GetBits( 1, 3 );
            _gctIsSorted = packed.GetBit( 4 );
            _gctSizeBits = packed.GetBits( 5, 3 );

            _backgroundColourIndex = Read( inputStream );
            _pixelAspectRatio = Read( inputStream );

            if( XmlDebugging )
            {
                WriteDebugXmlStartElement( "LogicalScreenSize" );
                WriteDebugXmlAttribute( "Width", width );
                WriteDebugXmlAttribute( "Height", height );
                WriteDebugXmlEndElement();

                WriteDebugXmlStartElement( "PackedFields" );
                WriteDebugXmlAttribute( "ByteRead", ToHex( packed.Byte ) );
                WriteDebugXmlAttribute( "HasGlobalColourTable", _hasGlobalColourTable );
                WriteDebugXmlAttribute( "ColourResolution", _colourResolution );
                WriteDebugXmlAttribute( "GlobalColourTableIsSorted", _gctIsSorted );
                WriteDebugXmlAttribute( "GlobalColourTableSizeBits", _gctSizeBits );
                WriteDebugXmlEndElement();

                WriteDebugXmlElement( "BackgroundColourIndex", _backgroundColourIndex );
                WriteDebugXmlElement( "PixelAspectRatio", _pixelAspectRatio );
            }

            if( width < 0 || height < 0 || packed.Byte < 0
               || _backgroundColourIndex < 0 || _pixelAspectRatio < 0 )
            {
                SetStatus( ErrorState.EndOfInputStream, "" );
            }
            WriteDebugXmlFinish();
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Writes this component to the supplied output stream.
        /// </summary>
        /// <param name="outputStream">
        /// The output stream to write to.
        /// </param>
        public override void WriteToStream( Stream outputStream )
        {
            // logical screen size
            WriteShort( _screenSize.Width, outputStream );
            WriteShort( _screenSize.Height, outputStream );

            // Packed fields
            PackedFields packed = new PackedFields();
            packed.SetBit( 0, _hasGlobalColourTable );
            packed.SetBits( 1, 3, _colourResolution );
            packed.SetBit( 4, _gctIsSorted );
            packed.SetBits( 5, 3, _gctSizeBits );
            WriteByte( packed.Byte, outputStream );

            WriteByte( _backgroundColourIndex, outputStream );
            WriteByte( _pixelAspectRatio, outputStream );
        }
Ejemplo n.º 19
0
		/// <summary>
		/// Reads and returns an image descriptor from the supplied stream.
		/// </summary>
		/// <param name="inputStream">
		/// The input stream to read.
		/// </param>
		/// <param name="xmlDebugging">Whether or not to create debug XML</param>
		public ImageDescriptor( Stream inputStream, bool xmlDebugging )
			: base( xmlDebugging )
		{
			int leftPosition = ReadShort( inputStream ); // (sub)image position & size
			int topPosition = ReadShort( inputStream );
			int width = ReadShort( inputStream );
			int height = ReadShort( inputStream );
			_position = new Point( leftPosition, topPosition );
			_size = new Size( width, height );

			PackedFields packed = new PackedFields( Read( inputStream ) );
			_hasLocalColourTable = packed.GetBit( 0 );
			_isInterlaced = packed.GetBit( 1 );
			_isSorted = packed.GetBit( 2 );
			_localColourTableSizeBits = packed.GetBits( 5, 3 );
			
			if( XmlDebugging )
			{
				WriteDebugXmlStartElement( "Position" );
				WriteDebugXmlAttribute( "X", _position.X );
				WriteDebugXmlAttribute( "Y", _position.Y );
				WriteDebugXmlEndElement();
				
				WriteDebugXmlStartElement( "Size" );
				WriteDebugXmlAttribute( "Width", _size.Width );
				WriteDebugXmlAttribute( "Height", _size.Height );
				WriteDebugXmlEndElement();
				
				WriteDebugXmlStartElement( "PackedFields" );
				WriteDebugXmlAttribute( "ByteRead", ToHex( packed.Byte ) );
				WriteDebugXmlAttribute( "HasLocalColourTable", 
				                        _hasLocalColourTable );
				WriteDebugXmlAttribute( "IsInterlaced", _isInterlaced );
				WriteDebugXmlAttribute( "LocalColourTableIsSorted", _isSorted );
				WriteDebugXmlAttribute( "LocalColourTableSizeBits", 
				                        _localColourTableSizeBits );
				WriteDebugXmlEndElement();
				
				WriteDebugXmlFinish();
			}
		}