示例#1
0
 //@Override
 public CustomImage process(CustomImage imageIn)
 {
     int r, g, b;
     int[] array = new int[256];
     int[] numArray = new int[imageIn.getHeight() * imageIn.getWidth()];
     int contrast = (int)(this.ContrastIntensity * 255f);
     int pos = 0;
     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);
             int index = (r * 0x1b36 + g * 0x5b8c + b * 0x93e) >> 15;
             array[index]++;
             numArray[pos] = index;
             pos++;
         }
     }
     for (int i = 1; i < 0x100; i++)
     {
         array[i] += array[i - 1];
     }
     for (int i = 0; i < 0x100; i++)
     {
         array[i] = (array[i] << 8) / imageIn.getHeight() * imageIn.getWidth();
         array[i] = ((contrast * array[i]) >> 8) + (((0xff - contrast) * i) >> 8);
     }
     pos = 0;
     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 (numArray[pos] != 0)
             {
                 int num = array[numArray[pos]];
                 r = (r * num) / numArray[pos];
                 g = (g * num) / numArray[pos];
                 b = (b * num) / numArray[pos];
                 r = (r > 0xff) ? ((byte)0xff) : ((r < 0) ? ((byte)0) : ((byte)r));
                 g = (g > 0xff) ? ((byte)0xff) : ((g < 0) ? ((byte)0) : ((byte)g));
                 b = (b > 0xff) ? ((byte)0xff) : ((b < 0) ? ((byte)0) : ((byte)b));
             }
             imageIn.setPixelColor(x, y, r, g, b);
             pos++;
         }
     }
     return imageIn;
 }
示例#2
0
 //@Override
 public CustomImage process(CustomImage imageIn)
 {
     int width = imageIn.getWidth();
     int height = imageIn.getHeight();
     int r = 0, g = 0, b = 0;
     for (int y = 0; y < height; y++)
     {
         for (int x = 0; x < width; x++)
         {
             if (y % MosiacSize == 0)
             {
                 if (x % MosiacSize == 0)
                 {
                     r = imageIn.getRComponent(x, y);
                     g = imageIn.getGComponent(x, y);
                     b = imageIn.getBComponent(x, y);
                 }
                 imageIn.setPixelColor(x, y, r, g, b);
             }
             else
             {
                 imageIn.setPixelColor(x, y, imageIn.getPixelColor(x, y - 1));
             }
         }
     }
     return imageIn;
 }
示例#3
0
        //@Override
        public CustomImage process(CustomImage imageIn)
        {
            float saturation = this.SaturationFactor + 1f;
            float negosaturation = 1f - saturation;

            int r, g, b, a;
            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);

                    float nego1 = negosaturation * 0.2126f;
                    float ngeo2 = nego1 + saturation;
                    float ngeo3 = negosaturation * 0.7152f;
                    float nego4 = ngeo3 + saturation;
                    float nego5 = negosaturation * 0.0722f;
                    float nego6 = nego5 + saturation;
                    float nego7 = ((r * ngeo2) + (g * ngeo3)) + (b * nego5);
                    float nego8 = ((r * nego1) + (g * nego4)) + (b * nego5);
                    float nego9 = ((r * nego1) + (g * ngeo3)) + (b * nego6);
                    r = (nego7 > 255f) ? ((byte)255f) : ((nego7 < 0f) ? ((byte)0f) : ((byte)nego7));
                    g = (nego8 > 255f) ? ((byte)255f) : ((nego8 < 0f) ? ((byte)0f) : ((byte)nego8));
                    b = (nego9 > 255f) ? ((byte)255f) : ((nego9 < 0f) ? ((byte)0f) : ((byte)nego9));
                    imageIn.setPixelColor(x, y, r, g, b);
                }
            }
            return imageIn;
        }
示例#4
0
        //@Override
        public CustomImage process(CustomImage imageIn)
        {
            int width = imageIn.getWidth();
            int height = imageIn.getHeight();
            CustomImage clone = imageIn.clone();
            int r = 0, g = 0, b = 0;
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    int k = NoiseFilter.getRandomInt(1, 123456);

                    int dx = x + k % 19;
                    int dy = y + k % 19;
                    if (dx >= width)
                    {
                        dx = width - 1;
                    }
                    if (dy >= height)
                    {
                        dy = height - 1;
                    }
                    r = clone.getRComponent(dx, dy);
                    g = clone.getGComponent(dx, dy);
                    b = clone.getBComponent(dx, dy);
                    imageIn.setPixelColor(x, y, r, g, b);
                }
            }
            return imageIn;
        }
示例#5
0
        private void drawTone(int a_x, int a_y, CustomImage imageIn)
        {
            int l_grayIntensity;
            int l_x;
            int l_y;

            for (int x = 0; x < DOT_AREA * DOT_AREA; x++)
            {
                l_x = x % DOT_AREA;
                l_y = x / DOT_AREA;

                if (a_x + l_x < imageIn.getWidth() && a_y + l_y < imageIn.getHeight())
                {

                    l_grayIntensity = 255 - (imageIn.getRComponent(a_x + l_x, a_y + l_y));
                    if (l_grayIntensity > arrDither[x])
                    {
                        imageIn.setPixelColor(a_x + l_x, a_y + l_y, 0, 0, 0);
                    }
                    else
                    {
                        imageIn.setPixelColor(a_x + l_x, a_y + l_y, 255, 255, 255);
                    }
                }
            }
        }
示例#6
0
        private CustomImage ProcessColor(int k00, int k01, int k02, int k20, int k21, int k22, CustomImage imageIn, int thresholdSq)
        {
            int width = imageIn.getWidth();
            int height = imageIn.getHeight();
            int r, g, b;
            CustomImage clone = imageIn.clone();
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    int color1 = GetPixelColor(clone, x - 1, y - 1, width, height);
                    int color2 = GetPixelColor(clone, x, y - 1, width, height);
                    int color3 = GetPixelColor(clone, x + 1, y - 1, width, height);
                    int color4 = GetPixelColor(clone, x - 1, y, width, height);
                    int color5 = GetPixelColor(clone, x + 1, y, width, height);
                    int color6 = GetPixelColor(clone, x - 1, y + 1, width, height);
                    int color7 = GetPixelColor(clone, x, y + 1, width, height);
                    int color8 = GetPixelColor(clone, x + 1, y + 1, width, height);

                    int color1RGB = (0x00FF0000 & color1) >> 16;
                    int color3RGB = (0x00FF0000 & color3) >> 16;
                    int color6RGB = (0x00FF0000 & color6) >> 16;
                    int color8RGB = (0x00FF0000 & color8) >> 16;
                    int colorSum1 = (color1RGB * k00 + color3RGB * k02 + ((0x00FF0000 & color2) >> 16) * k01 + color6RGB * k20 + ((0x00FF0000 & color7) >> 16) * k21 + color8RGB * k22) >> 8;
                    int colorSum2 = (color1RGB * k00 + color3RGB * k20 + ((0x00FF0000 & color4) >> 16) * k01 + color6RGB * k02 + ((0x00FF0000 & color5) >> 16) * k21 + color8RGB * k22) >> 8;
                    r = (((colorSum1 * colorSum1) + (colorSum2 * colorSum2)) > thresholdSq) ? 0 : 0xff;
                    if (this.DoInversion)
                    {
                        r = 255 - r;
                    }

                    color1RGB = (0x0000FF00 & color1) >> 8;
                    color3RGB = (0x0000FF00 & color3) >> 8;
                    color6RGB = (0x0000FF00 & color6) >> 8;
                    color8RGB = (0x0000FF00 & color8) >> 8;
                    colorSum1 = (color1RGB * k00 + color3RGB * k02 + ((0x0000FF00 & color2) >> 8) * k01 + color6RGB * k20 + ((0x0000FF00 & color7) >> 8) * k21 + color8RGB * k22) >> 8;
                    colorSum2 = (color1RGB * k00 + color3RGB * k20 + ((0x0000FF00 & color4) >> 8) * k01 + color6RGB * k02 + ((0x0000FF00 & color5) >> 8) * k21 + color8RGB * k22) >> 8;
                    g = (((colorSum1 * colorSum1) + (colorSum2 * colorSum2)) > thresholdSq) ? 0 : 0xff;
                    if (this.DoInversion)
                    {
                        g = 255 - g;
                    }

                    color1RGB = 0x000000FF & color1;
                    color3RGB = 0x000000FF & color3;
                    color6RGB = 0x000000FF & color6;
                    color8RGB = 0x000000FF & color8;
                    colorSum1 = (color1RGB * k00 + color3RGB * k02 + (0x000000FF & color2) * k01 + color6RGB * k20 + (0x000000FF & color7) * k21 + color8RGB * k22) >> 8;
                    colorSum2 = (color1RGB * k00 + color3RGB * k20 + (0x000000FF & color4) * k01 + color6RGB * k02 + (0x000000FF & color5) * k21 + color8RGB * k22) >> 8;
                    b = (((colorSum1 * colorSum1) + (colorSum2 * colorSum2)) > thresholdSq) ? 0 : 0xff;
                    if (DoInversion)
                    {
                        b = 255 - b;
                    }
                    imageIn.setPixelColor(x, y, r, g, b);
                }
            }
            return imageIn;
        }
示例#7
0
        //@Override
        public CustomImage process(CustomImage imageIn)
        {
            int r, g, b;
            // Convert to integer factors
            int bfi = (int)(BrightnessFactor * 255);
            float cf = 1f + ContrastFactor;
            cf *= cf;
            int cfi = (int)(cf * 32768) + 1;
            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);
                    // Modify brightness (addition)
                    if (bfi != 0)
                    {
                        // Add brightness
                        int ri = r + bfi;
                        int gi = g + bfi;
                        int bi = b + bfi;
                        // Clamp to byte boundaries
                        r = (byte)(ri > 255 ? 255 : (ri < 0 ? 0 : ri));
                        g = (byte)(gi > 255 ? 255 : (gi < 0 ? 0 : gi));
                        b = (byte)(bi > 255 ? 255 : (bi < 0 ? 0 : bi));
                    }
                    // Modifiy contrast (multiplication)
                    if (cfi != 32769)
                    {
                        // Transform to range [-128, 127]
                        int ri = r - 128;
                        int gi = g - 128;
                        int bi = b - 128;

                        // Multiply contrast factor
                        ri = (ri * cfi) >> 15;
                        gi = (gi * cfi) >> 15;
                        bi = (bi * cfi) >> 15;

                        // Transform back to range [0, 255]
                        ri = ri + 128;
                        gi = gi + 128;
                        bi = bi + 128;

                        // Clamp to byte boundaries
                        r = (byte)(ri > 255 ? 255 : (ri < 0 ? 0 : ri));
                        g = (byte)(gi > 255 ? 255 : (gi < 0 ? 0 : gi));
                        b = (byte)(bi > 255 ? 255 : (bi < 0 ? 0 : bi));
                    }
                    imageIn.setPixelColor(x, y, r, g, b);
                }
            }
            return imageIn;
        }
示例#8
0
 //@Override
 public CustomImage process(CustomImage imageIn)
 {
     for (int x = 0; x < imageIn.getWidth(); x += DOT_AREA)
     {
         for (int y = 0; y < imageIn.getHeight(); y += DOT_AREA)
         {
             drawTone(x, y, imageIn);
         }
     }
     return imageIn;
 }
示例#9
0
 /**
  * Method to extrapolate out
  *
  * @param imageIn
  * @param a_x
  * @param a_y
  * @param squareSize
  * @param a_rgb
  */
 private void fillRect(CustomImage imageIn, int a_x, int a_y, int squareSize, int a_rgb)
 {
     for (int x = a_x; x < a_x + squareSize; x++)
     {
         for (int y = a_y; y < a_y + squareSize; y++)
         {
             if (x < imageIn.getWidth() && y < imageIn.getHeight())
             {
                 imageIn.setPixelColor(x, y, a_rgb);
             }
         }
     }
 }
示例#10
0
        //@Override
        public CustomImage process(CustomImage imageIn)
        {
            int l_rgb;
            for (int x = 0; x < imageIn.getWidth(); x += pixelSize)
            {
                for (int y = 0; y < imageIn.getHeight(); y += pixelSize)
                {
                    l_rgb = getPredominantRGB(imageIn, x, y, pixelSize);
                    fillRect(imageIn, x, y, pixelSize, l_rgb);
                }
            }

            return imageIn;
        }
示例#11
0
 public CustomImage process(CustomImage imageIn)
 {
     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));
             imageIn.setPixelColor(x, y, r, g, b);
         }
     }
     return imageIn;
 }
示例#12
0
 //@Override
 public CustomImage process(CustomImage imageIn)
 {
     int r, g, b, corfinal;
     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);
             corfinal = (int)((r * 0.3) + (b * 0.59) + (g * 0.11));
             imageIn.setPixelColor(x, y, corfinal, corfinal, corfinal);
         }
     }
     return imageIn;
 }
示例#13
0
        //@Override
        public CustomImage process(CustomImage imageIn)
        {
            int r, g, b, a;
            int ratio = imageIn.getWidth() > imageIn.getHeight() ? imageIn.getHeight() * 32768 / imageIn.getWidth() : imageIn.getWidth() * 32768 / imageIn.getHeight();

            // Calculate center, min and max
            int cx = imageIn.getWidth() >> 1;
            int cy = imageIn.getHeight() >> 1;
            int max = cx * cx + cy * cy;
            int min = (int)(max * (1 - Size));
            int diff = max - min;

            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);

                    // Calculate distance to center and adapt aspect ratio
                    int dx = cx - x;
                    int dy = cy - y;
                    if (imageIn.getWidth() > imageIn.getHeight())
                    {
                        dx = (dx * ratio) >> 15;
                    }
                    else
                    {
                        dy = (dy * ratio) >> 15;
                    }
                    int distSq = dx * dx + dy * dy;

                    if (distSq > min)
                    {
                        // Calculate vignette
                        int v = ((max - distSq) << 8) / diff;
                        v *= v;

                        // Apply vignette
                        int ri = (r * v) >> 16;
                        int gi = (g * v) >> 16;
                        int bi = (b * v) >> 16;

                        // Check bounds
                        r = (byte)(ri > 255 ? 255 : (ri < 0 ? 0 : ri));
                        g = (byte)(gi > 255 ? 255 : (gi < 0 ? 0 : gi));
                        b = (byte)(bi > 255 ? 255 : (bi < 0 ? 0 : bi));
                    }

                    imageIn.setPixelColor(x, y, r, g, b);
                }
            }
            return imageIn;
        }
示例#14
0
        //@Override
        public CustomImage process(CustomImage imageIn)
        {
            int r, g, b;
            for (int x = 0; x < imageIn.getWidth(); x++)
            {
                for (int y = 0; y < imageIn.getHeight(); y += 3)
                {
                    r = 0;
                    g = 0;
                    b = 0;
                    for (int w = 0; w < 3; w++)
                    {
                        if (y + w < imageIn.getHeight())
                        {
                            r += (imageIn.getRComponent(x, y + w)) / 2;
                            g += (imageIn.getGComponent(x, y + w)) / 2;
                            b += (imageIn.getBComponent(x, y + w)) / 2;
                        }
                    }
                    r = getValidInterval(r);
                    g = getValidInterval(g);
                    b = getValidInterval(b);

                    for (int w = 0; w < 3; w++)
                    {
                        if (y + w < imageIn.getHeight())
                        {
                            if (w == 0)
                            {
                                imageIn.setPixelColor(x, y + w, r, 0, 0);
                            }
                            else if (w == 1)
                            {
                                imageIn.setPixelColor(x, y + w, 0, g, 0);
                            }
                            else if (w == 2)
                            {
                                imageIn.setPixelColor(x, y + w, 0, 0, b);
                            }
                        }
                    }
                }
            }
            return imageIn;
        }
示例#15
0
 //@Override
 public CustomImage process(CustomImage imageIn)
 {
     int width = imageIn.getWidth();
     int height = imageIn.getHeight();
     float[] imageArray = ConvertImageWithPadding(imageIn, width, height);
     imageArray = ApplyBlur(imageArray, width, height);
     int newwidth = width + Padding * 2;
     for (int i = 0; i < height; i++)
     {
         int num = ((i + 3) * newwidth) + 3;
         for (int j = 0; j < width; j++)
         {
             int pos = (num + j) * 3;
             imageIn.setPixelColor(j, i, (byte)(imageArray[pos] * 255f), (byte)(imageArray[pos + 1] * 255f), (byte)(imageArray[pos + 2] * 255f));
         }
     }
     return imageIn;
 }
示例#16
0
        //@Override
        public CustomImage process(CustomImage imageIn)
        {
            int r, g, b;
             int width = imageIn.getWidth();
             int height = imageIn.getHeight();
             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 * (1 - Size));
             int diff = max - min;

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

                  // Calculate distance to center and adapt aspect ratio
                  int dx = cx - x;
                  int dy = cy - y;
                  if (width > height){
                     dx = (dx * ratio) >> 15;
                  }
                  else{
                     dy = (dy * ratio) >> 15;
                  }
                  int distSq = dx * dx + dy * dy;
                  float v =  ((float)distSq / diff) * 255;
                  r = (int)(r + (v));
                  g = (int)(g + (v));
                  b = (int)(b + (v));
                  r = (byte)(r > 255 ? 255 : (r < 0 ? 0 : r));
                  g = (byte)(g > 255 ? 255 : (g < 0 ? 0 : g));
                  b = (byte)(b > 255 ? 255 : (b < 0 ? 0 : b));
                  imageIn.setPixelColor(x,y,r,g,b);
              }
             }
             return imageIn;
        }
示例#17
0
 //@Override
 public CustomImage process(CustomImage imageIn)
 {
     int width = imageIn.getWidth();
     int height = imageIn.getHeight();
     CustomImage clone = imageIn.clone();
     int r = 0, g = 0, b = 0, avg = 0;
     for (int x = 0; x < width; x++)
     {
         for (int y = 0; y < height; y++)
         {
             r = clone.getRComponent(x, y);
             g = clone.getGComponent(x, y);
             b = clone.getBComponent(x, y);
             avg = (r + g + b) / 3;
             avg = avg >= ThreshHold ? 255 : 0;
             imageIn.setPixelColor(x, y, avg, avg, avg);
         }
     }
     return imageIn;
 }
示例#18
0
        //@Override
        public CustomImage process(CustomImage imageIn)
        {
            int r, g, b;
            int threshold = (int)(this.Threshold * 255f);

            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);

                    int rgb = (((r * 0x1b36) + (g * 0x5b8c)) + (b * 0x93e)) >> 15;
                    r = g = b = rgb > threshold ? 0xff : 0;
                    imageIn.setPixelColor(x, y, r, g, b);
                }
            }
            return imageIn;
        }
示例#19
0
 //@Override
 public CustomImage process(CustomImage imageIn)
 {
     int width = imageIn.getWidth();
     int height = imageIn.getHeight();
     CustomImage clone = imageIn.clone();
     int r = 0, g = 0, b = 0, xx = 0, yy = 0;
     for (int x = 0; x < width; x++)
     {
         for (int y = 0; y < height; y++)
         {
             int pos = NoiseFilter.getRandomInt(1, 10000) % Model;
             xx = (x + pos) < width ? (x + pos) : (x - pos) >= 0 ? (x - pos) : x;
             yy = (y + pos) < height ? (y + pos) : (y - pos) >= 0 ? (y - pos) : y;
             r = clone.getRComponent(xx, yy);
             g = clone.getGComponent(xx, yy);
             b = clone.getBComponent(xx, yy);
             imageIn.setPixelColor(x, y, r, g, b);
         }
     }
     return imageIn;
 }
示例#20
0
 //@Override
 public CustomImage process(CustomImage imageIn)
 {
     int r, g, b, a;
     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);
             float quanR = (((float)((int)(r * 0.003921569f * levels))) / levels) * 255f;
             float quanG = (((float)((int)(g * 0.003921569f * levels))) / levels) * 255f;
             float quanB = (((float)((int)(b * 0.003921569f * levels))) / levels) * 255f;
             r = (quanR > 255f) ? 255 : ((quanR < 0f) ? 0 : ((byte)quanR));
             g = (quanG > 255f) ? 255 : ((quanG < 0f) ? 0 : ((byte)quanG));
             b = (quanB > 255f) ? 255 : ((quanB < 0f) ? 0 : ((byte)quanB));
             imageIn.setPixelColor(x, y, r, g, b);
         }
     }
     return imageIn;
 }
示例#21
0
        //@Override
        public CustomImage process(CustomImage imageIn)
        {
            for (int x = 0; x < (imageIn.getWidth() - 1); x++)
            {
                for (int y = 0; y < imageIn.getHeight(); y++)
                {
                    int rr = imageIn.getRComponent(x, y) - imageIn.getRComponent(x + 1, y) + 128;
                    int gg = imageIn.getGComponent(x, y) - imageIn.getGComponent(x + 1, y) + 128;
                    int bb = imageIn.getBComponent(x, y) - imageIn.getBComponent(x + 1, y) + 128;

                    if (rr > 255) rr = 255;
                    if (rr < 0) rr = 0;
                    if (gg > 255) gg = 255;
                    if (gg < 0) gg = 0;
                    if (bb > 255) bb = 255;
                    if (bb < 0) bb = 0;

                    imageIn.setPixelColor(x, y, rr, gg, bb);
                }
            }
            return imageIn;
        }
示例#22
0
        //@Override
        public CustomImage process(CustomImage imageIn)
        {
            int r, g, b;

            int height = imageIn.getHeight();
            int width = imageIn.getWidth();
            int start;
            int limit;
            CustomImage clone = imageIn.clone();

            if (this.IsHorizontal)
            {
                int y_offset = (int)(this.Offset * height);
                if (this.Offset > 0.5f)
                {
                    start = y_offset - (height - y_offset);
                    limit = y_offset;
                }
                else
                {
                    start = y_offset;
                    limit = y_offset + y_offset;
                }
                if (start < 0)
                {
                    start = 0;
                }
                for (int y = start; (y < limit) && (y < height); y++)
                {
                    int y_pos = (-y + (2 * y_offset)) - 1;
                    y_pos = (y_pos < 0) ? 0 : (y_pos >= height ? height - 1 : y_pos);
                    for (int x = 0; x < width; x++)
                    {
                        r = clone.getRComponent(x, y);
                        g = clone.getGComponent(x, y);
                        b = clone.getBComponent(x, y);
                        imageIn.setPixelColor(x, y_pos, r, g, b);
                    }
                }
            }
            else
            {
                int x_offset = (int)(this.Offset * width);
                if (this.Offset > 0.5f)
                {
                    start = x_offset - (width - x_offset);
                    limit = x_offset;
                }
                else
                {
                    start = x_offset;
                    limit = x_offset + x_offset;
                }
                if (start < 0)
                {
                    start = 0;
                }
                for (int x = start; (x < limit) && (x < width); x++)
                {
                    int x_pos = (-x + (2 * x_offset)) - 1;
                    x_pos = x_pos < 0 ? 0 : (x_pos >= width ? width - 1 : x_pos);
                    for (int y = 0; y < height; y++)
                    {
                        r = clone.getRComponent(x, y);
                        g = clone.getGComponent(x, y);
                        b = clone.getBComponent(x, y);
                        imageIn.setPixelColor(x_pos, y, r, g, b);
                    }
                }
            }
            return imageIn;
        }
示例#23
0
        /**
         * Method gets the predominant colour pixels to extrapolate
         * the pixelation from
         *
         * @param imageIn
         * @param a_x
         * @param a_y
         * @param squareSize
         * @return
         */
        private int getPredominantRGB(CustomImage imageIn, int a_x, int a_y, int squareSize)
        {
            int red = -1;
            int green = -1;
            int blue = -1;

            for (int x = a_x; x < a_x + squareSize; x++)
            {
                for (int y = a_y; y < a_y + squareSize; y++)
                {
                    if (x < imageIn.getWidth() && y < imageIn.getHeight())
                    {
                        if (red == -1)
                        {
                            red = imageIn.getRComponent(x, y);
                        }
                        else
                        {
                            red = (red + imageIn.getRComponent(x, y)) / 2;
                        }
                        if (green == -1)
                        {
                            green = imageIn.getGComponent(x, y);
                        }
                        else
                        {
                            green = (green + imageIn.getGComponent(x, y)) / 2;
                        }
                        if (blue == -1)
                        {
                            blue = imageIn.getBComponent(x, y);
                        }
                        else
                        {
                            blue = (blue + imageIn.getBComponent(x, y)) / 2;
                        }
                    }
                }
            }
            return (255 << 24) + (red << 16) + (green << 8) + blue;
        }
示例#24
0
        //@Override
        public CustomImage process(CustomImage imageIn)
        {
            int color;
            int width = imageIn.getWidth();
            int height = imageIn.getHeight();
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    int r = 0, g = 0, b = 0;
                    float value = kernel[0,0];
                    if (value != 0)
                    {
                        color = GetPixelColor(imageIn, x - 1, y - 1, width, height);
                        r +=(int)( ((0x00FF0000 & color) >> 16) * value);
                        g +=(int)( ((0x0000FF00 & color) >> 8) * value);
                        b +=(int)( (0x000000FF & color) * value);
                    }
                    value = kernel[0,1];
                    if (value != 0)
                    {
                        color = GetPixelColor(imageIn, x, y - 1, width, height);
                        r +=(int)( ((0x00FF0000 & color) >> 16) * value);
                        g +=(int)( ((0x0000FF00 & color) >> 8) * value);
                        b +=(int)( (0x000000FF & color) * value);
                    }
                    value = kernel[0,2];
                    if (value != 0)
                    {
                        color = GetPixelColor(imageIn, x + 1, y - 1, width, height);
                        r +=(int)( ((0x00FF0000 & color) >> 16) * value);
                        g +=(int)( ((0x0000FF00 & color) >> 8) * value);
                        b +=(int)( (0x000000FF & color) * value);
                    }
                    value = kernel[1,0];
                    if (value != 0)
                    {
                        color = GetPixelColor(imageIn, x - 1, y, width, height);
                        r +=(int)( ((0x00FF0000 & color) >> 16) * value);
                        g +=(int)( ((0x0000FF00 & color) >> 8) * value);
                        b +=(int)( (0x000000FF & color) * value);
                    }
                    value = kernel[1,1];
                    if (value != 0)
                    {
                        color = GetPixelColor(imageIn, x, y, width, height);
                        r +=(int)( ((0x00FF0000 & color) >> 0x10) * value);
                        g +=(int)( ((0x0000FF00 & color) >> 8) * value);
                        b +=(int)( (0x000000FF & color) * value);
                    }
                    value = kernel[1,2];
                    if (value != 0)
                    {
                        color = GetPixelColor(imageIn, x + 1, y, width, height);
                        r +=(int)( ((0x00FF0000 & color) >> 16) * value);
                        g +=(int)( ((0x0000FF00 & color) >> 8) * value);
                        b +=(int)( (0x000000FF & color) * value);
                    }
                    value = kernel[2,0];
                    if (value != 0)
                    {
                        color = GetPixelColor(imageIn, x - 1, y + 1, width, height);
                        r +=(int)( ((0x00FF0000 & color) >> 16) * value);
                        g +=(int)( ((0x0000FF00 & color) >> 8) * value);
                        b +=(int)( (0x000000FF & color) * value);
                    }
                    value = kernel[2,1];
                    if (value != 0)
                    {
                        color = GetPixelColor(imageIn, x, y + 1, width, height);
                        r +=(int)( ((0x00FF0000 & color) >> 16) * value);
                        g +=(int)( ((0x0000FF00 & color) >> 8) * value);
                        b +=(int)( (0x000000FF & color) * value);
                    }
                    value = kernel[2,2];
                    if (value != 0)
                    {
                        color = GetPixelColor(imageIn, x + 1, y + 1, width, height);
                        r +=(int)(((0x00FF0000 & color) >> 16) * value);
                        g +=(int)( ((0x0000FF00 & color) >> 8) * value);
                        b += (int)((0x000000FF & color) * value);
                    }
                    r = (r / this.factor) + this.offset;
                    g = (g / this.factor) + this.offset;
                    b = (b / this.factor) + this.offset;
                    if (r < 0)
                    {
                        r = 0;
                    }
                    if (r > 0xff)
                    {
                        r = 0xff;
                    }
                    if (b < 0)
                    {
                        b = 0;
                    }
                    if (b > 0xff)
                    {
                        b = 0xff;
                    }
                    if (g < 0)
                    {
                        g = 0;
                    }
                    if (g > 0xff)
                    {
                        g = 0xff;
                    }
                    imageIn.setPixelColor(x, y, r, g, b);
                }
            }

            return imageIn;
        }
示例#25
0
        public CustomImage Blend(CustomImage source1, CustomImage source2)
        {
            int num = (int)(Mixture * 255f);
            int num2 = 255 - num;
            for (int x = 0; x < source1.getWidth(); x++)
            {
                for (int y = 0; y < source1.getHeight(); y++)
                {
                    int r = 0, g = 0, b = 0;
                    int r1 = source1.getRComponent(x, y);
                    int g1 = source1.getGComponent(x, y);
                    int b1 = source1.getBComponent(x, y);
                    int r2 = source2.getRComponent(x, y);
                    int g2 = source2.getGComponent(x, y);
                    int b2 = source2.getBComponent(x, y);
                    switch (Mode)
                    {
                        case 1:
                            {//Additive
                                r = r1 + r2;
                                g = g1 + g2;
                                b = b1 + b2;
                                r = (r > 255) ? 255 : r;
                                g = (g > 255) ? 255 : g;
                                b = (b > 255) ? 255 : b;
                                break;
                            }
                        case 2:
                            {//Subractive
                                r = r1 + r2;
                                g = g1 + g2;
                                b = b1 + b2;
                                r = (r < 255) ? 0 : (r - 255);
                                g = (g < 255) ? 0 : (g - 255);
                                b = (b < 255) ? 0 : (b - 255);
                                break;
                            }
                        case 3:
                            {//Multiply
                                r = (r1 * r2) / 255;
                                g = (g1 * g2) / 255;
                                b = (b1 * b2) / 255;
                                break;
                            }
                        case 4:
                            {//Overlay
                                r = (r2 < 0x80) ? (((2 * r1) * r2) / 255) : (255 - (((2 * (255 - r1)) * (255 - r2)) / 255));
                                g = (g2 < 0x80) ? (((2 * g1) * g2) / 255) : (255 - (((2 * (255 - g1)) * (255 - g2)) / 255));
                                b = (b2 < 0x80) ? (((2 * b1) * b2) / 255) : (255 - (((2 * (255 - b1)) * (255 - b2)) / 255));
                                break;
                            }
                        case 5:
                            {//ColorDodge
                                r = (r1 << 8) / (255 - ((r2 != 255) ? r2 : 0xfe));
                                g = (g1 << 8) / (255 - ((g2 != 255) ? g2 : 0xfe));
                                b = (b1 << 8) / (255 - ((b2 != 255) ? b2 : 0xfe));
                                r = (r2 == 255) ? r2 : ((r < 255) ? r : 255);
                                g = (g2 == 255) ? g2 : ((g < 255) ? g : 255);
                                b = (b2 == 255) ? b2 : ((b < 255) ? b : 255);
                                break;
                            }
                        case 6:
                            {//ColorBurn
                                r = 255 - (((255 - r1) << 8) / ((r2 != 0) ? r2 : 1));
                                g = 255 - (((255 - g1) << 8) / ((g2 != 0) ? g2 : 1));
                                b = 255 - (((255 - b1) << 8) / ((b2 != 0) ? b2 : 1));
                                r = (r2 == 0) ? r2 : ((r > 0) ? r : 0);
                                g = (g2 == 0) ? g2 : ((g > 0) ? g : 0);
                                b = (b2 == 0) ? b2 : ((b > 0) ? b : 0);
                                break;
                            }
                        case 7://Lighten
                            r = (r2 > r1) ? r2 : r1;
                            g = (g2 > g1) ? g2 : g1;
                            b = (b2 > b1) ? b2 : b1;
                            break;
                        case 8:
                            {//Darken
                                r = (r2 > r1) ? r1 : r2;
                                g = (g2 > g1) ? g1 : g2;
                                b = (b2 > b1) ? b1 : b2;
                                break;
                            }
                        case 9:
                            {//Reflect
                                r = (r1 * r1) / (255 - ((r2 != 255) ? r2 : 0xfe));
                                g = (g1 * g1) / (255 - ((g2 != 255) ? g2 : 0xfe));
                                b = (b1 * b1) / (255 - ((b2 != 255) ? b2 : 0xfe));
                                r = (r2 == 255) ? r2 : ((r < 255) ? r : 255);
                                g = (g2 == 255) ? g2 : ((g < 255) ? g : 255);
                                b = (b2 == 255) ? b2 : ((b < 255) ? b : 255);
                                break;
                            }
                        case 10:
                            {//Glow
                                r = (r2 * r2) / (255 - ((r1 != 255) ? r1 : 0xfe));
                                g = (g2 * g2) / (255 - ((g1 != 255) ? g1 : 0xfe));
                                b = (b2 * b2) / (255 - ((b1 != 255) ? b1 : 0xfe));
                                r = (r1 == 255) ? r1 : ((r < 255) ? r : 255);
                                g = (g1 == 255) ? g1 : ((g < 255) ? g : 255);
                                b = (b1 == 255) ? b1 : ((b < 255) ? b : 255);
                                break;
                            }
                        case 11:
                            {//LinearLight
                                /*if (r2 >= 128){
                                    r = r1 + (2 * (r2 - 128));
                                    r = (r > 255) ? 255 : r;
                                    break;
                                }
                                r = r1 + (2 * r2);
                                r = (r < 255) ? 0 : (r - 255);
                                */
                                if (r2 < 128)
                                {
                                    r = r1 + (2 * r2);
                                    r = (r < 255) ? 0 : (r - 255);
                                }
                                else
                                {
                                    r = r1 + (2 * (r2 - 128));
                                    r = (r > 255) ? 255 : r;
                                }
                                if (g2 < 128)
                                {
                                    g = g1 + (2 * g2);
                                    g = (g < 255) ? 0 : (g - 255);
                                }
                                else
                                {
                                    g = g1 + (2 * (g2 - 128));
                                    g = (g > 255) ? 255 : g;
                                }
                                if (b2 < 128)
                                {
                                    b = b1 + (2 * b2);
                                    b = (b < 255) ? 0 : (b - 255);
                                }
                                else
                                {
                                    b = b1 + (2 * (b2 - 128));
                                    b = (b > 255) ? 255 : b;
                                }
                                break;
                            }
                        case 12:
                            { //Frame
                                if ((r2 == 0 && g2 == 0 && r2 == 0))
                                {//探测边框颜色(r2 > 230 && g2 > 230 && b2 > 230) ||
                                    r = r1;
                                    g = g1;
                                    b = b1;
                                }
                                else
                                {
                                    r = r2;
                                    g = g2;
                                    b = b2;
                                }
                                break;
                            }
                        default:
                            r = r2;
                            g = g2;
                            b = b2;
                            break;
                    }

                    r = (r1 * num2) + (r * num);
                    g = (g1 * num2) + (g * num);
                    b = (b1 * num2) + (b * num);
                    source1.setPixelColor(x, y, r >> 8, g >> 8, b >> 8);
                    //input1.setPixelColour(x, y, r, g, b);
                }
            }
            return source1;
        }
示例#26
0
 private CustomImage ProcessGray(int k00, int k01, int k02, int k20, int k21, int k22, CustomImage imageIn, int thresholdSq)
 {
     int width = imageIn.getWidth();
     int height = imageIn.getHeight();
     CustomImage clone = imageIn.clone();
     for (int x = 0; x < width; x++)
     {
         for (int y = 0; y < height; y++)
         {
             int color1 = GetPixelBrightness(clone, x - 1, y - 1, width, height);
             int color2 = GetPixelBrightness(clone, x, y - 1, width, height);
             int color3 = GetPixelBrightness(clone, x + 1, y - 1, width, height);
             int color4 = GetPixelBrightness(clone, x - 1, y, width, height);
             int color5 = GetPixelBrightness(clone, x + 1, y, width, height);
             int color6 = GetPixelBrightness(clone, x - 1, y + 1, width, height);
             int color7 = GetPixelBrightness(clone, x, y + 1, width, height);
             int color8 = GetPixelBrightness(clone, x + 1, y + 1, width, height);
             int colorSum1 = (color1 * k00 + color2 * k01 + color3 * k02 + color6 * k20 + color7 * k21 + color8 * k22) >> 8;
             int colorSum2 = (color1 * k00 + color3 * k20 + color4 * k01 + color5 * k21 + color6 * k02 + color8 * k22) >> 8;
             int rgb = (((colorSum1 * colorSum1) + (colorSum2 * colorSum2)) > thresholdSq) ? 0 : 0xff;
             if (DoInversion)
             {
                 rgb = 0xff - rgb;
             }
             imageIn.setPixelColor(x, y, rgb, rgb, rgb);
         }
     }
     return imageIn;
 }