Esempio n. 1
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;
        }
Esempio n. 2
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;
 }
Esempio n. 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;
        }
Esempio n. 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;//��ֱ��ͼģʽ��ǿ
 }
Esempio n. 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;
        }
Esempio n. 6
0
 //@Override
 public override CustomImage process(CustomImage imageIn)
 {
     width = imageIn.getWidth();
     height = imageIn.getHeight();
     buf2 = new short[width * height];
     buf1 = new short[width * height];
     source = imageIn.colorArray;
     temp = new int[source.Length];
     DropStone(width / 2, height / 2, Math.Max(width, height) / 4, Math.Max(width, height));
     for (int i = 0; i < 170; i++)
     {
         RippleSpread();
         render();
     }
     imageIn.colorArray = temp;
     return imageIn;
 }
Esempio n. 7
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;
        }
Esempio n. 8
0
        //@Override
        public CustomImage process(CustomImage imageIn)
        {
            int width = imageIn.getWidth();
            int height = imageIn.getHeight();
            double d = this.OriginAngleDegree * 0.0174532925;
            float cos = (float)Math.Cos(d);
            float sin = (float)Math.Sin(d);
            float radio = (cos * width) + (sin * height);
            float dcos = cos * radio;
            float dsin = sin * radio;
            int dist = (int)Math.Sqrt((double)((dcos * dcos) + (dsin * dsin)));
            dist = Math.Max(Math.Max(dist, width), height);

            if ((this.palette == null) || (dist != this.palette.Length))
            {
                this.palette = this.Gradientf.CreatePalette(dist);
            }
            byte[] red = this.palette.Red;
            byte[] green = this.palette.Green;
            byte[] blue = this.palette.Blue;
            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    radio = (cos * j) + (sin * i);
                    dcos = cos * radio;
                    dsin = sin * radio;
                    dist = (int)Math.Sqrt((double)((dcos * dcos) + (dsin * dsin)));
                    imageIn.setPixelColor(j, i, red[dist], green[dist], blue[dist]);
                }
            }
            return imageIn;
        }
Esempio n. 9
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;
        }
Esempio n. 10
0
        //@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;
        }