1 | /* |
---|
2 | * libpipi Proper image processing implementation 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 | * rgb.c: RGB combining function |
---|
17 | */ |
---|
18 | |
---|
19 | #include "config.h" |
---|
20 | #include "common.h" |
---|
21 | |
---|
22 | #include "pipi.h" |
---|
23 | #include "pipi_internals.h" |
---|
24 | |
---|
25 | pipi_image_t *pipi_rgb(pipi_image_t *i1, pipi_image_t *i2, pipi_image_t *i3) |
---|
26 | { |
---|
27 | pipi_image_t *dst; |
---|
28 | pipi_pixels_t *i1p, *i2p, *i3p, *dstp; |
---|
29 | float *i1data, *i2data, *i3data, *dstdata; |
---|
30 | int x, y, w, h; |
---|
31 | |
---|
32 | if(i1->w != i2->w || i1->h != i2->h || i1->w != i3->w || i1->h != i3->h) |
---|
33 | return NULL; |
---|
34 | |
---|
35 | w = i1->w; |
---|
36 | h = i1->h; |
---|
37 | |
---|
38 | dst = pipi_new(w, h); |
---|
39 | dstp = pipi_getpixels(dst, PIPI_PIXELS_RGBA_F); |
---|
40 | dstdata = (float *)dstp->pixels; |
---|
41 | |
---|
42 | i1p = pipi_getpixels(i1, PIPI_PIXELS_Y_F); |
---|
43 | i1data = (float *)i1p->pixels; |
---|
44 | i2p = pipi_getpixels(i2, PIPI_PIXELS_Y_F); |
---|
45 | i2data = (float *)i2p->pixels; |
---|
46 | i3p = pipi_getpixels(i3, PIPI_PIXELS_Y_F); |
---|
47 | i3data = (float *)i3p->pixels; |
---|
48 | |
---|
49 | for(y = 0; y < h; y++) |
---|
50 | { |
---|
51 | for(x = 0; x < w; x++) |
---|
52 | { |
---|
53 | dstdata[4 * (y * w + x)] = i1data[y * w + x]; |
---|
54 | dstdata[4 * (y * w + x) + 1] = i2data[y * w + x]; |
---|
55 | dstdata[4 * (y * w + x) + 2] = i3data[y * w + x]; |
---|
56 | dstdata[4 * (y * w + x) + 3] = 1.0; |
---|
57 | } |
---|
58 | } |
---|
59 | |
---|
60 | return dst; |
---|
61 | } |
---|
62 | |
---|