예제 #1
0
        bool ClearAndCheckImageFloat(ImageBufferFloat image, RGBA_Floats color)
        {
            image.NewGraphics2D().Clear(color);

            switch (image.BitDepth)
            {
                case 128:
                    for (int y = 0; y < image.Height; y++)
                    {
                        for (int x = 0; x < image.Width; x++)
                        {
                            RGBA_Floats pixelColor = image.GetPixel(x, y);
                            if (pixelColor != color)
                            {
                                return false;
                            }
                        }
                    }
                    break;

                default:
                    throw new NotImplementedException();
            }

            return true;
        }
예제 #2
0
		public SolidMaterial(RGBA_Floats color, double reflection, double transparency, double gloss)
		{
			this.color = color;
			this.Reflection = reflection;
			this.Transparency = transparency;
			this.Gloss = gloss;
		}
예제 #3
0
        public RGBA_Floats Blend(RGBA_Floats other, double weight)
        {
            RGBA_Floats result = new RGBA_Floats(this);

            result = this * (1 - weight) + other * weight;
            return(result);
        }
예제 #4
0
 public RGBA_Floats(RGBA_Floats c, float a_)
 {
     red   = c.red;
     green = c.green;
     blue  = c.blue;
     alpha = a_;
 }
예제 #5
0
 public RGBA_Bytes(RGBA_Floats c)
 {
     red   = ((byte)agg_basics.uround(c.red * (double)base_mask));
     green = ((byte)agg_basics.uround(c.green * (double)base_mask));
     blue  = ((byte)agg_basics.uround(c.blue * (double)base_mask));
     alpha = ((byte)agg_basics.uround(c.alpha * (double)base_mask));
 }
예제 #6
0
		public MeshViewerWidget(Vector3 displayVolume, Vector2 bedCenter, BedShape bedShape, string startingTextMessage = "")
		{
			RenderType = RenderTypes.Shaded;
			RenderBed = true;
			RenderBuildVolume = false;
			//SetMaterialColor(1, RGBA_Bytes.LightGray, RGBA_Bytes.White);
			BedColor = new RGBA_Floats(.8, .8, .8, .7).GetAsRGBA_Bytes();
			BuildVolumeColor = new RGBA_Floats(.2, .8, .3, .2).GetAsRGBA_Bytes();

			trackballTumbleWidget = new TrackballTumbleWidget();
			trackballTumbleWidget.DrawRotationHelperCircle = false;
			trackballTumbleWidget.DrawGlContent += trackballTumbleWidget_DrawGlContent;
			trackballTumbleWidget.TransformState = TrackBallController.MouseDownType.Rotation;

			AddChild(trackballTumbleWidget);

			CreatePrintBed(displayVolume, bedCenter, bedShape);

			trackballTumbleWidget.AnchorAll();

			partProcessingInfo = new PartProcessingInfo(startingTextMessage);

			GuiWidget labelContainer = new GuiWidget();
			labelContainer.AnchorAll();
			labelContainer.AddChild(partProcessingInfo);
			labelContainer.Selectable = false;

			this.AddChild(labelContainer);
		}
예제 #7
0
		public PointLight(Vector3 pos, RGBA_Floats color)
			: base(pos)
		{
			Color = color;

			strength = 10;
		}
예제 #8
0
		private void CreateGraphs()
		{
			int FrameRateOffset = -15;
			RGBA_Floats FrameRateControlColor = new RGBA_Floats(1, 1, 1, 1);

			m_PotentialDrawsBudgetPosition = new Vector2(10, (double)Height + FrameRateOffset);
			m_ShowPotentialDrawsBudgetGraph = new MatterHackers.Agg.UI.CheckBox(m_PotentialDrawsBudgetPosition.x, m_PotentialDrawsBudgetPosition.y, "D:000.000");
			m_ShowPotentialDrawsBudgetGraph.TextColor = FrameRateControlColor.GetAsRGBA_Bytes();
			//m_ShowPotentialDrawsBudgetGraph.inactive_color(FrameRateControlColor);
			AddChild(m_ShowPotentialDrawsBudgetGraph);
			m_PotentialDrawsBudgetGraph = new DataViewGraph(m_PotentialDrawsBudgetPosition, 100, 100);

			m_PotentialUpdatesBudgetPosition = new Vector2(115, (double)Height + FrameRateOffset);
			m_ShowPotentialUpdatesBudgetGraph = new MatterHackers.Agg.UI.CheckBox(m_PotentialUpdatesBudgetPosition.x, m_PotentialUpdatesBudgetPosition.y, "U:000.000");
			m_ShowPotentialUpdatesBudgetGraph.TextColor = FrameRateControlColor.GetAsRGBA_Bytes();
			//m_ShowPotentialUpdatesBudgetGraph.inactive_color(FrameRateControlColor);
			AddChild(m_ShowPotentialUpdatesBudgetGraph);
			m_PotentialUpdatesBudgetGraph = new DataViewGraph(m_PotentialUpdatesBudgetPosition, 100, 100);

			m_ActualDrawsBudgetPosition = new Vector2(220, (double)Height + FrameRateOffset);
			m_ShowActualDrawsBudgetGraph = new MatterHackers.Agg.UI.CheckBox(m_ActualDrawsBudgetPosition.x, m_ActualDrawsBudgetPosition.y, "A:000.000");
			m_ShowActualDrawsBudgetGraph.TextColor = FrameRateControlColor.GetAsRGBA_Bytes();
			//m_ShowActualDrawsBudgetGraph.inactive_color(FrameRateControlColor);
			AddChild(m_ShowActualDrawsBudgetGraph);
			m_ActualDrawsBudgetGraph = new DataViewGraph(m_ActualDrawsBudgetPosition, 100, 100);
		}
예제 #9
0
		public PlaneShape(Vector3 planeNormal, double distanceFromOrigin, RGBA_Floats color, RGBA_Floats oddcolor, double reflection, double transparency)
		{
			plane.planeNormal = planeNormal;
			plane.distanceToPlaneFromOrigin = distanceFromOrigin;
			//Color = color;
			OddColor = oddcolor;
			//Transparency = transparency;
			//Reflection = reflection;
		}
예제 #10
0
		public ChessboardMaterial(RGBA_Floats coloreven, RGBA_Floats colorodd, double reflection, double transparency, double gloss, double density)
		{
			this.ColorEven = coloreven;
			this.ColorOdd = colorodd;
			this.Reflection = reflection;
			this.Transparency = transparency;
			this.Gloss = gloss;
			this.Density = density;
		}
예제 #11
0
 public ImageBufferAccessorClipFloat(IImageFloat sourceImage, RGBA_Floats bk)
     : base(sourceImage)
 {
     m_OutsideBufferColor    = new float[4];
     m_OutsideBufferColor[0] = bk.red;
     m_OutsideBufferColor[1] = bk.green;
     m_OutsideBufferColor[2] = bk.blue;
     m_OutsideBufferColor[3] = bk.alpha;
 }
예제 #12
0
        static public RGBA_Floats operator *(RGBA_Floats A, float B)
        {
            RGBA_Floats temp = new RGBA_Floats();

            temp.red   = A.red * B;
            temp.green = A.green * B;
            temp.blue  = A.blue * B;
            temp.alpha = A.alpha * B;
            return(temp);
        }
예제 #13
0
        static public RGBA_Floats operator /(RGBA_Floats A, RGBA_Floats B)
        {
            RGBA_Floats temp = new RGBA_Floats();

            temp.red   = A.red / B.red;
            temp.green = A.green / B.green;
            temp.blue  = A.blue / B.blue;
            temp.alpha = A.alpha / B.alpha;
            return(temp);
        }
예제 #14
0
        static public RGBA_Floats operator /(RGBA_Floats A, double doubleB)
        {
            float       B    = (float)doubleB;
            RGBA_Floats temp = new RGBA_Floats();

            temp.red   = A.red / B;
            temp.green = A.green / B;
            temp.blue  = A.blue / B;
            temp.alpha = A.alpha / B;
            return(temp);
        }
예제 #15
0
        public static RGBA_Floats AdjustLightness(RGBA_Floats original, double lightnessMultiplier)
        {
            double hue0To1;
            double saturation0To1;
            double lightness0To1;

            original.GetHSL(out hue0To1, out saturation0To1, out lightness0To1);
            lightness0To1 *= lightnessMultiplier;

            return(FromHSL(hue0To1, saturation0To1, lightness0To1));
        }
예제 #16
0
        public RGBA_Bytes gradient(RGBA_Bytes c_8, double k)
        {
            RGBA_Floats c = c_8.GetAsRGBA_Floats();
            RGBA_Floats ret;

            ret.red   = (float)(red + (c.red - red) * k);
            ret.green = (float)(green + (c.green - green) * k);
            ret.blue  = (float)(blue + (c.blue - blue) * k);
            ret.alpha = (float)(alpha + (c.alpha - alpha) * k);
            return(ret.GetAsRGBA_Bytes());
        }
예제 #17
0
		public void RenderSolid(IImageFloat destImage, IRasterizer rasterizer, IScanlineCache scanLine, RGBA_Floats color)
		{
			if (rasterizer.rewind_scanlines())
			{
				scanLine.reset(rasterizer.min_x(), rasterizer.max_x());
				while (rasterizer.sweep_scanline(scanLine))
				{
					RenderSolidSingleScanLine(destImage, scanLine, color);
				}
			}
		}
예제 #18
0
        static public RGBA_Bytes operator *(RGBA_Bytes A, double doubleB)
        {
            float       B    = (float)doubleB;
            RGBA_Floats temp = new RGBA_Floats();

            temp.red   = A.red / 255.0f * B;
            temp.green = A.green / 255.0f * B;
            temp.blue  = A.blue / 255.0f * B;
            temp.alpha = A.alpha / 255.0f * B;
            return(new RGBA_Bytes(temp));
        }
        public override void OnDraw(Graphics2D graphics2D)
        {
            ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect());

#if SourceDepthFloat
            ImageClippingProxyFloat clippingProxy = new ImageClippingProxyFloat(graphics2D.DestImageFloat);

            clippingProxy.clear(new RGBA_Floats(1.0, 1.0, 1.0));
            clippingProxy.CopyFrom(m_TempDestImage, new RectangleInt(0, 0, (int)Width, (int)Height), 110, 35);
#else
            ImageClippingProxy clippingProxy = new ImageClippingProxy(widgetsSubImage);

            clippingProxy.clear(new ColorF(1.0, 1.0, 1.0));
            clippingProxy.CopyFrom(m_TempDestImage, new RectangleInt(0, 0, (int)Width, (int)Height), 110, 35);
#endif

            string   buf = string.Format("NSteps={0:F0}", m_num_steps);
            gsv_text t   = new gsv_text();
            t.start_point(200.0, 430);
            t.SetFontSize(10.0);
            t.text(buf);

            Stroke pt = new Stroke(t);
            pt.Width = 1.5;

            m_Rasterizer.add_path(pt);
#if SourceDepthFloat
            RGBA_Floats colorBlack = new RGBA_Floats(0, 0, 0);
#else
            Color colorBlack = new Color(0, 0, 0);
#endif
            ScanlineRenderer scanlineRenderer = new ScanlineRenderer();
            scanlineRenderer.RenderSolid(clippingProxy, m_Rasterizer, m_ScanlinePacked, colorBlack);

            if (m_time1 != m_time2 && m_num_pix > 0.0)
            {
                buf = string.Format("{0:F2} Kpix/sec", m_num_pix / (m_time2 - m_time1));
                t.start_point(200.0, 450);
                t.text(buf);
                m_Rasterizer.add_path(pt);
                scanlineRenderer.RenderSolid(clippingProxy, m_Rasterizer, m_ScanlinePacked, colorBlack);
            }

            if (filterSelectionButtons.SelectedIndex >= 14)
            {
                m_radius.Visible = true;
            }
            else
            {
                m_radius.Visible = true;
            }

            base.OnDraw(graphics2D);
        }
예제 #20
0
        public static IColorType AdjustLightness(this IColorType original, double lightnessMultiplier)
        {
            double hue0To1;
            double saturation0To1;
            double lightness0To1;

            RGBA_Floats colorF = original is RGBA_Floats ? (RGBA_Floats)original : original.GetAsRGBA_Floats();

            colorF.GetHSL(out hue0To1, out saturation0To1, out lightness0To1);
            lightness0To1 *= lightnessMultiplier;

            return(RGBA_Floats.FromHSL(hue0To1, saturation0To1, lightness0To1));
        }
예제 #21
0
        public static RGBA_Floats from_wavelength(float wl, float gamma)
        {
            RGBA_Floats t = new RGBA_Floats(0.0f, 0.0f, 0.0f);

            if (wl >= 380.0 && wl <= 440.0)
            {
                t.red  = (float)(-1.0 * (wl - 440.0) / (440.0 - 380.0));
                t.blue = 1.0f;
            }
            else if (wl >= 440.0 && wl <= 490.0)
            {
                t.green = (float)((wl - 440.0) / (490.0 - 440.0));
                t.blue  = 1.0f;
            }
            else if (wl >= 490.0 && wl <= 510.0)
            {
                t.green = 1.0f;
                t.blue  = (float)(-1.0 * (wl - 510.0) / (510.0 - 490.0));
            }
            else if (wl >= 510.0 && wl <= 580.0)
            {
                t.red   = (float)((wl - 510.0) / (580.0 - 510.0));
                t.green = 1.0f;
            }
            else if (wl >= 580.0 && wl <= 645.0)
            {
                t.red   = 1.0f;
                t.green = (float)(-1.0 * (wl - 645.0) / (645.0 - 580.0));
            }
            else if (wl >= 645.0 && wl <= 780.0)
            {
                t.red = 1.0f;
            }

            float s = 1.0f;

            if (wl > 700.0)
            {
                s = (float)(0.3 + 0.7 * (780.0 - wl) / (780.0 - 700.0));
            }
            else if (wl < 420.0)
            {
                s = (float)(0.3 + 0.7 * (wl - 380.0) / (420.0 - 380.0));
            }

            t.red   = (float)Math.Pow(t.red * s, gamma);
            t.green = (float)Math.Pow(t.green * s, gamma);
            t.blue  = (float)Math.Pow(t.blue * s, gamma);

            return(t);
        }
예제 #22
0
        public static RGBA_Floats GetTweenColor(RGBA_Floats Color1, RGBA_Floats Color2, double RatioOf2)
        {
            if (RatioOf2 <= 0)
            {
                return(new RGBA_Floats(Color1));
            }

            if (RatioOf2 >= 1.0)
            {
                return(new RGBA_Floats(Color2));
            }

            // figure out how much of each color we should be.
            double RatioOf1 = 1.0 - RatioOf2;

            return(new RGBA_Floats(
                       Color1.red * RatioOf1 + Color2.red * RatioOf2,
                       Color1.green * RatioOf1 + Color2.green * RatioOf2,
                       Color1.blue * RatioOf1 + Color2.blue * RatioOf2));
        }
예제 #23
0
        public static RGBA_Floats ComponentMax(RGBA_Floats a, RGBA_Floats b)
        {
            RGBA_Floats result = a;

            if (result.red < b.red)
            {
                result.red = b.red;
            }
            if (result.green < b.green)
            {
                result.green = b.green;
            }
            if (result.blue < b.blue)
            {
                result.blue = b.blue;
            }
            if (result.alpha < b.alpha)
            {
                result.alpha = b.alpha;
            }

            return(result);
        }
예제 #24
0
		private void RenderSolidSingleScanLine(IImageFloat destImage, IScanlineCache scanLine, RGBA_Floats color)
		{
			int y = scanLine.y();
			int num_spans = scanLine.num_spans();
			ScanlineSpan scanlineSpan = scanLine.begin();

			byte[] ManagedCoversArray = scanLine.GetCovers();
			for (; ; )
			{
				int x = scanlineSpan.x;
				if (scanlineSpan.len > 0)
				{
					destImage.blend_solid_hspan(x, y, scanlineSpan.len, color, ManagedCoversArray, scanlineSpan.cover_index);
				}
				else
				{
					int x2 = (x - (int)scanlineSpan.len - 1);
					destImage.blend_hline(x, y, x2, color, ManagedCoversArray[scanlineSpan.cover_index]);
				}
				if (--num_spans == 0) break;
				scanlineSpan = scanLine.GetNextScanlineSpan();
			}
		}
예제 #25
0
		public RGBA_Floats(RGBA_Floats c)
			: this(c, c.alpha)
		{
		}
        private void transform_image(double angle)
        {
            double width  = m_TempDestImage.Width;
            double height = m_TempDestImage.Height;

#if SourceDepthFloat
            ImageClippingProxyFloat clippedDest = new ImageClippingProxyFloat(m_TempDestImage);
#else
            ImageClippingProxy clippedDest = new ImageClippingProxy(m_TempDestImage);
#endif

            clippedDest.clear(new ColorF(1.0, 1.0, 1.0));

            Affine src_mtx = Affine.NewIdentity();
            src_mtx *= Affine.NewTranslation(-width / 2.0, -height / 2.0);
            src_mtx *= Affine.NewRotation(angle * Math.PI / 180.0);
            src_mtx *= Affine.NewTranslation(width / 2.0, height / 2.0);

            Affine img_mtx = new Affine(src_mtx);
            img_mtx.invert();

            double r = width;
            if (height < r)
            {
                r = height;
            }

            r *= 0.5;
            r -= 4.0;
            VertexSource.Ellipse       ell = new MatterHackers.Agg.VertexSource.Ellipse(width / 2.0, height / 2.0, r, r, 200);
            VertexSourceApplyTransform tr  = new VertexSourceApplyTransform(ell, src_mtx);

            m_num_pix += r * r * Math.PI;

#if SourceDepthFloat
            span_interpolator_linear_float interpolator = new span_interpolator_linear_float(img_mtx);
#else
            span_interpolator_linear interpolator = new span_interpolator_linear(img_mtx);
#endif

            ImageFilterLookUpTable filter = new ImageFilterLookUpTable();
            bool norm = m_normalize.Checked;

#if SourceDepthFloat
            ImageBufferAccessorClipFloat source = new ImageBufferAccessorClipFloat(m_RotatedImage, RGBA_Floats.rgba_pre(0, 0, 0, 0).ToColorF());
#else
            ImageBufferAccessorClip source = new ImageBufferAccessorClip(m_RotatedImage, ColorF.rgba_pre(0, 0, 0, 0).ToColor());
#endif
            IImageFilterFunction filterFunction   = null;
            ScanlineRenderer     scanlineRenderer = new ScanlineRenderer();

            switch (filterSelectionButtons.SelectedIndex)
            {
            case 0:
            {
#if SourceDepthFloat
                span_image_filter_float spanGenerator;
#else
                span_image_filter spanGenerator;
#endif

                switch (source.SourceImage.BitDepth)
                {
                case 24:
#if SourceDepthFloat
                    throw new NotImplementedException();
#else
                    spanGenerator = new span_image_filter_rgb_nn(source, interpolator);
#endif
                    break;

                case 32:
#if SourceDepthFloat
                    throw new NotImplementedException();
#else
                    spanGenerator = new span_image_filter_rgba_nn(source, interpolator);
#endif
                    break;

                default:
                    throw new NotImplementedException("only support 24 and 32 bit");
                }

                m_Rasterizer.add_path(tr);
                scanlineRenderer.GenerateAndRender(m_Rasterizer, m_ScanlineUnpacked, clippedDest, m_SpanAllocator, spanGenerator);
            }
            break;

            case 1:
            {
#if SourceDepthFloat
                span_image_filter_float spanGenerator;
#else
                span_image_filter spanGenerator;
#endif
                switch (source.SourceImage.BitDepth)
                {
                case 24:
#if SourceDepthFloat
                    throw new NotImplementedException();
#else
                    spanGenerator = new span_image_filter_rgb_bilinear(source, interpolator);
#endif
                    break;

                case 32:
#if SourceDepthFloat
                    throw new NotImplementedException();
#else
                    spanGenerator = new span_image_filter_rgba_bilinear(source, interpolator);
#endif
                    break;

#if SourceDepthFloat
                case 128:
                    spanGenerator = new span_image_filter_rgba_bilinear_float(source, interpolator);
                    break;
#endif

                default:
                    throw new NotImplementedException("only support 24 and 32 bit");
                }
                m_Rasterizer.add_path(tr);
                scanlineRenderer.GenerateAndRender(m_Rasterizer, m_ScanlineUnpacked, clippedDest, m_SpanAllocator, spanGenerator);
            }
            break;

            case 5:
            case 6:
            case 7:
            {
                switch (filterSelectionButtons.SelectedIndex)
                {
                case 5: filter.calculate(new image_filter_hanning(), norm); break;

                case 6: filter.calculate(new image_filter_hamming(), norm); break;

                case 7: filter.calculate(new image_filter_hermite(), norm); break;
                }

#if SourceDepthFloat
                throw new NotImplementedException();
#else
                span_image_filter_rgb_2x2 spanGenerator = new span_image_filter_rgb_2x2(source, interpolator, filter);
#endif
                m_Rasterizer.add_path(tr);
#if SourceDepthFloat
                throw new NotImplementedException();
#else
                scanlineRenderer.GenerateAndRender(m_Rasterizer, m_ScanlineUnpacked, clippedDest, m_SpanAllocator, spanGenerator);
#endif
            }
            break;

            case 2:
            case 3:
            case 4:
            case 8:
            case 9:
            case 10:
            case 11:
            case 12:
            case 13:
            case 14:
            case 15:
            case 16:
            {
                switch (filterSelectionButtons.SelectedIndex)
                {
                case 2: filter.calculate(new image_filter_bicubic(), norm); break;

                case 3: filter.calculate(new image_filter_spline16(), norm); break;

                case 4: filter.calculate(new image_filter_spline36(), norm); break;

                case 8: filter.calculate(new image_filter_kaiser(), norm); break;

                case 9: filter.calculate(new image_filter_quadric(), norm); break;

                case 10: filter.calculate(new image_filter_catrom(), norm); break;

                case 11: filter.calculate(new image_filter_gaussian(), norm); break;

                case 12: filter.calculate(new image_filter_bessel(), norm); break;

                case 13: filter.calculate(new image_filter_mitchell(), norm); break;

                case 14: filter.calculate(new image_filter_sinc(m_radius.Value), norm); break;

                case 15: filter.calculate(new image_filter_lanczos(m_radius.Value), norm); break;

                case 16:
                    filterFunction = new image_filter_blackman(m_radius.Value);
                    //filterFunction = new image_filter_bilinear();
                    filter.calculate(filterFunction, norm);
                    break;
                }

#if SourceDepthFloat
                span_image_filter_float spanGenerator;
#else
                span_image_filter spanGenerator;
#endif
                switch (source.SourceImage.BitDepth)
                {
                case 24:
#if SourceDepthFloat
                    throw new NotImplementedException();
#else
                    spanGenerator = new span_image_filter_rgb(source, interpolator, filter);
#endif
                    break;

                case 32:
#if SourceDepthFloat
                    throw new NotImplementedException();
#else
                    spanGenerator = new span_image_filter_rgba(source, interpolator, filter);
#endif
                    break;

#if SourceDepthFloat
                case 128:
                    spanGenerator = new span_image_filter_rgba_float(source, interpolator, filterFunction);
                    break;
#endif

                default:
                    throw new NotImplementedException("only support 24 and 32 bit");
                }

                m_Rasterizer.add_path(tr);
                scanlineRenderer.GenerateAndRender(m_Rasterizer, m_ScanlineUnpacked, clippedDest, m_SpanAllocator, spanGenerator);
            }
            break;
            }
        }
예제 #27
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect());

            if (orignialSize.x == 0)
            {
                orignialSize.x = WindowSize.x;
                orignialSize.y = WindowSize.y;
            }

            ImageBuffer destImageWithPreMultBlender = new ImageBuffer();

            switch (widgetsSubImage.BitDepth)
            {
            case 24:
                destImageWithPreMultBlender.Attach(widgetsSubImage, new BlenderPreMultBGR());
                break;

            case 32:
                destImageWithPreMultBlender.Attach(widgetsSubImage, new BlenderPreMultBGRA());
                break;

            default:
                throw new Exception("Unknown bit depth");
            }

            ImageClippingProxy clippingProxy_pre = new ImageClippingProxy(destImageWithPreMultBlender);

            clippingProxy_pre.clear(new RGBA_Floats(1.0, 1.0, 1.0));

            Affine src_mtx = Affine.NewIdentity();

            src_mtx *= Affine.NewTranslation(-orignialSize.x / 2 - 10, -orignialSize.y / 2 - 20 - 10);
            src_mtx *= Affine.NewRotation(drawAngle.Value * Math.PI / 180.0);
            src_mtx *= Affine.NewScaling(drawScale.Value);
            src_mtx *= Affine.NewTranslation(orignialSize.x / 2, orignialSize.y / 2 + 20);

            Affine img_mtx = Affine.NewIdentity();

            img_mtx *= Affine.NewTranslation(-orignialSize.x / 2 + 10, -orignialSize.y / 2 + 20 + 10);
            img_mtx *= Affine.NewRotation(drawAngle.Value * Math.PI / 180.0);
            img_mtx *= Affine.NewScaling(drawScale.Value);
            img_mtx *= Affine.NewTranslation(orignialSize.x / 2, orignialSize.y / 2 + 20);
            img_mtx.invert();

            MatterHackers.Agg.span_allocator sa = new span_allocator();

            span_interpolator_linear interpolator = new span_interpolator_linear(img_mtx);

            span_image_filter sg;

            switch (sourceImage.BitDepth)
            {
            case 24:
            {
                ImageBufferAccessorClip source = new ImageBufferAccessorClip(sourceImage, RGBA_Floats.rgba_pre(0, 0, 0, 0).GetAsRGBA_Bytes());
                sg = new span_image_filter_rgb_bilinear_clip(source, RGBA_Floats.rgba_pre(0, 0.4, 0, 0.5), interpolator);
            }
            break;

            case 32:
            {
                ImageBufferAccessorClip source = new ImageBufferAccessorClip(sourceImage, RGBA_Floats.rgba_pre(0, 0, 0, 0).GetAsRGBA_Bytes());
                sg = new span_image_filter_rgba_bilinear_clip(source, RGBA_Floats.rgba_pre(0, 0.4, 0, 0.5), interpolator);
            }
            break;

            default:
                throw new Exception("Bad sourc depth");
            }

            ScanlineRasterizer ras = new ScanlineRasterizer();

            ras.SetVectorClipBox(0, 0, Width, Height);
            ScanlineCachePacked8 sl = new ScanlineCachePacked8();
            //scanline_unpacked_8 sl = new scanline_unpacked_8();

            double r = orignialSize.x;

            if (orignialSize.y - 60 < r)
            {
                r = orignialSize.y - 60;
            }

            VertexSource.Ellipse ell = new VertexSource.Ellipse(orignialSize.x / 2.0 + 10,
                                                                orignialSize.y / 2.0 + 20 + 10,
                                                                r / 2.0 + 16.0,
                                                                r / 2.0 + 16.0, 200);

            VertexSourceApplyTransform tr = new VertexSourceApplyTransform(ell, src_mtx);

            ras.add_path(tr);
            //clippingProxy_pre.SetClippingBox(30, 0, (int)width(), (int)height());
            ScanlineRenderer scanlineRenderer = new ScanlineRenderer();

            scanlineRenderer.GenerateAndRender(ras, sl, clippingProxy_pre, sa, sg);

            if (false)             // this is test code to check different quality settings for scalling
            {
                Vector2 screenCenter = new Vector2(Width / 2, Height / 2);
                Vector2 deltaToMouse = mousePosition - screenCenter;
                double  angleToMouse = Math.Atan2(deltaToMouse.y, deltaToMouse.x);
                double  diagonalSize = Math.Sqrt(sourceImage.Width * sourceImage.Width + sourceImage.Height * sourceImage.Height);
                double  distToMouse  = deltaToMouse.Length;
                double  scalling     = distToMouse / diagonalSize;
                graphics2D.Render(sourceImage, Width / 2, Height / 2, angleToMouse - MathHelper.Tau / 8, scalling, scalling);
            }

            base.OnDraw(graphics2D);
        }
예제 #28
0
		public void DrawTo(Graphics2D graphics2D, Mesh meshToDraw, RGBA_Bytes partColorIn, double minZ, double maxZ)
		{
			RGBA_Floats partColor = partColorIn.GetAsRGBA_Floats();
			graphics2D.Rasterizer.gamma(new gamma_power(.3));
			RenderPoint[] points = new RenderPoint[3] { new RenderPoint(), new RenderPoint(), new RenderPoint() };

			foreach (Face face in meshToDraw.Faces)
			{
				int i = 0;
				Vector3 normal = Vector3.TransformVector(face.normal, trackballTumbleWidget.ModelviewMatrix).GetNormal();
				if (normal.z > 0)
				{
					foreach (FaceEdge faceEdge in face.FaceEdges())
					{
						points[i].position = trackballTumbleWidget.GetScreenPosition(faceEdge.firstVertex.Position);

						Vector3 transformedPosition = Vector3.TransformPosition(faceEdge.firstVertex.Position, trackballTumbleWidget.ModelviewMatrix);
						points[i].z = transformedPosition.z;
						i++;
					}

					RGBA_Floats polyDrawColor = new RGBA_Floats();
					double L = Vector3.Dot(lightNormal, normal);
					if (L > 0.0f)
					{
						polyDrawColor = partColor * lightIllumination * L;
					}

					polyDrawColor = RGBA_Floats.ComponentMax(polyDrawColor, partColor * ambiantIllumination);
					for (i = 0; i < 3; i++)
					{
						double ratio = (points[i].z - minZ) / (maxZ - minZ);
						int ratioInt16 = (int)(ratio * 65536);
						points[i].color = new RGBA_Bytes(polyDrawColor.Red0To255, ratioInt16 >> 8, ratioInt16 & 0xFF);
					}


#if true
					scanline_unpacked_8 sl = new scanline_unpacked_8();
					ScanlineRasterizer ras = new ScanlineRasterizer();
					render_gouraud(graphics2D.DestImage, sl, ras, points);
#else
					IRecieveBlenderByte oldBlender = graphics2D.DestImage.GetRecieveBlender();
					graphics2D.DestImage.SetRecieveBlender(new BlenderZBuffer());
					graphics2D.Render(polygonProjected, renderColor);
					graphics2D.DestImage.SetRecieveBlender(oldBlender);
#endif

					byte[] buffer = graphics2D.DestImage.GetBuffer();
					int pixels = graphics2D.DestImage.Width * graphics2D.DestImage.Height;
					for (int pixelIndex = 0; pixelIndex < pixels; pixelIndex++)
					{
						buffer[pixelIndex * 4 + ImageBuffer.OrderR] = buffer[pixelIndex * 4 + ImageBuffer.OrderR];
						buffer[pixelIndex * 4 + ImageBuffer.OrderG] = buffer[pixelIndex * 4 + ImageBuffer.OrderR];
						buffer[pixelIndex * 4 + ImageBuffer.OrderB] = buffer[pixelIndex * 4 + ImageBuffer.OrderR];
					}
				}
			}
		}
예제 #29
0
        private void RenderSolidSingleScanLine(IImageFloat destImage, IScanlineCache scanLine, RGBA_Floats color)
        {
            int          y            = scanLine.y();
            int          num_spans    = scanLine.num_spans();
            ScanlineSpan scanlineSpan = scanLine.begin();

            byte[] ManagedCoversArray = scanLine.GetCovers();
            for (; ;)
            {
                int x = scanlineSpan.x;
                if (scanlineSpan.len > 0)
                {
                    destImage.blend_solid_hspan(x, y, scanlineSpan.len, color, ManagedCoversArray, scanlineSpan.cover_index);
                }
                else
                {
                    int x2 = (x - (int)scanlineSpan.len - 1);
                    destImage.blend_hline(x, y, x2, color, ManagedCoversArray[scanlineSpan.cover_index]);
                }
                if (--num_spans == 0)
                {
                    break;
                }
                scanlineSpan = scanLine.GetNextScanlineSpan();
            }
        }
예제 #30
0
		static public RGBA_Floats operator *(RGBA_Floats A, RGBA_Floats B)
		{
			RGBA_Floats temp = new RGBA_Floats();
			temp.red = A.red * B.red;
			temp.green = A.green * B.green;
			temp.blue = A.blue * B.blue;
			temp.alpha = A.alpha * B.alpha;
			return temp;
		}
예제 #31
0
		public double SumOfDistances(RGBA_Floats other)
		{
			double dist = Math.Abs(red - other.red) + Math.Abs(green - other.green) + Math.Abs(blue - other.blue);
			return dist;
		}
예제 #32
0
        public override void Clear(IColorType iColor)
        {
            RectangleDouble clippingRect    = GetClippingRect();
            RectangleInt    clippingRectInt = new RectangleInt((int)clippingRect.Left, (int)clippingRect.Bottom, (int)clippingRect.Right, (int)clippingRect.Top);

            if (DestImage != null)
            {
                RGBA_Bytes color  = iColor.GetAsRGBA_Bytes();
                int        width  = DestImage.Width;
                int        height = DestImage.Height;
                byte[]     buffer = DestImage.GetBuffer();
                switch (DestImage.BitDepth)
                {
                case 8:
                {
                    byte byteColor = (byte)iColor.Red0To255;
                    for (int y = clippingRectInt.Bottom; y < clippingRectInt.Top; y++)
                    {
                        int bufferOffset       = DestImage.GetBufferOffsetXY((int)clippingRect.Left, y);
                        int bytesBetweenPixels = DestImage.GetBytesBetweenPixelsInclusive();
                        for (int x = 0; x < clippingRectInt.Width; x++)
                        {
                            buffer[bufferOffset] = color.blue;
                            bufferOffset        += bytesBetweenPixels;
                        }
                    }
                }
                break;

                case 24:
                    for (int y = clippingRectInt.Bottom; y < clippingRectInt.Top; y++)
                    {
                        int bufferOffset       = DestImage.GetBufferOffsetXY((int)clippingRect.Left, y);
                        int bytesBetweenPixels = DestImage.GetBytesBetweenPixelsInclusive();
                        for (int x = 0; x < clippingRectInt.Width; x++)
                        {
                            buffer[bufferOffset + 0] = color.blue;
                            buffer[bufferOffset + 1] = color.green;
                            buffer[bufferOffset + 2] = color.red;
                            bufferOffset            += bytesBetweenPixels;
                        }
                    }
                    break;

                case 32:
                {
                    for (int y = clippingRectInt.Bottom; y < clippingRectInt.Top; y++)
                    {
                        int bufferOffset       = DestImage.GetBufferOffsetXY((int)clippingRect.Left, y);
                        int bytesBetweenPixels = DestImage.GetBytesBetweenPixelsInclusive();
                        for (int x = 0; x < clippingRectInt.Width; x++)
                        {
                            buffer[bufferOffset + 0] = color.blue;
                            buffer[bufferOffset + 1] = color.green;
                            buffer[bufferOffset + 2] = color.red;
                            buffer[bufferOffset + 3] = color.alpha;
                            bufferOffset            += bytesBetweenPixels;
                        }
                    }
                }
                break;

                default:
                    throw new NotImplementedException();
                }
            }
            else             // it is a float
            {
                if (DestImageFloat == null)
                {
                    throw new Exception("You have to have either a byte or float DestImage.");
                }

                RGBA_Floats color  = iColor.GetAsRGBA_Floats();
                int         width  = DestImageFloat.Width;
                int         height = DestImageFloat.Height;
                float[]     buffer = DestImageFloat.GetBuffer();
                switch (DestImageFloat.BitDepth)
                {
                case 128:
                    for (int y = 0; y < height; y++)
                    {
                        int bufferOffset       = DestImageFloat.GetBufferOffsetXY(clippingRectInt.Left, y);
                        int bytesBetweenPixels = DestImageFloat.GetFloatsBetweenPixelsInclusive();
                        for (int x = 0; x < clippingRectInt.Width; x++)
                        {
                            buffer[bufferOffset + 0] = color.blue;
                            buffer[bufferOffset + 1] = color.green;
                            buffer[bufferOffset + 2] = color.red;
                            buffer[bufferOffset + 3] = color.alpha;
                            bufferOffset            += bytesBetweenPixels;
                        }
                    }
                    break;

                default:
                    throw new NotImplementedException();
                }
            }
        }
예제 #33
0
		static public RGBA_Floats operator *(RGBA_Floats A, double doubleB)
		{
			float B = (float)doubleB;
			RGBA_Floats temp = new RGBA_Floats();
			temp.red = A.red * B;
			temp.green = A.green * B;
			temp.blue = A.blue * B;
			temp.alpha = A.alpha * B;
			return temp;
		}
예제 #34
0
 /// <summary>
 /// specifies the background of the scene
 /// </summary>
 /// <param name="color">the color of the background</param>
 /// <param name="ambience">the ambient lighting used [0,1]</param>
 public Background(RGBA_Floats color, double ambience)
 {
     Color = color;
     Ambience = ambience;
 }
예제 #35
0
        public override void Render(IImageByte source,
                                    double destX, double destY,
                                    double angleRadians,
                                    double inScaleX, double inScaleY)
        {
            {             // exit early if the dest and source bounds don't touch.
                // TODO: <BUG> make this do rotation and scaling
                RectangleInt sourceBounds = source.GetBounds();
                RectangleInt destBounds   = this.destImageByte.GetBounds();
                sourceBounds.Offset((int)destX, (int)destY);

                if (!RectangleInt.DoIntersect(sourceBounds, destBounds))
                {
                    if (inScaleX != 1 || inScaleY != 1 || angleRadians != 0)
                    {
                        throw new NotImplementedException();
                    }
                    return;
                }
            }

            double scaleX = inScaleX;
            double scaleY = inScaleY;

            Affine graphicsTransform = GetTransform();

            if (!graphicsTransform.is_identity())
            {
                if (scaleX != 1 || scaleY != 1 || angleRadians != 0)
                {
                    throw new NotImplementedException();
                }
                graphicsTransform.transform(ref destX, ref destY);
            }

#if false // this is an optimization that eliminates the drawing of images that have their alpha set to all 0 (happens with generated images like explosions).
            MaxAlphaFrameProperty maxAlphaFrameProperty = MaxAlphaFrameProperty::GetMaxAlphaFrameProperty(source);

            if ((maxAlphaFrameProperty.GetMaxAlpha() * color.A_Byte) / 256 <= ALPHA_CHANNEL_BITS_DIVISOR)
            {
                m_OutFinalBlitBounds.SetRect(0, 0, 0, 0);
            }
#endif
            bool IsScaled = (scaleX != 1 || scaleY != 1);

            bool IsRotated = true;
            if (Math.Abs(angleRadians) < (0.1 * MathHelper.Tau / 360))
            {
                IsRotated    = false;
                angleRadians = 0;
            }

            //bool IsMipped = false;
            double sourceOriginOffsetX = source.OriginOffset.x;
            double sourceOriginOffsetY = source.OriginOffset.y;
            bool   CanUseMipMaps       = IsScaled;
            if (scaleX > 0.5 || scaleY > 0.5)
            {
                CanUseMipMaps = false;
            }

            bool renderRequriesSourceSampling = IsScaled || IsRotated || destX != (int)destX || destY != (int)destY;

            // this is the fast drawing path
            if (renderRequriesSourceSampling)
            {
#if false // if the scaling is small enough the results can be improved by using mip maps
                if (CanUseMipMaps)
                {
                    CMipMapFrameProperty *pMipMapFrameProperty = CMipMapFrameProperty::GetMipMapFrameProperty(source);
                    double OldScaleX = scaleX;
                    double OldScaleY = scaleY;
                    const CFrameInterface *pMippedFrame = pMipMapFrameProperty.GetMipMapFrame(ref scaleX, ref scaleY);
                    if (pMippedFrame != source)
                    {
                        IsMipped             = true;
                        source               = pMippedFrame;
                        sourceOriginOffsetX *= (OldScaleX / scaleX);
                        sourceOriginOffsetY *= (OldScaleY / scaleY);
                    }

                    HotspotOffsetX *= (inScaleX / scaleX);
                    HotspotOffsetY *= (inScaleY / scaleY);
                }
#endif
                switch (ImageRenderQuality)
                {
                case TransformQuality.Fastest:
                {
                    Affine destRectTransform;
                    DrawImageGetDestBounds(source, destX, destY, sourceOriginOffsetX, sourceOriginOffsetY, scaleX, scaleY, angleRadians, out destRectTransform);

                    Affine sourceRectTransform = new Affine(destRectTransform);
                    // We invert it because it is the transform to make the image go to the same position as the polygon. LBB [2/24/2004]
                    sourceRectTransform.invert();

                    span_image_filter        spanImageFilter;
                    span_interpolator_linear interpolator   = new span_interpolator_linear(sourceRectTransform);
                    ImageBufferAccessorClip  sourceAccessor = new ImageBufferAccessorClip(source, RGBA_Floats.rgba_pre(0, 0, 0, 0).GetAsRGBA_Bytes());

                    spanImageFilter = new span_image_filter_rgba_bilinear_clip(sourceAccessor, RGBA_Floats.rgba_pre(0, 0, 0, 0), interpolator);

                    DrawImage(source, spanImageFilter, destRectTransform);
                }
                break;

                case TransformQuality.Best:
                {
                    Affine destRectTransform;
                    DrawImageGetDestBounds(source, destX, destY, sourceOriginOffsetX, sourceOriginOffsetY, scaleX, scaleY, angleRadians, out destRectTransform);

                    Affine sourceRectTransform = new Affine(destRectTransform);
                    // We invert it because it is the transform to make the image go to the same position as the polygon. LBB [2/24/2004]
                    sourceRectTransform.invert();

                    span_interpolator_linear interpolator   = new span_interpolator_linear(sourceRectTransform);
                    ImageBufferAccessorClip  sourceAccessor = new ImageBufferAccessorClip(source, RGBA_Floats.rgba_pre(0, 0, 0, 0).GetAsRGBA_Bytes());

                    //spanImageFilter = new span_image_filter_rgba_bilinear_clip(sourceAccessor, RGBA_Floats.rgba_pre(0, 0, 0, 0), interpolator);

                    IImageFilterFunction filterFunction = null;
                    filterFunction = new image_filter_blackman(4);
                    ImageFilterLookUpTable filter = new ImageFilterLookUpTable();
                    filter.calculate(filterFunction, true);

                    span_image_filter spanGenerator = new span_image_filter_rgba(sourceAccessor, interpolator, filter);

                    DrawImage(source, spanGenerator, destRectTransform);
                }
                break;
                }
#if false // this is some debug you can enable to visualize the dest bounding box
                LineFloat(BoundingRect.left, BoundingRect.top, BoundingRect.right, BoundingRect.top, WHITE);
                LineFloat(BoundingRect.right, BoundingRect.top, BoundingRect.right, BoundingRect.bottom, WHITE);
                LineFloat(BoundingRect.right, BoundingRect.bottom, BoundingRect.left, BoundingRect.bottom, WHITE);
                LineFloat(BoundingRect.left, BoundingRect.bottom, BoundingRect.left, BoundingRect.top, WHITE);
#endif
            }
            else             // TODO: this can be even faster if we do not use an intermediate buffer
            {
                Affine destRectTransform;
                DrawImageGetDestBounds(source, destX, destY, sourceOriginOffsetX, sourceOriginOffsetY, scaleX, scaleY, angleRadians, out destRectTransform);

                Affine sourceRectTransform = new Affine(destRectTransform);
                // We invert it because it is the transform to make the image go to the same position as the polygon. LBB [2/24/2004]
                sourceRectTransform.invert();

                span_interpolator_linear interpolator   = new span_interpolator_linear(sourceRectTransform);
                ImageBufferAccessorClip  sourceAccessor = new ImageBufferAccessorClip(source, RGBA_Floats.rgba_pre(0, 0, 0, 0).GetAsRGBA_Bytes());

                span_image_filter spanImageFilter = null;
                switch (source.BitDepth)
                {
                case 32:
                    spanImageFilter = new span_image_filter_rgba_nn_stepXby1(sourceAccessor, interpolator);
                    break;

                case 24:
                    spanImageFilter = new span_image_filter_rgb_nn_stepXby1(sourceAccessor, interpolator);
                    break;

                case 8:
                    spanImageFilter = new span_image_filter_gray_nn_stepXby1(sourceAccessor, interpolator);
                    break;

                default:
                    throw new NotImplementedException();
                }
                //spanImageFilter = new span_image_filter_rgba_nn(sourceAccessor, interpolator);

                DrawImage(source, spanImageFilter, destRectTransform);
                DestImage.MarkImageChanged();
            }
        }
예제 #36
0
        public override void OnMouseMove(MouseEventArgs mouseEvent)
        {
            base.OnMouseMove(mouseEvent);

            if (trackBallController.CurrentTrackingType != TrackBallController.MouseDownType.None)
            {
                Vector2 lastMouseMovePoint;
                lastMouseMovePoint.x = mouseEvent.X;
                lastMouseMovePoint.y = mouseEvent.Y;
                trackBallController.OnMouseMove(lastMouseMovePoint);
                needRedraw = true;
                Invalidate();
            }

            if (Focused && MouseCaptured)
            {
                lastMouseMovePoint.x = mouseEvent.X;
                lastMouseMovePoint.y = mouseEvent.Y;

                cameraData = cameraDataAtStartOfMouseTracking;
                //cameraData.Rotate(trackBallRotation);

                //OrientCamera();
            }
            
            lastMouseMovePoint.x = mouseEvent.X;
            lastMouseMovePoint.y = mouseEvent.Y;

            Ray rayAtPoint = scene.camera.GetRay(lastMouseMovePoint.x, lastMouseMovePoint.y);

            IntersectInfo info = raytracer.TestIntersection(rayAtPoint, scene);
            if (info != null)
            {
                rayAtPoint.maxDistanceToConsider = double.PositiveInfinity;
                mouseOverColor = raytracer.CalculateColor(rayAtPoint, scene);
            }
        }
예제 #37
0
 public void RenderSolid(IImageFloat destImage, IRasterizer rasterizer, IScanlineCache scanLine, RGBA_Floats color)
 {
     if (rasterizer.rewind_scanlines())
     {
         scanLine.reset(rasterizer.min_x(), rasterizer.max_x());
         while (rasterizer.sweep_scanline(scanLine))
         {
             RenderSolidSingleScanLine(destImage, scanLine, color);
         }
     }
 }
예제 #38
0
		static public RGBA_Bytes operator *(RGBA_Bytes A, double doubleB)
		{
			float B = (float)doubleB;
			RGBA_Floats temp = new RGBA_Floats();
			temp.red = A.red / 255.0f * B;
			temp.green = A.green / 255.0f * B;
			temp.blue = A.blue / 255.0f * B;
			temp.alpha = A.alpha / 255.0f * B;
			return new RGBA_Bytes(temp);
		}
예제 #39
0
		public RGBA_Floats(RGBA_Floats c, float a_)
		{
			red = c.red;
			green = c.green;
			blue = c.blue;
			alpha = a_;
		}
예제 #40
0
		public static RGBA_Floats from_wavelength(float wl, float gamma)
		{
			RGBA_Floats t = new RGBA_Floats(0.0f, 0.0f, 0.0f);

			if (wl >= 380.0 && wl <= 440.0)
			{
				t.red = (float)(-1.0 * (wl - 440.0) / (440.0 - 380.0));
				t.blue = 1.0f;
			}
			else if (wl >= 440.0 && wl <= 490.0)
			{
				t.green = (float)((wl - 440.0) / (490.0 - 440.0));
				t.blue = 1.0f;
			}
			else if (wl >= 490.0 && wl <= 510.0)
			{
				t.green = 1.0f;
				t.blue = (float)(-1.0 * (wl - 510.0) / (510.0 - 490.0));
			}
			else if (wl >= 510.0 && wl <= 580.0)
			{
				t.red = (float)((wl - 510.0) / (580.0 - 510.0));
				t.green = 1.0f;
			}
			else if (wl >= 580.0 && wl <= 645.0)
			{
				t.red = 1.0f;
				t.green = (float)(-1.0 * (wl - 645.0) / (645.0 - 580.0));
			}
			else if (wl >= 645.0 && wl <= 780.0)
			{
				t.red = 1.0f;
			}

			float s = 1.0f;
			if (wl > 700.0) s = (float)(0.3 + 0.7 * (780.0 - wl) / (780.0 - 700.0));
			else if (wl < 420.0) s = (float)(0.3 + 0.7 * (wl - 380.0) / (420.0 - 380.0));

			t.red = (float)Math.Pow(t.red * s, gamma);
			t.green = (float)Math.Pow(t.green * s, gamma);
			t.blue = (float)Math.Pow(t.blue * s, gamma);

			return t;
		}
예제 #41
0
		public static RGBA_Floats AdjustLightness(RGBA_Floats original, double lightnessMultiplier)
		{
			double hue0To1;
			double saturation0To1;
			double lightness0To1;
			original.GetHSL(out hue0To1, out saturation0To1, out lightness0To1);
			lightness0To1 *= lightnessMultiplier;

			return FromHSL(hue0To1, saturation0To1, lightness0To1);
		}
예제 #42
0
        public double SumOfDistances(RGBA_Floats other)
        {
            double dist = Math.Abs(red - other.red) + Math.Abs(green - other.green) + Math.Abs(blue - other.blue);

            return(dist);
        }
예제 #43
0
		static public RGBA_Floats operator /(RGBA_Floats A, float B)
		{
			RGBA_Floats temp = new RGBA_Floats();
			temp.red = A.red / B;
			temp.green = A.green / B;
			temp.blue = A.blue / B;
			temp.alpha = A.alpha / B;
			return temp;
		}
예제 #44
0
		public static RGBA_Floats GetTweenColor(RGBA_Floats Color1, RGBA_Floats Color2, double RatioOf2)
		{
			if (RatioOf2 <= 0)
			{
				return new RGBA_Floats(Color1);
			}

			if (RatioOf2 >= 1.0)
			{
				return new RGBA_Floats(Color2);
			}

			// figure out how much of each color we should be.
			double RatioOf1 = 1.0 - RatioOf2;
			return new RGBA_Floats(
				Color1.red * RatioOf1 + Color2.red * RatioOf2,
				Color1.green * RatioOf1 + Color2.green * RatioOf2,
				Color1.blue * RatioOf1 + Color2.blue * RatioOf2);
		}
예제 #45
0
		public static RGBA_Floats ComponentMax(RGBA_Floats a, RGBA_Floats b)
		{
			RGBA_Floats result = a;
			if (result.red < b.red) result.red = b.red;
			if (result.green < b.green) result.green = b.green;
			if (result.blue < b.blue) result.blue = b.blue;
			if (result.alpha < b.alpha) result.alpha = b.alpha;

			return result;
		}
예제 #46
0
 public static RGBA_Floats rgba_pre(RGBA_Floats c, float a)
 {
     return(new RGBA_Floats(c, a).premultiply());
 }
예제 #47
0
		public static RGBA_Floats rgba_pre(RGBA_Floats c, float a)
		{
			return new RGBA_Floats(c, a).premultiply();
		}
예제 #48
0
 public RGBA_Floats(RGBA_Floats c)
     : this(c, c.alpha)
 {
 }
예제 #49
0
		public RGBA_Floats Blend(RGBA_Floats other, double weight)
		{
			RGBA_Floats result = new RGBA_Floats(this);
			result = this * (1 - weight) + other * weight;
			return result;
		}
		public override void generate(RGBA_Floats[] span, int spanIndex, int x, int y, int len)
		{
			base.interpolator().begin(x + base.filter_dx_dbl(), y + base.filter_dy_dbl(), len);

			ImageBufferFloat SourceRenderingBuffer = (ImageBufferFloat)base.source().SourceImage;
			ISpanInterpolatorFloat spanInterpolator = base.interpolator();
			int bufferIndex;
			float[] fg_ptr = SourceRenderingBuffer.GetBuffer(out bufferIndex);

			unchecked
			{
				do
				{
					float tempR;
					float tempG;
					float tempB;
					float tempA;

					float x_hr;
					float y_hr;

					spanInterpolator.coordinates(out x_hr, out y_hr);

					x_hr -= base.filter_dx_dbl();
					y_hr -= base.filter_dy_dbl();

					int x_lr = (int)x_hr;
					int y_lr = (int)y_hr;
					float weight;

					tempR = tempG = tempB = tempA = 0;

					x_hr -= x_lr;
					y_hr -= y_lr;

					bufferIndex = SourceRenderingBuffer.GetBufferOffsetXY(x_lr, y_lr);

#if false
                    unsafe
                    {
                        fixed (float* pSource = fg_ptr)
                        {
                            Vector4f tempFinal = new Vector4f(0.0f, 0.0f, 0.0f, 0.0f);

                            Vector4f color0 = Vector4f.LoadAligned((Vector4f*)&pSource[bufferIndex + 0]);
                            weight = (1.0f - x_hr) * (1.0f - y_hr);
                            Vector4f weight4f = new Vector4f(weight, weight, weight, weight);
                            tempFinal = tempFinal + weight4f * color0;

                            Vector4f color1 = Vector4f.LoadAligned((Vector4f*)&pSource[bufferIndex + 4]);
                            weight = (x_hr) * (1.0f - y_hr);
                            weight4f = new Vector4f(weight, weight, weight, weight);
                            tempFinal = tempFinal + weight4f * color1;

                            y_lr++;
                            bufferIndex = SourceRenderingBuffer.GetBufferOffsetXY(x_lr, y_lr);

                            Vector4f color2 = Vector4f.LoadAligned((Vector4f*)&pSource[bufferIndex + 0]);
                            weight = (1.0f - x_hr) * (y_hr);
                            weight4f = new Vector4f(weight, weight, weight, weight);
                            tempFinal = tempFinal + weight4f * color2;

                            Vector4f color3 = Vector4f.LoadAligned((Vector4f*)&pSource[bufferIndex + 4]);
                            weight = (x_hr) * (y_hr);
                            weight4f = new Vector4f(weight, weight, weight, weight);
                            tempFinal = tempFinal + weight4f * color3;

                            RGBA_Floats color;
                            color.m_B = tempFinal.X;
                            color.m_G = tempFinal.Y;
                            color.m_R = tempFinal.Z;
                            color.m_A = tempFinal.W;
                            span[spanIndex] = color;
                        }
                    }
#else
					weight = (1.0f - x_hr) * (1.0f - y_hr);
					tempR += weight * fg_ptr[bufferIndex + ImageBuffer.OrderR];
					tempG += weight * fg_ptr[bufferIndex + ImageBuffer.OrderG];
					tempB += weight * fg_ptr[bufferIndex + ImageBuffer.OrderB];
					tempA += weight * fg_ptr[bufferIndex + ImageBuffer.OrderA];
					bufferIndex += 4;

					weight = (x_hr) * (1.0f - y_hr);
					tempR += weight * fg_ptr[bufferIndex + ImageBuffer.OrderR];
					tempG += weight * fg_ptr[bufferIndex + ImageBuffer.OrderG];
					tempB += weight * fg_ptr[bufferIndex + ImageBuffer.OrderB];
					tempA += weight * fg_ptr[bufferIndex + ImageBuffer.OrderA];

					y_lr++;
					bufferIndex = SourceRenderingBuffer.GetBufferOffsetXY(x_lr, y_lr);

					weight = (1.0f - x_hr) * (y_hr);
					tempR += weight * fg_ptr[bufferIndex + ImageBuffer.OrderR];
					tempG += weight * fg_ptr[bufferIndex + ImageBuffer.OrderG];
					tempB += weight * fg_ptr[bufferIndex + ImageBuffer.OrderB];
					tempA += weight * fg_ptr[bufferIndex + ImageBuffer.OrderA];
					bufferIndex += 4;

					weight = (x_hr) * (y_hr);
					tempR += weight * fg_ptr[bufferIndex + ImageBuffer.OrderR];
					tempG += weight * fg_ptr[bufferIndex + ImageBuffer.OrderG];
					tempB += weight * fg_ptr[bufferIndex + ImageBuffer.OrderB];
					tempA += weight * fg_ptr[bufferIndex + ImageBuffer.OrderA];

					RGBA_Floats color;
					color.red = tempR;
					color.green = tempG;
					color.blue = tempB;
					color.alpha = tempA;
					span[spanIndex] = color;
#endif
					spanIndex++;
					spanInterpolator.Next();
				} while (--len != 0);
			}
		}
예제 #51
0
		public RGBA_Bytes(RGBA_Floats c)
		{
			red = ((byte)agg_basics.uround(c.red * (double)base_mask));
			green = ((byte)agg_basics.uround(c.green * (double)base_mask));
			blue = ((byte)agg_basics.uround(c.blue * (double)base_mask));
			alpha = ((byte)agg_basics.uround(c.alpha * (double)base_mask));
		}
		public override void generate(RGBA_Floats[] span, int spanIndex, int xInt, int yInt, int len)
		{
			base.interpolator().begin(xInt + base.filter_dx_dbl(), yInt + base.filter_dy_dbl(), len);

			float f_r, f_g, f_b, f_a;

			float[] fg_ptr;

			int radius = (int)m_filterFunction.radius();
			int diameter = radius * 2;
			int start = -(int)(diameter / 2 - 1);

			int x_count;

			ISpanInterpolatorFloat spanInterpolator = base.interpolator();
			IImageBufferAccessorFloat sourceAccessor = source();

			do
			{
				float x = xInt;
				float y = yInt;
				spanInterpolator.coordinates(out x, out y);
				//x -= (float)base.filter_dx_dbl();
				//y -= (float)base.filter_dy_dbl();
				int sourceXInt = (int)x;
				int sourceYInt = (int)y;
				Vector2 sourceOrigin = new Vector2(x, y);
				Vector2 sourceSample = new Vector2(sourceXInt + start, sourceYInt + start);

				f_b = f_g = f_r = f_a = 0;

				int y_count = diameter;

				int bufferIndex;
				fg_ptr = sourceAccessor.span(sourceXInt + start, sourceYInt + start, diameter, out bufferIndex);
				float totalWeight = 0.0f;
				for (; ; )
				{
					float yweight = (float)m_filterFunction.calc_weight(System.Math.Sqrt((sourceSample.y - sourceOrigin.y) * (sourceSample.y - sourceOrigin.y)));
					x_count = (int)diameter;
					for (; ; )
					{
						float xweight = (float)m_filterFunction.calc_weight(System.Math.Sqrt((sourceSample.x - sourceOrigin.x) * (sourceSample.x - sourceOrigin.x)));
						float weight = xweight * yweight;

						f_r += weight * fg_ptr[bufferIndex + ImageBuffer.OrderR];
						f_g += weight * fg_ptr[bufferIndex + ImageBuffer.OrderG];
						f_b += weight * fg_ptr[bufferIndex + ImageBuffer.OrderB];
						f_a += weight * fg_ptr[bufferIndex + ImageBuffer.OrderA];

						totalWeight += weight;
						sourceSample.x += 1;
						if (--x_count == 0) break;
						sourceAccessor.next_x(out bufferIndex);
					}

					sourceSample.x -= diameter;

					if (--y_count == 0) break;
					sourceSample.y += 1;
					fg_ptr = sourceAccessor.next_y(out bufferIndex);
				}

				if (f_b < 0) f_b = 0; if (f_b > 1) f_b = 1;
				if (f_r < 0) f_r = 0; if (f_r > 1) f_r = 1;
				if (f_g < 0) f_g = 0; if (f_g > 1) f_g = 1;

				span[spanIndex].red = f_r;
				span[spanIndex].green = f_g;
				span[spanIndex].blue = f_b;
				span[spanIndex].alpha = 1;// f_a;

				spanIndex++;
				spanInterpolator.Next();
			} while (--len != 0);
		}
예제 #53
0
		public ImageBufferAccessorClipFloat(IImageFloat sourceImage, RGBA_Floats bk)
			: base(sourceImage)
		{
			m_OutsideBufferColor = new float[4];
			m_OutsideBufferColor[0] = bk.red;
			m_OutsideBufferColor[1] = bk.green;
			m_OutsideBufferColor[2] = bk.blue;
			m_OutsideBufferColor[3] = bk.alpha;
		}
예제 #54
0
        private void AddAxisMarker()
        {
            int count = 10;
            double size = .1;
            for (int i = 1; i < count + 1; i++)
            {
                RGBA_Floats xColor = new RGBA_Floats(1, i / (double)count, i / (double)count);
                RayTracer.SolidMaterial xMaterial = new RayTracer.SolidMaterial(xColor, 0, 0.0, 2.0);
                RayTracer.BoxShape xBox = new RayTracer.BoxShape(new Vector3(i * size, 0, 0), new Vector3(i * size + size, size, size), xMaterial);
                renderCollection.Add(xBox);

                RGBA_Floats yColor = new RGBA_Floats(i / (double)count, 1, i / (double)count);
                RayTracer.SolidMaterial yMaterial = new RayTracer.SolidMaterial(yColor, 0, 0.0, 2.0);
                RayTracer.BoxShape yBox = new RayTracer.BoxShape(new Vector3(0, i * size, 0), new Vector3(size, i * size + size, size), yMaterial);
                //yBox.Transform.Position += new Vector3D(1, 1, 1);
                renderCollection.Add(yBox);

                RGBA_Floats zColor = new RGBA_Floats(i / (double)count, i / (double)count, 1);
                RayTracer.SolidMaterial zMaterial = new RayTracer.SolidMaterial(zColor, 0, 0.0, 2.0);
                RayTracer.BoxShape zBox = new RayTracer.BoxShape(new Vector3(0, 0, i * size), new Vector3(size, size, i * size + size), zMaterial);
                renderCollection.Add(zBox);
            }
        }