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; }