Skip to content
Snippets Groups Projects
Commit e808e18c authored by jorge.leitemac's avatar jorge.leitemac :juggling_tone5:
Browse files

commentaires et finitions

parent 0c5f1dcc
No related branches found
No related tags found
No related merge requests found
#include "gfx.h"
#include "pgm.h"
pgm_error renderPgm(struct gfx_context_t *context, const pgm *const orig) {
pgm_error renderPgm(struct gfx_context_t *context, const pgm *const orig)
{
//Modification de la fonction dans l'exemple d'utilisation de la lib pour intégrer pgm
uint32_t intensity;
uint32_t color;
gfx_clear(context, COLOR_BLACK);
......@@ -14,7 +15,7 @@ pgm_error renderPgm(struct gfx_context_t *context, const pgm *const orig) {
for (int j = 0; j < orig->pixels.n; j++)
{
intensity = orig->pixels.data[i][j];
color = MAKE_COLOR(intensity,intensity,intensity);
color = MAKE_COLOR(intensity, intensity, intensity);
gfx_putpixel(context, j, i, color);
}
}
......@@ -22,76 +23,75 @@ pgm_error renderPgm(struct gfx_context_t *context, const pgm *const orig) {
return success;
}
int main(){
int boxBlur[] = { 1, 2, 1, 2, 4, 2, 1, 2, 1};
int main()
{
int filtre[] = {1, 2, 1, 2, 4, 2, 1, 2, 1}; //Flou de gaus 3 x 3
int normeFiltre = 16;
pgm p;
pgm_read_from_file(&p, "./img/mandrill.pgm");
pgm_write_to_file(&p, "./img/mandrill2.pgm");
pgm ph;
pgm_photomaton(&ph,&p);
pgm_photomaton(&ph, &p);
pgm_write_to_file(&ph, "./img/photomaton_mandrill.pgm");
//SYM VERTICAL
pgm symV;
pgm_symmetry_vert(&symV, &p);
pgm_write_to_file(&symV, "./img/symV_mandrill.pgm");
//SYM HORIZONTAL
pgm symH;
pgm_symmetry_hori(&symH, &p);
pgm_write_to_file(&symH, "./img/symH_mandrill.pgm");
//SYM VERTICAL
pgm neg;
pgm_negative(&neg, &p);
pgm_write_to_file(&neg, "./img/neg_mandrill.pgm");
//NEGATIF
pgm neg;
pgm_negative(&neg, &p);
pgm_write_to_file(&neg, "./img/neg_mandrill.pgm");
//SYM VERTICAL
pgm symC;
pgm_symmetry_cent(&symC, &p);
pgm_write_to_file(&symC, "./img/symC_mandrill.pgm");
//SYM CENTRAL
pgm symC;
pgm_symmetry_cent(&symC, &p);
pgm_write_to_file(&symC, "./img/symC_mandrill.pgm");
//CONV
matrix kernel;
matrix_init_from_array(&kernel, 3, 3, boxBlur);
matrix_init_from_array(&kernel, 3, 3, filtre);
matrix_print(kernel);
pgm conv;
pgm_conv(&conv, &p, &kernel, 16);
pgm_conv(&conv, &p, &kernel, normeFiltre);
pgm_write_to_file(&conv, "./img/conv_mandrill.pgm");
//SYM CROP
pgm crop;
pgm_crop(&crop, &p, 100, 200, 100, 200);
pgm_write_to_file(&crop, "./img/crop_mandrill.pgm");
int longueur = p.pixels.m;
int hauteur = p.pixels.n;
struct gfx_context_t *ctxt = gfx_create("image", longueur, hauteur);
if (!ctxt) {
fprintf(stderr, "Graphics initialization failed!\n");
return EXIT_FAILURE;
}
renderPgm(ctxt, &p);
gfx_present(ctxt);
//SYM CROP
pgm crop;
pgm_crop(&crop, &p, 100, 200, 100, 200);
pgm_write_to_file(&crop, "./img/crop_mandrill.pgm");
while (gfx_keypressed() != SDLK_ESCAPE) {
}
gfx_destroy(ctxt);
matrix_destroy(&(kernel));
matrix_destroy(&(conv.pixels));
matrix_destroy(&(p.pixels));
matrix_destroy(&(symH.pixels));
matrix_destroy(&(symV.pixels));
matrix_destroy(&(neg.pixels));
matrix_destroy(&(symC.pixels));
matrix_destroy(&(crop.pixels));
matrix_destroy(&(ph.pixels));
//Crée une fenêtre contextuelle
struct gfx_context_t *ctxt = gfx_create("image", p.pixels.n, p.pixels.m);
if (!ctxt)
{
fprintf(stderr, "Graphics initialization failed!\n");
return EXIT_FAILURE;
}
//Crée l'image et l'affiche
renderPgm(ctxt, &crop);
gfx_present(ctxt);
//Stop le programme tant que l'user n'a pas appuyé escape
while (gfx_keypressed() != SDLK_ESCAPE){}
gfx_destroy(ctxt);
matrix_destroy(&(p.pixels));
matrix_destroy(&(ph.pixels));
matrix_destroy(&(symV.pixels));
matrix_destroy(&(symH.pixels));
matrix_destroy(&(neg.pixels));
matrix_destroy(&(symC.pixels));
matrix_destroy(&(kernel));
matrix_destroy(&(conv.pixels));
matrix_destroy(&(crop.pixels));
}
\ No newline at end of file
......@@ -214,10 +214,19 @@ pgm_error pgm_symmetry_cent(pgm *sym, const pgm *const orig){
return success;
}
pgm_error pgm_crop(pgm *crop, const pgm *const orig,int32_t x0, int32_t x1,int32_t y0, int32_t y1){
/**
* @brief Coupe une partie de l'image (à la position x0, x1, y0, y1)
* @param sym pgm résultant
* @param orig image originelle
* @param x0 debut de l'image coupée (en x)
* @param x1 fin de l'image coupée (en x)
* @param y0 debut de l'image coupée (en y)
* @param y1 fin de l'image coupée (en y)
* @return success ou failure en cas d'erreur
*/
pgm_error pgm_crop(pgm *crop, const pgm *const orig,int32_t x0, int32_t x1,int32_t y0, int32_t y1){
crop->max = orig->max;
//Extrait une submatrix de orig et l'affecte à crop
if(matrix_extract_submatrix(&crop->pixels, orig->pixels, x0, x1, y0, y1) != OK){
return failure;
}
......@@ -225,9 +234,13 @@ pgm_error pgm_crop(pgm *crop, const pgm *const orig,int32_t x0, int32_t x1,int32
return success;
}
/**
* @brief Les pixels sont divisés en 4 de manière a quadrupler l'image de départ (en 4x plus petit)
* @param sym pgm résultant
* @param orig image originelle
* @return success ou failure en cas d'erreur
*/
pgm_error pgm_photomaton(pgm *photomaton, const pgm *const orig){
int cpt = 0;
int32_t elem;
int32_t valeurs[orig->pixels.m * orig->pixels.n];
......@@ -257,6 +270,7 @@ pgm_error pgm_photomaton(pgm *photomaton, const pgm *const orig){
}
//Création du pgm
photomaton->max = orig->max;
if(matrix_init_from_array(&photomaton->pixels, orig->pixels.m, orig->pixels.n, valeurs) != OK){
return failure;
......@@ -265,6 +279,14 @@ pgm_error pgm_photomaton(pgm *photomaton, const pgm *const orig){
return success;
}
/**
* @brief Applique une matrice de convolution à un pgm (filtre)
* @param sym pgm résultant
* @param orig image originelle
* @param kernel matrice de convolution
* @param norme norme de la matrice de convultion (diviseur)
* @return success ou failure en cas d'erreur
*/
pgm_error pgm_conv(pgm *conv, const pgm *const orig,const matrix *const kernel, double norm){
conv->max = orig->max;
......@@ -308,7 +330,7 @@ pgm_error pgm_conv(pgm *conv, const pgm *const orig,const matrix *const kernel,
}
moy = moy / norm;
//Vérifie le dépassement de limites
if(moy < 0){
moy = 0;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment