1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| void WriteP5Char(char *fName, int scale, int ligne, int col,
MAT_I dArray)
{
FILE *OUT;
int i,j;
int c;
if ( (OUT = fopen(fName, "wb")) == NULL) {
fprintf(stderr,"Failed when writing file '%s'.\n", fName);
return;
}
printf("Writing '%s' ..... ", fName);
fflush(stdout);
fprintf(OUT,"P5\n");
fprintf(OUT,"%d %d\n%d\n",col,ligne,255);
for (i=0; i<ligne; i++) {
for (j=0; j< col; j++) {
c = dArray[i][j] * scale;
if (c > 255) c = 255;
if (c < 0) c = 0;
putc(c, OUT);
}
}
fclose(OUT);
printf(" DONE.\n");
return;
}
int Write_An_Image_Int(IMAGEINT *animage, int scale, char *name)
{
WriteP5Char(name, scale, animage->nligne, animage->ncol, animage->data);
return 0;
} |
Partager