source: libpipi/trunk/pipi/combine/mean.c @ 2844

Last change on this file since 2844 was 2844, checked in by Sam Hocevar, 11 years ago

Fix headers.

File size: 1.9 KB
Line 
1/*
2 *  libpipi       Pathetic image processing interface library
3 *  Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
5 *
6 *  $Id$
7 *
8 *  This library is free software. It comes without any warranty, to
9 *  the extent permitted by applicable law. You can redistribute it
10 *  and/or modify it under the terms of the Do What The Fuck You Want
11 *  To Public License, Version 2, as published by Sam Hocevar. See
12 *  http://sam.zoy.org/wtfpl/COPYING for more details.
13 */
14
15/*
16 * mean.c: Mean computation function
17 */
18
19#include "config.h"
20#include "common.h"
21
22#include "pipi.h"
23#include "pipi_internals.h"
24
25pipi_image_t *pipi_mean(pipi_image_t *img1, pipi_image_t *img2)
26{
27    pipi_image_t *dst;
28    pipi_pixels_t *img1p, *img2p, *dstp;
29    float *img1data, *img2data, *dstdata;
30    int x, y, w, h;
31
32    if(img1->w != img2->w || img1->h != img2->h)
33        return NULL;
34
35    w = img1->w;
36    h = img1->h;
37
38    dst = pipi_new(w, h);
39    dstp = pipi_getpixels(dst, PIPI_PIXELS_RGBA_F);
40    dstdata = (float *)dstp->pixels;
41
42    img1p = pipi_getpixels(img1, PIPI_PIXELS_RGBA_F);
43    img1data = (float *)img1p->pixels;
44    img2p = pipi_getpixels(img2, PIPI_PIXELS_RGBA_F);
45    img2data = (float *)img2p->pixels;
46
47    for(y = 0; y < h; y++)
48    {
49        for(x = 0; x < w; x++)
50        {
51            float p, q;
52
53            p = img1data[4 * (y * w + x)];
54            q = img2data[4 * (y * w + x)];
55            dstdata[4 * (y * w + x)] = (p + q) * 0.5;
56
57            p = img1data[4 * (y * w + x) + 1];
58            q = img2data[4 * (y * w + x) + 1];
59            dstdata[4 * (y * w + x) + 1] = (p + q) * 0.5;
60
61            p = img1data[4 * (y * w + x) + 2];
62            q = img2data[4 * (y * w + x) + 2];
63            dstdata[4 * (y * w + x) + 2] = (p + q) * 0.5;
64
65            p = img1data[4 * (y * w + x) + 3];
66            q = img2data[4 * (y * w + x) + 3];
67            dstdata[4 * (y * w + x) + 3] = (p + q) * 0.5;
68        }
69    }
70
71    return dst;
72}
73
Note: See TracBrowser for help on using the repository browser.