#include #include #include typedef int *ROW; void readFile(char *filename, ROW **image, int *nrows, int *ncols) { FILE *infile; char *line= NULL; ssize_t read; size_t len=0; int i; int row, col; int maxpix; ROW onerow; if ((infile= fopen(filename, "r"))==NULL) { printf("Could not open file\n"); exit(0); } for(i=0; i< 2; i++) { read = getline(&line, &len, infile); printf("%s", line); } fscanf(infile, "%d %d %d", &(*ncols), &(*nrows), &maxpix); printf("Ncols=%d Nrows=%d, Max pixel val=%d\n", *ncols, *nrows, maxpix); (*image) = (ROW *)malloc((*nrows)*sizeof(ROW)); for(i=0; i < *nrows; i++) { (*image)[i] = (int *)malloc((*ncols) * sizeof(int)); } for(row=0;row<(*nrows); row++) { for(col=0;col<(*ncols); col++) { fscanf(infile, "%d",&(*image)[row][col]); } } fclose(infile); } void writeFile(char *filename, ROW *image, int nrows, int ncols) { FILE *outfile; int row,col; outfile=fopen(filename, "w"); fprintf(outfile, "P2\n#Test PGM file\n%d %d\n255\n", ncols, nrows); for(row=0;row0) && (col>0)) { a = image[row-1][col-1]; b = image[row-1][col]; //etc... } // dx = ??; // dy = ??; // (*temp)[row][col] = (int)floor(sqrt(???))); } } for(col=0; col