diff --git a/pipi/context.c b/pipi/context.c index e822f1a..e63bc7d 100644 --- a/pipi/context.c +++ b/pipi/context.c @@ -62,7 +62,7 @@ int pipi_command(pipi_context_t *ctx, char const *cmd, ...) char const *file; va_list ap; - if(ctx->nimages <= 0) + if(ctx->nimages < 1) return -1; ctx->nimages--; va_start(ap, cmd); @@ -77,7 +77,7 @@ int pipi_command(pipi_context_t *ctx, char const *cmd, ...) char const *method; va_list ap; - if(ctx->nimages <= 0) + if(ctx->nimages < 1) return -1; va_start(ap, cmd); method = va_arg(ap, char const *); @@ -119,7 +119,7 @@ int pipi_command(pipi_context_t *ctx, char const *cmd, ...) char const *arg; va_list ap; - if(ctx->nimages <= 0) + if(ctx->nimages < 1) return -1; va_start(ap, cmd); arg = va_arg(ap, char const *); @@ -208,14 +208,14 @@ int pipi_command(pipi_context_t *ctx, char const *cmd, ...) } else if(!strcmp(cmd, "wrap")) { - if(ctx->nimages <= 0) + if(ctx->nimages < 1) return -1; ctx->images[ctx->nimages - 1]->wrap = 1; } else if(!strcmp(cmd, "autocontrast")) { pipi_image_t *tmp; - if(ctx->nimages <= 0) + if(ctx->nimages < 1) return -1; tmp = ctx->images[ctx->nimages - 1]; ctx->images[ctx->nimages - 1] = pipi_autocontrast(tmp); @@ -223,24 +223,33 @@ int pipi_command(pipi_context_t *ctx, char const *cmd, ...) } else if(!strcmp(cmd, "gray")) { - if(ctx->nimages <= 0) + if(ctx->nimages < 1) return -1; pipi_getpixels(ctx->images[ctx->nimages - 1], PIPI_PIXELS_Y_F); } else if(!strcmp(cmd, "free")) { - if(ctx->nimages <= 0) + if(ctx->nimages < 1) return -1; ctx->nimages--; pipi_free(ctx->images[ctx->nimages]); } else if(!strcmp(cmd, "dup")) { - if(ctx->nimages <= 0) + if(ctx->nimages < 1) return -1; ctx->images[ctx->nimages] = pipi_copy(ctx->images[ctx->nimages - 1]); ctx->nimages++; } + else if(!strcmp(cmd, "swap")) + { + pipi_image_t *tmp; + if(ctx->nimages < 2) + return -1; + tmp = ctx->images[ctx->nimages - 1]; + ctx->images[ctx->nimages - 1] = ctx->images[ctx->nimages - 2]; + ctx->images[ctx->nimages - 2] = tmp; + } else { return -1; diff --git a/src/pipi.c b/src/pipi.c index d2463dd..28095db 100644 --- a/src/pipi.c +++ b/src/pipi.c @@ -20,6 +20,11 @@ int main(int argc, char *argv[]) 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], "--dither")) { if(argv[1] == NULL)