示例#1
0
 public void SetFilterOffset(double dx, double dy)
 {
     m_dx_dbl = dx;
     m_dy_dbl = dy;
     m_dx_int = AggBasics.iround(dx * img_subpix_const.SCALE);
     m_dy_int = AggBasics.iround(dy * img_subpix_const.SCALE);
 }
示例#2
0
 public ColorRGBA(ColorRGBAf c)
 {
     red   = ((byte)AggBasics.uround(c.red * (double)BASE_MASK));
     green = ((byte)AggBasics.uround(c.green * (double)BASE_MASK));
     blue  = ((byte)AggBasics.uround(c.blue * (double)BASE_MASK));
     alpha = ((byte)AggBasics.uround(c.alpha * (double)BASE_MASK));
 }
示例#3
0
 //--------------------------------------------------------------------
 public void ResetGamma(IGammaFunction gamma_function)
 {
     for (int i = AA_SCALE - 1; i >= 0; --i)
     {
         m_gammaLut[i] = (int)AggBasics.uround(
             gamma_function.GetGamma((float)(i) / AA_MASK) * AA_MASK);
     }
 }
示例#4
0
 public static ColorRGBA Make(float r_, float g_, float b_, float a_)
 {
     return(new ColorRGBA(
                ((byte)AggBasics.uround_f(r_ * (float)BASE_MASK)),
                ((byte)AggBasics.uround_f(g_ * (float)BASE_MASK)),
                ((byte)AggBasics.uround_f(b_ * (float)BASE_MASK)),
                ((byte)AggBasics.uround_f(a_ * (float)BASE_MASK))));
 }
示例#5
0
 public static ColorRGBA Make(double r_, double g_, double b_)
 {
     return(new ColorRGBA(
                ((byte)AggBasics.uround(r_ * (double)BASE_MASK)),
                ((byte)AggBasics.uround(g_ * (double)BASE_MASK)),
                ((byte)AggBasics.uround(b_ * (double)BASE_MASK)),
                ((byte)AggBasics.uround(BASE_MASK))));
 }
        //--------------------------------------------------------------------
        // This function normalizes integer values and corrects the rounding
        // errors. It doesn't do anything with the source floating point values
        // (m_weight_array_dbl), it corrects only integers according to the rule
        // of 1.0 which means that any sum of pixel weights must be equal to 1.0.
        // So, the filter function must produce a graph of the proper shape.
        //--------------------------------------------------------------------
        public void Normalize()
        {
            int i;
            int flip = 1;

            for (i = 0; i < (int)ImgSubPixConst.SCALE; i++)
            {
                for (; ;)
                {
                    int sum = 0;
                    int j;
                    for (j = 0; j < m_diameter; j++)
                    {
                        sum += m_weight_array[j * (int)ImgSubPixConst.SCALE + i];
                    }

                    if (sum == (int)ImgFilterConst.SCALE)
                    {
                        break;
                    }

                    double k = (double)((int)ImgFilterConst.SCALE) / (double)(sum);
                    sum = 0;
                    for (j = 0; j < m_diameter; j++)
                    {
                        sum += m_weight_array[j * (int)ImgSubPixConst.SCALE + i] =
                            (int)AggBasics.iround(m_weight_array[j * (int)ImgSubPixConst.SCALE + i] * k);
                    }

                    sum -= (int)ImgFilterConst.SCALE;
                    int inc = (sum > 0) ? -1 : 1;

                    for (j = 0; j < m_diameter && sum != 0; j++)
                    {
                        flip ^= 1;
                        int idx = flip != 0 ? m_diameter / 2 + j / 2 : m_diameter / 2 - j / 2;
                        int v   = m_weight_array[idx * (int)ImgSubPixConst.SCALE + i];
                        if (v < (int)ImgFilterConst.SCALE)
                        {
                            m_weight_array[idx * (int)ImgSubPixConst.SCALE + i] += (int)inc;
                            sum += inc;
                        }
                    }
                }
            }

            int pivot = m_diameter << (ImgSubPixConst.SHIFT - 1);

            for (i = 0; i < pivot; i++)
            {
                m_weight_array[pivot + i] = m_weight_array[pivot - i];
            }
            int end = (Diameter << ImgSubPixConst.SHIFT) - 1;

            m_weight_array[0] = m_weight_array[end];
        }
示例#7
0
        void SetGamma(float g)
        {
            m_gamma = g;
            float inv_g = (float)(1.0 / g);

            for (int i = GAMMA_SIZE - 1; i >= 0; --i)
            {
                m_dir_gamma[i] = (byte)AggBasics.uround(Math.Pow(i / (float)GAMMA_MASK, m_gamma) * (float)GAMMA_MASK);
                m_inv_gamma[i] = (byte)AggBasics.uround(Math.Pow(i / (float)GAMMA_MASK, inv_g) * (float)GAMMA_MASK);
            }
        }
        void ReallocLut(double radius)
        {
            m_radius   = radius;
            m_diameter = AggBasics.uceil(radius) * 2;
            m_start    = -(m_diameter / 2 - 1);
            int size = m_diameter << ImgSubPixConst.SHIFT;

            if (size > m_weight_array.Length)
            {
                m_weight_array = new int[size];
            }
        }
 //--------------------------------------------------------------------
 public SpanGenGradient(ISpanInterpolator inter,
                        IGradientValueCalculator gvc,
                        IGradientColorsProvider m_colorsProvider,
                        double d1, double d2)
 {
     this.m_interpolator      = inter;
     this.m_grValueCalculator = gvc;
     this.m_colorsProvider    = m_colorsProvider;
     m_d1 = AggBasics.iround(d1 * GR_SUBPIX_SCALE);
     m_d2 = AggBasics.iround(d2 * GR_SUBPIX_SCALE);
     dd   = m_d2 - m_d1;
     if (dd < 1)
     {
         dd = 1;
     }
     stepRatio = (float)m_colorsProvider.GradientSteps / (float)dd;
 }
示例#10
0
            public void Calculate(double y)
            {
                double k = (y - m_y1) * m_1dy;

                if (k < 0.0)
                {
                    k = 0.0;
                }
                if (k > 1.0)
                {
                    k = 1.0;
                }
                m_r = m_r1 + AggBasics.iround(m_dr * k);
                m_g = m_g1 + AggBasics.iround(m_dg * k);
                m_b = m_b1 + AggBasics.iround(m_db * k);
                m_a = m_a1 + AggBasics.iround(m_da * k);
                m_x = AggBasics.iround((m_x1 + m_dx * k) * (double)SUBPIXEL_SCALE);
            }
示例#11
0
        void Calculate(Image.IImageFilter filter, bool normalization)
        {
            double r = filter.GetRadius();

            ReallocLut(r);
            int i;
            int pivot = Diameter << (ImgSubPixConst.SHIFT - 1);

            for (i = 0; i < pivot; i++)
            {
                double x = (double)i / (double)ImgSubPixConst.SCALE;
                double y = filter.CalculateWeight(x);
                m_weight_array[pivot + i]     =
                    m_weight_array[pivot - i] = AggBasics.iround(y * ImgFilterConst.SCALE);
            }
            int end = (Diameter << ImgSubPixConst.SHIFT) - 1;

            m_weight_array[0] = m_weight_array[end];
            if (normalization)
            {
                Normalize();
            }
        }
示例#12
0
 static int MulDiv(int a, int b, int c)
 {
     return(AggBasics.iround_f((float)a * (float)b / (float)c));
 }
示例#13
0
 //---------------------------------
 //from vector clipper
 static int upscale(double v)
 {
     return AggBasics.iround(v * poly_subpix.SCALE);
 }