diff --git a/pipi/Makefile.am b/pipi/Makefile.am index 444f1a1..0d06c2c 100644 --- a/pipi/Makefile.am +++ b/pipi/Makefile.am @@ -60,7 +60,7 @@ render_sources = \ combine_sources = \ combine/rgb.c \ - combine/mean.c \ + combine/merge.c \ combine/minmax.c \ combine/subadd.c \ combine/mulscreen.c diff --git a/pipi/combine/mean.c b/pipi/combine/merge.c similarity index 79% rename from pipi/combine/mean.c rename to pipi/combine/merge.c index e7efc51..dd6f7b9 100644 --- a/pipi/combine/mean.c +++ b/pipi/combine/merge.c @@ -23,16 +23,23 @@ #include "pipi.h" #include "pipi_internals.h" -pipi_image_t *pipi_mean(pipi_image_t *img1, pipi_image_t *img2) +pipi_image_t *pipi_merge(pipi_image_t *img1, pipi_image_t *img2, double t) { pipi_image_t *dst; pipi_pixels_t *img1p, *img2p, *dstp; float *img1data, *img2data, *dstdata; + double t2; int x, y, w, h; if(img1->w != img2->w || img1->h != img2->h) return NULL; + if(t < 0.0) + t = 0.0; + else if(t > 1.0) + t = 1.0; + t2 = 1.0 - t; + w = img1->w; h = img1->h; @@ -53,22 +60,27 @@ pipi_image_t *pipi_mean(pipi_image_t *img1, pipi_image_t *img2) p = img1data[4 * (y * w + x)]; q = img2data[4 * (y * w + x)]; - dstdata[4 * (y * w + x)] = (p + q) * 0.5; + dstdata[4 * (y * w + x)] = t * p + t2 * q; p = img1data[4 * (y * w + x) + 1]; q = img2data[4 * (y * w + x) + 1]; - dstdata[4 * (y * w + x) + 1] = (p + q) * 0.5; + dstdata[4 * (y * w + x) + 1] = t * p + t2 * q; p = img1data[4 * (y * w + x) + 2]; q = img2data[4 * (y * w + x) + 2]; - dstdata[4 * (y * w + x) + 2] = (p + q) * 0.5; + dstdata[4 * (y * w + x) + 2] = t * p + t2 * q; p = img1data[4 * (y * w + x) + 3]; q = img2data[4 * (y * w + x) + 3]; - dstdata[4 * (y * w + x) + 3] = (p + q) * 0.5; + dstdata[4 * (y * w + x) + 3] = t * p + t2 * q; } } return dst; } +pipi_image_t *pipi_mean(pipi_image_t *img1, pipi_image_t *img2) +{ + return pipi_merge(img1, img2, 0.5); +} + diff --git a/pipi/context.c b/pipi/context.c index 4238747..53f87c6 100644 --- a/pipi/context.c +++ b/pipi/context.c @@ -78,6 +78,7 @@ pipi_command_t const *pipi_get_command_list(void) { "combine", 0 }, { "split", 0 }, { "mean", 0 }, + { "merge", 1 }, { "min", 0 }, { "max", 0 }, { "add", 0 }, @@ -523,6 +524,30 @@ int pipi_command(pipi_context_t *ctx, char const *cmd, ...) ctx->images[ctx->nimages - 2] = dst; ctx->nimages--; } + else if(!strcmp(cmd, "merge")) + { + pipi_image_t *dst; + char const *arg; + va_list ap; + double val; + + if(ctx->nimages < 2) + return -1; + + va_start(ap, cmd); + arg = va_arg(ap, char const *); + va_end(ap); + val = atof(arg); + + dst = pipi_merge(ctx->images[ctx->nimages - 2], + ctx->images[ctx->nimages - 1], val); + if(dst == NULL) + return -1; + pipi_free(ctx->images[ctx->nimages - 2]); + pipi_free(ctx->images[ctx->nimages - 1]); + ctx->images[ctx->nimages - 2] = dst; + ctx->nimages--; + } else if(!strcmp(cmd, "min")) { pipi_image_t *dst; diff --git a/pipi/pipi.h b/pipi/pipi.h index 9f7288b..7bda7c3 100644 --- a/pipi/pipi.h +++ b/pipi/pipi.h @@ -166,6 +166,7 @@ __extern pipi_image_t *pipi_rgb(pipi_image_t *, pipi_image_t *, pipi_image_t *); __extern pipi_image_t *pipi_red(pipi_image_t *); __extern pipi_image_t *pipi_green(pipi_image_t *); __extern pipi_image_t *pipi_blue(pipi_image_t *); +__extern pipi_image_t *pipi_merge(pipi_image_t *, pipi_image_t *, double); __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_max(pipi_image_t *, pipi_image_t *);