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

ajout fonction write to file ok

parent a5d1f0c2
No related branches found
No related tags found
No related merge requests found
File added
......@@ -7,8 +7,8 @@ void foo(int* elem){
int main(){
matrix m;
pgm p;
pmg_read_from_file(&p, "./img/mandrill.pgm");
pmg_write_to_file(&p, "./img/mandrill2.pgm");
pmg_read_from_file(&p, "./img/mandrill.pgm");
}
\ No newline at end of file
......@@ -48,3 +48,32 @@ pgm_error pmg_read_from_file(pgm *p, char *filename)
return success;
}
pgm_error pmg_write_to_file(pgm *p, char *filename){
FILE *f = fopen(filename, "w");
if (NULL == f)
{
fprintf(stderr, "Can't open output file %s!\n",
filename); // affiche dans le canal d'erreur
exit(0);
}
//Ecrit le type de fichier a la première ligne
fprintf(f, "P5\n");
fprintf(f, "%d %d\n", p->pixels.m, p->pixels.n);
int32_t elem;
for (int i = 0; i < p->pixels.m; i++) {
for (int j = 0; j < p->pixels.n; j++)
{
if(matrix_get(&elem, p->pixels, i, j) != OK){
return failure;
};
fwrite(&elem, sizeof(uint8_t), 1, f);
}
}
fprintf(f, "%d %d\n", p->pixels.m, p->pixels.n);
fclose(f);
return success;
}
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