public void ApplyColorInversionTest() { // Input are expected are provided as resources, dithered is what // we are testing Bitmap input, inverted, expected; input = Properties.Resources.white_bitmap; var path = Path.Combine(baseDir, "white_inverse_test.bmp"); input.Save(path); using (var logo = new PrinterImage(path)) { logo.Resize(input.Width, 0, true); Assert.IsFalse(logo.IsInverted); logo.ApplyColorInversion(); inverted = logo.ImageData.ToBitmap(); expected = Properties.Resources.black_bitmap; // White should ivnert to black Assert.IsTrue(ImageTestHelpers.CompareMemCmp(expected, inverted)); Assert.True(logo.IsInverted); // Flip back to white, test that the inversion flag is cleared logo.ApplyColorInversion(); Assert.IsFalse(logo.IsInverted); }; }
public void BitmapImageToBitmapTest() { var bmps = new List <Bitmap>(); bmps.Add(Properties.Resources.gray_bitmap); bmps.Add(Properties.Resources.white_bitmap); bmps.Add(Properties.Resources.black_bitmap); bmps.Add(Properties.Resources.red_bitmap); bmps.Add(Properties.Resources.green_bitmap); bmps.Add(Properties.Resources.blue_bitmap); foreach (var inbmp in bmps) { using (var memory = new MemoryStream()) { inbmp.Save(memory, ImageFormat.Png); memory.Position = 0; var id = new BitmapImage(); id.BeginInit(); id.StreamSource = memory; id.CacheOption = BitmapCacheOption.OnLoad; id.EndInit(); Assert.IsTrue(ImageTestHelpers.CompareMemCmp(inbmp, id.ToBitmap())); } } }
public void BitmapToBufferTest() { var inbmp = Properties.Resources.gray_bitmap; var expectedBuff = ImageTestHelpers.BGRAGenerator(new byte[] { 128, 128, 128, 255 }, inbmp.Height * inbmp.Width); Assert.AreEqual(ImageConvertResults.Success, ImageTestHelpers.TestBitmapConversion(inbmp, expectedBuff)); inbmp = Properties.Resources.white_bitmap; expectedBuff = ImageTestHelpers.BGRAGenerator(new byte[] { 255, 255, 255, 255 }, inbmp.Height * inbmp.Width); Assert.AreEqual(ImageConvertResults.Success, ImageTestHelpers.TestBitmapConversion(inbmp, expectedBuff)); inbmp = Properties.Resources.black_bitmap; expectedBuff = ImageTestHelpers.BGRAGenerator(new byte[] { 0, 0, 0, 255 }, inbmp.Height * inbmp.Width); Assert.AreEqual(ImageConvertResults.Success, ImageTestHelpers.TestBitmapConversion(inbmp, expectedBuff)); inbmp = Properties.Resources.red_bitmap; expectedBuff = ImageTestHelpers.BGRAGenerator(new byte[] { 0, 0, 255, 255 }, inbmp.Height * inbmp.Width); Assert.AreEqual(ImageConvertResults.Success, ImageTestHelpers.TestBitmapConversion(inbmp, expectedBuff)); inbmp = Properties.Resources.green_bitmap; expectedBuff = ImageTestHelpers.BGRAGenerator(new byte[] { 0, 255, 0, 255 }, inbmp.Height * inbmp.Width); Assert.AreEqual(ImageConvertResults.Success, ImageTestHelpers.TestBitmapConversion(inbmp, expectedBuff)); inbmp = Properties.Resources.blue_bitmap; expectedBuff = ImageTestHelpers.BGRAGenerator(new byte[] { 255, 0, 0, 255 }, inbmp.Height * inbmp.Width); Assert.AreEqual(ImageConvertResults.Success, ImageTestHelpers.TestBitmapConversion(inbmp, expectedBuff)); }
public void GetDithererFloydSteinbergTest() { bool debugSave = true; // Input are expected are provided as resources, dithered is what // we are testing Bitmap input, dithered, expected; input = Properties.Resources.gray_bitmap; expected = Properties.Resources.gray_floydsteinbergs; dithered = DitherFactory.GetDitherer(Algorithms.FloydSteinberg).GenerateDithered(input); if (debugSave) { expected.Save(Path.Combine(baseDir, "gray_floydsteinbergs.bmp")); dithered.Save(Path.Combine(baseDir, "actual_FloydSteinbergs.bmp")); } Assert.IsTrue(ImageTestHelpers.CompareMemCmp(expected, dithered)); }
public void BitmapInvertColorChannelsTest() { var inbmp = Properties.Resources.gray_bitmap; var expectedBuff = ImageTestHelpers.BGRAGenerator(new byte[] { 128, 128, 128, 255 }, inbmp.Height * inbmp.Width); inbmp.InvertColorChannels(); var actualBuff = inbmp.ToBuffer(); Assert.AreEqual(expectedBuff, actualBuff); inbmp = Properties.Resources.white_bitmap; expectedBuff = ImageTestHelpers.BGRAGenerator(new byte[] { 0, 0, 0, 255 }, inbmp.Height * inbmp.Width); inbmp.InvertColorChannels(); actualBuff = inbmp.ToBuffer(); Assert.AreEqual(expectedBuff, actualBuff); inbmp = Properties.Resources.black_bitmap; expectedBuff = ImageTestHelpers.BGRAGenerator(new byte[] { 255, 255, 255, 255 }, inbmp.Height * inbmp.Width); inbmp.InvertColorChannels(); actualBuff = inbmp.ToBuffer(); Assert.AreEqual(expectedBuff, actualBuff); inbmp = Properties.Resources.red_bitmap; expectedBuff = ImageTestHelpers.BGRAGenerator(new byte[] { 255, 255, 0, 255 }, inbmp.Height * inbmp.Width); inbmp.InvertColorChannels(); actualBuff = inbmp.ToBuffer(); Assert.AreEqual(expectedBuff, actualBuff); inbmp = Properties.Resources.green_bitmap; expectedBuff = ImageTestHelpers.BGRAGenerator(new byte[] { 255, 0, 255, 255 }, inbmp.Height * inbmp.Width); inbmp.InvertColorChannels(); actualBuff = inbmp.ToBuffer(); Assert.AreEqual(expectedBuff, actualBuff); inbmp = Properties.Resources.blue_bitmap; expectedBuff = ImageTestHelpers.BGRAGenerator(new byte[] { 0, 255, 255, 255 }, inbmp.Height * inbmp.Width); inbmp.InvertColorChannels(); actualBuff = inbmp.ToBuffer(); Assert.AreEqual(expectedBuff, actualBuff); }