public void GetBitsTestIndexTooSmall()
 {
     ReportStart();
     try
     {
         _pf.GetBits(-1, 4);
     }
     catch (ArgumentOutOfRangeException ex)
     {
         string message
             = "Start index must be between 0 and 7. Supplied index: -1";
         Assert.AreEqual("startIndex", ex.ParamName);
         StringAssert.Contains(message, ex.Message);
         ReportEnd();
         throw;
     }
 }
        /// <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();
        }
        /// <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, "");
            }
        }
Exemple #4
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);
        }
Exemple #5
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();
            }
        }
        /// <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
        }
        /// <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();
            }
        }
 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();
 }
 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();
 }
		/// <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();
			}
		}
        /// <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();
        }
Exemple #12
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();
			}
		}