source: libpipi/trunk/pipi/combine/minmax.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 * minmax.c: min and max computation functions
17 */
18
19#include "config.h"
20
21#include "pipi.h"
22#include "pipi_internals.h"
23
24pipi_image_t *pipi_min(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 ? p : q;
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 ? p : q;
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 ? p : q;
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 ? p : q;
67        }
68    }
69
70    return dst;
71}
72
73pipi_image_t *pipi_max(pipi_image_t *img1, pipi_image_t *img2)
74{
75    pipi_image_t *dst;
76    pipi_pixels_t *img1p, *img2p, *dstp;
77    float *img1data, *img2data, *dstdata;
78    int x, y, w, h;
79
80    if(img1->w != img2->w || img1->h != img2->h)
81        return NULL;
82
83    w = img1->w;
84    h = img1->h;
85
86    dst = pipi_new(w, h);
87    dstp = pipi_getpixels(dst, PIPI_PIXELS_RGBA_F);
88    dstdata = (float *)dstp->pixels;
89
90    img1p = pipi_getpixels(img1, PIPI_PIXELS_RGBA_F);
91    img1data = (float *)img1p->pixels;
92    img2p = pipi_getpixels(img2, PIPI_PIXELS_RGBA_F);
93    img2data = (float *)img2p->pixels;
94
95    for(y = 0; y < h; y++)
96    {
97        for(x = 0; x < w; x++)
98        {
99            float p, q;
100
101            p = img1data[4 * (y * w + x)];
102            q = img2data[4 * (y * w + x)];
103            dstdata[4 * (y * w + x)] = p > q ? p : q;
104
105            p = img1data[4 * (y * w + x) + 1];
106            q = img2data[4 * (y * w + x) + 1];
107            dstdata[4 * (y * w + x) + 1] = p > q ? p : q;
108
109            p = img1data[4 * (y * w + x) + 2];
110            q = img2data[4 * (y * w + x) + 2];
111            dstdata[4 * (y * w + x) + 2] = p > q ? p : q;
112
113            p = img1data[4 * (y * w + x) + 3];
114            q = img2data[4 * (y * w + x) + 3];
115            dstdata[4 * (y * w + x) + 3] = p > q ? p : q;
116        }
117    }
118
119    return dst;
120}
121
Note: See TracBrowser for help on using the repository browser.