git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2753 92316355-f0b4-4df1-b90c-862c8a59935fremotes/tiles
| @@ -45,6 +45,7 @@ paint_sources = \ | |||||
| paint/tile.c | paint/tile.c | ||||
| combine_sources = \ | combine_sources = \ | ||||
| combine/rgb.c \ | |||||
| combine/mean.c \ | combine/mean.c \ | ||||
| combine/minmax.c \ | combine/minmax.c \ | ||||
| combine/subadd.c \ | combine/subadd.c \ | ||||
| @@ -0,0 +1,62 @@ | |||||
| /* | |||||
| * 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. | |||||
| */ | |||||
| /* | |||||
| * rgb.c: RGB combining function | |||||
| */ | |||||
| #include "config.h" | |||||
| #include "common.h" | |||||
| #include "pipi.h" | |||||
| #include "pipi_internals.h" | |||||
| pipi_image_t *pipi_rgb(pipi_image_t *i1, pipi_image_t *i2, pipi_image_t *i3) | |||||
| { | |||||
| pipi_image_t *dst; | |||||
| pipi_pixels_t *i1p, *i2p, *i3p, *dstp; | |||||
| float *i1data, *i2data, *i3data, *dstdata; | |||||
| int x, y, w, h; | |||||
| if(i1->w != i2->w || i1->h != i2->h || i1->w != i3->w || i1->h != i3->h) | |||||
| return NULL; | |||||
| w = i1->w; | |||||
| h = i1->h; | |||||
| dst = pipi_new(w, h); | |||||
| dstp = pipi_getpixels(dst, PIPI_PIXELS_RGBA_F); | |||||
| dstdata = (float *)dstp->pixels; | |||||
| i1p = pipi_getpixels(i1, PIPI_PIXELS_Y_F); | |||||
| i1data = (float *)i1p->pixels; | |||||
| i2p = pipi_getpixels(i2, PIPI_PIXELS_Y_F); | |||||
| i2data = (float *)i2p->pixels; | |||||
| i3p = pipi_getpixels(i3, PIPI_PIXELS_Y_F); | |||||
| i3data = (float *)i3p->pixels; | |||||
| for(y = 0; y < h; y++) | |||||
| { | |||||
| for(x = 0; x < w; x++) | |||||
| { | |||||
| dstdata[4 * (y * w + x)] = i1data[y * w + x]; | |||||
| dstdata[4 * (y * w + x) + 1] = i2data[y * w + x]; | |||||
| dstdata[4 * (y * w + x) + 2] = i3data[y * w + x]; | |||||
| dstdata[4 * (y * w + x) + 3] = 1.0; | |||||
| } | |||||
| } | |||||
| return dst; | |||||
| } | |||||
| @@ -373,6 +373,23 @@ int pipi_command(pipi_context_t *ctx, char const *cmd, ...) | |||||
| ctx->images[ctx->nimages - 1] = pipi_rotate270(tmp); | ctx->images[ctx->nimages - 1] = pipi_rotate270(tmp); | ||||
| pipi_free(tmp); | pipi_free(tmp); | ||||
| } | } | ||||
| else if(!strcmp(cmd, "rgb")) | |||||
| { | |||||
| pipi_image_t *dst; | |||||
| if(ctx->nimages < 3) | |||||
| return -1; | |||||
| dst = pipi_rgb(ctx->images[ctx->nimages - 3], | |||||
| ctx->images[ctx->nimages - 2], | |||||
| ctx->images[ctx->nimages - 1]); | |||||
| if(dst == NULL) | |||||
| return -1; | |||||
| pipi_free(ctx->images[ctx->nimages - 3]); | |||||
| pipi_free(ctx->images[ctx->nimages - 2]); | |||||
| pipi_free(ctx->images[ctx->nimages - 1]); | |||||
| ctx->images[ctx->nimages - 3] = dst; | |||||
| ctx->nimages -= 2; | |||||
| } | |||||
| else if(!strcmp(cmd, "mean")) | else if(!strcmp(cmd, "mean")) | ||||
| { | { | ||||
| pipi_image_t *dst; | pipi_image_t *dst; | ||||
| @@ -105,6 +105,7 @@ extern double pipi_measure_rmsd(pipi_image_t *, pipi_image_t *); | |||||
| extern pipi_image_t *pipi_resize(pipi_image_t *, int, int); | extern pipi_image_t *pipi_resize(pipi_image_t *, int, int); | ||||
| extern pipi_image_t *pipi_rgb(pipi_image_t *, pipi_image_t *, pipi_image_t *); | |||||
| extern pipi_image_t *pipi_mean(pipi_image_t *, pipi_image_t *); | extern pipi_image_t *pipi_mean(pipi_image_t *, pipi_image_t *); | ||||
| extern pipi_image_t *pipi_min(pipi_image_t *, pipi_image_t *); | extern pipi_image_t *pipi_min(pipi_image_t *, pipi_image_t *); | ||||
| extern pipi_image_t *pipi_max(pipi_image_t *, pipi_image_t *); | extern pipi_image_t *pipi_max(pipi_image_t *, pipi_image_t *); | ||||
| @@ -168,6 +168,11 @@ int main(int argc, char *argv[]) | |||||
| if(pipi_command(ctx, "wrap") != 0) | if(pipi_command(ctx, "wrap") != 0) | ||||
| return EXIT_FAILURE; | return EXIT_FAILURE; | ||||
| } | } | ||||
| else if(!strcmp(argv[0], "--rgb")) | |||||
| { | |||||
| if(pipi_command(ctx, "rgb") != 0) | |||||
| return EXIT_FAILURE; | |||||
| } | |||||
| else if(!strcmp(argv[0], "--mean")) | else if(!strcmp(argv[0], "--mean")) | ||||
| { | { | ||||
| if(pipi_command(ctx, "mean") != 0) | if(pipi_command(ctx, "mean") != 0) | ||||