//@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; }
//@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; }
//@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; }
//@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; }
//@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; }
//@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; }
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; }
//@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; }
//@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; }
//@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; }
//@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; }
//@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; }
protected int GetPixelColor(CustomImage input, int x, int y, int w, int h) { if (x < 0) { x = 0; } else if (x >= w) { x = w - 1; } if (y < 0) { y = 0; } else if (y >= h) { y = h - 1; } return (((255 << 24 | (input.getRComponent(x, y) << 16)) | (input.getGComponent(x, y) << 8)) | input.getBComponent(x, y)); }
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; }
float[] ConvertImageWithPadding(CustomImage imageIn, int width, int height) { int newheight = height + Padding * 2; int newwidth = width + Padding * 2; float[] numArray = new float[(newheight * newwidth) * 3]; int index = 0; int num = 0; for (int i = -3; num < newheight; i++) { int y = i; if (i < 0) { y = 0; } else if (i >= height) { y = height - 1; } int count = 0; int negpadding = -1 * Padding; while (count < newwidth) { int x = negpadding; if (negpadding < 0) { x = 0; } else if (negpadding >= width) { x = width - 1; } numArray[index] = imageIn.getRComponent(x, y) * 0.003921569f; numArray[index + 1] = imageIn.getGComponent(x, y) * 0.003921569f; numArray[index + 2] = imageIn.getBComponent(x, y) * 0.003921569f; count++; negpadding++; index += 3; } num++; } return numArray; }
protected int GetPixelBrightness(CustomImage input, int x, int y, int w, int h) { if (x < 0) { x = 0; } else if (x >= w) { x = w - 1; } if (y < 0) { y = 0; } else if (y >= h) { y = h - 1; } return ((((input.getRComponent(x, y) * 0x1b36) + (input.getGComponent(x, y) * 0x5b8c)) + (input.getBComponent(x, y) * 0x93e)) >> 15); }
/** * 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; }