int main(int argc, char **argv) { struct PPM *ppm, *a; printf("Reading \"%s\"\n", argc > 1 ? argv[1] : "test.ppm"); ppm = PPM_read(argc > 1 ? argv[1] : "test.ppm"); if (ppm) { printf("read successful\n"); } else { printf("read failed\n"); } a = PPM_dup(ppm); PPM_free(ppm); PPM_write(a, "a.ppm"); PPM_free(a); return 0; }
int main(int argc, char **argv) { struct PPM *ppm, *ppm_result; char *mask; float *bounds; struct E2D *e_field; float *pot_list; int obj_num; int iter_max; int i; if (argc <= 1) { printf("useage:\n\t%s <PPM-File>\n", argv[0]); return 0; } printf("Loading Image\n"); ppm = PPM_read(argv[1]); if (!ppm) { printf("PPM_read() failed\n"); return 1; } mask = init_mask(ppm->h, ppm->w); bounds = init_bounds(ppm->h, ppm->w); /* Input from stdin */ printf("Input Max Iterations for the (%d x %d) picture: ", ppm->w, ppm->h); if (scanf("%d", &iter_max) == 0) { return 0; } printf("Number of objects: "); if (scanf("%d", &obj_num) == 0) { return 0; } pot_list = (float*) malloc(obj_num * sizeof(float)); printf("Potentials of objects: \n"); for (i = 0; i < obj_num; ++i) { printf("\tObject %d = ", i+1); if (scanf("%f", &pot_list[i]) == 0) { WARNING("Warning: can not read more potentials."); break; } } /* End of Input */ printf("Detecting boundary\n"); ppm_to_boundary(ppm, pot_list, obj_num, mask, bounds); printf("Outputing boundary\n"); ppm_result = render_potential(ppm->h, ppm->w, bounds, PPM_table_gray); PPM_write(ppm_result, "output-boundary-gray.ppm"); PPM_free(ppm_result); printf("Calculating\n"); iteration(ppm->h, ppm->w, mask, bounds, iter_max); printf("Rendering\n"); /* scalar field ø */ ppm_result = render_potential(ppm->h, ppm->w, bounds, PPM_table_gray); PPM_write(ppm_result, "output-Phi-gray.ppm"); PPM_free(ppm_result); ppm_result = render_potential(ppm->h, ppm->w, bounds, PPM_table_hue); overlap(ppm_result, ppm); PPM_write(ppm_result, "output-Phi-hue.ppm"); PPM_free(ppm_result); /* END scalar field ø */ /* E² = |grad ø|^2 */ e_field = potential_to_E(ppm->h, ppm->w, bounds); ppm_result = render_E(ppm->h, ppm->w, e_field, PPM_table_gray); PPM_write(ppm_result, "output-E-Field-gray.ppm"); PPM_free(ppm_result); ppm_result = render_E(ppm->h, ppm->w, e_field, PPM_table_hue); overlap(ppm_result, ppm); PPM_write(ppm_result, "output-E-Field-hue.ppm"); PPM_free(ppm_result); free(e_field); /* END E² */ ppm_result = draw_e_lines(ppm->h, ppm->w, mask, bounds, COLOR_RED); overlap(ppm_result, ppm); PPM_write(ppm_result, "output-E-Lines.ppm"); PPM_free(ppm_result); free(pot_list); free(mask); free(bounds); PPM_free(ppm); return 0; }
/* main - main program * * Parameters: * argc - number of command line arguments * argv - pointer to command line argument array * * Returns: * none */ void main(int argc, char **argv) { int r_size, c_size; int type; char *infile, *outfile; FILE *readfile, *writefile, *logfile; ICON_S_T icon; COLOR_S_T raster[MAX_R_SIZE][MAX_C_SIZE]; /* handle input args */ if (argc == 1) { infile = INPUT_FILE_NAME; outfile = OUTPUT_FILE_NAME; } else { infile = argv[1]; outfile = argv[2]; } /* read image as icon file */ readfile = fopen(infile, "r"); if (readfile == (FILE *)NULL) { printf("Main: error opening %s to read\n", infile); exit(1); } else { printf("reading icon file ...\n"); LoadIcon( readfile, &icon ); } /* copy icon to PPM */ r_size = icon.size.y; c_size = icon.size.x; CopyIcon2Raster( &icon, r_size, c_size, &raster[0][0] ); /* save image as PPM file */ writefile = fopen(outfile, "w"); if (writefile == (FILE *)NULL) { printf("Main: error opening %s to write\n", outfile); exit(1); } else { printf("writing PPM file ...\n"); PPM_write(writefile, (char *)&raster[0][0], r_size, c_size, "generated by icon2ppm v1.0"); } exit(0); }