public void OpInequalityTest001() { int width = 16; int height = 16; Pixel color = Pixel.BlackPixel; Pixel spixel = new Pixel(127, 127, 127); sbyte scolor = 127; Bitmap bmp = new Bitmap(); bmp.Init(height, width, 0); bmp.Fill(scolor); IPixelMap map1 = PixelMapTests.CreateInitVerifyPixelMap(width, height, Pixel.BlackPixel); IPixelMap map2 = PixelMapTests.CreateInitVerifyPixelMap(width, height, Pixel.GreenPixel); IPixelMap map3 = PixelMapTests.CreateInitVerifyPixelMap(width, height, Pixel.RedPixel); PixelReference pix1 = (PixelReference)map1.CreateGPixelReference(0); PixelReference pix2 = (PixelReference)map2.CreateGPixelReference(0); PixelReference pix3 = (PixelReference)map3.CreateGPixelReference(0); PixelReference pix4 = (PixelReference)bmp.CreateGPixelReference(0); PixelReference pix11 = (PixelReference)pix1.Duplicate(); PixelReference pix21 = (PixelReference)pix2.Duplicate(); PixelReference pix31 = (PixelReference)pix3.Duplicate(); Assert.True(pix1 != pix2); Assert.False(pix1 != pix11); Assert.True(pix3 != pix2); Assert.False(pix2 != pix21); Assert.True(pix3 != pix1); Assert.False(pix3 != pix31); Assert.True(pix3 != (PixelReference)null); Assert.True((PixelReference)null != pix3); }
public void SetPixelsTest001() { int width = 16; int height = 16; Pixel color = Pixel.BluePixel; sbyte scolor = 127; Bitmap bmp = new Bitmap(); bmp.Init(height, width, 0); bmp.Fill(scolor); IPixelMap map1 = PixelMapTests.CreateInitVerifyPixelMap(width, height, color); IPixelMap map2 = PixelMapTests.CreateInitVerifyPixelMap(width, height, Pixel.GreenPixel); IPixelMap map3 = PixelMapTests.CreateInitVerifyPixelMap(width, height, Pixel.RedPixel); var pix1 = map1.CreateGPixelReference(0); var pix2 = map2.CreateGPixelReference(0); var pix3 = map3.CreateGPixelReference(0); var pix4 = bmp.CreateGPixelReference(0); Assert.Equal(scolor, bmp.GetByteAt(8)); pix4.SetPixels(pix1, 16); Assert.Equal(255, bmp.GetByteAt(8)); Assert.Equal(scolor, bmp.GetByteAt(24)); pix4.SetPixels(pix2, 16); Assert.Equal(0, bmp.GetByteAt(24)); Assert.Equal(scolor, bmp.GetByteAt(40)); pix4.SetPixels(pix3, 16); Assert.Equal(0, bmp.GetByteAt(40)); Assert.Equal(scolor, bmp.GetByteAt(56)); }
public void ScaleTest007() { int srcWidth = 48; int srcHeight = 27; int targetWidth = 32; int targetHeight = 18; var sclr = CreateVerifyPixelMapScaler(srcWidth, srcHeight, targetWidth, targetHeight); Rectangle srcRect = new Rectangle { Right = 0, Left = 48, Bottom = 0, Top = 27 }; Rectangle targetRect = new Rectangle { Right = 0, Left = 32, Bottom = 0, Top = 18 }; IPixelMap srcMap = PixelMapTests.CreateInitVerifyPixelMap(srcWidth, srcHeight, Pixel.RedPixel); IPixelMap destMap = PixelMapTests.CreateInitVerifyPixelMap(targetWidth, targetHeight, Pixel.WhitePixel); sclr.SetHorzRatio(32, 48); sclr.SetVertRatio(18, 27); sclr.Scale(srcRect, srcMap, targetRect, destMap); }
public void SetOffsetTest002() { int width = 32; int height = 32; Pixel color = Pixel.RedPixel; var map = PixelMapTests.CreateInitVerifyPixelMap(width, height, color); var pix = map.CreateGPixelReference(0); for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { pix.SetOffset(i, j); pix.Blue = unchecked ((sbyte)((i * width + j) % 256)); } } for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { pix.SetOffset(i, j); Assert.Equal(unchecked ((sbyte)((i * width + j) % 256)), pix.Blue); Assert.Equal(0, pix.Green); Assert.Equal(-1, pix.Red); } } }
public void ScaleTest012() { int srcWidth = 48; int srcHeight = 27; int targetWidth = 16; int targetHeight = 9; var sclr = CreateVerifyPixelMapScaler(srcWidth, srcHeight, targetWidth, targetHeight); Rectangle srcRect = new Rectangle { Right = 0, Left = srcWidth, Bottom = -1, Top = srcHeight - 1 }; Rectangle targetRect = new Rectangle { Right = 0, Left = targetWidth, Bottom = 0, Top = targetHeight }; IPixelMap srcMap = PixelMapTests.CreateInitVerifyPixelMap(srcWidth, srcHeight, Pixel.RedPixel); IPixelMap destMap = PixelMapTests.CreateInitVerifyPixelMap(targetWidth, targetHeight, Pixel.WhitePixel); Assert.Throws <DjvuArgumentException>(() => sclr.Scale(srcRect, srcMap, targetRect, destMap)); }
public void ScaleTest008() { int srcWidth = 48; int srcHeight = 27; int targetWidth = 16; int targetHeight = 9; var sclr = CreateVerifyPixelMapScaler(srcWidth, srcHeight, targetWidth, targetHeight); Rectangle srcRect = new Rectangle { Right = 0, Left = srcWidth, Bottom = 0, Top = srcHeight }; Rectangle targetRect = new Rectangle { Right = 0, Left = targetWidth, Bottom = 0, Top = targetHeight }; IPixelMap srcMap = PixelMapTests.CreateInitVerifyPixelMap(srcWidth, srcHeight, Pixel.RedPixel); IPixelMap destMap = PixelMapTests.CreateInitVerifyPixelMap(targetWidth, targetHeight, Pixel.WhitePixel); sclr.SetHorzRatio(targetWidth, srcWidth); sclr.SetVertRatio(targetHeight, srcHeight); sclr.Scale(srcRect, srcMap, targetRect, destMap); }
public void ScaleTest006() { int srcWidth = 48; int srcHeight = 27; int targetWidth = 32; int targetHeight = 18; var sclr = CreateVerifyPixelMapScaler(srcWidth, srcHeight, targetWidth, targetHeight); Rectangle srcRect = new Rectangle { Right = 0, Left = 48, Bottom = 0, Top = 27 }; srcRect.YMax -= 1; Rectangle targetRect = new Rectangle { Right = 0, Left = 32, Bottom = 0, Top = 18 }; IPixelMap srcMap = PixelMapTests.CreateInitVerifyPixelMap(srcWidth, srcHeight, Pixel.RedPixel); IPixelMap destMap = PixelMapTests.CreateInitVerifyPixelMap(targetWidth, targetHeight, Pixel.WhitePixel); Assert.Throws <DjvuArgumentException>(() => sclr.Scale(srcRect, srcMap, targetRect, destMap)); }
public void ToImageTest005() { int width = 32; int height = 32; Pixel color = Pixel.BluePixel; IPixelMap map1 = PixelMapTests.CreateInitVerifyPixelMap(width, height, color); map1.BytesPerPixel = 5; Assert.Throws <DjvuFormatException>(() => map1.ToImage()); }
public void OffsetTest001() { int width = 32; int height = 32; Pixel color = Pixel.BluePixel; IPixelMap map1 = PixelMapTests.CreateInitVerifyPixelMap(width, height, color); PixelReference pix = (PixelReference)map1.CreateGPixelReference(0); pix.Offset = 3 * width; Assert.Equal(3 * width, pix.Offset); }
public void RedOffsetTest() { int width = 256; int height = 256; Pixel color = Pixel.BluePixel; IPixelMap map1 = PixelMapTests.CreateInitVerifyPixelMap(width, height, color); PixelReference pix = (PixelReference)map1.CreateGPixelReference(0); Assert.Equal(2, pix.RedOffset); pix.RedOffset = 0; Assert.Equal(0, pix.RedOffset); }
public void Ycc2RgbTest001() { int width = 32; int height = 32; Pixel color = Pixel.RedPixel; var map = PixelMapTests.CreateInitVerifyPixelMap(width, height, color); map.IsRampNeeded = true; var pix = map.CreateGPixelReference(0); Assert.Throws <DjvuInvalidOperationException>(() => pix.Ycc2Rgb(width * height)); }
public void ParentTest() { int width = 256; int height = 256; Pixel color = Pixel.BluePixel; IPixelMap map1 = PixelMapTests.CreateInitVerifyPixelMap(width, height, color); IPixelMap map2 = PixelMapTests.CreateInitVerifyPixelMap(width, height, color); PixelReference pix = (PixelReference)map1.CreateGPixelReference(0); Assert.Same(pix.Parent, map1); pix.Parent = map2; Assert.NotSame(map1, map2); Assert.NotSame(pix.Parent, map1); Assert.Same(pix.Parent, map2); }
public void ToImageTest002() { int width = 32; int height = 32; Pixel color = Pixel.BluePixel; IPixelMap map1 = PixelMapTests.CreateInitVerifyPixelMap(width, height, color); map1.BytesPerPixel = 2; using (System.Drawing.Bitmap bmp = map1.ToImage()) { Assert.NotNull(bmp); Assert.IsType <System.Drawing.Bitmap>(bmp); Assert.Equal(width, bmp.Width); Assert.Equal(height, bmp.Height); } }
public void EqualsIPixelReference() { int width = 16; int height = 16; Pixel color = Pixel.BluePixel; IPixelMap map1 = PixelMapTests.CreateInitVerifyPixelMap(width, height, color); IPixelMap map2 = PixelMapTests.CreateInitVerifyPixelMap(width, height, color); IPixelMap map3 = PixelMapTests.CreateInitVerifyPixelMap(width, height, Pixel.BlackPixel); IPixelReference pix1 = map1.CreateGPixelReference(0); IPixelReference pix2 = map2.CreateGPixelReference(0); IPixelReference pix3 = map3.CreateGPixelReference(0); Assert.True(pix1.Equals(pix2)); Assert.False(pix1.Equals(pix3)); Assert.False(pix1.Equals((IPixelReference)null)); }
public void SetBGRTest001() { int width = 32; int height = 32; Pixel color = Pixel.RedPixel; var map = PixelMapTests.CreateInitVerifyPixelMap(width, height, color); PixelReference pix = (PixelReference)map.CreateGPixelReference(0); pix.SetOffset(10, 16); pix.SetBGR(0xafcfdf); Pixel testColor = new Pixel(0xafcfdf); Assert.True((Pixel)pix.ToPixel() == testColor); pix.SetOffset(10, 15); Assert.False((Pixel)pix.ToPixel() == testColor); pix.SetOffset(10, 17); Assert.False((Pixel)pix.ToPixel() == testColor); }
public void GetLineTest004() { int srcWidth = 48; int srcHeight = 27; int targetWidth = 16; int targetHeight = 9; var sclr = CreateVerifyPixelMapScaler(srcWidth, srcHeight, targetWidth, targetHeight); Rectangle srcRect = new Rectangle { Right = 0, Left = srcWidth, Bottom = 0, Top = srcHeight }; Rectangle redRect = new Rectangle { Right = 0, Left = targetWidth, Bottom = 0, Top = targetHeight }; IPixelMap srcMap = PixelMapTests.CreateInitVerifyPixelMap(srcWidth, srcHeight, Pixel.RedPixel); IPixelMap destMap = PixelMapTests.CreateInitVerifyPixelMap(targetWidth, targetHeight, Pixel.WhitePixel); sclr._PixelMap1 = srcMap; sclr._PixelMap2 = destMap; int fy = sclr._L2; var line = sclr.GetLine(fy, redRect, srcRect, srcMap); Assert.NotNull(line); }
public void SetPixelsTest002() { int width = 16; int height = 16; Pixel color = Pixel.BlackPixel; Pixel spixel = new Pixel(127, 127, 127); sbyte scolor = 127; Bitmap bmp = new Bitmap(); bmp.Init(height, width, 0); bmp.Fill(scolor); IPixelMap map1 = PixelMapTests.CreateInitVerifyPixelMap(width, height, Pixel.BlackPixel); IPixelMap map2 = PixelMapTests.CreateInitVerifyPixelMap(width, height, Pixel.GreenPixel); IPixelMap map3 = PixelMapTests.CreateInitVerifyPixelMap(width, height, Pixel.RedPixel); var pix1 = map1.CreateGPixelReference(0); var pix2 = map2.CreateGPixelReference(0); var pix3 = map3.CreateGPixelReference(0); var pix4 = bmp.CreateGPixelReference(0); Assert.Equal(color, map1.GetPixelAt(0, 8)); pix1.SetPixels(pix2, 16); Assert.Equal(Pixel.GreenPixel, map1.GetPixelAt(0, 8)); Assert.Equal(color, map1.GetPixelAt(1, 8)); pix1.SetPixels(pix3, 16); Assert.Equal(Pixel.RedPixel, map1.GetPixelAt(1, 8)); Assert.Equal(color, map1.GetPixelAt(2, 8)); pix1.SetPixels(pix4, 16); Assert.Equal(spixel, map1.GetPixelAt(2, 8)); Assert.Equal(color, map1.GetPixelAt(3, 8)); }