Example #1
0
 public span_image_filter_float(IImageBufferAccessorFloat src,
                                ISpanInterpolatorFloat interpolator, IImageFilterFunction filterFunction)
 {
     m_ImageBufferAccessor = src;
     m_interpolator        = interpolator;
     m_filterFunction      = filterFunction;
     m_dx_dbl = (0.5f);
     m_dy_dbl = (0.5f);
 }
Example #2
0
 public void calculate(IImageFilterFunction filter, bool normalization)
 {
     double r = filter.radius();
     realloc_lut(r);
     int i;
     int pivot = diameter() << ((int)image_subpixel_scale_e.image_subpixel_shift - 1);
     for (i = 0; i < pivot; i++)
     {
         double x = (double)i / (double)image_subpixel_scale_e.image_subpixel_scale;
         double y = filter.calc_weight(x);
         m_weight_array.Array[pivot + i] =
         m_weight_array.Array[pivot - i] = agg_basics.iround(y * (int)image_filter_scale_e.image_filter_scale);
     }
     int end = (diameter() << (int)image_subpixel_scale_e.image_subpixel_shift) - 1;
     m_weight_array.Array[0] = m_weight_array.Array[end];
     if (normalization)
     {
         normalize();
     }
 }
Example #3
0
        public void calculate(IImageFilterFunction filter, bool normalization)
        {
            double r = filter.radius();

            realloc_lut(r);
            int i;
            int pivot = diameter() << ((int)image_subpixel_scale_e.image_subpixel_shift - 1);

            for (i = 0; i < pivot; i++)
            {
                double x = (double)i / (double)image_subpixel_scale_e.image_subpixel_scale;
                double y = filter.calc_weight(x);
                m_weight_array.Array[pivot + i]     =
                    m_weight_array.Array[pivot - i] = agg_basics.iround(y * (int)image_filter_scale_e.image_filter_scale);
            }
            int end = (diameter() << (int)image_subpixel_scale_e.image_subpixel_shift) - 1;

            m_weight_array.Array[0] = m_weight_array.Array[end];
            if (normalization)
            {
                normalize();
            }
        }
Example #4
0
        public void Calculate(IImageFilterFunction filter, bool normalization)
        {
            double r = filter.Radius;

            ReallocateLookupTable(r);
            uint i;
            uint pivot = diameter() << ((int)EImageSubpixelScale.Shift - 1);

            for (i = 0; i < pivot; i++)
            {
                double x = (double)i / (double)EImageSubpixelScale.Scale;
                double y = filter.CalculateWeight(x);
                m_weight_array.Array[pivot + i]     =
                    m_weight_array.Array[pivot - i] = (short)Basics.Round(y * (int)EImageFilterScale.Scale);
            }
            uint end = (diameter() << (int)EImageSubpixelScale.Shift) - 1;

            m_weight_array.Array[0] = m_weight_array.Array[end];
            if (normalization)
            {
                Normalize();
            }
        }
Example #5
0
        public void Calculate(IImageFilterFunction <T> filter, bool normalization)
        {
            T r = filter.Radius();

            ReAllocLut(r);
            uint i;
            uint pivot = Diameter() << ((int)SubPixelScale.Shift - 1);

            for (i = 0; i < pivot; i++)
            {
                T x = M.New <T>(i).Divide((double)SubPixelScale.Scale);

                T y = filter.CalcWeight(x);
                m_weight_array.Array[pivot + i]     =
                    m_weight_array.Array[pivot - i] = (short)Basics.RoundInt(y.Multiply((int)FilterScale.Scale));
            }
            uint end = (Diameter() << (int)SubPixelScale.Shift) - 1;

            m_weight_array.Array[0] = m_weight_array.Array[end];
            if (normalization)
            {
                Normalize();
            }
        }
Example #6
0
        public ImageFilterLookUpTable(IImageFilterFunction filter)
            : this(filter, true)
        {

        }
Example #7
0
 public ImageFilterLookUpTable(IImageFilterFunction filter, bool normalization)
 {
     m_weight_array = new ArrayPOD<int>(256);
     calculate(filter, normalization);
 }
Example #8
0
 public void calculate(IImageFilterFunction filter)
 {
     calculate(filter, true);
 }
		public span_image_filter_float(IImageBufferAccessorFloat src,
			ISpanInterpolatorFloat interpolator, IImageFilterFunction filterFunction)
		{
			m_ImageBufferAccessor = src;
			m_interpolator = interpolator;
			m_filterFunction = filterFunction;
			m_dx_dbl = (0.5f);
			m_dy_dbl = (0.5f);
		}
Example #10
0
        public override void Render(IImageByte source,
                                    double destX,
                                    double destY,
                                    double angleRadians,
                                    double inScaleX,
                                    double inScaleY)
        {
            Affine graphicsTransform = GetTransform();

            // 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 + graphicsTransform.tx), (int)(destY + graphicsTransform.ty));

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

                //return;
            }

            double scaleX = inScaleX;
            double scaleY = inScaleY;

            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:
                {
                    DrawImageGetDestBounds(source, destX, destY, sourceOriginOffsetX, sourceOriginOffsetY, scaleX, scaleY, angleRadians, out Affine destRectTransform);

                    var 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;
                    var interpolator   = new span_interpolator_linear(sourceRectTransform);
                    var sourceAccessor = new ImageBufferAccessorClip(source, ColorF.rgba_pre(0, 0, 0, 0).ToColor());

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

                    DrawImage(spanImageFilter, destRectTransform);
                }

                break;

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

                    var 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();

                    var interpolator   = new span_interpolator_linear(sourceRectTransform);
                    var sourceAccessor = new ImageBufferAccessorClip(source, ColorF.rgba_pre(0, 0, 0, 0).ToColor());

                    // 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);
                    var filter = new ImageFilterLookUpTable();
                    filter.calculate(filterFunction, true);

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

                    DrawImage(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
            {
                DrawImageGetDestBounds(source, destX, destY, sourceOriginOffsetX, sourceOriginOffsetY, scaleX, scaleY, angleRadians, out Affine destRectTransform);

                var 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();

                var interpolator   = new span_interpolator_linear(sourceRectTransform);
                var sourceAccessor = new ImageBufferAccessorClip(source, ColorF.rgba_pre(0, 0, 0, 0).ToColor());

                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(spanImageFilter, destRectTransform);
                DestImage.MarkImageChanged();
            }
        }
        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;
            }
        }
Example #12
0
 public ImageFilterLookUpTable(IImageFilterFunction filter)
     : this(filter, true)
 {
 }
Example #13
0
 public ImageFilterLookUpTable(IImageFilterFunction filter, bool normalization)
 {
     m_weight_array = new ArrayPOD <short>(256);
     Calculate(filter, normalization);
 }
Example #14
0
 public void Calculate(IImageFilterFunction filter, bool normalization)
 {
     double r = filter.Radius;
     ReallocateLookupTable(r);
     uint i;
     uint pivot = diameter() << ((int)EImageSubpixelScale.Shift - 1);
     for (i = 0; i < pivot; i++)
     {
         double x = (double)i / (double)EImageSubpixelScale.Scale;
         double y = filter.CalculateWeight(x);
         m_weight_array.Array[pivot + i] =
         m_weight_array.Array[pivot - i] = (short)Basics.Round(y * (int)EImageFilterScale.Scale);
     }
     uint end = (diameter() << (int)EImageSubpixelScale.Shift) - 1;
     m_weight_array.Array[0] = m_weight_array.Array[end];
     if (normalization)
     {
         Normalize();
     }
 }
Example #15
0
 public void Calculate(IImageFilterFunction filter)
 {
     Calculate(filter, true);
 }
Example #16
0
 public void filterFunction(IImageFilterFunction v)
 {
     m_filterFunction = v;
 }
		public void filterFunction(IImageFilterFunction v)
		{
			m_filterFunction = v;
		}
		public span_image_filter_rgba_float(IImageBufferAccessorFloat src, ISpanInterpolatorFloat inter, IImageFilterFunction filterFunction)
			: base(src, inter, filterFunction)
		{
			if (src.SourceImage.GetFloatsBetweenPixelsInclusive() != 4)
			{
				throw new System.NotSupportedException("span_image_filter_rgba must have a 32 bit DestImage");
			}
		}