Added a filter Sepia

This commit is contained in:
Remizov Kirirll 2025-03-04 15:55:58 +03:00
parent 72c6a5ca33
commit aa90d4e4b2
3 changed files with 53 additions and 0 deletions

View File

@ -0,0 +1,12 @@
package org.example.lab_1.Helpers;
public class Helpers {
public static int CheckBit(int val, int min, int max){
if (val > max) {
return max;
} else if(val < min) {
return min;
}
return val;
}
}

View File

@ -9,6 +9,7 @@ import javafx.scene.image.WritableImage;
import javafx.scene.control.ProgressBar;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import static org.example.lab_1.Helpers.Helpers.CheckBit;
public class ImageEditorController {
@ -112,5 +113,44 @@ public class ImageEditorController {
progressBar.setVisible(false);
}
public void Sepia() {
progressBar.setVisible(true);
Image img = imageView.getImage();
if(img == null){ return; }
int w = (int) img.getWidth();
int h = (int) img.getHeight();
WritableImage SepiaImg = new WritableImage(w, h);
PixelReader Reader = img.getPixelReader();
PixelWriter Writer = SepiaImg.getPixelWriter();
for(int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
int argb = Reader.getArgb(x, y);
int a = (argb >> 24) & 0xFF;
int r = (argb >> 16) & 0xFF;
int g = (argb >> 8) & 0xFF;
int b = argb & 0xFF;
double grey = 0.299 * r + 0.587 * g + 0.144 * b;
int k = 32;
double f;
r = CheckBit((int) grey+(2*k), 0, 255);
f = grey+(0.5*k);
g = CheckBit((int) f, 0, 255);
b = CheckBit((int) grey-(1*k), 0, 255);
int newArgb = (a << 24) | (r << 16) | (g << 8) | b;
Writer.setArgb(x, y, newArgb);
}
}
imageView.setImage(SepiaImg);
System.out.println("Применён Sepia");
progressBar.setVisible(false);
}
}

View File

@ -18,6 +18,7 @@
<Menu text="Точечные">
<MenuItem text="Инверсия" onAction="#applyInversionFilter"/>
<MenuItem text="Оттенки серого" onAction="#GrayScaleFilter"/>
<MenuItem text="Сепия" onAction="#Sepia"/>
</Menu>
<Menu text="Матричные">
<!-- Пустое подменю -->