//@Override
        public Image process(Image imageIn)
        {
            double width = imageIn.getWidth();
            double height = imageIn.getHeight();
            Image clone = imageIn.clone();
            int r, g, b;
            for (int x = 0; x < (width - 1); x++)
            {
                for (int y = 0; y < (height - 1); y++)
                {
                    r = imageIn.getRComponent(x, y);
                    g = imageIn.getGComponent(x, y);
                    b = imageIn.getBComponent(x, y);

                    _scale = Math.Sqrt(width * width + height * height) / 2;
                    _offset = (int)(_scale / 2);
                    double cx = (x - width / 2.0) / _scale;
                    double cy = (y - height / 2.0) / _scale;
                    double angle = Math.Floor(Math.Atan2(cy, cx) / 2.0 / _amount) * 2.0 * _amount + _amount;
                    double radius = Math.Sqrt(cx * cx + cy * cy);
                    int xx = (int)(x - _offset * Math.Cos(angle));
                    int yy = (int)(y - _offset * Math.Sin(angle));
                    xx = Function.FClamp(xx, 0, (int)(width - 1));
                    yy = Function.FClamp(yy, 0, (int)(height - 1));

                    r = Function.FClamp0255(r + radius * (clone.getRComponent(xx, yy) - r));
                    g = Function.FClamp0255(g + radius * (clone.getGComponent(xx, yy) - g));
                    b = Function.FClamp0255(b + radius * (clone.getBComponent(xx, yy) - b));
                    imageIn.setPixelColor(x, y, r, g, b);
                }
            }
            return imageIn;
        }
        //@Override
        public Image process(Image imageIn)
        {
            double width = imageIn.getWidth();
            double height = imageIn.getHeight();
            Image  clone = imageIn.clone();
            int    r, g, b;

            for (int x = 0; x < (width - 1); x++)
            {
                for (int y = 0; y < (height - 1); y++)
                {
                    r = imageIn.getRComponent(x, y);
                    g = imageIn.getGComponent(x, y);
                    b = imageIn.getBComponent(x, y);

                    _scale  = Math.Sqrt(width * width + height * height) / 2;
                    _offset = (int)(_scale / 2);
                    double cx     = (x - width / 2.0) / _scale;
                    double cy     = (y - height / 2.0) / _scale;
                    double angle  = Math.Floor(Math.Atan2(cy, cx) / 2.0 / _amount) * 2.0 * _amount + _amount;
                    double radius = Math.Sqrt(cx * cx + cy * cy);
                    int    xx     = (int)(x - _offset * Math.Cos(angle));
                    int    yy     = (int)(y - _offset * Math.Sin(angle));
                    xx = Function.FClamp(xx, 0, (int)(width - 1));
                    yy = Function.FClamp(yy, 0, (int)(height - 1));

                    r = Function.FClamp0255(r + radius * (clone.getRComponent(xx, yy) - r));
                    g = Function.FClamp0255(g + radius * (clone.getGComponent(xx, yy) - g));
                    b = Function.FClamp0255(b + radius * (clone.getBComponent(xx, yy) - b));
                    imageIn.setPixelColor(x, y, r, g, b);
                }
            }
            return(imageIn);
        }
        //@Override
        public Image process(Image imageIn)
        {
            clone = imageIn.clone();
              int width = imageIn.getWidth();
              int height = imageIn.getHeight();
              for(int x = 0 ; x < width; x++){
                  for(int y = 0 ; y < height ; y++){
                        double   un_x = 0, un_y = 0 ;
                        double[] result = calc_undistorted_coord (x, y, un_x, un_y) ;
                        un_x = result[0];un_y = result[1];
                        int crNull = 0xFFFFFF;//WHITE
                        int cr  = crNull ;
                        if ( (un_x > -1) && (un_x < width) && (un_y > -1) && (un_y < height) )
                        {
                            // only this range is valid
                            int nSrcX = ((un_x < 0) ? -1 : (int)un_x);
                            int nSrcY = ((un_y < 0) ? -1 : (int)un_y);
                            int nSrcX_1 = nSrcX + 1;
                            int nSrcY_1 = nSrcY + 1;

                            int[] color = new int[4];
                            color[0] = IsInside(width, height, nSrcX, nSrcY) ? clone.getPixelColor(nSrcX,nSrcY) : crNull;
                            color[1] = IsInside(width, height, nSrcX_1, nSrcY) ? clone.getPixelColor(nSrcX_1,nSrcY) : crNull;
                            color[2] = IsInside(width, height, nSrcX, nSrcY_1) ? clone.getPixelColor(nSrcX,nSrcY_1) : crNull;
                            color[3] = IsInside(width, height, nSrcX_1, nSrcY_1) ? clone.getPixelColor(nSrcX_1,nSrcY_1) : crNull;
                            cr = GetBilinear(un_x-nSrcX, un_y-nSrcY, color);
                        }
                        imageIn.setPixelColor(x, y, cr);
                  }
              }
            return imageIn;
        }
        //@Override
        public Image process(Image imageIn)
        {
            clone = imageIn.clone();
            int width  = imageIn.getWidth();
            int height = imageIn.getHeight();

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    double   un_x = 0, un_y = 0;
                    double[] result = calc_undistorted_coord(x, y, un_x, un_y);
                    un_x = result[0]; un_y = result[1];
                    int crNull = 0xFFFFFF;                        //WHITE
                    int cr     = crNull;
                    if ((un_x > -1) && (un_x < width) && (un_y > -1) && (un_y < height))
                    {
                        // only this range is valid
                        int nSrcX   = ((un_x < 0) ? -1 : (int)un_x);
                        int nSrcY   = ((un_y < 0) ? -1 : (int)un_y);
                        int nSrcX_1 = nSrcX + 1;
                        int nSrcY_1 = nSrcY + 1;

                        int[] color = new int[4];
                        color[0] = IsInside(width, height, nSrcX, nSrcY) ? clone.getPixelColor(nSrcX, nSrcY) : crNull;
                        color[1] = IsInside(width, height, nSrcX_1, nSrcY) ? clone.getPixelColor(nSrcX_1, nSrcY) : crNull;
                        color[2] = IsInside(width, height, nSrcX, nSrcY_1) ? clone.getPixelColor(nSrcX, nSrcY_1) : crNull;
                        color[3] = IsInside(width, height, nSrcX_1, nSrcY_1) ? clone.getPixelColor(nSrcX_1, nSrcY_1) : crNull;
                        cr       = GetBilinear(un_x - nSrcX, un_y - nSrcY, color);
                    }
                    imageIn.setPixelColor(x, y, cr);
                }
            }
            return(imageIn);
        }
        //@Override
        public override Image process(Image imageIn)
        {
            int width = imageIn.getWidth();
            int height = imageIn.getHeight();
            int r = 0, g = 0, b = 0;

            Image clone = imageIn.clone();
            clone.clearImage((255 << 24) + (Colors.LightGray.R << 16) + (Colors.LightGray.G << 8) + Colors.LightGray.B);
            Point[] point = new Point[BannerNum];
            if (this.IsHorizontal)
            {//ˮƽ����
                int dh = height / BannerNum;
                int dw = width;
                for (int i = 0; i < BannerNum; i++)
                {
                    point[i] = new Point(0, i * dh);
                }
                for (int x = 0; x < dh; x++)
                {
                    for (int y = 0; y < BannerNum; y++)
                    {
                        for (int k = 0; k < dw; k++)
                        {
                            int xx = (int)point[y].X + k;
                            int yy = (int)point[y].Y + (int)(x / 1.1);
                            r = imageIn.getRComponent(xx, yy);
                            g = imageIn.getGComponent(xx, yy);
                            b = imageIn.getBComponent(xx, yy);
                            clone.setPixelColor(xx, yy, r, g, b);
                        }
                    }
                }
                //��ͼ�����ಿ�������
                for (int xx = 0; xx < width; xx++)
                {
                    for (int yy = (int)point[BannerNum - 1].Y + dh; yy < height; yy++)
                    {
                        r = imageIn.getRComponent(xx, yy);
                        g = imageIn.getGComponent(xx, yy);
                        b = imageIn.getBComponent(xx, yy);
                        clone.setPixelColor(xx, yy, r, g, b);
                    }
                }
            }
            else
            {//��ֱ����
                int dw = width / BannerNum;
                int dh = height;
                for (int i = 0; i < BannerNum; i++)
                {
                    point[i] = new Point(i * dw, 0);
                }
                for (int x = 0; x < dw; x++)
                {
                    for (int y = 0; y < BannerNum; y++)
                    {
                        for (int k = 0; k < dh; k++)
                        {
                            int xx = (int)point[y].X + (int)(x / 1.1);
                            int yy = (int)point[y].Y + k;
                            r = imageIn.getRComponent(xx, yy);
                            g = imageIn.getGComponent(xx, yy);
                            b = imageIn.getBComponent(xx, yy);
                            clone.setPixelColor(xx, yy, r, g, b);
                        }
                    }
                }
                //��ͼ�����ಿ�������
                for (int yy = 0; yy < height; yy++)
                {
                    for (int xx = (int)point[BannerNum - 1].X + dw; xx < width; xx++)
                    {
                        r = imageIn.getRComponent(xx, yy);
                        g = imageIn.getGComponent(xx, yy);
                        b = imageIn.getBComponent(xx, yy);
                        clone.setPixelColor(xx, yy, r, g, b);
                    }
                }
            }
            return clone;
        }
 //@Override
 public Image process(Image imageIn)
 {
     int[,] h = new int[3,256];
     int[] array = new int[3];
     int[] rgb = new int[] { 255, 255, 255 };
     int[] bb = new int[256];
     int[] gg = new int[256];
     int[] rr = new int[256];
     int intensity = (int) (this.Intensity * 255f);
     int intensity_invert = 255 - intensity;
     for (int x = 0; x < imageIn.getWidth() - 1; x++){
      for (int y = 0; y < imageIn.getHeight() - 1; y++)  {
        			  h[0,imageIn.getRComponent(x, y)]++;
       	          h[1,imageIn.getGComponent(x, y)]++;
       	          h[2,imageIn.getBComponent(x, y)]++;
      }
     }
     int[] percentileColor = GetPercentileColor(h, 0.005f);
     int[] meanColor = GetMeanColor(h);
     int[] hi = GetPercentileColor(h, 0.995f);
     float[] gamma = ComputeGamma(percentileColor, meanColor, hi);
     for (int i = 0; i < 3; i++){
     for (int j = 0; j < 256; j++){
         int[] arr = new int[3];
         for (int n = 0; n < 3; n++){
             float percent = j - percentileColor[n];
             if (percent < 0f){
                 arr[n] = array[n];
             }
             else if ((percent + percentileColor[n]) >= hi[n]){
                 arr[n] = rgb[n];
             }
             else {
                 double adjust = array[n] + ((rgb[n] - array[n]) * Math.Pow((double) (percent / ((float) (hi[n] - percentileColor[n]))), (double) gamma[n]));
                 arr[n] = (adjust > 255.0) ? ((int) 255.0) : ((adjust < 0.0) ? ((int) 0.0) : ((int) adjust));
             }
         }
         rr[j] = arr[0];
         gg[j] = arr[1];
         bb[j] = arr[2];
     }
     }
     Image clone = imageIn.clone();
     int r,g,b;
     for (int x = 0; x < imageIn.getWidth() - 1; x++){
       			 for (int y = 0; y < imageIn.getHeight() - 1; y++)  {
       				r = clone.getRComponent(x, y);
       				g = clone.getGComponent(x, y);
       				b = clone.getBComponent(x, y);
         r = (r * intensity_invert + rr[r] * intensity) >> 8;
         g = (g * intensity_invert + gg[g] * intensity) >> 8;
         b = (b * intensity_invert + bb[b] * intensity) >> 8;
         imageIn.setPixelColor(x, y, r, g, b);
      	 }
     }
     return imageIn;//��ֱ��ͼģʽ��ǿ
 }
 //@Override
 public Image process(Image imageIn)
 {
     Image clone = gradientFx.process(imageIn.clone());
     return blender.Blend(imageIn, clone);
 }
        //@Override
        public virtual Image process(Image imageIn)
        {
            int   r, g, b;
            int   width      = imageIn.getWidth();
            int   height     = imageIn.getHeight();
            int   realxpos   = (int)(width * Center.X);
            int   realypos   = (int)(height * Center.Y);
            float realradius = Math.Min(width, height) * Radius;
            Image clone      = imageIn.clone();

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    float pos = 1f - ((float)Math.Sqrt((double)(((x - realxpos) * (x - realxpos)) + (y - realypos) * (y - realypos))) / realradius);
                    if (pos <= 0f)
                    {
                        pos = 1f - (Distortion * pos * pos);
                        float pos1 = (x - realxpos) * pos + realxpos;
                        float pos2 = (y - realypos) * pos + realypos;
                        int   x1   = (int)pos1;
                        float pos3 = pos1 - x1;
                        int   x2   = (pos3 > 0f) ? (x1 + 1) : x1;
                        int   y1   = (int)pos2;
                        float pos4 = pos2 - y1;
                        int   y2   = (pos4 > 0f) ? (y1 + 1) : y1;
                        if (x1 < 0)
                        {
                            x1 = 0;
                        }
                        else if (x1 >= width)
                        {
                            x1 = width - 1;
                        }
                        if (x2 < 0)
                        {
                            x2 = 0;
                        }
                        else if (x2 >= width)
                        {
                            x2 = width - 1;
                        }
                        if (y1 < 0)
                        {
                            y1 = 0;
                        }
                        else if (y1 >= height)
                        {
                            y1 = height - 1;
                        }
                        if (y2 < 0)
                        {
                            y2 = 0;
                        }
                        else if (y2 >= height)
                        {
                            y2 = height - 1;
                        }
                        r = clone.getRComponent(x1, y1);
                        g = clone.getGComponent(x1, y1);
                        b = clone.getBComponent(x1, y1);

                        int r2 = clone.getRComponent(x2, y1);
                        int g2 = clone.getGComponent(x2, y1);
                        int b2 = clone.getBComponent(x2, y1);
                        int r3 = clone.getRComponent(x2, y2);
                        int g3 = clone.getGComponent(x2, y2);
                        int b3 = clone.getBComponent(x2, y2);
                        int r4 = clone.getRComponent(x1, y2);
                        int g4 = clone.getGComponent(x1, y2);
                        int b4 = clone.getBComponent(x1, y2);
                        r = (int)((r * (1f - pos4) * (1f - pos3) + r2 * (1f - pos4) * pos3 + r3 * pos4 * pos3) + r4 * pos4 * (1f - pos3));
                        g = (int)((g * (1f - pos4) * (1f - pos3) + g2 * (1f - pos4) * pos3 + g3 * pos4 * pos3) + g4 * pos4 * (1f - pos3));
                        b = (int)((b * (1f - pos4) * (1f - pos3) + b2 * (1f - pos4) * pos3 + b3 * pos4 * pos3) + b4 * pos4 * (1f - pos3));
                    }
                    else
                    {
                        r = clone.getRComponent(x, y);
                        g = clone.getGComponent(x, y);
                        b = clone.getBComponent(x, y);
                    }
                    imageIn.setPixelColor(x, y, r, g, b);
                }
            }
            return(imageIn);
        }
Beispiel #9
0
        //@Override
        public Image process(Image imageIn)
        {
            Image clone = gradientFx.process(imageIn.clone());

            return(blender.Blend(imageIn, clone));
        }
        //@Override
        public override Image process(Image imageIn)
        {
            int width = imageIn.getWidth();
            int height = imageIn.getHeight();
            int r = 0, g = 0, b = 0;

            Image clone = imageIn.clone();

            clone.clearImage((255 << 24) + (Colors.LightGray.R << 16) + (Colors.LightGray.G << 8) + Colors.LightGray.B);
            Point[] point = new Point[BannerNum];
            if (this.IsHorizontal)
            {//水平方向
                int dh = height / BannerNum;
                int dw = width;
                for (int i = 0; i < BannerNum; i++)
                {
                    point[i] = new Point(0, i * dh);
                }
                for (int x = 0; x < dh; x++)
                {
                    for (int y = 0; y < BannerNum; y++)
                    {
                        for (int k = 0; k < dw; k++)
                        {
                            int xx = (int)point[y].X + k;
                            int yy = (int)point[y].Y + (int)(x / 1.1);
                            r = imageIn.getRComponent(xx, yy);
                            g = imageIn.getGComponent(xx, yy);
                            b = imageIn.getBComponent(xx, yy);
                            clone.setPixelColor(xx, yy, r, g, b);
                        }
                    }
                }
                //对图像其余部分做填充
                for (int xx = 0; xx < width; xx++)
                {
                    for (int yy = (int)point[BannerNum - 1].Y + dh; yy < height; yy++)
                    {
                        r = imageIn.getRComponent(xx, yy);
                        g = imageIn.getGComponent(xx, yy);
                        b = imageIn.getBComponent(xx, yy);
                        clone.setPixelColor(xx, yy, r, g, b);
                    }
                }
            }
            else
            {//垂直方向
                int dw = width / BannerNum;
                int dh = height;
                for (int i = 0; i < BannerNum; i++)
                {
                    point[i] = new Point(i * dw, 0);
                }
                for (int x = 0; x < dw; x++)
                {
                    for (int y = 0; y < BannerNum; y++)
                    {
                        for (int k = 0; k < dh; k++)
                        {
                            int xx = (int)point[y].X + (int)(x / 1.1);
                            int yy = (int)point[y].Y + k;
                            r = imageIn.getRComponent(xx, yy);
                            g = imageIn.getGComponent(xx, yy);
                            b = imageIn.getBComponent(xx, yy);
                            clone.setPixelColor(xx, yy, r, g, b);
                        }
                    }
                }
                //对图像其余部分做填充
                for (int yy = 0; yy < height; yy++)
                {
                    for (int xx = (int)point[BannerNum - 1].X + dw; xx < width; xx++)
                    {
                        r = imageIn.getRComponent(xx, yy);
                        g = imageIn.getGComponent(xx, yy);
                        b = imageIn.getBComponent(xx, yy);
                        clone.setPixelColor(xx, yy, r, g, b);
                    }
                }
            }
            return(clone);
        }
        //@Override
        public Image process(Image imageIn)
        {
            int[,] h = new int[3, 256];
            int[] array            = new int[3];
            int[] rgb              = new int[] { 255, 255, 255 };
            int[] bb               = new int[256];
            int[] gg               = new int[256];
            int[] rr               = new int[256];
            int   intensity        = (int)(this.Intensity * 255f);
            int   intensity_invert = 255 - intensity;

            for (int x = 0; x < imageIn.getWidth() - 1; x++)
            {
                for (int y = 0; y < imageIn.getHeight() - 1; y++)
                {
                    h[0, imageIn.getRComponent(x, y)]++;
                    h[1, imageIn.getGComponent(x, y)]++;
                    h[2, imageIn.getBComponent(x, y)]++;
                }
            }
            int[]   percentileColor = GetPercentileColor(h, 0.005f);
            int[]   meanColor       = GetMeanColor(h);
            int[]   hi    = GetPercentileColor(h, 0.995f);
            float[] gamma = ComputeGamma(percentileColor, meanColor, hi);
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 256; j++)
                {
                    int[] arr = new int[3];
                    for (int n = 0; n < 3; n++)
                    {
                        float percent = j - percentileColor[n];
                        if (percent < 0f)
                        {
                            arr[n] = array[n];
                        }
                        else if ((percent + percentileColor[n]) >= hi[n])
                        {
                            arr[n] = rgb[n];
                        }
                        else
                        {
                            double adjust = array[n] + ((rgb[n] - array[n]) * Math.Pow((double)(percent / ((float)(hi[n] - percentileColor[n]))), (double)gamma[n]));
                            arr[n] = (adjust > 255.0) ? ((int)255.0) : ((adjust < 0.0) ? ((int)0.0) : ((int)adjust));
                        }
                    }
                    rr[j] = arr[0];
                    gg[j] = arr[1];
                    bb[j] = arr[2];
                }
            }
            Image clone = imageIn.clone();
            int   r, g, b;

            for (int x = 0; x < imageIn.getWidth() - 1; x++)
            {
                for (int y = 0; y < imageIn.getHeight() - 1; y++)
                {
                    r = clone.getRComponent(x, y);
                    g = clone.getGComponent(x, y);
                    b = clone.getBComponent(x, y);
                    r = (r * intensity_invert + rr[r] * intensity) >> 8;
                    g = (g * intensity_invert + gg[g] * intensity) >> 8;
                    b = (b * intensity_invert + bb[b] * intensity) >> 8;
                    imageIn.setPixelColor(x, y, r, g, b);
                }
            }
            return(imageIn);//做直方图模式增强
        }
        //@Override
        public virtual Image process(Image imageIn)
        {
            int r, g, b;
            int width = imageIn.getWidth();
            int height = imageIn.getHeight();
            int realxpos = (int)(width * Center.X);
            int realypos = (int)(height * Center.Y);
            float realradius = Math.Min(width, height) * Radius;
            Image clone = imageIn.clone();
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    float pos = 1f - ((float)Math.Sqrt((double)(((x - realxpos) * (x - realxpos)) + (y - realypos) * (y - realypos))) / realradius);
                    if (pos > 0f)
                    {
                        pos = 1f - (Distortion * pos * pos);
                        float pos1 = (x - realxpos) * pos + realxpos;
                        float pos2 = (y - realypos) * pos + realypos;
                        int x1 = (int)pos1;
                        float pos3 = pos1 - x1;
                        int x2 = (pos3 > 0f) ? (x1 + 1) : x1;
                        int y1 = (int)pos2;
                        float pos4 = pos2 - y1;
                        int y2 = (pos4 > 0f) ? (y1 + 1) : y1;
                        if (x1 < 0)
                        {
                            x1 = 0;
                        }
                        else if (x1 >= width)
                        {
                            x1 = width - 1;
                        }
                        if (x2 < 0)
                        {
                            x2 = 0;
                        }
                        else if (x2 >= width)
                        {
                            x2 = width - 1;
                        }
                        if (y1 < 0)
                        {
                            y1 = 0;
                        }
                        else if (y1 >= height)
                        {
                            y1 = height - 1;
                        }
                        if (y2 < 0)
                        {
                            y2 = 0;
                        }
                        else if (y2 >= height)
                        {
                            y2 = height - 1;
                        }
                        r = clone.getRComponent(x1, y1);
                        g = clone.getGComponent(x1, y1);
                        b = clone.getBComponent(x1, y1);

                        int r2 = clone.getRComponent(x2, y1);
                        int g2 = clone.getGComponent(x2, y1);
                        int b2 = clone.getBComponent(x2, y1);
                        int r3 = clone.getRComponent(x2, y2);
                        int g3 = clone.getGComponent(x2, y2);
                        int b3 = clone.getBComponent(x2, y2);
                        int r4 = clone.getRComponent(x1, y2);
                        int g4 = clone.getGComponent(x1, y2);
                        int b4 = clone.getBComponent(x1, y2);
                        r = (int)((r * (1f - pos4) * (1f - pos3) + r2 * (1f - pos4) * pos3 + r3 * pos4 * pos3) + r4 * pos4 * (1f - pos3));
                        g = (int)((g * (1f - pos4) * (1f - pos3) + g2 * (1f - pos4) * pos3 + g3 * pos4 * pos3) + g4 * pos4 * (1f - pos3));
                        b = (int)((b * (1f - pos4) * (1f - pos3) + b2 * (1f - pos4) * pos3 + b3 * pos4 * pos3) + b4 * pos4 * (1f - pos3));
                    }
                    else
                    {
                        r = clone.getRComponent(x, y);
                        g = clone.getGComponent(x, y);
                        b = clone.getBComponent(x, y);
                    }
                    imageIn.setPixelColor(x, y, r, g, b);
                }
            }
            return imageIn;
        }