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