Bläddra i källkod

* 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
remotes/tiles
sam 16 år sedan
förälder
incheckning
ee6e43cf81
1 ändrade filer med 35 tillägg och 0 borttagningar
  1. +35
    -0
      pipi/stock.c

+ 35
- 0
pipi/stock.c Visa fil

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


Laddar…
Avbryt
Spara