Exemple #1
0
 //@Override
 public CustomImage process(CustomImage imageIn)
 {
     int r, g, b;
     int num = (int)(this.Intensity * 32768f);
     for (int x = 0; x < imageIn.getWidth(); x++)
     {
         for (int y = 0; y < imageIn.getHeight(); y++)
         {
             r = imageIn.getRComponent(x, y);
             g = imageIn.getGComponent(x, y);
             b = imageIn.getBComponent(x, y);
             if (num != 0)
             {
                 int rr = getRandomInt(-255, 0xff) * num;
                 int gg = getRandomInt(-255, 0xff) * num;
                 int bb = getRandomInt(-255, 0xff) * num;
                 int rrr = r + (rr >> 15);
                 int ggg = g + (gg >> 15);
                 int bbb = b + (bb >> 15);
                 r = (rrr > 0xff) ? ((byte)0xff) : ((rrr < 0) ? ((byte)0) : ((byte)rrr));
                 g = (ggg > 0xff) ? ((byte)0xff) : ((ggg < 0) ? ((byte)0) : ((byte)ggg));
                 b = (bbb > 0xff) ? ((byte)0xff) : ((bbb < 0) ? ((byte)0) : ((byte)bbb));
             }
             imageIn.setPixelColor(x, y, r, g, b);
         }
     }
     return imageIn;
 }
Exemple #2
0
        //@Override
        public override CustomImage process(CustomImage imageIn)
        {
            int width = imageIn.getWidth();
            int halfw = width / 2;
            int height = imageIn.getHeight();
            int halfh = height / 2;
            int R = Math.Min(halfw, halfh);

            Point point = new Point(halfw, halfh);
            int r = 0, g = 0, b = 0;
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    float length = (float)Math.Sqrt(Math.Pow((x - point.X), 2) + Math.Pow((y - point.Y), 2));
                    r = imageIn.getRComponent(x, y);
                    g = imageIn.getGComponent(x, y);
                    b = imageIn.getBComponent(x, y);

                    if (length < R)
                    {
                        float pixel = Light * (1.0f - length / R);
                        r = r + (int)pixel;
                        r = Math.Max(0, Math.Min(r, 255));
                        g = g + (int)pixel;
                        g = Math.Max(0, Math.Min(g, 255));
                        b = b + (int)pixel;
                        b = Math.Max(0, Math.Min(b, 255));
                    }
                    imageIn.setPixelColor(x, y, r, g, b);
                }
            }
            return imageIn;
        }
Exemple #3
0
        public CustomImage process(CustomImage imageIn)
        {
            int tr = (255 << 24) + (Colors.Red.R << 16) + (Colors.Red.G << 8) + Colors.Red.B;
            int tg = (255 << 24) + (Colors.Green.R << 16) + (Colors.Green.G << 8) + Colors.Green.B;
            int tb = (255 << 24) + (Colors.Blue.R << 16) + (Colors.Blue.G << 8) + Colors.Blue.B;
            int r, g, b;
            for (int x = 0; x < imageIn.getWidth(); x++)
            {
                for (int y = 0; y < imageIn.getHeight(); y++)
                {
                    r = (255 - imageIn.getRComponent(x, y));
                    g = (255 - imageIn.getGComponent(x, y));
                    b = (255 - imageIn.getBComponent(x, y));

                    // Convert to gray with constant factors 0.2126, 0.7152, 0.0722
                    int gray = (r * 6966 + g * 23436 + b * 2366) >> 15;

                    // Apply Tint color
                    r = (byte)((gray * tr) >> 8);
                    g = (byte)((gray * tg) >> 8);
                    b = (byte)((gray * tb) >> 8);

                    imageIn.setPixelColor(x, y, r, g, b);
                }
            }
            return imageIn;
        }
Exemple #4
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;//��ֱ��ͼģʽ��ǿ
 }
Exemple #5
0
        //@Override
        public CustomImage process(CustomImage imageIn)
        {
            // Image size
            int width = imageIn.getWidth();
            int height = imageIn.getHeight();
            bool[][] mask = null;
            int[] grayMatrix = new int[256];

            // Init gray matrix
            for (int i = 0; i <= 255; i++) {
            grayMatrix[i] = (255 << 24) + (i << 16) + (i<< 8) + i;
            }

            int [,] luminance = new int[width,height];
            for (int y = 0; y < height ; y++) {
            for (int x = 0; x < width ; x++) {
                if(mask != null && !mask[x][y]){
                    continue;
                }
                luminance[x,y] = (int) Luminance(imageIn.getRComponent(x, y), imageIn.getGComponent(x, y), imageIn.getBComponent(x, y));
            }
            }

            int grayX, grayY;
            int magnitude;
            for (int y = 1; y < height-1; y++) {
            for (int x = 1; x < width-1; x++) {

                if(mask != null && !mask[x][y]){
                    continue;
                }

                grayX = - luminance[x-1,y-1] + luminance[x-1,y-1+2] - 2* luminance[x-1+1,y-1] + 2* luminance[x-1+1,y-1+2] - luminance[x-1+2,y-1]+ luminance[x-1+2,y-1+2];
                grayY = luminance[x-1,y-1] + 2* luminance[x-1,y-1+1] + luminance[x-1,y-1+2] - luminance[x-1+2,y-1] - 2* luminance[x-1+2,y-1+1] - luminance[x-1+2,y-1+2];

                // Magnitudes sum
                magnitude = 255 - truncate(Math.Abs(grayX) + Math.Abs(grayY));
                int grayscaleColor = grayMatrix[magnitude];

                // Apply the color into a new image
                imageIn.setPixelColor(x, y, grayscaleColor);
            }
            }

            return imageIn;
        }
Exemple #6
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 #7
0
        // @Override
        public CustomImage process(CustomImage imageIn)
        {
            // Image size
            int width = imageIn.getWidth();
            int height = imageIn.getHeight();
            bool[,] mask = null;
            int[] grayMatrix = new int[256];

            // Init gray matrix
            int outlineCase = 1;
            double rand = new Random().NextDouble();
            if (rand>0.33 && rand<0.66){
            outlineCase=2;
            }
            else if (rand>0.66){
            outlineCase=3;
            }
            for (int i = 255; i >= 0; i--) {
            int red=i,green=i,blue=i;
            if (i>127)
            {
                switch(outlineCase){
                case 1 :
                    red = 255-i;
                    break;
                case 2 :
                    green = 255-i;
                    break;
                case 3 :
                    blue = 255-i;
                    break;
                }
            }
            grayMatrix[255 - i] = (255 << 24) + (red << 16) + (green << 8) + blue;
            }

            int [,] luminance = new int[width,height];
            for (int y = 0; y < height ; y++) {
            for (int x = 0; x < width ; x++) {
                if(mask != null && !mask[x,y]){
                    continue;
                }
                luminance[x, y] = (int)Luminance(imageIn.getRComponent(x, y), imageIn.getGComponent(x, y), imageIn.getBComponent(x, y));
            }
            }

            int grayX, grayY;
            int magnitude;
            for (int y = 1; y < height-1; y++) {
            for (int x = 1; x < width-1; x++) {
                if(mask != null && !mask[x,y]){
                    continue;
                }

                grayX = - luminance[x-1,y-1] + luminance[x-1,y-1+2] - 2* luminance[x-1+1,y-1] + 2* luminance[x-1+1,y-1+2] - luminance[x-1+2,y-1]+ luminance[x-1+2,y-1+2];
                grayY = luminance[x-1,y-1] + 2* luminance[x-1,y-1+1] + luminance[x-1,y-1+2] - luminance[x-1+2,y-1] - 2* luminance[x-1+2,y-1+1] - luminance[x-1+2,y-1+2];

                // Magnitudes sum
                magnitude = 255 - truncate(Math.Abs(grayX) + Math.Abs(grayY));
                int grayscaleColor = grayMatrix[magnitude];

                // Apply the color into a new image
                imageIn.setPixelColor(x, y, grayscaleColor);
            }
            }

            return imageIn;
        }