J'ai un programme qui fonctionne sur les images PGM. Je dois le refaire pour qu'il fonctionne aussi sur les images PPM. J'utilise maintenant une table dynamiquement allouée pour stocker l'image en mémoire. Le problème est que cela fonctionne bien sur les images PGM, mais PPM sont coupés en deux. Input&output Que se passe-t-il? Ce sont des endroits que je pense se méfient:C - PGM et PPM - table allouée dynamiquement, image coupée en deux
Voici comment je crée la table:
obraz->piksele=(int**)malloc(obraz->wymy*sizeof(int *));
for(i=0; i<obraz->wymy; i++)
{
obraz->piksele[i]=(int*)malloc(obraz->wymx*sizeof(int));
}
for (i=0;i<obraz->wymy;i++) {
for (j=0;j<obraz->wymx;j++) {
fscanf(plik_we,"%d",&(obraz->piksele[i][j]));
}
}
}
return obraz->wymx*obraz->wymy;
}
Voici comment enregistrer un nouveau fichier:
int zapisz(FILE *plik_wy,TObraz *obraz)
{
int i,j;
if(obraz->format==2)
fprintf(plik_wy,"P2\n");
else
fprintf(plik_wy,"P3\n");
fprintf(plik_wy,"%d %d\n",obraz->wymx,obraz->wymy);
fprintf(plik_wy,"%d\n",obraz->szarosci);
for(i=0;i<obraz->wymy;i++)
{
for(j=0;j<obraz->wymx;j++)
{
fprintf(plik_wy,"%d ",obraz->piksele[i][j]);
if(j>1 && j%15==0)
fprintf(plik_wy,"\n");
}
}
return 0;
}
également la structure de TObraz:
typedef struct
{
int **piksele;
int format;
int wymx;
int wymy;
int szarosci;
} TObraz;