示例#1
0
        //------------------------------------------------------------------------
        public Perspective trans_perspectivemultiply_inv(Affine m)
        {
            Affine t = m;

            t.invert();
            return(multiply(t));
        }
示例#2
0
		public void invert_test()
		{
			Affine a = Affine.NewIdentity();
			a.translate(10, 10);
			Affine b = new Affine(a);
			b.invert();

			double x = 100;
			double y = 100;
			double newx = x;
			double newy = y;

			a.transform(ref newx, ref newy);
			b.transform(ref newx, ref newy);
			Assert.AreEqual(x, newx, .001);
			Assert.AreEqual(y, newy, .001);
		}
示例#3
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 scalling
				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 optomization 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 scalling 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
				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);
#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 intermediat 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();
			}
		}
示例#4
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect());

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

            ImageClippingProxy clippingProxy = new ImageClippingProxy(widgetsSubImage);

            clippingProxy.clear(new RGBA_Floats(0, 0, 0));

            m_profile.text_size(8.0);

            // draw a background to show how the alpha is working
            int RectWidth = 32;
            int xoffset   = 238;
            int yoffset   = 171;
            ScanlineRenderer scanlineRenderer = new ScanlineRenderer();

            for (int i = 0; i < 7; i++)
            {
                for (int j = 0; j < 7; j++)
                {
                    if ((i + j) % 2 != 0)
                    {
                        VertexSource.RoundedRect rect = new VertexSource.RoundedRect(i * RectWidth + xoffset, j * RectWidth + yoffset,
                                                                                     (i + 1) * RectWidth + xoffset, (j + 1) * RectWidth + yoffset, 2);
                        rect.normalize_radius();

                        ras.add_path(rect);
                        scanlineRenderer.render_scanlines_aa_solid(clippingProxy, ras, sl, new RGBA_Bytes(.9, .9, .9));
                    }
                }
            }

            double ini_scale = 1.0;

            Transform.Affine mtx1 = Affine.NewIdentity();
            mtx1 *= Affine.NewScaling(ini_scale, ini_scale);
            mtx1 *= Affine.NewTranslation(center_x, center_y);

            VertexSource.Ellipse e1 = new MatterHackers.Agg.VertexSource.Ellipse();
            e1.init(0.0, 0.0, 110.0, 110.0, 64);

            Transform.Affine mtx_g1 = Affine.NewIdentity();
            mtx_g1 *= Affine.NewScaling(ini_scale, ini_scale);
            mtx_g1 *= Affine.NewScaling(m_SaveData.m_scale, m_SaveData.m_scale);
            mtx_g1 *= Affine.NewScaling(m_scale_x, m_scale_y);
            mtx_g1 *= Affine.NewRotation(m_SaveData.m_angle);
            mtx_g1 *= Affine.NewTranslation(m_SaveData.m_center_x, m_SaveData.m_center_y);
            mtx_g1.invert();


            RGBA_Bytes[] color_profile = new RGBA_Bytes[256]; // color_type is defined in pixel_formats.h
            for (int i = 0; i < 256; i++)
            {
                color_profile[i] = new RGBA_Bytes(m_spline_r.spline()[i],
                                                  m_spline_g.spline()[i],
                                                  m_spline_b.spline()[i],
                                                  m_spline_a.spline()[i]);
            }

            VertexSourceApplyTransform t1 = new VertexSourceApplyTransform(e1, mtx1);

            IGradient innerGradient = null;

            switch (m_GradTypeRBox.SelectedIndex)
            {
            case 0:
                innerGradient = new gradient_radial();
                break;

            case 1:
                innerGradient = new gradient_diamond();
                break;

            case 2:
                innerGradient = new gradient_x();
                break;

            case 3:
                innerGradient = new gradient_xy();
                break;

            case 4:
                innerGradient = new gradient_sqrt_xy();
                break;

            case 5:
                innerGradient = new gradient_conic();
                break;
            }

            IGradient outerGradient = null;

            switch (m_GradWrapRBox.SelectedIndex)
            {
            case 0:
                outerGradient = new gradient_reflect_adaptor(innerGradient);
                break;

            case 1:
                outerGradient = new gradient_repeat_adaptor(innerGradient);
                break;

            case 2:
                outerGradient = new gradient_clamp_adaptor(innerGradient);
                break;
            }

            span_allocator           span_alloc = new span_allocator();
            color_function_profile   colors     = new color_function_profile(color_profile, m_profile.gamma());
            span_interpolator_linear inter      = new span_interpolator_linear(mtx_g1);
            span_gradient            span_gen   = new span_gradient(inter, outerGradient, colors, 0, 150);

            ras.add_path(t1);
            scanlineRenderer.GenerateAndRender(ras, sl, clippingProxy, span_alloc, span_gen);
            base.OnDraw(graphics2D);
        }