From 3ef211f08290ea62b5cad1c5b7a1f3bdf581d45a Mon Sep 17 00:00:00 2001 From: JFronny <33260128+jfronny@users.noreply.github.com> Date: Wed, 30 Jun 2021 10:42:25 +0200 Subject: [PATCH] fune functs --- .../java/io/gitlab/jfronny/ImgJava/Main.java | 3 + .../ImgJava/imageProcessing/UtilColor.java | 90 +++++++++++++++++++ .../gitlab/jfronny/ImgJava/util/MColor.java | 20 +++-- 3 files changed, 108 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/gitlab/jfronny/ImgJava/Main.java b/src/main/java/io/gitlab/jfronny/ImgJava/Main.java index 917f821..df297d1 100644 --- a/src/main/java/io/gitlab/jfronny/ImgJava/Main.java +++ b/src/main/java/io/gitlab/jfronny/ImgJava/Main.java @@ -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) { diff --git a/src/main/java/io/gitlab/jfronny/ImgJava/imageProcessing/UtilColor.java b/src/main/java/io/gitlab/jfronny/ImgJava/imageProcessing/UtilColor.java index 521e88f..e53e4f9 100644 --- a/src/main/java/io/gitlab/jfronny/ImgJava/imageProcessing/UtilColor.java +++ b/src/main/java/io/gitlab/jfronny/ImgJava/imageProcessing/UtilColor.java @@ -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; + } } diff --git a/src/main/java/io/gitlab/jfronny/ImgJava/util/MColor.java b/src/main/java/io/gitlab/jfronny/ImgJava/util/MColor.java index cb134b7..e89b8d9 100644 --- a/src/main/java/io/gitlab/jfronny/ImgJava/util/MColor.java +++ b/src/main/java/io/gitlab/jfronny/ImgJava/util/MColor.java @@ -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; + } }