public void IndexedPixelsCollectionException()
 {
     ReportStart();
     _pa = new PixelAnalysis( MakeBitmap( 10 ), QuantizerType.NeuQuant );
     _pa.Analyse();
     try
     {
         Assert.IsNull( _pa.IndexedPixelsCollection );
     }
     catch( InvalidOperationException ex )
     {
         string message
             = "The PixelAnalysis object was instantiated using the "
             + "constructor which accepts a single image and you "
             + "are attempting to retrieve the indexed pixels for a "
             + "collection of images. "
             + "Call the IndexedPixels property instead.";
         StringAssert.Contains( message, ex.Message );
         ReportEnd();
         throw;
     }
 }
 private void TestMultipleImages( int numberOfColours )
 {
     _images.Add( MakeBitmap( numberOfColours ) );
     _images.Add( MakeBitmap( numberOfColours ) );
     _pa = new PixelAnalysis( _images );
     _pa.Analyse();
     CheckColourTable( numberOfColours );
     CheckIndexedPixelsCollection( numberOfColours );
 }
 private void TestSingleImage( int numberOfColours, QuantizerType qt )
 {
     Bitmap image = MakeBitmap( numberOfColours );
     _pa = new PixelAnalysis( image, qt );
     _pa.Analyse();
     CheckColourTable( numberOfColours );
     CheckIndexedPixels( numberOfColours );
 }
 public void SingleImage257ColoursOctree()
 {
     ReportStart();
     Bitmap image = MakeBitmap( 257 );
     _pa = new PixelAnalysis( image, QuantizerType.Octree );
     _pa.Analyse();
     // FIXME: Octree quantizer is quantizing too much - reducing to 128 colours instead of 256
     // TODO: Check for exactly 256 colours once Octree quantizer returns 256-colour images
     //			Assert.AreEqual( 256, _pa.ColourTable.Length );
     Assert.LessOrEqual( _pa.ColourTable.Length, 256 );
     Assert.AreEqual( image.Width * image.Height,
                      _pa.IndexedPixels.Count );
     ReportEnd();
 }
 public void SingleImage257ColoursNeuQuant()
 {
     ReportStart();
     Bitmap image = MakeBitmap( 257 );
     _pa = new PixelAnalysis( image, QuantizerType.NeuQuant );
     _pa.Analyse();
     Assert.AreEqual( 256, _pa.ColourTable.Length );
     Assert.AreEqual( image.Width * image.Height,
                      _pa.IndexedPixels.Count );
     ReportEnd();
 }
        public void MultipleImages257Colours()
        {
            ReportStart();
            _images.Add( MakeBitmap( 257 ) );
            _images.Add( MakeBitmap( 257 ) );
            _pa = new PixelAnalysis( _images );
            _pa.Analyse();

            // Cannot use the TestMultipleImages method this time because using
            // more than 256 colours causes colour quantization to reduce it
            // to 256 colours. Exact contents of colour table and indexed pixels
            // are therefore unpredictable - we can only check their lengths.
            Assert.AreEqual( 256, _pa.ColourTable.Length );
            Assert.AreEqual( 2, _pa.IndexedPixelsCollection.Count );
            Assert.AreEqual( _images[0].Width * _images[0].Height,
                             _pa.IndexedPixelsCollection[0].Count );
            Assert.AreEqual( _images[1].Width * _images[1].Height,
                             _pa.IndexedPixelsCollection[1].Count );
            ReportEnd();
        }
Пример #7
0
		/// <summary>
		/// Writes a Logical Screen Descriptor to the supplied stream.
		/// Also writes a global colour table if required.
		/// </summary>
		/// <param name="outputStream">
		/// The stream to write to.
		/// </param>
		private void WriteLogicalScreenDescriptor( Stream outputStream )
		{
			bool hasGlobalColourTable = _strategy == ColourTableStrategy.UseGlobal;
			int colourResolution = 7; // TODO: parameterise colourResolution?
			bool globalColourTableIsSorted = false; // Sorting of colour tables is not currently supported
			int backgroundColorIndex = 0; // TODO: parameterise backgroundColourIndex?
			int pixelAspectRatio = 0; // TODO: parameterise pixelAspectRatio?
			if( _strategy == ColourTableStrategy.UseGlobal )
			{
				if( _quantizerType == QuantizerType.UseSuppliedPalette )
				{
					// use supplied palette
					_globalColourTable = new ColourTable();
					string buildColourTableCounterText 
						= "Building colour table from supplied palette";
					AddCounter( buildColourTableCounterText, 
					            _palette.Count );
					int paletteIndex = 0;
					foreach( Color c in _palette )
					{
						_globalColourTable.Add( c );
						MyProgressCounters[buildColourTableCounterText].Value 
							= paletteIndex;
						paletteIndex++;
					}
					_globalColourTable.Pad();
					RemoveCounter( buildColourTableCounterText );
				}
				else
				{
					// Analyse the pixels in all the images to build the
					// global colour table.
					Collection<Image> images = new Collection<Image>();
					foreach( GifFrame thisFrame in _frames )
					{
						Image thisImage = thisFrame.TheImage;
						images.Add( thisImage );
					}
					_pixelAnalysis = new PixelAnalysis( images );
					_pixelAnalysis.ColourQuality = _quality;
					_pixelAnalysis.Analyse();
					_globalColourTable = _pixelAnalysis.ColourTable;
				}
				LogicalScreenDescriptor lsd = 
					new LogicalScreenDescriptor( _logicalScreenSize, 
					                             hasGlobalColourTable, 
					                             colourResolution, 
					                             globalColourTableIsSorted, 
					                             _globalColourTable.SizeBits,
					                             backgroundColorIndex, 
					                             pixelAspectRatio );
				lsd.WriteToStream( outputStream );
				_globalColourTable.WriteToStream( outputStream );
			}
			else
			{
				LogicalScreenDescriptor lsd = 
					new LogicalScreenDescriptor( _logicalScreenSize, 
					                             hasGlobalColourTable, 
					                             colourResolution, 
					                             globalColourTableIsSorted, 
					                             7, 
					                             backgroundColorIndex, 
					                             pixelAspectRatio );
				lsd.WriteToStream( outputStream );
			}
		}
Пример #8
0
		private ColourTable SetActiveColourTable()
		{
			ColourTable act; // active colour table
			if( _strategy == ColourTableStrategy.UseLocal )
			{
				if( _quantizerType == QuantizerType.UseSuppliedPalette )
				{
					if( _frames[_encodingFrame].Palette == null )
					{
						// TESTME: SetActiveColourTable - SetActiveColourTable, UseSuppliedPalette, no palette supplied
						string message
							= "You have opted to use a local colour table built "
							+ "from a supplied palette, but frame "
							+ _encodingFrame
							+ "does not have a palette.";
						throw new InvalidOperationException( message );
					}
					else
					{
						// Build local colour table from colours in the frame's
						// supplied palette.
						act = new ColourTable();
						foreach( Color c in _frames[_encodingFrame].Palette )
						{
							act.Add( c );
						}
						act.Pad();
					}
				}
				else
				{
					// Build local colour table based on colours in the image.
					Image thisImage = _frames[_encodingFrame].TheImage;
					_pixelAnalysis = new PixelAnalysis( thisImage, 
					                                    _quantizerType );
					_pixelAnalysis.ColourQuality = _quality;
					_pixelAnalysis.Analyse();
					// make local colour table active
					act = _pixelAnalysis.ColourTable;
				}
			}
			else
			{
				// make global colour table active
				act = _globalColourTable;
			}
			return act;
		}