From 48b881b6faf8e9f9e622ac8d68592478bb18c814 Mon Sep 17 00:00:00 2001 From: sam Date: Thu, 14 Aug 2008 18:34:57 +0000 Subject: [PATCH] * Add pipi_tile, to create image mosaics. git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2717 92316355-f0b4-4df1-b90c-862c8a59935f --- pipi/Makefile.am | 6 +++- pipi/context.c | 26 +++++++++++++++ pipi/{fill => paint}/floodfill.c | 0 pipi/paint/tile.c | 55 ++++++++++++++++++++++++++++++++ pipi/pipi.h | 1 + src/pipi.c | 8 +++++ 6 files changed, 95 insertions(+), 1 deletion(-) rename pipi/{fill => paint}/floodfill.c (100%) create mode 100644 pipi/paint/tile.c diff --git a/pipi/Makefile.am b/pipi/Makefile.am index 4a3e232..76483c3 100644 --- a/pipi/Makefile.am +++ b/pipi/Makefile.am @@ -23,8 +23,8 @@ libpipi_la_SOURCES = \ resize.c \ dither.c \ measure.c \ - fill/floodfill.c \ $(codec_sources) \ + $(paint_sources) \ $(combine_sources) \ $(filter_sources) \ $(dither_sources) \ @@ -39,6 +39,10 @@ codec_libs = codec_sources = # Submodules +paint_sources = \ + paint/floodfill.c \ + paint/tile.c + combine_sources = \ combine/mean.c \ combine/minmax.c \ diff --git a/pipi/context.c b/pipi/context.c index 5d86be1..90ced40 100644 --- a/pipi/context.c +++ b/pipi/context.c @@ -167,6 +167,32 @@ int pipi_command(pipi_context_t *ctx, char const *cmd, ...) pipi_free(src); ctx->images[ctx->nimages - 1] = dst; } + else if(!strcmp(cmd, "tile")) + { + pipi_image_t *src, *dst; + char const *arg; + va_list ap; + int w, h; + + if(ctx->nimages < 1) + return -1; + va_start(ap, cmd); + arg = va_arg(ap, char const *); + va_end(ap); + w = atoi(arg); + arg = strchr(arg, 'x'); + if(!arg) + return -1; + h = atoi(arg + 1); + if(w <= 0 || h <= 0) + return -1; + src = ctx->images[ctx->nimages - 1]; + dst = pipi_tile(src, w, h); + if(dst == NULL) + return -1; + pipi_free(src); + ctx->images[ctx->nimages - 1] = dst; + } else if(!strcmp(cmd, "scale")) { pipi_image_t *src, *dst; diff --git a/pipi/fill/floodfill.c b/pipi/paint/floodfill.c similarity index 100% rename from pipi/fill/floodfill.c rename to pipi/paint/floodfill.c diff --git a/pipi/paint/tile.c b/pipi/paint/tile.c new file mode 100644 index 0000000..52e8538 --- /dev/null +++ b/pipi/paint/tile.c @@ -0,0 +1,55 @@ +/* + * 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. + */ + +/* + * tile.c: Tiling function + */ + +#include "config.h" +#include "common.h" + +#include "pipi.h" +#include "pipi_internals.h" + +pipi_image_t *pipi_tile(pipi_image_t *tile, int w, int h) +{ + pipi_image_t *dst; + pipi_pixels_t *tilep, *dstp; + float *tiledata, *dstdata; + int x, y, tw, th, todo; + + tw = tile->w; + th = tile->h; + + dst = pipi_new(w, h); + dstp = pipi_getpixels(dst, PIPI_PIXELS_RGBA_F); + dstdata = (float *)dstp->pixels; + + tilep = pipi_getpixels(tile, PIPI_PIXELS_RGBA_F); + tiledata = (float *)tilep->pixels; + + for(y = 0; y < h; y++) + { + for(x = 0; x < w; x += todo) + { + todo = (x + tw > w) ? w - x : tw; + memcpy(dstdata + 4 * (y * w + x), + tiledata + 4 * (y % th) * tw, + 4 * todo * sizeof(float)); + } + } + + return dst; +} + diff --git a/pipi/pipi.h b/pipi/pipi.h index b12ba89..41dc361 100644 --- a/pipi/pipi.h +++ b/pipi/pipi.h @@ -104,6 +104,7 @@ extern pipi_image_t *pipi_box_blur(pipi_image_t *, int); extern pipi_image_t *pipi_box_blur_ext(pipi_image_t *, int, int); extern pipi_image_t *pipi_autocontrast(pipi_image_t *); +extern pipi_image_t *pipi_tile(pipi_image_t *, int, int); extern int pipi_flood_fill(pipi_image_t *, int, int, float, float, float, float); diff --git a/src/pipi.c b/src/pipi.c index b4be763..85c81a0 100644 --- a/src/pipi.c +++ b/src/pipi.c @@ -41,6 +41,14 @@ int main(int argc, char *argv[]) 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)