Skip to content
This repository has been archived by the owner on Dec 6, 2018. It is now read-only.

Commit

Permalink
[v1.0.0] Teinte, Saturation, Luminosité
Browse files Browse the repository at this point in the history
Passage en v1.0.0 finale (il faut bien, à un moment...).
* Traitement image & commandes
	* Ajout de la fonction teinte
	* Ajout de la fonction saturation
	* Ajout de la fonction luminosité
* Utilitaires
	* Ajout de conversions RVB→TSL & TSL→RVB pour les fonctions teinte, saturation et luminosité
	* L'image par défaut est désormais générée à partir de teinte et luminosité
* Affichage de la fenêtre
	* La taille de l'écran est récupérable
	* L'échelle est désormais variable et est calculée selon les dimensions de l'écran
  • Loading branch information
GeoffreyFrogeye committed May 22, 2014
1 parent 386ff0b commit 82a60fc
Show file tree
Hide file tree
Showing 9 changed files with 264 additions and 122 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Nos noms complets et le nom du lycée sont masqués pour des raisons d'intimité
###Le programme
Ce programme est un éditeur basique d'images [PBM/PGM/PPM](http://fr.wikipedia.org/wiki/Portable_pixmap) s’exécutant en ligne de commande.

*Version :* Alpha
*Version :* v1.0.0

*Status :* [![Build Status](https://travis-ci.org/GeoffreyFrogeye/PILG.svg?branch=master)](https://travis-ci.org/GeoffreyFrogeye/PILG)

Expand Down
7 changes: 3 additions & 4 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
* Annuler
* Refaire
* Couleur **D**
* Teinte **D**
* Saturation **D**
* Luminosité **D**
* Teinte **C**
* Saturation **C**
* Luminosité **C**
* Contraste
* Dessin **C**
* Trait **C**
Expand All @@ -48,7 +48,6 @@
* Binaire **C**
* Niveaux de gris **C**
* Couleur **C**
* Aide
* Documentation


Expand Down
28 changes: 19 additions & 9 deletions src/affichageFenetre.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

int fenetreDimensionX; // Stocke les dimensions X de la fenêtre
int fenetreDimensionY; // Stocke les dimensions Y de la fenêtre
int ecranX = 1024;
int ecranY = 1080;
bool fenetreOuverte = false;
SDL_Surface *fenetreEcran;
SDL_Surface *fenetreImage;
Expand All @@ -11,16 +13,16 @@ SDL_Surface *fenetreImage;
void definirPixel(SDL_Surface *surface, int x, int y, Uint32 pixel) {
int nbOctetsParPixel = surface->format->BytesPerPixel;
Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * nbOctetsParPixel;

switch (nbOctetsParPixel) {
case 1:
*p = pixel;
break;

case 2:
*(Uint16 *)p = pixel;
break;

case 3:
if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
p[0] = (pixel >> 16) & 0xff;
Expand All @@ -31,16 +33,16 @@ void definirPixel(SDL_Surface *surface, int x, int y, Uint32 pixel) {
p[1] = (pixel >> 8) & 0xff;
p[2] = (pixel >> 16) & 0xff;
}

break;

case 4:
*(Uint32 *)p = pixel;
break;
}
}

void setNomFenetre(std::string nom) { // Change le nom de la fenêtre
void s_nomFenetre(std::string nom) { // Change le nom de la fenêtre
SDL_WM_SetCaption(nom.c_str(), NULL);
}

Expand Down Expand Up @@ -68,7 +70,7 @@ void afficherFenetre() {

void attendreFenetre() {
SDL_Event evenement;

do {
SDL_WaitEvent(&evenement);
} while (evenement.type != SDL_QUIT &&
Expand All @@ -93,7 +95,15 @@ void ouvrirFenetre(int dimensionX, int dimensionY,
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);
s_nomFenetre(nom);
SDL_LockSurface(fenetreImage);
fenetreOuverte = true;
}
}

void actualiserDimensionsEcran() {
SDL_Init(SDL_INIT_VIDEO);
const SDL_VideoInfo *info = SDL_GetVideoInfo();
ecranX = info->current_w;
ecranY = info->current_h;
SDL_Quit();
}
65 changes: 41 additions & 24 deletions src/analyserCommande.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,30 +316,43 @@ int executerCommande(Commande commande, Image &image) {
// } else {
// return 2;
// }
// } else if (commande.fonction == "teinte") {
// if (argumentPresent(commande, "v1")) {
// if (teinte(image, image, commande.v1)) {
// return 3;
// }
// } else {
// return 2;
// }
// } else if (commande.fonction == "saturation") {
// if (argumentPresent(commande, "v1")) {
// if (saturation(image, image, commande.v1)) {
// return 3;
// }
// } else {
// return 2;
// }
// } else if (commande.fonction == "luminosite") {
// if (argumentPresent(commande, "v1")) {
// if (luminosite(image, image, commande.v1)) {
// return 3;
// }
// } else {
// return 2;
// }
} else if (commande.fonction == "teinte") {
if (image.g_typeComposantes() == PILG_RVB) {
if (argumentPresent(commande, "v1")) {
if (teinte(image, image, commande.v1)) {
return 3;
}
} else {
return 2;
}
} else {
return 11;
}
} else if (commande.fonction == "saturation") {
if (image.g_typeComposantes() == PILG_RVB) {
if (argumentPresent(commande, "v1")) {
if (saturation(image, image, commande.v1)) {
return 3;
}
} else {
return 2;
}
} else {
return 11;
}
} else if (commande.fonction == "luminosite") {
if (image.g_typeComposantes() == PILG_RVB) {
if (argumentPresent(commande, "v1")) {
if (luminosite(image, image, commande.v1)) {
return 3;
}
} else {
return 2;
}
} else {
return 11;
}

// } else if (commande.fonction == "contraste") {
// if (argumentPresent(commande, "v1")) {
// if (contraste(image, image, commande.v1)) {
Expand Down Expand Up @@ -524,6 +537,10 @@ int procederCommande(vector< string > decoupe, Image &image) {
messageErreur("La composante donnée n'est pas valide");
break;

case 11:
messageErreur("Il est nécessaire d'avoir une image en mode RVB pour executer cette commande");
break;

default:
messageErreur("Impossible d'analyser la commande");
break;
Expand Down
4 changes: 2 additions & 2 deletions src/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

typedef enum {PILG_BIN, PILG_NIV, PILG_RVB} PILG_Comp;

typedef struct Pixel {
typedef struct {
PILG_Comp typeComposantes;
int maxComposante;
int r;
Expand Down Expand Up @@ -30,7 +30,7 @@ class Image {
// Validateurs
bool v_pixel(Pixel pixel) const;
bool v_dimensions(int x, int y) const;

private:
// Variables
int m_dimensionX;
Expand Down
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ int main(int argc, char *args[]) {

code = procederCommande(decoupe, image);
} else {
actualiserDimensionsEcran();
afficherImage(image);
boucleDeCommandes(image);
code = 0;
Expand Down
45 changes: 33 additions & 12 deletions src/testing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ int appliquer(Image &image, string nomFichier, bool ASCII) {
ouvrir(image, "tests/" + nomFichier);
Pixel pixel;
image.g_pixel(image.g_dimensionX() / 2, image.g_dimensionY() / 2, pixel);
// teinte(image, image, 180);
// saturation(image, image, 0.3);
// luminosite(image, image, -0.5);
// trait(image, image, image.g_dimensionX() / 4, image.g_dimensionY() / 4,
// image.g_dimensionX() - image.g_dimensionX() / 4,
// image.g_dimensionY() - image.g_dimensionY() / 4, pixel);
Expand Down Expand Up @@ -147,25 +150,43 @@ int main(int argc, char *args[]) {
#endif
presentation();
cout << "Éxecution des instructions dans testing.cpp." << endl << endl;
#define DIMENSIONS 50
Image image1 = genererRoue(DIMENSIONS * 2, DIMENSIONS, 255);
Image image2 = genererRoue(DIMENSIONS * 2, DIMENSIONS, 255);
// Image image1; // Tester si ça marche
actualiserDimensionsEcran();
#define DIMENSIONS 255
// Image image1 = genererRoue(DIMENSIONS, DIMENSIONS, 255);
Image image1 = imageDefaut();
// Image image = image1.g_vide();
// ouvrir(image1, "tests/PikachuP6.ppm");
// Image image2 = genererRoue(DIMENSIONS * 2, DIMENSIONS, 255);
// afficherImage(image1);
// attendreFenetre();
// Ouvrir fichier
// appliquer(image1, "PikachuP1.pbm", true);
// appliquer(image1, "PikachuP2.pgm", true);
// appliquer(image1, "PikachuP3.ppm", true);
// appliquer(image1, "PikachuP4.pbm", false);
// appliquer(image1, "PikachuP5.pgm", false);
// appliquer(image1, "PikachuP6.ppm", false);
// // Chronomètre
// int tempsDepart = clock();
// journal << "Temps d'execution: " << (float)(clock() - tempsDepart) / 1000000 <<
// "s" << endl;
// // Afficher différentes tailles de fenêtre
// for (int i = 500; i < 1200; i += 10) {
// image1 = genererRoue(i * 2, i, 255);
// afficherImage(image1);
// // attendreFenetre();
// }
// // Roue
// Image image = image1.g_vide();
// for (float i = 0; i < 2 * PI; i += 0.1) {
// pivoter(image1, image, DIMENSIONS/2, DIMENSIONS/2, i);
// afficherImage(image);
// }
// Ouvrir fichier
appliquer(image1, "PikachuP1.pbm", true);
appliquer(image1, "PikachuP2.pgm", true);
appliquer(image1, "PikachuP3.ppm", true);
appliquer(image1, "PikachuP4.pbm", false);
appliquer(image1, "PikachuP5.pgm", false);
appliquer(image1, "PikachuP6.ppm", false);
// // Roue des couleurs
// for (float i = -1; i <= 1; i += 0.01) {
// teinte(image1, image, i);
// afficherImage(image);
// }
// // Neige en dégradé
// for (int i; i < 300; i++) {
// afficherImage(genererBruit(200, 200));
Expand Down Expand Up @@ -202,7 +223,7 @@ int main(int argc, char *args[]) {
// afficherFenetre();
// }
// cout << "Éxecution du programme terminée. Vous pouvez quitter la fenêtre." << endl;
fermerFenetre();
// fermerFenetre();
journal.close();
return 0;
}
59 changes: 47 additions & 12 deletions src/traitementImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,28 +369,63 @@ int importer(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
// for (int x = 0, x = image.g_dimensionX(), x++) {
// for (int y = 0, y = image.g_dimensionY(), y++) {
// rvbVersTsl();
// g_pixel(x, y);
// }
// }
// return 1;
sortie = entree.g_vide();
Pixel pixel;
TSL tsl;

for (int x = 0; x < sortie.g_dimensionX(); x++) {
for (int y = 0; y < sortie.g_dimensionY(); y++) {
entree.g_pixel(x, y, pixel);
rvb2tsl(pixel, tsl);
tsl.t += teinte;
tsl2rvb(tsl, pixel);
sortie.s_pixel(x, y, pixel);
}
}

return 0;
}

int saturation(Image entree, Image &sortie,
float saturation) { // Sature l'image
// Utilisation de la méthode TSL
return 1;
sortie = entree.g_vide();
Pixel pixel;
TSL tsl;

for (int x = 0; x < sortie.g_dimensionX(); x++) {
for (int y = 0; y < sortie.g_dimensionY(); y++) {
entree.g_pixel(x, y, pixel);
rvb2tsl(pixel, tsl);
tsl.s += saturation;
tsl.s = tsl.s > 1 ? 1 : (tsl.s < 0 ? 0 : tsl.s);
tsl2rvb(tsl, pixel);
sortie.s_pixel(x, y, pixel);
}
}

return 0;
}

int luminosite(Image entree, Image &sortie,
float luminosite) { // Augmente la luminosité de l'image
// Utilisation de la méthode TSL
return 1;
sortie = entree.g_vide();
Pixel pixel;
TSL tsl;

for (int x = 0; x < sortie.g_dimensionX(); x++) {
for (int y = 0; y < sortie.g_dimensionY(); y++) {
entree.g_pixel(x, y, pixel);
rvb2tsl(pixel, tsl);
tsl.l += luminosite;
tsl.l = tsl.l > 1 ? 1 : (tsl.l < 0 ? 0 : tsl.l);
tsl2rvb(tsl, pixel);
sortie.s_pixel(x, y, pixel);
}
}

return 0;
}

int contraste(Image entree, Image &sortie,
Expand Down
Loading

0 comments on commit 82a60fc

Please sign in to comment.