int main(uint16_t argc, char_t *argv[]) { char_t name1[80], name2[80], name3[80]; uint32_t bits_per_pixel, length, width; sint16_t **image1, **image2; uint16_t max; errFlag = eReturnOK; /****************************************** * * Interpret the command line parameters. * *******************************************/ if(image1 == NULL) { errFlag = eImage1Null; } if(image2 == NULL) { errFlag = eImage2Null; } if(argc != 5){ printf( "\n" "\n usage: mainas in1-file in2-file " "out_file add-subtract" "\n" "\n recall add-subtract a=add s=subtract\n"); errFlag = eNotStuffArg; } if(errFlag == eReturnOK) { strcpy(name1, argv[1]); strcpy(name2, argv[2]); strcpy(name3, argv[3]); if(does_not_exist(name1)){ printf("\nERROR input file %s does not exist", name1); errFlag = eNotExistName1; } if(errFlag == eReturnOK) { if(does_not_exist(name2)){ printf("\nERROR input file %s does not exist", name2); errFlag = eNotExistName2; } if(errFlag == eReturnOK) { /****************************************** * * Ensure the two input images have the * same sizes. * *******************************************/ if(are_not_same_size(name1, name2)){ printf( "\nERROR Image files %s and %s are not same size", name1, name2); errFlag = eNotSameSize; } if(errFlag == eReturnOK) { /****************************************** * * Allocate the two image arrays * *******************************************/ get_image_size(name1, &length, &width); get_bitsperpixel(name1, &bits_per_pixel); image1 = allocate_image_array(length, width); image2 = allocate_image_array(length, width); /****************************************** * * Create the output file and read the * two input images. * *******************************************/ create_image_file(name1, name3); read_image_array(name1, image1); read_image_array(name2, image2); /******************************************** * * Add or subtract the input images and * write the result to the output image. * ********************************************/ if(argv[4][0] == 'a' || argv[4][0] == 'A'){ if(bits_per_pixel == 4) max = 16; else max = 255; add_image_array(image1, image2, length, width, max); } /* ends if add */ if(argv[4][0] == 's' || argv[4][0] == 'S') subtract_image_array(image1, image2, length, width); write_image_array(name3, image2); free_image_array(image1, length); free_image_array(image2, length); }//eNotSameSize }//eNotExistName }//eNotExistName1 }/*eNotStuffArg*/ return errFlag; } /* ends main */
int main(int32_t argc, char_t *argv[]) { errFlag = eReturnOK; char_t name1[80], name2[80], name3[80], type[80]; int32_t count, i, j; uint32_t length, width; /********************************************* * * Interpret the command line parameters. * **********************************************/ if(argc < 5) { printf( "\n\nNot enough parameters:" "\n" "\n usage: mainover in-file1 in-file2 out-file " "type" "\n" "\n recall type: nonzero zero greater less" " average" "\n the input images must be the same size" "\n" "\n"); errFlag = eNotSuffArg; } if(errFlag == eReturnOK) { strcpy(name1, argv[ARGV_ARGUMENT1]); strcpy(name2, argv[ARGV_ARGUMENT2]); strcpy(name3, argv[ARGV_ARGUMENT3]); strcpy(type, argv[ARGV_ARGUMENT4]); if(does_not_exist(name1)) { printf("\nERROR input file %s does not exist", name1); errFlag = eNotInputFile1; } if(errFlag == eReturnOK) { if(does_not_exist(name2)) { printf("\nERROR input file %s does not exist", name2); errFlag = eNotInputFile2; } /********************************************* * * Read the input image headers. * Ensure the input image are the same size. * Allocate the image arrays and read * the image data. * **********************************************/ if(errFlag == eReturnOK) { if(are_not_same_size(name1, name2)) { printf("\n Images %s and %s are not the same size", name1, name2); errFlag = eNotSameSize; } /* ends if sizes not the same */ if(errFlag == eReturnOK) { get_image_size(name1, &length, &width); the_image = allocate_image_array(length, width); out_image = allocate_image_array(length, width); create_image_file(name1, name3); read_image_array(name1, the_image); read_image_array(name2, out_image); /********************************************* * * Apply the desired overlay function. * **********************************************/ /* non-zero */ if(strncmp("non", type, 3) == 0) { non_zero_overlay(the_image, out_image, length, width); } /* ends non_zero operation */ /* zero */ if(strcmp("zero", type) == 0) { zero_overlay(the_image, out_image, length, width); } /* ends zero operation */ /* greater */ if(strncmp("gre", type, 3) == 0) { greater_overlay(the_image, out_image, length, width); } /* ends greater operation */ /* less */ if(strncmp("les", type, 3) == 0) { less_overlay(the_image, out_image, length, width); } /* ends less operation */ /* average */ if(strncmp("ave", type, 3) == 0) { average_overlay(the_image, out_image, length, width); } /* ends average operation */ write_image_array(name3, out_image); free_image_array(out_image, length); free_image_array(the_image, length); }}}} return errFlag; } /* ends main */
int main(int32_t argc, char_t *argv[]) { char_t in_name[MAX_NAME_LENGTH]; char_t out_name[MAX_NAME_LENGTH]; char_t *line, buffer[10]; sint16_t i, j; sint32_t height, width; sint16_t **the_image; errors error_flag = NO_ERROR; FILE *out_file; /****************************************** * * Ensure the command line is correct. * ******************************************/ if (argc != PARAM_NUMBER){ printf("\nusage: dumpi input-image output-file"); error_flag = WRONG_NUMBER_OF_PARAMETERS; } else { strcpy(in_name, argv[1]); strcpy(out_name, argv[2]); /****************************************** * * Ensure the input image exists. * Create the output text file. * Allocate an image array. * Read the image and dump the nubmers * to a text file. * ******************************************/ if (does_not_exist(in_name)) { printf("\nERROR input file %s does not exist", in_name); error_flag = IN_FILE_DOES_NOT_EXIST; } /* ends if does_not_exist */ if ((out_file = fopen(out_name, "wt")) == NULL) { printf("\nERROR Could not open file %s", out_name); error_flag = COULD_NOT_OPEN_OUT_FILE; } if (error_flag == NO_ERROR) { if (get_image_size(in_name, &height, &width) != 1) { error_flag = GET_IMAGE_SIZE_ERROR; } else { the_image = allocate_image_array(height, width); read_image_array(in_name, the_image); line = (char_t *) malloc(((width * SIZE_CONST1) + SIZE_CONST2) * sizeof(char_t *)); if ((line == NULL) || (the_image == NULL)) { error_flag = ALLOCATE_IMAGE_ARRAY_ERROR; } else { sprintf(line, " "); for (i = 0; i < width; i++) { sprintf(buffer, "%4d", i); strcat(line, buffer); } strcat(line, "\n"); fputs(line, out_file); for (i = 0; i < height; i++) { sprintf(line, "%5d>", i); for (j = 0; j < width; j++) { sprintf(buffer, "-%3d", the_image[i][j]); strcat(line, buffer); } strcat(line, "\n"); fputs(line, out_file); } } } } free_image_array(the_image, height); fclose(out_file); } return error_flag; } /* ends main */