Quellcode durchsuchen

* mean.c: implement pipi_mean() to compute a mean image.

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2705 92316355-f0b4-4df1-b90c-862c8a59935f
remotes/tiles
sam vor 16 Jahren
Ursprung
Commit
9bd6b555f9
5 geänderte Dateien mit 99 neuen und 0 gelöschten Zeilen
  1. +4
    -0
      pipi/Makefile.am
  2. +73
    -0
      pipi/combine/mean.c
  3. +15
    -0
      pipi/context.c
  4. +2
    -0
      pipi/pipi.h
  5. +5
    -0
      src/pipi.c

+ 4
- 0
pipi/Makefile.am Datei anzeigen

@@ -25,6 +25,7 @@ libpipi_la_SOURCES = \
measure.c \
fill/floodfill.c \
$(codec_sources) \
$(combine_sources) \
$(filter_sources) \
$(dither_sources) \
$(NULL)
@@ -38,6 +39,9 @@ codec_libs =
codec_sources =

# Submodules
combine_sources = \
combine/mean.c

filter_sources = \
filter/autocontrast.c \
filter/blur.c \


+ 73
- 0
pipi/combine/mean.c Datei anzeigen

@@ -0,0 +1,73 @@
/*
* 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.
*/

/*
* mean.c: Mean computation function
*/

#include "config.h"
#include "common.h"

#include "pipi.h"
#include "pipi_internals.h"

pipi_image_t *pipi_mean(pipi_image_t *img1, pipi_image_t *img2)
{
pipi_image_t *dst;
pipi_pixels_t *img1p, *img2p, *dstp;
float *img1data, *img2data, *dstdata;
int x, y, w, h;

if(img1->w != img2->w || img1->h != img2->h)
return NULL;

w = img1->w;
h = img1->h;

dst = pipi_new(w, h);
dstp = pipi_getpixels(dst, PIPI_PIXELS_RGBA_F);
dstdata = (float *)dstp->pixels;

img1p = pipi_getpixels(img1, PIPI_PIXELS_RGBA_F);
img1data = (float *)img1p->pixels;
img2p = pipi_getpixels(img2, PIPI_PIXELS_RGBA_F);
img2data = (float *)img2p->pixels;

for(y = 0; y < h; y++)
{
for(x = 0; x < w; x++)
{
float p, q;

p = img1data[4 * (y * w + x)];
q = img2data[4 * (y * w + x)];
dstdata[4 * (y * w + x)] = (p + q) * 0.5;

p = img1data[4 * (y * w + x) + 1];
q = img2data[4 * (y * w + x) + 1];
dstdata[4 * (y * w + x) + 1] = (p + q) * 0.5;

p = img1data[4 * (y * w + x) + 2];
q = img2data[4 * (y * w + x) + 2];
dstdata[4 * (y * w + x) + 2] = (p + q) * 0.5;

p = img1data[4 * (y * w + x) + 3];
q = img2data[4 * (y * w + x) + 3];
dstdata[4 * (y * w + x) + 3] = (p + q) * 0.5;
}
}

return dst;
}


+ 15
- 0
pipi/context.c Datei anzeigen

@@ -131,6 +131,21 @@ int pipi_command(pipi_context_t *ctx, char const *cmd, ...)
pipi_free(src);
ctx->images[ctx->nimages - 1] = dst;
}
else if(!strcmp(cmd, "mean"))
{
pipi_image_t *dst;

if(ctx->nimages < 2)
return -1;
dst = pipi_mean(ctx->images[ctx->nimages - 2],
ctx->images[ctx->nimages - 1]);
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, "wrap"))
{
if(ctx->nimages <= 0)


+ 2
- 0
pipi/pipi.h Datei anzeigen

@@ -85,6 +85,8 @@ 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_mean(pipi_image_t *, pipi_image_t *);

extern pipi_image_t *pipi_convolution(pipi_image_t *, int, int, double[]);
extern pipi_image_t *pipi_gaussian_blur(pipi_image_t *, float);
extern pipi_image_t *pipi_gaussian_blur_ext(pipi_image_t *,


+ 5
- 0
src/pipi.c Datei anzeigen

@@ -51,6 +51,11 @@ int main(int argc, char *argv[])
if(pipi_command(ctx, "wrap") != 0)
return EXIT_FAILURE;
}
else if(!strcmp(argv[0], "--mean"))
{
if(pipi_command(ctx, "mean") != 0)
return EXIT_FAILURE;
}
else if(!strcmp(argv[0], "--output") || !strcmp(argv[0], "-o"))
{
if(argv[1] == NULL)


Laden…
Abbrechen
Speichern