Advertisement
LilChicha174

Untitled

Apr 22nd, 2022
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.95 KB | None | 0 0
  1. int main(int argc, char **argv) {
  2.     struct Png image;
  3.     int index = 0, key;
  4.     int x0 = 0, y0 = 0, x1 = 0, y1 = 0, x2 = 0, y2 = 0, line_fat = 0, flag = 0;
  5.     int Red = 0, Green = 0, Blue = 0;
  6.     int x_photos = 1, y_photos = 1;
  7.     char* output = argv[1];
  8.  
  9.     read_png_file(argv[1], &image);
  10.     int width_pixel = process_file(&image);
  11.  
  12.     const struct option firstCordStruct = {"first", required_argument, NULL, 'f'};
  13.     const struct option secondCordStruct = {"second", required_argument, NULL, 's'};
  14.     const struct option thirdCordStruct = {"third", required_argument, NULL, 't'};
  15.     const struct option fatLineStruct = {"line", required_argument, NULL, 'l'};
  16.     const struct option castStruct = {"cast", required_argument, NULL, 'c'};
  17.     const struct option xPhotosStruct = {"xPhoto", required_argument, NULL, 'x'};
  18.     const struct option yPhotosStruct = {"yPhoto", required_argument, NULL, 'y'};
  19.     const struct option colorStruct = {"color", required_argument, NULL, 'C'};
  20.     const struct option outputStruct = {"output", required_argument, NULL, 'o'};
  21.  
  22.     opterr = 0;
  23.     if(argc == 1 || !strcmp(argv[2], "help")){
  24.         printHelp();
  25.         return 0;
  26.     }else if(!strcmp(argv[2], "info")){
  27.         print_info(&image);
  28.         return 0;
  29.     }else if(!strcmp(argv[2], "triangle")) {
  30.         struct option options[] = {firstCordStruct, secondCordStruct, thirdCordStruct, fatLineStruct,
  31.                 castStruct, colorStruct, outputStruct};
  32.         while((key = getopt_long(argc, argv, "f:s:t:l:c:C:o:", options, &index)) != -1) {
  33.             choice("triangle", key, &x0, &y0, &x1, &y1, &x2, &y2, &line_fat,
  34.                    &flag, &output, &Red, &Green, &Blue, 0, 0);
  35.         }
  36.         print_triangle(&image, width_pixel, x0, y0, x1, y1, x2, y2, line_fat, flag, Red, Green, Blue);
  37.         write_png_file(output, &image);
  38.     }else if(!strcmp(argv[2], "line")) {
  39.         struct option options[] = {firstCordStruct, secondCordStruct, fatLineStruct, colorStruct,
  40.                                     outputStruct};
  41.         while((key = getopt_long(argc, argv, "f:s:l:C:o:", options, &index)) != -1) {
  42.             choice("line", key, &x0, &y0, &x1, &y1, 0, 0,  &line_fat,
  43.                    0, &output, &Red, &Green, &Blue, 0, 0);
  44.         }
  45.         paint_line(&image, width_pixel, x0, y0, x1, y1, line_fat, Red, Green, Blue);
  46.         write_png_file(output, &image);
  47.     }else if(!strcmp(argv[2], "collage")) {
  48.         struct option options[] = {xPhotosStruct, yPhotosStruct, outputStruct};
  49.         while((key = getopt_long(argc, argv, "x:y:o:", options, &index)) != -1) {
  50.             choice("collage", key, 0, 0, 0, 0, 0, 0,  0,
  51.                    0, &output, 0, 0, 0, &x_photos, &y_photos);
  52.         }
  53.         make_collage(&image, width_pixel, x_photos, y_photos);
  54.         write_png_file(output, &image);
  55.     }
  56.  
  57.     for (int y = 0; y < image.height; y++)
  58.         free(image.row_pointers[y]);
  59.     free(image.row_pointers);
  60.  
  61.     return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement