Added a filter Gray Skale

This commit is contained in:
Remizov Kirirll 2025-03-04 15:25:38 +03:00
parent b508c42deb
commit 72c6a5ca33
2 changed files with 42 additions and 2 deletions

View File

@ -59,12 +59,10 @@ public class ImageEditorController {
int g = (argb >> 8) & 0xFF; int g = (argb >> 8) & 0xFF;
int b = argb & 0xFF; int b = argb & 0xFF;
// Invert colors
r = 255 - r; r = 255 - r;
g = 255 - g; g = 255 - g;
b = 255 - b; b = 255 - b;
// Reassemble ARGB
int invertedArgb = (a << 24) | (r << 16) | (g << 8) | b; int invertedArgb = (a << 24) | (r << 16) | (g << 8) | b;
pixelWriter.setArgb(x, y, invertedArgb); pixelWriter.setArgb(x, y, invertedArgb);
} }
@ -74,4 +72,45 @@ public class ImageEditorController {
System.out.println("Применен фильтр инверсии"); System.out.println("Применен фильтр инверсии");
progressBar.setVisible(false); progressBar.setVisible(false);
} }
public void GrayScaleFilter() {
progressBar.setVisible(true);
Image img = imageView.getImage();
if(img == null){ return; }
int w = (int) img.getWidth();
int h = (int) img.getHeight();
WritableImage GraySkaleImg = new WritableImage(w, h);
PixelReader Reader = img.getPixelReader();
PixelWriter Writer = GraySkaleImg.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;
r = (int) grey;
g = (int) grey;
b = (int) grey;
int newArgb = (a << 24) | (r << 16) | (g << 8) | b;
Writer.setArgb(x, y, newArgb);
}
}
imageView.setImage(GraySkaleImg);
System.out.println("Применён оттенки серого");
progressBar.setVisible(false);
}
} }

View File

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