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

Commit 82a60fc

Browse files
[v1.0.0] Teinte, Saturation, Luminosité
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
1 parent 386ff0b commit 82a60fc

File tree

9 files changed

+264
-122
lines changed

9 files changed

+264
-122
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Nos noms complets et le nom du lycée sont masqués pour des raisons d'intimité
1212
###Le programme
1313
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.
1414

15-
*Version :* Alpha
15+
*Version :* v1.0.0
1616

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

TODO.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
* Annuler
3131
* Refaire
3232
* Couleur **D**
33-
* Teinte **D**
34-
* Saturation **D**
35-
* Luminosité **D**
33+
* Teinte **C**
34+
* Saturation **C**
35+
* Luminosité **C**
3636
* Contraste
3737
* Dessin **C**
3838
* Trait **C**
@@ -48,7 +48,6 @@
4848
* Binaire **C**
4949
* Niveaux de gris **C**
5050
* Couleur **C**
51-
* Aide
5251
* Documentation
5352

5453

src/affichageFenetre.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
int fenetreDimensionX; // Stocke les dimensions X de la fenêtre
55
int fenetreDimensionY; // Stocke les dimensions Y de la fenêtre
6+
int ecranX = 1024;
7+
int ecranY = 1080;
68
bool fenetreOuverte = false;
79
SDL_Surface *fenetreEcran;
810
SDL_Surface *fenetreImage;
@@ -11,16 +13,16 @@ SDL_Surface *fenetreImage;
1113
void definirPixel(SDL_Surface *surface, int x, int y, Uint32 pixel) {
1214
int nbOctetsParPixel = surface->format->BytesPerPixel;
1315
Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * nbOctetsParPixel;
14-
16+
1517
switch (nbOctetsParPixel) {
1618
case 1:
1719
*p = pixel;
1820
break;
19-
21+
2022
case 2:
2123
*(Uint16 *)p = pixel;
2224
break;
23-
25+
2426
case 3:
2527
if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
2628
p[0] = (pixel >> 16) & 0xff;
@@ -31,16 +33,16 @@ void definirPixel(SDL_Surface *surface, int x, int y, Uint32 pixel) {
3133
p[1] = (pixel >> 8) & 0xff;
3234
p[2] = (pixel >> 16) & 0xff;
3335
}
34-
36+
3537
break;
36-
38+
3739
case 4:
3840
*(Uint32 *)p = pixel;
3941
break;
4042
}
4143
}
4244

43-
void setNomFenetre(std::string nom) { // Change le nom de la fenêtre
45+
void s_nomFenetre(std::string nom) { // Change le nom de la fenêtre
4446
SDL_WM_SetCaption(nom.c_str(), NULL);
4547
}
4648

@@ -68,7 +70,7 @@ void afficherFenetre() {
6870

6971
void attendreFenetre() {
7072
SDL_Event evenement;
71-
73+
7274
do {
7375
SDL_WaitEvent(&evenement);
7476
} while (evenement.type != SDL_QUIT &&
@@ -93,7 +95,15 @@ void ouvrirFenetre(int dimensionX, int dimensionY,
9395
fenetreImage = SDL_CreateRGBSurface(SDL_HWSURFACE, fenetreDimensionX,
9496
fenetreDimensionY, 32, 0, 0, 0, 0);
9597
SDL_FillRect(fenetreImage, NULL, SDL_MapRGB(fenetreEcran->format, 0, 0, 0));
96-
setNomFenetre(nom);
98+
s_nomFenetre(nom);
9799
SDL_LockSurface(fenetreImage);
98100
fenetreOuverte = true;
99-
}
101+
}
102+
103+
void actualiserDimensionsEcran() {
104+
SDL_Init(SDL_INIT_VIDEO);
105+
const SDL_VideoInfo *info = SDL_GetVideoInfo();
106+
ecranX = info->current_w;
107+
ecranY = info->current_h;
108+
SDL_Quit();
109+
}

src/analyserCommande.cpp

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -316,30 +316,43 @@ int executerCommande(Commande commande, Image &image) {
316316
// } else {
317317
// return 2;
318318
// }
319-
// } else if (commande.fonction == "teinte") {
320-
// if (argumentPresent(commande, "v1")) {
321-
// if (teinte(image, image, commande.v1)) {
322-
// return 3;
323-
// }
324-
// } else {
325-
// return 2;
326-
// }
327-
// } else if (commande.fonction == "saturation") {
328-
// if (argumentPresent(commande, "v1")) {
329-
// if (saturation(image, image, commande.v1)) {
330-
// return 3;
331-
// }
332-
// } else {
333-
// return 2;
334-
// }
335-
// } else if (commande.fonction == "luminosite") {
336-
// if (argumentPresent(commande, "v1")) {
337-
// if (luminosite(image, image, commande.v1)) {
338-
// return 3;
339-
// }
340-
// } else {
341-
// return 2;
342-
// }
319+
} else if (commande.fonction == "teinte") {
320+
if (image.g_typeComposantes() == PILG_RVB) {
321+
if (argumentPresent(commande, "v1")) {
322+
if (teinte(image, image, commande.v1)) {
323+
return 3;
324+
}
325+
} else {
326+
return 2;
327+
}
328+
} else {
329+
return 11;
330+
}
331+
} else if (commande.fonction == "saturation") {
332+
if (image.g_typeComposantes() == PILG_RVB) {
333+
if (argumentPresent(commande, "v1")) {
334+
if (saturation(image, image, commande.v1)) {
335+
return 3;
336+
}
337+
} else {
338+
return 2;
339+
}
340+
} else {
341+
return 11;
342+
}
343+
} else if (commande.fonction == "luminosite") {
344+
if (image.g_typeComposantes() == PILG_RVB) {
345+
if (argumentPresent(commande, "v1")) {
346+
if (luminosite(image, image, commande.v1)) {
347+
return 3;
348+
}
349+
} else {
350+
return 2;
351+
}
352+
} else {
353+
return 11;
354+
}
355+
343356
// } else if (commande.fonction == "contraste") {
344357
// if (argumentPresent(commande, "v1")) {
345358
// if (contraste(image, image, commande.v1)) {
@@ -524,6 +537,10 @@ int procederCommande(vector< string > decoupe, Image &image) {
524537
messageErreur("La composante donnée n'est pas valide");
525538
break;
526539

540+
case 11:
541+
messageErreur("Il est nécessaire d'avoir une image en mode RVB pour executer cette commande");
542+
break;
543+
527544
default:
528545
messageErreur("Impossible d'analyser la commande");
529546
break;

src/image.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
typedef enum {PILG_BIN, PILG_NIV, PILG_RVB} PILG_Comp;
44

5-
typedef struct Pixel {
5+
typedef struct {
66
PILG_Comp typeComposantes;
77
int maxComposante;
88
int r;
@@ -30,7 +30,7 @@ class Image {
3030
// Validateurs
3131
bool v_pixel(Pixel pixel) const;
3232
bool v_dimensions(int x, int y) const;
33-
33+
3434
private:
3535
// Variables
3636
int m_dimensionX;

src/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ int main(int argc, char *args[]) {
2727

2828
code = procederCommande(decoupe, image);
2929
} else {
30+
actualiserDimensionsEcran();
3031
afficherImage(image);
3132
boucleDeCommandes(image);
3233
code = 0;

src/testing.cpp

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ int appliquer(Image &image, string nomFichier, bool ASCII) {
120120
ouvrir(image, "tests/" + nomFichier);
121121
Pixel pixel;
122122
image.g_pixel(image.g_dimensionX() / 2, image.g_dimensionY() / 2, pixel);
123+
// teinte(image, image, 180);
124+
// saturation(image, image, 0.3);
125+
// luminosite(image, image, -0.5);
123126
// trait(image, image, image.g_dimensionX() / 4, image.g_dimensionY() / 4,
124127
// image.g_dimensionX() - image.g_dimensionX() / 4,
125128
// image.g_dimensionY() - image.g_dimensionY() / 4, pixel);
@@ -147,25 +150,43 @@ int main(int argc, char *args[]) {
147150
#endif
148151
presentation();
149152
cout << "Éxecution des instructions dans testing.cpp." << endl << endl;
150-
#define DIMENSIONS 50
151-
Image image1 = genererRoue(DIMENSIONS * 2, DIMENSIONS, 255);
152-
Image image2 = genererRoue(DIMENSIONS * 2, DIMENSIONS, 255);
153-
// Image image1; // Tester si ça marche
153+
actualiserDimensionsEcran();
154+
#define DIMENSIONS 255
155+
// Image image1 = genererRoue(DIMENSIONS, DIMENSIONS, 255);
156+
Image image1 = imageDefaut();
157+
// Image image = image1.g_vide();
158+
// ouvrir(image1, "tests/PikachuP6.ppm");
159+
// Image image2 = genererRoue(DIMENSIONS * 2, DIMENSIONS, 255);
154160
// afficherImage(image1);
155161
// attendreFenetre();
162+
// Ouvrir fichier
163+
// appliquer(image1, "PikachuP1.pbm", true);
164+
// appliquer(image1, "PikachuP2.pgm", true);
165+
// appliquer(image1, "PikachuP3.ppm", true);
166+
// appliquer(image1, "PikachuP4.pbm", false);
167+
// appliquer(image1, "PikachuP5.pgm", false);
168+
// appliquer(image1, "PikachuP6.ppm", false);
169+
// // Chronomètre
170+
// int tempsDepart = clock();
171+
// journal << "Temps d'execution: " << (float)(clock() - tempsDepart) / 1000000 <<
172+
// "s" << endl;
173+
// // Afficher différentes tailles de fenêtre
174+
// for (int i = 500; i < 1200; i += 10) {
175+
// image1 = genererRoue(i * 2, i, 255);
176+
// afficherImage(image1);
177+
// // attendreFenetre();
178+
// }
156179
// // Roue
157180
// Image image = image1.g_vide();
158181
// for (float i = 0; i < 2 * PI; i += 0.1) {
159182
// pivoter(image1, image, DIMENSIONS/2, DIMENSIONS/2, i);
160183
// afficherImage(image);
161184
// }
162-
// Ouvrir fichier
163-
appliquer(image1, "PikachuP1.pbm", true);
164-
appliquer(image1, "PikachuP2.pgm", true);
165-
appliquer(image1, "PikachuP3.ppm", true);
166-
appliquer(image1, "PikachuP4.pbm", false);
167-
appliquer(image1, "PikachuP5.pgm", false);
168-
appliquer(image1, "PikachuP6.ppm", false);
185+
// // Roue des couleurs
186+
// for (float i = -1; i <= 1; i += 0.01) {
187+
// teinte(image1, image, i);
188+
// afficherImage(image);
189+
// }
169190
// // Neige en dégradé
170191
// for (int i; i < 300; i++) {
171192
// afficherImage(genererBruit(200, 200));
@@ -202,7 +223,7 @@ int main(int argc, char *args[]) {
202223
// afficherFenetre();
203224
// }
204225
// cout << "Éxecution du programme terminée. Vous pouvez quitter la fenêtre." << endl;
205-
fermerFenetre();
226+
// fermerFenetre();
206227
journal.close();
207228
return 0;
208229
}

src/traitementImage.cpp

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -369,28 +369,63 @@ int importer(Image entree, Image &sortie, string nomFichier, int x, int y) {
369369

370370
// Couleur
371371

372-
373372
int teinte(Image entree, Image &sortie,
374373
float teinte) { // Change la teinte de l'image
375-
// for (int x = 0, x = image.g_dimensionX(), x++) {
376-
// for (int y = 0, y = image.g_dimensionY(), y++) {
377-
// rvbVersTsl();
378-
// g_pixel(x, y);
379-
// }
380-
// }
381-
// return 1;
374+
sortie = entree.g_vide();
375+
Pixel pixel;
376+
TSL tsl;
377+
378+
for (int x = 0; x < sortie.g_dimensionX(); x++) {
379+
for (int y = 0; y < sortie.g_dimensionY(); y++) {
380+
entree.g_pixel(x, y, pixel);
381+
rvb2tsl(pixel, tsl);
382+
tsl.t += teinte;
383+
tsl2rvb(tsl, pixel);
384+
sortie.s_pixel(x, y, pixel);
385+
}
386+
}
387+
388+
return 0;
382389
}
383390

384391
int saturation(Image entree, Image &sortie,
385392
float saturation) { // Sature l'image
386-
// Utilisation de la méthode TSL
387-
return 1;
393+
sortie = entree.g_vide();
394+
Pixel pixel;
395+
TSL tsl;
396+
397+
for (int x = 0; x < sortie.g_dimensionX(); x++) {
398+
for (int y = 0; y < sortie.g_dimensionY(); y++) {
399+
entree.g_pixel(x, y, pixel);
400+
rvb2tsl(pixel, tsl);
401+
tsl.s += saturation;
402+
tsl.s = tsl.s > 1 ? 1 : (tsl.s < 0 ? 0 : tsl.s);
403+
tsl2rvb(tsl, pixel);
404+
sortie.s_pixel(x, y, pixel);
405+
}
406+
}
407+
408+
return 0;
388409
}
389410

390411
int luminosite(Image entree, Image &sortie,
391412
float luminosite) { // Augmente la luminosité de l'image
392-
// Utilisation de la méthode TSL
393-
return 1;
413+
sortie = entree.g_vide();
414+
Pixel pixel;
415+
TSL tsl;
416+
417+
for (int x = 0; x < sortie.g_dimensionX(); x++) {
418+
for (int y = 0; y < sortie.g_dimensionY(); y++) {
419+
entree.g_pixel(x, y, pixel);
420+
rvb2tsl(pixel, tsl);
421+
tsl.l += luminosite;
422+
tsl.l = tsl.l > 1 ? 1 : (tsl.l < 0 ? 0 : tsl.l);
423+
tsl2rvb(tsl, pixel);
424+
sortie.s_pixel(x, y, pixel);
425+
}
426+
}
427+
428+
return 0;
394429
}
395430

396431
int contraste(Image entree, Image &sortie,

0 commit comments

Comments
 (0)