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

fix fix lib sdl2

parent 3859f251
No related branches found
No related tags found
No related merge requests found
CC=gcc -O3 -Wall -Wextra -pedantic -fsanitize=address -fsanitize=leak -lm CC=gcc -O3 -Wall -Wextra -pedantic -fsanitize=address -fsanitize=leak -lm
all : exec
exec: matrix.o pgm.o gfx.o main.o exec: matrix.o pgm.o gfx.o main.o
$(CC) $^ -o $@ -lSDL2 -g -pedantic $(CC) $^ -o $@ -lSDL2 -g -pedantic
......
#include "gfx.h" #include "gfx.h"
#include "pgm.h" #include "pgm.h"
static void 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 //Modification de la fonction dans l'exemple d'utilisation de la lib pour intégrer pgm
gfx_clear(context, COLOR_BLACK);
uint32_t intensity; uint32_t intensity;
uint32_t color; uint32_t color;
gfx_clear(context, COLOR_BLACK);
for (int i = 0; i < orig->pixels.m; i++) for (int i = 0; i < orig->pixels.m; i++)
{ {
for (int j = 0; j < orig->pixels.n; j++) for (int j = 0; j < orig->pixels.n; j++)
{ {
intensity = orig->max; intensity = orig->pixels.data[i][j];
color = MAKE_COLOR(intensity,intensity,intensity); color = MAKE_COLOR(intensity,intensity,intensity);
gfx_putpixel(context, i, j, color); gfx_putpixel(context, j, i, color);
} }
} }
return success;
} }
int main(){ int main(){
...@@ -25,19 +29,6 @@ int main(){ ...@@ -25,19 +29,6 @@ int main(){
pgm_read_from_file(&p, "./img/mandrill.pgm"); pgm_read_from_file(&p, "./img/mandrill.pgm");
pgm_write_to_file(&p, "./img/mandrill2.pgm"); pgm_write_to_file(&p, "./img/mandrill2.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;
}
while (gfx_keypressed() != SDLK_ESCAPE) {
renderPgm(ctxt, &p);
gfx_present(ctxt);
}
gfx_destroy(ctxt);
pgm ph; pgm ph;
pgm_photomaton(&ph,&p); pgm_photomaton(&ph,&p);
...@@ -77,6 +68,20 @@ int main(){ ...@@ -77,6 +68,20 @@ int main(){
pgm_crop(&crop, &p, 100, 200, 100, 200); pgm_crop(&crop, &p, 100, 200, 100, 200);
pgm_write_to_file(&crop, "./img/crop_mandrill.pgm"); 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);
while (gfx_keypressed() != SDLK_ESCAPE) {
}
gfx_destroy(ctxt);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment