int main (int argc, char *argv[] ) { assert(argc<=2); FILE *input; if (argc == 2) { input = fopen( argv[1], "rb"); if (!input) { perror(argv[1]); exit(1); } } else { input = stdin; } Bit2_T bitmap = pbmread(input); assert(bitmap); if (input != stdin) { fclose(input); } int w_pixels = Bit2_width(bitmap); int h_pixels = Bit2_height(bitmap); // call unblack on every edge pixel for (int i = 0; i < w_pixels; i++) { // top + bottom edge, +4 corners unblack(bitmap, i, 0); unblack(bitmap, i, h_pixels-1); } for (int j = 0; j < h_pixels; j++) { // left + right edge, no corners unblack(bitmap, 0, j); unblack(bitmap, w_pixels-1, j); } pbmwrite(bitmap); assert(bitmap); Bit2_free(&bitmap); return 0; }
int main(int argc, char *argv[]) { (void)argc; (void)argv; Bit2_T test_array; bool OK = true; int x; test_array = Bit2_new(DIM1, DIM2); OK &= (Bit2_width(test_array) == DIM1); OK &= (Bit2_height(test_array) == DIM2); // Bit2_put(test_array, 0, 0, 1); // printf("(0, 0) = %d\n", Bit2_get(test_array, 0, 0)); // printf("(0, 1) = %d\n", Bit2_get(test_array, 1, 0)); /* Note: we are only setting a value on the corner of the array */ Bit2_put(test_array, DIM1-1, DIM2-1, MARKER); OK &= (Bit2_get(test_array, DIM1-1, DIM2-1) == MARKER); x = Bit2_put(test_array, DIM1-1, DIM2-1, 0); OK &= (x == MARKER); /* hint: put returns previous value */ Bit2_put(test_array, DIM1-1, DIM2-1, MARKER); /* for map test */ printf("Trying column major\n"); Bit2_map_col_major(test_array, check_and_print, &OK); printf("Trying row major\n"); Bit2_map_row_major(test_array, check_and_print, &OK); Bit2_free(&test_array); printf("The array is %sOK!\n", (OK ? "" : "NOT ")); }