Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
                }
            }
        }
Exemplo n.º 5
0
        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));
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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));
        }
Exemplo n.º 8
0
        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());
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        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));
        }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
        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);
            }
        }
Exemplo n.º 14
0
        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));
        }
Exemplo n.º 15
0
        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);
        }
Exemplo n.º 16
0
        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);
        }
Exemplo n.º 17
0
        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));
        }