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

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

Change _C pixel format suffixes into _U8 for more clarity.

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