/* * Copyright 2018 Pedro Melgueira * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #include "macros.h" #include "sobel.h" #include "file_operations.h" #define ARGS_NEEDED 3 int ascii_to_hex(char c) { int num = (int) c; if(num < 58 && num > 47) { return num - 48; } if(num < 103 && num > 96) { return num - 87; } return num; } int main(int argc, char *argv[]) { char *file_out, *file_out_h, *file_out_v, *file_gray; byte *rgb, *gray, *sobel_h_res, *sobel_v_res, *contour_img0; int rgb_size, width, height; int inter_files = 0, gray_file = 0; // Get arguments if(argc < ARGS_NEEDED) { printf("Usage: TODO\n"); return 1; } // File names file_out = argv[1]; // Get size of input image char *width_token = strtok(argv[2], "x"); if(width_token) { width = atoi(width_token); } else { printf("Bad image size argument\n"); return 1; } char *height_token = strtok(NULL, "x"); if(height_token) { height = atoi(height_token); } else { printf("Bad image size argument\n"); return 1; } rgb_size = width*height*3; // Get optional arguments int arg_index = ARGS_NEEDED; while(arg_index < argc) { // If there is a flag to create intermediate files if(strcmp(argv[arg_index], "-i") == 0) { if(arg_index+3 > argc) { printf("Usage: TODO\n"); return 1; } inter_files = 1; file_out_h = argv[arg_index+1]; file_out_v = argv[arg_index+2]; arg_index += 3; } else if(strcmp(argv[arg_index], "-g") == 0) { if(arg_index+2 > argc) { printf("Usage: TODO\n"); return 1; } gray_file = 1; file_gray = argv[arg_index+1]; arg_index += 2; } else { printf("Argument \"%s\", is unknown.\n", argv[arg_index]); return 1; } } // Read file to rgb and get size byte contour[128][128]; // Allocate memory for buffer byte **contour_img = &contour_img0; *contour_img = malloc(sizeof(byte) * 128 * 128); FILE *finp; byte someArr[128][128]; int ctr = 0; finp = fopen("out.txt", "r"); if(NULL == finp) { printf("Unable to open file\n"); exit(-1); } // Read every char of file ONE BY ONE (not the whole thing at once) // We do this because this should look closer to the assembly implementation for(int chunk=0; chunk<64; chunk++) { int ioffset = (chunk/8)*16; int joffset = (chunk%8)*16; long long int read_val; byte first, second, third, fourth; for (int i=ioffset; i