Skip to content
Snippets Groups Projects
Commit 9929b0e2 authored by SAEZ Theo's avatar SAEZ Theo
Browse files

Ajout de la classe Mirror pour appliquer un effet de miroir sur les images et...

Ajout de la classe Mirror pour appliquer un effet de miroir sur les images et mise à jour de la classe Display pour l'utiliser.
parent 2d86eae2
No related branches found
No related tags found
No related merge requests found
Pipeline #48843 failed
Showing with 52 additions and 1 deletion
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
File added
No preview for this file type
No preview for this file type
......@@ -22,7 +22,7 @@ public class Display implements Initializable {
this.image = MatrixGrayImage.createImageFromPGMFile("images/luminy.pgm");
transform[] transformList = new transform[] {new DecreaseGrayLevels(8), new Outline(0.05), new Invert()};
transform[] transformList = new transform[] {new Mirror("both")};
transform transformation = new CompositeTransform(transformList);
......
public class Mirror implements transform {
private String axes;
public Mirror(String axes) {
this.axes = axes;
}
public void applyTo(GrayImage image) {
modify(image);
}
public void modify(GrayImage image) {
int width = image.getWidth();
int height = image.getHeight();
GrayColor shortLivedColor = new ByteGrayColor();
if (axes.equals("horizontal")) {
horizontalFlip(image, width, height, shortLivedColor);
}
if (axes.equals("vertical")) {
verticalFlip(image, width, height, shortLivedColor);
}
if (axes.equals("both")) {
horizontalFlip(image, width, height, shortLivedColor);
verticalFlip(image, width, height, shortLivedColor);
}
}
public void horizontalFlip(GrayImage image, int width, int height, GrayColor shortLivedColor) {
for (int i = 0; i < width * 0.5; i++){
for (int j = 0; j < height; j++){
shortLivedColor = image.getPixelGrayColor(i, j);
image.setPixel(image.getPixelGrayColor(width - 1 - i, j), i, j);
image.setPixel(shortLivedColor, width - 1 - i, j);
}
}
}
public void verticalFlip(GrayImage image, int width, int height, GrayColor shortLivedColor) {
for (int i = 0; i < width; i++){
for (int j = 0; j < height * 0.5; j++){
shortLivedColor = image.getPixelGrayColor(i, j);
image.setPixel(image.getPixelGrayColor(i, height - 1 -j), i, j);
image.setPixel(shortLivedColor, i, height - 1 - j);
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment