fune functs

This commit is contained in:
JFronny 2021-06-30 10:42:25 +02:00
parent 35749adf70
commit 3ef211f082
3 changed files with 108 additions and 5 deletions

View File

@ -29,9 +29,12 @@ public class Main {
//pict = stackViewer.push(ImageUtil.blurBox(pict, 10));
pict = stackViewer.push(UtilMatrix.blurGauss(pict, 3, 2));
pict = stackViewer.push(UtilMatrix.sharpen(pict, 3));
pict = stackViewer.push(UtilColor.invert(pict));
pict = stackViewer.push(UtilColor.switcheroo(pict));
pict = stackViewer.push(UtilColor.tint(pict, new Color(255, 0, 0, 128)));
pict = stackViewer.push(UtilColor.tint(pict, new Color(0, 255, 0, 0)));
pict = stackViewer.push(UtilColor.tint(pict, new Color(0, 0, 255, 255)));
pict = stackViewer.push(UtilColor.grayscale(pict));
pict.save(run.resolve("moscov.png"));
stackViewer.repaint();
} catch (IOException e) {

View File

@ -3,6 +3,7 @@ package io.gitlab.jfronny.ImgJava.imageProcessing;
import io.gitlab.jfronny.ImgJava.util.MColor;
import io.gitlab.jfronny.ImgJava.util.Picture;
import javax.swing.plaf.metal.MetalIconFactory;
import java.awt.*;
public class UtilColor {
@ -22,4 +23,93 @@ public class UtilColor {
picture.setPixelArray(pixelNeu);
return picture;
}
public static Picture tint(Picture picture, double factor) {
int w = picture.getWidth();
int h = picture.getHeight();
Color[][] pixel = picture.getPixelArray();
Color[][] pixelNeu = new Color[w][h];
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
pixelNeu[x][y] = new MColor(pixel[x][y]).mult(factor).get();
}
}
picture.setPixelArray(pixelNeu);
return picture;
}
public static Picture tint(Picture picture, double fR, double fG, double fB) {
int w = picture.getWidth();
int h = picture.getHeight();
Color[][] pixel = picture.getPixelArray();
Color[][] pixelNeu = new Color[w][h];
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
pixelNeu[x][y] = new MColor(pixel[x][y]).tint(fR, fG, fB).get();
}
}
picture.setPixelArray(pixelNeu);
return picture;
}
public static Picture switcheroo(Picture picture) {
int w = picture.getWidth();
int h = picture.getHeight();
Color[][] pixel = picture.getPixelArray();
Color[][] pixelNeu = new Color[w][h];
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
Color c = pixel[x][y];
pixelNeu[x][y] = new Color(c.getGreen(), c.getBlue(), c.getRed(), c.getAlpha());
}
}
picture.setPixelArray(pixelNeu);
return picture;
}
public static Picture invert(Picture picture) {
int w = picture.getWidth();
int h = picture.getHeight();
Color[][] pixel = picture.getPixelArray();
Color[][] pixelNeu = new Color[w][h];
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
pixelNeu[x][y] = new MColor(pixel[x][y]).invert().get();
}
}
picture.setPixelArray(pixelNeu);
return picture;
}
public static Picture grayscale(Picture picture) {
int w = picture.getWidth();
int h = picture.getHeight();
Color[][] pixel = picture.getPixelArray();
Color[][] pixelNeu = new Color[w][h];
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
Color c = pixel[x][y];
int n = c.getRed() + c.getGreen() + c.getBlue();
n /= 3;
pixelNeu[x][y] = new Color(n, n, n, c.getAlpha());
}
}
picture.setPixelArray(pixelNeu);
return picture;
}
}

View File

@ -48,11 +48,7 @@ public class MColor {
}
public MColor mult(double factor) {
r *= factor;
g *= factor;
b *= factor;
a *= factor;
return this;
return tint(factor, factor, factor);
}
public MColor div(double factor) {
@ -72,4 +68,18 @@ public class MColor {
b += t.getBlue() * f;
return this;
}
public MColor tint(double fR, double fG, double fB) {
r *= fR;
g *= fG;
b *= fB;
return this;
}
public MColor invert() {
r = 255 - r;
g = 255 - g;
b = 255 - b;
return this;
}
}