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

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

Support C99 types on Win32 through the same hacks as in libcaca.

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
21#include "pipi.h"
22#include "pipi_internals.h"
23
24pipi_image_t *pipi_rgb(pipi_image_t *i1, pipi_image_t *i2, pipi_image_t *i3)
25{
26    pipi_image_t *dst;
27    pipi_pixels_t *i1p, *i2p, *i3p, *dstp;
28    float *i1data, *i2data, *i3data, *dstdata;
29    int x, y, w, h;
30
31    if(i1->w != i2->w || i1->h != i2->h || i1->w != i3->w || i1->h != i3->h)
32        return NULL;
33
34    w = i1->w;
35    h = i1->h;
36
37    dst = pipi_new(w, h);
38    dstp = pipi_getpixels(dst, PIPI_PIXELS_RGBA_F);
39    dstdata = (float *)dstp->pixels;
40
41    i1p = pipi_getpixels(i1, PIPI_PIXELS_Y_F);
42    i1data = (float *)i1p->pixels;
43    i2p = pipi_getpixels(i2, PIPI_PIXELS_Y_F);
44    i2data = (float *)i2p->pixels;
45    i3p = pipi_getpixels(i3, PIPI_PIXELS_Y_F);
46    i3data = (float *)i3p->pixels;
47
48    for(y = 0; y < h; y++)
49    {
50        for(x = 0; x < w; x++)
51        {
52            dstdata[4 * (y * w + x)] = i1data[y * w + x];
53            dstdata[4 * (y * w + x) + 1] = i2data[y * w + x];
54            dstdata[4 * (y * w + x) + 2] = i3data[y * w + x];
55            dstdata[4 * (y * w + x) + 3] = 1.0;
56        }
57    }
58
59    return dst;
60}
61
62pipi_image_t *pipi_red(pipi_image_t *src)
63{
64    pipi_image_t *dst;
65    pipi_pixels_t *srcp, *dstp;
66    float *srcdata, *dstdata;
67    int x, y, w, h;
68
69    w = src->w;
70    h = src->h;
71
72    dst = pipi_new(w, h);
73    dstp = pipi_getpixels(dst, PIPI_PIXELS_Y_F);
74    dstdata = (float *)dstp->pixels;
75
76    srcp = pipi_getpixels(src, PIPI_PIXELS_RGBA_F);
77    srcdata = (float *)srcp->pixels;
78
79    for(y = 0; y < h; y++)
80        for(x = 0; x < w; x++)
81            dstdata[y * w + x] = srcdata[4 * (y * w + x)];
82
83    return dst;
84}
85
86pipi_image_t *pipi_green(pipi_image_t *src)
87{
88    pipi_image_t *dst;
89    pipi_pixels_t *srcp, *dstp;
90    float *srcdata, *dstdata;
91    int x, y, w, h;
92
93    w = src->w;
94    h = src->h;
95
96    dst = pipi_new(w, h);
97    dstp = pipi_getpixels(dst, PIPI_PIXELS_Y_F);
98    dstdata = (float *)dstp->pixels;
99
100    srcp = pipi_getpixels(src, PIPI_PIXELS_RGBA_F);
101    srcdata = (float *)srcp->pixels;
102
103    for(y = 0; y < h; y++)
104        for(x = 0; x < w; x++)
105            dstdata[y * w + x] = srcdata[4 * (y * w + x) + 1];
106
107    return dst;
108}
109
110pipi_image_t *pipi_blue(pipi_image_t *src)
111{
112    pipi_image_t *dst;
113    pipi_pixels_t *srcp, *dstp;
114    float *srcdata, *dstdata;
115    int x, y, w, h;
116
117    w = src->w;
118    h = src->h;
119
120    dst = pipi_new(w, h);
121    dstp = pipi_getpixels(dst, PIPI_PIXELS_Y_F);
122    dstdata = (float *)dstp->pixels;
123
124    srcp = pipi_getpixels(src, PIPI_PIXELS_RGBA_F);
125    srcdata = (float *)srcp->pixels;
126
127    for(y = 0; y < h; y++)
128        for(x = 0; x < w; x++)
129            dstdata[y * w + x] = srcdata[4 * (y * w + x) + 2];
130
131    return dst;
132}
133
Note: See TracBrowser for help on using the repository browser.