diff --git a/src/main/java/ByteGrayColor.java b/src/main/java/ByteGrayColor.java deleted file mode 100644 index e7783125b9e5b4be4a377b743b1e4ff670af659a..0000000000000000000000000000000000000000 --- a/src/main/java/ByteGrayColor.java +++ /dev/null @@ -1,59 +0,0 @@ -import javafx.scene.paint.Color; - -/** - * Created by Arnaud Labourel on 02/10/2018. - */ - -public class ByteGrayColor implements GrayColor { - - private static final int MINIMUM_GRAY_LEVEL = 0; - private static final int MAXIMUM_GRAY_LEVEL = 255; - private static final int OPACITY = 1; - - // TODO : rajouter constantes publique BLACK et WHITE - - private final int grayLevel; - - - public ByteGrayColor(){ - this.grayLevel = MINIMUM_GRAY_LEVEL; - } - - public ByteGrayColor(int grayLevel) { - // TODO : Corriger l'initialisation de la propriété grayLevel de l'instance. - this.grayLevel = 0; - } - - public ByteGrayColor(double luminosity) { - // TODO : Corriger l'initialisation de la propriété grayLevel de l'instance. - this.grayLevel = 0; - } - - @Override - public double getLuminosity() { - // TODO : Retourner la luminosité de la couleur (entre 0 noir et 1 blanc) - return 0; - } - - @Override - public Color getColor(){ - double component = grayLevel / (double) MAXIMUM_GRAY_LEVEL; - return new Color(component, component, component, OPACITY); - } - - - @Override - public int compareTo(GrayColor o) { - // TODO : Retourner la différence de niveau de gris. - return 0; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (this.getClass() != o.getClass()) return false; - ByteGrayColor color = (ByteGrayColor) o; - return this.compareTo(color) == 0; - } - -} diff --git a/src/main/java/Display.java b/src/main/java/Display.java deleted file mode 100644 index 5332f8958d2b62b7c27f03011765c7f21c7c5047..0000000000000000000000000000000000000000 --- a/src/main/java/Display.java +++ /dev/null @@ -1,51 +0,0 @@ -import javafx.fxml.FXML; -import javafx.fxml.Initializable; -import javafx.scene.canvas.Canvas; -import javafx.scene.canvas.GraphicsContext; -import javafx.scene.image.PixelWriter; - -import java.net.URL; -import java.util.ResourceBundle; - -/** - * Created by Arnaud Labourel on 04/10/2018. - */ -public class Display implements Initializable { - @FXML - private Canvas canvas; - - MatrixGrayImage image; - - @Override - public void initialize(URL location, ResourceBundle resources) { - - this.image = MatrixGrayImage.createImageFromPGMFile("images/luminy.pgm"); - - // TODO : Ajouter les transformations d'image. - - render(); - } - - public void render() { - int pixelWidth = image.getWidth(); - int pixelHeight = image.getHeight(); - - canvas.setWidth(pixelWidth); - canvas.setHeight(pixelHeight); - - GraphicsContext graphicsContext = canvas.getGraphicsContext2D(); - - PixelWriter pixelWriter = graphicsContext.getPixelWriter(); - - for (int i = 0; i < pixelWidth; i++) { - for (int j = 0; j < pixelHeight; j++) { - renderPixel(i,j, pixelWriter); - } - } - } - - private void renderPixel(int x, int y, PixelWriter pixelWriter) { - pixelWriter.setColor(x, y, image.getPixelColor(x, y)); - } - -} diff --git a/src/main/java/GrayColor.java b/src/main/java/GrayColor.java deleted file mode 100644 index e871b5d0b28213117b7f08dc11dca76de1604337..0000000000000000000000000000000000000000 --- a/src/main/java/GrayColor.java +++ /dev/null @@ -1,10 +0,0 @@ -import javafx.scene.paint.Color; - -/** - * Created by Arnaud Labourel on 04/10/2018. - * Interface correspondant à une couleur de gris. - */ -public interface GrayColor extends Comparable<GrayColor> { - double getLuminosity(); - Color getColor(); -} diff --git a/src/main/java/GrayImage.java b/src/main/java/GrayImage.java deleted file mode 100644 index fdf4199614551317487cc027b9df871cd3ac6b28..0000000000000000000000000000000000000000 --- a/src/main/java/GrayImage.java +++ /dev/null @@ -1,8 +0,0 @@ -/** - * Created by Arnaud Labourel on 04/10/2018. - */ - -public interface GrayImage extends Image { - void setPixel(GrayColor gray, int x, int y); - GrayColor getPixelGrayColor(int x, int y); -} diff --git a/src/main/java/Image.java b/src/main/java/Image.java deleted file mode 100644 index 282a6455aff46567d230fc835c29621e6eb9066d..0000000000000000000000000000000000000000 --- a/src/main/java/Image.java +++ /dev/null @@ -1,10 +0,0 @@ -import javafx.scene.paint.Color; - -/** - * Created by Arnaud Labourel on 02/10/2018. - */ -public interface Image { - Color getPixelColor(int x, int y); - int getWidth(); - int getHeight(); -} diff --git a/src/main/java/Main.java b/src/main/java/Main.java deleted file mode 100644 index 30f30b8d0eb2436c9632d0545e7bac2e3c1ea31b..0000000000000000000000000000000000000000 --- a/src/main/java/Main.java +++ /dev/null @@ -1,25 +0,0 @@ -import javafx.application.Application; -import javafx.fxml.FXMLLoader; -import javafx.scene.Parent; -import javafx.scene.Scene; -import javafx.stage.Stage; - -import java.io.IOException; - - -public class Main extends Application -{ - - public static void main(String[] args) { - launch(args); - } - - @Override - public void start(Stage primaryStage) throws IOException { - Parent root =FXMLLoader.load(getClass().getResource("fxml/Display.fxml")); - primaryStage.setTitle("Image display"); - primaryStage.setScene(new Scene(root)); - primaryStage.show(); - - } -} diff --git a/src/main/java/MatrixGrayImage.java b/src/main/java/MatrixGrayImage.java deleted file mode 100644 index 401bfe73793257dd828da66bc0ef92e06638c43e..0000000000000000000000000000000000000000 --- a/src/main/java/MatrixGrayImage.java +++ /dev/null @@ -1,109 +0,0 @@ -import javafx.scene.paint.Color; - -import java.io.FileWriter; -import java.io.InputStream; -import java.io.PrintWriter; -import java.util.Scanner; - -/** - * Created by Arnaud Labourel on 02/10/2018. - */ -public class MatrixGrayImage implements GrayImage { - - private final GrayColor[][] pixels; - private final int width; - private final int height; - - - @Override - public void setPixel(GrayColor gray, int x, int y) { - // TODO : Compléter la méthode pour modifier le pixel. - } - - @Override - public GrayColor getPixelGrayColor(int x, int y) { - // TODO : Changer les instructions pour retourner le bon pixel. - return new ByteGrayColor(); - } - - @Override - public Color getPixelColor(int x, int y) { - // TODO : Changer les instructions pour retourner la couleur du pixel. - return Color.WHITE; - } - - @Override - public int getWidth() { - // TODO : Changer les instructions pour retourner la largeur de l'image. - return 600; - } - - @Override - public int getHeight() { - // TODO : Changer les instructions pour retourner la hauteur de l'image. - return 400; - } - - public MatrixGrayImage(int width, int height){ - /* TODO : Modifier les instructions pour initialiser correctement - les propriétés de l'instance. - */ - this.width = 0; - this.height = 0; - this.pixels = null; - } - - - public static MatrixGrayImage createImageFromPGMFile(String fileName) { - // NE PAS MODIFIER ! - InputStream file = ClassLoader.getSystemResourceAsStream(fileName); - Scanner scan = new Scanner(file); - scan.nextLine(); - scan.nextLine(); - - int width = scan.nextInt(); - int height = scan.nextInt(); - - MatrixGrayImage result = new MatrixGrayImage(width, height); - - scan.nextInt(); - - for(int y = 0; y < height; y++){ - for(int x = 0; x < width; x++) { - GrayColor color = new ByteGrayColor(scan.nextInt()); - result.setPixel(color, x, y); - } - } - - return result; - } - - public void writeIntoPGMFormat(String fileName){ - // NE PAS MODIFIER ! - try { - FileWriter fileWriter = new FileWriter(fileName); - PrintWriter printWriter = new PrintWriter(fileWriter); - printWriter.println("P2"); - printWriter.println("# CREATOR: TP3 Version 1.0"); - printWriter.printf("%d %d\n",this.width, this.height); - - printWriter.println(pgmCodeOfGrayColor(pixels[0][0])); - - for(int y = 0; y < height; y++){ - for(int x = 0; x < width; x++) { - printWriter.println(pgmCodeOfGrayColor(getPixelGrayColor(x,y))); - } - } - printWriter.close(); - } - catch (Exception e){ - e.printStackTrace(); - } - } - - private static final int PGM_MAXIMUM_CODE = 255; - - private int pgmCodeOfGrayColor(GrayColor pixelGrayColor) { - return (int) (pixelGrayColor.getLuminosity() * (double) PGM_MAXIMUM_CODE); - } -} diff --git a/src/test/java/ByteGrayColorTest.java b/src/test/java/ByteGrayColorTest.java deleted file mode 100644 index 2f056266657273e624e9b39f4204649369570217..0000000000000000000000000000000000000000 --- a/src/test/java/ByteGrayColorTest.java +++ /dev/null @@ -1,60 +0,0 @@ -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.*; - -public class ByteGrayColorTest { - @Test - public void testGetLuminosity_whenColorCreatedWithGrayLevel(){ - ByteGrayColor black = new ByteGrayColor(0); - ByteGrayColor white = new ByteGrayColor(255); - assertThat(black.getLuminosity()).isCloseTo(0., within(.01)); - assertThat(white.getLuminosity()).isCloseTo(1., within(.01)); - } - - @Test - public void testGetLuminosity_whenColorCreatedWithLuminosity(){ - ByteGrayColor color1 = new ByteGrayColor(.25); - ByteGrayColor color2 = new ByteGrayColor(.75); - assertThat(color1.getLuminosity()).isCloseTo(.25, within(.01)); - assertThat(color2.getLuminosity()).isCloseTo(.75, within(.01)); - } - - @Test - public void testCompareTo_whenColorsCreatedWithGrayLevel(){ - ByteGrayColor color1 = new ByteGrayColor(100); - ByteGrayColor color2 = new ByteGrayColor(150); - ByteGrayColor color3 = new ByteGrayColor(200); - ByteGrayColor sameGrayLevelAsColor1 = new ByteGrayColor(100); - assertThat(color1.compareTo(color2)).isNegative(); - assertThat(color2.compareTo(color3)).isNegative(); - assertThat(color1.compareTo(color3)).isNegative(); - assertThat(color2.compareTo(color1)).isPositive(); - assertThat(color1.compareTo(sameGrayLevelAsColor1)).isZero(); - assertThat(color1.compareTo(color2)).isEqualTo(sameGrayLevelAsColor1.compareTo(color2)); - } - - @Test - public void testCompareTo_whenColorsCreatedWithLuminosity(){ - ByteGrayColor color1 = new ByteGrayColor(0.20); - ByteGrayColor color2 = new ByteGrayColor(0.60); - ByteGrayColor color3 = new ByteGrayColor(0.80); - ByteGrayColor sameLuminosityAsColor1 = new ByteGrayColor(0.20); - assertThat(color1.compareTo(color2)).isNegative(); - assertThat(color2.compareTo(color3)).isNegative(); - assertThat(color1.compareTo(color3)).isNegative(); - assertThat(color2.compareTo(color1)).isPositive(); - assertThat(color1.compareTo(sameLuminosityAsColor1)).isZero(); - assertThat(color1.compareTo(color2)).isEqualTo(sameLuminosityAsColor1.compareTo(color2)); - } - - @Test - public void testCompareTo_whenColorsCreatedWithLuminosityAndGrayLevel(){ - ByteGrayColor color1 = new ByteGrayColor(0.); - ByteGrayColor color2 = new ByteGrayColor(150); - ByteGrayColor color3 = new ByteGrayColor(1.); - assertThat(color1.compareTo(color2)).isNegative(); - assertThat(color2.compareTo(color3)).isNegative(); - assertThat(color1.compareTo(color3)).isNegative(); - assertThat(color2.compareTo(color1)).isPositive(); - } -} diff --git a/src/test/java/MatrixGrayImageTest.java b/src/test/java/MatrixGrayImageTest.java deleted file mode 100644 index 72e61003a07e683217990f7025cddb57a974730d..0000000000000000000000000000000000000000 --- a/src/test/java/MatrixGrayImageTest.java +++ /dev/null @@ -1,31 +0,0 @@ -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.*; - -class MatrixGrayImageTest { - - @Test - void testGetWidth() { - assertThat(new MatrixGrayImage(0,0).getWidth()).isEqualTo(0); - assertThat(new MatrixGrayImage(10,20).getWidth()).isEqualTo(10); - assertThat(new MatrixGrayImage(400,300).getWidth()).isEqualTo(400); - } - - @Test - void testGetHeight() { - assertThat(new MatrixGrayImage(0,0).getHeight()).isEqualTo(0); - assertThat(new MatrixGrayImage(10,20).getHeight()).isEqualTo(20); - assertThat(new MatrixGrayImage(400,300).getHeight()).isEqualTo(300); - } - - @Test - void testGetPixel_whenPixelHasBeenSet() { - GrayColor grey1 = new ByteGrayColor(0.2); - GrayColor grey2 = new ByteGrayColor(0.8); - MatrixGrayImage image = new MatrixGrayImage(10, 10); - image.setPixel(grey1, 1, 1); - assertThat(image.getPixelGrayColor(1,1)).isEqualTo(grey1); - image.setPixel(grey2, 3, 9); - assertThat(image.getPixelGrayColor(3,9)).isEqualTo(grey2); - } -} \ No newline at end of file