From 0f3943d0fefef658de4aea761689e9eabc33e460 Mon Sep 17 00:00:00 2001 From: sam Date: Mon, 11 Aug 2008 00:50:55 +0000 Subject: [PATCH] * Add functions that handle a stack-based processing queue. git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2692 92316355-f0b4-4df1-b90c-862c8a59935f --- pipi/Makefile.am | 1 + pipi/context.c | 95 +++++++++++++++++++++++++++++++++++++++++++ pipi/pipi.h | 7 ++++ pipi/pipi_internals.h | 6 +++ 4 files changed, 109 insertions(+) create mode 100644 pipi/context.c diff --git a/pipi/Makefile.am b/pipi/Makefile.am index 5ac4571..d98ac6f 100644 --- a/pipi/Makefile.am +++ b/pipi/Makefile.am @@ -16,6 +16,7 @@ libpipi_la_SOURCES = \ pipi.c \ pipi.h \ pipi_internals.h \ + context.c \ pixels.c \ codec.c \ resize.c \ diff --git a/pipi/context.c b/pipi/context.c new file mode 100644 index 0000000..bb43848 --- /dev/null +++ b/pipi/context.c @@ -0,0 +1,95 @@ +/* + * libpipi Proper image processing implementation library + * Copyright (c) 2004-2008 Sam Hocevar + * 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 +#include +#include +#include + +#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; +} + diff --git a/pipi/pipi.h b/pipi/pipi.h index fec1bad..30bb7a9 100644 --- a/pipi/pipi.h +++ b/pipi/pipi.h @@ -63,6 +63,13 @@ pipi_pixels_t; /* pipi_image_t: the main image type */ typedef struct pipi_image pipi_image_t; +/* pipi_context_t: the processing stack */ +typedef struct pipi_context pipi_context_t; + + +extern pipi_context_t *pipi_create_context(void); +extern void pipi_destroy_context(pipi_context_t *); +extern int pipi_command(pipi_context_t *, char const *, ...); extern pipi_image_t *pipi_load(const char *); extern pipi_image_t *pipi_new(int, int); diff --git a/pipi/pipi_internals.h b/pipi/pipi_internals.h index f5165d1..40afdf8 100644 --- a/pipi/pipi_internals.h +++ b/pipi/pipi_internals.h @@ -34,6 +34,12 @@ struct pipi_image void *codec_priv; }; +struct pipi_context +{ + int nimages; + pipi_image_t *images[1024]; /* FIXME: do dynamic allocation */ +}; + #ifdef USE_IMLIB2 pipi_image_t *pipi_load_imlib2(const char *name); pipi_image_t *pipi_new_imlib2(int width, int height);