|
|
@@ -7,260 +7,83 @@ |
|
|
|
|
|
|
|
#include <pipi.h> |
|
|
|
|
|
|
|
static const char * aliases[] = |
|
|
|
{ |
|
|
|
"-o", "--save", |
|
|
|
"--output", "--save", |
|
|
|
NULL, NULL, |
|
|
|
}; |
|
|
|
|
|
|
|
static pipi_command_t const *list; |
|
|
|
|
|
|
|
int main(int argc, char *argv[]) |
|
|
|
{ |
|
|
|
pipi_context_t *ctx; |
|
|
|
|
|
|
|
ctx = pipi_create_context(); |
|
|
|
list = pipi_get_command_list(); |
|
|
|
|
|
|
|
while(*++argv) |
|
|
|
{ |
|
|
|
if(!strcmp(argv[0], "--dup")) |
|
|
|
{ |
|
|
|
if(pipi_command(ctx, "dup") != 0) |
|
|
|
return EXIT_FAILURE; |
|
|
|
} |
|
|
|
else if(!strcmp(argv[0], "--swap")) |
|
|
|
{ |
|
|
|
if(pipi_command(ctx, "swap") != 0) |
|
|
|
return EXIT_FAILURE; |
|
|
|
} |
|
|
|
else if(!strcmp(argv[0], "--roll")) |
|
|
|
{ |
|
|
|
if(argv[1] == NULL) |
|
|
|
return EXIT_FAILURE; |
|
|
|
if(pipi_command(ctx, "roll", argv[1]) != 0) |
|
|
|
return EXIT_FAILURE; |
|
|
|
argv++; |
|
|
|
} |
|
|
|
else if(!strcmp(argv[0], "--gamma")) |
|
|
|
{ |
|
|
|
if(argv[1] == NULL) |
|
|
|
return EXIT_FAILURE; |
|
|
|
if(pipi_command(ctx, "gamma", argv[1]) != 0) |
|
|
|
return EXIT_FAILURE; |
|
|
|
argv++; |
|
|
|
} |
|
|
|
else if(!strcmp(argv[0], "--scale")) |
|
|
|
{ |
|
|
|
if(argv[1] == NULL) |
|
|
|
return EXIT_FAILURE; |
|
|
|
if(pipi_command(ctx, "scale", argv[1]) != 0) |
|
|
|
return EXIT_FAILURE; |
|
|
|
argv++; |
|
|
|
} |
|
|
|
else if(!strcmp(argv[0], "--geometry")) |
|
|
|
{ |
|
|
|
if(argv[1] == NULL) |
|
|
|
return EXIT_FAILURE; |
|
|
|
if(pipi_command(ctx, "geometry", argv[1]) != 0) |
|
|
|
return EXIT_FAILURE; |
|
|
|
argv++; |
|
|
|
} |
|
|
|
else if(!strcmp(argv[0], "--tile")) |
|
|
|
{ |
|
|
|
if(argv[1] == NULL) |
|
|
|
return EXIT_FAILURE; |
|
|
|
if(pipi_command(ctx, "tile", argv[1]) != 0) |
|
|
|
return EXIT_FAILURE; |
|
|
|
argv++; |
|
|
|
} |
|
|
|
else if(!strcmp(argv[0], "--dither")) |
|
|
|
{ |
|
|
|
if(argv[1] == NULL) |
|
|
|
return EXIT_FAILURE; |
|
|
|
if(pipi_command(ctx, "dither", argv[1]) != 0) |
|
|
|
return EXIT_FAILURE; |
|
|
|
argv++; |
|
|
|
} |
|
|
|
else if(!strcmp(argv[0], "--blur")) |
|
|
|
{ |
|
|
|
if(argv[1] == NULL) |
|
|
|
return EXIT_FAILURE; |
|
|
|
if(pipi_command(ctx, "blur", argv[1]) != 0) |
|
|
|
return EXIT_FAILURE; |
|
|
|
argv++; |
|
|
|
} |
|
|
|
else if(!strcmp(argv[0], "--boxblur")) |
|
|
|
{ |
|
|
|
if(argv[1] == NULL) |
|
|
|
return EXIT_FAILURE; |
|
|
|
if(pipi_command(ctx, "boxblur", argv[1]) != 0) |
|
|
|
return EXIT_FAILURE; |
|
|
|
argv++; |
|
|
|
} |
|
|
|
else if(!strcmp(argv[0], "--median")) |
|
|
|
{ |
|
|
|
if(argv[1] == NULL) |
|
|
|
return EXIT_FAILURE; |
|
|
|
if(pipi_command(ctx, "median", argv[1]) != 0) |
|
|
|
return EXIT_FAILURE; |
|
|
|
argv++; |
|
|
|
} |
|
|
|
else if(!strcmp(argv[0], "--gray")) |
|
|
|
{ |
|
|
|
if(pipi_command(ctx, "gray") != 0) |
|
|
|
return EXIT_FAILURE; |
|
|
|
} |
|
|
|
else if(!strcmp(argv[0], "--brightness")) |
|
|
|
{ |
|
|
|
if(argv[1] == NULL) |
|
|
|
return EXIT_FAILURE; |
|
|
|
if(pipi_command(ctx, "brightness", argv[1]) != 0) |
|
|
|
return EXIT_FAILURE; |
|
|
|
argv++; |
|
|
|
} |
|
|
|
else if(!strcmp(argv[0], "--contrast")) |
|
|
|
{ |
|
|
|
if(argv[1] == NULL) |
|
|
|
return EXIT_FAILURE; |
|
|
|
if(pipi_command(ctx, "contrast", argv[1]) != 0) |
|
|
|
return EXIT_FAILURE; |
|
|
|
argv++; |
|
|
|
} |
|
|
|
else if(!strcmp(argv[0], "--autocontrast")) |
|
|
|
{ |
|
|
|
if(pipi_command(ctx, "autocontrast") != 0) |
|
|
|
return EXIT_FAILURE; |
|
|
|
} |
|
|
|
else if(!strcmp(argv[0], "--order")) |
|
|
|
{ |
|
|
|
if(pipi_command(ctx, "order") != 0) |
|
|
|
return EXIT_FAILURE; |
|
|
|
} |
|
|
|
else if(!strcmp(argv[0], "--hflip")) |
|
|
|
{ |
|
|
|
if(pipi_command(ctx, "hflip") != 0) |
|
|
|
return EXIT_FAILURE; |
|
|
|
} |
|
|
|
else if(!strcmp(argv[0], "--vflip")) |
|
|
|
{ |
|
|
|
if(pipi_command(ctx, "vflip") != 0) |
|
|
|
return EXIT_FAILURE; |
|
|
|
} |
|
|
|
else if(!strcmp(argv[0], "--rotate90")) |
|
|
|
{ |
|
|
|
if(pipi_command(ctx, "rotate90") != 0) |
|
|
|
return EXIT_FAILURE; |
|
|
|
} |
|
|
|
else if(!strcmp(argv[0], "--rotate180")) |
|
|
|
{ |
|
|
|
if(pipi_command(ctx, "rotate180") != 0) |
|
|
|
return EXIT_FAILURE; |
|
|
|
} |
|
|
|
else if(!strcmp(argv[0], "--rotate270")) |
|
|
|
{ |
|
|
|
if(pipi_command(ctx, "rotate270") != 0) |
|
|
|
return EXIT_FAILURE; |
|
|
|
} |
|
|
|
else if(!strcmp(argv[0], "--invert")) |
|
|
|
{ |
|
|
|
if(pipi_command(ctx, "invert") != 0) |
|
|
|
return EXIT_FAILURE; |
|
|
|
} |
|
|
|
else if(!strcmp(argv[0], "--threshold")) |
|
|
|
{ |
|
|
|
if(argv[1] == NULL) |
|
|
|
return EXIT_FAILURE; |
|
|
|
if(pipi_command(ctx, "threshold", argv[1]) != 0) |
|
|
|
return EXIT_FAILURE; |
|
|
|
argv++; |
|
|
|
} |
|
|
|
else if(!strcmp(argv[0], "--dilate")) |
|
|
|
{ |
|
|
|
if(pipi_command(ctx, "dilate") != 0) |
|
|
|
return EXIT_FAILURE; |
|
|
|
} |
|
|
|
else if(!strcmp(argv[0], "--erode")) |
|
|
|
{ |
|
|
|
if(pipi_command(ctx, "erode") != 0) |
|
|
|
return EXIT_FAILURE; |
|
|
|
} |
|
|
|
else if(!strcmp(argv[0], "--wrap")) |
|
|
|
{ |
|
|
|
if(pipi_command(ctx, "wrap") != 0) |
|
|
|
return EXIT_FAILURE; |
|
|
|
} |
|
|
|
else if(!strcmp(argv[0], "--combine")) |
|
|
|
{ |
|
|
|
if(pipi_command(ctx, "combine") != 0) |
|
|
|
return EXIT_FAILURE; |
|
|
|
} |
|
|
|
else if(!strcmp(argv[0], "--split")) |
|
|
|
{ |
|
|
|
if(pipi_command(ctx, "split") != 0) |
|
|
|
return EXIT_FAILURE; |
|
|
|
} |
|
|
|
else if(!strcmp(argv[0], "--mean")) |
|
|
|
{ |
|
|
|
if(pipi_command(ctx, "mean") != 0) |
|
|
|
return EXIT_FAILURE; |
|
|
|
} |
|
|
|
else if(!strcmp(argv[0], "--min")) |
|
|
|
{ |
|
|
|
if(pipi_command(ctx, "min") != 0) |
|
|
|
return EXIT_FAILURE; |
|
|
|
} |
|
|
|
else if(!strcmp(argv[0], "--max")) |
|
|
|
{ |
|
|
|
if(pipi_command(ctx, "max") != 0) |
|
|
|
return EXIT_FAILURE; |
|
|
|
} |
|
|
|
else if(!strcmp(argv[0], "--add")) |
|
|
|
{ |
|
|
|
if(pipi_command(ctx, "add") != 0) |
|
|
|
return EXIT_FAILURE; |
|
|
|
} |
|
|
|
else if(!strcmp(argv[0], "--sub")) |
|
|
|
{ |
|
|
|
if(pipi_command(ctx, "sub") != 0) |
|
|
|
return EXIT_FAILURE; |
|
|
|
} |
|
|
|
else if(!strcmp(argv[0], "--difference")) |
|
|
|
{ |
|
|
|
if(pipi_command(ctx, "difference") != 0) |
|
|
|
return EXIT_FAILURE; |
|
|
|
} |
|
|
|
else if(!strcmp(argv[0], "--multiply")) |
|
|
|
{ |
|
|
|
if(pipi_command(ctx, "multiply") != 0) |
|
|
|
return EXIT_FAILURE; |
|
|
|
} |
|
|
|
else if(!strcmp(argv[0], "--divide")) |
|
|
|
{ |
|
|
|
if(pipi_command(ctx, "divide") != 0) |
|
|
|
return EXIT_FAILURE; |
|
|
|
} |
|
|
|
else if(!strcmp(argv[0], "--screen")) |
|
|
|
{ |
|
|
|
if(pipi_command(ctx, "screen") != 0) |
|
|
|
return EXIT_FAILURE; |
|
|
|
} |
|
|
|
else if(!strcmp(argv[0], "--overlay")) |
|
|
|
{ |
|
|
|
if(pipi_command(ctx, "overlay") != 0) |
|
|
|
return EXIT_FAILURE; |
|
|
|
} |
|
|
|
else if(!strcmp(argv[0], "--line")) |
|
|
|
{ |
|
|
|
if(argv[6] == NULL) |
|
|
|
return EXIT_FAILURE; |
|
|
|
if(pipi_command(ctx, "line", argv[1]) != 0) |
|
|
|
return EXIT_FAILURE; |
|
|
|
argv++; |
|
|
|
} |
|
|
|
else if(!strcmp(argv[0], "--output") || !strcmp(argv[0], "-o")) |
|
|
|
pipi_command_t const *cmd; |
|
|
|
char const * const *flag; |
|
|
|
char const * arg; |
|
|
|
int i; |
|
|
|
|
|
|
|
arg = argv[0]; |
|
|
|
for(flag = aliases; flag[0]; flag += 2) |
|
|
|
if(!strcmp(arg, flag[0])) |
|
|
|
arg = flag[1]; |
|
|
|
|
|
|
|
if(!strncmp(arg, "--", 2)) |
|
|
|
{ |
|
|
|
if(argv[1] == NULL) |
|
|
|
return EXIT_FAILURE; |
|
|
|
if(pipi_command(ctx, "save", argv[1]) != 0) |
|
|
|
for(cmd = list; cmd->name; cmd++) |
|
|
|
if(!strcmp(arg + 2, cmd->name)) |
|
|
|
break; |
|
|
|
|
|
|
|
if(!cmd->name) |
|
|
|
{ |
|
|
|
fprintf(stderr, "unknown command %s\n", argv[0]); |
|
|
|
return EXIT_FAILURE; |
|
|
|
argv++; |
|
|
|
} |
|
|
|
|
|
|
|
for(i = 1; i <= cmd->argc; i++) |
|
|
|
if(argv[i] == NULL) |
|
|
|
{ |
|
|
|
fprintf(stderr, "too few arguments for %s\n", argv[0]); |
|
|
|
return EXIT_FAILURE; |
|
|
|
} |
|
|
|
|
|
|
|
switch(cmd->argc) |
|
|
|
{ |
|
|
|
case 0: |
|
|
|
if(pipi_command(ctx, cmd->name) != 0) |
|
|
|
{ |
|
|
|
fprintf(stderr, "command %s failed\n", argv[0]); |
|
|
|
return EXIT_FAILURE; |
|
|
|
} |
|
|
|
break; |
|
|
|
case 1: |
|
|
|
if(pipi_command(ctx, cmd->name, argv[1]) != 0) |
|
|
|
{ |
|
|
|
fprintf(stderr, "command %s failed\n", argv[0]); |
|
|
|
return EXIT_FAILURE; |
|
|
|
} |
|
|
|
break; |
|
|
|
default: |
|
|
|
/* Can’t handle that argument count */ |
|
|
|
return EXIT_FAILURE; |
|
|
|
} |
|
|
|
|
|
|
|
argv += cmd->argc; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
if(pipi_command(ctx, "load", argv[0]) != 0) |
|
|
|
if(pipi_command(ctx, "load", arg) != 0) |
|
|
|
{ |
|
|
|
fprintf(stderr, "could not load `%s'\n", argv[0]); |
|
|
|
return EXIT_FAILURE; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|