diff --git a/Makefile b/Makefile index 8210993..f862039 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,8 @@ .PHONY: clean, mrproper ## Compilation CXX = g++ -CXXFLAGS = -lSDL -lSDLmain -DDEBUG +CXXFLAGS = -lSDL -lSDLmain +CXXFLAGSDEBUG = -lSDL -lSDLmain -DDEBUG ## Chemins EXEPATH = bin/ OBJPATH = obj/ @@ -14,14 +15,14 @@ main: main.o image.o $(CXX) $(OBJPATH)main.o $(OBJPATH)image.o -o $(EXEPATH)$@ $(CXXFLAGS) testing: test.o image.o - $(CXX) $(OBJPATH)test.o $(OBJPATH)image.o -o $(EXEPATH)$@ $(CXXFLAGS) + $(CXX) $(OBJPATH)test.o $(OBJPATH)image.o -o $(EXEPATH)$@ $(CXXFLAGSDEBUG) # Dépendances main.o: $(SRCPATH)main.cpp $(SRCPATH)image.h $(CXX) -c $< -o $(OBJPATH)$@ $(CXXFLAGS) test.o: $(SRCPATH)test.cpp $(SRCPATH)image.cpp - $(CXX) -c $< -o $(OBJPATH)$@ $(CXXFLAGS) + $(CXX) -c $< -o $(OBJPATH)$@ $(CXXFLAGSDEBUG) image.o: $(SRCPATH)image.cpp $(CXX) -c $< -o $(OBJPATH)$@ diff --git a/TODO.md b/TODO.md index 24f85e7..9ca3f2c 100644 --- a/TODO.md +++ b/TODO.md @@ -10,21 +10,19 @@ * Fonction principale * Fonction d'analyse de commande - * Analyse de la commande + * Analyse de la commande **C** * Analyse des arguments - * Correspondance commandes ↔ fonctions -* Objets **D** - * Fenêtre **D** - * SDL **C** - * BGI **A** + * Correspondance commandes ↔ fonctions **D** +* Objets **C** + * Fenêtre **C** * Pixel **C** * Image **C** * Fonctions **D** * Gestion de fichier **D** - * Créer - * Ouvrir - * Enregistrer - * Importer + * Créer **C** + * Ouvrir **D** + * Enregistrer **D** + * Importer **A** * Édition * Copier tout * Couper tout @@ -32,23 +30,24 @@ * Annuler * Refaire * Couleur **D** - * Teinte **D** + * Teinte **A** * Saturation **D** - * Luminosité **D** - * Contraste **D** + * Luminosité **A** + * Contraste **A** * Dessin **D** - * Trait - * Rectangle - * Cercle - * Disque + * Trait **D** + * Rectangle **A** + * Cercle **D** + * Disque **D** * Géométrie **D** - * Zoom - * Pivot - * Redimensionner + * Zoomer + * Pivoter + * Retourner **D** + * Redimensionner **A** * Conversion du mode **D** - * Binaire - * Niveaux de gris - * Couleur + * Binaire **D** + * Niveaux de gris **D** + * Couleur **D** * Aide * Documentation diff --git a/src/affichageFenetreSDL.cpp b/src/affichageFenetre.cpp similarity index 100% rename from src/affichageFenetreSDL.cpp rename to src/affichageFenetre.cpp diff --git a/src/affichageFenetreBGI.cpp b/src/affichageFenetreBGI.cpp deleted file mode 100644 index 075eae1..0000000 --- a/src/affichageFenetreBGI.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include - -int ouvrirFenetre(int dimensionX, int dimensionY, const char *nom) { // Crée une fenêtre - initwindow(dimensionX, dimensionY, nom, 0, 0); - return 0; -} - -int setNomFenetre(const char *nom) { // Change le nom de la fenêtre - return 0; -} - -int pointFenetre(int x, int y, int r, int v, int b) { - putpixel(x, y, COLOR(r, v, b)); - return 0; -} - -int afficherFenetre() { - - return 0; -} - -int attendreFenetre() { - while (kbhit()) { - delay(100); - } -} - -int fermerFenetre() { - closegraph(ALL_WINDOWS); -} diff --git a/src/analyserCommande.cpp b/src/analyserCommande.cpp index 5abe7d7..4e9cd7d 100644 --- a/src/analyserCommande.cpp +++ b/src/analyserCommande.cpp @@ -1,3 +1,89 @@ -int analyserCommande(string nom) { +#include +#include +using namespace std; + +int messageErreur(string message) { + cerr << "Erreur : " << message << endl; } + +int decoupeCommande(string commande, vector< string > &decoupe) { + // Boucle de découpage + // vector< string > decoupe; + string elementCourrant = ""; + bool dansLeVide = false; + bool echape = false; + bool vaEchapper = false; + bool entreSimplesGuillemets = false; + bool entreDoublesGuillemets = false; + for (int i = 0; i < commande.length(); i++) { + echape = false; + if (vaEchapper) { + vaEchapper = false; + echape = true; + } + if (commande[i] == ' ' && !(echape || entreSimplesGuillemets || entreDoublesGuillemets)) { + // cout << i << " : " << "espace" << endl; + if (!dansLeVide) { + // cout << "Ajout de " << elementCourrant << endl; + decoupe.push_back(elementCourrant); + elementCourrant = ""; + dansLeVide = true; + } + } else if (commande[i] == '\\' && !echape) { + vaEchapper = true; + } else if (commande[i] == '\'' && !(echape || entreDoublesGuillemets)) { + if (entreSimplesGuillemets) { + entreSimplesGuillemets = false; + // cout << "Ajout de " << elementCourrant << endl; + decoupe.push_back(elementCourrant); + elementCourrant = ""; + dansLeVide = true; + } else { + entreSimplesGuillemets = true; + } + } else if (commande[i] == '"' && !(echape || entreSimplesGuillemets)) { + if (entreDoublesGuillemets) { + entreDoublesGuillemets = false; + // cout << "Ajout de " << elementCourrant << endl; + decoupe.push_back(elementCourrant); + elementCourrant = ""; + dansLeVide = true; + } else { + entreDoublesGuillemets = true; + } + } else { + // cout << i << " : " << "else" << endl; + elementCourrant += commande[i]; + dansLeVide = false; + } + } + if (!dansLeVide) { + // cout << "Ajout de " << elementCourrant << endl; + decoupe.push_back(elementCourrant); + } +} + +int analyserDecoupe(vector< string > decoupe) { + for (int i = 0; i < decoupe.size(); i++) { // DEBUG + cout << "Argument " << i << " = " << decoupe[i] << endl; + } +} + +int boucleDeCommandes() { + bool continuer = true; + string commande; + + while (continuer) { + cout << "$ "; + getline(cin, commande); + if (commande == "exit" || commande == "quitter") { + continuer = false; + } else { + vector< string > decoupe; + decoupeCommande(commande, decoupe); + analyserDecoupe(decoupe); + } + } + return 0; +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index c7d2503..d30f956 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,14 +1,13 @@ #include #include -#include "affichageFenetreSDL.cpp" -#include "image.h" - using namespace std; -// Insertion des ensembles de fonctions massives séparés pour plus de clarté -#include "analyserCommande.cpp" +#include "affichageFenetre.cpp" +#include "image.h" #include "traitementImage.cpp" +#include "analyserCommande.cpp" + int main(int argc, char *args[]) { #if defined(WIN32) // Permet de refaire fonctionner cin et cout sous Windows après démarrage de SDL @@ -18,5 +17,15 @@ int main(int argc, char *args[]) { cout << "PILG" << endl; // Message d'entrée et de test + if (argc > 1) { + vector< string > decoupe; + for (int i = 1; i < argc; i++) { + decoupe.push_back(args[i]); + } + analyserDecoupe(decoupe); + } else { + boucleDeCommandes(); + } + return 0; } diff --git a/src/test.cpp b/src/test.cpp index 6ff089d..193ccb6 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -1,11 +1,13 @@ #include #include -#include "affichageFenetreSDL.cpp" -#include "image.h" - using namespace std; +#include "affichageFenetre.cpp" +#include "image.h" +#include "traitementImage.cpp" +#include "analyserCommande.cpp" + int main(int argc, char *args[]) { #if defined(WIN32) // Permet de refaire fonctionner cin et cout sous Windows après démarrage de SDL @@ -15,76 +17,87 @@ int main(int argc, char *args[]) { cout << "PILG - Debug" << endl; // Message d'entrée et de test - int dimX = 640, dimY = 128; - ouvrirFenetre(dimX, dimY, "PILG - Fenêtre de debug"); - - // Création imageRoue - Image imageRoue(dimX, dimY, 255, PILG_RVB); - Pixel pointRoue = imageRoue.g_pixelVide(); - int x, y, step; - float substep, lum; - for (x = 0; x < dimX; x++) { - for (y = 0; y < dimY; y++) { - step = (x * 6.0) / dimX; - substep = (x - step * (dimX / 6.0)) / (dimX / 6.0)*255; - lum = 1-((float) y)/dimY; - switch (step) { - case 0: - pointRoue.r = 255; - pointRoue.v = substep; - pointRoue.b = 0; - break; - case 1: - pointRoue.r = 255-substep; - pointRoue.v = 255; - pointRoue.b = 0; - break; - case 2: - pointRoue.r = 0; - pointRoue.v = 255; - pointRoue.b = substep; - break; - case 3: - pointRoue.r = 0; - pointRoue.v = 255-substep; - pointRoue.b = 255; - break; - case 4: - pointRoue.r = substep; - pointRoue.v = 0; - pointRoue.b = 255; - break; - case 5: - pointRoue.r = 255; - pointRoue.v = 0; - pointRoue.b = 255-substep; - break; - } - // Dégradé vers le noir - pointRoue.r = pointRoue.r*lum; - pointRoue.v = pointRoue.v*lum; - pointRoue.b = pointRoue.b*lum; - - // // Ajout de luminosité - // pointRoue.r = pointRoue.r + 50; - // pointRoue.v = pointRoue.v + 50; - // pointRoue.b = pointRoue.b + 50; - - // Remise dans l'intervalle - pointRoue.r = (pointRoue.r > 255 ? 255 : pointRoue.r); - pointRoue.v = (pointRoue.v > 255 ? 255 : pointRoue.v); - pointRoue.b = (pointRoue.b > 255 ? 255 : pointRoue.b); - - if (imageRoue.s_point(x, y, pointRoue) == 1) { - cerr << "Erreur : s_point() a été entré avec des valeurs incorrectes" << endl; - cout << "X : " << x << " - Y: " << y << " - R : " << pointRoue.r << " - V : " << pointRoue.v << " - B : " << pointRoue.b << endl; // DEBUG - return 1; - } - imageRoue.g_point(x, y, pointRoue); - pointFenetre(x, y, pointRoue.r, pointRoue.v, pointRoue.b); + // Analyse de commandes + if (argc > 1) { + vector< string > decoupe; + for (int i = 1; i < argc; i++) { + decoupe.push_back(args[i]); } + analyserDecoupe(decoupe); + } else { + boucleDeCommandes(); } - afficherFenetre(); + + // int dimX = 640, dimY = 128; + // ouvrirFenetre(dimX, dimY, "PILG - Fenêtre de debug"); + + // // Création imageRoue + // Image imageRoue(dimX, dimY, 255, PILG_RVB); + // Pixel pointRoue = imageRoue.g_pixelVide(); + // int x, y, step; + // float substep, lum; + // for (x = 0; x < dimX; x++) { + // for (y = 0; y < dimY; y++) { + // step = (x * 6.0) / dimX; + // substep = (x - step * (dimX / 6.0)) / (dimX / 6.0)*255; + // lum = 1-((float) y)/dimY; + // switch (step) { + // case 0: + // pointRoue.r = 255; + // pointRoue.v = substep; + // pointRoue.b = 0; + // break; + // case 1: + // pointRoue.r = 255-substep; + // pointRoue.v = 255; + // pointRoue.b = 0; + // break; + // case 2: + // pointRoue.r = 0; + // pointRoue.v = 255; + // pointRoue.b = substep; + // break; + // case 3: + // pointRoue.r = 0; + // pointRoue.v = 255-substep; + // pointRoue.b = 255; + // break; + // case 4: + // pointRoue.r = substep; + // pointRoue.v = 0; + // pointRoue.b = 255; + // break; + // case 5: + // pointRoue.r = 255; + // pointRoue.v = 0; + // pointRoue.b = 255-substep; + // break; + // } + // // Dégradé vers le noir + // pointRoue.r = pointRoue.r*lum; + // pointRoue.v = pointRoue.v*lum; + // pointRoue.b = pointRoue.b*lum; + + // // // Ajout de luminosité + // // pointRoue.r = pointRoue.r + 50; + // // pointRoue.v = pointRoue.v + 50; + // // pointRoue.b = pointRoue.b + 50; + + // // Remise dans l'intervalle + // pointRoue.r = (pointRoue.r > 255 ? 255 : pointRoue.r); + // pointRoue.v = (pointRoue.v > 255 ? 255 : pointRoue.v); + // pointRoue.b = (pointRoue.b > 255 ? 255 : pointRoue.b); + + // if (imageRoue.s_point(x, y, pointRoue) == 1) { + // cerr << "Erreur : s_point() a été entré avec des valeurs incorrectes" << endl; + // cout << "X : " << x << " - Y: " << y << " - R : " << pointRoue.r << " - V : " << pointRoue.v << " - B : " << pointRoue.b << endl; // DEBUG + // return 1; + // } + // imageRoue.g_point(x, y, pointRoue); + // pointFenetre(x, y, pointRoue.r, pointRoue.v, pointRoue.b); + // } + // } + // afficherFenetre(); // Cycle de couleurs avec utilisation d'Image // Image imageRoue(dimX, dimY, 255, PILG_RVB); @@ -119,9 +132,9 @@ int main(int argc, char *args[]) { // afficherFenetre(); // } - cout << "Éxecution du programme terminée. Vous pouvez quitter la fenêtre." << endl; - attendreFenetre(); - fermerFenetre(); + // cout << "Éxecution du programme terminée. Vous pouvez quitter la fenêtre." << endl; + // attendreFenetre(); + // fermerFenetre(); return 0; } diff --git a/src/traitementImage.cpp b/src/traitementImage.cpp index 705b339..e5d272c 100644 --- a/src/traitementImage.cpp +++ b/src/traitementImage.cpp @@ -1,23 +1,25 @@ // Gestion de fichiers int creer(Image &sortie, unsigned int dimensionX, unsigned int dimensionY, unsigned int maxComposante, PILG_Comp typeComposantes) { // Créer une image de dimensions X et Y - -sortie = new Image(dimensionX, dimensionY, maxComposante, typeComposantes); // Nouvelle - + Image *nouvelle = new Image(dimensionX, dimensionY, maxComposante, typeComposantes); + sortie = *nouvelle; } + int ouvrir(Image &sortie, string nomFichier) { // Ouvrir une image existante à partir du nom du fichier ***Geoffrey } -int sauver(Image entree, string nomFichier) { // Sauvegarder l'image obtenue dans un nouveau fichier + +int sauver(Image entree, string nomFichier, bool ASCII, string commentaire) { // Sauvegarder l'image obtenue dans un nouveau fichier } + int import(Image entree, Image &sortie, string nomFichier, int x, int y) { // Image fichierImporte; // sortie = entree // ouvrir(fichierImporte, nomFichier) // Pour x1 = 0 to x1 = fichierImporte.g_dimensionX - // Pour y1 = 0 to y1 = fichierImporte.g_dimensionY - // sortie.s_pixel(x1 + x, y1 + y, fichierImporte.g_pixel(x1, x2)); - // FinPour + // Pour y1 = 0 to y1 = fichierImporte.g_dimensionY + // sortie.s_pixel(x1 + x, y1 + y, fichierImporte.g_pixel(x1, x2)); + // FinPour // FinPour } @@ -27,112 +29,117 @@ int import(Image entree, Image &sortie, string nomFichier, int x, int y) { // Couleur int teinte(Image entree, Image &sortie, float teinte) { // Change la teinte de l'image // Si la teinte appartient à [0;1[ - // r1 = 0 - // r2 = 1 - // v1 = 1 - // v2 = 2 - // b1 = 2 - // b2 = 0 - // Valeur = Teinte + // r1 = 0 + // r2 = 1 + // v1 = 1 + // v2 = 2 + // b1 = 2 + // b2 = 0 + // Valeur = Teinte // Sinon Si la teinte appartient à [1;2[ - // r1 = 1 - // r2 = 2 - // v1 = 2 - // v2 = 0 - // b1 = 0 - // b2 = 1 - // Valeur = Teinte-1 + // r1 = 1 + // r2 = 2 + // v1 = 2 + // v2 = 0 + // b1 = 0 + // b2 = 1 + // Valeur = Teinte-1 // Sinon Si la teinte appartient à [2;3] - // r1 = 2 - // r2 = 0 - // v1 = 0 - // v2 = 1 - // b1 = 1 - // b2 = 2 - // Valeur = Teinte-2 + // r1 = 2 + // r2 = 0 + // v1 = 0 + // v2 = 1 + // b1 = 1 + // b2 = 2 + // Valeur = Teinte-2 // Fin Si // Pour x=0 à x=image.getDimensionX() - // Pour y=0 à y=image.getDimensionY() - // - // - // - // pixel.r = r1+(r2-r1)*valeur - // pixel.v = v1+(v2-v1)*valeur - // pixel.b = b1+(b2-b1)*valeur - // Fin Pour + // Pour y=0 à y=image.getDimensionY() + // + // + // + // pixel.r = r1+(r2-r1)*valeur + // pixel.v = v1+(v2-v1)*valeur + // pixel.b = b1+(b2-b1)*valeur + // Fin Pour // Fin Pour } int saturation(Image entree, Image &sortie, float saturation) { // Sature l'image // Pour x = image.g_DimensionX() - // Pour y = image.g_DimensionY() - // Ajouter la variable saturation à chaque valeur de chaque pixel - // Ne pas dépasser le seuil limite MaxComposante !!! - // Fin Pour + // Pour y = image.g_DimensionY() + // Ajouter la variable saturation à chaque valeur de chaque pixel + // Ne pas dépasser le seuil limite MaxComposante !!! + // Fin Pour // Fin Pour } + int luminosite(Image entree, Image &sortie, float luminosite) { // Augmente la luminosité de l'image // Pour x=0 à x=image.g_DimensionX() - // Pour y=0 à y=image.g_DimensionY() - // si image.g_typeComposante=1 - // pixel = image.g_point(x,y); - // pixel.g = luminosite*10+pixel.g; - // image.s_point(x, y, pixel); - // sinon si image.g_typeComposante=2 - // pixel = image.g_point(x,y); - // pixel.r = luminosite*10+pixel.r; - // pixel.v = luminosite*10+pixel.v; - // pixel.b = luminosite*10+pixel.b; - // image.s_point(x, y, pixel); - // Fin si - // Fin Pour + // Pour y=0 à y=image.g_DimensionY() + // si image.g_typeComposante=1 + // pixel = image.g_point(x,y); + // pixel.g = luminosite*10+pixel.g; + // image.s_point(x, y, pixel); + // sinon si image.g_typeComposante=2 + // pixel = image.g_point(x,y); + // pixel.r = luminosite*10+pixel.r; + // pixel.v = luminosite*10+pixel.v; + // pixel.b = luminosite*10+pixel.b; + // image.s_point(x, y, pixel); + // Fin si + // Fin Pour // Fin Pour } + int contraste(Image entree, Image &sortie, float contraste) { // Accentue les contrastes de l'image // pour x=0 à x=image.g_dimensionX() - //pour y=0 à y=image.g_DimensionY() - //si image.g_typeComposante=1 - //pixel = image.g_point(x,y); - //pixel.g = contraste*pixel.g; - // if pixel.g > Image.g_maxComposante - // pixel.g = Image.g_maxComposante - // end if + // pour y=0 à y=image.g_DimensionY() + // si image.g_typeComposante=1 + // pixel = image.g_point(x,y); + // pixel.g = contraste*pixel.g; + // if pixel.g > Image.g_maxComposante + // pixel.g = Image.g_maxComposante + // end if } // Dessin int trait(Image entree, Image &sortie, int x1, int y1, int x2, int y2, Pixel pixel) { // Dessine un trait d'un point (x1,y1) à un point (x2,y2) -// int x, y, dx, dy ; -// float e, e(1,0), e(0,1) ; // valeur d’erreur et incréments -// dy ← y2 - y1 ; -// dx ← x2 - x1 ; -// y ← y1 ; // rangée initiale -// e ← 0,0 ; // valeur d’erreur initiale -// e(1,0) ← dy / dx ; -// e(0,1) ← -1.0 ; -// pour x variant de x1 jusqu’à x2 par incrément de 1 faire -// tracerPixel(x, y) ; -// si (e ← e + e(1,0)) ≥ 0,5 alors // erreur pour le pixel suivant de même rangée -// y ← y + 1 ; // choisir plutôt le pixel suivant dans la rangée supérieure -// e ← e + e(0,1) ; // ajuste l’erreur commise dans cette nouvelle rangée -// fin si ; -// fin pour ; -//fin procédure ; + // int x, y, dx, dy ; + // float e, e(1,0), e(0,1) ; // valeur d’erreur et incréments + // dy ← y2 - y1 ; + // dx ← x2 - x1 ; + // y ← y1 ; // rangée initiale + // e ← 0,0 ; // valeur d’erreur initiale + // e(1,0) ← dy / dx ; + // e(0,1) ← -1.0 ; + // pour x variant de x1 jusqu’à x2 par incrément de 1 faire + // tracerPixel(x, y) ; + // si (e ← e + e(1,0)) ≥ 0,5 alors // erreur pour le pixel suivant de même rangée + // y ← y + 1 ; // choisir plutôt le pixel suivant dans la rangée supérieure + // e ← e + e(0,1) ; // ajuste l’erreur commise dans cette nouvelle rangée + // fin si ; + // fin pour ; + //fin procédure ; } + int rectangle(Image entree, Image &sortie, int x1, int y1, int x2, int y2, Pixel couleur) { // sortie = entree // pour x=x1 à x=x2 - //pour y=y1 à y=y2 - //sortie.s_pixel(x, y, couleur) - // FinPour + // pour y=y1 à y=y2 + // sortie.s_pixel(x, y, couleur) + // FinPour // FinPour } + int cercle(Image entree, Image &sortie, int x, int y, int r, Pixel couleur) { } + int disque(Image entree, Image &sortie, int x, int y, int r, Pixel couleur) { } @@ -141,31 +148,34 @@ int disque(Image entree, Image &sortie, int x, int y, int r, Pixel couleur) { int zoom(Image entree, Image &sortie) { } + int pivoter(Image entree, Image &sortie) { } + int retourner(Image entree, Image &sortie, int rotation) { } + int redimensionner(Image entree, Image &sortie, int x1, int x2, int y1, int y2) { - // sortie = new Image(x2-x1, y2-y1, entree.g_maxComposante(), entree.g_typeComposantes()) + // Image *nouvelle = new Image(x2-x1, y2-y1, entree.g_maxComposante(), entree.g_typeComposantes()); + // sortie = *nouvelle; // pour x=x1 à x=x2 - //pour y=y1 à y=y2 - // sortie.s_pixel(x, y, entree.g_pixel(x+x1, y+y1)); - // FinPour + // pour y=y1 à y=y2 + // sortie.s_pixel(x, y, entree.g_pixel(x+x1, y+y1)); + // FinPour // FinPour - - - } // Modification couleur int convBIN(Image entree, Image &sortie) { } + int convNIV(Image entree, Image &sortie) { } + int convRVB(Image entree, Image &sortie) { }