git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2717 92316355-f0b4-4df1-b90c-862c8a59935fremotes/tiles
@@ -23,8 +23,8 @@ libpipi_la_SOURCES = \ | |||||
resize.c \ | resize.c \ | ||||
dither.c \ | dither.c \ | ||||
measure.c \ | measure.c \ | ||||
fill/floodfill.c \ | |||||
$(codec_sources) \ | $(codec_sources) \ | ||||
$(paint_sources) \ | |||||
$(combine_sources) \ | $(combine_sources) \ | ||||
$(filter_sources) \ | $(filter_sources) \ | ||||
$(dither_sources) \ | $(dither_sources) \ | ||||
@@ -39,6 +39,10 @@ codec_libs = | |||||
codec_sources = | codec_sources = | ||||
# Submodules | # Submodules | ||||
paint_sources = \ | |||||
paint/floodfill.c \ | |||||
paint/tile.c | |||||
combine_sources = \ | combine_sources = \ | ||||
combine/mean.c \ | combine/mean.c \ | ||||
combine/minmax.c \ | combine/minmax.c \ | ||||
@@ -167,6 +167,32 @@ int pipi_command(pipi_context_t *ctx, char const *cmd, ...) | |||||
pipi_free(src); | pipi_free(src); | ||||
ctx->images[ctx->nimages - 1] = dst; | 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")) | else if(!strcmp(cmd, "scale")) | ||||
{ | { | ||||
pipi_image_t *src, *dst; | pipi_image_t *src, *dst; | ||||
@@ -0,0 +1,55 @@ | |||||
/* | |||||
* 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. | |||||
*/ | |||||
/* | |||||
* 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; | |||||
} | |||||
@@ -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_box_blur_ext(pipi_image_t *, int, int); | ||||
extern pipi_image_t *pipi_autocontrast(pipi_image_t *); | 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 *, | extern int pipi_flood_fill(pipi_image_t *, | ||||
int, int, float, float, float, float); | int, int, float, float, float, float); | ||||
@@ -41,6 +41,14 @@ int main(int argc, char *argv[]) | |||||
return EXIT_FAILURE; | return EXIT_FAILURE; | ||||
argv++; | 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")) | else if(!strcmp(argv[0], "--dither")) | ||||
{ | { | ||||
if(argv[1] == NULL) | if(argv[1] == NULL) | ||||