source: libpipi/trunk/pipi/render/noise.c @ 2844

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

Fix headers.

File size: 1.5 KB
RevLine 
[2765]1/*
[2844]2 *  libpipi       Pathetic image processing interface library
[2765]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 * noise.c: noise rendering functions
17 */
18
19#include "config.h"
20#include "common.h"
21
22#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
25
26#include "pipi.h"
27#include "pipi_internals.h"
28
29pipi_image_t *pipi_render_random(int w, int h)
30{
31    pipi_image_t *ret;
32    pipi_pixels_t *pix;
33    float *data;
34    unsigned int ctx = 1;
35    int x, y, t;
36
37    ret = pipi_new(w, h);
38    pix = pipi_getpixels(ret, PIPI_PIXELS_RGBA_F);
39    data = (float *)pix->pixels;
40
41    for(y = 0; y < h; y++)
42        for(x = 0; x < w; x++)
43        {
44            for(t = 0; t < 3; t++)
45            {
46                long hi, lo;
47
48                hi = ctx / 12773L;
49                lo = ctx % 12773L;
50                ctx = 16807L * lo - 2836L * hi;
51                if(ctx <= 0)
52                    ctx += 0x7fffffffL;
53
54                data[4 * (y * w + x) + t]
55                    = (double)((ctx % 65536) / 65535.);
56            }
57            data[4 * (y * w + x) + 3] = 1.0;
58        }
59
60    return ret;
61}
62
Note: See TracBrowser for help on using the repository browser.