Esempio n. 1
0
        protected override void ConvertBitmapData()
        {
            int scale = (int)Math.Pow(2, Power);

            Image.Data.Width  = Image.Data.Width * scale;
            Image.Data.Height = Image.Data.Height * scale;
            Image.Data.Data   = new byte[Image.Data.GetRealSize()];

            int[,] ditherMatrix = Dither.GenerateDitherMatrix(Power);

            for (int i = 0; i < oldData.Width; i++)
            {
                for (int k = 0; k < oldData.Height; k++)
                {
                    byte oldValue  = oldData.Get8BitDataAt(i, k);
                    int  threshold = (int)((double)oldValue / 255 * scale);
                    for (int m = 0; m < scale; m++)
                    {
                        for (int n = 0; n < scale; n++)
                        {
                            if (threshold >= ditherMatrix[m, n])
                            {
                                Image.Data.Set1BitDataAt(i * scale + m, k * scale + n, true);
                            }
                            else
                            {
                                Image.Data.Set1BitDataAt(i * scale + m, k * scale + n, false);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        public void TestGenerateDitherMatrix()
        {
            var matrix = Dither.GenerateDitherMatrix(1);

            Assert.Equal(new int[2, 2]
            {
                { 0, 2 },
                { 3, 1 }
            }, matrix);
            matrix = Dither.GenerateDitherMatrix(2);
            Assert.Equal(new int[4, 4]
            {
                { 0, 8, 2, 10 },
                { 12, 4, 14, 6 },
                { 3, 11, 1, 9 },
                { 15, 7, 13, 5 }
            }, matrix);
        }
Esempio n. 3
0
 public OrderedDitherConverter(BmpImage data, int DitherMatrixPower) : base(data)
 {
     ditherMatrix     = Dither.GenerateDitherMatrix(DitherMatrixPower);
     ditherMatrixSize = (int)Math.Pow(2, DitherMatrixPower);
 }
Esempio n. 4
0
 public OrderedDitherConverter(BmpImage data) : base(data)
 {
     ditherMatrix     = Dither.GenerateDitherMatrix(1);
     ditherMatrixSize = 2;
 }
Esempio n. 5
0
 public void TestThrowsWhenArgumentInvalid()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => Dither.GenerateDitherMatrix(0));
 }