Skip to content
Snippets Groups Projects
Commit 0af07d74 authored by poulpe's avatar poulpe
Browse files

[Update] Fix UINT32_MAX value in array data + fix somes warning + change...

[Update] Fix UINT32_MAX value in array data + fix somes warning + change malloc and type from Rivier pgm_read
parent e9ad00de
No related branches found
No related tags found
No related merge requests found
CC = gcc CC = gcc
CFLAGS = -std=gnu11 -Wall -Wextra -Wpedantic -Wwrite-strings -Walloc-zero -Wparentheses CFLAGS = -std=gnu11 -Wall -Wextra -Wpedantic -Wwrite-strings -Walloc-zero -Wparentheses
CFLAGS += -Wlarger-than=100000 -Wmissing-declarations -Wmissing-include-dirs -Wmissing-prototypes -Wformat-overflow=2 -Wunused-parameter CFLAGS += -Wlarger-than=100000 -Wmissing-declarations -Wmissing-include-dirs -Wmissing-prototypes -Wformat-overflow=2 -Wunused-parameter
CFLAGS += -g -pedantic -fsanitize=address -fsanitize=leak -fsanitize=undefined CFLAGS += -g -pedantic -fsanitize=address -fsanitize=leak -fsanitize=undefined -Wdiscarded-qualifiers
LDFLAGS = -lm -lSDL2main -lSDL2_image -lSDL2 -DGRAPHIC_PGM # LDFLAGS = -lm -lSDL2main -lSDL2_image -lSDL2 -DGRAPHIC_PGM #
############# COMMAND HELP ############# ############# COMMAND HELP #############
......
...@@ -145,7 +145,7 @@ struct gfx_context_t *initWindow(int width,int height,char tab[]) ...@@ -145,7 +145,7 @@ struct gfx_context_t *initWindow(int width,int height,char tab[])
return ctxt; return ctxt;
} }
void dessineTab2D(struct gfx_context_t *context ,uint32_t **tab,int width,int height,int lumMax) void dessineTab2D(struct gfx_context_t *context ,int32_t **tab,int width,int height,int lumMax)
{ {
int min = 0; int min = 0;
...@@ -157,17 +157,14 @@ void dessineTab2D(struct gfx_context_t *context ,uint32_t **tab,int width,int he ...@@ -157,17 +157,14 @@ void dessineTab2D(struct gfx_context_t *context ,uint32_t **tab,int width,int he
for (int j = 0; j < height; ++j) for (int j = 0; j < height; ++j)
{ {
px = tab[i][j]; px = tab[i][j];
intensity = (uint32_t)(( px - min)*255) / (255-min); //lumMax intensity = (uint32_t)((px - min)*255) / ((lumMax)-min); //lumMax
color = MAKE_COLOR(intensity,0,0); color = MAKE_COLOR(intensity,intensity,intensity);
gfx_putpixel(context, i, j, color); gfx_putpixel(context, i, j, color);
} }
} }
void waitSpacePress() void waitSpacePress(void)
{ {
while (gfx_keypressed() != SDLK_ESCAPE) while (gfx_keypressed() != SDLK_ESCAPE) {}
{
}
} }
...@@ -36,12 +36,12 @@ extern void gfx_clear(struct gfx_context_t *ctxt, uint32_t color); ...@@ -36,12 +36,12 @@ extern void gfx_clear(struct gfx_context_t *ctxt, uint32_t color);
extern struct gfx_context_t* gfx_create(char *text, uint width, uint height); extern struct gfx_context_t* gfx_create(char *text, uint width, uint height);
extern void gfx_destroy(struct gfx_context_t *ctxt); extern void gfx_destroy(struct gfx_context_t *ctxt);
extern void gfx_present(struct gfx_context_t *ctxt); extern void gfx_present(struct gfx_context_t *ctxt);
extern SDL_Keycode gfx_keypressed(); extern SDL_Keycode gfx_keypressed(void);
void drawCarrer(struct gfx_context_t *context,int posX,int posY,int carrer); void drawCarrer(struct gfx_context_t *context,int posX,int posY,int carrer);
void drawGraph(struct gfx_context_t *context,int *tab,int size); void drawGraph(struct gfx_context_t *context,int *tab,int size);
struct gfx_context_t *initWindow(int width,int height,char tab[]); struct gfx_context_t *initWindow(int width,int height,char tab[]);
void dessineTab2D(struct gfx_context_t *context ,uint32_t **tab,int width,int height,int lumMax); void dessineTab2D(struct gfx_context_t *context ,int32_t **tab,int width,int height,int lumMax);
void waitSpacePress(); void waitSpacePress(void);
#endif #endif
...@@ -9,8 +9,9 @@ ...@@ -9,8 +9,9 @@
#include "gfx.h" #include "gfx.h"
void write_error_graphic_file(const char *filename, const uint32_t size_n[],const double error_n[],const uint32_t length_data); void write_error_graphic_file(const char *filename, const uint32_t size_n[],const double error_n[],const uint32_t length_data);
void Integration_numerique(); void Integration_numerique(void);
void Convolution_filtrage(); void Convolution_filtrage(void);
void write_error_graphic_file(const char *filename, const uint32_t size_n[],const double error_n[],const uint32_t length_data) void write_error_graphic_file(const char *filename, const uint32_t size_n[],const double error_n[],const uint32_t length_data)
{ {
...@@ -46,16 +47,23 @@ void Convolution_filtrage() ...@@ -46,16 +47,23 @@ void Convolution_filtrage()
use only : matrix_create & matrix_free use only : matrix_create & matrix_free
*/ */
char *filname = "part3_5.pgm"; char filname[] = "part3_1.pgm";
char output_image[] = "out.pgm";
char output_convolve[] = "convolve.pgm";
pgm img; pgm img;
if (pgm_read_from_file(&img, filname) != ok) if (pgm_read_from_file(&img, filname) != ok)
{ {
printf("Impossible de lire l'image shouaitée\n"); printf("Impossible de lire l'image shouaitée\n");
return uninitialized; return;
} }
// Value get from read_from_file return UINT32_MAX FIX with malloc in 'traitementPGM.c'
printf("Value : %u\n",img.pixels.pM[1][1]);
PrintImagePGM(img, filname); PrintImagePGM(img, filname);
pgm_write_to_file(&img,"out.pgm"); pgm_write_to_file(&img,output_image);
matrix kernel = matrix_creat(3,3); matrix kernel = matrix_creat(3,3);
int tab []= {1,1,1,1,1,1,1,1,1}; int tab []= {1,1,1,1,1,1,1,1,1};
...@@ -68,9 +76,10 @@ void Convolution_filtrage() ...@@ -68,9 +76,10 @@ void Convolution_filtrage()
convolve_matrix(&res.pixels,&img.pixels,&kernel,1/(double)9); convolve_matrix(&res.pixels,&img.pixels,&kernel,1/(double)9);
PrintImagePGM(res, filname); PrintImagePGM(res, filname);
pgm_write_to_file(&res,"convolve.pgm"); pgm_write_to_file(&res,output_convolve);
matrix_destroy(&img.pixels); matrix_destroy(&img.pixels);
matrix_destroy(&res.pixels); matrix_destroy(&res.pixels);
...@@ -114,6 +123,4 @@ int main() ...@@ -114,6 +123,4 @@ int main()
Convolution_filtrage(); Convolution_filtrage();
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
\ No newline at end of file
...@@ -117,7 +117,7 @@ matrix* convolve_matrix(matrix* conv,matrix* orig, const matrix *const kernel, c ...@@ -117,7 +117,7 @@ matrix* convolve_matrix(matrix* conv,matrix* orig, const matrix *const kernel, c
//matrix_alloc(conv,orig->col,orig->row); //matrix_alloc(conv,orig->col,orig->row);
// Browse PGM struct orig and create sub matrix but with default value // Browse PGM struct orig and create sub matrix but with default value
uint32_t res = 0; int32_t res = 0;
for (int i = 0; i < orig->col; i += 1) for (int i = 0; i < orig->col; i += 1)
{ {
for (int j = 0; j < orig->row; j += 1) for (int j = 0; j < orig->row; j += 1)
...@@ -135,25 +135,27 @@ matrix* convolve_matrix(matrix* conv,matrix* orig, const matrix *const kernel, c ...@@ -135,25 +135,27 @@ matrix* convolve_matrix(matrix* conv,matrix* orig, const matrix *const kernel, c
} }
else else
{ {
if(base_i == 1 && base_j == 1)
printf("Orig(i:%d,j:%d) : %u\n",base_i,base_j,orig->data[base_i][base_j]);
tmp.data[k][l] = orig->data[base_i][base_j]; tmp.data[k][l] = orig->data[base_i][base_j];
} }
} }
} }
uint32_t tm, ker; // uint32_t tm, ker;
// Use matrix tmp with sub matrix // Use matrix tmp with sub matrix
for (int k = 0; k < tmp.col; k += 1) for (int k = 0; k < tmp.col; k += 1)
{ {
for (int l = 0; l < tmp.row; l += 1) for (int l = 0; l < tmp.row; l += 1)
{ {
tm = tmp.data[k][l]; // tm = tmp.data[k][l];
ker = kernel->data[k][l]; // ker = kernel->data[k][l];
res += tm * ker; res += tmp.data[k][l] * kernel->data[k][l];
} }
} }
//printf("Res(before) : %d / %lf\n",res,factor); //printf("Res(before) : %d / %lf\n",res,factor);
res = (double)res * factor; // Divide by factor of kernel res *= factor; // Divide by factor of kernel
//printf("Res(after) : %d\n",res); //printf("Res(after) : %d\n",res);
if(res > 65535) if(res > 65535)
......
...@@ -370,5 +370,7 @@ error_code matrix_setValue(matrix *mat, int value) ...@@ -370,5 +370,7 @@ error_code matrix_setValue(matrix *mat, int value)
} }
} }
return ok;
} }
\ No newline at end of file
...@@ -62,17 +62,18 @@ error_code pgm_read_from_file(pgm *p, char *filename) ...@@ -62,17 +62,18 @@ error_code pgm_read_from_file(pgm *p, char *filename)
p->pixels.pM = NULL; p->pixels.pM = NULL;
// Créer une liste contenant le fichier pgm // Créer une liste contenant le fichier pgm
__u_char *filechar = malloc(y * x * sizeof(__int32_t)); uint8_t *filechar = malloc(y * x * sizeof(int8_t));
__int32_t *fileint = malloc(y * x * sizeof(__int32_t)); int32_t *fileint = malloc(y * x * sizeof(int32_t));
__int16_t *fileint16 = malloc(y * x * sizeof(__int32_t)); uint16_t *fileint16 = malloc(y * x * sizeof(uint16_t));
//fread(filechar, sizeof(__u_char), y * x, fp); //fread(filechar, sizeof(__u_char), y * x, fp);
fread(fileint16, sizeof(__int16_t), y * x, fp); fread(fileint16, sizeof(uint16_t), y * x, fp);
// Cast les valleurs char en int32 compris par la matrix // Cast les valleurs char en int32 compris par la matrix
for (int i = 0; i < y * x; i++) for (int i = 0; i < y * x; i++)
{ {
fileint[i] = (__int32_t)fileint16[i]; fileint[i] = fileint16[i];
//printf("%d ",fileint[i]); //printf("%d ",fileint[i]);
} }
......
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