Ejemplo n.º 1
0
        public void TestRandomDataLength()
        {
            Random rd     = new Random();
            Int32  width  = rd.Next();
            Int32  height = rd.Next();

            width  %= 2160;
            height %= 3840;
            ColorGridData cgd = new ColorGridData(width, height);

            cgd.generate_random_color_grid();
            Assert.AreEqual(width * height * 4, cgd.random_data.Length);
        }
Ejemplo n.º 2
0
        public void TestRandomDataValue()
        {
            Random rd     = new Random();
            Int32  width  = rd.Next();
            Int32  height = rd.Next();

            width  %= 2160;
            height %= 3840;
            ColorGridData cgd1 = new ColorGridData(width, height);
            ColorGridData cgd2 = new ColorGridData(width, height);

            cgd1.generate_random_color_grid();
            cgd2.generate_random_color_grid();
            Assert.AreNotEqual(cgd1.random_data, cgd2.random_data);
        }
Ejemplo n.º 3
0
        public void TestHUESorting()
        {
            Int32 width  = 600;
            Int32 height = 600;

            Byte[]    bgr = new Byte[3], sorted_data;
            Stopwatch stopwatch = new Stopwatch();
            long      max_time_elapse = 2 * 1000;
            Int32     x = 0, y = 0, pixel_index = 0;
            float     previous_hue = 0, this_hue = 0;

            ColorGridData.color_align align = ColorGridData.color_align.left;


            ColorGridData cgd = new ColorGridData(width, height);

            cgd.generate_random_color_grid();

            stopwatch.Start();
            cgd.color_sort_by_hue(align, 360);
            stopwatch.Stop();

            if (max_time_elapse < stopwatch.ElapsedMilliseconds)
            {
                Assert.Fail("Spent " + stopwatch.ElapsedMilliseconds + " ms on sorting," + " beyond max [" + max_time_elapse + "] ms");
            }

            sorted_data = cgd.sorted_data;

            Assert.AreEqual(cgd.random_data.Length, cgd.sorted_data.Length);

            switch (align)
            {
            case ColorGridData.color_align.top:
            case ColorGridData.color_align.left:
                x = 0;
                y = 0;
                break;

            case ColorGridData.color_align.right:
                x = width - 1;
                y = 0;
                break;

            case ColorGridData.color_align.buttom:
                x = 0;
                y = height - 1;
                break;

            default:
                return;
            }

            while ((x >= 0) && (x < width) && (y >= 0) && (y < height))
            {
                pixel_index = y * width + x;
                this_hue    = this.TestCalculateHUE(sorted_data[pixel_index * 4], sorted_data[pixel_index * 4 + 1], sorted_data[pixel_index * 4 + 2]);
                if (this_hue < previous_hue)
                {
                    Assert.Fail("wrong sorting by HUE at point [" + x + "," + y + "]");
                }
                previous_hue = this_hue;
                switch (align)
                {
                case ColorGridData.color_align.left:
                    y++;
                    if (y == height)
                    {
                        x++;
                        y = 0;
                    }
                    break;

                case ColorGridData.color_align.top:
                    x++;
                    if (x == width)
                    {
                        y++;
                        x = 0;
                    }
                    break;

                case ColorGridData.color_align.right:
                    y++;
                    if (y == height)
                    {
                        x--;
                        y = 0;
                    }
                    break;

                case ColorGridData.color_align.buttom:
                    x++;
                    if (x == width)
                    {
                        y--;
                        x = 0;
                    }
                    break;

                default:
                    return;
                }
            }
        }