Exemple #1
0
 public void filter_offset(double dx, double dy)
 {
     m_dx_dbl = dx;
     m_dy_dbl = dy;
     m_dx_int = (uint)Basics.Round(dx * (int)image_subpixel_scale_e.Scale);
     m_dy_int = (uint)Basics.Round(dy * (int)image_subpixel_scale_e.Scale);
 }
Exemple #2
0
        //-------------------------------------------------------------------------
        public static void bisectrix(LineParameters l1,
                                     LineParameters l2,
                                     out int x, out int y)
        {
            double k  = (double)(l2.len) / (double)(l1.len);
            double tx = l2.x2 - (l2.x1 - l1.x1) * k;
            double ty = l2.y2 - (l2.y1 - l1.y1) * k;

            //All bisectrices must be on the right of the Line
            //If the next point is on the left (l1 => l2.2)
            //then the bisectix should be rotated by 180 degrees.
            if ((double)(l2.x2 - l2.x1) * (double)(l2.y1 - l1.y1) <
                (double)(l2.y2 - l2.y1) * (double)(l2.x1 - l1.x1) + 100.0)
            {
                tx -= (tx - l2.x1) * 2.0;
                ty -= (ty - l2.y1) * 2.0;
            }

            // Check if the bisectrix is too short
            double dx = tx - l2.x1;
            double dy = ty - l2.y1;

            if ((int)Math.Sqrt(dx * dx + dy * dy) < line_subpixel_scale)
            {
                x = (l2.x1 + l2.x1 + (l2.y1 - l1.y1) + (l2.y2 - l2.y1)) >> 1;
                y = (l2.y1 + l2.y1 - (l2.x1 - l1.x1) - (l2.x2 - l2.x1)) >> 1;
                return;
            }

            x = Basics.Round(tx);
            y = Basics.Round(ty);
        }
        //----------------------------------------------------------------
        public void Begin(double x, double y, uint len)
        {
            // Calculate transformed Coordinates At x1,y1
            double xt = x;
            double yt = y;

            m_trans_dir.Transform(ref xt, ref yt);
            int x1 = Basics.Round(xt * subpixel_scale);
            int y1 = Basics.Round(yt * subpixel_scale);

            double dx;
            double dy;
            double delta = 1 / (double)subpixel_scale;

            // Calculate Scale by X At x1,y1
            dx = xt + delta;
            dy = yt;
            m_trans_inv.Transform(ref dx, ref dy);
            dx -= x;
            dy -= y;
            int sx1 = (int)Basics.UnsignedRound(subpixel_scale / Math.Sqrt(dx * dx + dy * dy)) >> subpixel_shift;

            // Calculate Scale by Y At x1,y1
            dx = xt;
            dy = yt + delta;
            m_trans_inv.Transform(ref dx, ref dy);
            dx -= x;
            dy -= y;
            int sy1 = (int)Basics.UnsignedRound(subpixel_scale / Math.Sqrt(dx * dx + dy * dy)) >> subpixel_shift;

            // Calculate transformed Coordinates At x2,y2
            x += len;
            xt = x;
            yt = y;
            m_trans_dir.Transform(ref xt, ref yt);
            int x2 = Basics.Round(xt * subpixel_scale);
            int y2 = Basics.Round(yt * subpixel_scale);

            // Calculate Scale by X At x2,y2
            dx = xt + delta;
            dy = yt;
            m_trans_inv.Transform(ref dx, ref dy);
            dx -= x;
            dy -= y;
            int sx2 = (int)Basics.UnsignedRound(subpixel_scale / Math.Sqrt(dx * dx + dy * dy)) >> subpixel_shift;

            // Calculate Scale by Y At x2,y2
            dx = xt;
            dy = yt + delta;
            m_trans_inv.Transform(ref dx, ref dy);
            dx -= x;
            dy -= y;
            int sy2 = (int)Basics.UnsignedRound(subpixel_scale / Math.Sqrt(dx * dx + dy * dy)) >> subpixel_shift;

            // Initialize the interpolators
            m_coord_x = new Dda2LineInterpolator(x1, x2, (int)len);
            m_coord_y = new Dda2LineInterpolator(y1, y2, (int)len);
            m_scale_x = new Dda2LineInterpolator(sx1, sx2, (int)len);
            m_scale_y = new Dda2LineInterpolator(sy1, sy2, (int)len);
        }
Exemple #4
0
        //--------------------------------------------------------------------
        // 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()
        {
            uint i;
            int  flip = 1;

            for (i = 0; i < (int)EImageSubpixelScale.Scale; i++)
            {
                for (;;)
                {
                    int  sum = 0;
                    uint j;
                    for (j = 0; j < m_diameter; j++)
                    {
                        sum += m_weight_array.Array[j * (int)EImageSubpixelScale.Scale + i];
                    }

                    if (sum == (int)EImageFilterScale.Scale)
                    {
                        break;
                    }

                    double k = (double)((int)EImageFilterScale.Scale) / (double)(sum);
                    sum = 0;
                    for (j = 0; j < m_diameter; j++)
                    {
                        sum += m_weight_array.Array[j * (int)EImageSubpixelScale.Scale + i] =
                            (short)Basics.Round(m_weight_array.Array[j * (int)EImageSubpixelScale.Scale + i] * k);
                    }

                    sum -= (int)EImageFilterScale.Scale;
                    int inc = (sum > 0) ? -1 : 1;

                    for (j = 0; j < m_diameter && sum != 0; j++)
                    {
                        flip ^= 1;
                        uint idx = flip != 0 ? m_diameter / 2 + j / 2 : m_diameter / 2 - j / 2;
                        int  v   = m_weight_array.Array[idx * (int)EImageSubpixelScale.Scale + i];
                        if (v < (int)EImageFilterScale.Scale)
                        {
                            m_weight_array.Array[idx * (int)EImageSubpixelScale.Scale + i] += (short)inc;
                            sum += inc;
                        }
                    }
                }
            }

            uint pivot = m_diameter << ((int)EImageSubpixelScale.Shift - 1);

            for (i = 0; i < pivot; i++)
            {
                m_weight_array.Array[pivot + i] = m_weight_array.Array[pivot - i];
            }
            uint end = (diameter() << (int)EImageSubpixelScale.Shift) - 1;

            m_weight_array.Array[0] = m_weight_array.Array[end];
        }
Exemple #5
0
        //---------------------------------------------fix_degenerate_bisectrix_end
        public static void fix_degenerate_bisectrix_end(LineParameters lp,
                                                        ref int x, ref int y)
        {
            int d = Basics.Round(((double)(x - lp.x2) * (double)(lp.y2 - lp.y1) -
                                  (double)(y - lp.y2) * (double)(lp.x2 - lp.x1)) / lp.len);

            if (d < line_subpixel_scale / 2)
            {
                x = lp.x2 + (lp.y2 - lp.y1);
                y = lp.y2 - (lp.x2 - lp.x1);
            }
        }
 //----------------------------------------------------------------
 public void Begin(double x, double y, uint len)
 {
     m_pos   = 1;
     m_src_x = Basics.Round(x * subpixel_scale) + subpixel_scale;
     m_src_y = y;
     m_len   = len;
     if (len > m_subdiv_size)
     {
         len = (uint)m_subdiv_size;
     }
     m_interpolator.Begin(x, y, len);
 }
        //----------------------------------------------------------------
        public void ReSynchronize(double xe, double ye, uint len)
        {
            // Assume x1,y1 are equal to the ones At the previous End point
            int x1  = m_coord_x.y();
            int y1  = m_coord_y.y();
            int sx1 = m_scale_x.y();
            int sy1 = m_scale_y.y();

            // Calculate transformed Coordinates At x2,y2
            double xt = xe;
            double yt = ye;

            m_trans_dir.Transform(ref xt, ref yt);
            int x2 = Basics.Round(xt * subpixel_scale);
            int y2 = Basics.Round(yt * subpixel_scale);

            double delta = 1 / (double)subpixel_scale;
            double dx;
            double dy;

            // Calculate Scale by X At x2,y2
            dx = xt + delta;
            dy = yt;
            m_trans_inv.Transform(ref dx, ref dy);
            dx -= xe;
            dy -= ye;
            int sx2 = (int)Basics.UnsignedRound(subpixel_scale / Math.Sqrt(dx * dx + dy * dy)) >> subpixel_shift;

            // Calculate Scale by Y At x2,y2
            dx = xt;
            dy = yt + delta;
            m_trans_inv.Transform(ref dx, ref dy);
            dx -= xe;
            dy -= ye;
            int sy2 = (int)Basics.UnsignedRound(subpixel_scale / Math.Sqrt(dx * dx + dy * dy)) >> subpixel_shift;

            // Initialize the interpolators
            m_coord_x = new Dda2LineInterpolator(x1, x2, (int)len);
            m_coord_y = new Dda2LineInterpolator(y1, y2, (int)len);
            m_scale_x = new Dda2LineInterpolator(sx1, sx2, (int)len);
            m_scale_y = new Dda2LineInterpolator(sy1, sy2, (int)len);
        }
Exemple #8
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();
            }
        }
Exemple #9
0
 public static int Convert(double x)
 {
     return(Basics.Round(x * LineAABasics.line_subpixel_scale, LineAABasics.line_max_coord));
 }
Exemple #10
0
 public int UpScale(double v)
 {
     return(Basics.Round(v * (int)poly_subpixel_scale_e.Scale));
 }
Exemple #11
0
 private int MulDiv(double a, double b, double c)
 {
     return(Basics.Round(a * b / c));
 }