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

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

Fix headers.

File size: 3.2 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 * 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
25pipi_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
63pipi_image_t *pipi_red(pipi_image_t *src)
64{
65    pipi_image_t *dst;
66    pipi_pixels_t *srcp, *dstp;
67    float *srcdata, *dstdata;
68    int x, y, w, h;
69
70    w = src->w;
71    h = src->h;
72
73    dst = pipi_new(w, h);
74    dstp = pipi_getpixels(dst, PIPI_PIXELS_Y_F);
75    dstdata = (float *)dstp->pixels;
76
77    srcp = pipi_getpixels(src, PIPI_PIXELS_RGBA_F);
78    srcdata = (float *)srcp->pixels;
79
80    for(y = 0; y < h; y++)
81        for(x = 0; x < w; x++)
82            dstdata[y * w + x] = srcdata[4 * (y * w + x)];
83
84    return dst;
85}
86
87pipi_image_t *pipi_green(pipi_image_t *src)
88{
89    pipi_image_t *dst;
90    pipi_pixels_t *srcp, *dstp;
91    float *srcdata, *dstdata;
92    int x, y, w, h;
93
94    w = src->w;
95    h = src->h;
96
97    dst = pipi_new(w, h);
98    dstp = pipi_getpixels(dst, PIPI_PIXELS_Y_F);
99    dstdata = (float *)dstp->pixels;
100
101    srcp = pipi_getpixels(src, PIPI_PIXELS_RGBA_F);
102    srcdata = (float *)srcp->pixels;
103
104    for(y = 0; y < h; y++)
105        for(x = 0; x < w; x++)
106            dstdata[y * w + x] = srcdata[4 * (y * w + x) + 1];
107
108    return dst;
109}
110
111pipi_image_t *pipi_blue(pipi_image_t *src)
112{
113    pipi_image_t *dst;
114    pipi_pixels_t *srcp, *dstp;
115    float *srcdata, *dstdata;
116    int x, y, w, h;
117
118    w = src->w;
119    h = src->h;
120
121    dst = pipi_new(w, h);
122    dstp = pipi_getpixels(dst, PIPI_PIXELS_Y_F);
123    dstdata = (float *)dstp->pixels;
124
125    srcp = pipi_getpixels(src, PIPI_PIXELS_RGBA_F);
126    srcdata = (float *)srcp->pixels;
127
128    for(y = 0; y < h; y++)
129        for(x = 0; x < w; x++)
130            dstdata[y * w + x] = srcdata[4 * (y * w + x) + 2];
131
132    return dst;
133}
134
Note: See TracBrowser for help on using the repository browser.