public void Setup()
 {
     _frame = new GifFrame(WikipediaExample.ExpectedBitmap);
     Assert.AreEqual(10, _frame.Delay);
     BitmapAssert.AreEqual(WikipediaExample.ExpectedBitmap,
                           (Bitmap)_frame.TheImage);
 }
        public void TextureHandler_Bmp_CombineFailed()
        {
            TextureHandler target = new TextureHandler(32, 32);

            Bitmap input1 = new Bitmap(Path.Combine(localFolder, image_bmp_1_big_red));
            Bitmap input2 = new Bitmap(Path.Combine(localFolder, image_bmp_1_big_black));
            Bitmap input3 = new Bitmap(Path.Combine(localFolder, image_bmp_1_big_red));
            Bitmap input4 = new Bitmap(Path.Combine(localFolder, image_bmp_1_big_green));

            Bitmap[][] inputArray = new Bitmap[2][];
            inputArray[0] = new Bitmap[2] {
                input1, input2
            };
            inputArray[1] = new Bitmap[2] {
                input3, input4
            };

            target.Combine(inputArray, 32, 32, true);
            target.Save(Path.Combine(localFolder, image_bmp_1_combineFail_out), ImageFormat.Bmp);
            target.Dispose();

            Bitmap original = new Bitmap(Path.Combine(localFolder, image_bmp_1_big));
            Bitmap output   = new Bitmap(Path.Combine(localFolder, image_bmp_1_combineFail_out));

            BitmapAssert.AreNotEqual(original, output, 10, "Written image should not be like the reference.");

            // cleanup - dispose of the bitmaps
            original.Dispose();
            output.Dispose();
            input1.Dispose();
            input2.Dispose();
            input3.Dispose();
            input4.Dispose();
        }
        public void CompareQuantizedImages()
        {
            ReportStart();
            _oq = new OctreeQuantizer(255, 8);
            for (int colourCount = 1; colourCount < 500; colourCount += 50)
            {
                Collection <Color> distinctColours;

                Bitmap original = MakeBitmap(new Size(50, 50), colourCount);
                distinctColours = ImageTools.GetDistinctColours(original);
                // Make sure the bitmap we've created has the number of colours we want
                Assert.AreEqual(colourCount, distinctColours.Count);

                Bitmap quantized = _oq.Quantize(original);
                BitmapAssert.AreEqual(original, quantized, 60,                  // TODO: this is a rather large tolerance
                                      colourCount + " colours");

                distinctColours = ImageTools.GetDistinctColours(quantized);
                int expectedColours = colourCount > 256 ? 256 : colourCount;
                // FIXME: 65-colour image is quantized down to 64 colours
                // TODO: Check for exact number of colours once Octree quantizer stops reducing colour depth too much
//				Assert.AreEqual( expectedColours, distinctColours.Count, colourCount + " colours" );
                Assert.LessOrEqual(distinctColours.Count, expectedColours, colourCount + " colours");
            }
            ReportEnd();
        }
        public void InterlaceTest()
        {
            ReportStart();
            _decoder = new GifDecoder(@"images\Interlaced.gif");
            _decoder.Decode();
            Assert.AreEqual(true, _decoder.Frames[0].ImageDescriptor.IsInterlaced);
            Bitmap expected = new Bitmap(@"images\Interlaced.bmp");
            Bitmap actual   = (Bitmap)_decoder.Frames[0].TheImage;

            BitmapAssert.AreEqual(expected, actual);
            ReportEnd();
        }
Exemple #5
0
 private void CompareFrames(string baseFileName)
 {
     for (int f = 0; f < _decoder.Frames.Count; f++)
     {
         string frameFileName  = baseFileName + ".frame " + f + ".bmp";
         Bitmap expectedBitmap = new Bitmap(frameFileName);
         Bitmap actualBitmap   = (Bitmap)_decoder.Frames[f].TheImage;
         BitmapAssert.AreEqual(expectedBitmap,
                               actualBitmap,
                               "frame " + f);
     }
 }
        public void TextureHandler_Bmp_ReadWrite()
        {
            TextureHandler t1 = new TextureHandler(Path.Combine(localFolder, image_bmp_1));

            t1.Save(Path.Combine(localFolder, image_bmp_1_out), ImageFormat.Bmp);
            t1.Dispose();

            Bitmap original = new Bitmap(Path.Combine(localFolder, image_bmp_1));
            Bitmap output   = new Bitmap(Path.Combine(localFolder, image_bmp_1_out));

            BitmapAssert.AreEqual(original, output, 2, "Written image should be as the original.");

            // cleanup - dispose of the bitmaps
            original.Dispose();
            output.Dispose();
        }
        private void ConstructorStreamNullGraphicControlExtensionTest(bool xmlDebugging)
        {
            _decoder = new GifDecoder(@"images\NoGraphicControlExtension.gif",
                                      xmlDebugging);
            _decoder.Decode();
            Assert.AreEqual(ErrorState.NoGraphicControlExtension,
                            _decoder.Frames[0].ErrorState);
            Bitmap expected = new Bitmap(@"images\NoGraphicControlExtension.bmp");
            Bitmap actual   = (Bitmap)_decoder.Frames[0].TheImage;

            BitmapAssert.AreEqual(expected, actual);

            if (xmlDebugging)
            {
                Assert.AreEqual(ExpectedDebugXml, _decoder.Frames[0].DebugXml);
            }
        }
        public void TextureHandler_Bmp_ResizeDown()
        {
            TextureHandler t1 = new TextureHandler(Path.Combine(localFolder, image_bmp_1));

            t1.Resize(8, 8, true);
            t1.Save(Path.Combine(localFolder, image_bmp_1_small_out), ImageFormat.Bmp);
            t1.Dispose();

            Bitmap original = new Bitmap(Path.Combine(localFolder, image_bmp_1_small));
            Bitmap output   = new Bitmap(Path.Combine(localFolder, image_bmp_1_small_out));

            BitmapAssert.AreEqual(original, output, 128, "Written image should be like the reference.");

            // cleanup - dispose of the bitmaps
            original.Dispose();
            output.Dispose();
        }
Exemple #9
0
        public void BitmapToPixbuf_Convert()
        {
            Bitmap source = new Bitmap(Path.Combine(localFolder, image_Source_1));

            Random number = new Random();

            image_Target_1 = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"tempmageconvert-" + number.Next(5000, 50000).ToString() + ".png");
            source.ToPixbuf().Save(image_Target_1, "png");

            Bitmap target = new Bitmap(Path.Combine(localFolder, image_Target_1));

            BitmapAssert.AreEqual(source, target, 10, "Source image should be resembling the new file");
            target.Dispose();
            source.Dispose();

            // output files
            AddOutputFile(Path.Combine(localFolder, image_Target_1), false);
        }
Exemple #10
0
        public void TextureHandler_Bmp_ResizeUp()
        {
            // RL: This is a stress test, if it doesn't pass, it's not the end of the world as
            // most video card/driver will handle the upscaling very differently.
            TextureHandler t1 = new TextureHandler(Path.Combine(localFolder, image_bmp_1));

            t1.Resize(32, 32, true);
            t1.Save(Path.Combine(localFolder, image_bmp_1_big_out), ImageFormat.Bmp);
            t1.Dispose();

            Bitmap original = new Bitmap(Path.Combine(localFolder, image_bmp_1_big));
            Bitmap output   = new Bitmap(Path.Combine(localFolder, image_bmp_1_big_out));

            BitmapAssert.AreEqual(original, output, 200, "Written image should be like the reference.");

            // cleanup - dispose of the bitmaps
            original.Dispose();
            output.Dispose();
        }
Exemple #11
0
        public void ToBitmapTest()
        {
            ReportStart();
            foreach (string file in _paletteFiles)
            {
                _actual = Palette.FromFile(file);
                Bitmap b = _actual.ToBitmap();

                string expectedBitmapFile
                    = file.Replace("ColourTables", "images/PaletteBitmaps").Replace(".act", ".bmp");
                if (File.Exists(expectedBitmapFile) == false)
                {
                    string message
                        = "Expected bitmap file "
                          + Path.GetFullPath(expectedBitmapFile)
                          + " not found";
                    throw new FileNotFoundException(message);
                }
                Bitmap expected = new Bitmap(expectedBitmapFile);
                BitmapAssert.AreEqual(expected, b, file);
            }
            ReportEnd();
        }
Exemple #12
0
        /// <summary>
        /// Tests the AnimatedGifEncoder and the encoded GIF file it produces
        /// using the supplied parameters as property values.
        /// </summary>
        private void TestAnimatedGifEncoder(ColourTableStrategy strategy,
                                            int colourQuality,
                                            Size logicalScreenSize)
        {
            _e = new AnimatedGifEncoder();

            // Check default properties set by constructor.
            Assert.AreEqual(ColourTableStrategy.UseGlobal,
                            _e.ColourTableStrategy,
                            "Colour table strategy set by constructor");
            Assert.AreEqual(10,
                            _e.SamplingFactor,
                            "Colour quantization quality set by constructor");
            Assert.AreEqual(Size.Empty,
                            _e.LogicalScreenSize,
                            "Logical screen size set by constructor");

            _e.ColourTableStrategy = strategy;
            _e.SamplingFactor      = colourQuality;
            _e.LogicalScreenSize   = logicalScreenSize;

            // Check property set/gets
            Assert.AreEqual(strategy,
                            _e.ColourTableStrategy,
                            "Colour table strategy property set/get");
            Assert.AreEqual(colourQuality,
                            _e.SamplingFactor,
                            "Colour quantization quality property set/get");
            Assert.AreEqual(logicalScreenSize,
                            _e.LogicalScreenSize,
                            "Logical screen size property get/set");

            foreach (GifFrame thisFrame in _frames)
            {
                _e.AddFrame(thisFrame);
            }

            StackTrace t = new StackTrace();
            StackFrame f = t.GetFrame(1);
            string     fileName
                = "Checks." + this.GetType().Name
                  + "." + f.GetMethod().Name + ".gif";

            _e.WriteToFile(fileName);

            Stream s = File.OpenRead(fileName);

            // global info
            CheckGifHeader(s);
            bool shouldHaveGlobalColourTable
                = (strategy == ColourTableStrategy.UseGlobal);
            LogicalScreenDescriptor lsd
                = CheckLogicalScreenDescriptor(s, shouldHaveGlobalColourTable);

            // Only check the global colour table if there should be one
            ColourTable gct = null;

            if (shouldHaveGlobalColourTable)
            {
                gct = CheckColourTable(s, lsd.GlobalColourTableSize);
            }

            CheckExtensionIntroducer(s);
            CheckAppExtensionLabel(s);
            CheckNetscapeExtension(s, 0);

            CheckFrame(s, gct, Bitmap1());
            CheckFrame(s, gct, Bitmap2());

            // end of image data
            CheckGifTrailer(s);
            CheckEndOfStream(s);
            s.Close();

            // Check the file using the decoder
            _d = new GifDecoder(fileName);
            _d.Decode();
            Assert.AreEqual(ErrorState.Ok,
                            _d.ConsolidatedState,
                            "Decoder consolidated state");
            Assert.AreEqual(2, _d.Frames.Count, "Decoder frame count");
            Assert.AreEqual(shouldHaveGlobalColourTable,
                            _d.LogicalScreenDescriptor.HasGlobalColourTable,
                            "Should have global colour table");
            Assert.AreEqual(logicalScreenSize,
                            _d.LogicalScreenDescriptor.LogicalScreenSize,
                            "Decoder logical screen size");

            BitmapAssert.AreEqual(Bitmap1(),
                                  (Bitmap)_d.Frames[0].TheImage,
                                  "frame 0");
            BitmapAssert.AreEqual(Bitmap2(),
                                  (Bitmap)_d.Frames[1].TheImage,
                                  "frame 1");

            bool shouldHaveLocalColourTable = !shouldHaveGlobalColourTable;

            Assert.AreEqual(shouldHaveLocalColourTable,
                            _d.Frames[0].ImageDescriptor.HasLocalColourTable,
                            "Frame 0 has local colour table");
            Assert.AreEqual(shouldHaveLocalColourTable,
                            _d.Frames[1].ImageDescriptor.HasLocalColourTable,
                            "Frame 0 has local colour table");
        }
Exemple #13
0
        public void WikipediaExampleTest()
        {
            ReportStart();
            _e = new AnimatedGifEncoder();
            GifFrame frame = new GifFrame(WikipediaExample.ExpectedBitmap);

            frame.Delay = WikipediaExample.DelayTime;
            _e.AddFrame(frame);

            // TODO: some way of creating/testing a UseLocal version of WikipediaExample
            string fileName = "WikipediaExampleUseGlobal.gif";

            _e.WriteToFile(fileName);
            Stream s = File.OpenRead(fileName);

            int code;

            // check GIF header
            GifHeader gh = new GifHeader(s);

            Assert.AreEqual(ErrorState.Ok, gh.ConsolidatedState);

            // check logical screen descriptor
            LogicalScreenDescriptor lsd = new LogicalScreenDescriptor(s);

            Assert.AreEqual(ErrorState.Ok, lsd.ConsolidatedState);
            WikipediaExample.CheckLogicalScreenDescriptor(lsd);

            // read global colour table
            ColourTable gct
                = new ColourTable(s, WikipediaExample.GlobalColourTableSize);

            Assert.AreEqual(ErrorState.Ok, gct.ConsolidatedState);
            // cannot compare global colour table as different encoders will
            // produce difference colour tables.
//			WikipediaExample.CheckGlobalColourTable( gct );

            // check for extension introducer
            code = ExampleComponent.CallRead(s);
            Assert.AreEqual(GifComponent.CodeExtensionIntroducer, code);

            // check for app extension label
            code = ExampleComponent.CallRead(s);
            Assert.AreEqual(GifComponent.CodeApplicationExtensionLabel, code);

            // check netscape extension
            ApplicationExtension ae = new ApplicationExtension(s);

            Assert.AreEqual(ErrorState.Ok, ae.ConsolidatedState);
            NetscapeExtension ne = new NetscapeExtension(ae);

            Assert.AreEqual(ErrorState.Ok, ne.ConsolidatedState);
            Assert.AreEqual(0, ne.LoopCount);

            // check for extension introducer
            code = ExampleComponent.CallRead(s);
            Assert.AreEqual(GifComponent.CodeExtensionIntroducer, code);

            // check for gce label
            code = ExampleComponent.CallRead(s);
            Assert.AreEqual(GifComponent.CodeGraphicControlLabel, code);

            // check graphic control extension
            GraphicControlExtension gce = new GraphicControlExtension(s);

            Assert.AreEqual(ErrorState.Ok, gce.ConsolidatedState);
            WikipediaExample.CheckGraphicControlExtension(gce);

            // check for image separator
            code = ExampleComponent.CallRead(s);
            Assert.AreEqual(GifComponent.CodeImageSeparator, code);

            // check for image descriptor
            ImageDescriptor id = new ImageDescriptor(s);

            Assert.AreEqual(ErrorState.Ok, id.ConsolidatedState);
            WikipediaExample.CheckImageDescriptor(id);

            // read, decode and check image data
            // Cannot compare encoded LZW data directly as different encoders
            // will create different colour tables, so even if the bitmaps are
            // identical, the colour indices will be different
            int pixelCount = WikipediaExample.FrameSize.Width
                             * WikipediaExample.FrameSize.Height;
            TableBasedImageData tbid = new TableBasedImageData(s, pixelCount);

            for (int y = 0; y < WikipediaExample.LogicalScreenSize.Height; y++)
            {
                for (int x = 0; x < WikipediaExample.LogicalScreenSize.Width; x++)
                {
                    int i = (y * WikipediaExample.LogicalScreenSize.Width) + x;
                    Assert.AreEqual(WikipediaExample.ExpectedBitmap.GetPixel(x, y),
                                    gct[tbid.Pixels[i]],
                                    "X: " + x + ", Y: " + y);
                }
            }

            // Check for block terminator after image data
            code = ExampleComponent.CallRead(s);
            Assert.AreEqual(0x00, code);

            // check for GIF trailer
            code = ExampleComponent.CallRead(s);
            Assert.AreEqual(GifComponent.CodeTrailer, code);

            // check we're at the end of the stream
            code = ExampleComponent.CallRead(s);
            Assert.AreEqual(-1, code);
            s.Close();

            _d = new GifDecoder(fileName);
            _d.Decode();
            Assert.AreEqual(ErrorState.Ok, _d.ConsolidatedState);
            BitmapAssert.AreEqual(WikipediaExample.ExpectedBitmap,
                                  (Bitmap)_d.Frames[0].TheImage,
                                  "");
            ReportEnd();
        }
        internal static void CheckImage(Image image)
        {
            Bitmap actual = (Bitmap)image;

            BitmapAssert.AreEqual(ExpectedBitmap, actual);
        }