static int GetBilinear(double x, double y, int[] colors)
        {
            int[] px0 = new int[3];
            px0[0] = (colors[0] & 0xFF0000) >> 16;
            px0[1] = (colors[0] & 0x00FF00) >> 8;
            px0[2] = colors[0] & 0x0000FF;

            int[] px1 = new int[3];
            px1[0] = (colors[1] & 0xFF0000) >> 16;
            px1[1] = (colors[1] & 0x00FF00) >> 8;
            px1[2] = colors[1] & 0x0000FF;

            int[] px2 = new int[3];
            px2[0] = (colors[2] & 0xFF0000) >> 16;
            px2[1] = (colors[2] & 0x00FF00) >> 8;
            px2[2] = colors[2] & 0x0000FF;

            int[] px3 = new int[3];
            px3[0] = (colors[3] & 0xFF0000) >> 16;
            px3[1] = (colors[3] & 0x00FF00) >> 8;
            px3[2] = colors[3] & 0x0000FF;

            int[] crRet = new int[3];
            for (int i = 0; i < 3; i++)
            {
                double m0 = px0[i] + x * (px1[i] - px0[i]);
                double m1 = px2[i] + x * (px3[i] - px2[i]);
                double my = m0 + y * (m1 - m0);
                crRet[i] = Image.SAFECOLOR((int)my);
            }

            return(Image.rgb(crRet[0], crRet[1], crRet[2]));
        }
Beispiel #2
0
        public override Image process(Image imageIn)
        {
            int    r, g, b;
            int    width  = imageIn.getWidth();
            int    height = imageIn.getHeight();
            double hw     = width / 2.0;
            double hh     = height / 2.0;

            int ratio = width > height ? height * 32768 / width : width * 32768 / height;

            // Calculate center, min and max
            int cx   = width >> 1;
            int cy   = height >> 1;
            int max  = cx * cx + cy * cy;
            int min  = (int)(max * 0.5);
            int diff = max - min;

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    if (m_focusType == 1)//椭圆
                    {
                        // Calculate distance to center and adapt aspect ratio
                        int dx = cx - x;
                        int dy = cy - y;
                        if (imageIn.getWidth() > imageIn.getHeight())
                        {
                            dy = (dy * ratio) >> 14;
                        }
                        else
                        {
                            dx = (dx * ratio) >> 14;
                        }
                        int distSq = dx * dx + dy * dy;

                        if (distSq <= min)
                        {
                            continue;
                        }
                    }
                    else if (m_focusType == 2)//长方框
                    {
                        bool inarray = false;
                        if ((x < m_size) && (y < height - x) && (y >= x))
                        {
                            inarray = true; // left
                        }
                        else if ((y < m_size) && (x < width - y) && (x >= y))
                        {
                            inarray = true; // top
                        }
                        else if ((x > width - m_size) && (y >= width - x) && (y < height + x - width))
                        {
                            inarray = true; // right
                        }
                        else if (y > height - m_size)
                        {
                            inarray = true; // bottom
                        }
                        if (!inarray)
                        {
                            continue;
                        }
                    }
                    int i = (int)(x - hw);
                    int j = (int)(y - hh);
                    b = 0; g = 0; r = 0;

                    for (int mm = 0; mm < aasamples; mm++)
                    {
                        double u = i + m_aapt[mm].X;
                        double v = j - m_aapt[mm].Y;

                        double s = m_cos * u + m_sin * v;
                        double t = -m_sin * u + m_cos * v;

                        s += m_curvature * Math.Tan(s * m_scale);
                        t += m_curvature * Math.Tan(t * m_scale);
                        u  = m_cos * s - m_sin * t;
                        v  = m_sin * s + m_cos * t;

                        int xSample = (int)(hw + u);
                        int ySample = (int)(hh + v);

                        xSample = Function.FClamp(xSample, 0, width - 1);
                        ySample = Function.FClamp(ySample, 0, height - 1);

                        r += imageIn.getRComponent(xSample, ySample);
                        g += imageIn.getGComponent(xSample, ySample);
                        b += imageIn.getBComponent(xSample, ySample);
                    }
                    imageIn.setPixelColor(x, y, Image.SAFECOLOR(r / aasamples), Image.SAFECOLOR(g / aasamples), Image.SAFECOLOR(b / aasamples));
                }
            }
            return(imageIn);
        }
Beispiel #3
0
 static int DoubleRGB_to_RGB(double r, double g, double b)
 {
     return(Image.rgb(Image.SAFECOLOR((int)(r * 255)), Image.SAFECOLOR((int)(g * 255)), Image.SAFECOLOR((int)(b * 255))));
 }