public void RoundTripDataSimpleBits() { var srcData = new byte[] { 1, 2, 3, 4 }; var data = new BitArray(srcData); var bmp = _FilledSquare(Color.White, 4, 4); var pixels = _imageMaker.PixelsFromImage(bmp); var blended = _imageMaker.InjectData(pixels, data, bmp.Width, bmp.Height); var resultData = _dataMaker.ExtractData(blended, bmp.Width, bmp.Height); Assert.AreEqual(srcData.Length, resultData.Length); for (int i = 0; i < srcData.Length; i++) { Assert.AreEqual(srcData[i], resultData[i]); } }
public void RoundTripDataReadsHeader() { var testData = new byte[] { 1, 2, 3, 4 }; var dataToInject = new BitArray(testData); var bmp = _FilledSquare(Color.White, 10, 10); var whitePixels = _imageMaker.PixelsFromImage(bmp); var imageMaker = new ImageMaker(); imageMaker.Header.BitsPerPixel = 2; var dataMaker = new DataMaker(); dataMaker.Header.BitsPerPixel = -1; var injectedPixels = imageMaker.InjectData(whitePixels, dataToInject, 10, 10); byte[] extractedData = dataMaker.ExtractData(injectedPixels, 10, 10); Assert.AreEqual(testData, extractedData); }
public void RoundTripDataWritablePixels() { var testData = new byte[] { 213, 214, 215, 216 }; var dataToInject = new BitArray(testData); var bmp = _FilledSquare(Color.White, 10, 10); var whitePixels = _imageMaker.PixelsFromImage(bmp); var imageMaker = new ImageMaker(); imageMaker.Header.BitsPerPixel = 8; imageMaker.Header.SetWritableRange(4, 4, 8, 8); var dataMaker = new DataMaker(); var injectedPixels = imageMaker.InjectData(whitePixels, dataToInject, 10, 10); Dump(injectedPixels, "Injected pixels"); byte[] extractedData = dataMaker.ExtractData(injectedPixels, 10, 10); Assert.AreEqual(testData, extractedData); }