|
- /*
- * libpipi Proper image processing implementation library
- * Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org>
- * All Rights Reserved
- *
- * $Id$
- *
- * This library is free software. It comes without any warranty, to
- * the extent permitted by applicable law. You can redistribute it
- * and/or modify it under the terms of the Do What The Fuck You Want
- * To Public License, Version 2, as published by Sam Hocevar. See
- * http://sam.zoy.org/wtfpl/COPYING for more details.
- */
-
- /*
- * context.c: processing stack handling routines
- */
-
- #include "config.h"
- #include "common.h"
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdarg.h>
- #include <string.h>
-
- #include "pipi.h"
- #include "pipi_internals.h"
-
- pipi_context_t *pipi_create_context()
- {
- pipi_context_t *ret;
-
- ret = malloc(sizeof(pipi_context_t));
- memset(ret, 0, sizeof(pipi_context_t));
-
- return ret;
- }
-
- void pipi_destroy_context(pipi_context_t *ctx)
- {
- free(ctx);
- }
-
- int pipi_command(pipi_context_t *ctx, char const *cmd, ...)
- {
- if(!strcmp(cmd, "load"))
- {
- char const *file;
- va_list ap;
-
- va_start(ap, cmd);
- file = va_arg(ap, char const *);
- va_end(ap);
- ctx->images[ctx->nimages] = pipi_load(file);
- if(ctx->images[ctx->nimages] == NULL)
- return -1;
- ctx->nimages++;
- }
- else if(!strcmp(cmd, "save"))
- {
- char const *file;
- va_list ap;
-
- if(ctx->nimages <= 0)
- return -1;
- ctx->nimages--;
- va_start(ap, cmd);
- file = va_arg(ap, char const *);
- va_end(ap);
- pipi_save(ctx->images[ctx->nimages], file);
- pipi_free(ctx->images[ctx->nimages]);
- }
- else if(!strcmp(cmd, "free"))
- {
- if(ctx->nimages <= 0)
- return -1;
- ctx->nimages--;
- pipi_free(ctx->images[ctx->nimages]);
- }
- else if(!strcmp(cmd, "dup"))
- {
- if(ctx->nimages <= 0)
- return -1;
- ctx->images[ctx->nimages] = pipi_copy(ctx->images[ctx->nimages - 1]);
- ctx->nimages++;
- }
- else
- {
- return -1;
- }
-
- return 0;
- }
|