Exemple #1
0
 //@Override
 public CustomImage process(CustomImage 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];
     }
     }
     CustomImage 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 CustomImage process(CustomImage 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;
            CustomImage 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;
        }
Exemple #3
0
        //@Override
        public override CustomImage process(CustomImage imageIn)
        {
            int width = imageIn.getWidth();
            int height = imageIn.getHeight();
            int r = 0, g = 0, b = 0;

            CustomImage clone = imageIn.clone();
            clone.clearImage((255 << 24) + (Colors.LightGray.R << 16) + (Colors.LightGray.G << 8) + Colors.LightGray.B);

            Point[] point = new Point[BannerNum];
            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.8);
                        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);
                }
            }

            //垂直方向
            point = new Point[BannerNum];
            dw = width / BannerNum;
            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.8);
                        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;
        }
Exemple #4
0
 //@Override
 public CustomImage process(CustomImage imageIn)
 {
     CustomImage clone = gradientFx.process(imageIn.clone());
     return blender.Blend(imageIn, clone);
 }