public void ErrorMessageTest()
 {
     ReportStart();
     _status = new GifComponentStatus( ErrorState.Ok, "message" );
     Assert.AreEqual( "message", _status.ErrorMessage );
     ReportEnd();
 }
 public void ErrorMessageTest()
 {
     ReportStart();
     _status = new GifComponentStatus(ErrorState.Ok, "message");
     Assert.AreEqual("message", _status.ErrorMessage);
     ReportEnd();
 }
 public void ToStringTest()
 {
     ReportStart();
     _status = new GifComponentStatus(ErrorState.NotANetscapeExtension
                                      | ErrorState.BadDataBlockIntroducer,
                                      "error");
     Assert.AreEqual("BadDataBlockIntroducer, NotANetscapeExtension",
                     _status.ToString());
     ReportEnd();
 }
 public void ErrorStateTest()
 {
     ReportStart();
     foreach (ErrorState state in ErrorState.GetValues(typeof(ErrorState)))
     {
         _status = new GifComponentStatus(state, "error");
         Assert.AreEqual(state, _status.ErrorState);
     }
     ReportEnd();
 }
 public void ToStringTest()
 {
     ReportStart();
     _status = new GifComponentStatus( ErrorState.NotANetscapeExtension
                                      | ErrorState.BadDataBlockIntroducer,
                                      "error" );
     Assert.AreEqual( "BadDataBlockIntroducer, NotANetscapeExtension",
                      _status.ToString() );
     ReportEnd();
 }
 public void ErrorStateTest()
 {
     ReportStart();
     foreach( ErrorState state in ErrorState.GetValues( typeof( ErrorState ) ) )
     {
         _status = new GifComponentStatus( state, "error" );
         Assert.AreEqual( state, _status.ErrorState );
     }
     ReportEnd();
 }
예제 #7
0
        /// <summary>
        /// Sets the ComponentStatus property of thie GifComponent.
        /// </summary>
        /// <param name="errorState">
        /// A member of the Gif.Components.ErrorState enumeration.
        /// </param>
        /// <param name="errorMessage">
        /// An error message associated with the error state.
        /// </param>
        protected void SetStatus(ErrorState errorState, string errorMessage)
        {
            ErrorState newState   = _status.ErrorState | errorState;
            string     newMessage = _status.ErrorMessage;

            if (!String.IsNullOrEmpty(newMessage))
            {
                newMessage += Environment.NewLine;
            }
            newMessage += errorMessage;
            _status     = new GifComponentStatus(newState, newMessage);
        }
예제 #8
0
		/// <summary>
		/// Sets the pixels of the decoded image.
		/// </summary>
		/// <param name="imageData">
		/// Table based image data containing the indices within the active
		/// colour table of the colours of the pixels in this frame.
		/// </param>
		/// <param name="lsd">
		/// The logical screen descriptor for the GIF stream.
		/// </param>
		/// <param name="id">
		/// The image descriptor for this frame.
		/// </param>
		/// <param name="activeColourTable">
		/// The colour table to use with this frame - either the global colour
		/// table or a local colour table.
		/// </param>
		/// <param name="gce">
		/// The graphic control extension, if any, which precedes this image in
		/// the input stream.
		/// </param>
		/// <param name="previousFrame">
		/// The frame which precedes this one in the GIF stream, if present.
		/// </param>
		/// <param name="previousFrameBut1">
		/// The frame which precedes the frame before this one in the GIF stream,
		/// if present.
		/// </param>
		/// <param name="status">
		/// GifComponentStatus containing any errors which occurred during the
		/// creation of the bitmap.
		/// </param>
		private static Bitmap CreateBitmap( TableBasedImageData imageData,
		                                    LogicalScreenDescriptor lsd,
		                                    ImageDescriptor id,
		                                    ColourTable activeColourTable,
		                                    GraphicControlExtension gce,
		                                    GifFrame previousFrame,
		                                    GifFrame previousFrameBut1, 
		                                    out GifComponentStatus status )
		{
			status = new GifComponentStatus( ErrorState.Ok, "" );
			Color[] pixelsForThisFrame = new Color[lsd.LogicalScreenSize.Width 
			                                       * lsd.LogicalScreenSize.Height];
			
			Bitmap baseImage = GetBaseImage( previousFrame, 
			                                 previousFrameBut1, 
			                                 lsd, 
			                                 gce, 
			                                 activeColourTable );

			// copy each source line to the appropriate place in the destination
			int pass = 1;
			int interlaceRowIncrement = 8;
			int interlaceRowNumber = 0; // the row of pixels we're currently 
										// setting in an interlaced image.
			for( int i = 0; i < id.Size.Height; i++)  
			{
				int pixelRowNumber = i;
				if( id.IsInterlaced ) 
				{
					#region work out the pixel row we're setting for an interlaced image
					if( interlaceRowNumber >= id.Size.Height ) 
					{
						pass++;
						switch( pass )
						{
							case 2 :
								interlaceRowNumber = 4;
								break;
							case 3 :
								interlaceRowNumber = 2;
								interlaceRowIncrement = 4;
								break;
							case 4 :
								interlaceRowNumber = 1;
								interlaceRowIncrement = 2;
								break;
						}
					}
					#endregion
					pixelRowNumber = interlaceRowNumber;
					interlaceRowNumber += interlaceRowIncrement;
				}
				
				// Colour in the pixels for this row
				pixelRowNumber += id.Position.Y;
				if( pixelRowNumber < lsd.LogicalScreenSize.Height ) 
				{
					int k = pixelRowNumber * lsd.LogicalScreenSize.Width;
					int dx = k + id.Position.X; // start of line in dest
					int dlim = dx + id.Size.Width; // end of dest line
					if( (k + lsd.LogicalScreenSize.Width) < dlim ) 
					{
						// TESTME: CreateBitmap - past dest edge
						dlim = k + lsd.LogicalScreenSize.Width; // past dest edge
					}
					int sx = i * id.Size.Width; // start of line in source
					while (dx < dlim) 
					{
						// map color and insert in destination
						int indexInColourTable = (int) imageData.Pixels[sx++];
						// Set this pixel's colour if its index isn't the 
						// transparent colour index, or if this frame doesn't
						// have a transparent colour.
						Color c;
						if( gce.HasTransparentColour && indexInColourTable == gce.TransparentColourIndex )
						{
							c = Color.Empty; // transparent pixel
						}
						else
						{
							if( indexInColourTable < activeColourTable.Length )
							{
								c = activeColourTable[indexInColourTable];
							}
							else
							{
								// TESTME: CreateBitmap - BadColourIndex
								c = Color.Black;
								string message 
									= "Colour index: "
									+ indexInColourTable
									+ ", colour table length: "
									+ activeColourTable.Length
									+ " (" + dx + "," + pixelRowNumber + ")";
								status = new GifComponentStatus( ErrorState.BadColourIndex, 
								                                 message );
							}
						}
						pixelsForThisFrame[dx] = c;
						dx++;
					}
				}
			}
			return CreateBitmap( baseImage, pixelsForThisFrame );
		}
예제 #9
0
 /// <summary>
 /// Constructor.
 /// This is implicitly called by constructors of derived types.
 /// </summary>
 protected GifComponent()
 {
     _status = new GifComponentStatus(ErrorState.Ok, "");
 }
예제 #10
0
        /// <summary>
        /// Sets the ComponentStatus property of thie GifComponent.
        /// </summary>
        /// <param name="errorState">
        /// A member of the Gif.Components.ErrorState enumeration.
        /// </param>
        /// <param name="errorMessage">
        /// An error message associated with the error state.
        /// </param>
        protected void SetStatus( ErrorState errorState, string errorMessage )
        {
            ErrorState newState = _status.ErrorState | errorState;
            string newMessage = _status.ErrorMessage;
            if( !String.IsNullOrEmpty( newMessage ) )
            {
                newMessage += Environment.NewLine;
            }
            newMessage += errorMessage;
            _status = new GifComponentStatus( newState, newMessage );

            if( _xmlDebugging )
            {
                WriteDebugXmlErrorState( errorState, errorMessage );
            }
        }
예제 #11
0
 /// <summary>
 /// Constructor.
 /// This is implicitly called by constructors of derived types.
 /// </summary>
 protected GifComponent()
 {
     _status = new GifComponentStatus( ErrorState.Ok, "" );
 }
예제 #12
0
        /// <summary>
        /// Sets the pixels of the decoded image.
        /// </summary>
        /// <param name="imageData">
        /// Table based image data containing the indices within the active
        /// colour table of the colours of the pixels in this frame.
        /// </param>
        /// <param name="lsd">
        /// The logical screen descriptor for the GIF stream.
        /// </param>
        /// <param name="id">
        /// The image descriptor for this frame.
        /// </param>
        /// <param name="activeColourTable">
        /// The colour table to use with this frame - either the global colour
        /// table or a local colour table.
        /// </param>
        /// <param name="gce">
        /// The graphic control extension, if any, which precedes this image in
        /// the input stream.
        /// </param>
        /// <param name="previousFrame">
        /// The frame which precedes this one in the GIF stream, if present.
        /// </param>
        /// <param name="previousFrameBut1">
        /// The frame which precedes the frame before this one in the GIF stream,
        /// if present.
        /// </param>
        /// <param name="status">
        /// GifComponentStatus containing any errors which occurred during the
        /// creation of the bitmap.
        /// </param>
        private static Bitmap CreateBitmap(TableBasedImageData imageData,
                                           LogicalScreenDescriptor lsd,
                                           ImageDescriptor id,
                                           ColourTable activeColourTable,
                                           GraphicControlExtension gce,
                                           GifFrame previousFrame,
                                           GifFrame previousFrameBut1,
                                           out GifComponentStatus status)
        {
            status = new GifComponentStatus(ErrorState.Ok, "");
            Color[] pixelsForThisFrame = new Color[lsd.LogicalScreenSize.Width
                                                   * lsd.LogicalScreenSize.Height];

            Bitmap baseImage = GetBaseImage(previousFrame,
                                            previousFrameBut1,
                                            lsd,
                                            gce,
                                            activeColourTable);

            // copy each source line to the appropriate place in the destination
            int pass = 1;
            int interlaceRowIncrement = 8;
            int interlaceRowNumber    = 0;          // the row of pixels we're currently

            // setting in an interlaced image.
            for (int i = 0; i < id.Size.Height; i++)
            {
                int pixelRowNumber = i;
                if (id.IsInterlaced)
                {
                    #region work out the pixel row we're setting for an interlaced image
                    if (interlaceRowNumber >= id.Size.Height)
                    {
                        pass++;
                        switch (pass)
                        {
                        case 2:
                            interlaceRowNumber = 4;
                            break;

                        case 3:
                            interlaceRowNumber    = 2;
                            interlaceRowIncrement = 4;
                            break;

                        case 4:
                            interlaceRowNumber    = 1;
                            interlaceRowIncrement = 2;
                            break;
                        }
                    }
                    #endregion
                    pixelRowNumber      = interlaceRowNumber;
                    interlaceRowNumber += interlaceRowIncrement;
                }

                // Colour in the pixels for this row
                pixelRowNumber += id.Position.Y;
                if (pixelRowNumber < lsd.LogicalScreenSize.Height)
                {
                    int k    = pixelRowNumber * lsd.LogicalScreenSize.Width;
                    int dx   = k + id.Position.X;                   // start of line in dest
                    int dlim = dx + id.Size.Width;                  // end of dest line
                    if ((k + lsd.LogicalScreenSize.Width) < dlim)
                    {
                        // TESTME: CreateBitmap - past dest edge
                        dlim = k + lsd.LogicalScreenSize.Width;     // past dest edge
                    }
                    int sx = i * id.Size.Width;                     // start of line in source
                    while (dx < dlim)
                    {
                        // map color and insert in destination
                        int indexInColourTable = (int)imageData.Pixels[sx++];
                        // Set this pixel's colour if its index isn't the
                        // transparent colour index, or if this frame doesn't
                        // have a transparent colour.
                        Color c;
                        if (gce.HasTransparentColour && indexInColourTable == gce.TransparentColourIndex)
                        {
                            c = Color.Empty;                             // transparent pixel
                        }
                        else
                        {
                            if (indexInColourTable < activeColourTable.Length)
                            {
                                c = activeColourTable[indexInColourTable];
                            }
                            else
                            {
                                // TESTME: CreateBitmap - BadColourIndex
                                c = Color.Black;
                                string message
                                    = "Colour index: "
                                      + indexInColourTable
                                      + ", colour table length: "
                                      + activeColourTable.Length
                                      + " (" + dx + "," + pixelRowNumber + ")";
                                status = new GifComponentStatus(ErrorState.BadColourIndex,
                                                                message);
                            }
                        }
                        pixelsForThisFrame[dx] = c;
                        dx++;
                    }
                }
            }
            return(CreateBitmap(baseImage, pixelsForThisFrame));
        }