Changeset 3411 for libpipi


Ignore:
Timestamp:
Mar 24, 2009, 1:49:00 AM (12 years ago)
Author:
Sam Hocevar
Message:

mean.c: rename this file into merge.c and implement pipi_merge() for trivial
image merging.

Location:
libpipi/trunk/pipi
Files:
3 edited
1 moved

Legend:

Unmodified
Added
Removed
  • libpipi/trunk/pipi/Makefile.am

    r3397 r3411  
    6161combine_sources = \
    6262        combine/rgb.c \
    63         combine/mean.c \
     63        combine/merge.c \
    6464        combine/minmax.c \
    6565        combine/subadd.c \
  • libpipi/trunk/pipi/combine/merge.c

    • Property svn:keywords set to Id
    r3410 r3411  
    2424#include "pipi_internals.h"
    2525
    26 pipi_image_t *pipi_mean(pipi_image_t *img1, pipi_image_t *img2)
     26pipi_image_t *pipi_merge(pipi_image_t *img1, pipi_image_t *img2, double t)
    2727{
    2828    pipi_image_t *dst;
    2929    pipi_pixels_t *img1p, *img2p, *dstp;
    3030    float *img1data, *img2data, *dstdata;
     31    double t2;
    3132    int x, y, w, h;
    3233
    3334    if(img1->w != img2->w || img1->h != img2->h)
    3435        return NULL;
     36
     37    if(t < 0.0)
     38        t = 0.0;
     39    else if(t > 1.0)
     40        t = 1.0;
     41    t2 = 1.0 - t;
    3542
    3643    w = img1->w;
     
    5461            p = img1data[4 * (y * w + x)];
    5562            q = img2data[4 * (y * w + x)];
    56             dstdata[4 * (y * w + x)] = (p + q) * 0.5;
     63            dstdata[4 * (y * w + x)] = t * p + t2 * q;
    5764
    5865            p = img1data[4 * (y * w + x) + 1];
    5966            q = img2data[4 * (y * w + x) + 1];
    60             dstdata[4 * (y * w + x) + 1] = (p + q) * 0.5;
     67            dstdata[4 * (y * w + x) + 1] = t * p + t2 * q;
    6168
    6269            p = img1data[4 * (y * w + x) + 2];
    6370            q = img2data[4 * (y * w + x) + 2];
    64             dstdata[4 * (y * w + x) + 2] = (p + q) * 0.5;
     71            dstdata[4 * (y * w + x) + 2] = t * p + t2 * q;
    6572
    6673            p = img1data[4 * (y * w + x) + 3];
    6774            q = img2data[4 * (y * w + x) + 3];
    68             dstdata[4 * (y * w + x) + 3] = (p + q) * 0.5;
     75            dstdata[4 * (y * w + x) + 3] = t * p + t2 * q;
    6976        }
    7077    }
     
    7380}
    7481
     82pipi_image_t *pipi_mean(pipi_image_t *img1, pipi_image_t *img2)
     83{
     84    return pipi_merge(img1, img2, 0.5);
     85}
     86
  • libpipi/trunk/pipi/context.c

    r3410 r3411  
    7979        { "split", 0 },
    8080        { "mean", 0 },
     81        { "merge", 1 },
    8182        { "min", 0 },
    8283        { "max", 0 },
     
    524525        ctx->nimages--;
    525526    }
     527    else if(!strcmp(cmd, "merge"))
     528    {
     529        pipi_image_t *dst;
     530        char const *arg;
     531        va_list ap;
     532        double val;
     533
     534        if(ctx->nimages < 2)
     535            return -1;
     536
     537        va_start(ap, cmd);
     538        arg = va_arg(ap, char const *);
     539        va_end(ap);
     540        val = atof(arg);
     541
     542        dst = pipi_merge(ctx->images[ctx->nimages - 2],
     543                         ctx->images[ctx->nimages - 1], val);
     544        if(dst == NULL)
     545            return -1;
     546        pipi_free(ctx->images[ctx->nimages - 2]);
     547        pipi_free(ctx->images[ctx->nimages - 1]);
     548        ctx->images[ctx->nimages - 2] = dst;
     549        ctx->nimages--;
     550    }
    526551    else if(!strcmp(cmd, "min"))
    527552    {
  • libpipi/trunk/pipi/pipi.h

    r3410 r3411  
    167167__extern pipi_image_t *pipi_green(pipi_image_t *);
    168168__extern pipi_image_t *pipi_blue(pipi_image_t *);
     169__extern pipi_image_t *pipi_merge(pipi_image_t *, pipi_image_t *, double);
    169170__extern pipi_image_t *pipi_mean(pipi_image_t *, pipi_image_t *);
    170171__extern pipi_image_t *pipi_min(pipi_image_t *, pipi_image_t *);
Note: See TracChangeset for help on using the changeset viewer.