public void ThreeTimesThreeGrayscaleAdditiveToSubtractive() { var additiveHeader = new NetpbmHeader <byte>(ImageType.PAM, 3, 3, 1, new[] { Component.White }, 255); var additive = new NetpbmImage8(additiveHeader, new[] { new byte[] { 12, 34, 56 }, new byte[] { 78, 90, 12 }, new byte[] { 34, 56, 78 } }); var canon = new Canonicalizer(); var subtractive = canon.Canonicalize(additive, GrayscaleConversion.WhiteToBlack); subtractive.LoadData(); Assert.Equal(3, subtractive.Header.Width); Assert.Equal(3, subtractive.Header.Height); Assert.Equal(255, subtractive.Header.HighestComponentValue); Assert.Equal(1, subtractive.Header.Components.Count); Assert.Equal(Component.Black, subtractive.Header.Components[0]); Assert.NotNull(subtractive.LoadedNativeRows); Assert.Equal(3, subtractive.LoadedNativeRows.Count); Assert.Equal(3, subtractive.LoadedNativeRows[0].Count); Assert.Equal(3, subtractive.LoadedNativeRows[1].Count); Assert.Equal(3, subtractive.LoadedNativeRows[2].Count); Assert.Equal(243, subtractive.LoadedNativeRows[0][0]); Assert.Equal(221, subtractive.LoadedNativeRows[0][1]); Assert.Equal(199, subtractive.LoadedNativeRows[0][2]); Assert.Equal(177, subtractive.LoadedNativeRows[1][0]); Assert.Equal(165, subtractive.LoadedNativeRows[1][1]); Assert.Equal(243, subtractive.LoadedNativeRows[1][2]); Assert.Equal(221, subtractive.LoadedNativeRows[2][0]); Assert.Equal(199, subtractive.LoadedNativeRows[2][1]); Assert.Equal(177, subtractive.LoadedNativeRows[2][2]); }
public void SinglePixelBitmapTooManyRows() { var header = new NetpbmHeader <byte>(ImageType.PBM, 1, 1, 1, new[] { Component.Black }, 1); Assert.Throws <InvalidDataException>(() => { var img = new NetpbmImage8(header, new[] { new byte[] { 0 }, new byte[] { 0 } }); img.LoadData(); }); }
public void TwoTimesTwoGrayscaleTooFewPixelsInRow() { var header = new NetpbmHeader <byte>(ImageType.PGM, 2, 2, 1, new[] { Component.Black }, 127); Assert.Throws <InvalidDataException>(() => { var img = new NetpbmImage8(header, new[] { new byte[] { 0, 64 }, new byte[] { 127 } }); img.LoadData(); }); }
public void ThreeTimesThreeRGBTooFewRows() { var header = new NetpbmHeader <byte>(ImageType.PPM, 3, 3, 1, new[] { Component.Red, Component.Green, Component.Blue }, 255); Assert.Throws <InvalidDataException>(() => { var img = new NetpbmImage8( header, new[] { new byte[] { 255, 0, 0, 255, 0, 0, 255, 0, 0 }, new byte[] { 0, 255, 0, 0, 255, 0, 0, 255 } }); img.LoadData(); }); }
public void ThreeTimesThreeRGBOutOfRangePixel() { var header = new NetpbmHeader <byte>(ImageType.PPM, 3, 3, 1, new[] { Component.Red, Component.Green, Component.Blue }, 127); Assert.Throws <InvalidDataException>(() => { var img = new NetpbmImage8( header, new[] { new byte[] { 127, 0, 0, 127, 0, 0, 127, 0, 0 }, new byte[] { 0, 127, 0, 0, 127, 0, 0, 127 }, new byte[] { 0, 0, 127, 0, 0, 127, 0, 0, 128 } }); img.LoadData(); }); }
public void SinglePixelBitmapSubtractiveToAdditive() { var additiveHeader = new NetpbmHeader <byte>(ImageType.PAM, 1, 1, 1, new[] { Component.White }, 1); var additive = new NetpbmImage8(additiveHeader, new[] { new byte[] { 1 } }); var canon = new Canonicalizer(); var subtractive = canon.Canonicalize(additive, GrayscaleConversion.WhiteToBlack); subtractive.LoadData(); Assert.Equal(1, subtractive.Header.Width); Assert.Equal(1, subtractive.Header.Height); Assert.Equal(1, subtractive.Header.HighestComponentValue); Assert.Equal(1, subtractive.Header.Components.Count); Assert.Equal(Component.Black, subtractive.Header.Components[0]); Assert.NotNull(subtractive.LoadedNativeRows); Assert.Equal(1, subtractive.LoadedNativeRows.Count); Assert.Equal(1, subtractive.LoadedNativeRows[0].Count); Assert.Equal(0, subtractive.LoadedNativeRows[0][0]); }
public void ValidSinglePixelBitmap() { var hdr = new NetpbmHeader <byte>(ImageType.PBM, 1, 1, 1, new[] { Component.Black }, 1); var img = new NetpbmImage8(hdr, new[] { new byte[] { 1 } }); img.LoadData(); Assert.Equal(1, img.Header.Width); Assert.Equal(1, img.Header.Height); Assert.Equal(1, img.Header.HighestComponentValue); Assert.Equal(1, img.Header.Components.Count); Assert.Equal(Component.Black, img.Header.Components[0]); Assert.Equal(1, img.LoadedNativeRows.Count); Assert.Equal(1, img.LoadedNativeRows[0].Count); Assert.Equal(1, img.LoadedNativeRows[0][0]); Assert.Equal(1, img.GetNativePixel(0, 0).Count); Assert.Equal(1, img.GetNativePixel(0, 0)[0]); Assert.Equal(1, img.GetScaledPixel(0, 0).Count); Assert.Equal(1.0, img.GetScaledPixel(0, 0)[0]); Assert.Throws <ArgumentOutOfRangeException>("x", () => { img.GetNativePixel(1, 0); }); Assert.Throws <ArgumentOutOfRangeException>("x", () => { img.GetScaledPixel(1, 0); }); Assert.Throws <ArgumentOutOfRangeException>("y", () => { img.GetNativePixel(0, 1); }); Assert.Throws <ArgumentOutOfRangeException>("y", () => { img.GetScaledPixel(0, 1); }); }
public void ValidTwoTimesTwoGrayscale() { var header = new NetpbmHeader <byte>(ImageType.PGM, 2, 2, 1, new[] { Component.Black }, 127); var img = new NetpbmImage8(header, new[] { new byte[] { 0, 64 }, new byte[] { 127, 64 } }); img.LoadData(); Assert.Equal(2, img.Header.Width); Assert.Equal(2, img.Header.Height); Assert.Equal(127, img.Header.HighestComponentValue); Assert.Equal(1, img.Header.Components.Count); Assert.Equal(Component.Black, img.Header.Components[0]); Assert.Equal(2, img.LoadedNativeRows.Count); Assert.Equal(2, img.LoadedNativeRows[0].Count); Assert.Equal(2, img.LoadedNativeRows[1].Count); Assert.Equal(0, img.LoadedNativeRows[0][0]); Assert.Equal(64, img.LoadedNativeRows[0][1]); Assert.Equal(127, img.LoadedNativeRows[1][0]); Assert.Equal(64, img.LoadedNativeRows[1][1]); Assert.Equal(1, img.GetNativePixel(0, 0).Count); Assert.Equal(1, img.GetScaledPixel(0, 0).Count); Assert.Equal(0, img.GetNativePixel(0, 0)[0]); Assert.Equal(0.0, img.GetScaledPixel(0, 0)[0]); Assert.Equal(1, img.GetNativePixel(1, 0).Count); Assert.Equal(1, img.GetScaledPixel(1, 0).Count); Assert.Equal(64, img.GetNativePixel(1, 0)[0]); Assert.InRange(img.GetScaledPixel(1, 0)[0], 0.49, 0.51); Assert.Equal(1, img.GetNativePixel(0, 1).Count); Assert.Equal(1, img.GetScaledPixel(0, 1).Count); Assert.Equal(127, img.GetNativePixel(0, 1)[0]); Assert.Equal(1.0, img.GetScaledPixel(0, 1)[0]); Assert.Equal(1, img.GetNativePixel(1, 1).Count); Assert.Equal(1, img.GetScaledPixel(1, 1).Count); Assert.Equal(64, img.GetNativePixel(1, 1)[0]); Assert.InRange(img.GetScaledPixel(1, 1)[0], 0.49, 0.51); Assert.Throws <ArgumentOutOfRangeException>("x", () => { img.GetNativePixel(2, 0); }); Assert.Throws <ArgumentOutOfRangeException>("x", () => { img.GetScaledPixel(2, 0); }); Assert.Throws <ArgumentOutOfRangeException>("y", () => { img.GetNativePixel(0, 2); }); Assert.Throws <ArgumentOutOfRangeException>("y", () => { img.GetScaledPixel(0, 2); }); }
public void ValidThreeTimesThreeRGB() { var header = new NetpbmHeader <byte>(ImageType.PPM, 3, 3, 1, new[] { Component.Red, Component.Green, Component.Blue }, 255); var img = new NetpbmImage8( header, new[] { new byte[] { 255, 0, 0, 255, 0, 0, 255, 0, 0 }, new byte[] { 0, 255, 0, 0, 255, 0, 0, 255, 0 }, new byte[] { 0, 0, 255, 0, 0, 255, 0, 0, 255 } }); img.LoadData(); Assert.Equal(3, img.Header.Width); Assert.Equal(3, img.Header.Height); Assert.Equal(255, img.Header.HighestComponentValue); Assert.Equal(3, img.Header.Components.Count); Assert.Equal(Component.Red, img.Header.Components[0]); Assert.Equal(Component.Green, img.Header.Components[1]); Assert.Equal(Component.Blue, img.Header.Components[2]); Assert.Equal(3, img.LoadedNativeRows.Count); Assert.Equal(9, img.LoadedNativeRows[0].Count); Assert.Equal(9, img.LoadedNativeRows[1].Count); Assert.Equal(255, img.LoadedNativeRows[0][0]); Assert.Equal(0, img.LoadedNativeRows[0][1]); Assert.Equal(0, img.LoadedNativeRows[0][2]); Assert.Equal(255, img.LoadedNativeRows[0][3]); Assert.Equal(0, img.LoadedNativeRows[0][4]); Assert.Equal(0, img.LoadedNativeRows[0][5]); Assert.Equal(255, img.LoadedNativeRows[0][6]); Assert.Equal(0, img.LoadedNativeRows[0][7]); Assert.Equal(0, img.LoadedNativeRows[0][8]); Assert.Equal(0, img.LoadedNativeRows[1][0]); Assert.Equal(255, img.LoadedNativeRows[1][1]); Assert.Equal(0, img.LoadedNativeRows[1][2]); Assert.Equal(0, img.LoadedNativeRows[1][3]); Assert.Equal(255, img.LoadedNativeRows[1][4]); Assert.Equal(0, img.LoadedNativeRows[1][5]); Assert.Equal(0, img.LoadedNativeRows[1][6]); Assert.Equal(255, img.LoadedNativeRows[1][7]); Assert.Equal(0, img.LoadedNativeRows[1][8]); Assert.Equal(0, img.LoadedNativeRows[2][0]); Assert.Equal(0, img.LoadedNativeRows[2][1]); Assert.Equal(255, img.LoadedNativeRows[2][2]); Assert.Equal(0, img.LoadedNativeRows[2][3]); Assert.Equal(0, img.LoadedNativeRows[2][4]); Assert.Equal(255, img.LoadedNativeRows[2][5]); Assert.Equal(0, img.LoadedNativeRows[2][6]); Assert.Equal(0, img.LoadedNativeRows[2][7]); Assert.Equal(255, img.LoadedNativeRows[2][8]); Assert.Equal(3, img.GetNativePixel(0, 0).Count); Assert.Equal(3, img.GetScaledPixel(0, 0).Count); Assert.Equal(255, img.GetNativePixel(0, 0)[0]); Assert.Equal(1.0, img.GetScaledPixel(0, 0)[0]); Assert.Equal(0, img.GetNativePixel(0, 0)[1]); Assert.Equal(0.0, img.GetScaledPixel(0, 0)[1]); Assert.Equal(0, img.GetNativePixel(0, 0)[2]); Assert.Equal(0.0, img.GetScaledPixel(0, 0)[2]); Assert.Equal(3, img.GetNativePixel(1, 0).Count); Assert.Equal(3, img.GetScaledPixel(1, 0).Count); Assert.Equal(255, img.GetNativePixel(1, 0)[0]); Assert.Equal(1.0, img.GetScaledPixel(1, 0)[0]); Assert.Equal(0, img.GetNativePixel(1, 0)[1]); Assert.Equal(0.0, img.GetScaledPixel(1, 0)[1]); Assert.Equal(0, img.GetNativePixel(1, 0)[2]); Assert.Equal(0.0, img.GetScaledPixel(1, 0)[2]); Assert.Equal(3, img.GetNativePixel(2, 0).Count); Assert.Equal(3, img.GetScaledPixel(2, 0).Count); Assert.Equal(255, img.GetNativePixel(2, 0)[0]); Assert.Equal(1.0, img.GetScaledPixel(2, 0)[0]); Assert.Equal(0, img.GetNativePixel(2, 0)[1]); Assert.Equal(0.0, img.GetScaledPixel(2, 0)[1]); Assert.Equal(0, img.GetNativePixel(2, 0)[2]); Assert.Equal(0.0, img.GetScaledPixel(2, 0)[2]); Assert.Equal(3, img.GetNativePixel(0, 1).Count); Assert.Equal(3, img.GetScaledPixel(0, 1).Count); Assert.Equal(0, img.GetNativePixel(0, 1)[0]); Assert.Equal(0.0, img.GetScaledPixel(0, 1)[0]); Assert.Equal(255, img.GetNativePixel(0, 1)[1]); Assert.Equal(1.0, img.GetScaledPixel(0, 1)[1]); Assert.Equal(0, img.GetNativePixel(0, 1)[2]); Assert.Equal(0.0, img.GetScaledPixel(0, 1)[2]); Assert.Equal(3, img.GetNativePixel(1, 1).Count); Assert.Equal(3, img.GetScaledPixel(1, 1).Count); Assert.Equal(0, img.GetNativePixel(1, 1)[0]); Assert.Equal(0.0, img.GetScaledPixel(1, 1)[0]); Assert.Equal(255, img.GetNativePixel(1, 1)[1]); Assert.Equal(1.0, img.GetScaledPixel(1, 1)[1]); Assert.Equal(0, img.GetNativePixel(1, 1)[2]); Assert.Equal(0.0, img.GetScaledPixel(1, 1)[2]); Assert.Equal(3, img.GetNativePixel(2, 1).Count); Assert.Equal(3, img.GetScaledPixel(2, 1).Count); Assert.Equal(0, img.GetNativePixel(2, 1)[0]); Assert.Equal(0.0, img.GetScaledPixel(2, 1)[0]); Assert.Equal(255, img.GetNativePixel(2, 1)[1]); Assert.Equal(1.0, img.GetScaledPixel(2, 1)[1]); Assert.Equal(0, img.GetNativePixel(2, 1)[2]); Assert.Equal(0.0, img.GetScaledPixel(2, 1)[2]); Assert.Equal(3, img.GetNativePixel(0, 2).Count); Assert.Equal(3, img.GetScaledPixel(0, 2).Count); Assert.Equal(0, img.GetNativePixel(0, 2)[0]); Assert.Equal(0.0, img.GetScaledPixel(0, 2)[0]); Assert.Equal(0, img.GetNativePixel(0, 2)[1]); Assert.Equal(0.0, img.GetScaledPixel(0, 2)[1]); Assert.Equal(255, img.GetNativePixel(0, 2)[2]); Assert.Equal(1.0, img.GetScaledPixel(0, 2)[2]); Assert.Equal(3, img.GetNativePixel(1, 2).Count); Assert.Equal(3, img.GetScaledPixel(1, 2).Count); Assert.Equal(0, img.GetNativePixel(1, 2)[0]); Assert.Equal(0.0, img.GetScaledPixel(1, 2)[0]); Assert.Equal(0, img.GetNativePixel(1, 2)[1]); Assert.Equal(0.0, img.GetScaledPixel(1, 2)[1]); Assert.Equal(255, img.GetNativePixel(1, 2)[2]); Assert.Equal(1.0, img.GetScaledPixel(1, 2)[2]); Assert.Equal(3, img.GetNativePixel(2, 2).Count); Assert.Equal(3, img.GetScaledPixel(2, 2).Count); Assert.Equal(0, img.GetNativePixel(2, 2)[0]); Assert.Equal(0.0, img.GetScaledPixel(2, 2)[0]); Assert.Equal(0, img.GetNativePixel(2, 2)[1]); Assert.Equal(0.0, img.GetScaledPixel(2, 2)[1]); Assert.Equal(255, img.GetNativePixel(2, 2)[2]); Assert.Equal(1.0, img.GetScaledPixel(2, 2)[2]); Assert.Throws <ArgumentOutOfRangeException>("x", () => { img.GetNativePixel(3, 0); }); Assert.Throws <ArgumentOutOfRangeException>("x", () => { img.GetScaledPixel(3, 0); }); Assert.Throws <ArgumentOutOfRangeException>("y", () => { img.GetNativePixel(0, 3); }); Assert.Throws <ArgumentOutOfRangeException>("y", () => { img.GetScaledPixel(0, 3); }); }
public void FiveTimesFiveWCMYToCMYK() { var additiveHeader = new NetpbmHeader <byte>(ImageType.PAM, 5, 5, 1, new[] { Component.White, Component.Cyan, Component.Magenta, Component.Yellow }, 255); var additive = new NetpbmImage8(additiveHeader, new[] { new byte[] { 12, 34, 56, 78, 90, 12, 34, 56, 78, 90, 12, 34, 56, 78, 90, 12, 34, 56, 78, 90 }, new byte[] { 34, 56, 78, 90, 12, 34, 56, 78, 90, 12, 34, 56, 78, 90, 12, 34, 56, 78, 90, 12 }, new byte[] { 56, 78, 90, 12, 34, 56, 78, 90, 12, 34, 56, 78, 90, 12, 34, 56, 78, 90, 12, 34 }, new byte[] { 78, 90, 12, 34, 56, 78, 90, 12, 34, 56, 78, 90, 12, 34, 56, 78, 90, 12, 34, 56 }, new byte[] { 90, 12, 34, 56, 78, 90, 12, 34, 56, 78, 90, 12, 34, 56, 78, 90, 12, 34, 56, 78 } }); var referenceValues = new[] { new byte[] { 34, 56, 78, 243, 12, 34, 56, 165, 90, 12, 34, 177, 78, 90, 12, 199, 56, 78, 90, 221 }, new byte[] { 56, 78, 90, 221, 34, 56, 78, 243, 12, 34, 56, 165, 90, 12, 34, 177, 78, 90, 12, 199 }, new byte[] { 78, 90, 12, 199, 56, 78, 90, 221, 34, 56, 78, 243, 12, 34, 56, 165, 90, 12, 34, 177 }, new byte[] { 90, 12, 34, 177, 78, 90, 12, 199, 56, 78, 90, 221, 34, 56, 78, 243, 12, 34, 56, 165 }, new byte[] { 12, 34, 56, 165, 90, 12, 34, 177, 78, 90, 12, 199, 56, 78, 90, 221, 34, 56, 78, 243 } }; var canon = new Canonicalizer(); var subtractive = canon.Canonicalize(additive, GrayscaleConversion.WhiteToBlack); subtractive.LoadData(); Assert.Equal(5, subtractive.Header.Width); Assert.Equal(5, subtractive.Header.Height); Assert.Equal(255, subtractive.Header.HighestComponentValue); Assert.Equal(4, subtractive.Header.Components.Count); Assert.Equal(Component.Cyan, subtractive.Header.Components[0]); Assert.Equal(Component.Magenta, subtractive.Header.Components[1]); Assert.Equal(Component.Yellow, subtractive.Header.Components[2]); Assert.Equal(Component.Black, subtractive.Header.Components[3]); Assert.NotNull(subtractive.LoadedNativeRows); Assert.Equal(5, subtractive.LoadedNativeRows.Count); Assert.Equal(20, subtractive.LoadedNativeRows[0].Count); Assert.Equal(20, subtractive.LoadedNativeRows[1].Count); Assert.Equal(20, subtractive.LoadedNativeRows[2].Count); Assert.Equal(20, subtractive.LoadedNativeRows[3].Count); Assert.Equal(20, subtractive.LoadedNativeRows[4].Count); Assert.Equal((IEnumerable <byte>)referenceValues[0], (IEnumerable <byte>)subtractive.LoadedNativeRows[0]); Assert.Equal((IEnumerable <byte>)referenceValues[1], (IEnumerable <byte>)subtractive.LoadedNativeRows[1]); Assert.Equal((IEnumerable <byte>)referenceValues[2], (IEnumerable <byte>)subtractive.LoadedNativeRows[2]); Assert.Equal((IEnumerable <byte>)referenceValues[3], (IEnumerable <byte>)subtractive.LoadedNativeRows[3]); Assert.Equal((IEnumerable <byte>)referenceValues[4], (IEnumerable <byte>)subtractive.LoadedNativeRows[4]); }
public void ThreeTimesThreeBGRToRGB() { var bgrHeader = new NetpbmHeader <byte>(ImageType.PAM, 3, 3, 1, new[] { Component.Blue, Component.Green, Component.Red }, 255); var bgr = new NetpbmImage8(bgrHeader, new[] { new byte[] { 255, 0, 0, 0, 255, 0, 0, 0, 255 }, new byte[] { 0, 255, 0, 0, 0, 255, 255, 0, 0 }, new byte[] { 0, 0, 255, 255, 0, 0, 0, 255, 0 } }); var referenceValues = new[] { new byte[] { 0, 0, 255, 0, 255, 0, 255, 0, 0 }, new byte[] { 0, 255, 0, 255, 0, 0, 0, 0, 255 }, new byte[] { 255, 0, 0, 0, 0, 255, 0, 255, 0 } }; var canon = new Canonicalizer(); var rgb = canon.Canonicalize(bgr, GrayscaleConversion.WhiteToBlack); rgb.LoadData(); Assert.Equal(3, rgb.Header.Width); Assert.Equal(3, rgb.Header.Height); Assert.Equal(255, rgb.Header.HighestComponentValue); Assert.Equal(3, rgb.Header.Components.Count); Assert.Equal(Component.Red, rgb.Header.Components[0]); Assert.Equal(Component.Green, rgb.Header.Components[1]); Assert.Equal(Component.Blue, rgb.Header.Components[2]); Assert.NotNull(rgb.LoadedNativeRows); Assert.Equal(3, rgb.LoadedNativeRows.Count); Assert.Equal(9, rgb.LoadedNativeRows[0].Count); Assert.Equal(9, rgb.LoadedNativeRows[1].Count); Assert.Equal(9, rgb.LoadedNativeRows[2].Count); Assert.Equal((IEnumerable <byte>)referenceValues[0], (IEnumerable <byte>)rgb.LoadedNativeRows[0]); Assert.Equal((IEnumerable <byte>)referenceValues[1], (IEnumerable <byte>)rgb.LoadedNativeRows[1]); Assert.Equal((IEnumerable <byte>)referenceValues[2], (IEnumerable <byte>)rgb.LoadedNativeRows[2]); }