This repository has been archived on 2022-08-05. You can view files and clone it, but cannot push or open issues or pull requests.
school-projects/src/main/java/io/gitlab/jfronny/ImgJava/imageProcessing/UtilColor.java

116 lines
3.3 KiB
Java

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 {
public static Picture tint(Picture picture, Color tint) {
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(tint).get();
}
}
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;
}
}