From ee6e43cf81bf5c3c4aaa9e8c6c0def11845a2e6a Mon Sep 17 00:00:00 2001 From: sam Date: Mon, 11 Aug 2008 20:02:20 +0000 Subject: [PATCH] * stock.c: generate images with random noise. git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2697 92316355-f0b4-4df1-b90c-862c8a59935f --- pipi/stock.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/pipi/stock.c b/pipi/stock.c index cdd7c06..623a5c1 100644 --- a/pipi/stock.c +++ b/pipi/stock.c @@ -65,6 +65,41 @@ pipi_image_t *pipi_load_stock(char const *name) return ret; } + /* Generate a completely random image. */ + if(!strncmp(name, "random", 6)) + { + unsigned int ctx = 1; + int x, y, w, h; + + w = atoi(name + 6); + name = strchr(name + 6, 'x'); + if(!name) + return NULL; + h = atoi(name + 1); + if(w <= 0 || h <= 0) + return NULL; + + ret = pipi_new(w, h); + pix = pipi_getpixels(ret, PIPI_PIXELS_Y_F); + data = (float *)pix->pixels; + + for(y = 0; y < h; y++) + for(x = 0; x < w; x++) + { + long hi, lo; + + hi = ctx / 12773L; + lo = ctx % 12773L; + ctx = 16807L * lo - 2836L * hi; + if(ctx <= 0) + ctx += 0x7fffffffL; + + data[y * w + x] = (double)((ctx % 65536) / 65535.); + } + + return ret; + } + return NULL; }