public Image process(Image 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; }
//@Override public override Image process(Image 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; }
//@Override public Image process(Image imageIn) { double width = imageIn.getWidth(); double height = imageIn.getHeight(); Image clone = imageIn.clone(); int r, g, b; for (int x = 0; x < (width - 1); x++) { for (int y = 0; y < (height - 1); y++) { r = imageIn.getRComponent(x, y); g = imageIn.getGComponent(x, y); b = imageIn.getBComponent(x, y); _scale = Math.Sqrt(width * width + height * height) / 2; _offset = (int)(_scale / 2); double cx = (x - width / 2.0) / _scale; double cy = (y - height / 2.0) / _scale; double angle = Math.Floor(Math.Atan2(cy, cx) / 2.0 / _amount) * 2.0 * _amount + _amount; double radius = Math.Sqrt(cx * cx + cy * cy); int xx = (int)(x - _offset * Math.Cos(angle)); int yy = (int)(y - _offset * Math.Sin(angle)); xx = Function.FClamp(xx, 0, (int)(width - 1)); yy = Function.FClamp(yy, 0, (int)(height - 1)); r = Function.FClamp0255(r + radius * (clone.getRComponent(xx, yy) - r)); g = Function.FClamp0255(g + radius * (clone.getGComponent(xx, yy) - g)); b = Function.FClamp0255(b + radius * (clone.getBComponent(xx, yy) - b)); imageIn.setPixelColor(x, y, r, g, b); } } return imageIn; }
//@Override public Image process(Image 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; }
//@Override public Image process(Image imageIn) { int r, g, b; 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); double l = _lum_tab[GetGrayscale(r, g, b)] ; int cr = HLStoRGB (_hue, l, _saturation) ; imageIn.setPixelColor(x, y, cr); } } return imageIn; }
public Image process(Image imageIn) { int r, g, b; HslColor hsl = new HslColor(HueFactor, 0, 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); HslColor.RgbToHsl(r, g, b, hsl); hsl.h = this.HueFactor; int color = HslColor.HslToRgb(hsl); imageIn.setPixelColor(x, y, color); } } return imageIn; }
public Image process(Image imageIn) { // get source image size int width = imageIn.getWidth(); int height = imageIn.getHeight(); // processing region's dimension int widthToProcess = width; int heightToProcess = height; // if generator was specified, then generate a texture // otherwise use provided texture if ( textureGenerator != null ) { texture = textureGenerator.Generate( width, height ); } else { widthToProcess = Math.Min( width, texture.GetLength( 1 ) ); heightToProcess = Math.Min( height, texture.GetLength( 0 ) ); } int r, g, b; // texture for ( int y = 0; y < heightToProcess; y++ ) { for ( int x = 0; x < widthToProcess; x++ ) { double t = texture[y, x]; r = imageIn.getRComponent(x, y); g = imageIn.getGComponent(x, y); b = imageIn.getBComponent(x, y); // process each pixel r = (byte) Math.Min( 255.0f, ( preserveLevel * r) + ( filterLevel * r) * t ); g = (byte) Math.Min( 255.0f, ( preserveLevel * g) + ( filterLevel * g) * t ); b = (byte) Math.Min( 255.0f, ( preserveLevel * b) + ( filterLevel * b) * t ); imageIn.setPixelColor(x, y, r, g, b); } } return imageIn; }
//@Override public override Image process(Image imageIn) { int width = imageIn.getWidth(); int height = imageIn.getHeight(); int r = 0, g = 0, b = 0; Image clone = imageIn.clone(); clone.clearImage((255 << 24) + (Colors.LightGray.R << 16) + (Colors.LightGray.G << 8) + Colors.LightGray.B); Point[] point = new Point[BannerNum]; if (this.IsHorizontal) {//ˮƽ���� 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.1); 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); } } } else {//��ֱ���� int dw = width / BannerNum; int 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.1); 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; }
public override Image process(Image imageIn) { int r, g, b; int width = imageIn.getWidth(); int height = imageIn.getHeight(); double hw = width / 2.0; double hh = height / 2.0; 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 * 0.5); int diff = max - min; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { if (m_focusType == 1)//椭圆 { // Calculate distance to center and adapt aspect ratio int dx = cx - x; int dy = cy - y; if (imageIn.getWidth() > imageIn.getHeight()) { dy = (dy * ratio) >> 14; } else { dx = (dx * ratio) >> 14; } int distSq = dx * dx + dy * dy; if (distSq <= min) continue; } else if (m_focusType == 2)//长方框 { bool inarray = false; if ((x < m_size) && (y < height - x) && (y >= x)) inarray = true; // left else if ((y < m_size) && (x < width - y) && (x >= y)) inarray = true; // top else if ((x > width - m_size) && (y >= width - x) && (y < height + x - width)) inarray = true; // right else if (y > height - m_size) inarray = true; // bottom if (!inarray) continue; } int i = (int)(x - hw); int j = (int)(y - hh); b = 0; g = 0; r = 0; for (int mm = 0; mm < aasamples; mm++) { double u = i + m_aapt[mm].X; double v = j - m_aapt[mm].Y; double s = m_cos * u + m_sin * v; double t = -m_sin * u + m_cos * v; s += m_curvature * Math.Tan(s * m_scale); t += m_curvature * Math.Tan(t * m_scale); u = m_cos * s - m_sin * t; v = m_sin * s + m_cos * t; int xSample = (int)(hw + u); int ySample = (int)(hh + v); xSample = Function.FClamp(xSample, 0, width - 1); ySample = Function.FClamp(ySample, 0, height - 1); r += imageIn.getRComponent(xSample, ySample); g += imageIn.getGComponent(xSample, ySample); b += imageIn.getBComponent(xSample, ySample); } imageIn.setPixelColor(x, y, Image.SAFECOLOR(r / aasamples), Image.SAFECOLOR(g / aasamples), Image.SAFECOLOR(b / aasamples)); } } return imageIn; }
public Image process(Image imageIn) { Color rgb = new Color(); YCbCr ycbcr = new YCbCr(); float ky = 0, by = 0; float kcb = 0, bcb = 0; float kcr = 0, bcr = 0; // Y line parameters if (inY.Max != inY.Min) { ky = (outY.Max - outY.Min) / (inY.Max - inY.Min); by = outY.Min - ky * inY.Min; } // Cb line parameters if (inCb.Max != inCb.Min) { kcb = (outCb.Max - outCb.Min) / (inCb.Max - inCb.Min); bcb = outCb.Min - kcb * inCb.Min; } // Cr line parameters if (inCr.Max != inCr.Min) { kcr = (outCr.Max - outCr.Min) / (inCr.Max - inCr.Min); bcr = outCr.Min - kcr * inCr.Min; } for (int x = 0; x < imageIn.getWidth(); x++) { for (int y = 0; y < imageIn.getHeight(); y++) { rgb.R = (byte)imageIn.getRComponent(x, y); rgb.G = (byte)imageIn.getGComponent(x, y); rgb.B = (byte)imageIn.getBComponent(x, y); // convert to YCbCr ycbcr = YCbCr.FromRGB(rgb, ycbcr); // correct Y if (ycbcr.Y >= inY.Max) ycbcr.Y = outY.Max; else if (ycbcr.Y <= inY.Min) ycbcr.Y = outY.Min; else ycbcr.Y = ky * ycbcr.Y + by; // correct Cb if (ycbcr.Cb >= inCb.Max) ycbcr.Cb = outCb.Max; else if (ycbcr.Cb <= inCb.Min) ycbcr.Cb = outCb.Min; else ycbcr.Cb = kcb * ycbcr.Cb + bcb; // correct Cr if (ycbcr.Cr >= inCr.Max) ycbcr.Cr = outCr.Max; else if (ycbcr.Cr <= inCr.Min) ycbcr.Cr = outCr.Min; else ycbcr.Cr = kcr * ycbcr.Cr + bcr; // convert back to RGB rgb = YCbCr.ToRGB(ycbcr, rgb); imageIn.setPixelColor(x, y, rgb.R, rgb.G, rgb.B); } } return imageIn; }
//@Override public Image process(Image 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]; } } Image clone = imageIn.clone(); int r,g,b; for (int x = 0; x < imageIn.getWidth() - 1; x++){ for (int y = 0; y < imageIn.getHeight() - 1; y++) { r = clone.getRComponent(x, y); g = clone.getGComponent(x, y); b = clone.getBComponent(x, y); r = (r * intensity_invert + rr[r] * intensity) >> 8; g = (g * intensity_invert + gg[g] * intensity) >> 8; b = (b * intensity_invert + bb[b] * intensity) >> 8; imageIn.setPixelColor(x, y, r, g, b); } } return imageIn;//��ֱ��ͼģʽ��ǿ }
// @Override public Image process(Image 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; }
public override Image process(Image imageIn) { { int r, g, b; int width = imageIn.getWidth(); int height = imageIn.getHeight(); double hw = width / 2.0; double hh = imageIn.getHeight() / 2.0; for(int x = 0 ; x < width ; x++){ for(int y = 0 ; y < height ; y++){ int i = (int)(x - hw); int j = (int)(y - hh); b=0; g=0; r=0; for (int mm=0 ; mm < aasamples ; mm++){ double u = i + m_aapt[mm].X ; double v = j - m_aapt[mm].Y ; double s = m_cos * u + m_sin * v ; double t = -m_sin * u + m_cos * v ; s += m_curvature * Math.Tan(s * m_scale) ; t += m_curvature * Math.Tan(t * m_scale) ; u = m_cos * s - m_sin * t ; v = m_sin * s + m_cos * t ; int xSample = (int)(hw + u) ; int ySample = (int)(hh + v) ; xSample = Function.FClamp (xSample, 0, width -1) ; ySample = Function.FClamp (ySample, 0, height-1) ; r += imageIn.getRComponent(xSample, ySample); g += imageIn.getGComponent(xSample, ySample); b += imageIn.getBComponent(xSample, ySample); } imageIn.setPixelColor(x, y, Image.SAFECOLOR(r/aasamples), Image.SAFECOLOR(g/aasamples), Image.SAFECOLOR(b/aasamples)); } } return imageIn; } }
//@Override public override Image process(Image imageIn) { int width = imageIn.getWidth(); int height = imageIn.getHeight(); int r = 0, g = 0, b = 0; Image 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); }