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); } } } } } }
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); }
public OrderedDitherConverter(BmpImage data, int DitherMatrixPower) : base(data) { ditherMatrix = Dither.GenerateDitherMatrix(DitherMatrixPower); ditherMatrixSize = (int)Math.Pow(2, DitherMatrixPower); }
public OrderedDitherConverter(BmpImage data) : base(data) { ditherMatrix = Dither.GenerateDitherMatrix(1); ditherMatrixSize = 2; }
public void TestThrowsWhenArgumentInvalid() { Assert.Throws <ArgumentOutOfRangeException>(() => Dither.GenerateDitherMatrix(0)); }