public void SetI_Coord_ShouldCorrectlySetPixel(int x, int y, int color)
        {
            FastBitmap bmp = FastBmp;

            bmp.SetI(x, y, color);
            Assert.Equal(color, bmp.GetI(x, y));
        }
        private static Bitmap GrayDiff(Bitmap b1, Bitmap b2)
        {
            var res = new Bitmap(b1.Width, b1.Height);

            using (var fb1 = new FastBitmap(b1))
                using (var fb2 = new FastBitmap(b2))
                    using (var fb3 = new FastBitmap(res))
                    {
                        for (var i = 0; i < fb1.Count; i++)
                        {
                            var diff = (byte)Math.Abs(fb1.GetI(i).r - fb2.GetI(i).r);
                            fb3.SetI(i, (diff, diff, diff));
                        }
                    }

            var(min, max) = ((byte)255, (byte)0);
            FastBitmap.ForEach(res, cl =>
            {
                if (cl.r > max)
                {
                    max = cl.r;
                }
                if (cl.r < min)
                {
                    min = cl.r;
                }
            });

            return(FastBitmap.Select(res, cl =>
            {
                var t = (byte)((cl.r - min) / (double)(max - min) * 255);
                return (t, t, t);
            }));;
        }
        public void TrySetI_Coord_ShouldCorrectlySetPixel(int x, int y, int color, bool expected)
        {
            FastBitmap bmp    = FastBmp;
            bool       result = bmp.TrySetI(x, y, color);

            Assert.Equal(expected, result);
            Assert.Equal(color, expected ? bmp.GetI(x, y) : color);
        }
        public void Write_ShouldWriteFromBuffer(int[] buffer, int offset, int count, int position, int expectedWrite)
        {
            int write = FastBmp.Write(buffer, offset, count, position);

            Assert.Equal(expectedWrite, write);
            for (int i = 0; i < expectedWrite; i++)
            {
                Assert.Equal(buffer[i + offset], FastBmp.GetI(i + position));
            }
        }
        public void GetI_ShouldThrowException(int index)
        {
            FastBitmap bmp = FastBmp;

            Assert.Throws <IndexOutOfRangeException>(() => bmp.GetI(index));
        }
        public void GetI_ShouldReturnCorrectValue(int index, int expected)
        {
            FastBitmap bmp = FastBmp;

            Assert.Equal(expected, bmp.GetI(index));
        }
        public void GetI_Coord_ShouldThrowException(int x, int y)
        {
            FastBitmap bmp = FastBmp;

            Assert.Throws <IndexOutOfRangeException>(() => bmp.GetI(x, y));
        }
        public void GetI_Coord_ShouldReturnCorrectValue(int x, int y, int expected)
        {
            FastBitmap bmp = FastBmp;

            Assert.Equal(expected, bmp.GetI(x, y));
        }
Beispiel #9
0
        public static void Main(string[] args)
        {
            Console.WriteLine("FastBitmap (v1.2.0) Benchmarking App");
            Console.WriteLine("------------------------------------------------");

            //
            // Single-Core Passthrough Benchmarks
            //
            BenchmarkTest pt = new BenchmarkTest
            {
                Name           = "Single-Core Passthrough Benchmark",
                IterationCount = 3
            };

            // System.Drawing.Bitmap Coord Benchmark
            pt.AddBenchmark("SysBitmap Coord", () =>
            {
                using (Bitmap src = new Bitmap(Image.FromFile("image.jpg")))
                    using (Bitmap dst = new Bitmap(src.Width, src.Height))
                    {
                        Stopwatch sw = new Stopwatch();
                        sw.Start();
                        for (int x = 0; x < dst.Width; x++)
                        {
                            for (int y = 0; y < dst.Height; y++)
                            {
                                dst.SetPixel(x, y, src.GetPixel(x, y));
                            }
                        }
                        sw.Stop();

                        dst.Save("SystemBitmap.jpg");
                        return(src.Width * src.Height / sw.Elapsed.TotalSeconds);
                    }
            });

            // FastBitmap Coord Benchmark
            pt.AddBenchmark("FastBitmap Coord", () =>
            {
                using (FastBitmap src = FastBitmap.FromFile("image.jpg"))
                    using (FastBitmap dst = new FastBitmap(src.Width, src.Height))
                    {
                        Stopwatch sw = new Stopwatch();
                        sw.Start();
                        for (int x = 0; x < dst.Width; x++)
                        {
                            for (int y = 0; y < dst.Height; y++)
                            {
                                dst.Set(x, y, src.Get(x, y));
                            }
                        }
                        sw.Stop();

                        dst.Save("FastBitmapCoord.jpg");
                        return(src.Length / sw.Elapsed.TotalSeconds);
                    }
            });

            // FastBitmap Index Benchmark
            pt.AddBenchmark("FastBitmap Index", () =>
            {
                using (FastBitmap src = FastBitmap.FromFile("image.jpg"))
                    using (FastBitmap dst = new FastBitmap(src.Width, src.Height))
                    {
                        Stopwatch sw = new Stopwatch();
                        sw.Start();
                        for (int i = 0; i < dst.Length; i++)
                        {
                            dst.Set(i, src.Get(i));
                        }
                        sw.Stop();

                        dst.Save("FastBitmapIndex.jpg");
                        return(src.Length / sw.Elapsed.TotalSeconds);
                    }
            });

            // FastBitmap Int32 Coord Benchmark
            pt.AddBenchmark("FastBitmap Int32 Coord", () =>
            {
                using (FastBitmap src = FastBitmap.FromFile("image.jpg"))
                    using (FastBitmap dst = new FastBitmap(src.Width, src.Height))
                    {
                        Stopwatch sw = new Stopwatch();
                        sw.Start();
                        for (int x = 0; x < dst.Width; x++)
                        {
                            for (int y = 0; y < dst.Height; y++)
                            {
                                dst.SetI(x, y, src.GetI(x, y));
                            }
                        }
                        sw.Stop();

                        dst.Save("FastBitmapInt32Coord.jpg");
                        return(src.Length / sw.Elapsed.TotalSeconds);
                    }
            });

            // FastBitmap Int32 Index Benchmark
            pt.AddBenchmark("FastBitmap Int32 Index", () =>
            {
                using (FastBitmap src = FastBitmap.FromFile("image.jpg"))
                    using (FastBitmap dst = new FastBitmap(src.Width, src.Height))
                    {
                        Stopwatch sw = new Stopwatch();
                        sw.Start();
                        for (int i = 0; i < dst.Length; i++)
                        {
                            dst.SetI(i, src.GetI(i));
                        }
                        sw.Stop();

                        dst.Save("FastBitmapInt32Index.jpg");
                        return(src.Length / sw.Elapsed.TotalSeconds);
                    }
            });

            // Run Passthrough
            pt.Run();

            // Render Graph
            FastBitmap graph = pt.DrawGraph();

            graph.Save("graph.png", ImageFormat.Png);
            graph.Dispose();

            // Finished.
            Console.Write("\nAll Benchmarks Completed");
            Console.Read();
        }