| 1 | /* |
| 2 | This frei0r plugin generates white noise images |
| 3 | |
| 4 | Copyright (C) 2004, 2005 Martin Bayer <[email protected]> |
| 5 | |
| 6 | This library is free software; you can redistribute it and/or |
| 7 | modify it under the terms of the GNU Lesser General Public |
| 8 | License as published by the Free Software Foundation; either |
| 9 | version 2.1 of the License, or (at your option) any later version. |
| 10 | |
| 11 | This library is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | Lesser General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU Lesser General Public |
| 17 | License along with this library; if not, write to the Free Software |
| 18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | */ |
| 20 | |
| 21 | #include "frei0r.hpp" |
| 22 | |
| 23 | #include <algorithm> |
| 24 | |
| 25 | struct wnoise |
| 26 | { |
| 27 | wnoise(unsigned int s) |
| 28 | : seed(s) {} |
| 29 | |
| 30 | unsigned int seed; |
| 31 | |
| 32 | unsigned int operator()() |
| 33 | { |
| 34 | seed *= 3039177861U; // parameter for LCG |
| 35 | unsigned char rd = seed >> 24; |
| 36 | return (rd | rd << 8 | rd << 16 | 0xff000000); |
| 37 | } |
| 38 | |
| 39 | |
| 40 | }; |
| 41 | |
| 42 | class nois0r : public frei0r::source |
| 43 | { |
| 44 | public: |
| 45 | nois0r(unsigned int width, unsigned int height) |
| 46 | { |
| 47 | } |
| 48 | |
| 49 | |
| 50 | virtual void update(double time, |
| 51 | uint32_t* out) |
| 52 | { |
| 53 | wnoise wn(0x0f0f0f0f ^ (unsigned int)(time*100000.0)); |
| 54 | |
| 55 | std::generate(out, out+width*height, wn); |
| 56 | } |
| 57 | }; |
| 58 | |
| 59 | |
| 60 | frei0r::construct<nois0r> plugin("Nois0r", |
| 61 | "Generates white noise images", |
| 62 | "Martin Bayer", |
| 63 | 0,3); |
| 64 |