示例#1
1
        public AForgeCamera(string preferedCameraName = null, int preferedWidth = 640, int preferedHeight = 480, DownSample downSampleVideo = DownSample.None)
        {
            this.downSampleVideo = downSampleVideo;

            if (preferedCameraName != null)
            {
                FilterInfoCollection videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
                foreach (FilterInfo info in videoDevices)
                {
                    if (info.Name.Contains(preferedCameraName))
                    {
                        videoCaptureDevice = new VideoCaptureDevice(info.MonikerString);
                        videoCaptureDevice.DesiredFrameSize = new Size(preferedWidth, preferedHeight);
                        break;
                    }
                }
            }

            if (videoCaptureDevice == null)
            {
                VideoCaptureDeviceForm form = new VideoCaptureDeviceForm();
                if (form.ShowDialog(null) == DialogResult.OK)
                {
                    // create video source
                    videoCaptureDevice = form.VideoDevice;
                }
            }

            if (videoCaptureDevice != null)
            {
                //videoCaptureDevice.DesiredFrameRate = 5;
                //videoCaptureDevice.ProvideSnapshots = true;
                //videoCaptureDevice.DesiredSnapshotSize = new Size(preferedWidth, preferedHeight);
                //videoCaptureDevice.SnapshotFrame += new NewFrameEventHandler(videoCaptureDevice_SnapshotFrame);

                asyncCopiedVideoImage = new ImageBuffer(videoCaptureDevice.DesiredFrameSize.Width, videoCaptureDevice.DesiredFrameSize.Height, 32, new BlenderBGRA());
                if (downSampleVideo == DownSample.HalfSize)
                {
                    imageForExternalUse = new ImageBuffer(videoCaptureDevice.DesiredFrameSize.Width / 2, videoCaptureDevice.DesiredFrameSize.Height / 2, 32, new BlenderBGRA());
                }
                else
                {
                    imageForExternalUse = new ImageBuffer(videoCaptureDevice.DesiredFrameSize.Width, videoCaptureDevice.DesiredFrameSize.Height, 32, new BlenderBGRA());
                }
                videoCaptureDevice.Start();
                videoCaptureDevice.NewFrame += new NewFrameEventHandler(source_NewFrame);
            }
        }
 ImageBuffer LoadImage(string imageName)
 {
     string path = Path.Combine(ApplicationDataStorage.Instance.ApplicationStaticDataPath, imageName);
     ImageBuffer buffer = new ImageBuffer(10, 10, 32, new BlenderBGRA());
     ImageBMPIO.LoadImageData(path, buffer);
     return buffer;
 }
        GuiWidget CreateOptionsMenu()
        {
            ImageBuffer gearImage = new ImageBuffer();
            string imagePathAndFile = Path.Combine(ApplicationDataStorage.Instance.ApplicationStaticDataPath, "gear_icon.png");
            ImageBMPIO.LoadImageData(imagePathAndFile, gearImage);

            FlowLayoutWidget leftToRight = new FlowLayoutWidget();
            leftToRight.Margin = new BorderDouble(5, 0);
            string optionsString = new LocalizedString("Options").Translated;
            TextWidget optionsText = new TextWidget(optionsString, textColor: RGBA_Bytes.White);
            optionsText.VAnchor = Agg.UI.VAnchor.ParentCenter;
            optionsText.Margin = new BorderDouble(0, 0, 3, 0);
            leftToRight.AddChild(optionsText);
            GuiWidget gearWidget = new ImageWidget(gearImage);
            gearWidget.VAnchor = Agg.UI.VAnchor.ParentCenter;
            leftToRight.AddChild(gearWidget);
            leftToRight.HAnchor = HAnchor.FitToChildren;
            leftToRight.VAnchor = VAnchor.FitToChildren;

            Menu optionMenu = new Menu(leftToRight);
            optionMenu.OpenOffset = new Vector2(-2, -10);
            optionMenu.VAnchor = Agg.UI.VAnchor.ParentCenter;
            optionMenu.MenuItems.Add(new MenuItem(new ThemeColorSelectorWidget()));

            return optionMenu;
        }
示例#4
0
		public void ContainsTests()
		{
			// look for 24 bit
			{
				ImageBuffer imageToSearch = new ImageBuffer(150, 150, 24, new BlenderBGR());
				imageToSearch.NewGraphics2D().Circle(new Vector2(100, 100), 3, RGBA_Bytes.Red);
				ImageBuffer circleToFind = new ImageBuffer(10, 10, 24, new BlenderBGR());
				circleToFind.NewGraphics2D().Circle(new Vector2(5, 5), 3, RGBA_Bytes.Red);
				Assert.IsTrue(imageToSearch.Contains(circleToFind), "We should be able to find the circle.");

				ImageBuffer squareToFind = new ImageBuffer(10, 10, 24, new BlenderBGR());
				squareToFind.NewGraphics2D().FillRectangle(4, 4, 8, 8, RGBA_Bytes.Red);
				Assert.IsTrue(!imageToSearch.Contains(squareToFind), "We should be not find a square.");
			}

			// look for 32 bit
			{
				ImageBuffer imageToSearch = new ImageBuffer(150, 150, 32, new BlenderBGRA());
				imageToSearch.NewGraphics2D().Circle(new Vector2(100, 100), 3, RGBA_Bytes.Red);
				ImageBuffer circleToFind = new ImageBuffer(10, 10, 32, new BlenderBGRA());
				circleToFind.NewGraphics2D().Circle(new Vector2(5, 5), 3, RGBA_Bytes.Red);
				Assert.IsTrue(imageToSearch.Contains(circleToFind), "We should be able to find the circle.");

				ImageBuffer squareToFind = new ImageBuffer(10, 10, 32, new BlenderBGRA());
				squareToFind.NewGraphics2D().FillRectangle(4, 4, 8, 8, RGBA_Bytes.Red);
				Assert.IsTrue(!imageToSearch.Contains(squareToFind), "We should be not find a square.");
			}
		}
示例#5
0
		private void OutputImage(ImageBuffer imageToOutput, string fileName)
		{
			if (saveImagesForDebug)
			{
				ImageTgaIO.Save(imageToOutput, fileName);
			}
		}
示例#6
0
		private void SaveImage(ImageBuffer image, string dest)
		{
			if (saveImagesForDebug)
			{
				ImageTgaIO.Save(image, dest);
			}
		}
示例#7
0
		public void DoubleBufferTests()
		{
			{
				bool textWidgetDoubleBufferDefault = TextWidget.DoubleBufferDefault;

				// the text widget is double buffered
				TextWidget.DoubleBufferDefault = true;
				ImageBuffer doubleBufferImage = new ImageBuffer(65, 50, 24, new BlenderBGR());
				Button doubleBufferButton = new Button("testing", 0, 0);
				doubleBufferButton.OnDraw(doubleBufferImage.NewGraphics2D());
				SaveImage(doubleBufferImage, "z control.tga");

				// make sure the frame comparison function works.
				{
					ImageBuffer doubleBufferImageCopy = new ImageBuffer(doubleBufferImage, new BlenderBGR());
					Assert.IsTrue(doubleBufferImage == doubleBufferImageCopy);
				}

				// the text widget is not double buffered
				TextWidget.DoubleBufferDefault = false;
				ImageBuffer notDoubleBufferImage = new ImageBuffer(65, 50, 24, new BlenderBGR());
				Button notDoubleBufferButton = new Button("testing", 0, 0);
				notDoubleBufferButton.OnDraw(notDoubleBufferImage.NewGraphics2D());
				SaveImage(notDoubleBufferImage, "z test.tga");

				Assert.IsTrue(doubleBufferImage == notDoubleBufferImage);

				TextWidget.DoubleBufferDefault = textWidgetDoubleBufferDefault;
			}
		}
示例#8
0
文件: Blur.cs 项目: jeske/agg-sharp
        public static void DoYBlur(ImageBuffer sourceDest)
        {
            if (sourceDest.BitDepth != 8)
            {
                throw new NotImplementedException("We only work with 8 bit at the moment.");
            }

            int height = sourceDest.Height;
            int width = sourceDest.Width;
            byte[] buffer = sourceDest.GetBuffer();
            int strideInBytes = sourceDest.StrideInBytes();
            byte[] cache = new byte[height];

            for (int x = 0; x < width; x++)
            {
                int offset = x;
                for (int y = 0; y < height; y++)
                {
                    cache[y] = buffer[offset];
                    offset += strideInBytes;
                }

                offset = x;
                for (int y = 1; y < height - 1; y++)
                {
                    int newValue = (cache[y - 1] + cache[y] * 2 + cache[y + 1] + 2) / 4; // the + 2 is so that we will round correctly
                    buffer[offset] = (byte)newValue;
                    offset += strideInBytes;
                }
            }
        }
示例#9
0
文件: Blur.cs 项目: jeske/agg-sharp
        internal static void DoXBlur(ImageBuffer sourceDest)
        {
            if (sourceDest.BitDepth != 8)
            {
                throw new NotImplementedException("We only work with 8 bit at the moment.");
            }

            int height = sourceDest.Height;
            int width = sourceDest.Width;
            byte[] buffer = sourceDest.GetBuffer();
            byte[] cache = new byte[width];

            for (int y = 0; y < height; y++)
            {
                int offset = sourceDest.GetBufferOffsetY(y);
                for (int x = 0; x < width; x++)
                {
                    cache[x] = buffer[offset + x];
                }

                for (int x = 1; x < width - 1; x++)
                {
                    int newValue = (cache[x - 1] + cache[x] * 2 + cache[x + 1] + 2) / 4; // the + 2 is so that we will round correctly
                    buffer[offset + x] = (byte)newValue;
                }
            }
        }
        public LibraryThumbnailWidget(PrintItemWrapper item, string noThumbnailFileName, string buildingThumbnailFileName, Vector2 size)
        {
            this.PrintItem = item;

            // Set Display Attributes
            this.Margin = new BorderDouble(0);
            this.Padding = new BorderDouble(5);
            this.Width = size.x;
            this.Height = size.y;
            this.MinimumSize = size;
            this.BackgroundColor = normalBackgroundColor;
            this.Cursor = Cursors.Hand;

            // set background images
            if (noThumbnailImage.Width == 0)
            {
                ImageBMPIO.LoadImageData(this.GetImageLocation(noThumbnailFileName), noThumbnailImage);
                ImageBMPIO.LoadImageData(this.GetImageLocation(buildingThumbnailFileName), buildingThumbnailImage);
            }
            this.image = new ImageBuffer(buildingThumbnailImage);

            // Add Handlers
            this.Click += new ButtonEventHandler(onMouseClick);
            this.MouseEnterBounds += new EventHandler(onEnter);
            this.MouseLeaveBounds += new EventHandler(onExit);
            ActiveTheme.Instance.ThemeChanged.RegisterEvent(onThemeChanged, ref unregisterEvents);

            CreateThumNailThreadIfNeeded();
        }
示例#11
0
		public TextureMaterial(ImageBuffer texture, double reflection, double transparency, double gloss, double density)
		{
			this.Reflection = reflection;
			this.Transparency = transparency;
			this.Gloss = gloss;
			this.Density = density;
			this.Texture = texture;
		}
示例#12
0
		public static ImageBuffer CreateWhiteToColor(ImageBuffer normalImage, RGBA_Bytes color)
		{
			ImageBuffer destImage = new ImageBuffer(normalImage.Width, normalImage.Height, 32, new BlenderBGRA());

			DoWhiteToColor(destImage, normalImage, color);

			return destImage;
		}
示例#13
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect());

            IImageByte backBuffer = widgetsSubImage;
            
            GammaLookUpTable gamma = new GammaLookUpTable(m_gamma.Value);
            IRecieveBlenderByte NormalBlender = new BlenderBGRA();
            IRecieveBlenderByte GammaBlender = new BlenderGammaBGRA(gamma);
            ImageBuffer rasterNormal = new ImageBuffer();
            rasterNormal.Attach(backBuffer, NormalBlender);
            ImageBuffer rasterGamma = new ImageBuffer();
            rasterGamma.Attach(backBuffer, GammaBlender);
            ImageClippingProxy clippingProxyNormal = new ImageClippingProxy(rasterNormal);
            ImageClippingProxy clippingProxyGamma = new ImageClippingProxy(rasterGamma);

            clippingProxyNormal.clear(m_white_on_black.Checked ? new RGBA_Floats(0, 0, 0) : new RGBA_Floats(1, 1, 1));

            ScanlineRasterizer ras = new ScanlineRasterizer();
            ScanlineCachePacked8 sl = new ScanlineCachePacked8();

            VertexSource.Ellipse e = new VertexSource.Ellipse();

            // TODO: If you drag the control circles below the bottom of the window we get an exception.  This does not happen in AGG.
            // It needs to be debugged.  Turning on clipping fixes it.  But standard agg works without clipping.  Could be a bigger problem than this.
            //ras.clip_box(0, 0, width(), height());

            // Render two "control" circles
            e.init(m_x[0], m_y[0], 3, 3, 16);
            ras.add_path(e);
            ScanlineRenderer scanlineRenderer = new ScanlineRenderer();
            scanlineRenderer.render_scanlines_aa_solid(clippingProxyNormal, ras, sl, new RGBA_Bytes(127, 127, 127));
            e.init(m_x[1], m_y[1], 3, 3, 16);
            ras.add_path(e);
            scanlineRenderer.render_scanlines_aa_solid(clippingProxyNormal, ras, sl, new RGBA_Bytes(127, 127, 127));

            double d = m_offset.Value;

            // Creating a rounded rectangle
            VertexSource.RoundedRect r = new VertexSource.RoundedRect(m_x[0] + d, m_y[0] + d, m_x[1] + d, m_y[1] + d, m_radius.Value);
            r.normalize_radius();

            // Drawing as an outline
            if (!m_DrawAsOutlineCheckBox.Checked)
            {
                Stroke p = new Stroke(r);
                p.width(1.0);
                ras.add_path(p);
            }
            else
            {
                ras.add_path(r);
            }

            scanlineRenderer.render_scanlines_aa_solid(clippingProxyGamma, ras, sl, m_white_on_black.Checked ? new RGBA_Bytes(255, 255, 255) : new RGBA_Bytes(0, 0, 0));

            base.OnDraw(graphics2D);
        }
示例#14
0
			internal InternalImageGraphics2D(ImageBuffer owner)
				: base()
			{
				ScanlineRasterizer rasterizer = new ScanlineRasterizer();
				ImageClippingProxy imageClippingProxy = new ImageClippingProxy(owner);

				Initialize(imageClippingProxy, rasterizer);
				ScanlineCache = new ScanlineCachePacked8();
			}
示例#15
0
		private ImageBuffer LoadImage(string imageName)
		{
			string path = Path.Combine("Icons", imageName);
			ImageBuffer buffer = new ImageBuffer(10, 10, 32, new BlenderBGRA());

			StaticData.Instance.LoadImage(path, buffer);

			return buffer;
		}
示例#16
0
		public static void DoErode3x3MinValue(ImageBuffer source, ImageBuffer dest)
		{
			if (source.BitDepth != 32 || dest.BitDepth != 32)
			{
				throw new NotImplementedException("We only work with 32 bit at the moment.");
			}

			if (source.Width != dest.Width || source.Height != dest.Height)
			{
				throw new NotImplementedException("Source and Dest have to be the same size");
			}

			int height = source.Height;
			int width = source.Width;
			int sourceStrideInBytes = source.StrideInBytes();
			int destStrideInBytes = dest.StrideInBytes();
			byte[] sourceBuffer = source.GetBuffer();
			byte[] destBuffer = dest.GetBuffer();

			// This can be made much faster by holding the buffer pointer and offsets better // LBB 2013 06 09
			for (int testY = 1; testY < height - 1; testY++)
			{
				for (int testX = 1; testX < width - 1; testX++)
				{
					RGBA_Bytes minColor = RGBA_Bytes.White;
					int sourceOffset = source.GetBufferOffsetXY(testX, testY - 1);

					// x-1, y-1
					//minColor = MinColor(sourceBuffer, minColor, sourceOffset - 4);
					// x0, y-1
					minColor = MinColor(sourceBuffer, minColor, sourceOffset + 0);
					// x1, y-1
					//minColor = MinColor(sourceBuffer, minColor, sourceOffset + 4);

					// x-1, y0
					minColor = MinColor(sourceBuffer, minColor, sourceOffset + sourceStrideInBytes - 4);
					// x0, y0
					minColor = MinColor(sourceBuffer, minColor, sourceOffset + sourceStrideInBytes + 0);
					// x+1, y0
					minColor = MinColor(sourceBuffer, minColor, sourceOffset + sourceStrideInBytes + 4);

					// x-1, y+1
					//minColor = MinColor(sourceBuffer, minColor, sourceOffset + sourceStrideInBytes * 2 - 4);
					// x0, y+1
					minColor = MinColor(sourceBuffer, minColor, sourceOffset + sourceStrideInBytes * 2 + 0);
					// x+1, y+1
					//minColor = MinColor(sourceBuffer, minColor, sourceOffset + sourceStrideInBytes * 2 + 4);

					int destOffset = dest.GetBufferOffsetXY(testX, testY);
					destBuffer[destOffset + 2] = minColor.red;
					destBuffer[destOffset + 1] = minColor.green;
					destBuffer[destOffset + 0] = minColor.blue;
					destBuffer[destOffset + 3] = 255;
				}
			}
		}
示例#17
0
        unsafe void generate_alpha_mask(int cx, int cy)
        {
            alphaByteArray = new byte[cx * cy];
            {
#if USE_CLIPPING_ALPHA_MASK
                alphaMaskImageBuffer.AttachBuffer(alphaByteArray, 20 * cx + 20, cx - 40, cy - 40, cx, 8, 1);
#else
                alphaMaskImageBuffer.attach(alphaByteArray, (int)cx, (int)cy, cx, 1);
#endif

                ImageBuffer image = new ImageBuffer();
                image.Attach(alphaMaskImageBuffer, new blender_gray(1), 1, 0, 8);
                ImageClippingProxy clippingProxy = new ImageClippingProxy(image);
                ScanlineCachePacked8 sl = new ScanlineCachePacked8();

                clippingProxy.clear(new RGBA_Floats(0));

                VertexSource.Ellipse ellipseForMask = new MatterHackers.Agg.VertexSource.Ellipse();

                System.Random randGenerator = new Random(1432);

                ScanlineRenderer scanlineRenderer = new ScanlineRenderer();
                int i;
                int num = (int)numMasksSlider.Value;
                for (i = 0; i < num; i++)
                {
                    if (i == num - 1)
                    {
                        ellipseForMask.init(Width / 2, Height / 2, 110, 110, 100);
                        rasterizer.add_path(ellipseForMask);
                        scanlineRenderer.render_scanlines_aa_solid(clippingProxy, rasterizer, sl, new RGBA_Bytes(0, 0, 0, 255));

                        ellipseForMask.init(ellipseForMask.originX, ellipseForMask.originY, ellipseForMask.radiusX - 10, ellipseForMask.radiusY - 10, 100);
                        rasterizer.add_path(ellipseForMask);
                        scanlineRenderer.render_scanlines_aa_solid(clippingProxy, rasterizer, sl, new RGBA_Bytes(255, 0, 0, 255));
                    }
                    else
                    {
                        ellipseForMask.init(randGenerator.Next() % cx,
                                 randGenerator.Next() % cy,
                                 randGenerator.Next() % 100 + 20,
                                 randGenerator.Next() % 100 + 20,
                                 100);
                        // set the color to draw into the alpha channel.
                        // there is not very much reason to set the alpha as you will get the amount of 
                        // transparency based on the color you draw.  (you might want some type of different edeg effect but it will be minor).
                        rasterizer.add_path(ellipseForMask);
                        scanlineRenderer.render_scanlines_aa_solid(clippingProxy, rasterizer, sl, new RGBA_Bytes((int)((float)i / (float)num * 255), 0, 0, 255));
                    }

                }
                
                alphaMaskImageBuffer.DettachBuffer();
            }
        }
示例#18
0
文件: Dilate.cs 项目: jeske/agg-sharp
        public static void DoDilate3x3MaxValue(ImageBuffer source, ImageBuffer dest)
        {
            if (source.BitDepth != 32 || dest.BitDepth != 32)
            {
                throw new NotImplementedException("We only work with 32 bit at the moment.");
            }

            if (source.Width != dest.Width || source.Height != dest.Height)
            {
                throw new NotImplementedException("Source and Dest have to be the same size");
            }

            int height = source.Height;
            int width = source.Width;
            int sourceStrideInBytes = source.StrideInBytes();
            int destStrideInBytes = dest.StrideInBytes();
            byte[] sourceBuffer = source.GetBuffer();
            byte[] destBuffer = dest.GetBuffer();

            for (int testY = 1; testY < height - 1; testY++)
            {
                for (int testX = 1; testX < width - 1; testX++)
                {
                    RGBA_Bytes maxColor = RGBA_Bytes.Black;
                    int sourceOffset = source.GetBufferOffsetXY(testX, testY -1);

                    // x-1, y-1
                    //maxColor = MaxColor(sourceBuffer, maxColor, sourceOffset - 4);
                    // x0, y-1
                    maxColor = MaxColor(sourceBuffer, maxColor, sourceOffset + 0);
                    // x1, y-1
                    //maxColor = MaxColor(sourceBuffer, maxColor, sourceOffset + 4);

                    // x-1, y0
                    maxColor = MaxColor(sourceBuffer, maxColor, sourceOffset + sourceStrideInBytes - 4);
                    // x0, y0
                    maxColor = MaxColor(sourceBuffer, maxColor, sourceOffset + sourceStrideInBytes + 0);
                    // x+1, y0
                    maxColor = MaxColor(sourceBuffer, maxColor, sourceOffset + sourceStrideInBytes + 4);

                    // x-1, y+1
                    //maxColor = MaxColor(sourceBuffer, maxColor, sourceOffset + sourceStrideInBytes * 2 - 4);
                    // x0, y+1
                    maxColor = MaxColor(sourceBuffer, maxColor, sourceOffset + sourceStrideInBytes * 2 + 0);
                    // x+1, y+1
                    //maxColor = MaxColor(sourceBuffer, maxColor, sourceOffset + sourceStrideInBytes * 2 + 4);

                    int destOffset = dest.GetBufferOffsetXY(testX, testY);
                    destBuffer[destOffset + 2] = maxColor.red;
                    destBuffer[destOffset + 1] = maxColor.green;
                    destBuffer[destOffset + 0] = maxColor.blue;
                    destBuffer[destOffset + 3] = 255;
                }
            }
        }
		public TextImageWidget(string label, RGBA_Bytes fillColor, RGBA_Bytes borderColor, RGBA_Bytes textColor, double borderWidth, BorderDouble margin, ImageBuffer image = null, double fontSize = 12, FlowDirection flowDirection = FlowDirection.LeftToRight, double height = 40, double width = 0, bool centerText = false, double imageSpacing = 0)
			: base()
		{
			this.image = image;
			this.fillColor = fillColor;
			this.borderColor = borderColor;
			this.borderWidth = borderWidth;
			this.Margin = new BorderDouble(0);
			this.Padding = new BorderDouble(0);

			TextWidget textWidget = new TextWidget(label, pointSize: fontSize);
			ImageWidget imageWidget;

			FlowLayoutWidget container = new FlowLayoutWidget(flowDirection);

			if (centerText)
			{
				// make sure the contents are centered
				GuiWidget leftSpace = new GuiWidget(0, 1);
				leftSpace.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
				container.AddChild(leftSpace);
			}

			if (image != null && image.Width > 0)
			{
				imageWidget = new ImageWidget(image);
				imageWidget.VAnchor = VAnchor.ParentCenter;
				imageWidget.Margin = new BorderDouble(right: imageSpacing);
				container.AddChild(imageWidget);
			}

			if (label != "")
			{
				textWidget.VAnchor = VAnchor.ParentCenter;
				textWidget.TextColor = textColor;
				textWidget.Padding = new BorderDouble(3, 0);
				container.AddChild(textWidget);
			}

			if (centerText)
			{
				GuiWidget rightSpace = new GuiWidget(0, 1);
				rightSpace.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
				container.AddChild(rightSpace);

				container.HAnchor = Agg.UI.HAnchor.ParentLeftRight | Agg.UI.HAnchor.FitToChildren;
			}
			container.VAnchor = Agg.UI.VAnchor.ParentCenter;

			container.MinimumSize = new Vector2(width, height);
			container.Margin = margin;
			this.AddChild(container);
			HAnchor = HAnchor.ParentLeftRight | HAnchor.FitToChildren;
			VAnchor = VAnchor.ParentCenter | Agg.UI.VAnchor.FitToChildren;
		}
示例#20
0
		public blur()
		{
			m_rbuf2 = new ImageBuffer();
			m_shape_bounds = new RectangleDouble();
			m_method = new RadioButtonGroup(new Vector2(10.0, 10.0), new Vector2(130.0, 60.0));
			m_radius = new Slider(new Vector2(130 + 10.0, 10.0 + 4.0), new Vector2(290, 8.0));
			m_shadow_ctrl = new PolygonEditWidget(4);
			m_channel_r = new CheckBox(10.0, 80.0, "Red");
			m_channel_g = new CheckBox(10.0, 95.0, "Green");
			m_channel_b = new CheckBox(10.0, 110.0, "Blue");
			m_FlattenCurves = new CheckBox(10, 315, "Convert And Flatten Curves");
			m_FlattenCurves.Checked = true;

			AddChild(m_method);
			m_method.AddRadioButton("Stack Blur");
			m_method.AddRadioButton("Recursive Blur");
			m_method.AddRadioButton("Channels");
			m_method.SelectedIndex = 1;

			AddChild(m_radius);
			m_radius.SetRange(0.0, 40.0);
			m_radius.Value = 15.0;
			m_radius.Text = "Blur Radius={0:F2}";

			AddChild(m_shadow_ctrl);

			AddChild(m_channel_r);
			AddChild(m_channel_g);
			AddChild(m_channel_b);
			AddChild(m_FlattenCurves);
			m_channel_g.Checked = true;

			m_sl = new ScanlineCachePacked8();

			StyledTypeFace typeFaceForLargeA = new StyledTypeFace(LiberationSansFont.Instance, 300, flatenCurves: false);
			m_path = typeFaceForLargeA.GetGlyphForCharacter('a');

			Affine shape_mtx = Affine.NewIdentity();
			shape_mtx *= Affine.NewTranslation(150, 100);
			m_path = new VertexSourceApplyTransform(m_path, shape_mtx);
			m_shape = new FlattenCurves(m_path);

			bounding_rect.bounding_rect_single(m_shape, 0, ref m_shape_bounds);

			m_shadow_ctrl.SetXN(0, m_shape_bounds.Left);
			m_shadow_ctrl.SetYN(0, m_shape_bounds.Bottom);
			m_shadow_ctrl.SetXN(1, m_shape_bounds.Right);
			m_shadow_ctrl.SetYN(1, m_shape_bounds.Bottom);
			m_shadow_ctrl.SetXN(2, m_shape_bounds.Right);
			m_shadow_ctrl.SetYN(2, m_shape_bounds.Top);
			m_shadow_ctrl.SetXN(3, m_shape_bounds.Left);
			m_shadow_ctrl.SetYN(3, m_shape_bounds.Top);
			m_shadow_ctrl.line_color(new RGBA_Floats(0, 0.3, 0.5, 0.3));
		}
示例#21
0
		public void DoTrace()
		{
			CreateScene();
			RectangleInt rect = new RectangleInt(0, 0, size.x, size.y);
			if (destImage == null || destImage.Width != rect.Width || destImage.Height != rect.Height)
			{
				destImage = new ImageBuffer(rect.Width, rect.Height, 32, new BlenderBGRA());
			}

			raytracer.RayTraceScene(rect, scene);
			raytracer.CopyColorBufferToImage(destImage, rect);
		}
		public override bool LoadImageData(String fileName, ImageBuffer destImage)
		{
			if (System.IO.File.Exists(fileName))
			{
				Bitmap m_WidowsBitmap = new Bitmap(fileName);
				return ConvertBitmapToImage(destImage, m_WidowsBitmap);
			}
			else
			{
				throw new System.Exception(string.Format("Image file not found: {0}", fileName));
			}
		}
		public RandomFillWidget(Point2D size)
		{
			LocalBounds = new RectangleDouble(0, 0, size.x, size.y);
			image = new ImageBuffer(size.x, size.y, 32, new BlenderBGRA());

			Random rand = new Random();
			Graphics2D imageGraphics = image.NewGraphics2D();
			for (int i = 0; i < 30; i++)
			{
				imageGraphics.Circle(rand.NextDouble() * image.Width, rand.NextDouble() * image.Height, rand.NextDouble() * 10 + 5, RGBA_Bytes.Red);
			}
		}
		public void TextWidgetVisibleTest()
		{
			{
				GuiWidget rectangleWidget = new GuiWidget(100, 50);
				TextWidget itemToAdd = new TextWidget("test Item", 10, 10);
				rectangleWidget.AddChild(itemToAdd);
				rectangleWidget.DoubleBuffer = true;
				rectangleWidget.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White);
				rectangleWidget.OnDraw(rectangleWidget.BackBuffer.NewGraphics2D());

				ImageBuffer textOnly = new ImageBuffer(75, 20, 32, new BlenderBGRA());
				textOnly.NewGraphics2D().Clear(RGBA_Bytes.White);

				textOnly.NewGraphics2D().DrawString("test Item", 1, 1);

				if (saveImagesForDebug)
				{
					ImageTgaIO.Save(rectangleWidget.BackBuffer, "-rectangleWidget.tga");
					//ImageTgaIO.Save(itemToAdd.Children[0].BackBuffer, "-internalTextWidget.tga");
					ImageTgaIO.Save(textOnly, "-textOnly.tga");
				}

				Assert.IsTrue(rectangleWidget.BackBuffer.FindLeastSquaresMatch(textOnly, 1), "TextWidgets need to be drawing.");
				rectangleWidget.Close();
			}

			{
				GuiWidget rectangleWidget = new GuiWidget(100, 50);
				TextEditWidget itemToAdd = new TextEditWidget("test Item", 10, 10);
				rectangleWidget.AddChild(itemToAdd);
				rectangleWidget.DoubleBuffer = true;
				rectangleWidget.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White);
				rectangleWidget.OnDraw(rectangleWidget.BackBuffer.NewGraphics2D());

				ImageBuffer textOnly = new ImageBuffer(75, 20, 32, new BlenderBGRA());
				textOnly.NewGraphics2D().Clear(RGBA_Bytes.White);

				TypeFacePrinter stringPrinter = new TypeFacePrinter("test Item", 12);
				IVertexSource offsetText = new VertexSourceApplyTransform(stringPrinter, Affine.NewTranslation(1, -stringPrinter.LocalBounds.Bottom));
				textOnly.NewGraphics2D().Render(offsetText, RGBA_Bytes.Black);

				if (saveImagesForDebug)
				{
					ImageTgaIO.Save(rectangleWidget.BackBuffer, "-rectangleWidget.tga");
					//ImageTgaIO.Save(itemToAdd.Children[0].BackBuffer, "-internalTextWidget.tga");
					ImageTgaIO.Save(textOnly, "-textOnly.tga");
				}

				Assert.IsTrue(rectangleWidget.BackBuffer.FindLeastSquaresMatch(textOnly, 1), "TextWidgets need to be drawing.");
				rectangleWidget.Close();
			}
		}
示例#25
0
		private void AddWatermark()
		{
			string imagePathAndFile = Path.Combine(ApplicationDataStorage.Instance.ApplicationStaticDataPath, "OEMSettings", "watermark.png");
            if (File.Exists(imagePathAndFile))
            {
                ImageBuffer wattermarkImage = new ImageBuffer();
                ImageBMPIO.LoadImageData(imagePathAndFile, wattermarkImage);
                GuiWidget watermarkWidget = new ImageWidget(wattermarkImage);
                watermarkWidget.VAnchor = Agg.UI.VAnchor.ParentCenter;
                watermarkWidget.HAnchor = Agg.UI.HAnchor.ParentCenter;
                this.AddChildToBackground(watermarkWidget);
            }
		}
		public void pixel_high_res(ImageBuffer sourceImage, RGBA_Bytes[] destBuffer, int destBufferOffset, int x, int y)
		{
			int r, g, b, a;
			r = g = b = a = LineAABasics.line_subpixel_scale * LineAABasics.line_subpixel_scale / 2;

			int weight;
			int x_lr = x >> LineAABasics.line_subpixel_shift;
			int y_lr = y >> LineAABasics.line_subpixel_shift;

			x &= LineAABasics.line_subpixel_mask;
			y &= LineAABasics.line_subpixel_mask;
			int sourceOffset;
			byte[] ptr = sourceImage.GetPixelPointerXY(x_lr, y_lr, out sourceOffset);

			weight = (LineAABasics.line_subpixel_scale - x) *
					 (LineAABasics.line_subpixel_scale - y);
			r += weight * ptr[sourceOffset + ImageBuffer.OrderR];
			g += weight * ptr[sourceOffset + ImageBuffer.OrderG];
			b += weight * ptr[sourceOffset + ImageBuffer.OrderB];
			a += weight * ptr[sourceOffset + ImageBuffer.OrderA];

			sourceOffset += sourceImage.GetBytesBetweenPixelsInclusive();

			weight = x * (LineAABasics.line_subpixel_scale - y);
			r += weight * ptr[sourceOffset + ImageBuffer.OrderR];
			g += weight * ptr[sourceOffset + ImageBuffer.OrderG];
			b += weight * ptr[sourceOffset + ImageBuffer.OrderB];
			a += weight * ptr[sourceOffset + ImageBuffer.OrderA];

			ptr = sourceImage.GetPixelPointerXY(x_lr, y_lr + 1, out sourceOffset);

			weight = (LineAABasics.line_subpixel_scale - x) * y;
			r += weight * ptr[sourceOffset + ImageBuffer.OrderR];
			g += weight * ptr[sourceOffset + ImageBuffer.OrderG];
			b += weight * ptr[sourceOffset + ImageBuffer.OrderB];
			a += weight * ptr[sourceOffset + ImageBuffer.OrderA];

			sourceOffset += sourceImage.GetBytesBetweenPixelsInclusive();

			weight = x * y;
			r += weight * ptr[sourceOffset + ImageBuffer.OrderR];
			g += weight * ptr[sourceOffset + ImageBuffer.OrderG];
			b += weight * ptr[sourceOffset + ImageBuffer.OrderB];
			a += weight * ptr[sourceOffset + ImageBuffer.OrderA];

			destBuffer[destBufferOffset].red = (byte)(r >> LineAABasics.line_subpixel_shift * 2);
			destBuffer[destBufferOffset].green = (byte)(g >> LineAABasics.line_subpixel_shift * 2);
			destBuffer[destBufferOffset].blue = (byte)(b >> LineAABasics.line_subpixel_shift * 2);
			destBuffer[destBufferOffset].alpha = (byte)(a >> LineAABasics.line_subpixel_shift * 2);
		}
		private void AddWatermark()
		{
			string imagePathAndFile = Path.Combine("OEMSettings", "watermark.png");
			if (StaticData.Instance.FileExists(imagePathAndFile))
			{
				ImageBuffer wattermarkImage = new ImageBuffer();
				StaticData.Instance.LoadImage(imagePathAndFile, wattermarkImage);

				GuiWidget watermarkWidget = new ImageWidget(wattermarkImage);
				watermarkWidget.VAnchor = Agg.UI.VAnchor.ParentCenter;
				watermarkWidget.HAnchor = Agg.UI.HAnchor.ParentCenter;
				this.AddChildToBackground(watermarkWidget);
			}
		}
示例#28
0
		public static void DoThreshold(ImageBuffer result, ImageBuffer sourceImage, int threshold, TestThreshold testFunction)
		{
			if (sourceImage.BitDepth != result.BitDepth)
			{
				throw new NotImplementedException("All the images have to be the same bit depth.");
			}
			if (sourceImage.Width != result.Width || sourceImage.Height != result.Height)
			{
				throw new Exception("All images must be the same size.");
			}

			switch (sourceImage.BitDepth)
			{
				case 32:
					{
						int height = sourceImage.Height;
						int width = sourceImage.Width;
						byte[] resultBuffer = result.GetBuffer();
						byte[] sourceBuffer = sourceImage.GetBuffer();
						for (int y = 0; y < height; y++)
						{
							int offset = sourceImage.GetBufferOffsetY(y);

							for (int x = 0; x < width; x++)
							{
								if (testFunction(sourceBuffer, offset, threshold))
								{
									resultBuffer[offset + 0] = (byte)255;
									resultBuffer[offset + 1] = (byte)255;
									resultBuffer[offset + 2] = (byte)255;
									resultBuffer[offset + 3] = (byte)255;
								}
								else
								{
									resultBuffer[offset + 0] = (byte)0;
									resultBuffer[offset + 1] = (byte)0;
									resultBuffer[offset + 2] = (byte)0;
									resultBuffer[offset + 3] = (byte)0;
								}
								offset += 4;
							}
						}
					}
					break;

				default:
					throw new NotImplementedException();
			}
		}
示例#29
0
		public static void DoSubtract(ImageBuffer result, ImageBuffer imageToSubtractFrom, ImageBuffer imageToSubtract)
		{
			if (lookupSubtractAndClamp == null)
			{
				CreateLookup();
			}

			if (imageToSubtractFrom.BitDepth != imageToSubtract.BitDepth || imageToSubtract.BitDepth != result.BitDepth)
			{
				throw new NotImplementedException("All the images have to be the same bit depth.");
			}
			if (imageToSubtractFrom.Width != imageToSubtract.Width || imageToSubtractFrom.Height != imageToSubtract.Height
				|| imageToSubtractFrom.Width != result.Width || imageToSubtractFrom.Height != result.Height)
			{
				throw new Exception("All images must be the same size.");
			}

			switch (imageToSubtractFrom.BitDepth)
			{
				case 32:
					{
						int height = imageToSubtractFrom.Height;
						int width = imageToSubtractFrom.Width;
						byte[] resultBuffer = result.GetBuffer();
						byte[] imageABuffer = imageToSubtractFrom.GetBuffer();
						byte[] imageBBuffer = imageToSubtract.GetBuffer();
						for (int y = 0; y < height; y++)
						{
							int offset = imageToSubtractFrom.GetBufferOffsetY(y);

							for (int x = 0; x < width; x++)
							{
								resultBuffer[offset] = (byte)lookupSubtractAndClamp[imageABuffer[offset] - imageBBuffer[offset] + 255]; // add 255 to make sure not < 0
								offset++;
								resultBuffer[offset] = (byte)lookupSubtractAndClamp[imageABuffer[offset] - imageBBuffer[offset] + 255];
								offset++;
								resultBuffer[offset] = (byte)lookupSubtractAndClamp[imageABuffer[offset] - imageBBuffer[offset] + 255];
								offset++;
								resultBuffer[offset] = 255;
								offset++;
							}
						}
					}
					break;

				default:
					throw new NotImplementedException();
			}
		}
示例#30
0
		private bool ClearAndCheckImage(ImageBuffer image, RGBA_Bytes color)
		{
			image.NewGraphics2D().Clear(color);

			for (int y = 0; y < image.Height; y++)
			{
				for (int x = 0; x < image.Width; x++)
				{
					if (image.GetPixel(x, y) != color)
					{
						return false;
					}
				}
			}

			return true;
		}
示例#31
0
 public void AddImage(ImageBuffer imageBuffer)
 {
     imageList.Add(imageBuffer);
 }