Avancement dans l'éxecution de commandes

Le programme dispose désormais d'une image par défaut affichée à l'écran. L'analyse de commandes a été travaillé, pour la tester la fonction rectangle fonctionne, sans arguments cependant, ce sera donc un carré prédéfini qui apparaitra sur l'image de test. Diverses améliorations notables cependant.

* Modifié main.cpp
	* Ajout d'une Image par défaut (sorte de roue chromatique horizontale) aux proportions d'or
* Modifié analyserCommande.cpp
	* Ajout d'une fonction d'affichage d'une Image à l'écran
	* Ajout d'un objet Commande pour faciliter le transfert entre les fonctions
	* Ajout d'executerCommande()
		* Vérifie si les arguments requis sont présents grâce à argumentPresent()
		* Execute la fonction correspondante dans traitementImage.cpp
	* Ajout de procederCommande() qui gère l'execution d'analyserDecoupe() et d'executerCommande()
* Modifié traitementImage.cpp
	* Puisque chaque fonction n'est pas censé échouer, les types de retour sont des void
	* rectangle() codé
* Modifié affichageFenetre.cpp
	* attendreFenetre() autorise une action sur le clavier
	* Ajout de la valeur globale booléenne fenetreOuverte
	* Corrigé un éventuel bug pouvant arriver lorsque les dimensions étaient rectangulaires
* Modifié l'objet Image
	* Les validateurs sont désormais au nombre de deux, v_pixel() et v_dimensions() pour chaque Image, et sont publics
* Modifié testing.cpp
	* Ajout fonctions génératrices d'images de test pour chaque type de composante
* Mis à jour TODO.md
* Amélioration du Makefile
* Modification de .travis.yml pour placer le `make testing` en post-script
master
Geoffrey Frogeye 2014-05-08 19:44:09 +02:00
父節點 2e5cbafa3c
當前提交 43550b265f
共有 11 個檔案被更改,包括 468 行新增265 行删除

查看文件

@ -1,6 +1,8 @@
language: cpp
compiler: gcc
before_install:
- sudo apt-get update -qq
- sudo apt-get update
- sudo apt-get install -y libsdl1.2-dev
script: make && make testing
script: make
after_install:
- make testing

查看文件

@ -11,21 +11,26 @@ OBJPATH = obj/
SRCPATH = src/
# Programmes possibles
main: main.o image.o
$(CXX) $(OBJPATH)main.o $(OBJPATH)image.o -o $(EXEPATH)$@ $(CXXFLAGS)
main: $(EXEPATH)main
testing: $(EXEPATH)testing
testing: test.o image.o
$(CXX) $(OBJPATH)test.o $(OBJPATH)image.o -o $(EXEPATH)$@ $(CXXFLAGSDEBUG)
# Éxecutables
$(EXEPATH)main: $(OBJPATH)main.o $(OBJPATH)image.o
$(CXX) $^ -o $@ $(CXXFLAGS)
$(EXEPATH)testing: $(OBJPATH)testing.o $(OBJPATH)image.o
$(CXX) $^ -o $@ $(CXXFLAGSDEBUG)
# Dépendances
main.o: $(SRCPATH)main.cpp $(SRCPATH)image.h
$(CXX) -c $< -o $(OBJPATH)$@ $(CXXFLAGS)
## Fichiers executables
$(OBJPATH)main.o: $(SRCPATH)main.cpp $(SRCPATH)image.h
$(CXX) -c $< -o $@ $(CXXFLAGS)
test.o: $(SRCPATH)test.cpp $(SRCPATH)image.cpp
$(CXX) -c $< -o $(OBJPATH)$@ $(CXXFLAGSDEBUG)
image.o: $(SRCPATH)image.cpp
$(CXX) -c $< -o $(OBJPATH)$@
$(OBJPATH)testing.o: $(SRCPATH)testing.cpp $(SRCPATH)image.cpp
$(CXX) -c $< -o $@ $(CXXFLAGSDEBUG)
## Bibliothèques
$(OBJPATH)image.o: $(SRCPATH)image.cpp
$(CXX) -c $< -o $@
# Meta
clean:

10
TODO.md
查看文件

@ -8,11 +8,11 @@
###Liste générale
*Ordre donné à titre indicatif*
* Fonction principale
* Fonction d'analyse de commande
* Fonction principale **C**
* Fonction d'analyse de commande **D**
* Analyse de la commande **C**
* Analyse des arguments
* Correspondance commandes ↔ fonctions **D**
* Analyse des arguments **D**
* Execution des fonctions **C**
* Objets **C**
* Fenêtre **C**
* Pixel **C**
@ -36,7 +36,7 @@
* Contraste **A**
* Dessin **D**
* Trait **D**
* Rectangle **A**
* Rectangle **C**
* Cercle **D**
* Disque **D**
* Géométrie **D**

查看文件

@ -3,31 +3,22 @@
int fenetreDimensionX; // Stocke les dimensions X de la fenêtre
int fenetreDimensionY; // Stocke les dimensions Y de la fenêtre
bool fenetreOuverte = false;
SDL_Surface *fenetreEcran;
SDL_Surface *fenetreImage;
void definirPixel(SDL_Surface *surface, int x, int y, Uint32 pixel) {
/*nbOctetsParPixel représente le nombre d'octets utilisés pour stocker un pixel.
En multipliant ce nombre d'octets par 8 (un octet = 8 bits), on obtient la profondeur de couleur
de l'image : 8, 16, 24 ou 32 bits.*/
int nbOctetsParPixel = surface->format->BytesPerPixel;
/*Ici p est l'adresse du pixel que l'on veut modifier*/
/*surface->pixels contient l'adresse du premier pixel de l'image*/
Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * nbOctetsParPixel;
/*Gestion différente suivant le nombre d'octets par pixel de l'image*/
switch (nbOctetsParPixel) {
case 1:
*p = pixel;
break;
case 2:
*(Uint16 *)p = pixel;
break;
case 3:
/*Suivant l'architecture de la machine*/
if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
p[0] = (pixel >> 16) & 0xff;
p[1] = (pixel >> 8) & 0xff;
@ -38,7 +29,6 @@ void definirPixel(SDL_Surface *surface, int x, int y, Uint32 pixel) {
p[2] = (pixel >> 16) & 0xff;
}
break;
case 4:
*(Uint32 *)p = pixel;
break;
@ -53,17 +43,16 @@ void pointFenetre(int x, int y, int r, int v, int b) {
// std::cout << "(" << x << ";" << y << ") = (" << r << ";" << v << ";" << b << ")" << std::endl; // DEBUG
Uint32 pixel;
Uint8 u_r, u_v, u_b, u_a;
u_r = (r > 255 ? 0xff : (Uint8) r);
u_v = (v > 255 ? 0xff : (Uint8) v);
u_b = (b > 255 ? 0xff : (Uint8) b);
u_a = 0xff;
pixel = SDL_MapRGBA(fenetreImage->format, u_r, u_v, u_b, u_a);
definirPixel(fenetreImage, x, y, pixel);
}
void afficherFenetre() {
@ -79,24 +68,27 @@ void afficherFenetre() {
void attendreFenetre() {
SDL_Event evenement;
while (evenement.type != SDL_QUIT) {
do {
SDL_WaitEvent(&evenement);
}
} while (evenement.type != SDL_QUIT && evenement.type != SDL_KEYDOWN); //|| evenement.type != SDL_KEYDOWN);
}
void fermerFenetre() {
SDL_UnlockSurface(fenetreImage);
SDL_FreeSurface(fenetreImage);
SDL_Quit();
fenetreOuverte = false;
}
void ouvrirFenetre(int dimensionX, int dimensionY, std::string nom) { // Crée une fenêtre
void ouvrirFenetre(int dimensionX, int dimensionY, std::string nom) { // Crée une fenêtre
SDL_Init(SDL_INIT_VIDEO);
fenetreDimensionX = dimensionX;
fenetreDimensionY = dimensionY;
fenetreEcran = SDL_SetVideoMode(fenetreDimensionX, fenetreDimensionY, 32, SDL_HWSURFACE);
fenetreImage = SDL_CreateRGBSurface(SDL_HWSURFACE, fenetreDimensionX, fenetreDimensionX, 32, 0, 0, 0, 0);
fenetreImage = SDL_CreateRGBSurface(SDL_HWSURFACE, fenetreDimensionX, fenetreDimensionY, 32, 0, 0, 0, 0);
SDL_FillRect(fenetreImage, NULL, SDL_MapRGB(fenetreEcran->format, 0, 0, 0));
setNomFenetre(nom);
SDL_LockSurface(fenetreImage);
}
fenetreOuverte = true;
}

查看文件

@ -1,13 +1,51 @@
#include <vector>
#include <string>
#include <iostream>
using namespace std;
int messageErreur(string message) {
cerr << "Erreur : " << message << endl;
int chaineVersEntier(string chaine) {
return (int) chaine[0];
}
int decoupeCommande(string commande, vector< string > &decoupe) {
void afficherImage(Image image) {
int x, y, r, v, b, dimensionX = image.g_dimensionX(), dimensionY = image.g_dimensionY(), typeComposantes = image.g_typeComposantes();
float ratio = (255.0 / image.g_maxComposante());
Pixel pixel;
if (fenetreOuverte && (dimensionX != fenetreDimensionX || dimensionY != fenetreDimensionY)) {
fermerFenetre();
}
ouvrirFenetre(dimensionX, dimensionY, "PILG - Test");
for (x = 0; x < dimensionX; x++) {
for (y = 0; y < dimensionY; y++) {
image.g_pixel(x, y, pixel);
switch (typeComposantes) {
case PILG_BIN:
r = v = b = (pixel.n ? 255 : 0);
break;
case PILG_NIV:
r = v = b = pixel.g * ratio;
break;
case PILG_RVB:
r = pixel.r * ratio;
v = pixel.v * ratio;
b = pixel.b * ratio;
break;
}
pointFenetre(x, y, r, v, b);
}
}
afficherFenetre();
}
void messageErreur(string message) {
cerr << "Erreur : " << message << '.' << endl;
}
void decoupeCommande(string commande, vector< string > &decoupe) {
// Boucle de découpage
// vector< string > decoupe;
string elementCourrant = "";
@ -64,26 +102,96 @@ int decoupeCommande(string commande, vector< string > &decoupe) {
}
}
int analyserDecoupe(vector< string > decoupe) {
for (int i = 0; i < decoupe.size(); i++) { // DEBUG
cout << "Argument " << i << " = " << decoupe[i] << endl;
typedef struct Commande {
string fonction;
int x1, x2, y1, y2;
string fichierEntree, fichierSortie;
Pixel couleur;
// ...
vector< string > argumentsPresents;
} Commande;
int analyserDecoupe(Commande &commande, vector< string > decoupe, Image const &image) {
// for (int i = 0; i < decoupe.size(); i++) { // DEBUG
// cout << "Argument " << i << " = " << decoupe[i] << endl;
// }
commande.couleur = image.g_pixelVide();
commande.fonction = decoupe[0];
// Analyse des arguments
// for (int i = 1; i < decoupe.size(); i++) {
// ...
// }
return 0;
}
bool argumentPresent(Commande commande, string argumentVoulu) {
for (int i = 0; i < commande.argumentsPresents.size(); i++) {
if (commande.argumentsPresents[i] == argumentVoulu) {
return true;
}
}
return false;
}
int executerCommande(Commande commande, Image &image) {
if (commande.fonction == "rectangle") {
commande.couleur.v = image.g_maxComposante(); // DEBUG
rectangle(image, image, 5, 5, 10, 10, commande.couleur); // DEBUG
if (argumentPresent(commande, "x1") && argumentPresent(commande, "x2")
&& argumentPresent(commande, "y1") && argumentPresent(commande, "y2")
&& argumentPresent(commande, "couleur")) {
// TODO
} else {
return 2;
}
} else {
return 1;
}
return 0;
}
void procederCommande(vector< string > decoupe, Image &image) {
Commande commande;
switch (analyserDecoupe(commande, decoupe, image)) {
case 0:
switch (executerCommande(commande, image)) {
case 0:
break;
case 1:
messageErreur("Fonction inconnue");
break;
case 2:
messageErreur("Arguments manquants");
break;
default:
messageErreur("Impossible d'éxecuter la fonction");
}
break;
default:
messageErreur("Impossible d'analyse de la commande");
break;
}
}
int boucleDeCommandes() {
int boucleDeCommandes(Image image) { // REPL
bool continuer = true;
string commande;
string commandeTexte;
while (continuer) {
cout << "$ ";
getline(cin, commande);
if (commande == "exit" || commande == "quitter") {
getline(cin, commandeTexte);
if (commandeTexte == "quitter" || commandeTexte == "exit") {
continuer = false;
} else {
vector< string > decoupe;
decoupeCommande(commande, decoupe);
analyserDecoupe(decoupe);
decoupeCommande(commandeTexte, decoupe);
procederCommande(decoupe, image);
afficherImage(image);
}
}
return 0;
}
}

查看文件

@ -28,8 +28,8 @@ unsigned int Image::g_maxComposante() const {
return m_maxComposante;
}
int Image::g_point(unsigned int x, unsigned int y, Pixel &pixel) const {
if (enLimites(x, y)) {
int Image::g_pixel(unsigned int x, unsigned int y, Pixel &pixel) const {
if (v_dimensions(x, y)) {
pixel = m_tab[x][y];
return 0;
} else {
@ -38,11 +38,8 @@ int Image::g_point(unsigned int x, unsigned int y, Pixel &pixel) const {
}
// Setters
int Image::s_point(unsigned int x, unsigned int y, Pixel pixel) {
if (enLimites(x, y)
&& pixel.typeComposantes == m_typeComposantes
&& pixel.maxComposante == m_maxComposante
&& enLimitesComposantes(pixel)) {
int Image::s_pixel(unsigned int x, unsigned int y, Pixel pixel) {
if (v_dimensions(x, y) && v_pixel(pixel)) {
m_tab[x][y] = pixel;
return 0;
} else {
@ -71,25 +68,31 @@ Pixel Image::g_pixelVide() const {
return pixel;
}
bool Image::enLimitesComposantes(Pixel pixel) {
switch (pixel.typeComposantes) {
case PILG_BIN:
return true;
break;
case PILG_NIV:
return (pixel.g <= pixel.maxComposante);
break;
case PILG_RVB:
return (pixel.r <= pixel.maxComposante
&& pixel.v <= pixel.maxComposante
&& pixel.b <= pixel.maxComposante);
break;
default:
// Validateurs
bool Image::v_pixel(Pixel pixel) const {
if (pixel.typeComposantes == m_typeComposantes
&& pixel.maxComposante == m_maxComposante) {
switch (pixel.typeComposantes) {
case PILG_BIN:
return true;
break;
case PILG_NIV:
return (pixel.g <= pixel.maxComposante);
break;
case PILG_RVB:
return (pixel.r <= pixel.maxComposante
&& pixel.v <= pixel.maxComposante
&& pixel.b <= pixel.maxComposante);
break;
default:
return false;
break;
}
} else {
return false;
break;
}
}
bool Image::enLimites(unsigned int x, unsigned int y) const {
bool Image::v_dimensions(unsigned int x, unsigned int y) const {
return (x >= 0 && x < m_dimensionX && y >= 0 && y < m_dimensionY);
}

查看文件

@ -20,20 +20,20 @@ public:
unsigned int g_dimensionY() const;
PILG_Comp g_typeComposantes() const;
unsigned int g_maxComposante() const;
int g_point(unsigned int x, unsigned int y, Pixel &pixel) const;
int g_pixel(unsigned int x, unsigned int y, Pixel &pixel) const;
// Setters
int s_point(unsigned int x, unsigned int y, Pixel pixel);
int s_pixel(unsigned int x, unsigned int y, Pixel pixel);
// Utilitaires
Pixel g_pixelVide() const;
// Validateurs
bool v_pixel(Pixel pixel) const;
bool v_dimensions(unsigned int x, unsigned int y) const;
private:
// Utilitaires
static bool enLimitesComposantes(Pixel pixel);
bool enLimites(unsigned int x, unsigned int y) const;
// Variables
unsigned int m_dimensionX;
unsigned int m_dimensionY;
PILG_Comp m_typeComposantes; // 0 : N&B, 1 : Niveaux de gris, 2 : RVB
PILG_Comp m_typeComposantes;
unsigned int m_maxComposante; // Maximum de composante (sauf binaire)
std::vector< std::vector< Pixel > > m_tab;
};

查看文件

@ -1,5 +1,4 @@
#include <iostream>
#include <string>
using namespace std;
@ -8,23 +7,82 @@ using namespace std;
#include "traitementImage.cpp"
#include "analyserCommande.cpp"
#define NOMBREOR 1.61803398875
Image imageDefaut() {
int dimY = 256, dimX = dimY * NOMBREOR, maxComposante = 255;
Image imageRoue(dimX, dimY, maxComposante, 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) * maxComposante;
lum = 1 - ((float) y) / dimY;
switch (step) {
case 0:
pointRoue.r = maxComposante;
pointRoue.v = substep;
pointRoue.b = 0;
break;
case 1:
pointRoue.r = maxComposante - substep;
pointRoue.v = maxComposante;
pointRoue.b = 0;
break;
case 2:
pointRoue.r = 0;
pointRoue.v = maxComposante;
pointRoue.b = substep;
break;
case 3:
pointRoue.r = 0;
pointRoue.v = maxComposante - substep;
pointRoue.b = maxComposante;
break;
case 4:
pointRoue.r = substep;
pointRoue.v = 0;
pointRoue.b = maxComposante;
break;
case 5:
pointRoue.r = maxComposante;
pointRoue.v = 0;
pointRoue.b = maxComposante - substep;
break;
}
// Dégradé vers le noir
pointRoue.r = pointRoue.r * lum;
pointRoue.v = pointRoue.v * lum;
pointRoue.b = pointRoue.b * lum;
imageRoue.s_pixel(x, y, pointRoue);
}
}
return imageRoue;
}
int main(int argc, char *args[]) {
#if defined(WIN32) // Permet de refaire fonctionner cin et cout sous Windows après démarrage de SDL
#if defined(WIN32) // Permet de refaire fonctionner cout et cerr sous Windows après démarrage de SDL
freopen("CON", "w", stdout);
freopen("CON", "w", stderr);
#endif
cout << "PILG" << endl; // Message d'entrée et de test
if (argc > 1) {
Image image = imageDefaut();
if (argc > 1) { // Si la commande a été entrée avec des arguments
vector< string > decoupe;
for (int i = 1; i < argc; i++) {
decoupe.push_back(args[i]);
}
analyserDecoupe(decoupe);
procederCommande(decoupe, image);
} else {
boucleDeCommandes();
afficherImage(image);
boucleDeCommandes(image);
}
return 0;

查看文件

@ -1,140 +0,0 @@
#include <iostream>
#include <string>
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
freopen("CON", "w", stdout);
freopen("CON", "w", stderr);
#endif
cout << "PILG - Debug" << endl; // Message d'entrée et de test
// 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();
}
// 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);
// Pixel pointRoueRoue = imageRoue.g_pixelVide();
// int x, y, c;
// for (c = 0; c < 256; c++) { // À peu près 28 FPS avec SDL
// for (x = 0; x < dimX; x++) {
// for (y = 0; y < dimY; y++) {
// point.r = c;
// point.v = image.g_maxComposante() - c;
// point.b = 0;
// if (image.s_point(x, y, point) == 1) {
// cerr << "Erreur : s_point() a été entré avec des valeurs incorrectes" << endl;
// cout << "X : " << x << " - Y: " << y << " - R : " << point.r << " - V : " << point.v << " - B : " << point.b << endl; // DEBUG
// return 1;
// }
// image.g_point(x, y, point);
// pointFenetre(x, y, point.r, point.v, point.b);
// }
// }
// afficherFenetre();
// }
// // Cycle de couleurs sans utilisation d'Image
// int x, y, c;
// for (c = 0; c < 256; c++) { // À peu près 75 FPS avec SDL
// for (x = 0; x < dimX; x++) {
// for (y = 0; y < dimY; y++) {
// pointFenetre(x, y, c, 255 - c, 0);
// }
// }
// afficherFenetre();
// }
// cout << "Éxecution du programme terminée. Vous pouvez quitter la fenêtre." << endl;
// attendreFenetre();
// fermerFenetre();
return 0;
}

177
src/testing.cpp Normal file
查看文件

@ -0,0 +1,177 @@
#include <iostream>
#include <string>
using namespace std;
#include "affichageFenetre.cpp"
#include "image.h"
#include "traitementImage.cpp"
#include "analyserCommande.cpp"
Image genererRoue(int dimX, int dimY, int maxComposante) {
Image imageRoue(dimX, dimY, maxComposante, 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) * maxComposante;
lum = 1 - ((float) y) / dimY;
switch (step) {
case 0:
pointRoue.r = maxComposante;
pointRoue.v = substep;
pointRoue.b = 0;
break;
case 1:
pointRoue.r = maxComposante - substep;
pointRoue.v = maxComposante;
pointRoue.b = 0;
break;
case 2:
pointRoue.r = 0;
pointRoue.v = maxComposante;
pointRoue.b = substep;
break;
case 3:
pointRoue.r = 0;
pointRoue.v = maxComposante - substep;
pointRoue.b = maxComposante;
break;
case 4:
pointRoue.r = substep;
pointRoue.v = 0;
pointRoue.b = maxComposante;
break;
case 5:
pointRoue.r = maxComposante;
pointRoue.v = 0;
pointRoue.b = maxComposante - substep;
break;
}
// Dégradé vers le noir
pointRoue.r = pointRoue.r * lum;
pointRoue.v = pointRoue.v * lum;
pointRoue.b = pointRoue.b * lum;
// // Remise dans l'intervalle
// pointRoue.r = (pointRoue.r > maxComposante ? maxComposante : pointRoue.r);
// pointRoue.v = (pointRoue.v > maxComposante ? maxComposante : pointRoue.v);
// pointRoue.b = (pointRoue.b > maxComposante ? maxComposante : pointRoue.b);
if (imageRoue.s_pixel(x, y, pointRoue) == 1) {
cerr << "Erreur : s_pixel() a été entré avec des valeurs incorrectes" << endl;
cout << "X : " << x << " - Y: " << y << " - R : " << pointRoue.r << " - V : " << pointRoue.v << " - B : " << pointRoue.b << endl; // DEBUG
}
imageRoue.g_pixel(x, y, pointRoue);
}
}
return imageRoue;
}
Image genererDegrade(int dimX, int dimY, int maxComposante) {
Image image(dimX, dimY, maxComposante, PILG_NIV);
Pixel pixel = image.g_pixelVide();
int x, y;
for (x = 0; x < dimX; x++) {
for (y = 0; y < dimY; y++) {
pixel.g = (float) x * maxComposante / dimX;
image.s_pixel(x, y, pixel);
}
}
return image;
}
Image genererBruit(int dimX, int dimY) {
Image image(dimX, dimY, 0, PILG_BIN);
Pixel pixel = image.g_pixelVide();
int x, y;
for (x = 0; x < dimX; x++) {
for (y = 0; y < dimY; y++) {
pixel.n = ((float) rand() / RAND_MAX) < ((float) x / dimX);
image.s_pixel(x, y, pixel);
}
}
return image;
}
int main(int argc, char *args[]) {
#if defined(WIN32) // Permet de refaire fonctionner cout et cerr sous Windows après démarrage de SDL
freopen("CON", "w", stdout);
freopen("CON", "w", stderr);
#endif
cout << "PILG - Debug" << endl; // Message d'entrée et de test
// // 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();
// }
// // Afficher image par défaut
// // Image image = genererRoue(200, 200, 255);
// // Image image = genererDegrade(200, 200, 255);
// Image image = genererBruit(200, 200);
// Pixel couleurRectangle;
// couleurRectangle = image.g_pixelVide();
// // couleurRectangle.b = 255;
// // couleurRectangle.g = 255;
// couleurRectangle.b = true;
// rectangle(image, image, 5, 5, 10, 10, couleurRectangle);
// afficherImage(image);
// attendreFenetre();
// // Neige en dégradé
// for (int i; i < 300; i++) {
// afficherImage(genererBruit(200, 200));
// }
// Cycle de couleurs avec utilisation d'Image
// Image imageRoue(dimX, dimY, 255, PILG_RVB);
// Pixel pointRoueRoue = imageRoue.g_pixelVide();
// int x, y, c;
// for (c = 0; c < 256; c++) { // À peu près 28 FPS avec SDL
// for (x = 0; x < dimX; x++) {
// for (y = 0; y < dimY; y++) {
// pixel.r = c;
// pixel.v = image.g_maxComposante() - c;
// pixel.b = 0;
// if (image.s_pixel(x, y, pixel) == 1) {
// cerr << "Erreur : s_pixel() a été entré avec des valeurs incorrectes" << endl;
// cout << "X : " << x << " - Y: " << y << " - R : " << pixel.r << " - V : " << pixel.v << " - B : " << pixel.b << endl; // DEBUG
// return 1;
// }
// image.g_pixel(x, y, pixel);
// pointFenetre(x, y, pixel.r, pixel.v, pixel.b);
// }
// }
// afficherFenetre();
// }
// // Cycle de couleurs sans utilisation d'Image
// int x, y, c;
// for (c = 0; c < 256; c++) { // À peu près 75 FPS avec SDL
// for (x = 0; x < dimX; x++) {
// for (y = 0; y < dimY; y++) {
// pointFenetre(x, y, c, 255 - c, 0);
// }
// }
// afficherFenetre();
// }
// cout << "Éxecution du programme terminée. Vous pouvez quitter la fenêtre." << endl;
// attendreFenetre();
// fermerFenetre();
return 0;
}

查看文件

@ -1,18 +1,18 @@
// 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
// Gestion de fichiers
void creer(Image &sortie, unsigned int dimensionX, unsigned int dimensionY, unsigned int maxComposante, PILG_Comp typeComposantes) { // Créer une image de dimensions X et Y
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
void ouvrir(Image &sortie, string nomFichier) { // Ouvrir une image existante à partir du nom du fichier ***Geoffrey
}
int sauver(Image entree, string nomFichier, bool ASCII, string commentaire) { // Sauvegarder l'image obtenue dans un nouveau fichier
void 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) {
void import(Image entree, Image &sortie, string nomFichier, int x, int y) {
// Image fichierImporte;
// sortie = entree
// ouvrir(fichierImporte, nomFichier)
@ -20,14 +20,12 @@ int import(Image entree, Image &sortie, string nomFichier, int x, int y) {
// Pour y1 = 0 to y1 = fichierImporte.g_dimensionY
// sortie.s_pixel(x1 + x, y1 + y, fichierImporte.g_pixel(x1, x2));
// FinPour
// FinPour
// FinPour
}
// Edition ***Geoffrey
// Couleur
int teinte(Image entree, Image &sortie, float teinte) { // Change la teinte de l'image
void teinte(Image entree, Image &sortie, float teinte) { // Change la teinte de l'image
// Si la teinte appartient à [0;1[
// r1 = 0
// r2 = 1
@ -55,9 +53,9 @@ int teinte(Image entree, Image &sortie, float teinte) { // Change la teinte de l
// 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
@ -65,7 +63,7 @@ int teinte(Image entree, Image &sortie, float teinte) { // Change la teinte de l
// Fin Pour
}
int saturation(Image entree, Image &sortie, float saturation) { // Sature l'image
void 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
@ -74,29 +72,29 @@ int saturation(Image entree, Image &sortie, float saturation) { // Sature l'imag
// Fin Pour
}
int luminosite(Image entree, Image &sortie, float luminosite) { // Augmente la luminosité de l'image
void 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 = image.g_pixel(x,y);
// pixel.g = luminosite*10+pixel.g;
// image.s_point(x, y, pixel);
// image.s_pixel(x, y, pixel);
// sinon si image.g_typeComposante=2
// pixel = image.g_point(x,y);
// pixel = image.g_pixel(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);
// image.s_pixel(x, y, pixel);
// Fin si
// Fin Pour
// Fin Pour
}
int contraste(Image entree, Image &sortie, float contraste) { // Accentue les contrastes de l'image
void 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 = image.g_pixel(x,y);
// pixel.g = contraste*pixel.g;
// if pixel.g > Image.g_maxComposante
// pixel.g = Image.g_maxComposante
@ -106,7 +104,7 @@ int contraste(Image entree, Image &sortie, float contraste) { // Accentue les co
}
// 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)
void 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 ;
@ -126,38 +124,38 @@ int trait(Image entree, Image &sortie, int x1, int y1, int x2, int y2, Pixel pix
}
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
// FinPour
void rectangle(Image entree, Image &sortie, int x1, int y1, int x2, int y2, Pixel couleur) {
sortie = entree;
for (int x = x1; x <= x2; x++) {
for (int y = y1; y <= y2; y++) {
sortie.s_pixel(x, y, couleur);
}
}
}
int cercle(Image entree, Image &sortie, int x, int y, int r, Pixel couleur) {
void 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) {
void disque(Image entree, Image &sortie, int x, int y, int r, Pixel couleur) {
}
// Geométrie
int zoom(Image entree, Image &sortie) {
void zoom(Image entree, Image &sortie) {
}
int pivoter(Image entree, Image &sortie) {
void pivoter(Image entree, Image &sortie) {
}
int retourner(Image entree, Image &sortie, int rotation) {
void retourner(Image entree, Image &sortie, int rotation) {
}
int redimensionner(Image entree, Image &sortie, int x1, int x2, int y1, int y2) {
void redimensionner(Image entree, Image &sortie, int x1, int x2, int y1, int y2) {
// Image *nouvelle = new Image(x2-x1, y2-y1, entree.g_maxComposante(), entree.g_typeComposantes());
// sortie = *nouvelle;
// pour x=x1 à x=x2
@ -168,19 +166,19 @@ int redimensionner(Image entree, Image &sortie, int x1, int x2, int y1, int y2)
}
// Modification couleur
int convBIN(Image entree, Image &sortie) {
void convBIN(Image entree, Image &sortie) {
}
int convNIV(Image entree, Image &sortie) {
void convNIV(Image entree, Image &sortie) {
}
int convRVB(Image entree, Image &sortie) {
void convRVB(Image entree, Image &sortie) {
}
//Help
int aide() {
void aide() {
//Afficher le texte suivant :
}