Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void printHelp(){
- printf("Это программа с CLI для редактирования png файлов, версия программы 0.0001 :)\n");
- printf("Поддерживаются только файлы с глубиной цвета RGB!\n");
- printf("Формат ввода: ./bmpedit [имя исходного файла] [функция] -[ключ1]/--[полный ключ1] [аргумент1] ...\n\n");
- printf("Функции/ключи:\n");
- printf("triangle [имя файла] - рисование треугольника с возможностью его залить и выбрать цвет.\n");
- printf(" -f/--first [<x-координата>.<y-координата>] - первая вершина треугольника\n");
- printf(" -s/--second [<x-координата>.<y-координата>] - вторая вершина треугольника\n");
- printf(" -t/--third [<x-координата>.<y-координата>] - третья вершина треугольника\n");
- printf(" -l/--line [<число>] - толщина сторон треугольника(в пикселях)\n");
- printf(" -C/--color [<число>.<число>.<число>] - цвет заливки и треугольника (RGB)\n");
- printf(" -с/--cast [<число>] - заливка треугольника (по умолчанию без заливки) (1 - заливка, 0 - нет)\n");
- printf("line [имя файла] - рисование прямой линии.\n");
- printf(" -f/--first [<x-координата>.<y-координата>] - начало линии\n");
- printf(" -s/--second [<x-координата>.<y-координата>] - конец линии\n");
- printf(" -l/--line [<число>] - толщина линии(в пикселях)\n");
- printf(" -C/--color [<число>.<число>.<число>] - цвет линии (RGB)\n");
- printf("collage [имя файла] - создается коллаж из изображения.\n");
- printf(" -x/--xPhoto [<число>] - количество изображений по оси X\n");
- printf(" -y/--yPhoto [<число>] - количество изображений по оси Y\n");
- printf("help - вывод справки о работе программы.\n");
- printf("[имя файла] info - вывод информации об изображении.\n");
- printf("-o/--output [путь] - файл для вывода (по умолчанию исходный файл)\n");
- }
- void choice(char* func, int key, int* x0, int* y0, int* x1, int* y1, int* x2, int* y2, int* line_fat,
- int* cast, char** output, int* Red, int* Green, int* Blue, int* x_photos, int* y_photos){
- int i = 0;
- switch (key) {
- case 'f':
- *x0 = atoi(optarg);
- while(optarg[i] != '.'){
- i++;
- }
- *y0 = atoi(&optarg[i+1]);
- break;
- case 's':
- *x1 = atoi(optarg);
- while(optarg[i] != '.'){
- i++;
- }
- *y1 = atoi(&optarg[i+1]);
- break;
- case 't':
- *x2 = atoi(optarg);
- while(optarg[i] != '.'){
- i++;
- }
- *y2 = atoi(&optarg[i+1]);
- break;
- case 'l':
- *line_fat = atoi(optarg);
- break;
- case 'c':
- *cast = atoi(optarg);
- break;
- case 'C':
- *Red = atoi(optarg);
- while(optarg[i] != '.'){
- i++;
- }
- *Green = atoi(&optarg[i+1]);
- while(optarg[i] != '.'){
- i++;
- }
- *Blue = atoi(&optarg[i+1]);
- break;
- case 'x':
- *x_photos = atoi(optarg);
- break;
- case 'y':
- *y_photos = atoi(optarg);
- break;
- case 'o':
- *output = optarg;
- break;
- default:
- printf("Нет такого ключа для %s!\n", func);
- exit(-1);
- }
- }
- int main(int argc, char **argv) {
- struct Png image;
- int index = 0, key;
- int x0 = 0, y0 = 0, x1 = 0, y1 = 0, x2 = 0, y2 = 0, line_fat = 0, flag = 0;
- int Red = 0, Green = 0, Blue = 0;
- int x_photos = 1, y_photos = 1;
- char* output = argv[1];
- read_png_file(argv[1], &image);
- int width_pixel = process_file(&image);
- const struct option firstCordStruct = {"first", required_argument, NULL, 'f'};
- const struct option secondCordStruct = {"second", required_argument, NULL, 's'};
- const struct option thirdCordStruct = {"third", required_argument, NULL, 't'};
- const struct option fatLineStruct = {"line", required_argument, NULL, 'l'};
- const struct option castStruct = {"cast", required_argument, NULL, 'c'};
- const struct option xPhotosStruct = {"xPhoto", required_argument, NULL, 'x'};
- const struct option yPhotosStruct = {"yPhoto", required_argument, NULL, 'y'};
- const struct option colorStruct = {"color", required_argument, NULL, 'C'};
- const struct option outputStruct = {"output", required_argument, NULL, 'o'};
- opterr = 0;
- if(argc == 1 || !strcmp(argv[2], "help")){
- printHelp();
- return 0;
- }else if(!strcmp(argv[2], "info")){
- print_info(&image);
- return 0;
- }else if(!strcmp(argv[2], "triangle")) {
- struct option options[] = {firstCordStruct, secondCordStruct, thirdCordStruct, fatLineStruct,
- castStruct, colorStruct, outputStruct};
- while((key = getopt_long(argc, argv, "f:s:t:l:c:C:o:", options, &index)) != -1) {
- choice("triangle", key, &x0, &y0, &x1, &y1, &x2, &y2, &line_fat,
- &flag, &output, &Red, &Green, &Blue, 0, 0);
- }
- print_triangle(&image, width_pixel, x0, y0, x1, y1, x2, y2, line_fat, flag, Red, Green, Blue);
- write_png_file(output, &image);
- }else if(!strcmp(argv[2], "line")) {
- struct option options[] = {firstCordStruct, secondCordStruct, fatLineStruct, colorStruct,
- outputStruct};
- while((key = getopt_long(argc, argv, "f:s:l:C:o:", options, &index)) != -1) {
- choice("line", key, &x0, &y0, &x1, &y1, 0, 0, &line_fat,
- 0, &output, &Red, &Green, &Blue, 0, 0);
- }
- paint_line(&image, width_pixel, x0, y0, x1, y1, line_fat, Red, Green, Blue);
- write_png_file(output, &image);
- }else if(!strcmp(argv[2], "collage")) {
- struct option options[] = {xPhotosStruct, yPhotosStruct, outputStruct};
- while((key = getopt_long(argc, argv, "x:y:o:", options, &index)) != -1) {
- choice("collage", key, 0, 0, 0, 0, 0, 0, 0,
- 0, &output, 0, 0, 0, &x_photos, &y_photos);
- }
- make_collage(&image, width_pixel, x_photos, y_photos);
- write_png_file(output, &image);
- }
- for (int y = 0; y < image.height; y++)
- free(image.row_pointers[y]);
- free(image.row_pointers);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement