public void Render(IBitmapSrc source, AffinePlan[] affinePlans) { VectorToolBox.GetFreeVxs(out var v1, out var v2); //BuildImageBoundsPath(source.Width, source.Height, affinePlans, v1); BuildOrgImgRectVxs(source.Width, source.Height, v1); //Affine destRectTransform = Affine.NewMatix(affinePlans); var destRectTransform = new AffineMat(); destRectTransform.BuildFromAffinePlans(affinePlans); //TODO: review reusable span generator an interpolator *** var spanInterpolator = new SpanInterpolatorLinear(); // We invert it because it is the transform to make the image go to the same position as the polygon. LBB [2/24/2004] _reuseableAffine.SetElements(destRectTransform.CreateInvert()); spanInterpolator.Transformer = _reuseableAffine;// var imgSpanGen = new ImgSpanGenRGBA_BilinearClip( source, Drawing.Color.Transparent, spanInterpolator); TransformToVxs(ref destRectTransform, v1, v2); Render(v2, imgSpanGen); // VectorToolBox.ReleaseVxs(ref v1, ref v2); }
public override void Draw(CanvasPainter p) { p.FillColor = ColorRGBA.Blue; p.FillRectangle(0, 70, 150, 120); //------------------------------------------- var innerGradient = new Gradients.GvcRadial(); SpanInterpolatorLinear linerInterpolator = new SpanInterpolatorLinear(Affine.IdentityMatrix); LinearGradientColorsProvider linearColorProvider = new LinearGradientColorsProvider(ColorRGBA.Red, ColorRGBA.Yellow); SpanGenGradient spanGenGradient = new SpanGenGradient(linerInterpolator, innerGradient, linearColorProvider, 0, 150); SimpleRect srect = new SimpleRect(0, 0, 150, 50); p.Fill(srect.MakeVxs(), spanGenGradient); }
public void SetData(IGradientValueCalculator gvc, LinearGradientPair pair) { _linerInterpolator = new SpanInterpolatorLinear(); _linearGradientColorProvider = new LinearGradientColorsProvider(); _spanGenGr = new GradientSpanGen(); //TODO: //user can use other coord transformer _linerInterpolator.Transformer = _reusableRotationTransformer = new ReusableRotationTransformer(); _reusableRotationTransformer.Angle = pair.Angle; _linearGradientColorProvider.SetColors(pair.c1, pair.c2, pair.steps); _spanGenGr.Reset(_linerInterpolator, gvc, _linearGradientColorProvider, pair._distance); _spanGenGr.SetStartPoint(pair.x1, pair.y1); }
public override void Draw(PixelFarm.Drawing.Painter p) { if (p is AggPainter) { var p2 = (AggPainter)p; p.FillColor = Drawing.Color.Red; p.FillRect(0, 70, 150, 120); //------------------------------------------- var innerGradient = new Gradients.GvcRadial(); SpanInterpolatorLinear linerInterpolator = new SpanInterpolatorLinear(Affine.IdentityMatrix); LinearGradientColorsProvider linearColorProvider = new LinearGradientColorsProvider(Drawing.Color.Red, Drawing.Color.Yellow); SpanGenGradient spanGenGradient = new SpanGenGradient(linerInterpolator, innerGradient, linearColorProvider, 0, 150); SimpleRect srect = new SimpleRect(0, 0, 150, 50); var v1 = GetFreeVxs(); p2.Fill(srect.MakeVxs(v1), spanGenGradient); ReleaseVxs(ref v1); } }
void transform_image(double angle) { double width = rbuf_img(0).Width; double height = rbuf_img(0).Height; #if SourceDepth24 FormatRGB pixf = new FormatRGB(rbuf_img(0), new BlenderBGR()); FormatRGB pixf_pre = new FormatRGB(rbuf_img(0), new BlenderPreMultBGR()); #else pixfmt_alpha_blend_rgba32 pixf = new pixfmt_alpha_blend_rgba32(rbuf_img(0), new blender_bgra32()); pixfmt_alpha_blend_rgba32 pixf_pre = new pixfmt_alpha_blend_rgba32(rbuf_img(0), new blender_bgra_pre()); #endif FormatClippingProxy rb = new FormatClippingProxy(pixf); FormatClippingProxy rb_pre = new FormatClippingProxy(pixf_pre); rb.Clear(new RGBA_Doubles(1.0, 1.0, 1.0)); IAffineTransformMatrix <T> src_mtx = MatrixFactory <T> .NewIdentity(VectorDimension.Two); src_mtx.Translate(MatrixFactory <T> .CreateVector2D(-width / 2.0, -height / 2.0)); src_mtx.RotateAlong(MatrixFactory <T> .CreateVector2D(0, 0), angle * Math.PI / 180.0); src_mtx.Translate(MatrixFactory <T> .CreateVector2D(width / 2.0, height / 2.0)); IAffineTransformMatrix <T> img_mtx = MatrixFactory <T> .CreateAffine(src_mtx); img_mtx = img_mtx.Inverse; double r = width; if (height < r) { r = height; } r *= 0.5; r -= 4.0; VertexSource.Ellipse <T> ell = new AGG.VertexSource.Ellipse <T>(width / 2.0, height / 2.0, r, r, 200); ConvTransform <T> tr = new ConvTransform <T>(ell, src_mtx); m_num_pix += r * r * Math.PI; SpanInterpolatorLinear <T> interpolator = new SpanInterpolatorLinear <T>(img_mtx); ImageFilterLookUpTable <T> filter = new ImageFilterLookUpTable <T>(); bool norm = m_normalize.status(); #if SourceDepth24 FormatRGB pixf_img = new FormatRGB(rbuf_img(1), new BlenderBGR()); #else pixfmt_alpha_blend_rgba32 pixf_img = new pixfmt_alpha_blend_rgba32(rbuf_img(1), new blender_bgra32()); #endif RasterBufferAccessorClip source = new RasterBufferAccessorClip(pixf_img, RGBA_Doubles.RgbaPre(0, 0, 0, 0)); switch (m_filters.cur_item()) { case 0: { #if SourceDepth24 SpanImageFilterRgbNN <T> sg = new SpanImageFilterRgbNN <T>(source, interpolator); #else span_image_filter_rgba_nn sg = new span_image_filter_rgba_nn(source, interpolator); #endif m_Rasterizer.AddPath(tr); Renderer <T> .GenerateAndRender(m_Rasterizer, m_ScanlineUnpacked, rb_pre, m_SpanAllocator, sg); } break; case 1: { #if SourceDepth24 //span_image_filter_rgb_bilinear_clip sg = new span_image_filter_rgb_bilinear_clip(pixf_img, rgba.rgba_pre(0, 0.4, 0, 0.5), interpolator); SpanImageFilterRgbBilinear <T> sg = new SpanImageFilterRgbBilinear <T>(source, interpolator); #else //span_image_filter_rgba_bilinear_clip sg = new span_image_filter_rgba_bilinear_clip(pixf_img, rgba.rgba_pre(0, 0, 0, 0), interpolator); span_image_filter_rgba_bilinear sg = new span_image_filter_rgba_bilinear(source, interpolator); #endif m_Rasterizer.AddPath(tr); Renderer <T> .GenerateAndRender(m_Rasterizer, m_ScanlineUnpacked, rb_pre, m_SpanAllocator, sg); } break; case 5: case 6: case 7: { switch (m_filters.cur_item()) { case 5: filter.Calculate(new ImageFilterHanning <T>(), norm); break; case 6: filter.Calculate(new ImageFilterHamming <T>(), norm); break; case 7: filter.Calculate(new ImageFilterHermite <T>(), norm); break; } SpanImageFilterRgb2x2 <T> sg = new SpanImageFilterRgb2x2 <T>(source, interpolator, filter); m_Rasterizer.AddPath(tr); Renderer <T> .GenerateAndRender(m_Rasterizer, m_ScanlineUnpacked, rb_pre, m_SpanAllocator, sg); } 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 (m_filters.cur_item()) { case 2: filter.Calculate(new ImageFilterBicubic <T>(), norm); break; case 3: filter.Calculate(new ImageFilterSpline16 <T>(), norm); break; case 4: filter.Calculate(new ImageFilterSpline36 <T>(), norm); break; case 8: filter.Calculate(new ImageFilterKaiser <T>(), norm); break; case 9: filter.Calculate(new ImageFilterQuadric <T>(), norm); break; case 10: filter.Calculate(new ImageFilterCatrom <T>(), norm); break; case 11: filter.Calculate(new ImageFilterGaussian <T>(), norm); break; case 12: filter.Calculate(new ImageFilterBessel <T>(), norm); break; case 13: filter.Calculate(new ImageFilterMitchell <T>(), norm); break; case 14: filter.Calculate(new ImageFilterSinc <T>(m_radius.value()), norm); break; case 15: filter.Calculate(new ImageFilterLanczos <T>(m_radius.value()), norm); break; case 16: filter.Calculate(new ImageFilterBlackman <T>(m_radius.value()), norm); break; } #if SourceDepth24 SpanImageFilterRgb <T> sg = new SpanImageFilterRgb <T>(source, interpolator, filter); #else span_image_filter_rgb sg = new span_image_filter_rgba(source, interpolator, filter); #endif m_Rasterizer.AddPath(tr); Renderer <T> .GenerateAndRender(m_Rasterizer, m_ScanlineUnpacked, rb_pre, m_SpanAllocator, sg); } break; } }
public override void OnDraw() { RasterizerScanlineAA <T> ras = new RasterizerScanlineAA <T>(); ScanlineUnpacked8 sl = new ScanlineUnpacked8(); #if SourceDepth24 FormatRGB pixf = new FormatRGB(rbuf_window(), new BlenderBGR()); #else FormatRGBA pixf = new FormatRGBA(rbuf_window(), new blender_bgra32()); #endif FormatClippingProxy clippingProxy = new FormatClippingProxy(pixf); clippingProxy.Clear(new RGBA_Doubles(0, 0, 0)); m_profile.text_size(8.0); //m_profile.Render(ras, sl, clippingProxy); //m_spline_r.Render(ras, sl, clippingProxy); //m_spline_g.Render(ras, sl, clippingProxy); //m_spline_b.Render(ras, sl, clippingProxy); //m_spline_a.Render(ras, sl, clippingProxy); //m_GradTypeRBox.Render(ras, sl, clippingProxy); //m_GradWrapRBox.Render(ras, sl, clippingProxy); // draw a background to show how the alpha is working int RectWidth = 32; int xoffset = 238; int yoffset = 171; for (int i = 0; i < 7; i++) { for (int j = 0; j < 7; j++) { if ((i + j) % 2 != 0) { VertexSource.RoundedRect <T> rect = new VertexSource.RoundedRect <T>(i * RectWidth + xoffset, j * RectWidth + yoffset, (i + 1) * RectWidth + xoffset, (j + 1) * RectWidth + yoffset, 2); rect.NormalizeRadius(); // Drawing as an outline ras.AddPath(rect); Renderer <T> .RenderSolid(clippingProxy, ras, sl, new RGBA_Bytes(.9, .9, .9)); } } } double ini_scale = 1.0; IAffineTransformMatrix <T> mtx1 = MatrixFactory <T> .NewIdentity(VectorDimension.Two); mtx1.Scale(MatrixFactory <T> .CreateVector2D(ini_scale, ini_scale)); mtx1.Translate(MatrixFactory <T> .CreateVector2D(center_x, center_y)); mtx1.Add(trans_affine_resizing()); VertexSource.Ellipse <T> e1 = new AGG.VertexSource.Ellipse <T>(); e1.Init(0.0, 0.0, 110.0, 110.0, 64); IAffineTransformMatrix <T> mtx_g1 = MatrixFactory <T> .NewIdentity(VectorDimension.Two); mtx_g1.Scale(MatrixFactory <T> .CreateVector2D(ini_scale, ini_scale)); mtx_g1.Scale(MatrixFactory <T> .CreateVector2D(m_SaveData.m_scale, m_SaveData.m_scale)); mtx_g1.Scale(MatrixFactory <T> .CreateVector2D(m_scale_x, m_scale_y)); mtx_g1.RotateAlong(MatrixFactory <T> .CreateVector2D(0, 0), m_SaveData.m_angle.ToDouble()); mtx_g1.Translate(MatrixFactory <T> .CreateVector2D(m_SaveData.m_center_x, m_SaveData.m_center_y)); mtx_g1.Add(trans_affine_resizing()); mtx_g1 = mtx_g1.Inverse; 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].ToInt(), m_spline_g.spline()[i].ToInt(), m_spline_b.spline()[i].ToInt(), m_spline_a.spline()[i].ToInt()); } ConvTransform <T> t1 = new ConvTransform <T>(e1, mtx1); IGradient innerGradient = null; switch (m_GradTypeRBox.cur_item()) { case 0: innerGradient = new GradientRadial(); break; case 1: innerGradient = new GradientDiamond(); break; case 2: innerGradient = new GradientX(); break; case 3: innerGradient = new GradientXY(); break; case 4: innerGradient = new GradientSqrtXY(); break; case 5: innerGradient = new GradientConic(); break; } IGradient outerGradient = null; switch (m_GradWrapRBox.cur_item()) { case 0: outerGradient = new GradientReflectAdaptor(innerGradient); break; case 1: outerGradient = new GradientRepeatAdaptor(innerGradient); break; case 2: outerGradient = new GradientClampAdaptor(innerGradient); break; } SpanAllocator span_alloc = new SpanAllocator(); ColorFunctionProfile colors = new ColorFunctionProfile(color_profile, m_profile.gamma()); SpanInterpolatorLinear <T> inter = new SpanInterpolatorLinear <T>(mtx_g1); SpanGradient <T> span_gen = new SpanGradient <T>(inter, outerGradient, colors, 0, 150); ras.AddPath(t1); Renderer <T> .GenerateAndRender(ras, sl, clippingProxy, span_alloc, span_gen); base.OnDraw(); }
public void Render(IImageReaderWriter source, double destX, double destY) { int inScaleX = 1; int inScaleY = 1; int angleRadians = 0; // exit early if the dest and source bounds don't touch. // TODO: <BUG> make this do rotation and scalling RectInt sourceBounds = source.GetBounds(); sourceBounds.Offset((int)destX, (int)destY); RectInt destBounds = this.destImageReaderWriter.GetBounds(); if (!RectInt.DoIntersect(sourceBounds, destBounds)) { //if (inScaleX != 1 || inScaleY != 1 || angleRadians != 0) //{ // throw new NotImplementedException(); //} return; } double scaleX = inScaleX; double scaleY = inScaleY; Affine graphicsTransform = this.CurrentTransformMatrix; if (!graphicsTransform.IsIdentity()) { 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 isScale = (scaleX != 1 || scaleY != 1); bool isRotated = false; if (angleRadians != 0 && Math.Abs(angleRadians) >= (0.1 * MathHelper.Tau / 360)) { isRotated = true; } else { angleRadians = 0;//reset very small angle to 0 } //bool IsMipped = false; //double ox, oy; //source.GetOriginOffset(out ox, out oy); bool canUseMipMaps = isScale; if (scaleX > 0.5 || scaleY > 0.5) { canUseMipMaps = false; } bool needSourceResampling = isScale || isRotated || destX != (int)destX || destY != (int)destY; VectorToolBox.GetFreeVxs(out VertexStore imgBoundsPath); // this is the fast drawing path if (needSourceResampling) { #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 = BuildImageBoundsPath(source.Width, source.Height, destX, destY, ox, oy, scaleX, scaleY, angleRadians, imgBoundsPath); // We invert it because it is the transform to make the image go to the same position as the polygon. LBB [2/24/2004] Affine sourceRectTransform = destRectTransform.CreateInvert(); var imgSpanGen = new ImgSpanGenRGBA_BilinearClip( source, Drawing.Color.Black, new SpanInterpolatorLinear(sourceRectTransform)); VectorToolBox.GetFreeVxs(out VertexStore v1); destRectTransform.TransformToVxs(imgBoundsPath, v1); Render(v1, imgSpanGen); VectorToolBox.ReleaseVxs(ref v1); #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 = BuildImageBoundsPath(source.Width, source.Height, destX, destY, imgBoundsPath); // We invert it because it is the transform to make the image go to the same position as the polygon. LBB [2/24/2004] Affine sourceRectTransform = destRectTransform.CreateInvert(); var interpolator = new SpanInterpolatorLinear(sourceRectTransform); ImgSpanGen imgSpanGen = null; switch (source.BitDepth) { case 32: imgSpanGen = new ImgSpanGenRGBA_NN_StepXBy1(source, interpolator); break; //case 24: // imgSpanGen = new ImgSpanGenRGB_NNStepXby1(source, interpolator); // break; case 8: imgSpanGen = new ImgSpanGenGray_NNStepXby1(source, interpolator); break; default: throw new NotImplementedException(); } VectorToolBox.GetFreeVxs(out VertexStore v1); destRectTransform.TransformToVxs(imgBoundsPath, v1); Render(v1, imgSpanGen); VectorToolBox.ReleaseVxs(ref v1); unchecked { destImageChanged++; }; } VectorToolBox.ReleaseVxs(ref imgBoundsPath); }
public override void OnDraw() { //typedef agg::renderer_base<pixfmt> renderer_base; //typedef agg::renderer_base<pixfmt_pre> renderer_base_pre; #if SourceDepth24 pixfmt_alpha_blend_rgb pixf = new pixfmt_alpha_blend_rgb(rbuf_window(), new blender_bgr()); pixfmt_alpha_blend_rgb pixf_pre = new pixfmt_alpha_blend_rgb(rbuf_window(), new blender_bgr_pre()); #else FormatRGBA pixf = new FormatRGBA(rbuf_window(), new BlenderBGRA()); FormatRGBA pixf_pre = new FormatRGBA(rbuf_window(), new BlenderPreMultBGRA()); #endif FormatClippingProxy clippingProxy = new FormatClippingProxy(pixf); FormatClippingProxy clippingProxy_pre = new FormatClippingProxy(pixf_pre); clippingProxy.Clear(new RGBA_Doubles(1.0, 1.0, 1.0)); IAffineTransformMatrix <T> src_mtx = MatrixFactory <T> .NewIdentity(VectorDimension.Two); src_mtx.Translate(MatrixFactory <T> .CreateVector2D(initial_width().Negative().Divide(2).Subtract(10), initial_height().Negative().Divide(2).Subtract(30))); src_mtx.RotateAlong(MatrixFactory <T> .CreateVector2D(0, 0), m_angle.value().Multiply(Math.PI / 180.0).ToDouble()); src_mtx.Scale(m_scale.value()); src_mtx.Translate(MatrixFactory <T> .CreateVector2D(initial_width().Divide(2), initial_height().Divide(2).Add(20))); src_mtx.Multiply(trans_affine_resizing()); IAffineTransformMatrix <T> img_mtx = MatrixFactory <T> .NewIdentity(VectorDimension.Two); img_mtx.Translate(MatrixFactory <T> .CreateVector2D(initial_width().Negative().Divide(2).Add(10), initial_height().Negative().Divide(2).Add(30))); img_mtx.RotateAlong(MatrixFactory <T> .CreateVector2D(0, 0), m_angle.value().Multiply(Math.PI / 180.0).ToDouble()); img_mtx.Scale(m_scale.value()); img_mtx.Translate(MatrixFactory <T> .CreateVector2D(initial_width().Divide(2), initial_height().Divide(2).Add(20))); img_mtx.Multiply(trans_affine_resizing()); img_mtx = img_mtx.Inverse; AGG.SpanAllocator sa = new SpanAllocator(); SpanInterpolatorLinear <T> interpolator = new SpanInterpolatorLinear <T>(img_mtx); #if SourceDepth24 pixfmt_alpha_blend_rgb img_pixf = new pixfmt_alpha_blend_rgb(rbuf_img(0), new blender_bgr()); #else FormatRGBA img_pixf = new FormatRGBA(rbuf_img(0), new BlenderBGRA()); #endif #if SourceDepth24 span_image_filter_rgb_bilinear_clip sg; sg = new span_image_filter_rgb_bilinear_clip(img_pixf, rgba.rgba_pre(0, 0.4, 0, 0.5), interpolator); #else SpanImageFilterRgbaBilinearClip <T> sg; RasterBufferAccessorClip source = new RasterBufferAccessorClip(img_pixf, RGBA_Doubles.RgbaPre(0, 0, 0, 0)); sg = new SpanImageFilterRgbaBilinearClip <T>(source, RGBA_Doubles.RgbaPre(0, 0.4, 0, 0.5), interpolator); #endif RasterizerScanlineAA <T> ras = new RasterizerScanlineAA <T>(); ras.SetVectorClipBox(M.Zero <T>(), M.Zero <T>(), width(), height()); //agg.scanline_packed_8 sl = new scanline_packed_8(); ScanlineUnpacked8 sl = new ScanlineUnpacked8(); T r = initial_width(); if (initial_height().Subtract(60).LessThan(r)) { r = initial_height().Subtract(60); } Ellipse <T> ell = new Ellipse <T>(initial_width().Divide(2.0).Add(10), initial_height().Divide(2.0).Add(30), r.Divide(2.0).Add(16.0), r.Divide(2.0).Add(16.0), 200); ConvTransform <T> tr = new ConvTransform <T>(ell, src_mtx); ras.AddPath(tr); #if use_timers for (uint j = 0; j < 10; j++) { Renderer.GenerateAndRender(ras, sl, clippingProxy_pre, sa, sg); } AllTimer.Start(); image1_100_Times.Start(); for (uint i = 0; i < 500; i++) { #endif //clippingProxy_pre.SetClippingBox(30, 0, (int)width(), (int)height()); //clippingProxy.SetClippingBox(30, 0, (int)width(), (int)height()); Renderer <T> .GenerateAndRender(ras, sl, clippingProxy_pre, sa, sg); #if use_timers } image1_100_Times.Stop(); #endif //m_angle.SetTransform(trans_affine_resizing()); //m_scale.SetTransform(trans_affine_resizing()); #if use_timers AllTimer.Stop(); CExecutionTimer.Instance.AppendResultsToFile("TimingTest.txt", AllTimer.GetTotalSeconds()); CExecutionTimer.Instance.Reset(); #endif base.OnDraw(); }