source: libpipi/trunk/pipi/test.c @ 2637

Last change on this file since 2637 was 2605, checked in by Sam Hocevar, 14 years ago
  • Big API reorganisation. Now libpipi can transparently convert between colour spaces for a given image. For instance, if pipi_gaussian_blur is applied to a 32-bpp image, it is automatically converted to gamma-corrected 32-bit floats beforehands, then converted back to normal.
  • TODO: clipping, regions of interest, more formats, getpixel macros...
File size: 1.8 KB
Line 
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 * test.c: my repository of test functions
17 */
18
19#include "config.h"
20#include "common.h"
21
22#include <stdlib.h>
23#include <string.h>
24
25#include "pipi.h"
26#include "pipi_internals.h"
27
28void pipi_test(pipi_image_t *img)
29{
30    pipi_pixels_t *pixels;
31    float *data;
32    int x, y;
33
34    pixels = pipi_getpixels(img, PIPI_PIXELS_RGBA_F);
35    data = (float *)pixels->pixels;
36
37    for(y = 0; y < img->h; y++)
38    {
39        for(x = 0; x < img->w; x++)
40        {
41            double r = 0, g = 0, b = 0;
42
43            r = data[(y * img->w + x) * 4];
44            g = data[(y * img->w + x) * 4 + 1];
45            b = data[(y * img->w + x) * 4 + 2];
46
47            if(r + g + b == 0)
48                r = g = b = 1. / 3;
49            else if(r + g + b < 1.)
50            {
51                double d = (1. - r - g - b) / 3;
52                r += d; g += d; b += d;
53            }
54            else if(2. - r + g - b < 1.)
55            {
56                double d = (-1. + r - g + b) / 3;
57                r -= d; g += d; b -= d;
58            }
59            else if(2. + r - g - b < 1.)
60            {
61                double d = (-1. - r + g + b) / 3;
62                r += d; g -= d; b -= d;
63            }
64
65            data[(y * img->w + x) * 4] = r;
66            data[(y * img->w + x) * 4 + 1] = g;
67            data[(y * img->w + x) * 4 + 2] = b;
68        }
69    }
70}
71
Note: See TracBrowser for help on using the repository browser.