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 | |
---|
21 | #include <stdlib.h> |
---|
22 | |
---|
23 | #include "pipi.h" |
---|
24 | #include "pipi_internals.h" |
---|
25 | |
---|
26 | pipi_image_t *pipi_mean(pipi_image_t *img1, pipi_image_t *img2) |
---|
27 | { |
---|
28 | pipi_image_t *dst; |
---|
29 | pipi_pixels_t *img1p, *img2p, *dstp; |
---|
30 | float *img1data, *img2data, *dstdata; |
---|
31 | int x, y, w, h; |
---|
32 | |
---|
33 | if(img1->w != img2->w || img1->h != img2->h) |
---|
34 | return NULL; |
---|
35 | |
---|
36 | w = img1->w; |
---|
37 | h = img1->h; |
---|
38 | |
---|
39 | dst = pipi_new(w, h); |
---|
40 | dstp = pipi_get_pixels(dst, PIPI_PIXELS_RGBA_F32); |
---|
41 | dstdata = (float *)dstp->pixels; |
---|
42 | |
---|
43 | img1p = pipi_get_pixels(img1, PIPI_PIXELS_RGBA_F32); |
---|
44 | img1data = (float *)img1p->pixels; |
---|
45 | img2p = pipi_get_pixels(img2, PIPI_PIXELS_RGBA_F32); |
---|
46 | img2data = (float *)img2p->pixels; |
---|
47 | |
---|
48 | for(y = 0; y < h; y++) |
---|
49 | { |
---|
50 | for(x = 0; x < w; x++) |
---|
51 | { |
---|
52 | float p, q; |
---|
53 | |
---|
54 | p = img1data[4 * (y * w + x)]; |
---|
55 | q = img2data[4 * (y * w + x)]; |
---|
56 | dstdata[4 * (y * w + x)] = (p + q) * 0.5; |
---|
57 | |
---|
58 | p = img1data[4 * (y * w + x) + 1]; |
---|
59 | q = img2data[4 * (y * w + x) + 1]; |
---|
60 | dstdata[4 * (y * w + x) + 1] = (p + q) * 0.5; |
---|
61 | |
---|
62 | p = img1data[4 * (y * w + x) + 2]; |
---|
63 | q = img2data[4 * (y * w + x) + 2]; |
---|
64 | dstdata[4 * (y * w + x) + 2] = (p + q) * 0.5; |
---|
65 | |
---|
66 | p = img1data[4 * (y * w + x) + 3]; |
---|
67 | q = img2data[4 * (y * w + x) + 3]; |
---|
68 | dstdata[4 * (y * w + x) + 3] = (p + q) * 0.5; |
---|
69 | } |
---|
70 | } |
---|
71 | |
---|
72 | return dst; |
---|
73 | } |
---|
74 | |
---|